Skip to content

Commit

Permalink
lnwallet: thread thru input.AuxTapleaf to all relevant areas
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guggero committed Apr 29, 2024
1 parent 918f11f commit 11f3626
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 72 deletions.
24 changes: 22 additions & 2 deletions contractcourt/chain_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,30 @@ func (c *chainWatcher) handleUnknownLocalState(
&c.cfg.chanState.LocalChanCfg, &c.cfg.chanState.RemoteChanCfg,
)

auxLeaves, err := lnwallet.AuxLeavesFromCommit(
c.cfg.chanState, c.cfg.chanState.LocalCommitment,
c.cfg.auxLeafStore, *commitKeyRing,
)
if err != nil {
return false, fmt.Errorf("unable to fetch aux leaves: %w", err)
}

// With the keys derived, we'll construct the remote script that'll be
// present if they have a non-dust balance on the commitment.
var leaseExpiry uint32
if c.cfg.chanState.ChanType.HasLeaseExpiration() {
leaseExpiry = c.cfg.chanState.ThawHeight
}

remoteAuxLeaf := fn.MapOption(
func(l lnwallet.CommitAuxLeaves) input.AuxTapLeaf {
return l.RemoteAuxLeaf
},
)(auxLeaves)
remoteScript, _, err := lnwallet.CommitScriptToRemote(
c.cfg.chanState.ChanType, c.cfg.chanState.IsInitiator,
commitKeyRing.ToRemoteKey, leaseExpiry, input.NoneTapLeaf(),
commitKeyRing.ToRemoteKey, leaseExpiry,
fn.FlattenOption(remoteAuxLeaf),
)
if err != nil {
return false, err
Expand All @@ -441,11 +456,16 @@ func (c *chainWatcher) handleUnknownLocalState(
// Next, we'll derive our script that includes the revocation base for
// the remote party allowing them to claim this output before the CSV
// delay if we breach.
localAuxLeaf := fn.MapOption(
func(l lnwallet.CommitAuxLeaves) input.AuxTapLeaf {
return l.LocalAuxLeaf
},
)(auxLeaves)
localScript, err := lnwallet.CommitScriptToSelf(
c.cfg.chanState.ChanType, c.cfg.chanState.IsInitiator,
commitKeyRing.ToLocalKey, commitKeyRing.RevocationKey,
uint32(c.cfg.chanState.LocalChanCfg.CsvDelay), leaseExpiry,
input.NoneTapLeaf(),
fn.FlattenOption(localAuxLeaf),
)
if err != nil {
return false, err
Expand Down
4 changes: 2 additions & 2 deletions input/size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ func genTimeoutTx(t *testing.T,
// Create the unsigned timeout tx.
timeoutTx, err := lnwallet.CreateHtlcTimeoutTx(
chanType, false, testOutPoint, testAmt, testCLTVExpiry,
testCSVDelay, 0, testPubkey, testPubkey,
testCSVDelay, 0, testPubkey, testPubkey, input.NoneTapLeaf(),
)
require.NoError(t, err)

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

Expand Down

0 comments on commit 11f3626

Please sign in to comment.