MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MaybeSendFeefilter

Method MaybeSendFeefilter

src/net_processing.cpp:5584–5624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5582}
5583
5584void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::microseconds current_time)
5585{
5586 if (m_opts.ignore_incoming_txs) return;
5587 if (pto.GetCommonVersion() < FEEFILTER_VERSION) return;
5588 // peers with the forcerelay permission should not filter txs to us
5589 if (pto.HasPermission(NetPermissionFlags::ForceRelay)) return;
5590 // Don't send feefilter messages to outbound block-relay-only peers since they should never announce
5591 // transactions to us, regardless of feefilter state.
5592 if (pto.IsBlockOnlyConn()) return;
5593
5594 CAmount currentFilter = m_mempool.GetMinFee().GetFeePerK();
5595
5596 if (m_chainman.IsInitialBlockDownload()) {
5597 // Received tx-inv messages are discarded when the active
5598 // chainstate is in IBD, so tell the peer to not send them.
5599 currentFilter = MAX_MONEY;
5600 } else {
5601 static const CAmount MAX_FILTER{m_fee_filter_rounder.round(MAX_MONEY)};
5602 if (peer.m_fee_filter_sent == MAX_FILTER) {
5603 // Send the current filter if we sent MAX_FILTER previously
5604 // and made it out of IBD.
5605 peer.m_next_send_feefilter = 0us;
5606 }
5607 }
5608 if (current_time > peer.m_next_send_feefilter) {
5609 CAmount filterToSend = m_fee_filter_rounder.round(currentFilter);
5610 // We always have a fee filter of at least the min relay fee
5611 filterToSend = std::max(filterToSend, m_mempool.m_opts.min_relay_feerate.GetFeePerK());
5612 if (filterToSend != peer.m_fee_filter_sent) {
5613 MakeAndPushMessage(pto, NetMsgType::FEEFILTER, filterToSend);
5614 peer.m_fee_filter_sent = filterToSend;
5615 }
5616 peer.m_next_send_feefilter = current_time + m_rng.rand_exp_duration(AVG_FEEFILTER_BROADCAST_INTERVAL);
5617 }
5618 // If the fee filter has changed substantially and it's still more than MAX_FEEFILTER_CHANGE_DELAY
5619 // until scheduled broadcast, then move the broadcast to within MAX_FEEFILTER_CHANGE_DELAY.
5620 else if (current_time + MAX_FEEFILTER_CHANGE_DELAY < peer.m_next_send_feefilter &&
5621 (currentFilter < 3 * peer.m_fee_filter_sent / 4 || currentFilter > 4 * peer.m_fee_filter_sent / 3)) {
5622 peer.m_next_send_feefilter = current_time + m_rng.randrange<std::chrono::microseconds>(MAX_FEEFILTER_CHANGE_DELAY);
5623 }
5624}
5625
5626namespace {
5627class CompareInvMempoolOrder

Callers

nothing calls this directly

Calls 8

GetCommonVersionMethod · 0.80
HasPermissionMethod · 0.80
IsBlockOnlyConnMethod · 0.80
GetFeePerKMethod · 0.80
roundMethod · 0.80
rand_exp_durationMethod · 0.80
GetMinFeeMethod · 0.45

Tested by

no test coverage detected