Convert the rest of net_processing to GenTxidVariant

This commit is contained in:
marcofleon 2025-04-01 11:47:49 +01:00
parent ab739dd4fa
commit 90a1a6f405
3 changed files with 13 additions and 23 deletions

View file

@ -826,7 +826,7 @@ private:
std::shared_ptr<const CBlock> m_most_recent_block GUARDED_BY(m_most_recent_block_mutex);
std::shared_ptr<const CBlockHeaderAndShortTxIDs> m_most_recent_compact_block GUARDED_BY(m_most_recent_block_mutex);
uint256 m_most_recent_block_hash GUARDED_BY(m_most_recent_block_mutex);
std::unique_ptr<const std::map<uint256, CTransactionRef>> m_most_recent_block_txs GUARDED_BY(m_most_recent_block_mutex);
std::unique_ptr<const std::map<GenTxidVariant, CTransactionRef>> m_most_recent_block_txs GUARDED_BY(m_most_recent_block_mutex);
// Data about the low-work headers synchronization, aggregated from all peers' HeadersSyncStates.
/** Mutex guarding the other m_headers_presync_* variables. */
@ -917,7 +917,7 @@ private:
std::atomic<std::chrono::seconds> m_last_tip_update{0s};
/** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
CTransactionRef FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxid& gtxid)
CTransactionRef FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxidVariant& gtxid)
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, NetEventsInterface::g_msgproc_mutex);
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc)
@ -1995,7 +1995,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
std::async(std::launch::deferred, [&] { return NetMsg::Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
{
auto most_recent_block_txs = std::make_unique<std::map<uint256, CTransactionRef>>();
auto most_recent_block_txs = std::make_unique<std::map<GenTxidVariant, CTransactionRef>>();
for (const auto& tx : pblock->vtx) {
most_recent_block_txs->emplace(tx->GetHash(), tx);
most_recent_block_txs->emplace(tx->GetWitnessHash(), tx);
@ -2365,10 +2365,10 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
}
}
CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxid& gtxid)
CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxidVariant& gtxid)
{
// If a tx was in the mempool prior to the last INV for this peer, permit the request.
auto txinfo = m_mempool.info_for_relay(gtxid.ToVariant(), tx_relay.m_last_inv_sequence);
auto txinfo = m_mempool.info_for_relay(gtxid, tx_relay.m_last_inv_sequence);
if (txinfo.tx) {
return std::move(txinfo.tx);
}
@ -2377,7 +2377,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay,
{
LOCK(m_most_recent_block_mutex);
if (m_most_recent_block_txs != nullptr) {
auto it = m_most_recent_block_txs->find(gtxid.GetHash());
auto it = m_most_recent_block_txs->find(gtxid);
if (it != m_most_recent_block_txs->end()) return it->second;
}
}
@ -3945,11 +3945,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
pfrom.fDisconnect = true;
return;
}
const GenTxid gtxid = ToGenTxid(inv);
const GenTxidVariant gtxid = ToGenTxid(inv);
AddKnownTx(*peer, inv.hash);
if (!m_chainman.IsInitialBlockDownload()) {
const bool fAlreadyHave{m_txdownloadman.AddTxAnnouncement(pfrom.GetId(), gtxid.ToVariant(), current_time)};
const bool fAlreadyHave{m_txdownloadman.AddTxAnnouncement(pfrom.GetId(), gtxid, current_time)};
LogDebug(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
}
} else {
@ -4881,7 +4881,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
if (vInv.size() <= node::MAX_PEER_TX_ANNOUNCEMENTS + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
for (CInv &inv : vInv) {
if (inv.IsGenTxMsg()) {
tx_invs.emplace_back(ToGenTxidVariant(inv));
tx_invs.emplace_back(ToGenTxid(inv));
}
}
}
@ -5710,7 +5710,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
txinfo.tx->GetWitnessHash().ToUint256() :
txinfo.tx->GetHash().ToUint256(),
};
tx_relay->m_tx_inventory_to_send.erase(Txid::FromUint256(inv.hash));
tx_relay->m_tx_inventory_to_send.erase(ToGenTxid(inv));
// Don't send transactions that peers will not put into their mempool
if (txinfo.fee < filterrate.GetFee(txinfo.vsize)) {
@ -5761,7 +5761,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
continue;
}
// Not in the mempool anymore? don't bother sending it.
auto txinfo = m_mempool.info(ToGenTxid(inv).ToVariant());
auto txinfo = m_mempool.info(ToGenTxid(inv));
if (!txinfo.tx) {
continue;
}

View file

@ -118,15 +118,7 @@ std::vector<std::string> serviceFlagsToStr(uint64_t flags)
return str_flags;
}
// TODO: Remove this function and rename the one below to ToGenTxid.
// This is only here for intermediate commits.
GenTxid ToGenTxid(const CInv& inv)
{
assert(inv.IsGenTxMsg());
return inv.IsMsgWtx() ? GenTxid::Wtxid(inv.hash) : GenTxid::Txid(inv.hash);
}
GenTxidVariant ToGenTxidVariant(const CInv& inv)
GenTxidVariant ToGenTxid(const CInv& inv)
{
assert(inv.IsGenTxMsg());
if (inv.IsMsgWtx()) {

View file

@ -526,8 +526,6 @@ public:
};
/** Convert a TX/WITNESS_TX/WTX CInv to a GenTxid. */
GenTxid ToGenTxid(const CInv& inv);
// Remove this once all GenTxids are switched to the variant.
GenTxidVariant ToGenTxidVariant(const CInv& inv);
GenTxidVariant ToGenTxid(const CInv& inv);
#endif // BITCOIN_PROTOCOL_H