From a60f863d3e276534444571282f432b913d3967db Mon Sep 17 00:00:00 2001 From: marcofleon Date: Tue, 1 Jul 2025 22:06:01 +0100 Subject: [PATCH] scripted-diff: Replace GenTxidVariant with GenTxid -BEGIN VERIFY SCRIPT- sed -i 's/GenTxidVariant/GenTxid/g' $(git grep -l 'GenTxidVariant') -END VERIFY SCRIPT- --- src/net_processing.cpp | 24 ++++++++++++------------ src/node/txdownloadman.h | 8 ++++---- src/node/txdownloadman_impl.cpp | 20 ++++++++++---------- src/node/txdownloadman_impl.h | 8 ++++---- src/protocol.cpp | 4 ++-- src/protocol.h | 2 +- src/test/fuzz/txdownloadman.cpp | 8 ++++---- src/test/fuzz/txrequest.cpp | 8 ++++---- src/test/txrequest_tests.cpp | 16 ++++++++-------- src/txmempool.cpp | 2 +- src/txmempool.h | 2 +- src/txrequest.cpp | 20 ++++++++++---------- src/txrequest.h | 6 +++--- src/util/transaction_identifier.h | 4 ++-- 14 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index cf367aac67d..7d3bb5f8ab3 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -302,7 +302,7 @@ struct Peer { * non-wtxid-relay peers, wtxid for wtxid-relay peers). We use the * mempool to sort transactions in dependency order before relay, so * this does not have to be sorted. */ - std::set m_tx_inventory_to_send GUARDED_BY(m_tx_inventory_mutex); + std::set m_tx_inventory_to_send GUARDED_BY(m_tx_inventory_mutex); /** Whether the peer has requested us to send our complete mempool. Only * permitted if the peer has NetPermissionFlags::Mempool or we advertise * NODE_BLOOM. See BIP35. */ @@ -856,7 +856,7 @@ private: std::shared_ptr m_most_recent_block GUARDED_BY(m_most_recent_block_mutex); std::shared_ptr 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> m_most_recent_block_txs GUARDED_BY(m_most_recent_block_mutex); + std::unique_ptr> 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. */ @@ -2027,7 +2027,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>(); + auto most_recent_block_txs = std::make_unique>(); for (const auto& tx : pblock->vtx) { most_recent_block_txs->emplace(tx->GetHash(), tx); most_recent_block_txs->emplace(tx->GetWitnessHash(), tx); @@ -2166,7 +2166,7 @@ void PeerManagerImpl::RelayTransaction(const Txid& txid, const Wtxid& wtxid) // in the announcement. if (tx_relay->m_next_inv_send_time == 0s) continue; - const auto gtxid{peer.m_wtxid_relay ? GenTxidVariant{wtxid} : GenTxidVariant{txid}}; + const auto gtxid{peer.m_wtxid_relay ? GenTxid{wtxid} : GenTxid{txid}}; if (!tx_relay->m_tx_inventory_known_filter.contains(gtxid.ToUint256())) { tx_relay->m_tx_inventory_to_send.insert(gtxid); } @@ -4011,7 +4011,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, pfrom.fDisconnect = true; return; } - const GenTxidVariant gtxid = ToGenTxid(inv); + const GenTxid gtxid = ToGenTxid(inv); AddKnownTx(*peer, inv.hash); if (!m_chainman.IsInitialBlockDownload()) { @@ -4942,7 +4942,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, if (msg_type == NetMsgType::NOTFOUND) { std::vector vInv; vRecv >> vInv; - std::vector tx_invs; + std::vector tx_invs; if (vInv.size() <= node::MAX_PEER_TX_ANNOUNCEMENTS + MAX_BLOCKS_IN_TRANSIT_PER_PEER) { for (CInv &inv : vInv) { if (inv.IsGenTxMsg()) { @@ -5450,7 +5450,7 @@ class CompareInvMempoolOrder public: explicit CompareInvMempoolOrder(CTxMemPool* mempool) : m_mempool{mempool} {} - bool operator()(std::set::iterator a, std::set::iterator b) + bool operator()(std::set::iterator a, std::set::iterator b) { /* As std::make_heap produces a max-heap, we want the entries with the * fewest ancestors/highest fee to sort later. */ @@ -5793,9 +5793,9 @@ bool PeerManagerImpl::SendMessages(CNode* pto) // Determine transactions to relay if (fSendTrickle) { // Produce a vector with all candidates for sending - std::vector::iterator> vInvTx; + std::vector::iterator> vInvTx; vInvTx.reserve(tx_relay->m_tx_inventory_to_send.size()); - for (std::set::iterator it = tx_relay->m_tx_inventory_to_send.begin(); it != tx_relay->m_tx_inventory_to_send.end(); it++) { + for (std::set::iterator it = tx_relay->m_tx_inventory_to_send.begin(); it != tx_relay->m_tx_inventory_to_send.end(); it++) { vInvTx.push_back(it); } const CFeeRate filterrate{tx_relay->m_fee_filter_received.load()}; @@ -5812,9 +5812,9 @@ bool PeerManagerImpl::SendMessages(CNode* pto) while (!vInvTx.empty() && nRelayedTransactions < broadcast_max) { // Fetch the top element from the heap std::pop_heap(vInvTx.begin(), vInvTx.end(), compareInvMempoolOrder); - std::set::iterator it = vInvTx.back(); + std::set::iterator it = vInvTx.back(); vInvTx.pop_back(); - GenTxidVariant hash = *it; + GenTxid hash = *it; Assume(peer->m_wtxid_relay == hash.IsWtxid()); CInv inv(peer->m_wtxid_relay ? MSG_WTX : MSG_TX, hash.ToUint256()); // Remove it from the to-be-sent set @@ -5962,7 +5962,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto) // { LOCK(m_tx_download_mutex); - for (const GenTxidVariant& gtxid : m_txdownloadman.GetRequestsToSend(pto->GetId(), current_time)) { + for (const GenTxid& gtxid : m_txdownloadman.GetRequestsToSend(pto->GetId(), current_time)) { vGetData.emplace_back(gtxid.IsWtxid() ? MSG_WTX : (MSG_TX | GetFetchFlags(*peer)), gtxid.ToUint256()); if (vGetData.size() >= MAX_GETDATA_SZ) { MakeAndPushMessage(*pto, NetMsgType::GETDATA, vGetData); diff --git a/src/node/txdownloadman.h b/src/node/txdownloadman.h index 5c5e61cdca7..9eb246740b9 100644 --- a/src/node/txdownloadman.h +++ b/src/node/txdownloadman.h @@ -16,7 +16,7 @@ class CBlock; class CRollingBloomFilter; class CTxMemPool; -class GenTxidVariant; +class GenTxid; class TxRequestTracker; namespace node { class TxDownloadManagerImpl; @@ -138,13 +138,13 @@ public: /** Consider adding this tx hash to txrequest. Should be called whenever a new inv has been received. * Also called internally when a transaction is missing parents so that we can request them. * Returns true if this was a dropped inv (p2p_inv=true and we already have the tx), false otherwise. */ - bool AddTxAnnouncement(NodeId peer, const GenTxidVariant& gtxid, std::chrono::microseconds now); + bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now); /** Get getdata requests to send. */ - std::vector GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time); + std::vector GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time); /** Should be called when a notfound for a tx has been received. */ - void ReceivedNotFound(NodeId nodeid, const std::vector& gtxids); + void ReceivedNotFound(NodeId nodeid, const std::vector& gtxids); /** Respond to successful transaction submission to mempool */ void MempoolAcceptedTx(const CTransactionRef& tx); diff --git a/src/node/txdownloadman_impl.cpp b/src/node/txdownloadman_impl.cpp index a8fe8971bed..5bb435f5321 100644 --- a/src/node/txdownloadman_impl.cpp +++ b/src/node/txdownloadman_impl.cpp @@ -39,15 +39,15 @@ void TxDownloadManager::DisconnectedPeer(NodeId nodeid) { m_impl->DisconnectedPeer(nodeid); } -bool TxDownloadManager::AddTxAnnouncement(NodeId peer, const GenTxidVariant& gtxid, std::chrono::microseconds now) +bool TxDownloadManager::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now) { return m_impl->AddTxAnnouncement(peer, gtxid, now); } -std::vector TxDownloadManager::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time) +std::vector TxDownloadManager::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time) { return m_impl->GetRequestsToSend(nodeid, current_time); } -void TxDownloadManager::ReceivedNotFound(NodeId nodeid, const std::vector& gtxids) +void TxDownloadManager::ReceivedNotFound(NodeId nodeid, const std::vector& gtxids) { m_impl->ReceivedNotFound(nodeid, gtxids); } @@ -122,7 +122,7 @@ void TxDownloadManagerImpl::BlockDisconnected() RecentConfirmedTransactionsFilter().reset(); } -bool TxDownloadManagerImpl::AlreadyHaveTx(const GenTxidVariant& gtxid, bool include_reconsiderable) +bool TxDownloadManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_reconsiderable) { const uint256& hash = gtxid.ToUint256(); @@ -167,7 +167,7 @@ void TxDownloadManagerImpl::DisconnectedPeer(NodeId nodeid) } -bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxidVariant& gtxid, std::chrono::microseconds now) +bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now) { // If this is an orphan we are trying to resolve, consider this peer as a orphan resolution candidate instead. // - is wtxid matching something in orphanage @@ -261,16 +261,16 @@ bool TxDownloadManagerImpl::MaybeAddOrphanResolutionCandidate(const std::vector< return true; } -std::vector TxDownloadManagerImpl::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time) +std::vector TxDownloadManagerImpl::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time) { - std::vector requests; - std::vector> expired; + std::vector requests; + std::vector> expired; auto requestable = m_txrequest.GetRequestable(nodeid, current_time, &expired); for (const auto& [expired_nodeid, gtxid] : expired) { LogDebug(BCLog::NET, "timeout of inflight %s %s from peer=%d\n", gtxid.IsWtxid() ? "wtx" : "tx", gtxid.ToUint256().ToString(), expired_nodeid); } - for (const GenTxidVariant& gtxid : requestable) { + for (const GenTxid& gtxid : requestable) { if (!AlreadyHaveTx(gtxid, /*include_reconsiderable=*/false)) { LogDebug(BCLog::NET, "Requesting %s %s peer=%d\n", gtxid.IsWtxid() ? "wtx" : "tx", gtxid.ToUint256().ToString(), nodeid); @@ -285,7 +285,7 @@ std::vector TxDownloadManagerImpl::GetRequestsToSend(NodeId node return requests; } -void TxDownloadManagerImpl::ReceivedNotFound(NodeId nodeid, const std::vector& gtxids) +void TxDownloadManagerImpl::ReceivedNotFound(NodeId nodeid, const std::vector& gtxids) { for (const auto& gtxid : gtxids) { // If we receive a NOTFOUND message for a tx we requested, mark the announcement for it as diff --git a/src/node/txdownloadman_impl.h b/src/node/txdownloadman_impl.h index e5bbc1e8030..3e0213352ca 100644 --- a/src/node/txdownloadman_impl.h +++ b/src/node/txdownloadman_impl.h @@ -155,7 +155,7 @@ public: * - m_recent_rejects_reconsiderable (if include_reconsiderable = true) * - m_recent_confirmed_transactions * */ - bool AlreadyHaveTx(const GenTxidVariant& gtxid, bool include_reconsiderable); + bool AlreadyHaveTx(const GenTxid& gtxid, bool include_reconsiderable); void ConnectedPeer(NodeId nodeid, const TxDownloadConnectionInfo& info); void DisconnectedPeer(NodeId nodeid); @@ -163,13 +163,13 @@ public: /** Consider adding this tx hash to txrequest. Should be called whenever a new inv has been received. * Also called internally when a transaction is missing parents so that we can request them. */ - bool AddTxAnnouncement(NodeId peer, const GenTxidVariant& gtxid, std::chrono::microseconds now); + bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now); /** Get getdata requests to send. */ - std::vector GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time); + std::vector GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time); /** Marks a tx as ReceivedResponse in txrequest. */ - void ReceivedNotFound(NodeId nodeid, const std::vector& gtxids); + void ReceivedNotFound(NodeId nodeid, const std::vector& gtxids); /** Look for a child of this transaction in the orphanage to form a 1-parent-1-child package, * skipping any combinations that have already been tried. Return the resulting package along with diff --git a/src/protocol.cpp b/src/protocol.cpp index a8ad50ab728..5217c45daaf 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -118,8 +118,8 @@ std::vector serviceFlagsToStr(uint64_t flags) return str_flags; } -GenTxidVariant ToGenTxid(const CInv& inv) +GenTxid ToGenTxid(const CInv& inv) { assert(inv.IsGenTxMsg()); - return inv.IsMsgWtx() ? GenTxidVariant{Wtxid::FromUint256(inv.hash)} : GenTxidVariant{Txid::FromUint256(inv.hash)}; + return inv.IsMsgWtx() ? GenTxid{Wtxid::FromUint256(inv.hash)} : GenTxid{Txid::FromUint256(inv.hash)}; } diff --git a/src/protocol.h b/src/protocol.h index 35b2722afb9..804597b86d8 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -526,6 +526,6 @@ public: }; /** Convert a TX/WITNESS_TX/WTX CInv to a GenTxid. */ -GenTxidVariant ToGenTxid(const CInv& inv); +GenTxid ToGenTxid(const CInv& inv); #endif // BITCOIN_PROTOCOL_H diff --git a/src/test/fuzz/txdownloadman.cpp b/src/test/fuzz/txdownloadman.cpp index af6265678d6..b65ba0eb383 100644 --- a/src/test/fuzz/txdownloadman.cpp +++ b/src/test/fuzz/txdownloadman.cpp @@ -228,8 +228,8 @@ FUZZ_TARGET(txdownloadman, .init = initialize) }, [&] { auto gtxid = fuzzed_data_provider.ConsumeBool() ? - GenTxidVariant{rand_tx->GetHash()} : - GenTxidVariant{rand_tx->GetWitnessHash()}; + GenTxid{rand_tx->GetHash()} : + GenTxid{rand_tx->GetWitnessHash()}; txdownloadman.AddTxAnnouncement(rand_peer, gtxid, time); }, [&] { @@ -373,8 +373,8 @@ FUZZ_TARGET(txdownloadman_impl, .init = initialize) }, [&] { auto gtxid = fuzzed_data_provider.ConsumeBool() ? - GenTxidVariant{rand_tx->GetHash()} : - GenTxidVariant{rand_tx->GetWitnessHash()}; + GenTxid{rand_tx->GetHash()} : + GenTxid{rand_tx->GetWitnessHash()}; txdownload_impl.AddTxAnnouncement(rand_peer, gtxid, time); }, [&] { diff --git a/src/test/fuzz/txrequest.cpp b/src/test/fuzz/txrequest.cpp index 1cab9bc471c..c1585d7c00e 100644 --- a/src/test/fuzz/txrequest.cpp +++ b/src/test/fuzz/txrequest.cpp @@ -204,7 +204,7 @@ public: } // Call TxRequestTracker's implementation. - auto gtxid = is_wtxid ? GenTxidVariant{Wtxid::FromUint256(TXHASHES[txhash])} : GenTxidVariant{Txid::FromUint256(TXHASHES[txhash])}; + auto gtxid = is_wtxid ? GenTxid{Wtxid::FromUint256(TXHASHES[txhash])} : GenTxid{Txid::FromUint256(TXHASHES[txhash])}; m_tracker.ReceivedInv(peer, gtxid, preferred, reqtime); } @@ -247,13 +247,13 @@ public: //! list of (sequence number, txhash, is_wtxid) tuples. std::vector> result; - std::vector> expected_expired; + std::vector> expected_expired; for (int txhash = 0; txhash < MAX_TXHASHES; ++txhash) { // Mark any expired REQUESTED announcements as COMPLETED. for (int peer2 = 0; peer2 < MAX_PEERS; ++peer2) { Announcement& ann2 = m_announcements[txhash][peer2]; if (ann2.m_state == State::REQUESTED && ann2.m_time <= m_now) { - auto gtxid = ann2.m_is_wtxid ? GenTxidVariant{Wtxid::FromUint256(TXHASHES[txhash])} : GenTxidVariant{Txid::FromUint256(TXHASHES[txhash])}; + auto gtxid = ann2.m_is_wtxid ? GenTxid{Wtxid::FromUint256(TXHASHES[txhash])} : GenTxid{Txid::FromUint256(TXHASHES[txhash])}; expected_expired.emplace_back(peer2, gtxid); ann2.m_state = State::COMPLETED; break; @@ -272,7 +272,7 @@ public: std::sort(expected_expired.begin(), expected_expired.end()); // Compare with TxRequestTracker's implementation. - std::vector> expired; + std::vector> expired; const auto actual = m_tracker.GetRequestable(peer, m_now, &expired); std::sort(expired.begin(), expired.end()); assert(expired == expected_expired); diff --git a/src/test/txrequest_tests.cpp b/src/test/txrequest_tests.cpp index 0278f824f6c..ba82a986a1b 100644 --- a/src/test/txrequest_tests.cpp +++ b/src/test/txrequest_tests.cpp @@ -61,7 +61,7 @@ struct Runner /** Which (peer, gtxid) combinations are known to be expired. These need to be accumulated here instead of * checked directly in the GetRequestable return value to avoid introducing a dependency between the various * parallel tests. */ - std::multiset> expired; + std::multiset> expired; }; std::chrono::microseconds TxRequestTest::RandomTime8s() { return std::chrono::microseconds{1 + m_rng.randbits(23)}; } @@ -110,7 +110,7 @@ public: } /** Schedule a ReceivedInv call at the Scheduler's current time. */ - void ReceivedInv(NodeId peer, const GenTxidVariant& gtxid, bool pref, std::chrono::microseconds reqtime) + void ReceivedInv(NodeId peer, const GenTxid& gtxid, bool pref, std::chrono::microseconds reqtime) { auto& runner = m_runner; runner.actions.emplace_back(m_now, [=, &runner]() { @@ -160,7 +160,7 @@ public: * @param offset Offset with the current time to use (must be <= 0). This allows simulations of time going * backwards (but note that the ordering of this event only follows the scenario's m_now. */ - void Check(NodeId peer, const std::vector& expected, size_t candidates, size_t inflight, + void Check(NodeId peer, const std::vector& expected, size_t candidates, size_t inflight, size_t completed, const std::string& checkname, std::chrono::microseconds offset = std::chrono::microseconds{0}) { @@ -169,7 +169,7 @@ public: const auto now = m_now; assert(offset.count() <= 0); runner.actions.emplace_back(m_now, [=, &runner]() { - std::vector> expired_now; + std::vector> expired_now; auto ret = runner.txrequest.GetRequestable(peer, now + offset, &expired_now); for (const auto& entry : expired_now) { runner.expired.insert(entry); @@ -191,12 +191,12 @@ public: * * Every expected expiration should be accounted for through exactly one call to this function. */ - void CheckExpired(NodeId peer, GenTxidVariant gtxid) + void CheckExpired(NodeId peer, GenTxid gtxid) { const auto& testname = m_testname; auto& runner = m_runner; runner.actions.emplace_back(m_now, [=, &runner]() { - auto it = runner.expired.find(std::pair{peer, gtxid}); + auto it = runner.expired.find(std::pair{peer, gtxid}); BOOST_CHECK_MESSAGE(it != runner.expired.end(), "[" + testname + "] missing expiration"); if (it != runner.expired.end()) runner.expired.erase(it); }); @@ -236,10 +236,10 @@ public: } /** Generate a random GenTxid; the txhash follows NewTxHash; the transaction identifier is random. */ - GenTxidVariant NewGTxid(const std::vector>& orders = {}) + GenTxid NewGTxid(const std::vector>& orders = {}) { const uint256 txhash{NewTxHash(orders)}; - return m_rng.randbool() ? GenTxidVariant{Wtxid::FromUint256(txhash)} : GenTxidVariant{Txid::FromUint256(txhash)}; + return m_rng.randbool() ? GenTxid{Wtxid::FromUint256(txhash)} : GenTxid{Txid::FromUint256(txhash)}; } /** Generate a new random NodeId to use as peer. The same NodeId is never returned twice diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 3c22909ad6b..9d78a6e716c 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -794,7 +794,7 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei assert(innerUsage == cachedInnerUsage); } -bool CTxMemPool::CompareDepthAndScore(const GenTxidVariant& hasha, const GenTxidVariant& hashb) const +bool CTxMemPool::CompareDepthAndScore(const GenTxid& hasha, const GenTxid& hashb) const { /* Return `true` if hasha should be considered sooner than hashb. Namely when: * a is not in the mempool, but b is diff --git a/src/txmempool.h b/src/txmempool.h index bc5af815baf..40be8025c49 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -472,7 +472,7 @@ public: void removeConflicts(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(cs); void removeForBlock(const std::vector& vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs); - bool CompareDepthAndScore(const GenTxidVariant& hasha, const GenTxidVariant& hashb) const; + bool CompareDepthAndScore(const GenTxid& hasha, const GenTxid& hashb) const; bool isSpent(const COutPoint& outpoint) const; unsigned int GetTransactionsUpdated() const; void AddTransactionsUpdated(unsigned int n); diff --git a/src/txrequest.cpp b/src/txrequest.cpp index 02f03435154..37496614129 100644 --- a/src/txrequest.cpp +++ b/src/txrequest.cpp @@ -60,7 +60,7 @@ using SequenceNumber = uint64_t; /** An announcement. This is the data we track for each txid or wtxid that is announced to us by each peer. */ struct Announcement { /** Txid or wtxid that was announced. */ - const GenTxidVariant m_gtxid; + const GenTxid m_gtxid; /** For CANDIDATE_{DELAYED,BEST,READY} the reqtime; for REQUESTED the expiry. */ std::chrono::microseconds m_time; /** What peer the request was from. */ @@ -93,7 +93,7 @@ struct Announcement { } /** Construct a new announcement from scratch, initially in CANDIDATE_DELAYED state. */ - Announcement(const GenTxidVariant& gtxid, NodeId peer, bool preferred, std::chrono::microseconds reqtime, + Announcement(const GenTxid& gtxid, NodeId peer, bool preferred, std::chrono::microseconds reqtime, SequenceNumber sequence) : m_gtxid(gtxid), m_time(reqtime), m_peer(peer), m_sequence(sequence), m_preferred(preferred) {} }; @@ -481,7 +481,7 @@ private: //! - REQUESTED announcements with expiry <= now are turned into COMPLETED. //! - CANDIDATE_DELAYED announcements with reqtime <= now are turned into CANDIDATE_{READY,BEST}. //! - CANDIDATE_{READY,BEST} announcements with reqtime > now are turned into CANDIDATE_DELAYED. - void SetTimePoint(std::chrono::microseconds now, std::vector>* expired) + void SetTimePoint(std::chrono::microseconds now, std::vector>* expired) { if (expired) expired->clear(); @@ -574,7 +574,7 @@ public: } } - void ReceivedInv(NodeId peer, const GenTxidVariant& gtxid, bool preferred, + void ReceivedInv(NodeId peer, const GenTxid& gtxid, bool preferred, std::chrono::microseconds reqtime) { // Bail out if we already have a CANDIDATE_BEST announcement for this (txhash, peer) combination. The case @@ -594,8 +594,8 @@ public: } //! Find the GenTxids to request now from peer. - std::vector GetRequestable(NodeId peer, std::chrono::microseconds now, - std::vector>* expired) + std::vector GetRequestable(NodeId peer, std::chrono::microseconds now, + std::vector>* expired) { // Move time. SetTimePoint(now, expired); @@ -615,7 +615,7 @@ public: }); // Convert to GenTxid and return. - std::vector ret; + std::vector ret; ret.reserve(selected.size()); std::transform(selected.begin(), selected.end(), std::back_inserter(ret), [](const Announcement* ann) { return ann->m_gtxid; @@ -729,7 +729,7 @@ void TxRequestTracker::PostGetRequestableSanityCheck(std::chrono::microseconds n m_impl->PostGetRequestableSanityCheck(now); } -void TxRequestTracker::ReceivedInv(NodeId peer, const GenTxidVariant& gtxid, bool preferred, +void TxRequestTracker::ReceivedInv(NodeId peer, const GenTxid& gtxid, bool preferred, std::chrono::microseconds reqtime) { m_impl->ReceivedInv(peer, gtxid, preferred, reqtime); @@ -745,8 +745,8 @@ void TxRequestTracker::ReceivedResponse(NodeId peer, const uint256& txhash) m_impl->ReceivedResponse(peer, txhash); } -std::vector TxRequestTracker::GetRequestable(NodeId peer, std::chrono::microseconds now, - std::vector>* expired) +std::vector TxRequestTracker::GetRequestable(NodeId peer, std::chrono::microseconds now, + std::vector>* expired) { return m_impl->GetRequestable(peer, now, expired); } diff --git a/src/txrequest.h b/src/txrequest.h index f38f4e486ec..084c5ffffea 100644 --- a/src/txrequest.h +++ b/src/txrequest.h @@ -132,7 +132,7 @@ public: * fetched. The new announcement is given the specified preferred and reqtime values, and takes its is_wtxid * from the specified gtxid. */ - void ReceivedInv(NodeId peer, const GenTxidVariant& gtxid, bool preferred, + void ReceivedInv(NodeId peer, const GenTxid& gtxid, bool preferred, std::chrono::microseconds reqtime); /** Deletes all announcements for a given peer. @@ -163,8 +163,8 @@ public: * from dependent transactions being requested out of order: if multiple dependent transactions are announced * simultaneously by one peer, and end up being requested from them, the requests will happen in announcement order. */ - std::vector GetRequestable(NodeId peer, std::chrono::microseconds now, - std::vector>* expired = nullptr); + std::vector GetRequestable(NodeId peer, std::chrono::microseconds now, + std::vector>* expired = nullptr); /** Marks a transaction as requested, with a specified expiry. * diff --git a/src/util/transaction_identifier.h b/src/util/transaction_identifier.h index 95b755f4a67..02e8ec077db 100644 --- a/src/util/transaction_identifier.h +++ b/src/util/transaction_identifier.h @@ -84,7 +84,7 @@ using Wtxid = transaction_identifier; template concept TxidOrWtxid = std::is_same_v || std::is_same_v; -class GenTxidVariant : public std::variant +class GenTxid : public std::variant { public: using variant::variant; @@ -96,7 +96,7 @@ public: return std::visit([](const auto& id) -> const uint256& { return id.ToUint256(); }, *this); } - friend auto operator<=>(const GenTxidVariant& a, const GenTxidVariant& b) + friend auto operator<=>(const GenTxid& a, const GenTxid& b) { return std::tuple(a.IsWtxid(), a.ToUint256()) <=> std::tuple(b.IsWtxid(), b.ToUint256()); }