Skip to content

Commit 10b7a6d

Browse files
committed
refactor: make txmempool interface use GenTxid
1 parent 5c124e1 commit 10b7a6d

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/net_processing.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ bool static AlreadyHave(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LO
14531453
if (g_recent_confirmed_transactions->contains(inv.hash)) return true;
14541454
}
14551455

1456-
return recentRejects->contains(inv.hash) || mempool.exists(inv.hash, inv.IsMsgWtx());
1456+
return recentRejects->contains(inv.hash) || mempool.exists(ToGenTxid(inv));
14571457
}
14581458
case MSG_BLOCK:
14591459
case MSG_WITNESS_BLOCK:
@@ -1673,7 +1673,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
16731673
//! Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed).
16741674
CTransactionRef static FindTxForGetData(const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main)
16751675
{
1676-
auto txinfo = mempool.info(gtxid.GetHash(), gtxid.IsWtxid());
1676+
auto txinfo = mempool.info(gtxid);
16771677
if (txinfo.tx) {
16781678
// If a TX could have been INVed in reply to a MEMPOOL request,
16791679
// or is older than UNCONDITIONAL_RELAY_DELAY, permit the request
@@ -4358,14 +4358,15 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
43584358
std::set<uint256>::iterator it = vInvTx.back();
43594359
vInvTx.pop_back();
43604360
uint256 hash = *it;
4361+
CInv inv(state.m_wtxid_relay ? MSG_WTX : MSG_TX, hash);
43614362
// Remove it from the to-be-sent set
43624363
pto->m_tx_relay->setInventoryTxToSend.erase(it);
43634364
// Check if not in the filter already
43644365
if (pto->m_tx_relay->filterInventoryKnown.contains(hash)) {
43654366
continue;
43664367
}
43674368
// Not in the mempool anymore? don't bother sending it.
4368-
auto txinfo = m_mempool.info(hash, state.m_wtxid_relay);
4369+
auto txinfo = m_mempool.info(ToGenTxid(inv));
43694370
if (!txinfo.tx) {
43704371
continue;
43714372
}
@@ -4378,7 +4379,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
43784379
if (pto->m_tx_relay->pfilter && !pto->m_tx_relay->pfilter->IsRelevantAndUpdate(*txinfo.tx)) continue;
43794380
// Send
43804381
State(pto->GetId())->m_recently_announced_invs.insert(hash);
4381-
vInv.push_back(CInv(state.m_wtxid_relay ? MSG_WTX : MSG_TX, hash));
4382+
vInv.push_back(inv);
43824383
nRelayedTransactions++;
43834384
{
43844385
// Expire old relay messages

src/txmempool.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -811,15 +811,17 @@ CTransactionRef CTxMemPool::get(const uint256& hash) const
811811
return i->GetSharedTx();
812812
}
813813

814-
TxMempoolInfo CTxMemPool::info(const uint256& hash, bool wtxid) const
814+
TxMempoolInfo CTxMemPool::info(const GenTxid& gtxid) const
815815
{
816816
LOCK(cs);
817-
indexed_transaction_set::const_iterator i = (wtxid ? get_iter_from_wtxid(hash) : mapTx.find(hash));
817+
indexed_transaction_set::const_iterator i = (gtxid.IsWtxid() ? get_iter_from_wtxid(gtxid.GetHash()) : mapTx.find(gtxid.GetHash()));
818818
if (i == mapTx.end())
819819
return TxMempoolInfo();
820820
return GetInfo(i);
821821
}
822822

823+
TxMempoolInfo CTxMemPool::info(const uint256& txid) const { return info(GenTxid{false, txid}); }
824+
823825
void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta)
824826
{
825827
{

src/txmempool.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -716,22 +716,24 @@ class CTxMemPool
716716
return totalTxSize;
717717
}
718718

719-
bool exists(const uint256& hash, bool wtxid=false) const
719+
bool exists(const GenTxid& gtxid) const
720720
{
721721
LOCK(cs);
722-
if (wtxid) {
723-
return (mapTx.get<index_by_wtxid>().count(hash) != 0);
722+
if (gtxid.IsWtxid()) {
723+
return (mapTx.get<index_by_wtxid>().count(gtxid.GetHash()) != 0);
724724
}
725-
return (mapTx.count(hash) != 0);
725+
return (mapTx.count(gtxid.GetHash()) != 0);
726726
}
727+
bool exists(const uint256& txid) const { return exists(GenTxid{false, txid}); }
727728

728729
CTransactionRef get(const uint256& hash) const;
729730
txiter get_iter_from_wtxid(const uint256& wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
730731
{
731732
AssertLockHeld(cs);
732733
return mapTx.project<0>(mapTx.get<index_by_wtxid>().find(wtxid));
733734
}
734-
TxMempoolInfo info(const uint256& hash, bool wtxid=false) const;
735+
TxMempoolInfo info(const uint256& hash) const;
736+
TxMempoolInfo info(const GenTxid& gtxid) const;
735737
std::vector<TxMempoolInfo> infoAll() const;
736738

737739
size_t DynamicMemoryUsage() const;

0 commit comments

Comments
 (0)