From 9c3218c51e8cc27bfcccd47018caaf72b1be4464 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Mon, 6 Jan 2020 11:42:05 +0100 Subject: [PATCH] lnwallet/channel: reuse derived SingleTweak on local force close When creating the keyring, the tweak is already calculated in the remote commitment case. We add the calculation also for our own commitment, so we can use it in all cases without deriving the tweak. --- lnwallet/channel.go | 5 +---- lnwallet/commitment.go | 9 ++++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index ff2228b4..fbb58d0c 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -5436,9 +5436,6 @@ func NewLocalForceCloseSummary(chanState *channeldb.OpenChannel, signer input.Si // nil. var commitResolution *CommitOutputResolution if len(delayScript) != 0 { - singleTweak := input.SingleTweakBytes( - commitPoint, chanState.LocalChanCfg.DelayBasePoint.PubKey, - ) localBalance := localCommit.LocalBalance commitResolution = &CommitOutputResolution{ SelfOutPoint: wire.OutPoint{ @@ -5447,7 +5444,7 @@ func NewLocalForceCloseSummary(chanState *channeldb.OpenChannel, signer input.Si }, SelfOutputSignDesc: input.SignDescriptor{ KeyDesc: chanState.LocalChanCfg.DelayBasePoint, - SingleTweak: singleTweak, + SingleTweak: keyRing.LocalCommitKeyTweak, WitnessScript: selfScript, Output: &wire.TxOut{ PkScript: delayScript, diff --git a/lnwallet/commitment.go b/lnwallet/commitment.go index 67b5cbc1..459dd83b 100644 --- a/lnwallet/commitment.go +++ b/lnwallet/commitment.go @@ -96,13 +96,20 @@ func DeriveCommitmentKeys(commitPoint *btcec.PublicKey, tweaklessCommit := chanType.IsTweakless() + // Depending on if this is our commit or not, we'll choose the correct + // base point. + localBasePoint := localChanCfg.PaymentBasePoint + if isOurCommit { + localBasePoint = localChanCfg.DelayBasePoint + } + // First, we'll derive all the keys that don't depend on the context of // whose commitment transaction this is. keyRing := &CommitmentKeyRing{ CommitPoint: commitPoint, LocalCommitKeyTweak: input.SingleTweakBytes( - commitPoint, localChanCfg.PaymentBasePoint.PubKey, + commitPoint, localBasePoint.PubKey, ), LocalHtlcKeyTweak: input.SingleTweakBytes( commitPoint, localChanCfg.HtlcBasePoint.PubKey,