sweep: shorten storeRecord method signature

This commit shortens the function signature of `storeRecord`, also makes
sure we don't call `t.records.Store` directly but always using
`storeRecord` instead so it's easier to trace the record creation.
This commit is contained in:
yyforyongyu committed 2025-02-05 19:48:18 +08:00
1 parent c68b8e8c1e
commit bde5124e1b
2 files changed
+70 -40

No files matched your search

+16 -26
View File
@@ -440,6 +440,20 @@ func (t *TxPublisher) storeInitialRecord(req *BumpRequest) (
return requestID, record
}
// storeRecord stores the given record in the records map.
func (t *TxPublisher) storeRecord(requestID uint64, sweepCtx *sweepTxCtx,
req *BumpRequest, f FeeFunction) {
// Register the record.
t.records.Store(requestID, &monitorRecord{
tx: sweepCtx.tx,
req: req,
feeFunction: f,
fee: sweepCtx.fee,
outpointToTxIndex: sweepCtx.outpointToTxIndex,
})
}
// NOTE: part of the `chainio.Consumer` interface.
func (t *TxPublisher) Name() string {
return "TxPublisher"
@@ -508,10 +522,7 @@ func (t *TxPublisher) createRBFCompliantTx(requestID uint64, req *BumpRequest,
switch {
case err == nil:
// The tx is valid, store it.
t.storeRecord(
requestID, sweepCtx.tx, req, f, sweepCtx.fee,
sweepCtx.outpointToTxIndex,
)
t.storeRecord(requestID, sweepCtx, req, f)
log.Infof("Created initial sweep tx=%v for %v inputs: "+
"feerate=%v, fee=%v, inputs:\n%v",
@@ -565,21 +576,6 @@ func (t *TxPublisher) createRBFCompliantTx(requestID uint64, req *BumpRequest,
}
}
// storeRecord stores the given record in the records map.
func (t *TxPublisher) storeRecord(requestID uint64, tx *wire.MsgTx,
req *BumpRequest, f FeeFunction, fee btcutil.Amount,
outpointToTxIndex map[wire.OutPoint]int) {
// Register the record.
t.records.Store(requestID, &monitorRecord{
tx: tx,
req: req,
feeFunction: f,
fee: fee,
outpointToTxIndex: outpointToTxIndex,
})
}
// createAndCheckTx creates a tx based on the given inputs, change output
// script, and the fee rate. In addition, it validates the tx's mempool
// acceptance before returning a tx that can be published directly, along with
@@ -1195,13 +1191,7 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
// The tx has been created without any errors, we now register a new
// record by overwriting the same requestID.
t.records.Store(requestID, &monitorRecord{
tx: sweepCtx.tx,
req: r.req,
feeFunction: r.feeFunction,
fee: sweepCtx.fee,
outpointToTxIndex: sweepCtx.outpointToTxIndex,
})
t.storeRecord(requestID, sweepCtx, r.req, r.feeFunction)
// Attempt to broadcast this new tx.
result, err := t.broadcast(requestID)