From f92c7a3af05d7b704b2ccb2d56679597aa9b0c76 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Mon, 6 Jan 2020 11:42:04 +0100 Subject: [PATCH] lnwallet: nil single tweak when creating keyring To make the channel state machine less concerned about the type of commitment, we nil the local tweak when creating the keyring, depending on the commitment type. --- lnwallet/channel.go | 14 -------------- lnwallet/commitment.go | 7 +++++++ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index c0743ea0..a8bde14e 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1929,13 +1929,6 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64, }, HashType: txscript.SigHashAll, } - - // If this is a tweakless commitment, then we can safely blank - // out the SingleTweak value as it isn't needed. - tweaklessCommit := chanState.ChanType.IsTweakless() - if tweaklessCommit { - localSignDesc.SingleTweak = nil - } } // Similarly, if the remote balance exceeds the remote party's dust @@ -4807,13 +4800,6 @@ func NewUnilateralCloseSummary(chanState *channeldb.OpenChannel, signer input.Si }, MaturityDelay: 0, } - - // If this is a tweakless commitment, then we can safely blank - // out the SingleTweak value as it isn't needed. - tweaklessCommit := chanState.ChanType.IsTweakless() - if tweaklessCommit { - commitResolution.SelfOutputSignDesc.SingleTweak = nil - } } closeSummary := channeldb.ChannelCloseSummary{ diff --git a/lnwallet/commitment.go b/lnwallet/commitment.go index 99f57768..59f5f197 100644 --- a/lnwallet/commitment.go +++ b/lnwallet/commitment.go @@ -146,6 +146,13 @@ func DeriveCommitmentKeys(commitPoint *btcec.PublicKey, // we'll use that directly, and ignore the commitPoint tweak. if tweaklessCommit { keyRing.ToRemoteKey = toRemoteBasePoint + + // If this is not our commitment, the above ToRemoteKey will be + // ours, and we blank out the local commitment tweak to + // indicate that the key should not be tweaked when signing. + if !isOurCommit { + keyRing.LocalCommitKeyTweak = nil + } } else { keyRing.ToRemoteKey = input.TweakPubKey( toRemoteBasePoint, commitPoint,