Skip to content

Commit 72f7b80

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 33f2db1 commit 72f7b80

File tree

6 files changed

+298
-72
lines changed

6 files changed

+298
-72
lines changed

contractcourt/chain_watcher.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,15 +424,30 @@ func (c *chainWatcher) handleUnknownLocalState(
424424
&c.cfg.chanState.LocalChanCfg, &c.cfg.chanState.RemoteChanCfg,
425425
)
426426

427+
auxLeaves, err := lnwallet.AuxLeavesFromCommit(
428+
c.cfg.chanState, c.cfg.chanState.LocalCommitment,
429+
c.cfg.auxLeafStore, *commitKeyRing,
430+
)
431+
if err != nil {
432+
return false, fmt.Errorf("unable to fetch aux leaves: %w", err)
433+
}
434+
427435
// With the keys derived, we'll construct the remote script that'll be
428436
// present if they have a non-dust balance on the commitment.
429437
var leaseExpiry uint32
430438
if c.cfg.chanState.ChanType.HasLeaseExpiration() {
431439
leaseExpiry = c.cfg.chanState.ThawHeight
432440
}
441+
442+
remoteAuxLeaf := fn.MapOption(
443+
func(l lnwallet.CommitAuxLeaves) input.AuxTapLeaf {
444+
return l.RemoteAuxLeaf
445+
},
446+
)(auxLeaves)
433447
remoteScript, _, err := lnwallet.CommitScriptToRemote(
434448
c.cfg.chanState.ChanType, c.cfg.chanState.IsInitiator,
435-
commitKeyRing.ToRemoteKey, leaseExpiry, input.NoneTapLeaf(),
449+
commitKeyRing.ToRemoteKey, leaseExpiry,
450+
fn.FlattenOption(remoteAuxLeaf),
436451
)
437452
if err != nil {
438453
return false, err
@@ -441,11 +456,16 @@ func (c *chainWatcher) handleUnknownLocalState(
441456
// Next, we'll derive our script that includes the revocation base for
442457
// the remote party allowing them to claim this output before the CSV
443458
// delay if we breach.
459+
localAuxLeaf := fn.MapOption(
460+
func(l lnwallet.CommitAuxLeaves) input.AuxTapLeaf {
461+
return l.LocalAuxLeaf
462+
},
463+
)(auxLeaves)
444464
localScript, err := lnwallet.CommitScriptToSelf(
445465
c.cfg.chanState.ChanType, c.cfg.chanState.IsInitiator,
446466
commitKeyRing.ToLocalKey, commitKeyRing.RevocationKey,
447467
uint32(c.cfg.chanState.LocalChanCfg.CsvDelay), leaseExpiry,
448-
input.NoneTapLeaf(),
468+
fn.FlattenOption(localAuxLeaf),
449469
)
450470
if err != nil {
451471
return false, err

input/size_test.go

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

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

0 commit comments

Comments
 (0)