@@ -747,6 +747,8 @@ func remoteHtlcTimeoutSweepDesc(keyRing *lnwallet.CommitmentKeyRing,
747
747
return lfn.Err [tapscriptSweepDescs ](err )
748
748
}
749
749
750
+ // TODO(roasbeef): use GenTaprootHtlcScript instead?
751
+
750
752
// Now that we have the script tree, we'll make the control block needed
751
753
// to spend it, but taking the revoked path.
752
754
ctrlBlock , err := htlcScriptTree .CtrlBlockForPath (
@@ -1967,8 +1969,8 @@ func newBlobWithWitnessInfo(i input.Input) lfn.Result[blobWithWitnessInfo] {
1967
1969
secondLevel bool
1968
1970
)
1969
1971
switch i .WitnessType () {
1970
-
1971
1972
// This is the case when we're sweeping the HTLC output on our local
1973
+
1972
1974
// commitment transaction via a second level HTLC.
1973
1975
//
1974
1976
// The final witness stack is:
@@ -2173,14 +2175,15 @@ func (a *AuxSweeper) sweepContracts(inputs []input.Input,
2173
2175
log .Infof ("Generating anchor output for vpkts=%v" ,
2174
2176
limitSpewer .Sdump (sPkts ))
2175
2177
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 ()
2178
+ // If this is a sweep from the local commitment transaction. Then we'll
2179
+ // have both the first and second level sweeps. However for the first
2180
+ // sweep, it's a broadcast of a pre-signed transaction, so we don't need
2181
+ // an anchor output for those.
2182
+ directPkts := sPkts .directSpendPkts ()
2180
2183
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 {
2184
+ // If there're no direct level vPkts, then we can just return a nil
2185
+ // error as we don't have a real sweep output to create.
2186
+ if len (directPkts ) == 0 {
2184
2187
return lfn.Err [sweep.SweepOutput ](nil )
2185
2188
}
2186
2189
@@ -2195,17 +2198,32 @@ func (a *AuxSweeper) sweepContracts(inputs []input.Input,
2195
2198
if err != nil {
2196
2199
return lfn.Err [returnType ](err )
2197
2200
}
2198
- for idx := range firstLevelVpkts {
2199
- for _ , vOut := range firstLevelVpkts [idx ].Outputs {
2201
+ for idx := range directPkts {
2202
+ for _ , vOut := range directPkts [idx ].Outputs {
2200
2203
vOut .SetAnchorInternalKey (
2201
2204
internalKey , a .cfg .ChainParams .HDCoinType ,
2202
2205
)
2203
2206
}
2204
2207
}
2205
2208
2209
+ // For any second level outputs we're sweeping, we'll need to sign for
2210
+ // it, as now we know the txid of the sweeping transaction. We'll do
2211
+ // this again when we register for the final broadcast, we we need to
2212
+ // sign the right prevIDs.
2213
+ for _ , sweepSet := range sPkts .secondLevel {
2214
+ for _ , vPkt := range sweepSet .vPkts {
2215
+ for _ , vIn := range vPkt .Inputs {
2216
+ vIn .PrevID .OutPoint = sweepSet .btcInput .OutPoint ()
2217
+ }
2218
+ for _ , vOut := range vPkt .Outputs {
2219
+ vOut .Asset .PrevWitnesses [0 ].PrevID .OutPoint = sweepSet .btcInput .OutPoint ()
2220
+ }
2221
+ }
2222
+ }
2223
+
2206
2224
// Now that we have our set of resolutions, we'll make a new commitment
2207
2225
// out of all the vPackets contained.
2208
- outCommitments , err := tapsend .CreateOutputCommitments (firstLevelVpkts )
2226
+ outCommitments , err := tapsend .CreateOutputCommitments (directPkts )
2209
2227
if err != nil {
2210
2228
return lfn .Errf [returnType ]("unable to create " +
2211
2229
"output commitments: %w" , err )
0 commit comments