Skip to content

Commit f6fdedf

Browse files
committed
Merge bitcoin/bitcoin#25648: refactor: Remove all policy globals
ddddd69 sort after scripted-diff (MacroFake) fac812c scripted-diff: Move mempool_args to src/node (MacroFake) 6666438 Remove ::g_max_datacarrier_bytes global (MacroFake) fad0b4f Pass datacarrier setting into IsStandard (MacroFake) fa2a6b8 Combine datacarrier globals into one (MacroFake) fa477d3 Remove ::GetVirtualTransactionSize() alias (MacroFake) fa2f6c1 Remove ::fIsBareMultisigStd global (MacroFake) fadc14e Remove ::dustRelayFee (MacroFake) fa8a7f0 Remove ::IsStandardTx(tx, reason) alias (MacroFake) fa7a911 test: Remove unused cs_main (MacroFake) fa9cba7 Remove ::incrementalRelayFee and ::minRelayTxFee globals (MacroFake) fa14860 Remove ::fRequireStandard global (MacroFake) fa468bd Return optional error from ApplyArgsManOptions (MacroFake) Pull request description: This change is good because: * It moves module-specific init-logic out of the bloated init.cpp * It removes a global from validation.cpp and places it into the data structure that needs it (mempool) ACKs for top commit: glozow: re ACK ddddd69 ryanofsky: Code review ACK ddddd69 ariard: Light Code Review ACK ddddd69 Tree-SHA512: 9de2ce601cfcaa4dfd7d1c92270568895ce8702ccdffb59829fbe9618eab0fd88d738afef33ed66988c66861115e0340e881056bfb71e2aed4af2440bd37eb1e
2 parents de3c46c + ddddd69 commit f6fdedf

39 files changed

+269
-229
lines changed

ci/test/06_script_b.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if [ "${RUN_TIDY}" = "true" ]; then
4545
" src/init"\
4646
" src/kernel"\
4747
" src/node/chainstate.cpp"\
48+
" src/node/mempool_args.cpp"\
4849
" src/policy/feerate.cpp"\
4950
" src/policy/packages.cpp"\
5051
" src/policy/settings.cpp"\

doc/policy/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
**Policy** (Mempool or Transaction Relay Policy) is the node's set of validation rules, in addition
44
to consensus, enforced for unconfirmed transactions before submitting them to the mempool. These
55
rules are local to the node and configurable (e.g. `-minrelaytxfee`, `-limitancestorsize`,
6-
`-incrementalRelayFee`). Policy may include restrictions on the transaction itself, the transaction
6+
`-incrementalrelayfee`). Policy may include restrictions on the transaction itself, the transaction
77
in relation to the current chain tip, and the transaction in relation to the node's mempool
88
contents. Policy is *not* applied to transactions in blocks.
99

doc/policy/mempool-replacements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ This set of rules is similar but distinct from BIP125.
7171
Bitcoin Core implementation.
7272

7373
* The incremental relay feerate used to calculate the required additional fees is distinct from
74-
`minRelayTxFee` and configurable using `-incrementalrelayfee`
74+
`-minrelaytxfee` and configurable using `-incrementalrelayfee`
7575
([PR #9380](https://github.com/bitcoin/bitcoin/pull/9380)).
7676

7777
* RBF enabled by default in the wallet GUI as of **v0.18.1** ([PR

doc/policy/packages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ If any transactions in the package are already in the mempool, they are not subm
8181
("deduplicated") and are thus excluded from this calculation.
8282

8383
To meet the two feerate requirements of a mempool, i.e., the pre-configured minimum relay feerate
84-
(`minRelayTxFee`) and the dynamic mempool minimum feerate, the total package feerate is used instead
84+
(`-minrelaytxfee`) and the dynamic mempool minimum feerate, the total package feerate is used instead
8585
of the individual feerate. The individual transactions are allowed to be below the feerate
8686
requirements if the package meets the feerate requirements. For example, the parent(s) in the
8787
package can pay no fees but be paid for by the child.

src/Makefile.am

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ BITCOIN_CORE_H = \
139139
compat/cpuid.h \
140140
compat/endian.h \
141141
compressor.h \
142-
node/connection_types.h \
143142
consensus/consensus.h \
144143
consensus/tx_check.h \
145144
consensus/tx_verify.h \
@@ -149,7 +148,6 @@ BITCOIN_CORE_H = \
149148
dbwrapper.h \
150149
deploymentinfo.h \
151150
deploymentstatus.h \
152-
node/eviction.h \
153151
external_signer.h \
154152
flatfile.h \
155153
fs.h \
@@ -184,7 +182,6 @@ BITCOIN_CORE_H = \
184182
logging.h \
185183
logging/timer.h \
186184
mapport.h \
187-
mempool_args.h \
188185
memusage.h \
189186
merkleblock.h \
190187
net.h \
@@ -199,13 +196,16 @@ BITCOIN_CORE_H = \
199196
node/caches.h \
200197
node/chainstate.h \
201198
node/coin.h \
199+
node/connection_types.h \
202200
node/context.h \
201+
node/eviction.h \
202+
node/interface_ui.h \
203+
node/mempool_args.h \
203204
node/mempool_persist_args.h \
204205
node/miner.h \
205206
node/minisketchwrapper.h \
206207
node/psbt.h \
207208
node/transaction.h \
208-
node/interface_ui.h \
209209
node/utxo_snapshot.h \
210210
noui.h \
211211
outputtype.h \
@@ -372,24 +372,24 @@ libbitcoin_node_a_SOURCES = \
372372
kernel/context.cpp \
373373
kernel/mempool_persist.cpp \
374374
mapport.cpp \
375-
mempool_args.cpp \
376375
net.cpp \
377-
netgroup.cpp \
378376
net_processing.cpp \
377+
netgroup.cpp \
379378
node/blockstorage.cpp \
380379
node/caches.cpp \
381380
node/chainstate.cpp \
382381
node/coin.cpp \
383382
node/connection_types.cpp \
384383
node/context.cpp \
385384
node/eviction.cpp \
385+
node/interface_ui.cpp \
386386
node/interfaces.cpp \
387+
node/mempool_args.cpp \
387388
node/mempool_persist_args.cpp \
388389
node/miner.cpp \
389390
node/minisketchwrapper.cpp \
390391
node/psbt.cpp \
391392
node/transaction.cpp \
392-
node/interface_ui.cpp \
393393
noui.cpp \
394394
policy/fees.cpp \
395395
policy/fees_args.cpp \
@@ -402,8 +402,8 @@ libbitcoin_node_a_SOURCES = \
402402
rpc/fees.cpp \
403403
rpc/mempool.cpp \
404404
rpc/mining.cpp \
405-
rpc/node.cpp \
406405
rpc/net.cpp \
406+
rpc/node.cpp \
407407
rpc/output_script.cpp \
408408
rpc/rawtransaction.cpp \
409409
rpc/server.cpp \

src/init.cpp

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <interfaces/init.h>
3232
#include <interfaces/node.h>
3333
#include <mapport.h>
34-
#include <mempool_args.h>
3534
#include <net.h>
3635
#include <net_permissions.h>
3736
#include <net_processing.h>
@@ -42,6 +41,7 @@
4241
#include <node/chainstate.h>
4342
#include <node/context.h>
4443
#include <node/interface_ui.h>
44+
#include <node/mempool_args.h>
4545
#include <node/mempool_persist_args.h>
4646
#include <node/miner.h>
4747
#include <policy/feerate.h>
@@ -935,16 +935,6 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
935935
LogPrintf("Warning: nMinimumChainWork set below default value of %s\n", chainparams.GetConsensus().nMinimumChainWork.GetHex());
936936
}
937937

938-
// incremental relay fee sets the minimum feerate increase necessary for BIP 125 replacement in the mempool
939-
// and the amount the mempool min fee increases above the feerate of txs evicted due to mempool limiting.
940-
if (args.IsArgSet("-incrementalrelayfee")) {
941-
if (std::optional<CAmount> inc_relay_fee = ParseMoney(args.GetArg("-incrementalrelayfee", ""))) {
942-
::incrementalRelayFee = CFeeRate{inc_relay_fee.value()};
943-
} else {
944-
return InitError(AmountErrMsg("incrementalrelayfee", args.GetArg("-incrementalrelayfee", "")));
945-
}
946-
}
947-
948938
// block pruning; get the amount of disk space (in MiB) to allot for block & undo files
949939
int64_t nPruneArg = args.GetIntArg("-prune", 0);
950940
if (nPruneArg < 0) {
@@ -973,19 +963,6 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
973963
return InitError(Untranslated("peertimeout must be a positive integer."));
974964
}
975965

976-
if (args.IsArgSet("-minrelaytxfee")) {
977-
if (std::optional<CAmount> min_relay_fee = ParseMoney(args.GetArg("-minrelaytxfee", ""))) {
978-
// High fee check is done afterward in CWallet::Create()
979-
::minRelayTxFee = CFeeRate{min_relay_fee.value()};
980-
} else {
981-
return InitError(AmountErrMsg("minrelaytxfee", args.GetArg("-minrelaytxfee", "")));
982-
}
983-
} else if (incrementalRelayFee > ::minRelayTxFee) {
984-
// Allow only setting incrementalRelayFee to control both
985-
::minRelayTxFee = incrementalRelayFee;
986-
LogPrintf("Increasing minrelaytxfee to %s to match incrementalrelayfee\n",::minRelayTxFee.ToString());
987-
}
988-
989966
// Sanity check argument for min fee for including tx in block
990967
// TODO: Harmonize which arguments need sanity checking and where that happens
991968
if (args.IsArgSet("-blockmintxfee")) {
@@ -994,28 +971,10 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
994971
}
995972
}
996973

997-
// Feerate used to define dust. Shouldn't be changed lightly as old
998-
// implementations may inadvertently create non-standard transactions
999-
if (args.IsArgSet("-dustrelayfee")) {
1000-
if (std::optional<CAmount> parsed = ParseMoney(args.GetArg("-dustrelayfee", ""))) {
1001-
dustRelayFee = CFeeRate{parsed.value()};
1002-
} else {
1003-
return InitError(AmountErrMsg("dustrelayfee", args.GetArg("-dustrelayfee", "")));
1004-
}
1005-
}
1006-
1007-
fRequireStandard = !args.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
1008-
if (!chainparams.IsTestChain() && !fRequireStandard) {
1009-
return InitError(strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.NetworkIDString()));
1010-
}
1011974
nBytesPerSigOp = args.GetIntArg("-bytespersigop", nBytesPerSigOp);
1012975

1013976
if (!g_wallet_init_interface.ParameterInteraction()) return false;
1014977

1015-
fIsBareMultisigStd = args.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
1016-
fAcceptDatacarrier = args.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER);
1017-
nMaxDatacarrierBytes = args.GetIntArg("-datacarriersize", nMaxDatacarrierBytes);
1018-
1019978
// Option to startup with mocktime set (used for regression testing):
1020979
SetMockTime(args.GetIntArg("-mocktime", 0)); // SetMockTime(0) is a no-op
1021980

@@ -1418,7 +1377,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14181377
.estimator = node.fee_estimator.get(),
14191378
.check_ratio = chainparams.DefaultConsistencyChecks() ? 1 : 0,
14201379
};
1421-
ApplyArgsManOptions(args, mempool_opts);
1380+
if (const auto err{ApplyArgsManOptions(args, chainparams, mempool_opts)}) {
1381+
return InitError(*err);
1382+
}
14221383
mempool_opts.check_ratio = std::clamp<int>(mempool_opts.check_ratio, 0, 1'000'000);
14231384

14241385
int64_t descendant_limit_bytes = mempool_opts.limits.descendant_size_vbytes * 40;

src/kernel/mempool_options.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66

77
#include <kernel/mempool_limits.h>
88

9+
#include <policy/feerate.h>
10+
#include <policy/policy.h>
11+
#include <script/standard.h>
12+
913
#include <chrono>
1014
#include <cstdint>
15+
#include <optional>
1116

1217
class CBlockPolicyEstimator;
1318

@@ -33,6 +38,20 @@ struct MemPoolOptions {
3338
int check_ratio{0};
3439
int64_t max_size_bytes{DEFAULT_MAX_MEMPOOL_SIZE_MB * 1'000'000};
3540
std::chrono::seconds expiry{std::chrono::hours{DEFAULT_MEMPOOL_EXPIRY_HOURS}};
41+
CFeeRate incremental_relay_feerate{DEFAULT_INCREMENTAL_RELAY_FEE};
42+
/** A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) */
43+
CFeeRate min_relay_feerate{DEFAULT_MIN_RELAY_TX_FEE};
44+
CFeeRate dust_relay_feerate{DUST_RELAY_TX_FEE};
45+
/**
46+
* A data carrying output is an unspendable output containing data. The script
47+
* type is designated as TxoutType::NULL_DATA.
48+
*
49+
* Maximum size of TxoutType::NULL_DATA scripts that this node considers standard.
50+
* If nullopt, any size is nonstandard.
51+
*/
52+
std::optional<unsigned> max_datacarrier_bytes{DEFAULT_ACCEPT_DATACARRIER ? std::optional{MAX_OP_RETURN_RELAY} : std::nullopt};
53+
bool permit_bare_multisig{DEFAULT_PERMIT_BAREMULTISIG};
54+
bool require_standard{true};
3655
bool full_rbf{DEFAULT_MEMPOOL_FULL_RBF};
3756
MemPoolLimits limits{};
3857
};

src/mempool_args.cpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4759,8 +4759,8 @@ void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::mi
47594759
}
47604760
if (current_time > peer.m_next_send_feefilter) {
47614761
CAmount filterToSend = g_filter_rounder.round(currentFilter);
4762-
// We always have a fee filter of at least minRelayTxFee
4763-
filterToSend = std::max(filterToSend, ::minRelayTxFee.GetFeePerK());
4762+
// We always have a fee filter of at least the min relay fee
4763+
filterToSend = std::max(filterToSend, m_mempool.m_min_relay_feerate.GetFeePerK());
47644764
if (filterToSend != peer.m_fee_filter_sent) {
47654765
m_connman.PushMessage(&pto, CNetMsgMaker(pto.GetCommonVersion()).Make(NetMsgType::FEEFILTER, filterToSend));
47664766
peer.m_fee_filter_sent = filterToSend;

src/node/interfaces.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,11 @@ class NodeImpl : public Node
301301
}
302302
}
303303
bool getNetworkActive() override { return m_context->connman && m_context->connman->GetNetworkActive(); }
304-
CFeeRate getDustRelayFee() override { return ::dustRelayFee; }
304+
CFeeRate getDustRelayFee() override
305+
{
306+
if (!m_context->mempool) return CFeeRate{DUST_RELAY_TX_FEE};
307+
return m_context->mempool->m_dust_relay_feerate;
308+
}
305309
UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override
306310
{
307311
JSONRPCRequest req;
@@ -676,9 +680,21 @@ class ChainImpl : public Chain
676680
if (!m_node.mempool) return {};
677681
return m_node.mempool->GetMinFee();
678682
}
679-
CFeeRate relayMinFee() override { return ::minRelayTxFee; }
680-
CFeeRate relayIncrementalFee() override { return ::incrementalRelayFee; }
681-
CFeeRate relayDustFee() override { return ::dustRelayFee; }
683+
CFeeRate relayMinFee() override
684+
{
685+
if (!m_node.mempool) return CFeeRate{DEFAULT_MIN_RELAY_TX_FEE};
686+
return m_node.mempool->m_min_relay_feerate;
687+
}
688+
CFeeRate relayIncrementalFee() override
689+
{
690+
if (!m_node.mempool) return CFeeRate{DEFAULT_INCREMENTAL_RELAY_FEE};
691+
return m_node.mempool->m_incremental_relay_feerate;
692+
}
693+
CFeeRate relayDustFee() override
694+
{
695+
if (!m_node.mempool) return CFeeRate{DUST_RELAY_TX_FEE};
696+
return m_node.mempool->m_dust_relay_feerate;
697+
}
682698
bool havePruned() override
683699
{
684700
LOCK(::cs_main);

0 commit comments

Comments
 (0)