Skip to content

Commit 42e3250

Browse files
committed
[net processing] [refactor] Move m_next_send_feefilter and m_fee_filter_sent
Move m_next_send_feefilter and m_fee_filter_sent out of the `TxRelay` data structure. All of the other members of `TxRelay` are related to sending transactions _to_ the peer, whereas m_fee_filter_sent and m_next_send_feefilter are both related to receiving transactions _from_ the peer. A node's tx relay behaviour is not always symmetrical (eg a blocksonly node will ignore incoming transactions, but may still send out its own transactions), so it doesn't make sense to group the feefilter sending data with the TxRelay data in a single structure. This does not change behaviour, since IsBlockOnlyConn() is always equal to !peer.m_tx_relay. We still don't send feefilter messages to outbound block-relay-only peers (tested in p2p_feefilter.py).
1 parent b74a6dd commit 42e3250

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/net_processing.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ struct Peer {
237237

238238
/** Whether this peer relays txs via wtxid */
239239
std::atomic<bool> m_wtxid_relay{false};
240+
/** The feerate in the most recent BIP133 `feefilter` message sent to the peer.
241+
* It is *not* a p2p protocol violation for the peer to send us
242+
* transactions with a lower fee rate than this. See BIP133. */
243+
CAmount m_fee_filter_sent{0};
244+
/** Timestamp after which we will send the next BIP133 `feefilter` message
245+
* to the peer. */
246+
std::chrono::microseconds m_next_send_feefilter{0};
240247

241248
struct TxRelay {
242249
mutable RecursiveMutex m_bloom_filter_mutex;
@@ -260,8 +267,6 @@ struct Peer {
260267

261268
/** Minimum fee rate with which to filter inv's to this node */
262269
std::atomic<CAmount> m_fee_filter_received{0};
263-
CAmount m_fee_filter_sent{0};
264-
std::chrono::microseconds m_next_send_feefilter{0};
265270
};
266271

267272
/** Transaction relay data. Will be a nullptr if we're not relaying
@@ -4565,10 +4570,12 @@ void PeerManagerImpl::MaybeSendAddr(CNode& node, Peer& peer, std::chrono::micros
45654570
void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::microseconds current_time)
45664571
{
45674572
if (m_ignore_incoming_txs) return;
4568-
if (!peer.m_tx_relay) return;
45694573
if (pto.GetCommonVersion() < FEEFILTER_VERSION) return;
45704574
// peers with the forcerelay permission should not filter txs to us
45714575
if (pto.HasPermission(NetPermissionFlags::ForceRelay)) return;
4576+
// Don't send feefilter messages to outbound block-relay-only peers since they should never announce
4577+
// transactions to us, regardless of feefilter state.
4578+
if (pto.IsBlockOnlyConn()) return;
45724579

45734580
CAmount currentFilter = m_mempool.GetMinFee(gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
45744581
static FeeFilterRounder g_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}};
@@ -4579,27 +4586,27 @@ void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::mi
45794586
currentFilter = MAX_MONEY;
45804587
} else {
45814588
static const CAmount MAX_FILTER{g_filter_rounder.round(MAX_MONEY)};
4582-
if (peer.m_tx_relay->m_fee_filter_sent == MAX_FILTER) {
4589+
if (peer.m_fee_filter_sent == MAX_FILTER) {
45834590
// Send the current filter if we sent MAX_FILTER previously
45844591
// and made it out of IBD.
4585-
peer.m_tx_relay->m_next_send_feefilter = 0us;
4592+
peer.m_next_send_feefilter = 0us;
45864593
}
45874594
}
4588-
if (current_time > peer.m_tx_relay->m_next_send_feefilter) {
4595+
if (current_time > peer.m_next_send_feefilter) {
45894596
CAmount filterToSend = g_filter_rounder.round(currentFilter);
45904597
// We always have a fee filter of at least minRelayTxFee
45914598
filterToSend = std::max(filterToSend, ::minRelayTxFee.GetFeePerK());
4592-
if (filterToSend != peer.m_tx_relay->m_fee_filter_sent) {
4599+
if (filterToSend != peer.m_fee_filter_sent) {
45934600
m_connman.PushMessage(&pto, CNetMsgMaker(pto.GetCommonVersion()).Make(NetMsgType::FEEFILTER, filterToSend));
4594-
peer.m_tx_relay->m_fee_filter_sent = filterToSend;
4601+
peer.m_fee_filter_sent = filterToSend;
45954602
}
4596-
peer.m_tx_relay->m_next_send_feefilter = GetExponentialRand(current_time, AVG_FEEFILTER_BROADCAST_INTERVAL);
4603+
peer.m_next_send_feefilter = GetExponentialRand(current_time, AVG_FEEFILTER_BROADCAST_INTERVAL);
45974604
}
45984605
// If the fee filter has changed substantially and it's still more than MAX_FEEFILTER_CHANGE_DELAY
45994606
// until scheduled broadcast, then move the broadcast to within MAX_FEEFILTER_CHANGE_DELAY.
4600-
else if (current_time + MAX_FEEFILTER_CHANGE_DELAY < peer.m_tx_relay->m_next_send_feefilter &&
4601-
(currentFilter < 3 * peer.m_tx_relay->m_fee_filter_sent / 4 || currentFilter > 4 * peer.m_tx_relay->m_fee_filter_sent / 3)) {
4602-
peer.m_tx_relay->m_next_send_feefilter = current_time + GetRandomDuration<std::chrono::microseconds>(MAX_FEEFILTER_CHANGE_DELAY);
4607+
else if (current_time + MAX_FEEFILTER_CHANGE_DELAY < peer.m_next_send_feefilter &&
4608+
(currentFilter < 3 * peer.m_fee_filter_sent / 4 || currentFilter > 4 * peer.m_fee_filter_sent / 3)) {
4609+
peer.m_next_send_feefilter = current_time + GetRandomDuration<std::chrono::microseconds>(MAX_FEEFILTER_CHANGE_DELAY);
46034610
}
46044611
}
46054612

0 commit comments

Comments
 (0)