Browse Source

Return shared_ptr<CTransaction> from mempool removes

0.14
Pieter Wuille 8 years ago
parent
commit
4100499db4
  1. 10
      src/main.cpp
  2. 2
      src/test/blockencodings_tests.cpp
  3. 3
      src/test/mempool_tests.cpp
  4. 8
      src/txmempool.cpp
  5. 7
      src/txmempool.h

10
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 * 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. * 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<CTransaction> &txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*,int>> &txChanged) 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)
{ {
assert(pindexNew->pprev == chainActive.Tip()); assert(pindexNew->pprev == chainActive.Tip());
// Read block from disk. // Read block from disk.
@ -2926,7 +2926,7 @@ static void PruneBlockIndexCandidates() {
* Try to make some progress towards making pindexMostWork the active block. * Try to make some progress towards making pindexMostWork the active block.
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork. * 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<CTransaction>& txConflicted, std::vector<std::tuple<CTransaction,CBlockIndex*,int>>& txChanged) 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)
{ {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
const CBlockIndex *pindexOldTip = chainActive.Tip(); const CBlockIndex *pindexOldTip = chainActive.Tip();
@ -3037,7 +3037,7 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
break; break;
const CBlockIndex *pindexFork; const CBlockIndex *pindexFork;
std::list<CTransaction> txConflicted; std::vector<std::shared_ptr<const CTransaction>> txConflicted;
bool fInitialDownload; bool fInitialDownload;
{ {
LOCK(cs_main); LOCK(cs_main);
@ -3068,9 +3068,9 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
// throw all transactions though the signal-interface // throw all transactions though the signal-interface
// while _not_ holding the cs_main lock // while _not_ holding the cs_main lock
BOOST_FOREACH(const CTransaction &tx, txConflicted) for(std::shared_ptr<const CTransaction> 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: // ... and about transactions that got confirmed:
for(unsigned int i = 0; i < txChanged.size(); i++) for(unsigned int i = 0; i < txChanged.size(); i++)

2
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); BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2].GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1);
std::list<CTransaction> removed; std::vector<std::shared_ptr<const CTransaction>> removed;
pool.removeRecursive(block.vtx[2], &removed); pool.removeRecursive(block.vtx[2], &removed);
BOOST_CHECK_EQUAL(removed.size(), 1); BOOST_CHECK_EQUAL(removed.size(), 1);

3
src/test/mempool_tests.cpp

@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
CTxMemPool testPool(CFeeRate(0)); CTxMemPool testPool(CFeeRate(0));
std::list<CTransaction> removed; std::vector<std::shared_ptr<const CTransaction>> removed;
// Nothing in pool, remove should do nothing: // Nothing in pool, remove should do nothing:
testPool.removeRecursive(txParent, &removed); testPool.removeRecursive(txParent, &removed);
@ -547,6 +547,7 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7, &pool)); pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7, &pool));
std::vector<CTransaction> vtx; std::vector<CTransaction> vtx;
std::vector<std::shared_ptr<const CTransaction>> conflicts;
SetMockTime(42); SetMockTime(42);
SetMockTime(42 + CTxMemPool::ROLLING_FEE_HALFLIFE); SetMockTime(42 + CTxMemPool::ROLLING_FEE_HALFLIFE);
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000); BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000);

8
src/txmempool.cpp

@ -503,7 +503,7 @@ void CTxMemPool::CalculateDescendants(txiter entryit, setEntries &setDescendants
} }
} }
void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list<CTransaction>* removed) void CTxMemPool::removeRecursive(const CTransaction &origTx, std::vector<std::shared_ptr<const CTransaction>>* removed)
{ {
// Remove transaction from memory pool // Remove transaction from memory pool
{ {
@ -532,7 +532,7 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, std::list<CTransact
} }
if (removed) { if (removed) {
BOOST_FOREACH(txiter it, setAllRemoves) { BOOST_FOREACH(txiter it, setAllRemoves) {
removed->push_back(it->GetTx()); removed->emplace_back(it->GetSharedTx());
} }
} }
RemoveStaged(setAllRemoves, false); RemoveStaged(setAllRemoves, false);
@ -576,7 +576,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
RemoveStaged(setAllRemoves, false); RemoveStaged(setAllRemoves, false);
} }
void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>* removed) void CTxMemPool::removeConflicts(const CTransaction &tx, std::vector<std::shared_ptr<const CTransaction>>* removed)
{ {
// Remove transactions which depend on inputs of tx, recursively // Remove transactions which depend on inputs of tx, recursively
LOCK(cs); LOCK(cs);
@ -597,7 +597,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
* Called when a block is connected. Removes from mempool and updates the miner fee estimator. * Called when a block is connected. Removes from mempool and updates the miner fee estimator.
*/ */
void CTxMemPool::removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight, void CTxMemPool::removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
std::list<CTransaction>* conflicts, bool fCurrentEstimate) std::vector<std::shared_ptr<const CTransaction>>* conflicts, bool fCurrentEstimate)
{ {
LOCK(cs); LOCK(cs);
std::vector<CTxMemPoolEntry> entries; std::vector<CTxMemPoolEntry> entries;

7
src/txmempool.h

@ -6,7 +6,6 @@
#ifndef BITCOIN_TXMEMPOOL_H #ifndef BITCOIN_TXMEMPOOL_H
#define BITCOIN_TXMEMPOOL_H #define BITCOIN_TXMEMPOOL_H
#include <list>
#include <memory> #include <memory>
#include <set> #include <set>
@ -521,11 +520,11 @@ public:
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate = true); bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool fCurrentEstimate = true);
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool fCurrentEstimate = true); bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool fCurrentEstimate = true);
void removeRecursive(const CTransaction &tx, std::list<CTransaction>* removed = NULL); void removeRecursive(const CTransaction &tx, std::vector<std::shared_ptr<const CTransaction>>* removed = NULL);
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags); void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
void removeConflicts(const CTransaction &tx, std::list<CTransaction>* removed = NULL); void removeConflicts(const CTransaction &tx, std::vector<std::shared_ptr<const CTransaction>>* removed = NULL);
void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight, void removeForBlock(const std::vector<CTransaction>& vtx, unsigned int nBlockHeight,
std::list<CTransaction>* conflicts = NULL, bool fCurrentEstimate = true); std::vector<std::shared_ptr<const CTransaction>>* conflicts = NULL, bool fCurrentEstimate = true);
void clear(); void clear();
void _clear(); //lock free void _clear(); //lock free
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb); bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);

Loading…
Cancel
Save