routing: deep copy any transaciton we obtain from GetBlock call.

This commit is contained in:
Mohamed Awnallah 2024-01-11 17:51:09 +02:00
parent 2f04ce7c6e
commit 99908ed2dc
No known key found for this signature in database
GPG Key ID: 5D55706029E9B87E
11 changed files with 20 additions and 16 deletions

View File

@ -613,7 +613,7 @@ func (b *BitcoindNotifier) confDetailsManually(confRequest chainntnfs.ConfReques
}
return &chainntnfs.TxConfirmation{
Tx: tx,
Tx: tx.Copy(),
BlockHash: blockHash,
BlockHeight: height,
TxIndex: uint32(txIndex),
@ -874,11 +874,13 @@ func (b *BitcoindNotifier) historicalSpendDetails(
continue
}
txHash := tx.TxHash()
txCopy := tx.Copy()
txHash := txCopy.TxHash()
spendOutPoint := &txCopy.TxIn[inputIdx].PreviousOutPoint
return &chainntnfs.SpendDetail{
SpentOutPoint: &tx.TxIn[inputIdx].PreviousOutPoint,
SpentOutPoint: spendOutPoint,
SpenderTxHash: &txHash,
SpendingTx: tx,
SpendingTx: txCopy,
SpenderInputIndex: inputIdx,
SpendingHeight: int32(height),
}, nil

View File

@ -667,7 +667,7 @@ func (b *BtcdNotifier) confDetailsManually(confRequest chainntnfs.ConfRequest,
}
return &chainntnfs.TxConfirmation{
Tx: tx,
Tx: tx.Copy(),
BlockHash: blockHash,
BlockHeight: height,
TxIndex: uint32(txIndex),

View File

@ -788,7 +788,7 @@ func ConfDetailsFromTxIndex(chainConn TxIndexConn, r ConfRequest,
}
return &TxConfirmation{
Tx: &tx,
Tx: tx.Copy(),
BlockHash: blockHash,
BlockHeight: uint32(blockHeight),
TxIndex: uint32(txIndex),

View File

@ -635,7 +635,7 @@ func (n *NeutrinoNotifier) historicalConfDetails(confRequest chainntnfs.ConfRequ
}
return &chainntnfs.TxConfirmation{
Tx: tx.MsgTx(),
Tx: tx.MsgTx().Copy(),
BlockHash: blockHash,
BlockHeight: scanHeight,
TxIndex: uint32(i),

View File

@ -1168,10 +1168,12 @@ func testListTransactionDetails(miner *rpctest.Harness,
t.Fatalf("err fetching block: %s", err)
}
transactions :=
make(map[chainhash.Hash][]*wire.TxOut, len(fetchedBlock.Transactions))
transactions := make(
map[chainhash.Hash][]*wire.TxOut,
len(fetchedBlock.Transactions),
)
for _, tx := range fetchedBlock.Transactions {
transactions[tx.TxHash()] = tx.TxOut
transactions[tx.TxHash()] = tx.Copy().TxOut
}
blockTxOuts[fetchedBlock.BlockHash()] = transactions

View File

@ -264,7 +264,7 @@ func (b *BitcoindFilteredChainView) chainFilterer() {
continue
}
filteredTxns = append(filteredTxns, tx)
filteredTxns = append(filteredTxns, tx.Copy())
txAlreadyFiltered = true
}
}

View File

@ -283,7 +283,7 @@ func (b *BtcdFilteredChainView) chainFilterer() {
continue
}
filteredTxns = append(filteredTxns, tx)
filteredTxns = append(filteredTxns, tx.Copy())
txAlreadyFiltered = true
}

View File

@ -296,7 +296,7 @@ func (c *CfFilteredChainView) FilterBlock(blockHash *chainhash.Hash) (*FilteredB
if ok {
filteredBlock.Transactions = append(
filteredBlock.Transactions,
tx.MsgTx(),
tx.MsgTx().Copy(),
)
c.filterMtx.Lock()

View File

@ -378,7 +378,7 @@ func (m *mockChainView) FilterBlock(blockHash *chainhash.Hash) (*chainview.Filte
prevOp := txIn.PreviousOutPoint
if _, ok := m.filter[prevOp]; ok {
filteredBlock.Transactions = append(
filteredBlock.Transactions, tx,
filteredBlock.Transactions, tx.Copy(),
)
m.Lock()

View File

@ -1894,7 +1894,7 @@ func (r *ChannelRouter) fetchFundingTx(
chanID.TxIndex, numTxns-1, chanID)
}
return fundingBlock.Transactions[chanID.TxIndex], nil
return fundingBlock.Transactions[chanID.TxIndex].Copy(), nil
}
// routingMsg couples a routing related routing topology update to the

View File

@ -165,7 +165,7 @@ func (l *Lookout) processEpoch(epoch *chainntnfs.BlockEpoch,
hint := blob.NewBreachHintFromHash(&hash)
txHints = append(txHints, hint)
hintToTx[hint] = tx
hintToTx[hint] = tx.Copy()
}
// Query the database to see if any of the breach hints cause a match