Skip to content

Commit e2327b7

Browse files
committed
tapchannel: use new directSpendPkts method
Direct spends are spends directly from the commitment transaction. If we don't have any direct spends, then we don't need to make a change addr, as second level spends are already bound to an anchor output.
1 parent 6c4976f commit e2327b7

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

tapchannel/aux_sweeper.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ func remoteHtlcTimeoutSweepDesc(keyRing *lnwallet.CommitmentKeyRing,
749749
return lfn.Err[tapscriptSweepDescs](err)
750750
}
751751

752+
// TODO(roasbeef): use GenTaprootHtlcScript instead?
753+
752754
// Now that we have the script tree, we'll make the control block needed
753755
// to spend it, but taking the revoked path.
754756
ctrlBlock, err := htlcScriptTree.CtrlBlockForPath(
@@ -1969,8 +1971,8 @@ func newBlobWithWitnessInfo(i input.Input) lfn.Result[blobWithWitnessInfo] {
19691971
secondLevel bool
19701972
)
19711973
switch i.WitnessType() {
1972-
19731974
// This is the case when we're sweeping the HTLC output on our local
1975+
19741976
// commitment transaction via a second level HTLC.
19751977
//
19761978
// The final witness stack is:
@@ -2136,6 +2138,7 @@ func extractInputVPackets(inputs []input.Input) lfn.Result[sweepVpkts] {
21362138
return lfn.Err[sweepVpkts](err)
21372139
}
21382140

2141+
vPkts2 = append(vPkts2, *vpkt)
21392142
}
21402143

21412144
return lfn.Ok(sweepVpkts{
@@ -2173,14 +2176,15 @@ func (a *AuxSweeper) sweepContracts(inputs []input.Input,
21732176
log.Infof("Generating anchor output for vpkts=%v",
21742177
limitSpewer.Sdump(sPkts))
21752178

2176-
// Second level packets will already be anchored to the output assigned
2177-
// to it, so we only need to re-create the commitment for the first
2178-
// level outputs, which can be swept directly into the wallet.
2179-
firstLevelVpkts := sPkts.firstLevelPkts()
2179+
// If this is a sweep from the local commitment transaction. Then we'll
2180+
// have both the first and second level sweeps. However for the first
2181+
// sweep, it's a broadcast of a pre-signed transaction, so we don't need
2182+
// an anchor output for those.
2183+
directPkts := sPkts.directSpendPkts()
21802184

2181-
// If there're no first level vPkts, then we can just return a nil error
2182-
// as we don't have a real sweep output to create.
2183-
if len(firstLevelVpkts) == 0 {
2185+
// If there're no direct level vPkts, then we can just return a nil
2186+
// error as we don't have a real sweep output to create.
2187+
if len(directPkts) == 0 {
21842188
return lfn.Err[sweep.SweepOutput](nil)
21852189
}
21862190

@@ -2195,17 +2199,32 @@ func (a *AuxSweeper) sweepContracts(inputs []input.Input,
21952199
if err != nil {
21962200
return lfn.Err[returnType](err)
21972201
}
2198-
for idx := range firstLevelVpkts {
2199-
for _, vOut := range firstLevelVpkts[idx].Outputs {
2202+
for idx := range directPkts {
2203+
for _, vOut := range directPkts[idx].Outputs {
22002204
vOut.SetAnchorInternalKey(
22012205
internalKey, a.cfg.ChainParams.HDCoinType,
22022206
)
22032207
}
22042208
}
22052209

2210+
// For any second level outputs we're sweeping, we'll need to sign for
2211+
// it, as now we know the txid of the sweeping transaction. We'll do
2212+
// this again when we register for the final broadcast, we we need to
2213+
// sign the right prevIDs.
2214+
for _, sweepSet := range sPkts.secondLevel {
2215+
for _, vPkt := range sweepSet.vPkts {
2216+
for _, vIn := range vPkt.Inputs {
2217+
vIn.PrevID.OutPoint = sweepSet.btcInput.OutPoint()
2218+
}
2219+
for _, vOut := range vPkt.Outputs {
2220+
vOut.Asset.PrevWitnesses[0].PrevID.OutPoint = sweepSet.btcInput.OutPoint()
2221+
}
2222+
}
2223+
}
2224+
22062225
// Now that we have our set of resolutions, we'll make a new commitment
22072226
// out of all the vPackets contained.
2208-
outCommitments, err := tapsend.CreateOutputCommitments(firstLevelVpkts)
2227+
outCommitments, err := tapsend.CreateOutputCommitments(directPkts)
22092228
if err != nil {
22102229
return lfn.Errf[returnType]("unable to create "+
22112230
"output commitments: %w", err)

0 commit comments

Comments
 (0)