Skip to content

Commit e3bacef

Browse files
gmaxwellsipa
authored andcommitted
Move bloom and feerate filtering to just prior to tx sending.
This will avoid sending more pointless INVs around updates, and prevents using filter updates to timetag transactions.
1 parent d4a6f40 commit e3bacef

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/main.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5794,6 +5794,9 @@ bool SendMessages(CNode* pto)
57945794
pto->nNextInvSend = PoissonNextSend(nNow, INVENTORY_BROADCAST_INTERVAL >> !pto->fInbound);
57955795
}
57965796

5797+
// Time to send but the peer has requested we not relay transactions.
5798+
if (fSendTrickle && !pto->fRelayTxes) pto->setInventoryTxToSend.clear();
5799+
57975800
// Respond to BIP35 mempool requests
57985801
if (fSendTrickle && pto->fSendMempool) {
57995802
std::vector<uint256> vtxid;
@@ -5839,13 +5842,19 @@ bool SendMessages(CNode* pto)
58395842
for (std::set<uint256>::iterator it = pto->setInventoryTxToSend.begin(); it != pto->setInventoryTxToSend.end(); it++) {
58405843
vInvTx.push_back(it);
58415844
}
5845+
CAmount filterrate = 0;
5846+
{
5847+
LOCK(pto->cs_feeFilter);
5848+
filterrate = pto->minFeeFilter;
5849+
}
58425850
// Topologically and fee-rate sort the inventory we send for privacy and priority reasons.
58435851
// A heap is used so that not all items need sorting if only a few are being sent.
58445852
CompareInvMempoolOrder compareInvMempoolOrder(&mempool);
58455853
std::make_heap(vInvTx.begin(), vInvTx.end(), compareInvMempoolOrder);
58465854
// No reason to drain out at many times the network's capacity,
58475855
// especially since we have many peers and some will draw much shorter delays.
58485856
unsigned int nRelayedTransactions = 0;
5857+
LOCK(pto->cs_filter);
58495858
while (!vInvTx.empty() && nRelayedTransactions < INVENTORY_BROADCAST_MAX) {
58505859
// Fetch the top element from the heap
58515860
std::pop_heap(vInvTx.begin(), vInvTx.end(), compareInvMempoolOrder);
@@ -5858,6 +5867,19 @@ bool SendMessages(CNode* pto)
58585867
if (pto->filterInventoryKnown.contains(hash)) {
58595868
continue;
58605869
}
5870+
// Not in the mempool anymore? don't bother sending it.
5871+
CFeeRate feeRate;
5872+
if (!mempool.lookupFeeRate(*it, feeRate)) {
5873+
continue;
5874+
}
5875+
if (filterrate && feeRate.GetFeePerK() < filterrate) {
5876+
continue;
5877+
}
5878+
if (pto->pfilter) {
5879+
CTransaction tx;
5880+
if (!mempool.lookup(*it, tx)) continue;
5881+
if (!pto->pfilter->IsRelevantAndUpdate(tx)) continue;
5882+
}
58615883
// Send
58625884
vInv.push_back(CInv(MSG_TX, hash));
58635885
nRelayedTransactions++;

src/net.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,20 +2071,7 @@ void RelayTransaction(const CTransaction& tx, CFeeRate feerate)
20712071
LOCK(cs_vNodes);
20722072
BOOST_FOREACH(CNode* pnode, vNodes)
20732073
{
2074-
if(!pnode->fRelayTxes)
2075-
continue;
2076-
{
2077-
LOCK(pnode->cs_feeFilter);
2078-
if (feerate.GetFeePerK() < pnode->minFeeFilter)
2079-
continue;
2080-
}
2081-
LOCK(pnode->cs_filter);
2082-
if (pnode->pfilter)
2083-
{
2084-
if (pnode->pfilter->IsRelevantAndUpdate(tx))
2085-
pnode->PushInventory(inv);
2086-
} else
2087-
pnode->PushInventory(inv);
2074+
pnode->PushInventory(inv);
20882075
}
20892076
}
20902077

0 commit comments

Comments
 (0)