Skip to content

Commit aeecb1c

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#21992: p2p: Remove -feefilter option
a7a43e8 Factor feefilter logic out (amadeuszpawlik) c0385f1 Remove -feefilter option (amadeuszpawlik) Pull request description: net: Remove -feefilter option, as it is debug only and isn't used in any tests. Checking this option for every peer on every iteration of the message handler is unnecessary, as described in #21545. refactor: Move feefilter logic out into a separate `MaybeSendFeefilter(...)` function to improve readability of the already long `SendMessages(...)`. fixes #21545 The configuration option `-feefilter` has been added in 9e072a6: _"Implement "feefilter" P2P message"_ According to the [BIP133](https://github.com/bitcoin/bips/blob/master/bip-0133.mediawiki), turning the fee filter off was ment for: > [...] a node [...] using prioritisetransaction to accept transactions whose actual fee rates might fall below the node's mempool min fee [in order to] disable the fee filter to make sure it is exposed to all possible txid's `-feefilter` was subsequently set as debug only in #8150, with the motivation that the help message was too difficult to translate. ACKs for top commit: jnewbery: Code review ACK a7a43e8 promag: Code review ACK a7a43e8. MarcoFalke: review ACK a7a43e8 🦁 Tree-SHA512: 8ef9a2f255597c0279d3047dcc968fd30fb7402e981b69206d08eed452c705ed568c24e646e98d06eac118eddd09205b584f45611d1c874abf38f48b08b67630
2 parents 0a90907 + a7a43e8 commit aeecb1c

File tree

3 files changed

+47
-43
lines changed

3 files changed

+47
-43
lines changed

src/init.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ void SetupServerArgs(NodeContext& node)
390390
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
391391
argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
392392
argsman.AddArg("-dbcache=<n>", strprintf("Maximum database cache size <n> MiB (%d to %d, default: %d). In addition, unused mempool memory is shared for this cache (see -maxmempool).", nMinDbCache, nMaxDbCache, nDefaultDbCache), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
393-
argsman.AddArg("-feefilter", strprintf("Tell other nodes to filter invs to us by our mempool min fee (default: %u)", DEFAULT_FEEFILTER), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
394393
argsman.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
395394
argsman.AddArg("-loadblock=<file>", "Imports blocks from external file on startup", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
396395
argsman.AddArg("-maxmempool=<n>", strprintf("Keep the transaction memory pool below <n> megabytes (default: %u)", DEFAULT_MAX_MEMPOOL_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);

src/net_processing.cpp

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ class PeerManagerImpl final : public PeerManager
364364
*/
365365
void RelayAddress(NodeId originator, const CAddress& addr, bool fReachable);
366366

367+
/** Send `feefilter` message. */
368+
void MaybeSendFeefilter(CNode& node, std::chrono::microseconds current_time) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
369+
367370
const CChainParams& m_chainparams;
368371
CConnman& m_connman;
369372
CAddrMan& m_addrman;
@@ -4276,6 +4279,49 @@ void PeerManagerImpl::MaybeSendAddr(CNode& node, Peer& peer, std::chrono::micros
42764279
}
42774280
}
42784281

4282+
void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, std::chrono::microseconds current_time)
4283+
{
4284+
AssertLockHeld(cs_main);
4285+
4286+
if (m_ignore_incoming_txs) return;
4287+
if (!pto.m_tx_relay) return;
4288+
if (pto.GetCommonVersion() < FEEFILTER_VERSION) return;
4289+
// peers with the forcerelay permission should not filter txs to us
4290+
if (pto.HasPermission(NetPermissionFlags::ForceRelay)) return;
4291+
4292+
CAmount currentFilter = m_mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
4293+
static FeeFilterRounder g_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}};
4294+
4295+
if (m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
4296+
// Received tx-inv messages are discarded when the active
4297+
// chainstate is in IBD, so tell the peer to not send them.
4298+
currentFilter = MAX_MONEY;
4299+
} else {
4300+
static const CAmount MAX_FILTER{g_filter_rounder.round(MAX_MONEY)};
4301+
if (pto.m_tx_relay->lastSentFeeFilter == MAX_FILTER) {
4302+
// Send the current filter if we sent MAX_FILTER previously
4303+
// and made it out of IBD.
4304+
pto.m_tx_relay->m_next_send_feefilter = 0us;
4305+
}
4306+
}
4307+
if (current_time > pto.m_tx_relay->m_next_send_feefilter) {
4308+
CAmount filterToSend = g_filter_rounder.round(currentFilter);
4309+
// We always have a fee filter of at least minRelayTxFee
4310+
filterToSend = std::max(filterToSend, ::minRelayTxFee.GetFeePerK());
4311+
if (filterToSend != pto.m_tx_relay->lastSentFeeFilter) {
4312+
m_connman.PushMessage(&pto, CNetMsgMaker(pto.GetCommonVersion()).Make(NetMsgType::FEEFILTER, filterToSend));
4313+
pto.m_tx_relay->lastSentFeeFilter = filterToSend;
4314+
}
4315+
pto.m_tx_relay->m_next_send_feefilter = PoissonNextSend(current_time, AVG_FEEFILTER_BROADCAST_INTERVAL);
4316+
}
4317+
// If the fee filter has changed substantially and it's still more than MAX_FEEFILTER_CHANGE_DELAY
4318+
// until scheduled broadcast, then move the broadcast to within MAX_FEEFILTER_CHANGE_DELAY.
4319+
else if (current_time + MAX_FEEFILTER_CHANGE_DELAY < pto.m_tx_relay->m_next_send_feefilter &&
4320+
(currentFilter < 3 * pto.m_tx_relay->lastSentFeeFilter / 4 || currentFilter > 4 * pto.m_tx_relay->lastSentFeeFilter / 3)) {
4321+
pto.m_tx_relay->m_next_send_feefilter = current_time + GetRandomDuration<std::chrono::microseconds>(MAX_FEEFILTER_CHANGE_DELAY);
4322+
}
4323+
}
4324+
42794325
namespace {
42804326
class CompareInvMempoolOrder
42814327
{
@@ -4762,46 +4808,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
47624808
if (!vGetData.empty())
47634809
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::GETDATA, vGetData));
47644810

4765-
//
4766-
// Message: feefilter
4767-
//
4768-
if (pto->m_tx_relay != nullptr &&
4769-
!m_ignore_incoming_txs &&
4770-
pto->GetCommonVersion() >= FEEFILTER_VERSION &&
4771-
gArgs.GetBoolArg("-feefilter", DEFAULT_FEEFILTER) &&
4772-
!pto->HasPermission(NetPermissionFlags::ForceRelay) // peers with the forcerelay permission should not filter txs to us
4773-
) {
4774-
CAmount currentFilter = m_mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
4775-
static FeeFilterRounder g_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}};
4776-
if (m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
4777-
// Received tx-inv messages are discarded when the active
4778-
// chainstate is in IBD, so tell the peer to not send them.
4779-
currentFilter = MAX_MONEY;
4780-
} else {
4781-
static const CAmount MAX_FILTER{g_filter_rounder.round(MAX_MONEY)};
4782-
if (pto->m_tx_relay->lastSentFeeFilter == MAX_FILTER) {
4783-
// Send the current filter if we sent MAX_FILTER previously
4784-
// and made it out of IBD.
4785-
pto->m_tx_relay->m_next_send_feefilter = 0us;
4786-
}
4787-
}
4788-
if (current_time > pto->m_tx_relay->m_next_send_feefilter) {
4789-
CAmount filterToSend = g_filter_rounder.round(currentFilter);
4790-
// We always have a fee filter of at least minRelayTxFee
4791-
filterToSend = std::max(filterToSend, ::minRelayTxFee.GetFeePerK());
4792-
if (filterToSend != pto->m_tx_relay->lastSentFeeFilter) {
4793-
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::FEEFILTER, filterToSend));
4794-
pto->m_tx_relay->lastSentFeeFilter = filterToSend;
4795-
}
4796-
pto->m_tx_relay->m_next_send_feefilter = PoissonNextSend(current_time, AVG_FEEFILTER_BROADCAST_INTERVAL);
4797-
}
4798-
// If the fee filter has changed substantially and it's still more than MAX_FEEFILTER_CHANGE_DELAY
4799-
// until scheduled broadcast, then move the broadcast to within MAX_FEEFILTER_CHANGE_DELAY.
4800-
else if (current_time + MAX_FEEFILTER_CHANGE_DELAY < pto->m_tx_relay->m_next_send_feefilter &&
4801-
(currentFilter < 3 * pto->m_tx_relay->lastSentFeeFilter / 4 || currentFilter > 4 * pto->m_tx_relay->lastSentFeeFilter / 3)) {
4802-
pto->m_tx_relay->m_next_send_feefilter = current_time + GetRandomDuration<std::chrono::microseconds>(MAX_FEEFILTER_CHANGE_DELAY);
4803-
}
4804-
}
4811+
MaybeSendFeefilter(*pto, current_time);
48054812
} // release cs_main
48064813
return true;
48074814
}

src/validation.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ static constexpr bool DEFAULT_COINSTATSINDEX{false};
8282
static const char* const DEFAULT_BLOCKFILTERINDEX = "0";
8383
/** Default for -persistmempool */
8484
static const bool DEFAULT_PERSIST_MEMPOOL = true;
85-
/** Default for using fee filter */
86-
static const bool DEFAULT_FEEFILTER = true;
8785
/** Default for -stopatheight */
8886
static const int DEFAULT_STOPATHEIGHT = 0;
8987
/** Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ::ChainActive().Tip() will not be pruned. */

0 commit comments

Comments
 (0)