Skip to content

Commit b8035d9

Browse files
Roasbeefguggero
authored andcommitted
sweep: expand NotifyBroadcast to include an outpoint index
In this commit, we expand the `NotifyBroadcast` to include an outpoint index. This is useful as it indicates the index of a given required tx out input.
1 parent 83f1c88 commit b8035d9

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

contractcourt/breach_arbitrator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ justiceTxBroadcast:
752752
}
753753

754754
return aux.NotifyBroadcast(
755-
&bumpReq, finalTx.justiceTx, finalTx.fee,
755+
&bumpReq, finalTx.justiceTx, finalTx.fee, nil,
756756
)
757757
})
758758
if err != nil {

sweep/fee_bumper.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,9 @@ func (t *TxPublisher) broadcast(requestID uint64) (*BumpResult, error) {
603603
// Before we go to broadcast, we'll notify the aux sweeper, if it's
604604
// present of this new broadcast attempt.
605605
err := fn.MapOptionZ(t.cfg.AuxSweeper, func(aux AuxSweeper) error {
606-
return aux.NotifyBroadcast(record.req, tx, record.fee)
606+
return aux.NotifyBroadcast(
607+
record.req, tx, record.fee, record.outpointToTxIndex,
608+
)
607609
})
608610
if err != nil {
609611
return nil, fmt.Errorf("unable to notify aux sweeper: %w", err)
@@ -725,6 +727,9 @@ type monitorRecord struct {
725727

726728
// fee is the fee paid by the tx.
727729
fee btcutil.Amount
730+
731+
// outpointToTxIndex is a map of outpoint to tx index.
732+
outpointToTxIndex map[wire.OutPoint]int
728733
}
729734

730735
// Start starts the publisher by subscribing to block epoch updates and kicking
@@ -1042,10 +1047,11 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
10421047
// The tx has been created without any errors, we now register a new
10431048
// record by overwriting the same requestID.
10441049
t.records.Store(requestID, &monitorRecord{
1045-
tx: sweepCtx.tx,
1046-
req: r.req,
1047-
feeFunction: r.feeFunction,
1048-
fee: sweepCtx.fee,
1050+
tx: sweepCtx.tx,
1051+
req: r.req,
1052+
feeFunction: r.feeFunction,
1053+
fee: sweepCtx.fee,
1054+
outpointToTxIndex: sweepCtx.outpointToTxIndex,
10491055
})
10501056

10511057
// Attempt to broadcast this new tx.
@@ -1199,6 +1205,10 @@ type sweepTxCtx struct {
11991205
fee btcutil.Amount
12001206

12011207
extraTxOut fn.Option[SweepOutput]
1208+
1209+
// outpointToTxIndex maps the outpoint of the inputs to their index in
1210+
// the sweep transaction.
1211+
outpointToTxIndex map[wire.OutPoint]int
12021212
}
12031213

12041214
// createSweepTx creates a sweeping tx based on the given inputs, change
@@ -1229,6 +1239,7 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input,
12291239
// We start by adding all inputs that commit to an output. We do this
12301240
// since the input and output index must stay the same for the
12311241
// signatures to be valid.
1242+
outpointToTxIndex := make(map[wire.OutPoint]int)
12321243
for _, o := range inputs {
12331244
if o.RequiredTxOut() == nil {
12341245
continue
@@ -1240,6 +1251,8 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input,
12401251
Sequence: o.BlocksToMaturity(),
12411252
})
12421253
sweepTx.AddTxOut(o.RequiredTxOut())
1254+
1255+
outpointToTxIndex[o.OutPoint()] = len(sweepTx.TxOut) - 1
12431256
}
12441257

12451258
// Sum up the value contained in the remaining inputs, and add them to
@@ -1331,9 +1344,10 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input,
13311344
)(changeOutputsOpt)
13321345

13331346
return &sweepTxCtx{
1334-
tx: sweepTx,
1335-
fee: txFee,
1336-
extraTxOut: fn.FlattenOption(extraTxOut),
1347+
tx: sweepTx,
1348+
fee: txFee,
1349+
extraTxOut: fn.FlattenOption(extraTxOut),
1350+
outpointToTxIndex: outpointToTxIndex,
13371351
}, nil
13381352
}
13391353

sweep/interface.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@ type AuxSweeper interface {
9393
// NotifyBroadcast is used to notify external callers of the broadcast
9494
// of a sweep transaction, generated by the passed BumpRequest.
9595
NotifyBroadcast(req *BumpRequest, tx *wire.MsgTx,
96-
totalFees btcutil.Amount) error
96+
totalFees btcutil.Amount,
97+
outpointToTxIndex map[wire.OutPoint]int) error
9798
}

sweep/mock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func (m *MockAuxSweeper) ExtraBudgetForInputs(
352352
// NotifyBroadcast is used to notify external callers of the broadcast
353353
// of a sweep transaction, generated by the passed BumpRequest.
354354
func (*MockAuxSweeper) NotifyBroadcast(_ *BumpRequest, _ *wire.MsgTx,
355-
_ btcutil.Amount) error {
355+
_ btcutil.Amount, _ map[wire.OutPoint]int) error {
356356

357357
return nil
358358
}

0 commit comments

Comments
 (0)