@@ -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}
@@ -2147,7 +2152,8 @@ func sweepExclusionProofGen(sweepInternalKey keychain.KeyDescriptor,
21472152// registerAndBroadcastSweep finalizes a sweep attempt by generating a
21482153// transition proof for it, then registering the sweep with the porter.
21492154func (a * AuxSweeper ) registerAndBroadcastSweep (req * sweep.BumpRequest ,
2150- sweepTx * wire.MsgTx , fee btcutil.Amount ) error {
2155+ sweepTx * wire.MsgTx , fee btcutil.Amount ,
2156+ outpointToTxIndex map [wire.OutPoint ]int ) error {
21512157
21522158 // TODO(roasbeef): need to handle replacement -- will porter just
21532159 // upsert in place?
@@ -2202,6 +2208,24 @@ func (a *AuxSweeper) registerAndBroadcastSweep(req *sweep.BumpRequest,
22022208 for _ , vIn := range vPkt .Inputs {
22032209 vIn .PrevID .OutPoint = sweepSet .btcInput .OutPoint ()
22042210 }
2211+ // For pre-signed HTLC txns we'll need to make sure we update the output
2212+ // index in the vPkt. As the ordering is only determined at broadcast
2213+ // time.
2214+ if outpointToTxIndex != nil {
2215+ for _ , sweepPkt := range vPkts .allVpktsWithInput () {
2216+ op := sweepPkt .btcInput .OutPoint ()
2217+ finalOutputIndex , ok := outpointToTxIndex [op ]
2218+ if ! ok {
2219+ continue
2220+ }
2221+
2222+ for _ , vPkt := range sweepPkt .vPkts {
2223+ for _ , vOut := range vPkt .Outputs {
2224+ vOut .AnchorOutputIndex = uint32 (
2225+ finalOutputIndex ,
2226+ )
2227+ }
2228+ }
22052229 }
22062230 }
22072231
@@ -2303,6 +2327,7 @@ func (a *AuxSweeper) contractResolver() {
23032327 case req := <- a .broadcastReqs :
23042328 req .resp <- a .registerAndBroadcastSweep (
23052329 req .req , req .tx , req .fee ,
2330+ req .outpointToTxIndex ,
23062331 )
23072332
23082333 case <- a .quit :
@@ -2390,13 +2415,15 @@ func (a *AuxSweeper) ExtraBudgetForInputs(
23902415// NotifyBroadcast is used to notify external callers of the broadcast of a
23912416// sweep transaction, generated by the passed BumpRequest.
23922417func (a * AuxSweeper ) NotifyBroadcast (req * sweep.BumpRequest ,
2393- tx * wire.MsgTx , fee btcutil.Amount ) error {
2418+ tx * wire.MsgTx , fee btcutil.Amount ,
2419+ outpointToTxIndex map [wire.OutPoint ]int ) error {
23942420
23952421 auxReq := & broadcastReq {
2396- req : req ,
2397- tx : tx ,
2398- fee : fee ,
2399- resp : make (chan error , 1 ),
2422+ req : req ,
2423+ tx : tx ,
2424+ fee : fee ,
2425+ outpointToTxIndex : outpointToTxIndex ,
2426+ resp : make (chan error , 1 ),
24002427 }
24012428
24022429 if ! fn .SendOrQuit (a .broadcastReqs , auxReq , a .quit ) {
0 commit comments