Skip to content

Commit 288d85d

Browse files
committed
Get rid of CTxMempool::lookup() entirely
1 parent c2a4724 commit 288d85d

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

src/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,8 +1445,10 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, const Consensus::P
14451445

14461446
LOCK(cs_main);
14471447

1448-
if (mempool.lookup(hash, txOut))
1448+
std::shared_ptr<const CTransaction> ptx = mempool.get(hash);
1449+
if (ptx)
14491450
{
1451+
txOut = *ptx;
14501452
return true;
14511453
}
14521454

src/test/policyestimator_tests.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
7474
// 9/10 blocks add 2nd highest and so on until ...
7575
// 1/10 blocks add lowest fee/pri transactions
7676
while (txHashes[9-h].size()) {
77-
CTransaction btx;
78-
if (mpool.lookup(txHashes[9-h].back(), btx))
79-
block.push_back(btx);
77+
std::shared_ptr<const CTransaction> ptx = mpool.get(txHashes[9-h].back());
78+
if (ptx)
79+
block.push_back(*ptx);
8080
txHashes[9-h].pop_back();
8181
}
8282
}
@@ -160,9 +160,9 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
160160
// Estimates should still not be below original
161161
for (int j = 0; j < 10; j++) {
162162
while(txHashes[j].size()) {
163-
CTransaction btx;
164-
if (mpool.lookup(txHashes[j].back(), btx))
165-
block.push_back(btx);
163+
std::shared_ptr<const CTransaction> ptx = mpool.get(txHashes[j].back());
164+
if (ptx)
165+
block.push_back(*ptx);
166166
txHashes[j].pop_back();
167167
}
168168
}
@@ -181,9 +181,9 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
181181
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
182182
uint256 hash = tx.GetHash();
183183
mpool.addUnchecked(hash, entry.Fee(feeV[k/4][j]).Time(GetTime()).Priority(priV[k/4][j]).Height(blocknum).FromTx(tx, &mpool));
184-
CTransaction btx;
185-
if (mpool.lookup(hash, btx))
186-
block.push_back(btx);
184+
std::shared_ptr<const CTransaction> ptx = mpool.get(hash);
185+
if (ptx)
186+
block.push_back(*ptx);
187187
}
188188
}
189189
mpool.removeForBlock(block, ++blocknum, dummyConflicted);

src/txmempool.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -831,16 +831,6 @@ std::shared_ptr<const CTransaction> CTxMemPool::get(const uint256& hash) const
831831
return i->GetSharedTx();
832832
}
833833

834-
bool CTxMemPool::lookup(uint256 hash, CTransaction& result) const
835-
{
836-
auto tx = get(hash);
837-
if (tx) {
838-
result = *tx;
839-
return true;
840-
}
841-
return false;
842-
}
843-
844834
TxMempoolInfo CTxMemPool::info(const uint256& hash) const
845835
{
846836
LOCK(cs);
@@ -960,9 +950,9 @@ bool CCoinsViewMemPool::GetCoins(const uint256 &txid, CCoins &coins) const {
960950
// If an entry in the mempool exists, always return that one, as it's guaranteed to never
961951
// conflict with the underlying cache, and it cannot have pruned entries (as it contains full)
962952
// transactions. First checking the underlying cache risks returning a pruned entry instead.
963-
CTransaction tx;
964-
if (mempool.lookup(txid, tx)) {
965-
coins = CCoins(tx, MEMPOOL_HEIGHT);
953+
shared_ptr<const CTransaction> ptx = mempool.get(txid);
954+
if (ptx) {
955+
coins = CCoins(*ptx, MEMPOOL_HEIGHT);
966956
return true;
967957
}
968958
return (base->GetCoins(txid, coins) && !coins.IsPruned());

src/txmempool.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ class CTxMemPool
607607
return (mapTx.count(hash) != 0);
608608
}
609609

610-
bool lookup(uint256 hash, CTransaction& result) const;
611610
std::shared_ptr<const CTransaction> get(const uint256& hash) const;
612611
TxMempoolInfo info(const uint256& hash) const;
613612
std::vector<TxMempoolInfo> infoAll() const;

0 commit comments

Comments
 (0)