Skip to content

Commit 54c47a3

Browse files
authored
Merge pull request #8449 from ProofOfKeags/refactor/lnwallet/delete-LightningChannel-status
lnwallet: simplify status row
2 parents 47fced6 + 3a02f2b commit 54c47a3

File tree

2 files changed

+11
-48
lines changed

2 files changed

+11
-48
lines changed

lnwallet/channel.go

+9-46
Original file line numberDiff line numberDiff line change
@@ -153,38 +153,6 @@ func (e *ErrCommitSyncLocalDataLoss) Error() string {
153153
e.CommitPoint.SerializeCompressed())
154154
}
155155

156-
// channelState is an enum like type which represents the current state of a
157-
// particular channel.
158-
// TODO(roasbeef): actually update state
159-
type channelState uint8
160-
161-
const (
162-
// channelPending indicates this channel is still going through the
163-
// funding workflow, and isn't yet open.
164-
channelPending channelState = iota // nolint: unused
165-
166-
// channelOpen represents an open, active channel capable of
167-
// sending/receiving HTLCs.
168-
channelOpen
169-
170-
// channelClosing represents a channel which is in the process of being
171-
// closed.
172-
channelClosing
173-
174-
// channelClosed represents a channel which has been fully closed. Note
175-
// that before a channel can be closed, ALL pending HTLCs must be
176-
// settled/removed.
177-
channelClosed
178-
179-
// channelDispute indicates that an un-cooperative closure has been
180-
// detected within the channel.
181-
channelDispute
182-
183-
// channelPendingPayment indicates that there a currently outstanding
184-
// HTLCs within the channel.
185-
channelPendingPayment // nolint:unused
186-
)
187-
188156
// PaymentHash represents the sha256 of a random value. This hash is used to
189157
// uniquely track incoming/outgoing payments within this channel, as well as
190158
// payments requested by the wallet/daemon.
@@ -1283,7 +1251,7 @@ type LightningChannel struct {
12831251
// the commitment transaction that spends the multi-sig output.
12841252
signDesc *input.SignDescriptor
12851253

1286-
status channelState
1254+
isClosed bool
12871255

12881256
// ChanPoint is the funding outpoint of this channel.
12891257
ChanPoint *wire.OutPoint
@@ -1538,7 +1506,7 @@ func (lc *LightningChannel) createSignDesc() error {
15381506
// events do so properly.
15391507
func (lc *LightningChannel) ResetState() {
15401508
lc.Lock()
1541-
lc.status = channelOpen
1509+
lc.isClosed = false
15421510
lc.Unlock()
15431511
}
15441512

@@ -7593,9 +7561,8 @@ func (lc *LightningChannel) ForceClose() (*LocalForceCloseSummary, error) {
75937561
"summary: %w", err)
75947562
}
75957563

7596-
// Set the channel state to indicate that the channel is now in a
7597-
// contested state.
7598-
lc.status = channelDispute
7564+
// Mark the channel as closed to block future closure requests.
7565+
lc.isClosed = true
75997566

76007567
return summary, nil
76017568
}
@@ -7789,8 +7756,8 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
77897756
lc.Lock()
77907757
defer lc.Unlock()
77917758

7792-
// If we've already closed the channel, then ignore this request.
7793-
if lc.status == channelClosed {
7759+
// If we're already closing the channel, then ignore this request.
7760+
if lc.isClosed {
77947761
// TODO(roasbeef): check to ensure no pending payments
77957762
return nil, nil, 0, ErrChanClosing
77967763
}
@@ -7853,10 +7820,6 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
78537820
}
78547821
}
78557822

7856-
// As everything checks out, indicate in the channel status that a
7857-
// channel closure has been initiated.
7858-
lc.status = channelClosing
7859-
78607823
closeTXID := closeTx.TxHash()
78617824
return sig, &closeTXID, ourBalance, nil
78627825
}
@@ -7877,8 +7840,8 @@ func (lc *LightningChannel) CompleteCooperativeClose(
78777840
lc.Lock()
78787841
defer lc.Unlock()
78797842

7880-
// If the channel is already closed, then ignore this request.
7881-
if lc.status == channelClosed {
7843+
// If the channel is already closing, then ignore this request.
7844+
if lc.isClosed {
78827845
// TODO(roasbeef): check to ensure no pending payments
78837846
return nil, 0, ErrChanClosing
78847847
}
@@ -7982,7 +7945,7 @@ func (lc *LightningChannel) CompleteCooperativeClose(
79827945
// As the transaction is sane, and the scripts are valid we'll mark the
79837946
// channel now as closed as the closure transaction should get into the
79847947
// chain in a timely manner and possibly be re-broadcast by the wallet.
7985-
lc.status = channelClosed
7948+
lc.isClosed = true
79867949

79877950
return closeTx, ourBalance, nil
79887951
}

lnwallet/channel_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2147,8 +2147,8 @@ func TestCooperativeCloseDustAdherence(t *testing.T) {
21472147
}
21482148

21492149
resetChannelState := func() {
2150-
aliceChannel.status = channelOpen
2151-
bobChannel.status = channelOpen
2150+
aliceChannel.ResetState()
2151+
bobChannel.ResetState()
21522152
}
21532153

21542154
setBalances := func(aliceBalance, bobBalance lnwire.MilliSatoshi) {

0 commit comments

Comments
 (0)