Skip to content

Commit 292993e

Browse files
committed
tapchannel: update registerAndBroadcastSweep for HTLC sweeps
In this commit, we update `registerAndBroadcastSweep` to be able to handle HTLC sweeps. First, we only need to set the anchor for first level sweeps. We weren't able to sign the 2nd level sweeps earlier as we didn't know the txid of the transaction that swept them. Now that we're about to broadcast, we know the sweeping transaction so we can set the prevID properly, then sign the sweeping transaction.
1 parent 7310bb3 commit 292993e

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

tapchannel/aux_sweeper.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,7 @@ func (a *AuxSweeper) resolveContract(
17181718
default:
17191719
return lfn.Errf[returnType]("unknown resolution type: %v",
17201720
req.Type)
1721+
// TODO(roasbeef): need to do HTLC revocation casesj:w
17211722
}
17221723

17231724
// The input proofs above were made originally using the fake commit tx
@@ -1951,6 +1952,7 @@ func prepVpkts(bRes lfn.Result[blobWithWitnessInfo],
19511952
// none of the inputs have any resolution blobs. Then an empty slice will be
19521953
// returned.
19531954
func extractInputVPackets(inputs []input.Input) lfn.Result[sweepVpkts] {
1955+
19541956
type returnType = sweepVpkts
19551957

19561958
// Otherwise, we'll extract the set of resolution blobs from the inputs
@@ -2179,7 +2181,8 @@ func (a *AuxSweeper) registerAndBroadcastSweep(req *sweep.BumpRequest,
21792181
internalKey.PubKey.SerializeCompressed())
21802182

21812183
// We'll also use the passed in context to set the anchor key again for
2182-
// all the vOuts.
2184+
// all the vOuts, but only for first level vPkts, as second level
2185+
// packets already commit to the internal key of the vOut.
21832186
for idx := range vPkts.firstLevelPkts() {
21842187
for _, vOut := range vPkts.firstLevelPkts()[idx].Outputs {
21852188
vOut.SetAnchorInternalKey(
@@ -2188,8 +2191,42 @@ func (a *AuxSweeper) registerAndBroadcastSweep(req *sweep.BumpRequest,
21882191
}
21892192
}
21902193

2194+
// For any second level outputs we're sweeping, we'll need to sign for
2195+
// it, as now we know the txid of the sweeping transaction.
2196+
for _, sweepSet := range vPkts.secondLevel {
2197+
for _, vPkt := range sweepSet.vPkts {
2198+
for _, vIn := range vPkt.Inputs {
2199+
vIn.PrevID.OutPoint = sweepSet.btcInput.OutPoint()
2200+
}
2201+
}
2202+
}
2203+
2204+
// If we have second level vPkts, then we'll need to sign them here, as
2205+
// now we know the input we're spending which was set above.
2206+
for _, sweepSet := range vPkts.secondLevel {
2207+
tapSigDesc, err := sweepSet.tapSigDesc.UnwrapOrErr(
2208+
fmt.Errorf("tap sig desc not populated"),
2209+
)
2210+
if err != nil {
2211+
return err
2212+
}
2213+
2214+
err = a.signSweepVpackets(
2215+
sweepSet.vPkts, *sweepSet.btcInput.SignDesc(),
2216+
tapSigDesc.TapTweak.Val, tapSigDesc.CtrlBlock.Val,
2217+
lfn.None[lnwallet.AuxSigDesc](),
2218+
lfn.None[uint32](),
2219+
)
2220+
if err != nil {
2221+
return fmt.Errorf("unable to sign second level "+
2222+
"vPkts: %w", err)
2223+
}
2224+
}
2225+
21912226
// Now that we have our vPkts, we'll re-create the output commitments.
2192-
outCommitments, err := tapsend.CreateOutputCommitments(vPkts.allPkts())
2227+
outCommitments, err := tapsend.CreateOutputCommitments(
2228+
vPkts.allPkts(),
2229+
)
21932230
if err != nil {
21942231
return fmt.Errorf("unable to create output "+
21952232
"commitments: %w", err)

0 commit comments

Comments
 (0)