@@ -5235,34 +5235,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
52355235 pfrom->fDisconnect = true ;
52365236 return true ;
52375237 }
5238- LOCK2 (cs_main, pfrom->cs_filter );
52395238
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 ;
52665241 }
52675242
52685243
@@ -5815,13 +5790,52 @@ bool SendMessages(CNode* pto)
58155790 }
58165791 pto->vInventoryBlockToSend .clear ();
58175792
5818- // Determine transactions to relay
5793+ // Check whether periodic sends should happen
58195794 bool fSendTrickle = pto->fWhitelisted ;
58205795 if (pto->nNextInvSend < nNow) {
58215796 fSendTrickle = true ;
58225797 // Use half the delay for outbound peers, as there is less privacy concern for them.
58235798 pto->nNextInvSend = PoissonNextSend (nNow, INVENTORY_BROADCAST_INTERVAL >> !pto->fInbound );
58245799 }
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
58255839 if (fSendTrickle ) {
58265840 // Produce a vector with all candidates for sending
58275841 vector<std::set<uint256>::iterator> vInvTx;
@@ -5851,6 +5865,10 @@ bool SendMessages(CNode* pto)
58515865 // Send
58525866 vInv.push_back (CInv (MSG_TX, hash));
58535867 nRelayedTransactions++;
5868+ if (vInv.size () == MAX_INV_SZ) {
5869+ pto->PushMessage (NetMsgType::INV, vInv);
5870+ vInv.clear ();
5871+ }
58545872 pto->filterInventoryKnown .insert (hash);
58555873 }
58565874 }
0 commit comments