mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-05 20:49:48 +02:00
sweep: update storeRecord to include utxo index
In this commit, we complete a recently added feature by ensuring that even if we go through the RBF loop to create a txn, that we still populate the `outpointToIndex` map. Unit tests have been updated to ensure this is always set as expected.
This commit is contained in:
parent
bd36f76530
commit
7ed2c10671
@ -455,6 +455,7 @@ func (t *TxPublisher) createRBFCompliantTx(req *BumpRequest,
|
|||||||
// The tx is valid, return the request ID.
|
// The tx is valid, return the request ID.
|
||||||
requestID := t.storeRecord(
|
requestID := t.storeRecord(
|
||||||
sweepCtx.tx, req, f, sweepCtx.fee,
|
sweepCtx.tx, req, f, sweepCtx.fee,
|
||||||
|
sweepCtx.outpointToTxIndex,
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Infof("Created tx %v for %v inputs: feerate=%v, "+
|
log.Infof("Created tx %v for %v inputs: feerate=%v, "+
|
||||||
@ -510,7 +511,8 @@ func (t *TxPublisher) createRBFCompliantTx(req *BumpRequest,
|
|||||||
|
|
||||||
// storeRecord stores the given record in the records map.
|
// storeRecord stores the given record in the records map.
|
||||||
func (t *TxPublisher) storeRecord(tx *wire.MsgTx, req *BumpRequest,
|
func (t *TxPublisher) storeRecord(tx *wire.MsgTx, req *BumpRequest,
|
||||||
f FeeFunction, fee btcutil.Amount) uint64 {
|
f FeeFunction, fee btcutil.Amount,
|
||||||
|
outpointToTxIndex map[wire.OutPoint]int) uint64 {
|
||||||
|
|
||||||
// Increase the request counter.
|
// Increase the request counter.
|
||||||
//
|
//
|
||||||
@ -520,10 +522,11 @@ func (t *TxPublisher) storeRecord(tx *wire.MsgTx, req *BumpRequest,
|
|||||||
|
|
||||||
// Register the record.
|
// Register the record.
|
||||||
t.records.Store(requestID, &monitorRecord{
|
t.records.Store(requestID, &monitorRecord{
|
||||||
tx: tx,
|
tx: tx,
|
||||||
req: req,
|
req: req,
|
||||||
feeFunction: f,
|
feeFunction: f,
|
||||||
fee: fee,
|
fee: fee,
|
||||||
|
outpointToTxIndex: outpointToTxIndex,
|
||||||
})
|
})
|
||||||
|
|
||||||
return requestID
|
return requestID
|
||||||
|
@ -323,8 +323,16 @@ func TestStoreRecord(t *testing.T) {
|
|||||||
// Get the current counter and check it's increased later.
|
// Get the current counter and check it's increased later.
|
||||||
initialCounter := tp.requestCounter.Load()
|
initialCounter := tp.requestCounter.Load()
|
||||||
|
|
||||||
|
op := wire.OutPoint{
|
||||||
|
Hash: chainhash.Hash{1},
|
||||||
|
Index: 0,
|
||||||
|
}
|
||||||
|
utxoIndex := map[wire.OutPoint]int{
|
||||||
|
op: 0,
|
||||||
|
}
|
||||||
|
|
||||||
// Call the method under test.
|
// Call the method under test.
|
||||||
requestID := tp.storeRecord(tx, req, feeFunc, fee)
|
requestID := tp.storeRecord(tx, req, feeFunc, fee, utxoIndex)
|
||||||
|
|
||||||
// Check the request ID is as expected.
|
// Check the request ID is as expected.
|
||||||
require.Equal(t, initialCounter+1, requestID)
|
require.Equal(t, initialCounter+1, requestID)
|
||||||
@ -336,6 +344,7 @@ func TestStoreRecord(t *testing.T) {
|
|||||||
require.Equal(t, feeFunc, record.feeFunction)
|
require.Equal(t, feeFunc, record.feeFunction)
|
||||||
require.Equal(t, fee, record.fee)
|
require.Equal(t, fee, record.fee)
|
||||||
require.Equal(t, req, record.req)
|
require.Equal(t, req, record.req)
|
||||||
|
require.Equal(t, utxoIndex, record.outpointToTxIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// mockers wraps a list of mocked interfaces used inside tx publisher.
|
// mockers wraps a list of mocked interfaces used inside tx publisher.
|
||||||
@ -665,9 +674,17 @@ func TestTxPublisherBroadcast(t *testing.T) {
|
|||||||
feerate := chainfee.SatPerKWeight(1000)
|
feerate := chainfee.SatPerKWeight(1000)
|
||||||
m.feeFunc.On("FeeRate").Return(feerate)
|
m.feeFunc.On("FeeRate").Return(feerate)
|
||||||
|
|
||||||
|
op := wire.OutPoint{
|
||||||
|
Hash: chainhash.Hash{1},
|
||||||
|
Index: 0,
|
||||||
|
}
|
||||||
|
utxoIndex := map[wire.OutPoint]int{
|
||||||
|
op: 0,
|
||||||
|
}
|
||||||
|
|
||||||
// Create a testing record and put it in the map.
|
// Create a testing record and put it in the map.
|
||||||
fee := btcutil.Amount(1000)
|
fee := btcutil.Amount(1000)
|
||||||
requestID := tp.storeRecord(tx, req, m.feeFunc, fee)
|
requestID := tp.storeRecord(tx, req, m.feeFunc, fee, utxoIndex)
|
||||||
|
|
||||||
// Quickly check when the requestID cannot be found, an error is
|
// Quickly check when the requestID cannot be found, an error is
|
||||||
// returned.
|
// returned.
|
||||||
@ -754,6 +771,14 @@ func TestRemoveResult(t *testing.T) {
|
|||||||
// Create a testing record and put it in the map.
|
// Create a testing record and put it in the map.
|
||||||
fee := btcutil.Amount(1000)
|
fee := btcutil.Amount(1000)
|
||||||
|
|
||||||
|
op := wire.OutPoint{
|
||||||
|
Hash: chainhash.Hash{1},
|
||||||
|
Index: 0,
|
||||||
|
}
|
||||||
|
utxoIndex := map[wire.OutPoint]int{
|
||||||
|
op: 0,
|
||||||
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
setupRecord func() uint64
|
setupRecord func() uint64
|
||||||
@ -765,7 +790,9 @@ func TestRemoveResult(t *testing.T) {
|
|||||||
// removed.
|
// removed.
|
||||||
name: "remove on TxConfirmed",
|
name: "remove on TxConfirmed",
|
||||||
setupRecord: func() uint64 {
|
setupRecord: func() uint64 {
|
||||||
id := tp.storeRecord(tx, req, m.feeFunc, fee)
|
id := tp.storeRecord(
|
||||||
|
tx, req, m.feeFunc, fee, utxoIndex,
|
||||||
|
)
|
||||||
tp.subscriberChans.Store(id, nil)
|
tp.subscriberChans.Store(id, nil)
|
||||||
|
|
||||||
return id
|
return id
|
||||||
@ -780,7 +807,9 @@ func TestRemoveResult(t *testing.T) {
|
|||||||
// When the tx is failed, the records will be removed.
|
// When the tx is failed, the records will be removed.
|
||||||
name: "remove on TxFailed",
|
name: "remove on TxFailed",
|
||||||
setupRecord: func() uint64 {
|
setupRecord: func() uint64 {
|
||||||
id := tp.storeRecord(tx, req, m.feeFunc, fee)
|
id := tp.storeRecord(
|
||||||
|
tx, req, m.feeFunc, fee, utxoIndex,
|
||||||
|
)
|
||||||
tp.subscriberChans.Store(id, nil)
|
tp.subscriberChans.Store(id, nil)
|
||||||
|
|
||||||
return id
|
return id
|
||||||
@ -796,7 +825,9 @@ func TestRemoveResult(t *testing.T) {
|
|||||||
// Noop when the tx is neither confirmed or failed.
|
// Noop when the tx is neither confirmed or failed.
|
||||||
name: "noop when tx is not confirmed or failed",
|
name: "noop when tx is not confirmed or failed",
|
||||||
setupRecord: func() uint64 {
|
setupRecord: func() uint64 {
|
||||||
id := tp.storeRecord(tx, req, m.feeFunc, fee)
|
id := tp.storeRecord(
|
||||||
|
tx, req, m.feeFunc, fee, utxoIndex,
|
||||||
|
)
|
||||||
tp.subscriberChans.Store(id, nil)
|
tp.subscriberChans.Store(id, nil)
|
||||||
|
|
||||||
return id
|
return id
|
||||||
@ -844,9 +875,17 @@ func TestNotifyResult(t *testing.T) {
|
|||||||
// Create a test tx.
|
// Create a test tx.
|
||||||
tx := &wire.MsgTx{LockTime: 1}
|
tx := &wire.MsgTx{LockTime: 1}
|
||||||
|
|
||||||
|
op := wire.OutPoint{
|
||||||
|
Hash: chainhash.Hash{1},
|
||||||
|
Index: 0,
|
||||||
|
}
|
||||||
|
utxoIndex := map[wire.OutPoint]int{
|
||||||
|
op: 0,
|
||||||
|
}
|
||||||
|
|
||||||
// Create a testing record and put it in the map.
|
// Create a testing record and put it in the map.
|
||||||
fee := btcutil.Amount(1000)
|
fee := btcutil.Amount(1000)
|
||||||
requestID := tp.storeRecord(tx, req, m.feeFunc, fee)
|
requestID := tp.storeRecord(tx, req, m.feeFunc, fee, utxoIndex)
|
||||||
|
|
||||||
// Create a subscription to the event.
|
// Create a subscription to the event.
|
||||||
subscriber := make(chan *BumpResult, 1)
|
subscriber := make(chan *BumpResult, 1)
|
||||||
@ -1201,9 +1240,17 @@ func TestHandleTxConfirmed(t *testing.T) {
|
|||||||
// Create a test tx.
|
// Create a test tx.
|
||||||
tx := &wire.MsgTx{LockTime: 1}
|
tx := &wire.MsgTx{LockTime: 1}
|
||||||
|
|
||||||
|
op := wire.OutPoint{
|
||||||
|
Hash: chainhash.Hash{1},
|
||||||
|
Index: 0,
|
||||||
|
}
|
||||||
|
utxoIndex := map[wire.OutPoint]int{
|
||||||
|
op: 0,
|
||||||
|
}
|
||||||
|
|
||||||
// Create a testing record and put it in the map.
|
// Create a testing record and put it in the map.
|
||||||
fee := btcutil.Amount(1000)
|
fee := btcutil.Amount(1000)
|
||||||
requestID := tp.storeRecord(tx, req, m.feeFunc, fee)
|
requestID := tp.storeRecord(tx, req, m.feeFunc, fee, utxoIndex)
|
||||||
record, ok := tp.records.Load(requestID)
|
record, ok := tp.records.Load(requestID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
||||||
@ -1273,9 +1320,17 @@ func TestHandleFeeBumpTx(t *testing.T) {
|
|||||||
tx: tx,
|
tx: tx,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
op := wire.OutPoint{
|
||||||
|
Hash: chainhash.Hash{1},
|
||||||
|
Index: 0,
|
||||||
|
}
|
||||||
|
utxoIndex := map[wire.OutPoint]int{
|
||||||
|
op: 0,
|
||||||
|
}
|
||||||
|
|
||||||
// Create a testing record and put it in the map.
|
// Create a testing record and put it in the map.
|
||||||
fee := btcutil.Amount(1000)
|
fee := btcutil.Amount(1000)
|
||||||
requestID := tp.storeRecord(tx, req, m.feeFunc, fee)
|
requestID := tp.storeRecord(tx, req, m.feeFunc, fee, utxoIndex)
|
||||||
|
|
||||||
// Create a subscription to the event.
|
// Create a subscription to the event.
|
||||||
subscriber := make(chan *BumpResult, 1)
|
subscriber := make(chan *BumpResult, 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user