Skip to content

Commit

Permalink
Merge bitcoin#29260: refactor: remove CTxMemPool::queryHashes()
Browse files Browse the repository at this point in the history
282b12d refactor: remove CTxMemPool::queryHashes() (stickies-v)

Pull request description:

  `CTxMemPool::queryHashes()` is only used in `MempoolToJSON()`, where it can just as easily be replaced with the more general `CTxMemPool::entryAll()`. No behaviour change, just cleans up the code.

ACKs for top commit:
  dergoegge:
    Code review ACK 282b12d
  TheCharlatan:
    ACK 282b12d
  glozow:
    ACK 282b12d. Looks like there's no conflicts.

Tree-SHA512: 16160dec8e1f2457fa0f62dc96d2d2efd92c4bab810ecdb0e08918b8e85a667702c8e41421eeb4ea6abe92a5956a2a39a7a6368514973b78be0d22de2ad299b2
  • Loading branch information
glozow committed Jan 22, 2024
2 parents 0375244 + 282b12d commit 651fb03
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 23 deletions.
10 changes: 4 additions & 6 deletions src/rpc/mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,15 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempoo
}
return o;
} else {
UniValue a(UniValue::VARR);
uint64_t mempool_sequence;
std::vector<uint256> vtxid;
{
LOCK(pool.cs);
pool.queryHashes(vtxid);
for (const CTxMemPoolEntry& e : pool.entryAll()) {
a.push_back(e.GetTx().GetHash().ToString());
}
mempool_sequence = pool.GetSequence();
}
UniValue a(UniValue::VARR);
for (const uint256& hash : vtxid)
a.push_back(hash.ToString());

if (!include_mempool_sequence) {
return a;
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/test/fuzz/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, Cha
if (!info_all.empty()) {
const auto& tx_to_remove = *PickValue(fuzzed_data_provider, info_all).tx;
WITH_LOCK(tx_pool.cs, tx_pool.removeRecursive(tx_to_remove, MemPoolRemovalReason::BLOCK /* dummy */));
std::vector<uint256> all_txids;
tx_pool.queryHashes(all_txids);
assert(all_txids.size() < info_all.size());
assert(tx_pool.size() < info_all.size());
WITH_LOCK(::cs_main, tx_pool.check(chainstate.CoinsTip(), chainstate.m_chain.Height() + 1));
}
SyncWithValidationInterfaceQueue();
Expand Down
13 changes: 0 additions & 13 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,19 +803,6 @@ std::vector<CTxMemPool::indexed_transaction_set::const_iterator> CTxMemPool::Get
return iters;
}

void CTxMemPool::queryHashes(std::vector<uint256>& vtxid) const
{
LOCK(cs);
auto iters = GetSortedDepthAndScore();

vtxid.clear();
vtxid.reserve(mapTx.size());

for (auto it : iters) {
vtxid.push_back(it->GetTx().GetHash());
}
}

static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it) {
return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
}
Expand Down
1 change: 0 additions & 1 deletion src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ class CTxMemPool
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs);

bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb, bool wtxid=false);
void queryHashes(std::vector<uint256>& vtxid) const;
bool isSpent(const COutPoint& outpoint) const;
unsigned int GetTransactionsUpdated() const;
void AddTransactionsUpdated(unsigned int n);
Expand Down

0 comments on commit 651fb03

Please sign in to comment.