Merge pull request #8449 from ProofOfKeags/refactor/lnwallet/delete-LightningChannel-status

lnwallet: simplify status row
This commit is contained in:
Yong 2024-02-03 13:48:31 +08:00 committed by GitHub
commit 54c47a3feb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 48 deletions

View file

@ -153,38 +153,6 @@ func (e *ErrCommitSyncLocalDataLoss) Error() string {
e.CommitPoint.SerializeCompressed())
}
// channelState is an enum like type which represents the current state of a
// particular channel.
// TODO(roasbeef): actually update state
type channelState uint8
const (
// channelPending indicates this channel is still going through the
// funding workflow, and isn't yet open.
channelPending channelState = iota // nolint: unused
// channelOpen represents an open, active channel capable of
// sending/receiving HTLCs.
channelOpen
// channelClosing represents a channel which is in the process of being
// closed.
channelClosing
// channelClosed represents a channel which has been fully closed. Note
// that before a channel can be closed, ALL pending HTLCs must be
// settled/removed.
channelClosed
// channelDispute indicates that an un-cooperative closure has been
// detected within the channel.
channelDispute
// channelPendingPayment indicates that there a currently outstanding
// HTLCs within the channel.
channelPendingPayment // nolint:unused
)
// PaymentHash represents the sha256 of a random value. This hash is used to
// uniquely track incoming/outgoing payments within this channel, as well as
// payments requested by the wallet/daemon.
@ -1283,7 +1251,7 @@ type LightningChannel struct {
// the commitment transaction that spends the multi-sig output.
signDesc *input.SignDescriptor
status channelState
isClosed bool
// ChanPoint is the funding outpoint of this channel.
ChanPoint *wire.OutPoint
@ -1538,7 +1506,7 @@ func (lc *LightningChannel) createSignDesc() error {
// events do so properly.
func (lc *LightningChannel) ResetState() {
lc.Lock()
lc.status = channelOpen
lc.isClosed = false
lc.Unlock()
}
@ -7593,9 +7561,8 @@ func (lc *LightningChannel) ForceClose() (*LocalForceCloseSummary, error) {
"summary: %w", err)
}
// Set the channel state to indicate that the channel is now in a
// contested state.
lc.status = channelDispute
// Mark the channel as closed to block future closure requests.
lc.isClosed = true
return summary, nil
}
@ -7789,8 +7756,8 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
lc.Lock()
defer lc.Unlock()
// If we've already closed the channel, then ignore this request.
if lc.status == channelClosed {
// If we're already closing the channel, then ignore this request.
if lc.isClosed {
// TODO(roasbeef): check to ensure no pending payments
return nil, nil, 0, ErrChanClosing
}
@ -7853,10 +7820,6 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
}
}
// As everything checks out, indicate in the channel status that a
// channel closure has been initiated.
lc.status = channelClosing
closeTXID := closeTx.TxHash()
return sig, &closeTXID, ourBalance, nil
}
@ -7877,8 +7840,8 @@ func (lc *LightningChannel) CompleteCooperativeClose(
lc.Lock()
defer lc.Unlock()
// If the channel is already closed, then ignore this request.
if lc.status == channelClosed {
// If the channel is already closing, then ignore this request.
if lc.isClosed {
// TODO(roasbeef): check to ensure no pending payments
return nil, 0, ErrChanClosing
}
@ -7982,7 +7945,7 @@ func (lc *LightningChannel) CompleteCooperativeClose(
// As the transaction is sane, and the scripts are valid we'll mark the
// channel now as closed as the closure transaction should get into the
// chain in a timely manner and possibly be re-broadcast by the wallet.
lc.status = channelClosed
lc.isClosed = true
return closeTx, ourBalance, nil
}

View file

@ -2147,8 +2147,8 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
}
resetChannelState := func() {
aliceChannel.status = channelOpen
bobChannel.status = channelOpen
aliceChannel.ResetState()
bobChannel.ResetState()
}
setBalances := func(aliceBalance, bobBalance lnwire.MilliSatoshi) {