@@ -1226,7 +1226,7 @@ func collectOutputs(a *Allocation,
12261226func createSecondLevelHtlcAllocations (chanType channeldb.ChannelType ,
12271227 initiator bool , htlcOutputs []* cmsg.AssetOutput , htlcAmt btcutil.Amount ,
12281228 commitCsvDelay uint32 , keys lnwallet.CommitmentKeyRing ,
1229- outputIndex fn.Option [uint32 ],
1229+ outputIndex fn.Option [uint32 ], htlcTimeout fn. Option [ uint32 ],
12301230) ([]* Allocation , error ) {
12311231
12321232 // TODO(roasbeef): thaw height not implemented for taproot chans rn
@@ -1267,6 +1267,8 @@ func createSecondLevelHtlcAllocations(chanType channeldb.ChannelType,
12671267 SortTaprootKeyBytes : schnorr .SerializePubKey (
12681268 htlcTree .TaprootKey ,
12691269 ),
1270+ // TODO(roasbeef): don't need it here?
1271+ CLTV : htlcTimeout .UnwrapOr (0 ),
12701272 }}
12711273
12721274 return allocations , nil
@@ -1277,14 +1279,13 @@ func createSecondLevelHtlcAllocations(chanType channeldb.ChannelType,
12771279func CreateSecondLevelHtlcPackets (chanState lnwallet.AuxChanState ,
12781280 commitTx * wire.MsgTx , htlcAmt btcutil.Amount ,
12791281 keys lnwallet.CommitmentKeyRing , chainParams * address.ChainParams ,
1280- htlcOutputs []* cmsg.AssetOutput ) ([] * tappsbt. VPacket , [] * Allocation ,
1281- error ) {
1282+ htlcOutputs []* cmsg.AssetOutput , htlcTimeout fn. Option [ uint32 ] ,
1283+ ) ([] * tappsbt. VPacket , [] * Allocation , error ) {
12821284
12831285 allocations , err := createSecondLevelHtlcAllocations (
12841286 chanState .ChanType , chanState .IsInitiator ,
1285- htlcOutputs , htlcAmt ,
1286- uint32 (chanState .LocalChanCfg .CsvDelay ), keys ,
1287- fn .None [uint32 ](),
1287+ htlcOutputs , htlcAmt , uint32 (chanState .LocalChanCfg .CsvDelay ),
1288+ keys , fn .None [uint32 ](), htlcTimeout ,
12881289 )
12891290 if err != nil {
12901291 return nil , nil , err
@@ -1303,6 +1304,15 @@ func CreateSecondLevelHtlcPackets(chanState lnwallet.AuxChanState,
13031304 return nil , nil , fmt .Errorf ("error distributing coins: %w" , err )
13041305 }
13051306
1307+ // If the HTLC timeout was present, then we'll also manually add it as a
1308+ // param to the vOut here, as it's just used for sorting with
1309+ // allocations.
1310+ for _ , vPkt := range vPackets {
1311+ for _ , o := range vPkt .Outputs {
1312+ o .LockTime = uint64 (htlcTimeout .UnwrapOr (0 ))
1313+ }
1314+ }
1315+
13061316 ctx := context .Background ()
13071317 for idx := range vPackets {
13081318 err := tapsend .PrepareOutputAssets (ctx , vPackets [idx ])
@@ -1320,12 +1330,13 @@ func CreateSecondLevelHtlcPackets(chanState lnwallet.AuxChanState,
13201330func CreateSecondLevelHtlcTx (chanState lnwallet.AuxChanState ,
13211331 commitTx * wire.MsgTx , htlcAmt btcutil.Amount ,
13221332 keys lnwallet.CommitmentKeyRing , chainParams * address.ChainParams ,
1323- htlcOutputs []* cmsg.AssetOutput ) (input.AuxTapLeaf , error ) {
1333+ htlcOutputs []* cmsg.AssetOutput , htlcTimeout fn.Option [uint32 ],
1334+ ) (input.AuxTapLeaf , error ) {
13241335
13251336 none := input .NoneTapLeaf ()
13261337
13271338 vPackets , allocations , err := CreateSecondLevelHtlcPackets (
1328- chanState , commitTx , htlcAmt , keys , chainParams , htlcOutputs ,
1339+ chanState , commitTx , htlcAmt , keys , chainParams , htlcOutputs , htlcTimeout ,
13291340 )
13301341 if err != nil {
13311342 return none , fmt .Errorf ("error creating second level HTLC " +
@@ -1353,6 +1364,7 @@ func CreateSecondLevelHtlcTx(chanState lnwallet.AuxChanState,
13531364 if err != nil {
13541365 return none , fmt .Errorf ("error creating aux leaf: %w" , err )
13551366 }
1367+
13561368 return lfn .Some (auxLeaf ), nil
13571369}
13581370
0 commit comments