lnwallet/channel: reduce scope of commitSecretCorrect
This commit is contained in:
1 file changed
+16
-14
+16
-14
@@ -3138,7 +3138,6 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
|||||||
// If the remote party included the optional fields, then we'll verify
|
// If the remote party included the optional fields, then we'll verify
|
||||||
// their correctness first, as it will influence our decisions below.
|
// their correctness first, as it will influence our decisions below.
|
||||||
hasRecoveryOptions := msg.LocalUnrevokedCommitPoint != nil
|
hasRecoveryOptions := msg.LocalUnrevokedCommitPoint != nil
|
||||||
commitSecretCorrect := true
|
|
||||||
if hasRecoveryOptions && msg.RemoteCommitTailHeight != 0 {
|
if hasRecoveryOptions && msg.RemoteCommitTailHeight != 0 {
|
||||||
// We'll check that they've really sent a valid commit
|
// We'll check that they've really sent a valid commit
|
||||||
// secret from our shachain for our prior height, but only if
|
// secret from our shachain for our prior height, but only if
|
||||||
@@ -3149,22 +3148,25 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
commitSecretCorrect = bytes.Equal(
|
commitSecretCorrect := bytes.Equal(
|
||||||
heightSecret[:], msg.LastRemoteCommitSecret[:],
|
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
|
// 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 {
|
switch {
|
||||||
// If we owe the remote party a revocation message, then we'll re-send
|
// 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
|
// 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
|
// 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
|
// what our remote chain tail should be doesn't match up, and their
|
||||||
// purported commitment secrete matches up, then we'll behind!
|
// purported commitment secrete matches up, then we're behind!
|
||||||
case (msg.RemoteCommitTailHeight > localChainTail.height &&
|
case msg.RemoteCommitTailHeight > localChainTail.height &&
|
||||||
hasRecoveryOptions && commitSecretCorrect):
|
hasRecoveryOptions:
|
||||||
|
|
||||||
// In this case, we've likely lost data and shouldn't proceed
|
// In this case, we've likely lost data and shouldn't proceed
|
||||||
// with channel updates. So we'll return the appropriate error
|
// with channel updates. So we'll return the appropriate error
|
||||||
|
|||||||
Reference in new issue
Block a user