From 4100499db4e886d7a9ad2dcf4007ce44fb2c1a62 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 15 Aug 2016 12:57:10 +0200 Subject: Return shared_ptr from mempool removes --- src/main.cpp | 10 +++++----- src/test/blockencodings_tests.cpp | 2 +- src/test/mempool_tests.cpp | 3 ++- src/txmempool.cpp | 8 ++++---- src/txmempool.h | 7 +++---- 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index a60e47504f..0e97b1ea14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2803,7 +2803,7 @@ static int64_t nTimePostConnect = 0; * Connect a new block to chainActive. pblock is either NULL or a pointer to a CBlock * corresponding to pindexNew, to bypass loading it again from disk. */ -bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock, std::list &txConflicted, std::vector> &txChanged) +bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock, std::vector> &txConflicted, std::vector> &txChanged) { assert(pindexNew->pprev == chainActive.Tip()); // Read block from disk. @@ -2926,7 +2926,7 @@ static void PruneBlockIndexCandidates() { * Try to make some progress towards making pindexMostWork the active block. * pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork. */ -static bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool& fInvalidFound, std::list& txConflicted, std::vector>& txChanged) +static bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool& fInvalidFound, std::vector>& txConflicted, std::vector>& txChanged) { AssertLockHeld(cs_main); const CBlockIndex *pindexOldTip = chainActive.Tip(); @@ -3037,7 +3037,7 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, break; const CBlockIndex *pindexFork; - std::list txConflicted; + std::vector> txConflicted; bool fInitialDownload; { LOCK(cs_main); @@ -3068,9 +3068,9 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, // throw all transactions though the signal-interface // while _not_ holding the cs_main lock - BOOST_FOREACH(const CTransaction &tx, txConflicted) + for(std::shared_ptr tx : txConflicted) { - GetMainSignals().SyncTransaction(tx, pindexNewTip, CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK); + GetMainSignals().SyncTransaction(*tx, pindexNewTip, CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK); } // ... and about transactions that got confirmed: for(unsigned int i = 0; i < txChanged.size(); i++) diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp index f3f1befbc0..b0d9184816 100644 --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest) BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2].GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1); - std::list removed; + std::vector> removed; pool.removeRecursive(block.vtx[2], &removed); BOOST_CHECK_EQUAL(removed.size(), 1); diff --git a/src/test/mempool_tests.cpp b/src/test/mempool_tests.cpp index 003daa203f..555d36faac 100644 --- a/src/test/mempool_tests.cpp +++ b/src/test/mempool_tests.cpp @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest) CTxMemPool testPool(CFeeRate(0)); - std::list removed; + std::vector> removed; // Nothing in pool, remove should do nothing: testPool.removeRecursive(txParent, &removed); @@ -547,6 +547,7 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7, &pool)); std::vector vtx; + std::vector> conflicts; SetMockTime(42); SetMockTime(42 + CTxMemPool::ROLLING_FEE_HALFLIFE); BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 193542ee5e..e5d28ac2ea 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -503,7 +503,7 @@ void CTxMemPool::CalculateDescendants(txiter entryit, setEntries &setDescendants } } -void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list* removed) +void CTxMemPool::removeRecursive(const CTransaction &origTx, std::vector>* removed) { // Remove transaction from memory pool { @@ -532,7 +532,7 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, std::listpush_back(it->GetTx()); + removed->emplace_back(it->GetSharedTx()); } } RemoveStaged(setAllRemoves, false); @@ -576,7 +576,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem RemoveStaged(setAllRemoves, false); } -void CTxMemPool::removeConflicts(const CTransaction &tx, std::list* removed) +void CTxMemPool::removeConflicts(const CTransaction &tx, std::vector>* removed) { // Remove transactions which depend on inputs of tx, recursively LOCK(cs); @@ -597,7 +597,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list * Called when a block is connected. Removes from mempool and updates the miner fee estimator. */ void CTxMemPool::removeForBlock(const std::vector& vtx, unsigned int nBlockHeight, - std::list* conflicts, bool fCurrentEstimate) + std::vector>* conflicts, bool fCurrentEstimate) { LOCK(cs); std::vector entries; diff --git a/src/txmempool.h b/src/txmempool.h index 297f5b8e5a..1a7e054e37 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -6,7 +6,6 @@ #ifndef BITCOIN_TXMEMPOOL_H #define BITCOIN_TXMEMPOOL_H -#include #include #include @@ -521,11 +520,11 @@ public: bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate = true); bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool fCurrentEstimate = true); - void removeRecursive(const CTransaction &tx, std::list* removed = NULL); + void removeRecursive(const CTransaction &tx, std::vector>* removed = NULL); void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags); - void removeConflicts(const CTransaction &tx, std::list* removed = NULL); + void removeConflicts(const CTransaction &tx, std::vector>* removed = NULL); void removeForBlock(const std::vector& vtx, unsigned int nBlockHeight, - std::list* conflicts = NULL, bool fCurrentEstimate = true); + std::vector>* conflicts = NULL, bool fCurrentEstimate = true); void clear(); void _clear(); //lock free bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb); -- cgit v1.2.3