contractcourt: ignore all other dispatch cases in closeObserver when recovered chan

In this commit, we modify the `closeObserver` to fast path the DLP
dispatch case if we detect that the channel has been restored. We do
this as otherwise, we may inadvertently enter one of the other cases
erroneously, causing us to now properly look up their dlp commitment
point.
This commit is contained in:
Olaoluwa Osuntokun 2019-03-10 17:47:06 -07:00
parent c722f2c064
commit 26f6fd7db2
No known key found for this signature in database
GPG Key ID: CE58F7F8E20FD9A2
2 changed files with 22 additions and 21 deletions

@ -386,12 +386,12 @@ func (c *chainWatcher) closeObserver(spendNtfn *chainntnfs.SpendEvent) {
} }
switch { switch {
// If state number spending transaction matches the // If state number spending transaction matches the current
// current latest state, then they've initiated a // latest state, then they've initiated a unilateral close. So
// unilateral close. So we'll trigger the unilateral // we'll trigger the unilateral close signal so subscribers can
// close signal so subscribers can clean up the state // clean up the state as necessary.
// as necessary. case broadcastStateNum == remoteStateNum && !isRecoveredChan:
case broadcastStateNum == remoteStateNum:
err := c.dispatchRemoteForceClose( err := c.dispatchRemoteForceClose(
commitSpend, *remoteCommit, commitSpend, *remoteCommit,
c.cfg.chanState.RemoteCurrentRevocation, c.cfg.chanState.RemoteCurrentRevocation,
@ -402,14 +402,13 @@ func (c *chainWatcher) closeObserver(spendNtfn *chainntnfs.SpendEvent) {
c.cfg.chanState.FundingOutpoint, err) c.cfg.chanState.FundingOutpoint, err)
} }
// We'll also handle the case of the remote party // We'll also handle the case of the remote party broadcasting
// broadcasting their commitment transaction which is // their commitment transaction which is one height above ours.
// one height above ours. This case can arise when we // This case can arise when we initiate a state transition, but
// initiate a state transition, but the remote party // the remote party has a fail crash _after_ accepting the new
// has a fail crash _after_ accepting the new state, // state, but _before_ sending their signature to us.
// but _before_ sending their signature to us.
case broadcastStateNum == remoteStateNum+1 && case broadcastStateNum == remoteStateNum+1 &&
remoteChainTip != nil: remoteChainTip != nil && !isRecoveredChan:
err := c.dispatchRemoteForceClose( err := c.dispatchRemoteForceClose(
commitSpend, remoteChainTip.Commitment, commitSpend, remoteChainTip.Commitment,
@ -425,8 +424,12 @@ func (c *chainWatcher) closeObserver(spendNtfn *chainntnfs.SpendEvent) {
// known state for them, and they don't have a pending // known state for them, and they don't have a pending
// commitment (we write them to disk before sending out), then // commitment (we write them to disk before sending out), then
// this means that we've lost data. In this case, we'll enter // this means that we've lost data. In this case, we'll enter
// the DLP protocol. // the DLP protocol. Otherwise, if we've recovered our channel
case broadcastStateNum > remoteStateNum: // state from scratch, then we don't know what the precise
// current state is, so we assume either the remote party
// forced closed or we've been breached. In the latter case,
// our tower will take care of us.
case broadcastStateNum > remoteStateNum || isRecoveredChan:
log.Warnf("Remote node broadcast state #%v, "+ log.Warnf("Remote node broadcast state #%v, "+
"which is more than 1 beyond best known "+ "which is more than 1 beyond best known "+
"state #%v!!! Attempting recovery...", "state #%v!!! Attempting recovery...",

@ -2436,8 +2436,6 @@ func (r *rpcServer) ListChannels(ctx context.Context,
resp := &lnrpc.ListChannelsResponse{} resp := &lnrpc.ListChannelsResponse{}
// TODO(roasbeef): expose chan status flags as well
graph := r.server.chanDB.ChannelGraph() graph := r.server.chanDB.ChannelGraph()
dbChannels, err := r.server.chanDB.FetchAllOpenChannels() dbChannels, err := r.server.chanDB.FetchAllOpenChannels()
@ -4686,17 +4684,17 @@ func (r *rpcServer) ForwardingHistory(ctx context.Context,
// once lnd is running, or via the InitWallet and UnlockWallet methods from the // once lnd is running, or via the InitWallet and UnlockWallet methods from the
// WalletUnlocker service. // WalletUnlocker service.
func (r *rpcServer) ExportChannelBackup(ctx context.Context, func (r *rpcServer) ExportChannelBackup(ctx context.Context,
in *lnrpc.ChannelPoint) (*lnrpc.ChannelBackup, error) { in *lnrpc.ExportChannelBackupRequest) (*lnrpc.ChannelBackup, error) {
// First, we'll convert the lnrpc channel point into a wire.OutPoint // First, we'll convert the lnrpc channel point into a wire.OutPoint
// that we can manipulate. // that we can manipulate.
txid, err := getChanPointFundingTxid(in) txid, err := getChanPointFundingTxid(in.ChanPoint)
if err != nil { if err != nil {
return nil, err return nil, err
} }
chanPoint := wire.OutPoint{ chanPoint := wire.OutPoint{
Hash: *txid, Hash: *txid,
Index: in.OutputIndex, Index: in.ChanPoint.OutputIndex,
} }
// Next, we'll attempt to fetch a channel backup for this channel from // Next, we'll attempt to fetch a channel backup for this channel from
@ -4730,7 +4728,7 @@ func (r *rpcServer) ExportChannelBackup(ctx context.Context,
} }
return &lnrpc.ChannelBackup{ return &lnrpc.ChannelBackup{
ChanPoint: in, ChanPoint: in.ChanPoint,
ChanBackup: packedBackup, ChanBackup: packedBackup,
}, nil }, nil
} }