Skip to content

Commit 4100499

Browse files
committed
Return shared_ptr<CTransaction> from mempool removes
1 parent 51f2783 commit 4100499

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,7 +2803,7 @@ static int64_t nTimePostConnect = 0;
28032803
* Connect a new block to chainActive. pblock is either NULL or a pointer to a CBlock
28042804
* corresponding to pindexNew, to bypass loading it again from disk.
28052805
*/
2806-
bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock, std::list<CTransaction> &txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*,int>> &txChanged)
2806+
bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock, std::vector<std::shared_ptr<const CTransaction>> &txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*,int>> &txChanged)
28072807
{
28082808
assert(pindexNew->pprev == chainActive.Tip());
28092809
// Read block from disk.
@@ -2926,7 +2926,7 @@ static void PruneBlockIndexCandidates() {
29262926
* Try to make some progress towards making pindexMostWork the active block.
29272927
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
29282928
*/
2929-
static bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool& fInvalidFound, std::list<CTransaction>& txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*,int>>& txChanged)
2929+
static bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool& fInvalidFound, std::vector<std::shared_ptr<const CTransaction>>& txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*,int>>& txChanged)
29302930
{
29312931
AssertLockHeld(cs_main);
29322932
const CBlockIndex *pindexOldTip = chainActive.Tip();
@@ -3037,7 +3037,7 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
30373037
break;
30383038

30393039
const CBlockIndex *pindexFork;
3040-
std::list<CTransaction> txConflicted;
3040+
std::vector<std::shared_ptr<const CTransaction>> txConflicted;
30413041
bool fInitialDownload;
30423042
{
30433043
LOCK(cs_main);
@@ -3068,9 +3068,9 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
30683068

30693069
// throw all transactions though the signal-interface
30703070
// while _not_ holding the cs_main lock
3071-
BOOST_FOREACH(const CTransaction &tx, txConflicted)
3071+
for(std::shared_ptr<const CTransaction> tx : txConflicted)
30723072
{
3073-
GetMainSignals().SyncTransaction(tx, pindexNewTip, CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK);
3073+
GetMainSignals().SyncTransaction(*tx, pindexNewTip, CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK);
30743074
}
30753075
// ... and about transactions that got confirmed:
30763076
for(unsigned int i = 0; i < txChanged.size(); i++)

src/test/blockencodings_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
8080

8181
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2].GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1);
8282

83-
std::list<CTransaction> removed;
83+
std::vector<std::shared_ptr<const CTransaction>> removed;
8484
pool.removeRecursive(block.vtx[2], &removed);
8585
BOOST_CHECK_EQUAL(removed.size(), 1);
8686

src/test/mempool_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
5555

5656

5757
CTxMemPool testPool(CFeeRate(0));
58-
std::list<CTransaction> removed;
58+
std::vector<std::shared_ptr<const CTransaction>> removed;
5959

6060
// Nothing in pool, remove should do nothing:
6161
testPool.removeRecursive(txParent, &removed);
@@ -547,6 +547,7 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
547547
pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7, &pool));
548548

549549
std::vector<CTransaction> vtx;
550+
std::vector<std::shared_ptr<const CTransaction>> conflicts;
550551
SetMockTime(42);
551552
SetMockTime(42 + CTxMemPool::ROLLING_FEE_HALFLIFE);
552553
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000);

src/txmempool.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void CTxMemPool::CalculateDescendants(txiter entryit, setEntries &setDescendants
503503
}
504504
}
505505

506-
void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list<CTransaction>* removed)
506+
void CTxMemPool::removeRecursive(const CTransaction &origTx, std::vector<std::shared_ptr<const CTransaction>>* removed)
507507
{
508508
// Remove transaction from memory pool
509509
{
@@ -532,7 +532,7 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list<CTransact
532532
}
533533
if (removed) {
534534
BOOST_FOREACH(txiter it, setAllRemoves) {
535-
removed->push_back(it->GetTx());
535+
removed->emplace_back(it->GetSharedTx());
536536
}
537537
}
538538
RemoveStaged(setAllRemoves, false);
@@ -576,7 +576,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
576576
RemoveStaged(setAllRemoves, false);
577577
}
578578

579-
void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>* removed)
579+
void CTxMemPool::removeConflicts(const CTransaction &tx, std::vector<std::shared_ptr<const CTransaction>>* removed)
580580
{
581581
// Remove transactions which depend on inputs of tx, recursively
582582
LOCK(cs);
@@ -597,7 +597,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
597597
* Called when a block is connected. Removes from mempool and updates the miner fee estimator.
598598
*/
599599
void CTxMemPool::removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
600-
std::list<CTransaction>* conflicts, bool fCurrentEstimate)
600+
std::vector<std::shared_ptr<const CTransaction>>* conflicts, bool fCurrentEstimate)
601601
{
602602
LOCK(cs);
603603
std::vector<CTxMemPoolEntry> entries;

src/txmempool.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef BITCOIN_TXMEMPOOL_H
77
#define BITCOIN_TXMEMPOOL_H
88

9-
#include <list>
109
#include <memory>
1110
#include <set>
1211

@@ -521,11 +520,11 @@ class CTxMemPool
521520
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate = true);
522521
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool fCurrentEstimate = true);
523522

524-
void removeRecursive(const CTransaction &tx, std::list<CTransaction>* removed = NULL);
523+
void removeRecursive(const CTransaction &tx, std::vector<std::shared_ptr<const CTransaction>>* removed = NULL);
525524
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
526-
void removeConflicts(const CTransaction &tx, std::list<CTransaction>* removed = NULL);
525+
void removeConflicts(const CTransaction &tx, std::vector<std::shared_ptr<const CTransaction>>* removed = NULL);
527526
void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
528-
std::list<CTransaction>* conflicts = NULL, bool fCurrentEstimate = true);
527+
std::vector<std::shared_ptr<const CTransaction>>* conflicts = NULL, bool fCurrentEstimate = true);
529528
void clear();
530529
void _clear(); //lock free
531530
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);

0 commit comments

Comments
 (0)