Skip to content

Commit 9dfbde7

Browse files
committed
lnwallet: thread thru input.AuxTapleaf to all relevant areas
In this commit, we start to thread thru the new aux tap leaf structures to all relevant areas. This includes: commitment outputs, resolution creation, breach handling, and also HTLC scripts.
1 parent 2ab22b0 commit 9dfbde7

File tree

6 files changed

+345
-76
lines changed

6 files changed

+345
-76
lines changed

contractcourt/chain_watcher.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,36 @@ func (c *chainWatcher) handleUnknownLocalState(
426426
&c.cfg.chanState.LocalChanCfg, &c.cfg.chanState.RemoteChanCfg,
427427
)
428428

429+
auxResult, err := fn.MapOptionZ(
430+
c.cfg.auxLeafStore,
431+
//nolint:lll
432+
func(s lnwallet.AuxLeafStore) fn.Result[lnwallet.CommitDiffAuxResult] {
433+
return s.FetchLeavesFromCommit(
434+
lnwallet.NewAuxChanState(c.cfg.chanState),
435+
c.cfg.chanState.LocalCommitment, *commitKeyRing,
436+
)
437+
},
438+
).Unpack()
439+
if err != nil {
440+
return false, fmt.Errorf("unable to fetch aux leaves: %w", err)
441+
}
442+
429443
// With the keys derived, we'll construct the remote script that'll be
430444
// present if they have a non-dust balance on the commitment.
431445
var leaseExpiry uint32
432446
if c.cfg.chanState.ChanType.HasLeaseExpiration() {
433447
leaseExpiry = c.cfg.chanState.ThawHeight
434448
}
449+
450+
remoteAuxLeaf := fn.ChainOption(
451+
func(l lnwallet.CommitAuxLeaves) input.AuxTapLeaf {
452+
return l.RemoteAuxLeaf
453+
},
454+
)(auxResult.AuxLeaves)
435455
remoteScript, _, err := lnwallet.CommitScriptToRemote(
436456
c.cfg.chanState.ChanType, c.cfg.chanState.IsInitiator,
437-
commitKeyRing.ToRemoteKey, leaseExpiry, input.NoneTapLeaf(),
457+
commitKeyRing.ToRemoteKey, leaseExpiry,
458+
remoteAuxLeaf,
438459
)
439460
if err != nil {
440461
return false, err
@@ -443,11 +464,16 @@ func (c *chainWatcher) handleUnknownLocalState(
443464
// Next, we'll derive our script that includes the revocation base for
444465
// the remote party allowing them to claim this output before the CSV
445466
// delay if we breach.
467+
localAuxLeaf := fn.ChainOption(
468+
func(l lnwallet.CommitAuxLeaves) input.AuxTapLeaf {
469+
return l.LocalAuxLeaf
470+
},
471+
)(auxResult.AuxLeaves)
446472
localScript, err := lnwallet.CommitScriptToSelf(
447473
c.cfg.chanState.ChanType, c.cfg.chanState.IsInitiator,
448474
commitKeyRing.ToLocalKey, commitKeyRing.RevocationKey,
449475
uint32(c.cfg.chanState.LocalChanCfg.CsvDelay), leaseExpiry,
450-
input.NoneTapLeaf(),
476+
localAuxLeaf,
451477
)
452478
if err != nil {
453479
return false, err

input/size_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ func genTimeoutTx(t *testing.T,
13881388
// Create the unsigned timeout tx.
13891389
timeoutTx, err := lnwallet.CreateHtlcTimeoutTx(
13901390
chanType, false, testOutPoint, testAmt, testCLTVExpiry,
1391-
testCSVDelay, 0, testPubkey, testPubkey,
1391+
testCSVDelay, 0, testPubkey, testPubkey, input.NoneTapLeaf(),
13921392
)
13931393
require.NoError(t, err)
13941394

@@ -1457,7 +1457,7 @@ func genSuccessTx(t *testing.T, chanType channeldb.ChannelType) *wire.MsgTx {
14571457
// Create the unsigned success tx.
14581458
successTx, err := lnwallet.CreateHtlcSuccessTx(
14591459
chanType, false, testOutPoint, testAmt, testCSVDelay, 0,
1460-
testPubkey, testPubkey,
1460+
testPubkey, testPubkey, input.NoneTapLeaf(),
14611461
)
14621462
require.NoError(t, err)
14631463

0 commit comments

Comments
 (0)