@@ -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<GenTxidVariant > 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;
@@ -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
}
@@ -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 ? GenTxidVariant{ wtxid} : GenTxidVariant{ 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,
@@ -5442,20 +5442,15 @@ void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::mi
5442
5442
namespace {
5443
5443
class CompareInvMempoolOrder
5444
5444
{
5445
- CTxMemPool* mp;
5446
- bool m_wtxid_relay;
5445
+ const CTxMemPool* m_mempool;
5447
5446
public:
5448
- explicit CompareInvMempoolOrder (CTxMemPool *_mempool, bool use_wtxid)
5449
- {
5450
- mp = _mempool;
5451
- m_wtxid_relay = use_wtxid;
5452
- }
5447
+ explicit CompareInvMempoolOrder (CTxMemPool* mempool) : m_mempool{mempool} {}
5453
5448
5454
- bool operator ()(std::set<uint256 >::iterator a, std::set<uint256 >::iterator b)
5449
+ bool operator ()(std::set<GenTxidVariant >::iterator a, std::set<GenTxidVariant >::iterator b)
5455
5450
{
5456
5451
/* As std::make_heap produces a max-heap, we want the entries with the
5457
5452
* fewest ancestors/highest fee to sort later. */
5458
- return mp ->CompareDepthAndScore (*b, *a, m_wtxid_relay );
5453
+ return m_mempool ->CompareDepthAndScore (*b, *a);
5459
5454
}
5460
5455
};
5461
5456
} // namespace
@@ -5773,7 +5768,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5773
5768
txinfo.tx ->GetWitnessHash ().ToUint256 () :
5774
5769
txinfo.tx ->GetHash ().ToUint256 (),
5775
5770
};
5776
- tx_relay->m_tx_inventory_to_send .erase (inv. hash );
5771
+ tx_relay->m_tx_inventory_to_send .erase (ToGenTxid ( inv). ToVariant () );
5777
5772
5778
5773
// Don't send transactions that peers will not put into their mempool
5779
5774
if (txinfo.fee < filterrate.GetFee (txinfo.vsize )) {
@@ -5794,15 +5789,15 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5794
5789
// Determine transactions to relay
5795
5790
if (fSendTrickle ) {
5796
5791
// Produce a vector with all candidates for sending
5797
- std::vector<std::set<uint256 >::iterator> vInvTx;
5792
+ std::vector<std::set<GenTxidVariant >::iterator> vInvTx;
5798
5793
vInvTx.reserve (tx_relay->m_tx_inventory_to_send .size ());
5799
- for (std::set<uint256 >::iterator it = tx_relay->m_tx_inventory_to_send .begin (); it != tx_relay->m_tx_inventory_to_send .end (); it++) {
5794
+ for (std::set<GenTxidVariant >::iterator it = tx_relay->m_tx_inventory_to_send .begin (); it != tx_relay->m_tx_inventory_to_send .end (); it++) {
5800
5795
vInvTx.push_back (it);
5801
5796
}
5802
5797
const CFeeRate filterrate{tx_relay->m_fee_filter_received .load ()};
5803
5798
// Topologically and fee-rate sort the inventory we send for privacy and priority reasons.
5804
5799
// A heap is used so that not all items need sorting if only a few are being sent.
5805
- CompareInvMempoolOrder compareInvMempoolOrder (&m_mempool, peer-> m_wtxid_relay );
5800
+ CompareInvMempoolOrder compareInvMempoolOrder (&m_mempool);
5806
5801
std::make_heap (vInvTx.begin (), vInvTx.end (), compareInvMempoolOrder);
5807
5802
// No reason to drain out at many times the network's capacity,
5808
5803
// especially since we have many peers and some will draw much shorter delays.
@@ -5813,14 +5808,15 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5813
5808
while (!vInvTx.empty () && nRelayedTransactions < broadcast_max) {
5814
5809
// Fetch the top element from the heap
5815
5810
std::pop_heap (vInvTx.begin (), vInvTx.end (), compareInvMempoolOrder);
5816
- std::set<uint256 >::iterator it = vInvTx.back ();
5811
+ std::set<GenTxidVariant >::iterator it = vInvTx.back ();
5817
5812
vInvTx.pop_back ();
5818
- uint256 hash = *it;
5819
- CInv inv (peer->m_wtxid_relay ? MSG_WTX : MSG_TX, hash);
5813
+ GenTxidVariant hash = *it;
5814
+ Assume (peer->m_wtxid_relay == hash.IsWtxid ());
5815
+ CInv inv (peer->m_wtxid_relay ? MSG_WTX : MSG_TX, hash.ToUint256 ());
5820
5816
// Remove it from the to-be-sent set
5821
5817
tx_relay->m_tx_inventory_to_send .erase (it);
5822
5818
// Check if not in the filter already
5823
- if (tx_relay->m_tx_inventory_known_filter .contains (hash)) {
5819
+ if (tx_relay->m_tx_inventory_known_filter .contains (hash. ToUint256 () )) {
5824
5820
continue ;
5825
5821
}
5826
5822
// Not in the mempool anymore? don't bother sending it.
@@ -5840,7 +5836,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
5840
5836
MakeAndPushMessage (*pto, NetMsgType::INV, vInv);
5841
5837
vInv.clear ();
5842
5838
}
5843
- tx_relay->m_tx_inventory_known_filter .insert (hash);
5839
+ tx_relay->m_tx_inventory_known_filter .insert (hash. ToUint256 () );
5844
5840
}
5845
5841
5846
5842
// Ensure we'll respond to GETDATA requests for anything we've just announced
0 commit comments