@@ -76,6 +76,11 @@ type broadcastReq struct {
7676 // fee is the fee that was used for the transaction.
7777 fee btcutil.Amount
7878
79+ // outpointToTxIndex maps a spent outpoint to the tx index on the sweep
80+ // transaction of the corresponding output. This is only needed to make
81+ // sure we make proofs properly for the pre-signed HTLC transactions.
82+ outpointToTxIndex map [wire.OutPoint ]int
83+
7984 // resp is the error result of the broadcast.
8085 resp chan error
8186}
@@ -2229,7 +2234,8 @@ func sweepExclusionProofGen(sweepInternalKey keychain.KeyDescriptor,
22292234// registerAndBroadcastSweep finalizes a sweep attempt by generating a
22302235// transition proof for it, then registering the sweep with the porter.
22312236func (a * AuxSweeper ) registerAndBroadcastSweep (req * sweep.BumpRequest ,
2232- sweepTx * wire.MsgTx , fee btcutil.Amount ) error {
2237+ sweepTx * wire.MsgTx , fee btcutil.Amount ,
2238+ outpointToTxIndex map [wire.OutPoint ]int ) error {
22332239
22342240 // TODO(roasbeef): need to handle replacement -- will porter just
22352241 // upsert in place?
@@ -2304,6 +2310,27 @@ func (a *AuxSweeper) registerAndBroadcastSweep(req *sweep.BumpRequest,
23042310 }
23052311 }
23062312
2313+ // For pre-signed HTLC txns we'll need to make sure we update the output
2314+ // index in the vPkt. As the ordering is only determined at broadcast
2315+ // time.
2316+ if outpointToTxIndex != nil {
2317+ for _ , sweepPkt := range vPkts .allVpktsWithInput () {
2318+ op := sweepPkt .btcInput .OutPoint ()
2319+ finalOutputIndex , ok := outpointToTxIndex [op ]
2320+ if ! ok {
2321+ continue
2322+ }
2323+
2324+ for _ , vPkt := range sweepPkt .vPkts {
2325+ for _ , vOut := range vPkt .Outputs {
2326+ vOut .AnchorOutputIndex = uint32 (
2327+ finalOutputIndex ,
2328+ )
2329+ }
2330+ }
2331+ }
2332+ }
2333+
23072334 // If we have second level vPkts, then we'll need to sign them here, as
23082335 // now we know the input we're spending which was set above.
23092336 for _ , sweepSet := range vPkts .secondLevel {
@@ -2402,6 +2429,7 @@ func (a *AuxSweeper) contractResolver() {
24022429 case req := <- a .broadcastReqs :
24032430 req .resp <- a .registerAndBroadcastSweep (
24042431 req .req , req .tx , req .fee ,
2432+ req .outpointToTxIndex ,
24052433 )
24062434
24072435 case <- a .quit :
@@ -2489,13 +2517,15 @@ func (a *AuxSweeper) ExtraBudgetForInputs(
24892517// NotifyBroadcast is used to notify external callers of the broadcast of a
24902518// sweep transaction, generated by the passed BumpRequest.
24912519func (a * AuxSweeper ) NotifyBroadcast (req * sweep.BumpRequest ,
2492- tx * wire.MsgTx , fee btcutil.Amount ) error {
2520+ tx * wire.MsgTx , fee btcutil.Amount ,
2521+ outpointToTxIndex map [wire.OutPoint ]int ) error {
24932522
24942523 auxReq := & broadcastReq {
2495- req : req ,
2496- tx : tx ,
2497- fee : fee ,
2498- resp : make (chan error , 1 ),
2524+ req : req ,
2525+ tx : tx ,
2526+ fee : fee ,
2527+ outpointToTxIndex : outpointToTxIndex ,
2528+ resp : make (chan error , 1 ),
24992529 }
25002530
25012531 if ! fn .SendOrQuit (a .broadcastReqs , auxReq , a .quit ) {
0 commit comments