Skip to content

Commit

Permalink
Merge bitcoin#15891: test: Require standard txs in regtest by default
Browse files Browse the repository at this point in the history
fa89bad test: Require standard txs in regtest (MarcoFalke)
fa9b419 test: Add test that mainnet requires standard txs (MarcoFalke)
fa613ca 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 bitcoin#15846 unnecessarily hard and unintuitive.

  Of course, testnet policy remains unchanged to allow propagation of non-standard txs.

ACKs for top commit:
  ajtowns:
    ACK fa89bad

Tree-SHA512: c4c675affb054868850bd2683aa07f4c741a448cbacb2ea8334191e105f426b0790fe6a468be61e9c5880d24154f7bf1c7075051697172dce92180c1bc3a1c90
  • Loading branch information
MarcoFalke authored and Munkybooty committed Jan 24, 2022
1 parent 58571c3 commit a8ff955
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class CMainParams : public CChainParams {
fDefaultConsistencyChecks = false;
fRequireStandard = true;
fRequireRoutableExternalIP = true;
fMineBlocksOnDemand = false;
m_is_test_chain = false;
fAllowMultipleAddressesFromGroup = false;
fAllowMultiplePorts = false;
nLLMQConnectionRetryTimeout = 60;
Expand Down Expand Up @@ -525,7 +525,7 @@ class CTestNetParams : public CChainParams {
fDefaultConsistencyChecks = false;
fRequireStandard = false;
fRequireRoutableExternalIP = true;
fMineBlocksOnDemand = false;
m_is_test_chain = true;
fAllowMultipleAddressesFromGroup = false;
fAllowMultiplePorts = true;
nLLMQConnectionRetryTimeout = 60;
Expand Down Expand Up @@ -908,9 +908,9 @@ class CRegTestParams : public CChainParams {
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
Expand Down
8 changes: 5 additions & 3 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ class CChainParams
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 */
Expand Down Expand Up @@ -130,7 +132,7 @@ class CChainParams
bool fDefaultConsistencyChecks;
bool fRequireStandard;
bool fRequireRoutableExternalIP;
bool fMineBlocksOnDemand;
bool m_is_test_chain;
bool fAllowMultipleAddressesFromGroup;
bool fAllowMultiplePorts;
int nLLMQConnectionRetryTimeout;
Expand Down
3 changes: 2 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion test/functional/feature_bip68_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
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()
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def set_test_params(self):
# 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)
Expand Down
6 changes: 5 additions & 1 deletion test/functional/feature_cltv.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ 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

Expand Down
5 changes: 5 additions & 0 deletions test/functional/feature_config_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def test_config_file_parser(self):
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')
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_maxuploadtarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
1 change: 0 additions & 1 deletion test/functional/mempool_accept.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def set_test_params(self):
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):
Expand Down
6 changes: 5 additions & 1 deletion test/functional/mempool_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion test/functional/mining_prioritisetransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion test/functional/p2p_compactblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def set_test_params(self):
self.setup_clean_chain = True
# both nodes has the same version
self.num_nodes = 2
self.extra_args = [["-txindex"]] * 2
self.extra_args = [[
"-acceptnonstdtxn=1",
"-txindex",
]] * 2
self.utxos = []

def skip_test_if_missing_module(self):
Expand Down
3 changes: 3 additions & 0 deletions test/functional/p2p_invalid_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
class WalletTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 4
self.extra_args = [[
"-acceptnonstdtxn=1",
]] * self.num_nodes
self.setup_clean_chain = True
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]

Expand Down

0 comments on commit a8ff955

Please sign in to comment.