From ef520f49c310bd91d0ec8f04e950cadae05a0fe7 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 11 Dec 2017 15:42:00 -0800 Subject: [PATCH] lnwallet: during channel resynchronization detect lack of commitment window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we extend the ProcessChanSyncMsg to detect a case where we don’t have the necessary revocation window to send out a new commit. This can arise if the remote party sends us a new state, but we haven’t yet fully processed their FundingLocked message yet, so we would be unable to create a new commitment state. We fix this by enumerating each of our actions in the case of an error. If we get ErrNoWindow, then this indicates that we can’t give the remote party the commitment we would like to optimistically send over. This isn’t an issue though, as in the next round, we’ll resynchronize our state. --- lnwallet/channel.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 44974507a..d14fea1d7 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -3161,16 +3161,30 @@ func (lc *LightningChannel) ProcessChanSyncMsg(msg *lnwire.ChannelReestablish) ( lc.remoteCommitChain.tip().height { commitSig, htlcSigs, err := lc.SignNextCommitment() - if err != nil { + switch { + + // If we signed this state, then we'll accumulate + // another update to send over. + case err == nil: + updates = append(updates, &lnwire.CommitSig{ + ChanID: lnwire.NewChanIDFromOutPoint( + &lc.channelState.FundingOutpoint, + ), + CommitSig: commitSig, + HtlcSigs: htlcSigs, + }) + + // If we get a failure due to not knowing their next + // point, then this is fine as they'll either send + // FundingLocked, or revoke their next state to allow + // us to continue forwards. + case err == ErrNoWindow: + + // Otherwise, this is an error and we'll treat it as + // such. + default: return nil, err } - updates = append(updates, &lnwire.CommitSig{ - ChanID: lnwire.NewChanIDFromOutPoint( - &lc.channelState.FundingOutpoint, - ), - CommitSig: commitSig, - HtlcSigs: htlcSigs, - }) } // If we don't owe the remote party a revocation, but their value for