2017-12-20 09:34:08 +01:00
#!/usr/bin/env python3
2023-04-25 13:51:26 +02:00
# Copyright (c) 2017-2020 The Bitcoin Core developers
2017-12-20 09:34:08 +01:00
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
""" Test various command line arguments and configuration file parameters. """
import os
2020-09-05 18:51:33 +02:00
import time
2017-12-20 09:34:08 +01:00
from test_framework . test_framework import BitcoinTestFramework
2021-01-21 16:48:24 +01:00
from test_framework import util
2018-03-22 11:04:37 +01:00
2017-12-20 09:34:08 +01:00
class ConfArgsTest ( BitcoinTestFramework ) :
def set_test_params ( self ) :
self . setup_clean_chain = True
self . num_nodes = 1
2019-12-09 19:52:38 +01:00
self . supports_cli = False
2022-11-30 20:23:48 +01:00
self . wallet_names = [ ]
2017-12-20 09:34:08 +01:00
2018-09-06 12:52:06 +02:00
def test_config_file_parser ( self ) :
2021-02-21 11:01:20 +01:00
self . stop_node ( 0 )
2018-09-06 12:52:06 +02:00
inc_conf_file_path = os . path . join ( self . nodes [ 0 ] . datadir , ' include.conf ' )
2021-07-19 20:00:59 +02:00
with open ( os . path . join ( self . nodes [ 0 ] . datadir , ' dash.conf ' ) , ' a ' , encoding = ' utf-8 ' ) as conf :
2018-09-06 12:52:06 +02:00
conf . write ( ' includeconf= {} \n ' . format ( inc_conf_file_path ) )
2019-06-20 22:59:10 +02:00
self . nodes [ 0 ] . assert_start_raises_init_error (
2020-02-05 15:46:55 +01:00
expected_msg = ' Error: Error parsing command line arguments: Invalid parameter -dash_cli=1 ' ,
2019-06-20 22:59:10 +02:00
extra_args = [ ' -dash_cli=1 ' ] ,
)
with open ( inc_conf_file_path , ' w ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' dash_conf=1 \n ' )
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [ ' Ignoring unknown configuration value dash_conf ' ] ) :
self . start_node ( 0 )
self . stop_node ( 0 )
2018-09-06 12:52:06 +02:00
with open ( inc_conf_file_path , ' w ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' -dash=1 \n ' )
2019-07-10 14:06:57 +02:00
self . nodes [ 0 ] . assert_start_raises_init_error ( expected_msg = ' Error: Error reading configuration file: parse error on line 1: -dash=1, options in configuration file must be specified without leading - ' )
2018-09-06 12:52:06 +02:00
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
if self . is_wallet_compiled ( ) :
with open ( inc_conf_file_path , ' w ' , encoding = ' utf8 ' ) as conf :
conf . write ( " wallet=foo \n " )
2020-02-04 21:55:18 +01:00
self . nodes [ 0 ] . assert_start_raises_init_error ( expected_msg = ' Error: Config setting for -wallet only applied on %s network when in [ %s ] section. ' % ( self . chain , self . chain ) )
2021-10-17 04:03:18 +02:00
2021-01-21 16:48:24 +01:00
main_conf_file_path = os . path . join ( self . options . tmpdir , ' node0 ' , ' dash_main.conf ' )
util . write_config ( main_conf_file_path , n = 0 , chain = ' ' , extra_config = ' includeconf= {} \n ' . format ( inc_conf_file_path ) )
2019-07-16 22:07:14 +02:00
with open ( inc_conf_file_path , ' w ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' acceptnonstdtxn=1 \n ' )
2021-01-21 16:48:24 +01:00
self . nodes [ 0 ] . assert_start_raises_init_error ( extra_args = [ " -conf= {} " . format ( main_conf_file_path ) ] , expected_msg = ' Error: acceptnonstdtxn is not currently supported for main chain ' )
2019-07-16 22:07:14 +02:00
2018-09-06 12:52:06 +02:00
with open ( inc_conf_file_path , ' w ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' nono \n ' )
2019-07-10 14:06:57 +02:00
self . nodes [ 0 ] . assert_start_raises_init_error ( expected_msg = ' Error: Error reading configuration file: parse error on line 1: nono, if you intended to specify a negated option, use nono=1 instead ' )
2018-09-06 12:52:06 +02:00
2018-11-12 15:20:30 +01:00
with open ( inc_conf_file_path , ' w ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' server=1 \n rpcuser=someuser \n rpcpassword=some#pass ' )
2019-07-10 14:06:57 +02:00
self . nodes [ 0 ] . assert_start_raises_init_error ( expected_msg = ' Error: Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided ' )
2018-11-12 15:20:30 +01:00
2019-01-09 15:07:32 +01:00
with open ( inc_conf_file_path , ' w ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' server=1 \n rpcuser=someuser \n main.rpcpassword=some#pass ' )
2019-07-10 14:06:57 +02:00
self . nodes [ 0 ] . assert_start_raises_init_error ( expected_msg = ' Error: Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided ' )
2019-01-09 15:07:32 +01:00
with open ( inc_conf_file_path , ' w ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' server=1 \n rpcuser=someuser \n [main] \n rpcpassword=some#pass ' )
2019-07-10 14:06:57 +02:00
self . nodes [ 0 ] . assert_start_raises_init_error ( expected_msg = ' Error: Error reading configuration file: parse error on line 4, using # in rpcpassword can be ambiguous and should be avoided ' )
2019-01-09 15:07:32 +01:00
2019-03-02 15:59:09 +01:00
inc_conf_file2_path = os . path . join ( self . nodes [ 0 ] . datadir , ' include2.conf ' )
with open ( os . path . join ( self . nodes [ 0 ] . datadir , ' dash.conf ' ) , ' a ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' includeconf= {} \n ' . format ( inc_conf_file2_path ) )
Merge #14708: Warn unrecognised sections in the config file
3fb09b9889665a24b34f25e9d1385a05058a28b7 Warn unrecognized sections in the config file (Akio Nakamura)
Pull request description:
This PR intends to resolve #14702.
In the config file, sections are specified by square bracket pair "[]"$,
or included in the option name itself which separated by a period"(.)".
Typicaly, [testnet] is not a correct section name and specified options
in that section are ignored but user cannot recognize what is happen.
So, add some log-warning messages if unrecognized section names are
present in the config file after checking section only args.
note: Currentry, followings are out of scope of this PR.
1) Empty section name or option name can describe.
e.g. [] , .a=b, =c
2) Multiple period characters can exist in the section name and option name.
e.g. [c.d.e], [..], f.g.h.i=j, ..=k
Tree-SHA512: 2cea02a0525feb40320613989a75cd7b7b1bd12158d5e6f3174ca77e6a25bb84425dd8812f62483df9fc482045c7b5402d69bc714430518b1847d055a2dc304b
2018-11-21 16:43:46 +01:00
with open ( inc_conf_file_path , ' w ' , encoding = ' utf-8 ' ) as conf :
2019-03-02 15:59:09 +01:00
conf . write ( ' testnot.datadir=1 \n ' )
with open ( inc_conf_file2_path , ' w ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' [testnet] \n ' )
Merge #14708: Warn unrecognised sections in the config file
3fb09b9889665a24b34f25e9d1385a05058a28b7 Warn unrecognized sections in the config file (Akio Nakamura)
Pull request description:
This PR intends to resolve #14702.
In the config file, sections are specified by square bracket pair "[]"$,
or included in the option name itself which separated by a period"(.)".
Typicaly, [testnet] is not a correct section name and specified options
in that section are ignored but user cannot recognize what is happen.
So, add some log-warning messages if unrecognized section names are
present in the config file after checking section only args.
note: Currentry, followings are out of scope of this PR.
1) Empty section name or option name can describe.
e.g. [] , .a=b, =c
2) Multiple period characters can exist in the section name and option name.
e.g. [c.d.e], [..], f.g.h.i=j, ..=k
Tree-SHA512: 2cea02a0525feb40320613989a75cd7b7b1bd12158d5e6f3174ca77e6a25bb84425dd8812f62483df9fc482045c7b5402d69bc714430518b1847d055a2dc304b
2018-11-21 16:43:46 +01:00
self . restart_node ( 0 )
2020-06-01 10:05:15 +02:00
self . nodes [ 0 ] . stop_node ( expected_stderr = ' Warning: ' + inc_conf_file_path + ' :1 Section [testnot] is not recognized. ' + os . linesep + inc_conf_file2_path + ' :1 Section [testnet] is not recognized. ' )
Merge #14708: Warn unrecognised sections in the config file
3fb09b9889665a24b34f25e9d1385a05058a28b7 Warn unrecognized sections in the config file (Akio Nakamura)
Pull request description:
This PR intends to resolve #14702.
In the config file, sections are specified by square bracket pair "[]"$,
or included in the option name itself which separated by a period"(.)".
Typicaly, [testnet] is not a correct section name and specified options
in that section are ignored but user cannot recognize what is happen.
So, add some log-warning messages if unrecognized section names are
present in the config file after checking section only args.
note: Currentry, followings are out of scope of this PR.
1) Empty section name or option name can describe.
e.g. [] , .a=b, =c
2) Multiple period characters can exist in the section name and option name.
e.g. [c.d.e], [..], f.g.h.i=j, ..=k
Tree-SHA512: 2cea02a0525feb40320613989a75cd7b7b1bd12158d5e6f3174ca77e6a25bb84425dd8812f62483df9fc482045c7b5402d69bc714430518b1847d055a2dc304b
2018-11-21 16:43:46 +01:00
2018-09-06 12:52:06 +02:00
with open ( inc_conf_file_path , ' w ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' ' ) # clear
2019-03-02 15:59:09 +01:00
with open ( inc_conf_file2_path , ' w ' , encoding = ' utf-8 ' ) as conf :
conf . write ( ' ' ) # clear
2018-09-06 12:52:06 +02:00
2020-09-29 15:16:44 +02:00
def test_invalid_command_line_options ( self ) :
self . nodes [ 0 ] . assert_start_raises_init_error (
expected_msg = ' Error: No proxy server specified. Use -proxy=<ip> or -proxy=<ip:port>. ' ,
extra_args = [ ' -proxy ' ] ,
)
2021-06-08 04:19:35 +02:00
def test_log_buffer ( self ) :
2021-02-21 11:01:20 +01:00
self . stop_node ( 0 )
2020-01-11 00:37:33 +01:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [ ' Warning: parsed potentially confusing double-negative -connect=0 \n ' ] ) :
2021-06-08 04:19:35 +02:00
self . start_node ( 0 , extra_args = [ ' -noconnect=0 ' ] )
2020-01-30 23:10:50 +01:00
def test_args_log ( self ) :
2021-02-21 11:01:20 +01:00
self . stop_node ( 0 )
2020-01-30 23:10:50 +01:00
self . log . info ( ' Test config args logging ' )
with self . nodes [ 0 ] . assert_debug_log (
expected_msgs = [
' Command-line arg: addnode= " some.node " ' ,
' Command-line arg: rpcauth=**** ' ,
' Command-line arg: rpcbind=**** ' ,
' Command-line arg: rpcpassword=**** ' ,
' Command-line arg: rpcuser=**** ' ,
' Command-line arg: torpassword=**** ' ,
2020-02-05 11:41:36 +01:00
' Config file arg: %s = " 1 " ' % self . chain ,
' Config file arg: [ %s ] server= " 1 " ' % self . chain ,
2020-01-30 23:10:50 +01:00
] ,
unexpected_msgs = [
' alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc0 ' ,
' 127.1.1.1 ' ,
' secret-rpcuser ' ,
' secret-torpassword ' ,
] ) :
self . start_node ( 0 , extra_args = [
' -addnode=some.node ' ,
' -rpcauth=alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc0 ' ,
' -rpcbind=127.1.1.1 ' ,
' -rpcpassword= ' ,
' -rpcuser=secret-rpcuser ' ,
' -torpassword=secret-torpassword ' ,
] )
2020-07-23 18:32:49 +02:00
def test_networkactive ( self ) :
self . log . info ( ' Test -networkactive option ' )
2021-02-21 11:01:20 +01:00
self . stop_node ( 0 )
2020-07-23 18:32:49 +02:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [ ' SetNetworkActive: true \n ' ] ) :
self . start_node ( 0 )
2021-02-21 11:01:20 +01:00
self . stop_node ( 0 )
2020-07-23 18:32:49 +02:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [ ' SetNetworkActive: true \n ' ] ) :
self . start_node ( 0 , extra_args = [ ' -networkactive ' ] )
2021-02-21 11:01:20 +01:00
self . stop_node ( 0 )
2020-07-23 18:32:49 +02:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [ ' SetNetworkActive: true \n ' ] ) :
self . start_node ( 0 , extra_args = [ ' -networkactive=1 ' ] )
2021-02-21 11:01:20 +01:00
self . stop_node ( 0 )
2020-07-23 18:32:49 +02:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [ ' SetNetworkActive: false \n ' ] ) :
self . start_node ( 0 , extra_args = [ ' -networkactive=0 ' ] )
2021-02-21 11:01:20 +01:00
self . stop_node ( 0 )
2020-07-23 18:32:49 +02:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [ ' SetNetworkActive: false \n ' ] ) :
self . start_node ( 0 , extra_args = [ ' -nonetworkactive ' ] )
2021-02-21 11:01:20 +01:00
self . stop_node ( 0 )
2020-07-23 18:32:49 +02:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [ ' SetNetworkActive: false \n ' ] ) :
self . start_node ( 0 , extra_args = [ ' -nonetworkactive=1 ' ] )
2020-09-05 18:51:33 +02:00
def test_seed_peers ( self ) :
2021-02-12 18:23:03 +01:00
self . log . info ( ' Test seed peers ' )
2020-09-05 18:51:33 +02:00
default_data_dir = self . nodes [ 0 ] . datadir
2021-02-21 11:01:20 +01:00
# Only regtest has no fixed seeds. To avoid connections to random
# nodes, regtest is the only network where it is safe to enable
# -fixedseeds in tests
util . assert_equal ( self . nodes [ 0 ] . getblockchaininfo ( ) [ ' chain ' ] , ' regtest ' )
self . stop_node ( 0 )
2020-09-05 18:51:33 +02:00
# No peers.dat exists and -dnsseed=1
# We expect the node will use DNS Seeds, but Regtest mode has 0 DNS seeds
# So after 60 seconds, the node should fallback to fixed seeds (this is a slow test)
assert not os . path . exists ( os . path . join ( default_data_dir , " peers.dat " ) )
2021-02-12 18:23:03 +01:00
start = int ( time . time ( ) )
2020-09-05 18:51:33 +02:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [
" Loaded 0 addresses from peers.dat " ,
2021-02-21 11:01:20 +01:00
" 0 addresses found from DNS seeds " ,
2021-05-05 16:46:19 +02:00
" opencon thread start " , # Ensure ThreadOpenConnections::start time is properly set
2021-02-21 11:01:20 +01:00
] ) :
self . start_node ( 0 , extra_args = [ ' -dnsseed=1 ' , ' -fixedseeds=1 ' , f ' -mocktime= { start } ' ] )
2021-02-12 18:23:03 +01:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [
2021-02-21 11:01:20 +01:00
" Adding fixed seeds as 60 seconds have passed and addrman is empty " ,
] ) :
2021-02-12 18:23:03 +01:00
self . nodes [ 0 ] . setmocktime ( start + 65 )
2020-09-05 18:51:33 +02:00
self . stop_node ( 0 )
# No peers.dat exists and -dnsseed=0
# We expect the node will fallback immediately to fixed seeds
assert not os . path . exists ( os . path . join ( default_data_dir , " peers.dat " ) )
start = time . time ( )
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [
" Loaded 0 addresses from peers.dat " ,
" DNS seeding disabled " ,
2023-05-04 20:59:29 +02:00
" Adding fixed seeds as -dnsseed=0 (or IPv4/IPv6 connections are disabled via -onlynet) and neither -addnode nor -seednode are provided \n " ,
2021-02-21 11:01:20 +01:00
] ) :
self . start_node ( 0 , extra_args = [ ' -dnsseed=0 ' , ' -fixedseeds=1 ' ] )
2020-09-05 18:51:33 +02:00
assert time . time ( ) - start < 60
self . stop_node ( 0 )
2022-07-22 19:54:35 +02:00
self . nodes [ 0 ] . assert_start_raises_init_error ( [ ' -dnsseed=1 ' , ' -onlynet=i2p ' , ' -i2psam=127.0.0.1:7656 ' ] , " Error: Incompatible options: -dnsseed=1 was explicitly specified, but -onlynet forbids connections to IPv4/IPv6 " )
2020-09-05 18:51:33 +02:00
# No peers.dat exists and dns seeds are disabled.
# We expect the node will not add fixed seeds when explicitly disabled.
assert not os . path . exists ( os . path . join ( default_data_dir , " peers.dat " ) )
start = time . time ( )
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [
" Loaded 0 addresses from peers.dat " ,
" DNS seeding disabled " ,
2021-02-21 11:01:20 +01:00
" Fixed seeds are disabled " ,
] ) :
2020-09-05 18:51:33 +02:00
self . start_node ( 0 , extra_args = [ ' -dnsseed=0 ' , ' -fixedseeds=0 ' ] )
assert time . time ( ) - start < 60
self . stop_node ( 0 )
# No peers.dat exists and -dnsseed=0, but a -addnode is provided
# We expect the node will allow 60 seconds prior to using fixed seeds
assert not os . path . exists ( os . path . join ( default_data_dir , " peers.dat " ) )
2021-02-12 18:23:03 +01:00
start = int ( time . time ( ) )
2020-09-05 18:51:33 +02:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [
" Loaded 0 addresses from peers.dat " ,
2021-02-21 11:01:20 +01:00
" DNS seeding disabled " ,
2021-05-05 16:46:19 +02:00
" opencon thread start " , # Ensure ThreadOpenConnections::start time is properly set
2021-02-21 11:01:20 +01:00
] ) :
self . start_node ( 0 , extra_args = [ ' -dnsseed=0 ' , ' -fixedseeds=1 ' , ' -addnode=fakenodeaddr ' , f ' -mocktime= { start } ' ] )
2021-02-12 18:23:03 +01:00
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = [
2021-02-21 11:01:20 +01:00
" Adding fixed seeds as 60 seconds have passed and addrman is empty " ,
] ) :
2021-02-12 18:23:03 +01:00
self . nodes [ 0 ] . setmocktime ( start + 65 )
2020-09-05 18:51:33 +02:00
2020-09-25 21:33:47 +02:00
def test_connect_with_seednode ( self ) :
self . log . info ( ' Test -connect with -seednode ' )
seednode_ignored = [ ' -seednode is ignored when -connect is used \n ' ]
dnsseed_ignored = [ ' -dnsseed is ignored when -connect is used and -proxy is specified \n ' ]
addcon_thread_started = [ ' addcon thread start \n ' ]
self . stop_node ( 0 )
# When -connect is supplied, expanding addrman via getaddr calls to ADDR_FETCH(-seednode)
# nodes is irrelevant and -seednode is ignored.
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = seednode_ignored ) :
self . start_node ( 0 , extra_args = [ ' -connect=fakeaddress1 ' , ' -seednode=fakeaddress2 ' ] )
# With -proxy, an ADDR_FETCH connection is made to a peer that the dns seed resolves to.
# ADDR_FETCH connections are not used when -connect is used.
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = dnsseed_ignored ) :
self . restart_node ( 0 , extra_args = [ ' -connect=fakeaddress1 ' , ' -dnsseed=1 ' , ' -proxy=1.2.3.4 ' ] )
# If the user did not disable -dnsseed, but it was soft-disabled because they provided -connect,
# they shouldn't see a warning about -dnsseed being ignored.
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = addcon_thread_started ,
unexpected_msgs = dnsseed_ignored ) :
self . restart_node ( 0 , extra_args = [ ' -connect=fakeaddress1 ' , ' -proxy=1.2.3.4 ' ] )
# We have to supply expected_msgs as it's a required argument
# The expected_msg must be something we are confident will be logged after the unexpected_msg
# These cases test for -connect being supplied but only to disable it
for connect_arg in [ ' -connect=0 ' , ' -noconnect ' ] :
with self . nodes [ 0 ] . assert_debug_log ( expected_msgs = addcon_thread_started ,
unexpected_msgs = seednode_ignored ) :
self . restart_node ( 0 , extra_args = [ connect_arg , ' -seednode=fakeaddress2 ' ] )
2017-12-20 09:34:08 +01:00
def run_test ( self ) :
2021-06-08 04:19:35 +02:00
self . test_log_buffer ( )
2020-01-30 23:10:50 +01:00
self . test_args_log ( )
2020-09-05 18:51:33 +02:00
self . test_seed_peers ( )
2020-07-23 18:32:49 +02:00
self . test_networkactive ( )
2020-09-25 21:33:47 +02:00
self . test_connect_with_seednode ( )
2021-06-08 04:19:35 +02:00
2018-09-06 12:52:06 +02:00
self . test_config_file_parser ( )
2020-09-29 15:16:44 +02:00
self . test_invalid_command_line_options ( )
2018-09-06 12:52:06 +02:00
2017-12-20 09:34:08 +01:00
# Remove the -datadir argument so it doesn't override the config file
self . nodes [ 0 ] . args = [ arg for arg in self . nodes [ 0 ] . args if not arg . startswith ( " -datadir " ) ]
2018-03-22 11:04:37 +01:00
default_data_dir = self . nodes [ 0 ] . datadir
2017-12-20 09:34:08 +01:00
new_data_dir = os . path . join ( default_data_dir , ' newdatadir ' )
new_data_dir_2 = os . path . join ( default_data_dir , ' newdatadir2 ' )
# Check that using -datadir argument on non-existent directory fails
self . nodes [ 0 ] . datadir = new_data_dir
2021-04-08 22:29:01 +02:00
self . nodes [ 0 ] . assert_start_raises_init_error ( [ ' -datadir= ' + new_data_dir ] , ' Error: Specified data directory " ' + new_data_dir + ' " does not exist. ' )
2017-12-20 09:34:08 +01:00
# Check that using non-existent datadir in conf file fails
2020-02-29 20:45:39 +01:00
conf_file = os . path . join ( default_data_dir , " dash.conf " )
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns)
5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)
005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns)
608415d [tests] Unit tests for network-specific config entries (Anthony Towns)
68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)
d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns)
8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns)
30f9407 [tests] Unit tests for config file sections (Anthony Towns)
95eb66d ArgsManager: support config file sections (Anthony Towns)
4d34fcc ArgsManager: drop m_negated_args (Anthony Towns)
3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns)
Pull request description:
The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file:
<cfields> an alternative to that would be sections in a config file. and on the
cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5.
This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line.
The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys.
I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf:
wallet=/secret/wallet.dat
upnp=1
and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified:
upnp=1
[main]
wallet=/secret/wallet.dat
For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance.
I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have:
maxmempool=200
[regtest]
maxmempool=100
your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect...
The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected.
Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos
Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
2020-04-29 14:50:51 +02:00
2021-01-22 15:58:07 +01:00
# datadir needs to be set before [chain] section
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns)
5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)
005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns)
608415d [tests] Unit tests for network-specific config entries (Anthony Towns)
68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)
d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns)
8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns)
30f9407 [tests] Unit tests for config file sections (Anthony Towns)
95eb66d ArgsManager: support config file sections (Anthony Towns)
4d34fcc ArgsManager: drop m_negated_args (Anthony Towns)
3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns)
Pull request description:
The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file:
<cfields> an alternative to that would be sections in a config file. and on the
cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5.
This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line.
The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys.
I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf:
wallet=/secret/wallet.dat
upnp=1
and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified:
upnp=1
[main]
wallet=/secret/wallet.dat
For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance.
I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have:
maxmempool=200
[regtest]
maxmempool=100
your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect...
The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected.
Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos
Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
2020-04-29 14:50:51 +02:00
conf_file_contents = open ( conf_file , encoding = ' utf8 ' ) . read ( )
with open ( conf_file , ' w ' , encoding = ' utf8 ' ) as f :
2017-12-20 09:34:08 +01:00
f . write ( " datadir= " + new_data_dir + " \n " )
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns)
5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)
005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns)
608415d [tests] Unit tests for network-specific config entries (Anthony Towns)
68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)
d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns)
8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns)
30f9407 [tests] Unit tests for config file sections (Anthony Towns)
95eb66d ArgsManager: support config file sections (Anthony Towns)
4d34fcc ArgsManager: drop m_negated_args (Anthony Towns)
3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns)
Pull request description:
The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file:
<cfields> an alternative to that would be sections in a config file. and on the
cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5.
This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line.
The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys.
I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf:
wallet=/secret/wallet.dat
upnp=1
and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified:
upnp=1
[main]
wallet=/secret/wallet.dat
For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance.
I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have:
maxmempool=200
[regtest]
maxmempool=100
your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect...
The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected.
Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos
Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
2020-04-29 14:50:51 +02:00
f . write ( conf_file_contents )
2018-07-18 15:23:20 +02:00
2019-04-29 21:46:34 +02:00
self . nodes [ 0 ] . assert_start_raises_init_error ( [ ' -conf= ' + conf_file ] , ' Error: Error reading configuration file: specified data directory " ' + new_data_dir + ' " does not exist. ' )
2017-12-20 09:34:08 +01:00
Merge bitcoin/bitcoin#22622: util: Check if specified config file cannot be opened
127b4608e9dbb8217c74c9332e82fcec8c326fa8 test: Check if specified config file cannot be opened (nthumann)
6bb54708e6457f21596793a7149dc6dfea1dc871 util: Check if specified config file cannot be opened (nthumann)
Pull request description:
Fixes https://github.com/bitcoin/bitcoin/issues/22612.
When running e.g. `./src/bitcoind -datadir=/tmp/bitcoin -regtest -conf=/tmp/bitcoin/regtest/bitcoin.conf` and the specified config cannot be opened (doesn't exist, permission denied, ...), the initialization silently uses the default config.
As voidburn already noted:
> I can't think of a situation in which a config file is specified explicitly (in the startup options, as per service unit linked above), but inaccessible, where the fail condition should be to keep booting using defaults instead.
With this patch applied, the initialization will fail immediately, if the specified config file cannot be opened. If no config file is explicitly specified, the behavior is unchanged. This not only affects `bitcoind`, but also `bitcoin-cli` and `bitcoin-qt`.
In the example below the datadir is accessible, but the config file is not due to insufficient permissions:
```
$ ./src/bitcoind -datadir=/tmp/bitcoin -regtest --debug=1 -conf=/tmp/bitcoin/regtest/bitcoin.conf
Error: Error reading configuration file: specified config file "/tmp/bitcoin/regtest/bitcoin.conf" could not be opened.
```
ACKs for top commit:
0xB10C:
ACK 127b4608e9dbb8217c74c9332e82fcec8c326fa8
Zero-1729:
tACK 127b4608e9dbb8217c74c9332e82fcec8c326fa8
theStack:
Tested ACK 127b4608e9dbb8217c74c9332e82fcec8c326fa8
Tree-SHA512: 4fe487921485426f1d1da8d256c388af517b984b639d776aec7b159b3e23b669824093d3bdd31139d9415ed5f5de405b3e6a51b110c8ab471f12b9c99ac67cc1
2021-08-23 12:57:58 +02:00
# Check that an explicitly specified config file that cannot be opened fails
none_existent_conf_file = os . path . join ( default_data_dir , " none_existent_dash.conf " )
self . nodes [ 0 ] . assert_start_raises_init_error ( [ ' -conf= ' + none_existent_conf_file ] , ' Error: Error reading configuration file: specified config file " ' + none_existent_conf_file + ' " could not be opened. ' )
2017-12-20 09:34:08 +01:00
# Create the directory and ensure the config file now works
os . mkdir ( new_data_dir )
2018-07-18 15:23:20 +02:00
# Temporarily disabled, because this test would access the user's home dir (~/.bitcoin)
2022-11-30 20:24:02 +01:00
self . start_node ( 0 , [ ' -conf= ' + conf_file ] )
2019-04-29 21:46:34 +02:00
self . stop_node ( 0 )
assert os . path . exists ( os . path . join ( new_data_dir , self . chain , ' blocks ' ) )
2017-12-20 09:34:08 +01:00
# Ensure command line argument overrides datadir in conf
os . mkdir ( new_data_dir_2 )
self . nodes [ 0 ] . datadir = new_data_dir_2
2022-11-30 20:24:02 +01:00
self . start_node ( 0 , [ ' -datadir= ' + new_data_dir_2 , ' -conf= ' + conf_file ] )
2018-10-08 06:39:53 +02:00
assert os . path . exists ( os . path . join ( new_data_dir_2 , self . chain , ' blocks ' ) )
2017-12-20 09:34:08 +01:00
if __name__ == ' __main__ ' :
ConfArgsTest ( ) . main ( )