@@ -1722,6 +1722,7 @@ func (a *AuxSweeper) resolveContract(
17221722 default :
17231723 return lfn .Errf [returnType ]("unknown resolution type: %v" ,
17241724 req .Type )
1725+ // TODO(roasbeef): need to do HTLC revocation casesj:w
17251726 }
17261727
17271728 // The input proofs above were made originally using the fake commit tx
@@ -1955,6 +1956,7 @@ func prepVpkts(bRes lfn.Result[blobWithWitnessInfo],
19551956// none of the inputs have any resolution blobs. Then an empty slice will be
19561957// returned.
19571958func extractInputVPackets (inputs []input.Input ) lfn.Result [sweepVpkts ] {
1959+
19581960 type returnType = sweepVpkts
19591961
19601962 // Otherwise, we'll extract the set of resolution blobs from the inputs
@@ -2161,7 +2163,7 @@ func (a *AuxSweeper) registerAndBroadcastSweep(req *sweep.BumpRequest,
21612163
21622164 // If we don't have any vPackets that had our resolution data in them,
21632165 // then we can exit early.
2164- if len (vPkts ) == 0 {
2166+ if len (vPkts . firstLevel ) == 0 && len ( vPkts . secondLevel ) == 0 {
21652167 log .Infof ("Sweep request had no vPkts, exiting" )
21662168 return nil
21672169 }
@@ -2183,17 +2185,52 @@ func (a *AuxSweeper) registerAndBroadcastSweep(req *sweep.BumpRequest,
21832185 internalKey .PubKey .SerializeCompressed ())
21842186
21852187 // We'll also use the passed in context to set the anchor key again for
2186- // all the vOuts.
2187- for idx := range vPkts {
2188- for _ , vOut := range vPkts [idx ].Outputs {
2188+ // all the vOuts, but only for first level vPkts, as second level
2189+ // packets already commit to the internal key of the vOut.
2190+ for idx := range vPkts .firstLevelPkts () {
2191+ for _ , vOut := range vPkts .firstLevelPkts ()[idx ].Outputs {
21892192 vOut .SetAnchorInternalKey (
21902193 internalKey , a .cfg .ChainParams .HDCoinType ,
21912194 )
21922195 }
21932196 }
21942197
2198+ // For any second level outputs we're sweeping, we'll need to sign for
2199+ // it, as now we know the txid of the sweeping transaction.
2200+ for _ , sweepSet := range vPkts .secondLevel {
2201+ for _ , vPkt := range sweepSet .vPkts {
2202+ for _ , vIn := range vPkt .Inputs {
2203+ vIn .PrevID .OutPoint = sweepSet .btcInput .OutPoint ()
2204+ }
2205+ }
2206+ }
2207+
2208+ // If we have second level vPkts, then we'll need to sign them here, as
2209+ // now we know the input we're spending which was set above.
2210+ for _ , sweepSet := range vPkts .secondLevel {
2211+ tapSigDesc , err := sweepSet .tapSigDesc .UnwrapOrErr (
2212+ fmt .Errorf ("tap sig desc not populated" ),
2213+ )
2214+ if err != nil {
2215+ return err
2216+ }
2217+
2218+ err = a .signSweepVpackets (
2219+ sweepSet .vPkts , * sweepSet .btcInput .SignDesc (),
2220+ tapSigDesc .TapTweak .Val , tapSigDesc .CtrlBlock .Val ,
2221+ lfn .None [lnwallet.AuxSigDesc ](),
2222+ lfn .None [uint32 ](),
2223+ )
2224+ if err != nil {
2225+ return fmt .Errorf ("unable to sign second level " +
2226+ "vPkts: %w" , err )
2227+ }
2228+ }
2229+
21952230 // Now that we have our vPkts, we'll re-create the output commitments.
2196- outCommitments , err := tapsend .CreateOutputCommitments (vPkts )
2231+ outCommitments , err := tapsend .CreateOutputCommitments (
2232+ vPkts .allPkts (),
2233+ )
21972234 if err != nil {
21982235 return fmt .Errorf ("unable to create output " +
21992236 "commitments: %w" , err )
@@ -2215,15 +2252,16 @@ func (a *AuxSweeper) registerAndBroadcastSweep(req *sweep.BumpRequest,
22152252 //
22162253 // TODO(roasbeef): base off allocations? then can serialize, then
22172254 // re-use the logic
2218- for idx := range vPkts {
2219- vPkt := vPkts [idx ]
2255+ allVpkts := vPkts .allPkts ()
2256+ for idx := range allVpkts {
2257+ vPkt := allVpkts [idx ]
22202258 for outIdx := range vPkt .Outputs {
22212259 exclusionCreator := sweepExclusionProofGen (
22222260 changeInternalKey ,
22232261 )
22242262
22252263 proofSuffix , err := tapsend .CreateProofSuffixCustom (
2226- sweepTx , vPkt , outCommitments , outIdx , vPkts ,
2264+ sweepTx , vPkt , outCommitments , outIdx , allVpkts ,
22272265 exclusionCreator ,
22282266 )
22292267 if err != nil {
@@ -2243,7 +2281,7 @@ func (a *AuxSweeper) registerAndBroadcastSweep(req *sweep.BumpRequest,
22432281 // We pass false for the last arg as we already updated our suffix
22442282 // proofs here.
22452283 return shipChannelTxn (
2246- a .cfg .TxSender , sweepTx , outCommitments , vPkts , int64 (fee ),
2284+ a .cfg .TxSender , sweepTx , outCommitments , allVpkts , int64 (fee ),
22472285 )
22482286}
22492287
0 commit comments