@@ -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
@@ -5811,13 +5786,52 @@ bool SendMessages(CNode* pto)
5811
5786
}
5812
5787
pto->vInventoryBlockToSend .clear ();
5813
5788
5814
- // Determine transactions to relay
5789
+ // Check whether periodic sends should happen
5815
5790
bool fSendTrickle = pto->fWhitelisted ;
5816
5791
if (pto->nNextInvSend < nNow) {
5817
5792
fSendTrickle = true ;
5818
5793
// Use half the delay for outbound peers, as there is less privacy concern for them.
5819
5794
pto->nNextInvSend = PoissonNextSend (nNow, INVENTORY_BROADCAST_INTERVAL >> !pto->fInbound );
5820
5795
}
5796
+
5797
+ // Respond to BIP35 mempool requests
5798
+ if (fSendTrickle && pto->fSendMempool ) {
5799
+ std::vector<uint256> vtxid;
5800
+ mempool.queryHashes (vtxid);
5801
+ pto->fSendMempool = false ;
5802
+ CAmount filterrate = 0 ;
5803
+ {
5804
+ LOCK (pto->cs_feeFilter );
5805
+ filterrate = pto->minFeeFilter ;
5806
+ }
5807
+
5808
+ LOCK (pto->cs_filter );
5809
+
5810
+ BOOST_FOREACH (const uint256& hash, vtxid) {
5811
+ CInv inv (MSG_TX, hash);
5812
+ pto->setInventoryTxToSend .erase (hash);
5813
+ if (filterrate) {
5814
+ CFeeRate feeRate;
5815
+ mempool.lookupFeeRate (hash, feeRate);
5816
+ if (feeRate.GetFeePerK () < filterrate)
5817
+ continue ;
5818
+ }
5819
+ if (pto->pfilter ) {
5820
+ CTransaction tx;
5821
+ bool fInMemPool = mempool.lookup (hash, tx);
5822
+ if (!fInMemPool ) continue ; // another thread removed since queryHashes, maybe...
5823
+ if (!pto->pfilter ->IsRelevantAndUpdate (tx)) continue ;
5824
+ }
5825
+ pto->filterInventoryKnown .insert (hash);
5826
+ vInv.push_back (inv);
5827
+ if (vInv.size () == MAX_INV_SZ) {
5828
+ pto->PushMessage (NetMsgType::INV, vInv);
5829
+ vInv.clear ();
5830
+ }
5831
+ }
5832
+ }
5833
+
5834
+ // Determine transactions to relay
5821
5835
if (fSendTrickle ) {
5822
5836
// Produce a vector with all candidates for sending
5823
5837
vector<std::set<uint256>::iterator> vInvTx;
@@ -5847,6 +5861,10 @@ bool SendMessages(CNode* pto)
5847
5861
// Send
5848
5862
vInv.push_back (CInv (MSG_TX, hash));
5849
5863
nRelayedTransactions++;
5864
+ if (vInv.size () == MAX_INV_SZ) {
5865
+ pto->PushMessage (NetMsgType::INV, vInv);
5866
+ vInv.clear ();
5867
+ }
5850
5868
pto->filterInventoryKnown .insert (hash);
5851
5869
}
5852
5870
}
0 commit comments