Browse Source

Merge #9240: Remove txConflicted

a874ab5 remove internal tracking of mempool conflicts for reporting to wallet (Alex Morcos)
bf663f8 remove external usage of mempool conflict tracking (Alex Morcos)
0.14
Pieter Wuille 8 years ago
parent
commit
a1dcf2e108
No known key found for this signature in database
GPG Key ID: DBA1A67379A1A931
  1. 6
      src/test/blockencodings_tests.cpp
  2. 42
      src/test/mempool_tests.cpp
  3. 15
      src/txmempool.cpp
  4. 6
      src/txmempool.h
  5. 12
      src/validation.cpp

6
src/test/blockencodings_tests.cpp

@ -80,9 +80,9 @@ 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::vector<CTransactionRef> removed; size_t poolSize = pool.size();
pool.removeRecursive(*block.vtx[2], &removed); pool.removeRecursive(*block.vtx[2]);
BOOST_CHECK_EQUAL(removed.size(), 1); BOOST_CHECK_EQUAL(pool.size(), poolSize - 1);
CBlock block2; CBlock block2;
std::vector<CTransactionRef> vtx_missing; std::vector<CTransactionRef> vtx_missing;

42
src/test/mempool_tests.cpp

@ -55,17 +55,17 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
CTxMemPool testPool(CFeeRate(0)); CTxMemPool testPool(CFeeRate(0));
std::vector<CTransactionRef> removed;
// Nothing in pool, remove should do nothing: // Nothing in pool, remove should do nothing:
testPool.removeRecursive(txParent, &removed); unsigned int poolSize = testPool.size();
BOOST_CHECK_EQUAL(removed.size(), 0); testPool.removeRecursive(txParent);
BOOST_CHECK_EQUAL(testPool.size(), poolSize);
// Just the parent: // Just the parent:
testPool.addUnchecked(txParent.GetHash(), entry.FromTx(txParent)); testPool.addUnchecked(txParent.GetHash(), entry.FromTx(txParent));
testPool.removeRecursive(txParent, &removed); poolSize = testPool.size();
BOOST_CHECK_EQUAL(removed.size(), 1); testPool.removeRecursive(txParent);
removed.clear(); BOOST_CHECK_EQUAL(testPool.size(), poolSize - 1);
// Parent, children, grandchildren: // Parent, children, grandchildren:
testPool.addUnchecked(txParent.GetHash(), entry.FromTx(txParent)); testPool.addUnchecked(txParent.GetHash(), entry.FromTx(txParent));
@ -75,19 +75,21 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
testPool.addUnchecked(txGrandChild[i].GetHash(), entry.FromTx(txGrandChild[i])); testPool.addUnchecked(txGrandChild[i].GetHash(), entry.FromTx(txGrandChild[i]));
} }
// Remove Child[0], GrandChild[0] should be removed: // Remove Child[0], GrandChild[0] should be removed:
testPool.removeRecursive(txChild[0], &removed); poolSize = testPool.size();
BOOST_CHECK_EQUAL(removed.size(), 2); testPool.removeRecursive(txChild[0]);
removed.clear(); BOOST_CHECK_EQUAL(testPool.size(), poolSize - 2);
// ... make sure grandchild and child are gone: // ... make sure grandchild and child are gone:
testPool.removeRecursive(txGrandChild[0], &removed); poolSize = testPool.size();
BOOST_CHECK_EQUAL(removed.size(), 0); testPool.removeRecursive(txGrandChild[0]);
testPool.removeRecursive(txChild[0], &removed); BOOST_CHECK_EQUAL(testPool.size(), poolSize);
BOOST_CHECK_EQUAL(removed.size(), 0); poolSize = testPool.size();
testPool.removeRecursive(txChild[0]);
BOOST_CHECK_EQUAL(testPool.size(), poolSize);
// Remove parent, all children/grandchildren should go: // Remove parent, all children/grandchildren should go:
testPool.removeRecursive(txParent, &removed); poolSize = testPool.size();
BOOST_CHECK_EQUAL(removed.size(), 5); testPool.removeRecursive(txParent);
BOOST_CHECK_EQUAL(testPool.size(), poolSize - 5);
BOOST_CHECK_EQUAL(testPool.size(), 0); BOOST_CHECK_EQUAL(testPool.size(), 0);
removed.clear();
// Add children and grandchildren, but NOT the parent (simulate the parent being in a block) // Add children and grandchildren, but NOT the parent (simulate the parent being in a block)
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
@ -97,10 +99,10 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
} }
// Now remove the parent, as might happen if a block-re-org occurs but the parent cannot be // Now remove the parent, as might happen if a block-re-org occurs but the parent cannot be
// put into the mempool (maybe because it is non-standard): // put into the mempool (maybe because it is non-standard):
testPool.removeRecursive(txParent, &removed); poolSize = testPool.size();
BOOST_CHECK_EQUAL(removed.size(), 6); testPool.removeRecursive(txParent);
BOOST_CHECK_EQUAL(testPool.size(), poolSize - 6);
BOOST_CHECK_EQUAL(testPool.size(), 0); BOOST_CHECK_EQUAL(testPool.size(), 0);
removed.clear();
} }
template<typename name> template<typename name>
@ -412,7 +414,7 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
/* after tx6 is mined, tx7 should move up in the sort */ /* after tx6 is mined, tx7 should move up in the sort */
std::vector<CTransactionRef> vtx; std::vector<CTransactionRef> vtx;
vtx.push_back(MakeTransactionRef(tx6)); vtx.push_back(MakeTransactionRef(tx6));
pool.removeForBlock(vtx, 1, NULL, false); pool.removeForBlock(vtx, 1);
sortedOrder.erase(sortedOrder.begin()+1); sortedOrder.erase(sortedOrder.begin()+1);
sortedOrder.pop_back(); sortedOrder.pop_back();

15
src/txmempool.cpp

@ -503,7 +503,7 @@ void CTxMemPool::CalculateDescendants(txiter entryit, setEntries &setDescendants
} }
} }
void CTxMemPool::removeRecursive(const CTransaction &origTx, std::vector<CTransactionRef>* removed) void CTxMemPool::removeRecursive(const CTransaction &origTx)
{ {
// Remove transaction from memory pool // Remove transaction from memory pool
{ {
@ -530,11 +530,6 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, std::vector<CTransa
BOOST_FOREACH(txiter it, txToRemove) { BOOST_FOREACH(txiter it, txToRemove) {
CalculateDescendants(it, setAllRemoves); CalculateDescendants(it, setAllRemoves);
} }
if (removed) {
BOOST_FOREACH(txiter it, setAllRemoves) {
removed->emplace_back(it->GetSharedTx());
}
}
RemoveStaged(setAllRemoves, false); RemoveStaged(setAllRemoves, false);
} }
} }
@ -576,7 +571,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
RemoveStaged(setAllRemoves, false); RemoveStaged(setAllRemoves, false);
} }
void CTxMemPool::removeConflicts(const CTransaction &tx, std::vector<CTransactionRef>* removed) void CTxMemPool::removeConflicts(const CTransaction &tx)
{ {
// Remove transactions which depend on inputs of tx, recursively // Remove transactions which depend on inputs of tx, recursively
LOCK(cs); LOCK(cs);
@ -586,7 +581,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::vector<CTransactio
const CTransaction &txConflict = *it->second; const CTransaction &txConflict = *it->second;
if (txConflict != tx) if (txConflict != tx)
{ {
removeRecursive(txConflict, removed); removeRecursive(txConflict);
ClearPrioritisation(txConflict.GetHash()); ClearPrioritisation(txConflict.GetHash());
} }
} }
@ -597,7 +592,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::vector<CTransactio
* 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<CTransactionRef>& vtx, unsigned int nBlockHeight, void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight,
std::vector<CTransactionRef>* conflicts, bool fCurrentEstimate) bool fCurrentEstimate)
{ {
LOCK(cs); LOCK(cs);
std::vector<CTxMemPoolEntry> entries; std::vector<CTxMemPoolEntry> entries;
@ -617,7 +612,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
stage.insert(it); stage.insert(it);
RemoveStaged(stage, true); RemoveStaged(stage, true);
} }
removeConflicts(*tx, conflicts); removeConflicts(*tx);
ClearPrioritisation(tx->GetHash()); ClearPrioritisation(tx->GetHash());
} }
// After the txs in the new block have been removed from the mempool, update policy estimates // After the txs in the new block have been removed from the mempool, update policy estimates

6
src/txmempool.h

@ -527,11 +527,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::vector<CTransactionRef>* removed = NULL); void removeRecursive(const CTransaction &tx);
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::vector<CTransactionRef>* removed = NULL); void removeConflicts(const CTransaction &tx);
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight, void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight,
std::vector<CTransactionRef>* conflicts = NULL, bool fCurrentEstimate = true); 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);

12
src/validation.cpp

@ -2145,11 +2145,10 @@ static int64_t nTimeChainState = 0;
static int64_t nTimePostConnect = 0; static int64_t nTimePostConnect = 0;
/** /**
* Used to track conflicted transactions removed from mempool and transactions * Used to track blocks whose transactions were applied to the UTXO state as a
* applied to the UTXO state as a part of a single ActivateBestChainStep call. * part of a single ActivateBestChainStep call.
*/ */
struct ConnectTrace { struct ConnectTrace {
std::vector<CTransactionRef> txConflicted;
std::vector<std::pair<CBlockIndex*, std::shared_ptr<const CBlock> > > blocksConnected; std::vector<std::pair<CBlockIndex*, std::shared_ptr<const CBlock> > > blocksConnected;
}; };
@ -2200,7 +2199,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4; int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
LogPrint("bench", " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001); LogPrint("bench", " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001);
// Remove conflicting transactions from the mempool.; // Remove conflicting transactions from the mempool.;
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, &connectTrace.txConflicted, !IsInitialBlockDownload()); mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, !IsInitialBlockDownload());
// Update chainActive & related variables. // Update chainActive & related variables.
UpdateTip(pindexNew, chainparams); UpdateTip(pindexNew, chainparams);
@ -2425,11 +2424,6 @@ 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
for (const auto& tx : connectTrace.txConflicted)
{
GetMainSignals().SyncTransaction(*tx, pindexNewTip, CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK);
}
// ... and about transactions that got confirmed:
for (const auto& pair : connectTrace.blocksConnected) { for (const auto& pair : connectTrace.blocksConnected) {
assert(pair.second); assert(pair.second);
const CBlock& block = *(pair.second); const CBlock& block = *(pair.second);

Loading…
Cancel
Save