Skip to content

Commit fa14860

Browse files
author
MacroFake
committed
Remove ::fRequireStandard global
1 parent fa468bd commit fa14860

File tree

9 files changed

+20
-17
lines changed

9 files changed

+20
-17
lines changed

src/init.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,10 +1004,6 @@ bool AppInitParameterInteraction(const ArgsManager& args, bool use_syscall_sandb
10041004
}
10051005
}
10061006

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-
}
10111007
nBytesPerSigOp = args.GetIntArg("-bytespersigop", nBytesPerSigOp);
10121008

10131009
if (!g_wallet_init_interface.ParameterInteraction()) return false;

src/kernel/mempool_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct MemPoolOptions {
3333
int check_ratio{0};
3434
int64_t max_size_bytes{DEFAULT_MAX_MEMPOOL_SIZE_MB * 1'000'000};
3535
std::chrono::seconds expiry{std::chrono::hours{DEFAULT_MEMPOOL_EXPIRY_HOURS}};
36+
bool require_standard{true};
3637
bool full_rbf{DEFAULT_MEMPOOL_FULL_RBF};
3738
MemPoolLimits limits{};
3839
};

src/mempool_args.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& argsman, con
3939

4040
if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};
4141

42+
mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard());
43+
if (!chainparams.IsTestChain() && !mempool_opts.require_standard) {
44+
return strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.NetworkIDString());
45+
}
46+
4247
mempool_opts.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf);
4348

4449
ApplyArgsManOptions(argsman, mempool_opts.limits);

src/test/fuzz/tx_pool.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,15 @@ void MockTime(FuzzedDataProvider& fuzzed_data_provider, const CChainState& chain
116116
SetMockTime(time);
117117
}
118118

119-
CTxMemPool MakeMempool(const NodeContext& node)
119+
CTxMemPool MakeMempool(FuzzedDataProvider& fuzzed_data_provider, const NodeContext& node)
120120
{
121121
// Take the default options for tests...
122122
CTxMemPool::Options mempool_opts{MemPoolOptionsForTest(node)};
123123

124124
// ...override specific options for this specific fuzz suite
125125
mempool_opts.estimator = nullptr;
126126
mempool_opts.check_ratio = 1;
127+
mempool_opts.require_standard = fuzzed_data_provider.ConsumeBool();
127128

128129
// ...and construct a CTxMemPool from it
129130
return CTxMemPool{mempool_opts};
@@ -150,7 +151,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
150151
constexpr CAmount SUPPLY_TOTAL{COINBASE_MATURITY * 50 * COIN};
151152

152153
SetMempoolConstraints(*node.args, fuzzed_data_provider);
153-
CTxMemPool tx_pool_{MakeMempool(node)};
154+
CTxMemPool tx_pool_{MakeMempool(fuzzed_data_provider, node)};
154155
MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(&tx_pool_);
155156

156157
chainstate.SetMempool(&tx_pool);
@@ -237,7 +238,6 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
237238
auto txr = std::make_shared<TransactionsDelta>(removed, added);
238239
RegisterSharedValidationInterface(txr);
239240
const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
240-
::fRequireStandard = fuzzed_data_provider.ConsumeBool();
241241

242242
// Make sure ProcessNewPackage on one transaction works.
243243
// The result is not guaranteed to be the same as what is returned by ATMP.
@@ -325,7 +325,7 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
325325
}
326326

327327
SetMempoolConstraints(*node.args, fuzzed_data_provider);
328-
CTxMemPool tx_pool_{MakeMempool(node)};
328+
CTxMemPool tx_pool_{MakeMempool(fuzzed_data_provider, node)};
329329
MockedTxPool& tx_pool = *static_cast<MockedTxPool*>(&tx_pool_);
330330

331331
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300)
@@ -348,7 +348,6 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
348348

349349
const auto tx = MakeTransactionRef(mut_tx);
350350
const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
351-
::fRequireStandard = fuzzed_data_provider.ConsumeBool();
352351
const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx, GetTime(), bypass_limits, /*test_accept=*/false));
353352
const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
354353
if (accepted) {

src/txmempool.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ CTxMemPool::CTxMemPool(const Options& opts)
458458
minerPolicyEstimator{opts.estimator},
459459
m_max_size_bytes{opts.max_size_bytes},
460460
m_expiry{opts.expiry},
461+
m_require_standard{opts.require_standard},
461462
m_full_rbf{opts.full_rbf},
462463
m_limits{opts.limits}
463464
{

src/txmempool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ class CTxMemPool
568568

569569
const int64_t m_max_size_bytes;
570570
const std::chrono::seconds m_expiry;
571+
const bool m_require_standard;
571572
const bool m_full_rbf;
572573

573574
using Limits = kernel::MemPoolLimits;

src/validation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ GlobalMutex g_best_block_mutex;
124124
std::condition_variable g_best_block_cv;
125125
uint256 g_best_block;
126126
bool g_parallel_script_checks{false};
127-
bool fRequireStandard = true;
128127
bool fCheckBlockIndex = false;
129128
bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED;
130129
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
@@ -700,8 +699,9 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
700699

701700
// Rather not work on nonstandard transactions (unless -testnet/-regtest)
702701
std::string reason;
703-
if (fRequireStandard && !IsStandardTx(tx, reason))
702+
if (m_pool.m_require_standard && !IsStandardTx(tx, reason)) {
704703
return state.Invalid(TxValidationResult::TX_NOT_STANDARD, reason);
704+
}
705705

706706
// Do not work on transactions that are too small.
707707
// A transaction with 1 segwit input and 1 P2WPHK output has non-witness size of 82 bytes.
@@ -807,13 +807,14 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
807807
return false; // state filled in by CheckTxInputs
808808
}
809809

810-
if (fRequireStandard && !AreInputsStandard(tx, m_view)) {
810+
if (m_pool.m_require_standard && !AreInputsStandard(tx, m_view)) {
811811
return state.Invalid(TxValidationResult::TX_INPUTS_NOT_STANDARD, "bad-txns-nonstandard-inputs");
812812
}
813813

814814
// Check for non-standard witnesses.
815-
if (tx.HasWitness() && fRequireStandard && !IsWitnessStandard(tx, m_view))
815+
if (tx.HasWitness() && m_pool.m_require_standard && !IsWitnessStandard(tx, m_view)) {
816816
return state.Invalid(TxValidationResult::TX_WITNESS_MUTATED, "bad-witness-nonstandard");
817+
}
817818

818819
int64_t nSigOpsCost = GetTransactionSigOpCost(tx, m_view, STANDARD_SCRIPT_VERIFY_FLAGS);
819820

src/validation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ extern uint256 g_best_block;
100100
* False indicates all script checking is done on the main threadMessageHandler thread.
101101
*/
102102
extern bool g_parallel_script_checks;
103-
extern bool fRequireStandard;
104103
extern bool fCheckBlockIndex;
105104
extern bool fCheckpointsEnabled;
106105
/** If the tip is older than this (in seconds), the node is considered to be in initial block download. */

test/functional/p2p_segwit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def run_test(self):
245245
self.test_node = self.nodes[0].add_p2p_connection(TestP2PConn(), services=P2P_SERVICES)
246246
# self.old_node sets only NODE_NETWORK
247247
self.old_node = self.nodes[0].add_p2p_connection(TestP2PConn(), services=NODE_NETWORK)
248-
# self.std_node is for testing node1 (fRequireStandard=true)
248+
# self.std_node is for testing node1 (requires standard txs)
249249
self.std_node = self.nodes[1].add_p2p_connection(TestP2PConn(), services=P2P_SERVICES)
250250
# self.std_wtx_node is for testing node1 with wtxid relay
251251
self.std_wtx_node = self.nodes[1].add_p2p_connection(TestP2PConn(wtxidrelay=True), services=P2P_SERVICES)
@@ -1382,15 +1382,15 @@ def test_segwit_versions(self):
13821382
tx3.vout.append(CTxOut(total_value - 1000, script_pubkey))
13831383
tx3.rehash()
13841384

1385-
# First we test this transaction against fRequireStandard=true node
1385+
# First we test this transaction against std_node
13861386
# making sure the txid is added to the reject filter
13871387
self.std_node.announce_tx_and_wait_for_getdata(tx3)
13881388
test_transaction_acceptance(self.nodes[1], self.std_node, tx3, with_witness=True, accepted=False, reason="bad-txns-nonstandard-inputs")
13891389
# Now the node will no longer ask for getdata of this transaction when advertised by same txid
13901390
self.std_node.announce_tx_and_wait_for_getdata(tx3, success=False)
13911391

13921392
# Spending a higher version witness output is not allowed by policy,
1393-
# even with fRequireStandard=false.
1393+
# even with the node that accepts non-standard txs.
13941394
test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=False, reason="reserved for soft-fork upgrades")
13951395

13961396
# Building a block with the transaction must be valid, however.

0 commit comments

Comments
 (0)