From 3825ca71dd7ee72944c584f1092747148d94b365 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 12 Jul 2018 11:02:52 +0200 Subject: [PATCH] lnwallet/channel: reduce scope of commitSecretCorrect --- lnwallet/channel.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index f8a182bb2..8ece0533e 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -3138,7 +3138,6 @@ func (lc *LightningChannel) ProcessChanSyncMsg( // If the remote party included the optional fields, then we'll verify // their correctness first, as it will influence our decisions below. hasRecoveryOptions := msg.LocalUnrevokedCommitPoint != nil - commitSecretCorrect := true if hasRecoveryOptions && msg.RemoteCommitTailHeight != 0 { // We'll check that they've really sent a valid commit // secret from our shachain for our prior height, but only if @@ -3149,22 +3148,25 @@ func (lc *LightningChannel) ProcessChanSyncMsg( if err != nil { return nil, nil, nil, err } - commitSecretCorrect = bytes.Equal( + commitSecretCorrect := bytes.Equal( heightSecret[:], msg.LastRemoteCommitSecret[:], ) + + // If the commit secret they sent is incorrect then we'll fail + // the channel as the remote node has an inconsistent state. + if !commitSecretCorrect { + // In this case, we'll return an error to indicate the + // remote node sent us the wrong values. This will let + // the caller act accordingly. + walletLog.Errorf("ChannelPoint(%v), sync failed: "+ + "remote provided invalid commit secret!", + lc.channelState.FundingOutpoint) + return nil, nil, nil, ErrInvalidLastCommitSecret + } } // TODO(roasbeef): check validity of commitment point after the fact - // If the commit secret they sent is incorrect then we'll fail the - // channel as the remote node has an inconsistent state. - if !commitSecretCorrect { - // In this case, we'll return an error to indicate the remote - // node sent us the wrong values. This will let the caller act - // accordingly. - return nil, nil, nil, ErrInvalidLastCommitSecret - } - switch { // If we owe the remote party a revocation message, then we'll re-send // the last revocation message that we sent. This will be the @@ -3213,9 +3215,9 @@ func (lc *LightningChannel) ProcessChanSyncMsg( // If we don't owe the remote party a revocation, but their value for // what our remote chain tail should be doesn't match up, and their - // purported commitment secrete matches up, then we'll behind! - case (msg.RemoteCommitTailHeight > localChainTail.height && - hasRecoveryOptions && commitSecretCorrect): + // purported commitment secrete matches up, then we're behind! + case msg.RemoteCommitTailHeight > localChainTail.height && + hasRecoveryOptions: // In this case, we've likely lost data and shouldn't proceed // with channel updates. So we'll return the appropriate error