| 4566 | } |
| 4567 | |
| 4568 | void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, std::chrono::microseconds current_time) |
| 4569 | { |
| 4570 | AssertLockHeld(cs_main); |
| 4571 | |
| 4572 | if (m_ignore_incoming_txs) return; |
| 4573 | if (!pto.m_tx_relay) return; |
| 4574 | if (pto.GetCommonVersion() < FEEFILTER_VERSION) return; |
| 4575 | // peers with the forcerelay permission should not filter txs to us |
| 4576 | if (pto.HasPermission(NetPermissionFlags::ForceRelay)) return; |
| 4577 | |
| 4578 | CAmount currentFilter = m_mempool.GetMinFee(gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK(); |
| 4579 | static FeeFilterRounder g_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}}; |
| 4580 | |
| 4581 | if (m_chainman.ActiveChainstate().IsInitialBlockDownload()) { |
| 4582 | // Received tx-inv messages are discarded when the active |
| 4583 | // chainstate is in IBD, so tell the peer to not send them. |
| 4584 | currentFilter = MAX_MONEY; |
| 4585 | } else { |
| 4586 | static const CAmount MAX_FILTER{g_filter_rounder.round(MAX_MONEY)}; |
| 4587 | if (pto.m_tx_relay->lastSentFeeFilter == MAX_FILTER) { |
| 4588 | // Send the current filter if we sent MAX_FILTER previously |
| 4589 | // and made it out of IBD. |
| 4590 | pto.m_tx_relay->m_next_send_feefilter = 0us; |
| 4591 | } |
| 4592 | } |
| 4593 | if (current_time > pto.m_tx_relay->m_next_send_feefilter) { |
| 4594 | CAmount filterToSend = g_filter_rounder.round(currentFilter); |
| 4595 | // We always have a fee filter of at least minRelayTxFee |
| 4596 | filterToSend = std::max(filterToSend, ::minRelayTxFee.GetFeePerK()); |
| 4597 | if (filterToSend != pto.m_tx_relay->lastSentFeeFilter) { |
| 4598 | m_connman.PushMessage(&pto, CNetMsgMaker(pto.GetCommonVersion()).Make(NetMsgType::FEEFILTER, filterToSend)); |
| 4599 | pto.m_tx_relay->lastSentFeeFilter = filterToSend; |
| 4600 | } |
| 4601 | pto.m_tx_relay->m_next_send_feefilter = GetExponentialRand(current_time, AVG_FEEFILTER_BROADCAST_INTERVAL); |
| 4602 | } |
| 4603 | // If the fee filter has changed substantially and it's still more than MAX_FEEFILTER_CHANGE_DELAY |
| 4604 | // until scheduled broadcast, then move the broadcast to within MAX_FEEFILTER_CHANGE_DELAY. |
| 4605 | else if (current_time + MAX_FEEFILTER_CHANGE_DELAY < pto.m_tx_relay->m_next_send_feefilter && |
| 4606 | (currentFilter < 3 * pto.m_tx_relay->lastSentFeeFilter / 4 || currentFilter > 4 * pto.m_tx_relay->lastSentFeeFilter / 3)) { |
| 4607 | pto.m_tx_relay->m_next_send_feefilter = current_time + GetRandomDuration<std::chrono::microseconds>(MAX_FEEFILTER_CHANGE_DELAY); |
| 4608 | } |
| 4609 | } |
| 4610 | |
| 4611 | namespace { |
| 4612 | class CompareInvMempoolOrder |
nothing calls this directly
no test coverage detected