Skip to content

Commit c876a89

Browse files
Replace GenTxid with Txid/Wtxid overloads in txmempool
Co-authored-by: stickies-v <[email protected]>
1 parent de858ce commit c876a89

20 files changed

+95
-91
lines changed

src/interfaces/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class Chain
208208
virtual RBFTransactionState isRBFOptIn(const CTransaction& tx) = 0;
209209

210210
//! Check if transaction is in mempool.
211-
virtual bool isInMempool(const uint256& txid) = 0;
211+
virtual bool isInMempool(const Txid& txid) = 0;
212212

213213
//! Check if transaction has descendants in mempool.
214214
virtual bool hasDescendantsInMempool(const uint256& txid) = 0;

src/net_processing.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ class PeerManagerImpl final : public PeerManager
947947
std::atomic<std::chrono::seconds> m_last_tip_update{0s};
948948

949949
/** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
950-
CTransactionRef FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxid& gtxid)
950+
CTransactionRef FindTxForGetData(const Peer::TxRelay& tx_relay, const CInv& inv)
951951
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, NetEventsInterface::g_msgproc_mutex);
952952

953953
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc)
@@ -2391,10 +2391,15 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
23912391
}
23922392
}
23932393

2394-
CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxid& gtxid)
2394+
CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay, const CInv& inv)
23952395
{
2396+
auto gtxid{ToGenTxid(inv).ToVariant()};
23962397
// If a tx was in the mempool prior to the last INV for this peer, permit the request.
2397-
auto txinfo = m_mempool.info_for_relay(gtxid, tx_relay.m_last_inv_sequence);
2398+
auto txinfo{std::visit(
2399+
[&](const auto& id) EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_msgproc_mutex) {
2400+
return m_mempool.info_for_relay(id, tx_relay.m_last_inv_sequence);
2401+
},
2402+
gtxid)};
23982403
if (txinfo.tx) {
23992404
return std::move(txinfo.tx);
24002405
}
@@ -2403,7 +2408,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay,
24032408
{
24042409
LOCK(m_most_recent_block_mutex);
24052410
if (m_most_recent_block_txs != nullptr) {
2406-
auto it = m_most_recent_block_txs->find(gtxid.GetHash());
2411+
auto it = m_most_recent_block_txs->find(gtxid.ToUint256());
24072412
if (it != m_most_recent_block_txs->end()) return it->second;
24082413
}
24092414
}
@@ -2437,8 +2442,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
24372442
continue;
24382443
}
24392444

2440-
CTransactionRef tx = FindTxForGetData(*tx_relay, ToGenTxid(inv));
2441-
if (tx) {
2445+
if (auto tx{FindTxForGetData(*tx_relay, inv)}) {
24422446
// WTX and WITNESS_TX imply we serialize with witness
24432447
const auto maybe_with_witness = (inv.IsMsgTx() ? TX_NO_WITNESS : TX_WITH_WITNESS);
24442448
MakeAndPushMessage(pfrom, NetMsgType::TX, maybe_with_witness(*tx));
@@ -4306,7 +4310,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
43064310
// Always relay transactions received from peers with forcerelay
43074311
// permission, even if they were already in the mempool, allowing
43084312
// the node to function as a gateway for nodes hidden behind it.
4309-
if (!m_mempool.exists(GenTxid::Txid(tx.GetHash()))) {
4313+
if (!m_mempool.exists(tx.GetHash())) {
43104314
LogPrintf("Not relaying non-mempool transaction %s (wtxid=%s) from forcerelay peer=%d\n",
43114315
tx.GetHash().ToString(), tx.GetWitnessHash().ToString(), pfrom.GetId());
43124316
} else {
@@ -5820,7 +5824,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
58205824
continue;
58215825
}
58225826
// Not in the mempool anymore? don't bother sending it.
5823-
auto txinfo = m_mempool.info(ToGenTxid(inv));
5827+
auto txinfo{std::visit([&](const auto& id) { return m_mempool.info(id); }, hash)};
58245828
if (!txinfo.tx) {
58255829
continue;
58265830
}

src/node/interfaces.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,11 @@ class ChainImpl : public Chain
669669
LOCK(m_node.mempool->cs);
670670
return IsRBFOptIn(tx, *m_node.mempool);
671671
}
672-
bool isInMempool(const uint256& txid) override
672+
bool isInMempool(const Txid& txid) override
673673
{
674674
if (!m_node.mempool) return false;
675675
LOCK(m_node.mempool->cs);
676-
return m_node.mempool->exists(GenTxid::Txid(txid));
676+
return m_node.mempool->exists(txid);
677677
}
678678
bool hasDescendantsInMempool(const uint256& txid) override
679679
{

src/node/mempool_persist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bool LoadMempool(CTxMemPool& pool, const fs::path& load_path, Chainstate& active
106106
// wallet(s) having loaded it while we were processing
107107
// mempool transactions; consider these as valid, instead of
108108
// failed, but mark them as 'already there'
109-
if (pool.exists(GenTxid::Txid(tx->GetHash()))) {
109+
if (pool.exists(tx->GetHash())) {
110110
++already_there;
111111
} else {
112112
++failed;

src/node/mini_miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ MiniMiner::MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& ou
2727
// Anything that's spent by the mempool is to-be-replaced
2828
// Anything otherwise unavailable just has a bump fee of 0
2929
for (const auto& outpoint : outpoints) {
30-
if (!mempool.exists(GenTxid::Txid(outpoint.hash))) {
30+
if (!mempool.exists(outpoint.hash)) {
3131
// This UTXO is either confirmed or not yet submitted to mempool.
3232
// If it's confirmed, no bump fee is required.
3333
// If it's not yet submitted, we have no information, so return 0.

src/node/txdownloadman_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ bool TxDownloadManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_rec
148148

149149
if (RecentConfirmedTransactionsFilter().contains(hash)) return true;
150150

151-
return RecentRejectsFilter().contains(hash) || m_opts.m_mempool.exists(gtxid);
151+
return RecentRejectsFilter().contains(hash) || std::visit([&](const auto& id) { return m_opts.m_mempool.exists(id); }, gtxid.ToVariant());
152152
}
153153

154154
void TxDownloadManagerImpl::ConnectedPeer(NodeId nodeid, const TxDownloadConnectionInfo& info)
@@ -383,7 +383,7 @@ node::RejectedTxTodo TxDownloadManagerImpl::MempoolRejectedTx(const CTransaction
383383
fRejectedParents = true;
384384
break;
385385
} else if (RecentRejectsReconsiderableFilter().contains(parent_txid) &&
386-
!m_opts.m_mempool.exists(GenTxid::Txid(parent_txid))) {
386+
!m_opts.m_mempool.exists(Txid::FromUint256(parent_txid))) {
387387
// More than 1 parent in m_lazy_recent_rejects_reconsiderable: 1p1c will not be
388388
// sufficient to accept this package, so just give up here.
389389
if (rejected_parent_reconsiderable.has_value()) {

src/policy/rbf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool)
3232

3333
// If this transaction is not in our mempool, then we can't be sure
3434
// we will know about all its inputs.
35-
if (!pool.exists(GenTxid::Txid(tx.GetHash()))) {
35+
if (!pool.exists(tx.GetHash())) {
3636
return RBFTransactionState::UNKNOWN;
3737
}
3838

@@ -107,7 +107,7 @@ std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx,
107107
if (!parents_of_conflicts.count(tx.vin[j].prevout.hash)) {
108108
// Rather than check the UTXO set - potentially expensive - it's cheaper to just check
109109
// if the new input refers to a tx that's in the mempool.
110-
if (pool.exists(GenTxid::Txid(tx.vin[j].prevout.hash))) {
110+
if (pool.exists(tx.vin[j].prevout.hash)) {
111111
return strprintf("replacement %s adds unconfirmed input, idx %d",
112112
tx.GetHash().ToString(), j);
113113
}

src/rpc/mempool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
311311
std::set<std::string> setDepends;
312312
for (const CTxIn& txin : tx.vin)
313313
{
314-
if (pool.exists(GenTxid::Txid(txin.prevout.hash)))
314+
if (pool.exists(txin.prevout.hash))
315315
setDepends.insert(txin.prevout.hash.ToString());
316316
}
317317

@@ -1038,7 +1038,7 @@ static RPCHelpMan submitpackage()
10381038
// Belt-and-suspenders check; everything should be successful here
10391039
CHECK_NONFATAL(package_result.m_tx_results.size() == txns.size());
10401040
for (const auto& tx : txns) {
1041-
CHECK_NONFATAL(mempool.exists(GenTxid::Txid(tx->GetHash())));
1041+
CHECK_NONFATAL(mempool.exists(tx->GetHash()));
10421042
}
10431043
break;
10441044
}
@@ -1062,7 +1062,7 @@ static RPCHelpMan submitpackage()
10621062
size_t num_broadcast{0};
10631063
for (const auto& tx : txns) {
10641064
// We don't want to re-submit the txn for validation in BroadcastTransaction
1065-
if (!mempool.exists(GenTxid::Txid(tx->GetHash()))) {
1065+
if (!mempool.exists(tx->GetHash())) {
10661066
continue;
10671067
}
10681068

src/test/fuzz/mini_miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ FUZZ_TARGET(mini_miner_selection, .init = initialize_miner)
173173
if (!pool.GetConflictTx(coin)) outpoints.push_back(coin);
174174
}
175175
for (const auto& tx : transactions) {
176-
assert(pool.exists(GenTxid::Txid(tx->GetHash())));
176+
assert(pool.exists(tx->GetHash()));
177177
for (uint32_t n{0}; n < tx->vout.size(); ++n) {
178178
COutPoint coin{tx->GetHash(), n};
179179
if (!pool.GetConflictTx(coin)) outpoints.push_back(coin);

src/test/fuzz/package_eval.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ FUZZ_TARGET(ephemeral_package_eval, .init = initialize_tx_pool)
310310
const auto delta = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-50 * COIN, +50 * COIN);
311311
// We only prioritise out of mempool transactions since PrioritiseTransaction doesn't
312312
// filter for ephemeral dust
313-
if (tx_pool.exists(GenTxid::Txid(txid))) {
314-
const auto tx_info{tx_pool.info(GenTxid::Txid(txid))};
313+
if (tx_pool.exists(txid)) {
314+
const auto tx_info{tx_pool.info(txid)};
315315
if (GetDust(*tx_info.tx, tx_pool.m_opts.dust_relay_feerate).empty()) {
316316
tx_pool.PrioritiseTransaction(txid.ToUint256(), delta);
317317
}

0 commit comments

Comments
 (0)