mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-30 18:43:42 +02:00
Merge pull request #8449 from ProofOfKeags/refactor/lnwallet/delete-LightningChannel-status
lnwallet: simplify status row
This commit is contained in:
@ -153,38 +153,6 @@ func (e *ErrCommitSyncLocalDataLoss) Error() string {
|
|||||||
e.CommitPoint.SerializeCompressed())
|
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
|
// PaymentHash represents the sha256 of a random value. This hash is used to
|
||||||
// uniquely track incoming/outgoing payments within this channel, as well as
|
// uniquely track incoming/outgoing payments within this channel, as well as
|
||||||
// payments requested by the wallet/daemon.
|
// payments requested by the wallet/daemon.
|
||||||
@ -1283,7 +1251,7 @@ type LightningChannel struct {
|
|||||||
// the commitment transaction that spends the multi-sig output.
|
// the commitment transaction that spends the multi-sig output.
|
||||||
signDesc *input.SignDescriptor
|
signDesc *input.SignDescriptor
|
||||||
|
|
||||||
status channelState
|
isClosed bool
|
||||||
|
|
||||||
// ChanPoint is the funding outpoint of this channel.
|
// ChanPoint is the funding outpoint of this channel.
|
||||||
ChanPoint *wire.OutPoint
|
ChanPoint *wire.OutPoint
|
||||||
@ -1538,7 +1506,7 @@ func (lc *LightningChannel) createSignDesc() error {
|
|||||||
// events do so properly.
|
// events do so properly.
|
||||||
func (lc *LightningChannel) ResetState() {
|
func (lc *LightningChannel) ResetState() {
|
||||||
lc.Lock()
|
lc.Lock()
|
||||||
lc.status = channelOpen
|
lc.isClosed = false
|
||||||
lc.Unlock()
|
lc.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7593,9 +7561,8 @@ func (lc *LightningChannel) ForceClose() (*LocalForceCloseSummary, error) {
|
|||||||
"summary: %w", err)
|
"summary: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the channel state to indicate that the channel is now in a
|
// Mark the channel as closed to block future closure requests.
|
||||||
// contested state.
|
lc.isClosed = true
|
||||||
lc.status = channelDispute
|
|
||||||
|
|
||||||
return summary, nil
|
return summary, nil
|
||||||
}
|
}
|
||||||
@ -7789,8 +7756,8 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
|
|||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
|
|
||||||
// If we've already closed the channel, then ignore this request.
|
// If we're already closing the channel, then ignore this request.
|
||||||
if lc.status == channelClosed {
|
if lc.isClosed {
|
||||||
// TODO(roasbeef): check to ensure no pending payments
|
// TODO(roasbeef): check to ensure no pending payments
|
||||||
return nil, nil, 0, ErrChanClosing
|
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()
|
closeTXID := closeTx.TxHash()
|
||||||
return sig, &closeTXID, ourBalance, nil
|
return sig, &closeTXID, ourBalance, nil
|
||||||
}
|
}
|
||||||
@ -7877,8 +7840,8 @@ func (lc *LightningChannel) CompleteCooperativeClose(
|
|||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
|
|
||||||
// If the channel is already closed, then ignore this request.
|
// If the channel is already closing, then ignore this request.
|
||||||
if lc.status == channelClosed {
|
if lc.isClosed {
|
||||||
// TODO(roasbeef): check to ensure no pending payments
|
// TODO(roasbeef): check to ensure no pending payments
|
||||||
return nil, 0, ErrChanClosing
|
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
|
// 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
|
// 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.
|
// chain in a timely manner and possibly be re-broadcast by the wallet.
|
||||||
lc.status = channelClosed
|
lc.isClosed = true
|
||||||
|
|
||||||
return closeTx, ourBalance, nil
|
return closeTx, ourBalance, nil
|
||||||
}
|
}
|
||||||
|
@ -2147,8 +2147,8 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetChannelState := func() {
|
resetChannelState := func() {
|
||||||
aliceChannel.status = channelOpen
|
aliceChannel.ResetState()
|
||||||
bobChannel.status = channelOpen
|
bobChannel.ResetState()
|
||||||
}
|
}
|
||||||
|
|
||||||
setBalances := func(aliceBalance, bobBalance lnwire.MilliSatoshi) {
|
setBalances := func(aliceBalance, bobBalance lnwire.MilliSatoshi) {
|
||||||
|
Reference in New Issue
Block a user