@@ -747,6 +747,8 @@ func remoteHtlcTimeoutSweepDesc(keyRing *lnwallet.CommitmentKeyRing,
747747 return lfn.Err [tapscriptSweepDescs ](err )
748748 }
749749
750+ // TODO(roasbeef): use GenTaprootHtlcScript instead?
751+
750752 // Now that we have the script tree, we'll make the control block needed
751753 // to spend it, but taking the revoked path.
752754 ctrlBlock , err := htlcScriptTree .CtrlBlockForPath (
@@ -1967,8 +1969,8 @@ func newBlobWithWitnessInfo(i input.Input) lfn.Result[blobWithWitnessInfo] {
19671969 secondLevel bool
19681970 )
19691971 switch i .WitnessType () {
1970-
19711972 // This is the case when we're sweeping the HTLC output on our local
1973+
19721974 // commitment transaction via a second level HTLC.
19731975 //
19741976 // The final witness stack is:
@@ -2173,14 +2175,15 @@ func (a *AuxSweeper) sweepContracts(inputs []input.Input,
21732175 log .Infof ("Generating anchor output for vpkts=%v" ,
21742176 limitSpewer .Sdump (sPkts ))
21752177
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 ()
21802183
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 {
21842187 return lfn.Err [sweep.SweepOutput ](nil )
21852188 }
21862189
@@ -2195,17 +2198,32 @@ func (a *AuxSweeper) sweepContracts(inputs []input.Input,
21952198 if err != nil {
21962199 return lfn.Err [returnType ](err )
21972200 }
2198- for idx := range firstLevelVpkts {
2199- for _ , vOut := range firstLevelVpkts [idx ].Outputs {
2201+ for idx := range directPkts {
2202+ for _ , vOut := range directPkts [idx ].Outputs {
22002203 vOut .SetAnchorInternalKey (
22012204 internalKey , a .cfg .ChainParams .HDCoinType ,
22022205 )
22032206 }
22042207 }
22052208
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+
22062224 // Now that we have our set of resolutions, we'll make a new commitment
22072225 // out of all the vPackets contained.
2208- outCommitments , err := tapsend .CreateOutputCommitments (firstLevelVpkts )
2226+ outCommitments , err := tapsend .CreateOutputCommitments (directPkts )
22092227 if err != nil {
22102228 return lfn .Errf [returnType ]("unable to create " +
22112229 "output commitments: %w" , err )
0 commit comments