mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
contractcourt: move responsibility for closing force closes to chanArb
This commit moves the responsibility for closing local and remote force closes in the database from the chain watcher to the channel arbitrator. We do this because we previously would close the channel in the database, before sending the event to the channel arbitrator. This could lead to a situation where the channel was marked closed, but the channel arbitrator didn't receive the event before shutdown. As we don't listen for chain events for channels that are closed, those channels would be stuck in the pending close state forever, as the channel arbitrator state machine wouldn't progress. We fix this by letting the ChannelArbitrator close the channel in the database. After the contract resolutions are logged (in the state callback before transitioning to StateContractClosed) we mark the channel closed in the database. This way we make sure that it is marked closed only if the resolutions have been successfully persisted.
This commit is contained in:
@@ -1438,6 +1438,25 @@ func (c *ChannelArbitrator) channelAttendant(bestHeight int32) {
|
||||
return
|
||||
}
|
||||
|
||||
// After the set of resolutions are successfully
|
||||
// logged, we can safely close the channel. After this
|
||||
// succeeds we won't be getting chain events anymore,
|
||||
// so we must make sure we can recover on restart after
|
||||
// it is marked closed. If the next state transation
|
||||
// fails, we'll start up in the prior state again, and
|
||||
// we won't be longer getting chain events. In this
|
||||
// case we must manually re-trigger the state
|
||||
// transition into StateContractClosed based on the
|
||||
// close status of the channel.
|
||||
err = c.cfg.MarkChannelClosed(
|
||||
closeInfo.ChannelCloseSummary,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("unable to mark "+
|
||||
"channel closed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// We'll now advance our state machine until it reaches
|
||||
// a terminal state.
|
||||
_, _, err = c.advanceState(
|
||||
@@ -1482,6 +1501,24 @@ func (c *ChannelArbitrator) channelAttendant(bestHeight int32) {
|
||||
return
|
||||
}
|
||||
|
||||
// After the set of resolutions are successfully
|
||||
// logged, we can safely close the channel. After this
|
||||
// succeeds we won't be getting chain events anymore,
|
||||
// so we must make sure we can recover on restart after
|
||||
// it is marked closed. If the next state transation
|
||||
// fails, we'll start up in the prior state again, and
|
||||
// we won't be longer getting chain events. In this
|
||||
// case we must manually re-trigger the state
|
||||
// transition into StateContractClosed based on the
|
||||
// close status of the channel.
|
||||
closeSummary := &uniClosure.ChannelCloseSummary
|
||||
err = c.cfg.MarkChannelClosed(closeSummary)
|
||||
if err != nil {
|
||||
log.Errorf("unable to mark channel closed: %v",
|
||||
err)
|
||||
return
|
||||
}
|
||||
|
||||
// We'll now advance our state machine until it reaches
|
||||
// a terminal state.
|
||||
_, _, err = c.advanceState(
|
||||
|
Reference in New Issue
Block a user