lnwallet/channel: exposes channelState via State for testing
This commit is contained in:
1 file changed
+17
-6
+17
-6
@@ -1208,7 +1208,8 @@ type LightningChannel struct {
|
|||||||
|
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
|
||||||
wg sync.WaitGroup
|
cowg sync.WaitGroup
|
||||||
|
wg sync.WaitGroup
|
||||||
|
|
||||||
shutdown int32
|
shutdown int32
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
@@ -1342,6 +1343,7 @@ func NewLightningChannel(signer Signer, events chainntnfs.ChainNotifier,
|
|||||||
// Launch the close observer which will vigilantly watch the
|
// Launch the close observer which will vigilantly watch the
|
||||||
// network for any broadcasts the current or prior commitment
|
// network for any broadcasts the current or prior commitment
|
||||||
// transactions, taking action accordingly.
|
// transactions, taking action accordingly.
|
||||||
|
lc.cowg.Add(1)
|
||||||
go lc.closeObserver(channelCloseNtfn)
|
go lc.closeObserver(channelCloseNtfn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1376,6 +1378,11 @@ func (lc *LightningChannel) CancelObserver() {
|
|||||||
close(lc.observerQuit)
|
close(lc.observerQuit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitForClose blocks until the channel's close observer has terminated.
|
||||||
|
func (lc *LightningChannel) WaitForClose() {
|
||||||
|
lc.cowg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
// ResetState resets the state of the channel back to the default state. This
|
// ResetState resets the state of the channel back to the default state. This
|
||||||
// ensures that any active goroutines which need to act based on on-chain
|
// ensures that any active goroutines which need to act based on on-chain
|
||||||
// events do so properly.
|
// events do so properly.
|
||||||
@@ -1962,6 +1969,8 @@ func newBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
|||||||
//
|
//
|
||||||
// NOTE: This MUST be run as a goroutine.
|
// NOTE: This MUST be run as a goroutine.
|
||||||
func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEvent) {
|
func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEvent) {
|
||||||
|
defer lc.cowg.Done()
|
||||||
|
|
||||||
walletLog.Infof("Close observer for ChannelPoint(%v) active",
|
walletLog.Infof("Close observer for ChannelPoint(%v) active",
|
||||||
lc.channelState.FundingOutpoint)
|
lc.channelState.FundingOutpoint)
|
||||||
|
|
||||||
@@ -2169,8 +2178,9 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven
|
|||||||
"broadcast!!!", lc.channelState.FundingOutpoint,
|
"broadcast!!!", lc.channelState.FundingOutpoint,
|
||||||
remoteStateNum)
|
remoteStateNum)
|
||||||
|
|
||||||
if err := lc.channelState.MarkBorked(true); err != nil {
|
if err := lc.channelState.MarkBorked(); err != nil {
|
||||||
walletLog.Errorf("unable to mark channel as borked: %v", err)
|
walletLog.Errorf("unable to mark channel as borked: %v",
|
||||||
|
err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2231,7 +2241,8 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven
|
|||||||
|
|
||||||
err = lc.DeleteState(&closeSummary)
|
err = lc.DeleteState(&closeSummary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
walletLog.Errorf("unable to delete channel state: %v", err)
|
walletLog.Errorf("unable to delete channel state: %v",
|
||||||
|
err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3271,7 +3282,7 @@ func (lc *LightningChannel) ProcessChanSyncMsg(msg *lnwire.ChannelReestablish) (
|
|||||||
// chain reported by the remote party is not equal to our chain tail,
|
// chain reported by the remote party is not equal to our chain tail,
|
||||||
// then we cannot sync.
|
// then we cannot sync.
|
||||||
case !oweRevocation && localChainTail.height != msg.RemoteCommitTailHeight:
|
case !oweRevocation && localChainTail.height != msg.RemoteCommitTailHeight:
|
||||||
if err := lc.channelState.MarkBorked(true); err != nil {
|
if err := lc.channelState.MarkBorked(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3303,7 +3314,7 @@ func (lc *LightningChannel) ProcessChanSyncMsg(msg *lnwire.ChannelReestablish) (
|
|||||||
} else if !oweCommitment && remoteChainTip.height+1 !=
|
} else if !oweCommitment && remoteChainTip.height+1 !=
|
||||||
msg.NextLocalCommitHeight {
|
msg.NextLocalCommitHeight {
|
||||||
|
|
||||||
if err := lc.channelState.MarkBorked(true); err != nil {
|
if err := lc.channelState.MarkBorked(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user