@@ -302,7 +302,7 @@ struct Peer {
302
302
* non-wtxid-relay peers, wtxid for wtxid-relay peers). We use the
303
303
* mempool to sort transactions in dependency order before relay, so
304
304
* 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);
306
306
/* * Whether the peer has requested us to send our complete mempool. Only
307
307
* permitted if the peer has NetPermissionFlags::Mempool or we advertise
308
308
* NODE_BLOOM. See BIP35. */
@@ -536,7 +536,7 @@ class PeerManagerImpl final : public PeerManager
536
536
std::vector<TxOrphanage::OrphanTxBase> GetOrphanTransactions () override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
537
537
PeerManagerInfo GetInfo () const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
538
538
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);
540
540
void SetBestBlock (int height, std::chrono::seconds time) override
541
541
{
542
542
m_best_height = height;
@@ -856,7 +856,7 @@ class PeerManagerImpl final : public PeerManager
856
856
std::shared_ptr<const CBlock> m_most_recent_block GUARDED_BY (m_most_recent_block_mutex);
857
857
std::shared_ptr<const CBlockHeaderAndShortTxIDs> m_most_recent_compact_block GUARDED_BY (m_most_recent_block_mutex);
858
858
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);
860
860
861
861
// Data about the low-work headers synchronization, aggregated from all peers' HeadersSyncStates.
862
862
/* * Mutex guarding the other m_headers_presync_* variables. */
@@ -947,7 +947,7 @@ class PeerManagerImpl final : public PeerManager
947
947
std::atomic<std::chrono::seconds> m_last_tip_update{0s};
948
948
949
949
/* * 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 )
951
951
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, NetEventsInterface::g_msgproc_mutex);
952
952
953
953
void ProcessGetData (CNode& pfrom, Peer& peer, const std::atomic<bool >& interruptMsgProc)
@@ -1583,7 +1583,7 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
1583
1583
CTransactionRef tx = m_mempool.get (txid);
1584
1584
1585
1585
if (tx != nullptr ) {
1586
- RelayTransaction (txid, tx->GetWitnessHash ());
1586
+ RelayTransaction (Txid::FromUint256 ( txid) , tx->GetWitnessHash ());
1587
1587
} else {
1588
1588
m_mempool.RemoveUnbroadcastTx (txid, true );
1589
1589
}
@@ -2027,7 +2027,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
2027
2027
std::async (std::launch::deferred, [&] { return NetMsg::Make (NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
2028
2028
2029
2029
{
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>>();
2031
2031
for (const auto & tx : pblock->vtx ) {
2032
2032
most_recent_block_txs->emplace (tx->GetHash (), tx);
2033
2033
most_recent_block_txs->emplace (tx->GetWitnessHash (), tx);
@@ -2150,7 +2150,7 @@ void PeerManagerImpl::SendPings()
2150
2150
for (auto & it : m_peer_map) it.second ->m_ping_queued = true ;
2151
2151
}
2152
2152
2153
- void PeerManagerImpl::RelayTransaction (const uint256 & txid, const uint256 & wtxid)
2153
+ void PeerManagerImpl::RelayTransaction (const Txid & txid, const Wtxid & wtxid)
2154
2154
{
2155
2155
LOCK (m_peer_mutex);
2156
2156
for (auto & it : m_peer_map) {
@@ -2166,11 +2166,11 @@ void PeerManagerImpl::RelayTransaction(const uint256& txid, const uint256& wtxid
2166
2166
// in the announcement.
2167
2167
if (tx_relay->m_next_inv_send_time == 0s) continue ;
2168
2168
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 );
2172
2172
}
2173
- };
2173
+ }
2174
2174
}
2175
2175
2176
2176
void PeerManagerImpl::RelayAddress (NodeId originator,
@@ -2391,10 +2391,15 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
2391
2391
}
2392
2392
}
2393
2393
2394
- CTransactionRef PeerManagerImpl::FindTxForGetData (const Peer::TxRelay& tx_relay, const GenTxid& gtxid )
2394
+ CTransactionRef PeerManagerImpl::FindTxForGetData (const Peer::TxRelay& tx_relay, const CInv& inv )
2395
2395
{
2396
+ auto gtxid{ToGenTxid (inv)};
2396
2397
// 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)};
2398
2403
if (txinfo.tx ) {
2399
2404
return std::move (txinfo.tx );
2400
2405
}
@@ -2403,7 +2408,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay,
2403
2408
{
2404
2409
LOCK (m_most_recent_block_mutex);
2405
2410
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);
2407
2412
if (it != m_most_recent_block_txs->end ()) return it->second ;
2408
2413
}
2409
2414
}
@@ -2437,8 +2442,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
2437
2442
continue ;
2438
2443
}
2439
2444
2440
- CTransactionRef tx = FindTxForGetData (*tx_relay, ToGenTxid (inv));
2441
- if (tx) {
2445
+ if (auto tx{FindTxForGetData (*tx_relay, inv)}) {
2442
2446
// WTX and WITNESS_TX imply we serialize with witness
2443
2447
const auto maybe_with_witness = (inv.IsMsgTx () ? TX_NO_WITNESS : TX_WITH_WITNESS);
2444
2448
MakeAndPushMessage (pfrom, NetMsgType::TX, maybe_with_witness (*tx));
@@ -4294,7 +4298,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4294
4298
// Always relay transactions received from peers with forcerelay
4295
4299
// permission, even if they were already in the mempool, allowing
4296
4300
// 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 ())) {
4298
4302
LogPrintf (" Not relaying non-mempool transaction %s (wtxid=%s) from forcerelay peer=%d\n " ,
4299
4303
tx.GetHash ().ToString (), tx.GetWitnessHash ().ToString (), pfrom.GetId ());
4300
4304
} else {
@@ -4928,11 +4932,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4928
4932
if (msg_type == NetMsgType::NOTFOUND) {
4929
4933
std::vector<CInv> vInv;
4930
4934
vRecv >> vInv;
4931
- std::vector<uint256 > tx_invs;
4935
+ std::vector<GenTxid > tx_invs;
4932
4936
if (vInv.size () <= node::MAX_PEER_TX_ANNOUNCEMENTS + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
4933
4937
for (CInv &inv : vInv) {
4934
4938
if (inv.IsGenTxMsg ()) {
4935
- tx_invs.emplace_back (inv. hash );
4939
+ tx_invs.emplace_back (ToGenTxid ( inv) );
4936
4940
}
4937
4941
}
4938
4942
}
@@ -5432,20 +5436,15 @@ void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::mi
5432
5436
namespace {
5433
5437
class CompareInvMempoolOrder
5434
5438
{
5435
- CTxMemPool* mp;
5436
- bool m_wtxid_relay;
5439
+ const CTxMemPool* m_mempool;
5437
5440
public:
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} {}
5443
5442
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)
5445
5444
{
5446
5445
/* As std::make_heap produces a max-heap, we want the entries with the
5447
5446
* fewest ancestors/highest fee to sort later. */
5448
- return mp ->CompareDepthAndScore (*b, *a, m_wtxid_relay );
5447
+ return m_mempool ->CompareDepthAndScore (*b, *a);
5449
5448
}
5450
5449
};
5451
5450
} // namespace
@@ -5763,7 +5762,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5763
5762
txinfo.tx ->GetWitnessHash ().ToUint256 () :
5764
5763
txinfo.tx ->GetHash ().ToUint256 (),
5765
5764
};
5766
- tx_relay->m_tx_inventory_to_send .erase (inv. hash );
5765
+ tx_relay->m_tx_inventory_to_send .erase (ToGenTxid ( inv) );
5767
5766
5768
5767
// Don't send transactions that peers will not put into their mempool
5769
5768
if (txinfo.fee < filterrate.GetFee (txinfo.vsize )) {
@@ -5784,15 +5783,15 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5784
5783
// Determine transactions to relay
5785
5784
if (fSendTrickle ) {
5786
5785
// Produce a vector with all candidates for sending
5787
- std::vector<std::set<uint256 >::iterator> vInvTx;
5786
+ std::vector<std::set<GenTxid >::iterator> vInvTx;
5788
5787
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++) {
5790
5789
vInvTx.push_back (it);
5791
5790
}
5792
5791
const CFeeRate filterrate{tx_relay->m_fee_filter_received .load ()};
5793
5792
// Topologically and fee-rate sort the inventory we send for privacy and priority reasons.
5794
5793
// 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);
5796
5795
std::make_heap (vInvTx.begin (), vInvTx.end (), compareInvMempoolOrder);
5797
5796
// No reason to drain out at many times the network's capacity,
5798
5797
// especially since we have many peers and some will draw much shorter delays.
@@ -5803,18 +5802,19 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5803
5802
while (!vInvTx.empty () && nRelayedTransactions < broadcast_max) {
5804
5803
// Fetch the top element from the heap
5805
5804
std::pop_heap (vInvTx.begin (), vInvTx.end (), compareInvMempoolOrder);
5806
- std::set<uint256 >::iterator it = vInvTx.back ();
5805
+ std::set<GenTxid >::iterator it = vInvTx.back ();
5807
5806
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 ());
5810
5810
// Remove it from the to-be-sent set
5811
5811
tx_relay->m_tx_inventory_to_send .erase (it);
5812
5812
// 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 () )) {
5814
5814
continue ;
5815
5815
}
5816
5816
// 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)} ;
5818
5818
if (!txinfo.tx ) {
5819
5819
continue ;
5820
5820
}
@@ -5830,7 +5830,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5830
5830
MakeAndPushMessage (*pto, NetMsgType::INV, vInv);
5831
5831
vInv.clear ();
5832
5832
}
5833
- tx_relay->m_tx_inventory_known_filter .insert (hash);
5833
+ tx_relay->m_tx_inventory_known_filter .insert (hash. ToUint256 () );
5834
5834
}
5835
5835
5836
5836
// Ensure we'll respond to GETDATA requests for anything we've just announced
@@ -5953,7 +5953,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5953
5953
{
5954
5954
LOCK (m_tx_download_mutex);
5955
5955
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 ());
5957
5957
if (vGetData.size () >= MAX_GETDATA_SZ) {
5958
5958
MakeAndPushMessage (*pto, NetMsgType::GETDATA, vGetData);
5959
5959
vGetData.clear ();
0 commit comments