From 8ca90f3f99defa239ea1fe0f4d40a245dda71690 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 16 Jul 2019 16:07:14 -0400 Subject: [PATCH] Merge #15891: test: Require standard txs in regtest by default fa89badf887dcc01e5bdece248b5e7d234fee227 test: Require standard txs in regtest (MarcoFalke) fa9b4191609c3ef75e69d391eb91e4d5c1e0bcf5 test: Add test that mainnet requires standard txs (MarcoFalke) fa613ca0a8f99c4771859de9e571878530d3ecb5 chainparams: Remove unused fMineBlocksOnDemand (MarcoFalke) Pull request description: I don't see a reason why regtest should allow non-standard txs, as it makes testing mainnet behaviour such as #15846 unnecessarily hard and unintuitive. Of course, testnet policy remains unchanged to allow propagation of non-standard txs. ACKs for top commit: ajtowns: ACK fa89badf887dcc01e5bdece248b5e7d234fee227 Tree-SHA512: c4c675affb054868850bd2683aa07f4c741a448cbacb2ea8334191e105f426b0790fe6a468be61e9c5880d24154f7bf1c7075051697172dce92180c1bc3a1c90 --- src/chainparams.cpp | 10 +++++----- src/chainparams.h | 8 +++++--- src/init.cpp | 3 ++- test/functional/feature_bip68_sequence.py | 5 ++++- test/functional/feature_block.py | 2 +- test/functional/feature_cltv.py | 7 ++++++- test/functional/feature_config_args.py | 5 +++++ test/functional/feature_dip0020_activation.py | 3 ++- test/functional/feature_fee_estimation.py | 6 +++--- test/functional/feature_maxuploadtarget.py | 2 +- test/functional/mempool_accept.py | 1 - test/functional/mempool_limit.py | 6 +++++- test/functional/mining_prioritisetransaction.py | 5 ++++- test/functional/p2p_compactblocks.py | 5 ++++- test/functional/p2p_invalid_tx.py | 5 ++++- test/functional/wallet_basic.py | 5 ++++- 16 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 995b233cc9..f91cd17b9b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -309,7 +309,7 @@ public: fDefaultConsistencyChecks = false; fRequireStandard = true; fRequireRoutableExternalIP = true; - fMineBlocksOnDemand = false; + m_is_test_chain = false; fAllowMultipleAddressesFromGroup = false; fAllowMultiplePorts = false; nLLMQConnectionRetryTimeout = 60; @@ -525,7 +525,7 @@ public: fDefaultConsistencyChecks = false; fRequireStandard = false; fRequireRoutableExternalIP = true; - fMineBlocksOnDemand = false; + m_is_test_chain = true; fAllowMultipleAddressesFromGroup = false; fAllowMultiplePorts = true; nLLMQConnectionRetryTimeout = 60; @@ -726,7 +726,7 @@ public: fDefaultConsistencyChecks = false; fRequireStandard = false; fRequireRoutableExternalIP = true; - fMineBlocksOnDemand = false; + m_is_test_chain = true; fAllowMultipleAddressesFromGroup = true; fAllowMultiplePorts = true; nLLMQConnectionRetryTimeout = 60; @@ -908,9 +908,9 @@ public: vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds. fDefaultConsistencyChecks = true; - fRequireStandard = false; + fRequireStandard = true; fRequireRoutableExternalIP = false; - fMineBlocksOnDemand = true; + m_is_test_chain = true; fAllowMultipleAddressesFromGroup = true; fAllowMultiplePorts = true; nLLMQConnectionRetryTimeout = 1; // must be lower then the LLMQ signing session timeout so that tests have control over failing behavior diff --git a/src/chainparams.h b/src/chainparams.h index adb4b725f1..09808800e6 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -70,13 +70,15 @@ public: bool RequireStandard() const { return fRequireStandard; } /** Require addresses specified with "-externalip" parameter to be routable */ bool RequireRoutableExternalIP() const { return fRequireRoutableExternalIP; } + /** If this is a test chain */ + bool IsTestChain() const { return m_is_test_chain; } uint64_t PruneAfterHeight() const { return nPruneAfterHeight; } /** Minimum free space (in GB) needed for data directory */ uint64_t AssumedBlockchainSize() const { return m_assumed_blockchain_size; } /** Minimum free space (in GB) needed for data directory when pruned; Does not include prune target*/ uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; } - /** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */ - bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; } + /** Whether it is possible to mine blocks on demand (no retargeting) */ + bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; } /** Allow multiple addresses to be selected from the same network group (e.g. 192.168.x.x) */ bool AllowMultipleAddressesFromGroup() const { return fAllowMultipleAddressesFromGroup; } /** Allow nodes with the same address and multiple ports */ @@ -130,7 +132,7 @@ protected: bool fDefaultConsistencyChecks; bool fRequireStandard; bool fRequireRoutableExternalIP; - bool fMineBlocksOnDemand; + bool m_is_test_chain; bool fAllowMultipleAddressesFromGroup; bool fAllowMultiplePorts; int nLLMQConnectionRetryTimeout; diff --git a/src/init.cpp b/src/init.cpp index 4ceb288b76..a6ae5ceaae 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1494,8 +1494,9 @@ bool AppInitParameterInteraction() } fRequireStandard = !gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()); - if (chainparams.RequireStandard() && !fRequireStandard) + if (!chainparams.IsTestChain() && !fRequireStandard) { return InitError(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.NetworkIDString())); + } nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp); if (!g_wallet_init_interface.ParameterInteraction()) return false; diff --git a/test/functional/feature_bip68_sequence.py b/test/functional/feature_bip68_sequence.py index 5f29f53237..eee3a67314 100755 --- a/test/functional/feature_bip68_sequence.py +++ b/test/functional/feature_bip68_sequence.py @@ -21,7 +21,10 @@ NOT_FINAL_ERROR = "non-BIP68-final (code 64)" class BIP68Test(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 - self.extra_args = [[], ["-acceptnonstdtxn=0"]] + self.extra_args = [ + ["-acceptnonstdtxn=1"], + ["-acceptnonstdtxn=0"], + ] def skip_test_if_missing_module(self): self.skip_if_no_wallet() diff --git a/test/functional/feature_block.py b/test/functional/feature_block.py index 8d4f6ca801..238acc4492 100755 --- a/test/functional/feature_block.py +++ b/test/functional/feature_block.py @@ -82,7 +82,7 @@ class FullBlockTest(BitcoinTestFramework): # which causes RPC to hang, so we need to increase RPC timeouts self.rpc_timeout = 180 # Must set '-dip3params=2000:2000' to create pre-dip3 blocks only - self.extra_args = [['-dip3params=2000:2000']] + self.extra_args = [['-dip3params=2000:2000', '-acceptnonstdtxn=1']] # This is a consensus block test, we don't care about tx policy def setup_nodes(self): self.add_nodes(self.num_nodes, self.extra_args) diff --git a/test/functional/feature_cltv.py b/test/functional/feature_cltv.py index f4b1034e3e..0d3de388f1 100755 --- a/test/functional/feature_cltv.py +++ b/test/functional/feature_cltv.py @@ -59,7 +59,12 @@ def cltv_validate(node, tx, height): class BIP65Test(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 - self.extra_args = [['-whitelist=127.0.0.1', '-dip3params=9000:9000', '-par=1']] # Use only one script thread to get the exact reject reason for testing + self.extra_args = [[ + '-whitelist=127.0.0.1', + '-dip3params=9000:9000', + '-par=1', # Use only one script thread to get the exact reject reason for testing + '-acceptnonstdtxn=1', # cltv_invalidate is nonstandard + ]] self.setup_clean_chain = True self.rpc_timeout = 120 diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py index 16b6598853..450450d842 100755 --- a/test/functional/feature_config_args.py +++ b/test/functional/feature_config_args.py @@ -40,6 +40,11 @@ class ConfArgsTest(BitcoinTestFramework): conf.write("wallet=foo\n") self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Config setting for -wallet only applied on regtest network when in [regtest] section.') + with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: + conf.write('regtest=0\n') # mainnet + conf.write('acceptnonstdtxn=1\n') + self.nodes[0].assert_start_raises_init_error(expected_msg='Error: acceptnonstdtxn is not currently supported for main chain') + with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: conf.write('nono\n') self.nodes[0].assert_start_raises_init_error(expected_msg='Error reading configuration file: parse error on line 1: nono, if you intended to specify a negated option, use nono=1 instead') diff --git a/test/functional/feature_dip0020_activation.py b/test/functional/feature_dip0020_activation.py index 7359723f06..471e4fdc66 100755 --- a/test/functional/feature_dip0020_activation.py +++ b/test/functional/feature_dip0020_activation.py @@ -19,6 +19,7 @@ DISABLED_OPCODE_ERROR = "non-mandatory-script-verify-flag (Attempted to use a di class DIP0020ActivationTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 + self.extra_args = [["-acceptnonstdtxn=1"]] def skip_test_if_missing_module(self): self.skip_if_no_wallet() @@ -31,7 +32,7 @@ class DIP0020ActivationTest(BitcoinTestFramework): utxos = self.node.listunspent() assert len(utxos) > 0 - # Send some coins to a P2SH address constructed using disabled opcodes + # Lock some coins using disabled opcodes utxo = utxos[len(utxos) - 1] value = int(satoshi_round(utxo["amount"] - self.relayfee) * COIN) tx = CTransaction() diff --git a/test/functional/feature_fee_estimation.py b/test/functional/feature_fee_estimation.py index c000df2182..692c71a2f6 100755 --- a/test/functional/feature_fee_estimation.py +++ b/test/functional/feature_fee_estimation.py @@ -126,9 +126,9 @@ class EstimateFeeTest(BitcoinTestFramework): self.num_nodes = 3 # mine non-standard txs (e.g. txs with "dust" outputs) self.extra_args = [ - ["-maxorphantxsize=1000", "-whitelist=127.0.0.1"], - ["-blockmaxsize=17000", "-maxorphantxsize=1000", "-whitelist=127.0.0.1"], - ["-blockmaxsize=8000", "-maxorphantxsize=1000", "-whitelist=127.0.0.1"] + ["-acceptnonstdtxn=1", "-maxorphantxsize=1000", "-whitelist=127.0.0.1"], + ["-acceptnonstdtxn=1", "-blockmaxsize=17000", "-maxorphantxsize=1000", "-whitelist=127.0.0.1"], + ["-acceptnonstdtxn=1", "-blockmaxsize=8000", "-maxorphantxsize=1000", "-whitelist=127.0.0.1"] ] def skip_test_if_missing_module(self): diff --git a/test/functional/feature_maxuploadtarget.py b/test/functional/feature_maxuploadtarget.py index f12ec8a354..8341d14979 100755 --- a/test/functional/feature_maxuploadtarget.py +++ b/test/functional/feature_maxuploadtarget.py @@ -35,7 +35,7 @@ class MaxUploadTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True self.num_nodes = 1 - self.extra_args = [["-maxuploadtarget=200", "-blockmaxsize=999000", "-maxtipage="+str(2*60*60*24*7)]] + self.extra_args = [["-maxuploadtarget=200", "-blockmaxsize=999000", "-maxtipage="+str(2*60*60*24*7), "-acceptnonstdtxn=1"]] # Cache for utxos, as the listunspent may take a long time later in the test self.utxo_cache = [] diff --git a/test/functional/mempool_accept.py b/test/functional/mempool_accept.py index 5f994b9837..f58de536f1 100755 --- a/test/functional/mempool_accept.py +++ b/test/functional/mempool_accept.py @@ -38,7 +38,6 @@ class MempoolAcceptanceTest(BitcoinTestFramework): self.extra_args = [[ '-txindex', '-reindex', # Need reindex for txindex - '-acceptnonstdtxn=0', # Try to mimic main-net ]] * self.num_nodes def skip_test_if_missing_module(self): diff --git a/test/functional/mempool_limit.py b/test/functional/mempool_limit.py index 00da7c5dbf..ee43520ac3 100755 --- a/test/functional/mempool_limit.py +++ b/test/functional/mempool_limit.py @@ -13,7 +13,11 @@ class MempoolLimitTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True self.num_nodes = 1 - self.extra_args = [["-maxmempool=5", "-spendzeroconfchange=0"]] + self.extra_args = [[ + "-acceptnonstdtxn=1", + "-maxmempool=5", + "-spendzeroconfchange=0", + ]] def skip_test_if_missing_module(self): self.skip_if_no_wallet() diff --git a/test/functional/mining_prioritisetransaction.py b/test/functional/mining_prioritisetransaction.py index 0c47c56bff..6df4f44df6 100755 --- a/test/functional/mining_prioritisetransaction.py +++ b/test/functional/mining_prioritisetransaction.py @@ -12,7 +12,10 @@ class PrioritiseTransactionTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True self.num_nodes = 2 - self.extra_args = [["-printpriority=1"]] * 2 + self.extra_args = [[ + "-printpriority=1", + "-acceptnonstdtxn=1", + ]] * self.num_nodes def skip_test_if_missing_module(self): self.skip_if_no_wallet() diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py index 86a61c3abc..9c026277e2 100755 --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -93,7 +93,10 @@ class CompactBlocksTest(BitcoinTestFramework): self.setup_clean_chain = True # both nodes has the same version self.num_nodes = 2 - self.extra_args = [["-txindex"]] * 2 + self.extra_args = [[ + "-txindex", + "-acceptnonstdtxn=1", + ]] * 2 self.utxos = [] def skip_test_if_missing_module(self): diff --git a/test/functional/p2p_invalid_tx.py b/test/functional/p2p_invalid_tx.py index d13c18ded9..322bb58998 100755 --- a/test/functional/p2p_invalid_tx.py +++ b/test/functional/p2p_invalid_tx.py @@ -27,6 +27,9 @@ class InvalidTxRequestTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 + self.extra_args = [[ + "-acceptnonstdtxn=1", + ]] self.setup_clean_chain = True def bootstrap_p2p(self, *, num_connections=1): @@ -100,7 +103,7 @@ class InvalidTxRequestTest(BitcoinTestFramework): self.test_orphan_tx_handling(block1.vtx[0].sha256, False) self.log.info('Test orphan transaction handling, resolve via block') - self.restart_node(0, ['-persistmempool=0']) + self.restart_node(0, ["-acceptnonstdtxn=1", '-persistmempool=0']) self.reconnect_p2p(num_connections=2) self.test_orphan_tx_handling(block2.vtx[0].sha256, True) diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py index fe766073a5..6d00e5ff77 100755 --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -21,8 +21,11 @@ from test_framework.util import ( class WalletTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 4 + self.extra_args = [[ + "-acceptnonstdtxn=1", + '-usehd={:d}'.format(i%2==0), + ] for i in range(self.num_nodes)] self.setup_clean_chain = True - self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)] def skip_test_if_missing_module(self): self.skip_if_no_wallet()