From 739f82e43ad3945dcec5e529617d8860cd8beedf Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 10 Jun 2024 19:56:50 -0700 Subject: [PATCH] lnwallet: pass tap leaf through in NewLocalForceCloseSummary Before this commit, the leaf wasn't yet passed in on force close. This is needed to detect the force close outputs properly. --- lnwallet/channel.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index fbbf27cc4..5f066eb23 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -8182,14 +8182,29 @@ func NewLocalForceCloseSummary(chanState *channeldb.OpenChannel, &chanState.LocalChanCfg, &chanState.RemoteChanCfg, ) + localCommit := chanState.LocalCommitment + + // If we have a custom blob, then we'll attempt to fetch the aux leaves + // for this state. + auxLeaves, err := AuxLeavesFromCommit( + chanState, localCommit, leafStore, *keyRing, + ) + if err != nil { + return nil, fmt.Errorf("unable to fetch aux leaves: %w", err) + } + var leaseExpiry uint32 if chanState.ChanType.HasLeaseExpiration() { leaseExpiry = chanState.ThawHeight } + + localAuxLeaf := fn.MapOption(func(l CommitAuxLeaves) input.AuxTapLeaf { + return l.LocalAuxLeaf + })(auxLeaves) toLocalScript, err := CommitScriptToSelf( chanState.ChanType, chanState.IsInitiator, keyRing.ToLocalKey, keyRing.RevocationKey, csvTimeout, leaseExpiry, - input.NoneTapLeaf(), + fn.FlattenOption(localAuxLeaf), ) if err != nil { return nil, err @@ -8303,15 +8318,6 @@ func NewLocalForceCloseSummary(chanState *channeldb.OpenChannel, // outgoing HTLC's that we'll need to claim as well. If this is after // recovery there is not much we can do with HTLCs, so we'll always // use what we have in our latest state when extracting resolutions. - localCommit := chanState.LocalCommitment - - auxLeaves, err := AuxLeavesFromCommit( - chanState, localCommit, leafStore, *keyRing, - ) - if err != nil { - return nil, fmt.Errorf("unable to fetch aux leaves: %w", err) - } - htlcResolutions, err := extractHtlcResolutions( chainfee.SatPerKWeight(localCommit.FeePerKw), true, signer, localCommit.Htlcs, keyRing, &chanState.LocalChanCfg,