Skip to content

Commit

Permalink
remove external usage of mempool conflict tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
morcos authored and furszy committed Jan 28, 2021
1 parent ef429af commit 76c72c6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/test/mempool_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
/* after tx6 is mined, tx7 should move up in the sort */
std::vector<CTransactionRef> vtx;
vtx.emplace_back(MakeTransactionRef(tx6));
pool.removeForBlock(vtx, 1, nullptr, false);
pool.removeForBlock(vtx, 1);

sortedOrder.erase(sortedOrder.begin()+1);
// Ties are broken by hash
Expand Down
6 changes: 2 additions & 4 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,11 @@ void CTxMemPool::AddTransactionsUpdated(unsigned int n)
nTransactionsUpdated += n;
}


bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool fCurrentEstimate)
{
// Add to memory pool without checking anything.
// Used by AcceptToMemoryPool(), which DOES do all the appropriate checks.
LOCK(cs);

indexed_transaction_set::iterator newit = mapTx.insert(entry).first;
mapLinks.insert(make_pair(newit, TxLinks()));

Expand Down Expand Up @@ -606,7 +604,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.
*/
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight,
std::vector<CTransactionRef>* conflicts, bool fCurrentEstimate)
bool fCurrentEstimate)
{
LOCK(cs);
std::vector<CTxMemPoolEntry> entries;
Expand All @@ -623,7 +621,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
stage.insert(it);
RemoveStaged(stage, true);
}
removeConflicts(*tx, conflicts);
removeConflicts(*tx);
ClearPrioritisation(tx->GetHash());
}
// After the txs in the new block have been removed from the mempool, update policy estimates
Expand Down
2 changes: 1 addition & 1 deletion src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class CTxMemPool
void removeWithAnchor(const uint256& invalidRoot);
void removeConflicts(const CTransaction& tx, std::vector<CTransactionRef>* removed = nullptr);
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight,
std::vector<CTransactionRef>* conflicts = nullptr, bool fCurrentEstimate = true);
bool fCurrentEstimate = true);
void clear();
void _clear(); // lock-free
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
Expand Down
11 changes: 3 additions & 8 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2023,11 +2023,10 @@ static int64_t nTimeChainState = 0;
static int64_t nTimePostConnect = 0;

/**
* Used to track conflicted transactions removed from mempool and transactions
* applied to the UTXO state as a part of a single ActivateBestChainStep call.
* Used to track blocks whose transactions were applied to the UTXO state as a
* part of a single ActivateBestChainStep call.
*/
struct ConnectTrace {
std::vector<CTransactionRef> txConflicted;
std::vector<std::pair<CBlockIndex*, std::shared_ptr<const CBlock> > > blocksConnected;
};

Expand Down Expand Up @@ -2092,7 +2091,7 @@ bool static ConnectTip(CValidationState& state, CBlockIndex* pindexNew, const st
LogPrint(BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs]\n", (nTime5 - nTime4) * 0.001, nTimeChainState * 0.000001);

// 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.
UpdateTip(pindexNew);
// Update MN manager cache
Expand Down Expand Up @@ -2305,10 +2304,6 @@ bool ActivateBestChain(CValidationState& state, std::shared_ptr<const CBlock> pb
fInitialDownload = IsInitialBlockDownload();

// throw all transactions though the signal-interface
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) {
assert(pair.second);
const CBlock& block = *(pair.second);
Expand Down

0 comments on commit 76c72c6

Please sign in to comment.