Skip to content

Commit

Permalink
Get rid of CTxMempool::lookup() entirely
Browse files Browse the repository at this point in the history
Coming from btc@288d85ddf2e0a0c9d25a23db56052883170466d0
  • Loading branch information
furszy committed Dec 31, 2020
1 parent be823f8 commit c4fb8d9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
18 changes: 9 additions & 9 deletions src/test/policyestimator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
// 9/10 blocks add 2nd highest and so on until ...
// 1/10 blocks add lowest fee transactions
while (txHashes[9-h].size()) {
CTransaction btx;
if (mpool.lookup(txHashes[9-h].back(), btx))
block.push_back(std::make_shared<const CTransaction>(btx));
CTransactionRef ptx = mpool.get(txHashes[9-h].back());
if (ptx)
block.emplace_back(ptx);
txHashes[9-h].pop_back();
}
}
Expand Down Expand Up @@ -144,9 +144,9 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
// Estimates should still not be below original
for (int j = 0; j < 10; j++) {
while(txHashes[j].size()) {
CTransaction btx;
if (mpool.lookup(txHashes[j].back(), btx))
block.push_back(std::make_shared<const CTransaction>(btx));
CTransactionRef ptx = mpool.get(txHashes[j].back());
if (ptx)
block.emplace_back(ptx);
txHashes[j].pop_back();
}
}
Expand All @@ -164,9 +164,9 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
uint256 hash = tx.GetHash();
mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Priority(0).Height(blocknum).FromTx(tx, &mpool));
CTransaction btx;
if (mpool.lookup(hash, btx))
block.push_back(std::make_shared<const CTransaction>(btx));
CTransactionRef ptx = mpool.get(hash);
if (ptx)
block.emplace_back(ptx);
}
}
mpool.removeForBlock(block, ++blocknum, dummyConflicted);
Expand Down
18 changes: 4 additions & 14 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,16 +903,6 @@ std::shared_ptr<const CTransaction> CTxMemPool::get(const uint256& hash) const
return i->GetSharedTx();
}

bool CTxMemPool::lookup(uint256 hash, CTransaction& result) const
{
auto tx = get(hash);
if (tx) {
result = *tx;
return true;
}
return false;
}

TxMempoolInfo CTxMemPool::info(const uint256& hash) const
{
LOCK(cs);
Expand Down Expand Up @@ -1038,10 +1028,10 @@ bool CCoinsViewMemPool::GetCoin(const COutPoint& outpoint, Coin& coin) const
// If an entry in the mempool exists, always return that one, as it's guaranteed to never
// conflict with the underlying cache, and it cannot have pruned entries (as it contains full)
// transactions. First checking the underlying cache risks returning a pruned entry instead.
CTransaction tx;
if (mempool.lookup(outpoint.hash, tx)) {
if (outpoint.n < tx.vout.size()) {
coin = Coin(tx.vout[outpoint.n], MEMPOOL_HEIGHT, false, false);
CTransactionRef ptx = mempool.get(outpoint.hash);
if (ptx) {
if (outpoint.n < ptx->vout.size()) {
coin = Coin(ptx->vout[outpoint.n], MEMPOOL_HEIGHT, false, false);
return true;
} else {
return false;
Expand Down
1 change: 0 additions & 1 deletion src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ class CTxMemPool
return (it != mapTx.end() && outpoint.n < it->GetTx().vout.size());
}

bool lookup(uint256 hash, CTransaction& result) const;
CTransactionRef get(const uint256& hash) const;
TxMempoolInfo info(const uint256& hash) const;
std::vector<TxMempoolInfo> infoAll() const;
Expand Down
5 changes: 4 additions & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,10 @@ bool GetTransaction(const uint256& hash, CTransaction& txOut, uint256& hashBlock
LOCK(cs_main);

if (!blockIndex) {
if (mempool.lookup(hash, txOut)) {

CTransactionRef ptx = mempool.get(hash);
if (ptx) {
txOut = *ptx;
return true;
}

Expand Down

0 comments on commit c4fb8d9

Please sign in to comment.