@@ -302,7 +302,7 @@ struct Peer {
302302 * non-wtxid-relay peers, wtxid for wtxid-relay peers). We use the
303303 * mempool to sort transactions in dependency order before relay, so
304304 * this does not have to be sorted. */
305- std::set<uint256 > m_tx_inventory_to_send GUARDED_BY (m_tx_inventory_mutex);
305+ std::set<GenTxid > m_tx_inventory_to_send GUARDED_BY (m_tx_inventory_mutex);
306306 /* * Whether the peer has requested us to send our complete mempool. Only
307307 * permitted if the peer has NetPermissionFlags::Mempool or we advertise
308308 * NODE_BLOOM. See BIP35. */
@@ -536,7 +536,7 @@ class PeerManagerImpl final : public PeerManager
536536 std::vector<TxOrphanage::OrphanTxBase> GetOrphanTransactions () override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
537537 PeerManagerInfo GetInfo () const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
538538 void SendPings () override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
539- void RelayTransaction (const uint256 & txid, const uint256 & wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
539+ void RelayTransaction (const Txid & txid, const Wtxid & wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
540540 void SetBestBlock (int height, std::chrono::seconds time) override
541541 {
542542 m_best_height = height;
@@ -856,7 +856,7 @@ class PeerManagerImpl final : public PeerManager
856856 std::shared_ptr<const CBlock> m_most_recent_block GUARDED_BY (m_most_recent_block_mutex);
857857 std::shared_ptr<const CBlockHeaderAndShortTxIDs> m_most_recent_compact_block GUARDED_BY (m_most_recent_block_mutex);
858858 uint256 m_most_recent_block_hash GUARDED_BY (m_most_recent_block_mutex);
859- std::unique_ptr<const std::map<uint256 , CTransactionRef>> m_most_recent_block_txs GUARDED_BY (m_most_recent_block_mutex);
859+ std::unique_ptr<const std::map<GenTxid , CTransactionRef>> m_most_recent_block_txs GUARDED_BY (m_most_recent_block_mutex);
860860
861861 // Data about the low-work headers synchronization, aggregated from all peers' HeadersSyncStates.
862862 /* * Mutex guarding the other m_headers_presync_* variables. */
@@ -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)
@@ -1583,7 +1583,7 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
15831583 CTransactionRef tx = m_mempool.get (txid);
15841584
15851585 if (tx != nullptr ) {
1586- RelayTransaction (txid, tx->GetWitnessHash ());
1586+ RelayTransaction (Txid::FromUint256 ( txid) , tx->GetWitnessHash ());
15871587 } else {
15881588 m_mempool.RemoveUnbroadcastTx (txid, true );
15891589 }
@@ -2027,7 +2027,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
20272027 std::async (std::launch::deferred, [&] { return NetMsg::Make (NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
20282028
20292029 {
2030- auto most_recent_block_txs = std::make_unique<std::map<uint256 , CTransactionRef>>();
2030+ auto most_recent_block_txs = std::make_unique<std::map<GenTxid , CTransactionRef>>();
20312031 for (const auto & tx : pblock->vtx ) {
20322032 most_recent_block_txs->emplace (tx->GetHash (), tx);
20332033 most_recent_block_txs->emplace (tx->GetWitnessHash (), tx);
@@ -2150,7 +2150,7 @@ void PeerManagerImpl::SendPings()
21502150 for (auto & it : m_peer_map) it.second ->m_ping_queued = true ;
21512151}
21522152
2153- void PeerManagerImpl::RelayTransaction (const uint256 & txid, const uint256 & wtxid)
2153+ void PeerManagerImpl::RelayTransaction (const Txid & txid, const Wtxid & wtxid)
21542154{
21552155 LOCK (m_peer_mutex);
21562156 for (auto & it : m_peer_map) {
@@ -2166,11 +2166,11 @@ void PeerManagerImpl::RelayTransaction(const uint256& txid, const uint256& wtxid
21662166 // in the announcement.
21672167 if (tx_relay->m_next_inv_send_time == 0s) continue ;
21682168
2169- const uint256& hash {peer.m_wtxid_relay ? wtxid : txid};
2170- if (!tx_relay->m_tx_inventory_known_filter .contains (hash )) {
2171- tx_relay->m_tx_inventory_to_send .insert (hash );
2169+ const auto gtxid {peer.m_wtxid_relay ? GenTxid{ wtxid} : GenTxid{ txid} };
2170+ if (!tx_relay->m_tx_inventory_known_filter .contains (gtxid. ToUint256 () )) {
2171+ tx_relay->m_tx_inventory_to_send .insert (gtxid );
21722172 }
2173- };
2173+ }
21742174}
21752175
21762176void PeerManagerImpl::RelayAddress (NodeId originator,
@@ -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)};
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);
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));
@@ -4294,7 +4298,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
42944298 // Always relay transactions received from peers with forcerelay
42954299 // permission, even if they were already in the mempool, allowing
42964300 // the node to function as a gateway for nodes hidden behind it.
4297- if (!m_mempool.exists (GenTxid::Txid ( tx.GetHash () ))) {
4301+ if (!m_mempool.exists (tx.GetHash ())) {
42984302 LogPrintf (" Not relaying non-mempool transaction %s (wtxid=%s) from forcerelay peer=%d\n " ,
42994303 tx.GetHash ().ToString (), tx.GetWitnessHash ().ToString (), pfrom.GetId ());
43004304 } else {
@@ -4928,11 +4932,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
49284932 if (msg_type == NetMsgType::NOTFOUND) {
49294933 std::vector<CInv> vInv;
49304934 vRecv >> vInv;
4931- std::vector<uint256 > tx_invs;
4935+ std::vector<GenTxid > tx_invs;
49324936 if (vInv.size () <= node::MAX_PEER_TX_ANNOUNCEMENTS + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
49334937 for (CInv &inv : vInv) {
49344938 if (inv.IsGenTxMsg ()) {
4935- tx_invs.emplace_back (inv. hash );
4939+ tx_invs.emplace_back (ToGenTxid ( inv) );
49364940 }
49374941 }
49384942 }
@@ -5432,20 +5436,15 @@ void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::mi
54325436namespace {
54335437class CompareInvMempoolOrder
54345438{
5435- CTxMemPool* mp;
5436- bool m_wtxid_relay;
5439+ const CTxMemPool* m_mempool;
54375440public:
5438- explicit CompareInvMempoolOrder (CTxMemPool *_mempool, bool use_wtxid)
5439- {
5440- mp = _mempool;
5441- m_wtxid_relay = use_wtxid;
5442- }
5441+ explicit CompareInvMempoolOrder (CTxMemPool* mempool) : m_mempool{mempool} {}
54435442
5444- bool operator ()(std::set<uint256 >::iterator a, std::set<uint256 >::iterator b)
5443+ bool operator ()(std::set<GenTxid >::iterator a, std::set<GenTxid >::iterator b)
54455444 {
54465445 /* As std::make_heap produces a max-heap, we want the entries with the
54475446 * fewest ancestors/highest fee to sort later. */
5448- return mp ->CompareDepthAndScore (*b, *a, m_wtxid_relay );
5447+ return m_mempool ->CompareDepthAndScore (*b, *a);
54495448 }
54505449};
54515450} // namespace
@@ -5763,7 +5762,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
57635762 txinfo.tx ->GetWitnessHash ().ToUint256 () :
57645763 txinfo.tx ->GetHash ().ToUint256 (),
57655764 };
5766- tx_relay->m_tx_inventory_to_send .erase (inv. hash );
5765+ tx_relay->m_tx_inventory_to_send .erase (ToGenTxid ( inv) );
57675766
57685767 // Don't send transactions that peers will not put into their mempool
57695768 if (txinfo.fee < filterrate.GetFee (txinfo.vsize )) {
@@ -5784,15 +5783,15 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
57845783 // Determine transactions to relay
57855784 if (fSendTrickle ) {
57865785 // Produce a vector with all candidates for sending
5787- std::vector<std::set<uint256 >::iterator> vInvTx;
5786+ std::vector<std::set<GenTxid >::iterator> vInvTx;
57885787 vInvTx.reserve (tx_relay->m_tx_inventory_to_send .size ());
5789- for (std::set<uint256 >::iterator it = tx_relay->m_tx_inventory_to_send .begin (); it != tx_relay->m_tx_inventory_to_send .end (); it++) {
5788+ for (std::set<GenTxid >::iterator it = tx_relay->m_tx_inventory_to_send .begin (); it != tx_relay->m_tx_inventory_to_send .end (); it++) {
57905789 vInvTx.push_back (it);
57915790 }
57925791 const CFeeRate filterrate{tx_relay->m_fee_filter_received .load ()};
57935792 // Topologically and fee-rate sort the inventory we send for privacy and priority reasons.
57945793 // A heap is used so that not all items need sorting if only a few are being sent.
5795- CompareInvMempoolOrder compareInvMempoolOrder (&m_mempool, peer-> m_wtxid_relay );
5794+ CompareInvMempoolOrder compareInvMempoolOrder (&m_mempool);
57965795 std::make_heap (vInvTx.begin (), vInvTx.end (), compareInvMempoolOrder);
57975796 // No reason to drain out at many times the network's capacity,
57985797 // especially since we have many peers and some will draw much shorter delays.
@@ -5803,18 +5802,19 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
58035802 while (!vInvTx.empty () && nRelayedTransactions < broadcast_max) {
58045803 // Fetch the top element from the heap
58055804 std::pop_heap (vInvTx.begin (), vInvTx.end (), compareInvMempoolOrder);
5806- std::set<uint256 >::iterator it = vInvTx.back ();
5805+ std::set<GenTxid >::iterator it = vInvTx.back ();
58075806 vInvTx.pop_back ();
5808- uint256 hash = *it;
5809- CInv inv (peer->m_wtxid_relay ? MSG_WTX : MSG_TX, hash);
5807+ GenTxid hash = *it;
5808+ Assume (peer->m_wtxid_relay == hash.IsWtxid ());
5809+ CInv inv (peer->m_wtxid_relay ? MSG_WTX : MSG_TX, hash.ToUint256 ());
58105810 // Remove it from the to-be-sent set
58115811 tx_relay->m_tx_inventory_to_send .erase (it);
58125812 // Check if not in the filter already
5813- if (tx_relay->m_tx_inventory_known_filter .contains (hash)) {
5813+ if (tx_relay->m_tx_inventory_known_filter .contains (hash. ToUint256 () )) {
58145814 continue ;
58155815 }
58165816 // Not in the mempool anymore? don't bother sending it.
5817- auto txinfo = m_mempool.info (ToGenTxid (inv)) ;
5817+ auto txinfo{ std::visit ([&]( const auto & id) { return m_mempool.info (id); }, hash)} ;
58185818 if (!txinfo.tx ) {
58195819 continue ;
58205820 }
@@ -5830,7 +5830,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
58305830 MakeAndPushMessage (*pto, NetMsgType::INV, vInv);
58315831 vInv.clear ();
58325832 }
5833- tx_relay->m_tx_inventory_known_filter .insert (hash);
5833+ tx_relay->m_tx_inventory_known_filter .insert (hash. ToUint256 () );
58345834 }
58355835
58365836 // Ensure we'll respond to GETDATA requests for anything we've just announced
@@ -5953,7 +5953,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
59535953 {
59545954 LOCK (m_tx_download_mutex);
59555955 for (const GenTxid& gtxid : m_txdownloadman.GetRequestsToSend (pto->GetId (), current_time)) {
5956- vGetData.emplace_back (gtxid.IsWtxid () ? MSG_WTX : (MSG_TX | GetFetchFlags (*peer)), gtxid.GetHash ());
5956+ vGetData.emplace_back (gtxid.IsWtxid () ? MSG_WTX : (MSG_TX | GetFetchFlags (*peer)), gtxid.ToUint256 ());
59575957 if (vGetData.size () >= MAX_GETDATA_SZ) {
59585958 MakeAndPushMessage (*pto, NetMsgType::GETDATA, vGetData);
59595959 vGetData.clear ();
0 commit comments