mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-29 18:10:48 +02:00
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.
This commit is contained in:
@ -752,7 +752,7 @@ justiceTxBroadcast:
|
|||||||
}
|
}
|
||||||
|
|
||||||
return aux.NotifyBroadcast(
|
return aux.NotifyBroadcast(
|
||||||
&bumpReq, finalTx.justiceTx, finalTx.fee,
|
&bumpReq, finalTx.justiceTx, finalTx.fee, nil,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -603,7 +603,9 @@ func (t *TxPublisher) broadcast(requestID uint64) (*BumpResult, error) {
|
|||||||
// Before we go to broadcast, we'll notify the aux sweeper, if it's
|
// Before we go to broadcast, we'll notify the aux sweeper, if it's
|
||||||
// present of this new broadcast attempt.
|
// present of this new broadcast attempt.
|
||||||
err := fn.MapOptionZ(t.cfg.AuxSweeper, func(aux AuxSweeper) error {
|
err := fn.MapOptionZ(t.cfg.AuxSweeper, func(aux AuxSweeper) error {
|
||||||
return aux.NotifyBroadcast(record.req, tx, record.fee)
|
return aux.NotifyBroadcast(
|
||||||
|
record.req, tx, record.fee, record.outpointToTxIndex,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to notify aux sweeper: %w", err)
|
return nil, fmt.Errorf("unable to notify aux sweeper: %w", err)
|
||||||
@ -725,6 +727,9 @@ type monitorRecord struct {
|
|||||||
|
|
||||||
// fee is the fee paid by the tx.
|
// fee is the fee paid by the tx.
|
||||||
fee btcutil.Amount
|
fee btcutil.Amount
|
||||||
|
|
||||||
|
// outpointToTxIndex is a map of outpoint to tx index.
|
||||||
|
outpointToTxIndex map[wire.OutPoint]int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts the publisher by subscribing to block epoch updates and kicking
|
// Start starts the publisher by subscribing to block epoch updates and kicking
|
||||||
@ -1046,6 +1051,7 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
|
|||||||
req: r.req,
|
req: r.req,
|
||||||
feeFunction: r.feeFunction,
|
feeFunction: r.feeFunction,
|
||||||
fee: sweepCtx.fee,
|
fee: sweepCtx.fee,
|
||||||
|
outpointToTxIndex: sweepCtx.outpointToTxIndex,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Attempt to broadcast this new tx.
|
// Attempt to broadcast this new tx.
|
||||||
@ -1199,6 +1205,10 @@ type sweepTxCtx struct {
|
|||||||
fee btcutil.Amount
|
fee btcutil.Amount
|
||||||
|
|
||||||
extraTxOut fn.Option[SweepOutput]
|
extraTxOut fn.Option[SweepOutput]
|
||||||
|
|
||||||
|
// outpointToTxIndex maps the outpoint of the inputs to their index in
|
||||||
|
// the sweep transaction.
|
||||||
|
outpointToTxIndex map[wire.OutPoint]int
|
||||||
}
|
}
|
||||||
|
|
||||||
// createSweepTx creates a sweeping tx based on the given inputs, change
|
// createSweepTx creates a sweeping tx based on the given inputs, change
|
||||||
@ -1229,6 +1239,7 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input,
|
|||||||
// We start by adding all inputs that commit to an output. We do this
|
// We start by adding all inputs that commit to an output. We do this
|
||||||
// since the input and output index must stay the same for the
|
// since the input and output index must stay the same for the
|
||||||
// signatures to be valid.
|
// signatures to be valid.
|
||||||
|
outpointToTxIndex := make(map[wire.OutPoint]int)
|
||||||
for _, o := range inputs {
|
for _, o := range inputs {
|
||||||
if o.RequiredTxOut() == nil {
|
if o.RequiredTxOut() == nil {
|
||||||
continue
|
continue
|
||||||
@ -1240,6 +1251,8 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input,
|
|||||||
Sequence: o.BlocksToMaturity(),
|
Sequence: o.BlocksToMaturity(),
|
||||||
})
|
})
|
||||||
sweepTx.AddTxOut(o.RequiredTxOut())
|
sweepTx.AddTxOut(o.RequiredTxOut())
|
||||||
|
|
||||||
|
outpointToTxIndex[o.OutPoint()] = len(sweepTx.TxOut) - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sum up the value contained in the remaining inputs, and add them to
|
// Sum up the value contained in the remaining inputs, and add them to
|
||||||
@ -1334,6 +1347,7 @@ func (t *TxPublisher) createSweepTx(inputs []input.Input,
|
|||||||
tx: sweepTx,
|
tx: sweepTx,
|
||||||
fee: txFee,
|
fee: txFee,
|
||||||
extraTxOut: fn.FlattenOption(extraTxOut),
|
extraTxOut: fn.FlattenOption(extraTxOut),
|
||||||
|
outpointToTxIndex: outpointToTxIndex,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,5 +93,6 @@ type AuxSweeper interface {
|
|||||||
// NotifyBroadcast is used to notify external callers of the broadcast
|
// NotifyBroadcast is used to notify external callers of the broadcast
|
||||||
// of a sweep transaction, generated by the passed BumpRequest.
|
// of a sweep transaction, generated by the passed BumpRequest.
|
||||||
NotifyBroadcast(req *BumpRequest, tx *wire.MsgTx,
|
NotifyBroadcast(req *BumpRequest, tx *wire.MsgTx,
|
||||||
totalFees btcutil.Amount) error
|
totalFees btcutil.Amount,
|
||||||
|
outpointToTxIndex map[wire.OutPoint]int) error
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ func (m *MockAuxSweeper) ExtraBudgetForInputs(
|
|||||||
// NotifyBroadcast is used to notify external callers of the broadcast
|
// NotifyBroadcast is used to notify external callers of the broadcast
|
||||||
// of a sweep transaction, generated by the passed BumpRequest.
|
// of a sweep transaction, generated by the passed BumpRequest.
|
||||||
func (*MockAuxSweeper) NotifyBroadcast(_ *BumpRequest, _ *wire.MsgTx,
|
func (*MockAuxSweeper) NotifyBroadcast(_ *BumpRequest, _ *wire.MsgTx,
|
||||||
_ btcutil.Amount) error {
|
_ btcutil.Amount, _ map[wire.OutPoint]int) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user