@@ -5235,34 +5235,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
5235
5235
pfrom->fDisconnect = true ;
5236
5236
return true ;
5237
5237
}
5238
- LOCK2 (cs_main, pfrom->cs_filter );
5239
5238
5240
- std::vector<uint256> vtxid;
5241
- mempool.queryHashes (vtxid);
5242
- vector<CInv> vInv;
5243
- BOOST_FOREACH (uint256& hash, vtxid) {
5244
- CInv inv (MSG_TX, hash);
5245
- if (pfrom->pfilter ) {
5246
- CTransaction tx;
5247
- bool fInMemPool = mempool.lookup (hash, tx);
5248
- if (!fInMemPool ) continue ; // another thread removed since queryHashes, maybe...
5249
- if (!pfrom->pfilter ->IsRelevantAndUpdate (tx)) continue ;
5250
- }
5251
- if (pfrom->minFeeFilter ) {
5252
- CFeeRate feeRate;
5253
- mempool.lookupFeeRate (hash, feeRate);
5254
- LOCK (pfrom->cs_feeFilter );
5255
- if (feeRate.GetFeePerK () < pfrom->minFeeFilter )
5256
- continue ;
5257
- }
5258
- vInv.push_back (inv);
5259
- if (vInv.size () == MAX_INV_SZ) {
5260
- pfrom->PushMessage (NetMsgType::INV, vInv);
5261
- vInv.clear ();
5262
- }
5263
- }
5264
- if (vInv.size () > 0 )
5265
- pfrom->PushMessage (NetMsgType::INV, vInv);
5239
+ LOCK (pfrom->cs_inventory );
5240
+ pfrom->fSendMempool = true ;
5266
5241
}
5267
5242
5268
5243
@@ -5815,13 +5790,52 @@ bool SendMessages(CNode* pto)
5815
5790
}
5816
5791
pto->vInventoryBlockToSend .clear ();
5817
5792
5818
- // Determine transactions to relay
5793
+ // Check whether periodic sends should happen
5819
5794
bool fSendTrickle = pto->fWhitelisted ;
5820
5795
if (pto->nNextInvSend < nNow) {
5821
5796
fSendTrickle = true ;
5822
5797
// Use half the delay for outbound peers, as there is less privacy concern for them.
5823
5798
pto->nNextInvSend = PoissonNextSend (nNow, INVENTORY_BROADCAST_INTERVAL >> !pto->fInbound );
5824
5799
}
5800
+
5801
+ // Respond to BIP35 mempool requests
5802
+ if (fSendTrickle && pto->fSendMempool ) {
5803
+ std::vector<uint256> vtxid;
5804
+ mempool.queryHashes (vtxid);
5805
+ pto->fSendMempool = false ;
5806
+ CAmount filterrate = 0 ;
5807
+ {
5808
+ LOCK (pto->cs_feeFilter );
5809
+ filterrate = pto->minFeeFilter ;
5810
+ }
5811
+
5812
+ LOCK (pto->cs_filter );
5813
+
5814
+ BOOST_FOREACH (const uint256& hash, vtxid) {
5815
+ CInv inv (MSG_TX, hash);
5816
+ pto->setInventoryTxToSend .erase (hash);
5817
+ if (filterrate) {
5818
+ CFeeRate feeRate;
5819
+ mempool.lookupFeeRate (hash, feeRate);
5820
+ if (feeRate.GetFeePerK () < filterrate)
5821
+ continue ;
5822
+ }
5823
+ if (pto->pfilter ) {
5824
+ CTransaction tx;
5825
+ bool fInMemPool = mempool.lookup (hash, tx);
5826
+ if (!fInMemPool ) continue ; // another thread removed since queryHashes, maybe...
5827
+ if (!pto->pfilter ->IsRelevantAndUpdate (tx)) continue ;
5828
+ }
5829
+ pto->filterInventoryKnown .insert (hash);
5830
+ vInv.push_back (inv);
5831
+ if (vInv.size () == MAX_INV_SZ) {
5832
+ pto->PushMessage (NetMsgType::INV, vInv);
5833
+ vInv.clear ();
5834
+ }
5835
+ }
5836
+ }
5837
+
5838
+ // Determine transactions to relay
5825
5839
if (fSendTrickle ) {
5826
5840
// Produce a vector with all candidates for sending
5827
5841
vector<std::set<uint256>::iterator> vInvTx;
@@ -5851,6 +5865,10 @@ bool SendMessages(CNode* pto)
5851
5865
// Send
5852
5866
vInv.push_back (CInv (MSG_TX, hash));
5853
5867
nRelayedTransactions++;
5868
+ if (vInv.size () == MAX_INV_SZ) {
5869
+ pto->PushMessage (NetMsgType::INV, vInv);
5870
+ vInv.clear ();
5871
+ }
5854
5872
pto->filterInventoryKnown .insert (hash);
5855
5873
}
5856
5874
}
0 commit comments