diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 43411b19..14366729 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -74,6 +74,7 @@ int main (int argc, char * const * argv) ("config", boost::program_options::value>()->multitoken(), "Pass node configuration values. This takes precedence over any values in the configuration file. This option can be repeated multiple times.") ("daemon", "Start node daemon") ("compare_rep_weights", "Display a summarized comparison between the hardcoded bootstrap weights and representative weights from the ledger. Full comparison is output to logs") + ("debug_block_dump", "Display all the blocks in the ledger in text format") ("debug_block_count", "Display the number of blocks") ("debug_bootstrap_generate", "Generate bootstrap sequence of blocks") ("debug_dump_frontier_unchecked_dependents", "Dump frontiers which have matching unchecked keys") @@ -307,6 +308,21 @@ int main (int argc, char * const * argv) result = -1; } } + else if (vm.count ("debug_block_dump")) + { + auto inactive_node = nano::default_inactive_node (data_path, vm); + auto transaction = inactive_node->node->store.tx_begin_read (); + auto i = inactive_node->node->store.block.begin (transaction); + auto end = inactive_node->node->store.block.end (); + for (; i != end; ++i) + { + nano::block_hash hash = i->first; + nano::block_w_sideband sideband = i->second; + std::shared_ptr b = sideband.block; + std::cout << hash.to_string () << std::endl + << b->to_json (); + } + } else if (vm.count ("debug_block_count")) { auto node_flags = nano::inactive_node_flag_defaults (); diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 7034014b..c8ea3456 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -44,6 +44,7 @@ void nano::add_node_options (boost::program_options::options_description & descr { // clang-format off description_a.add_options () + ("initialize", "Initialize the data folder, if it is not already initialised. This command is meant to be run when the data folder is empty, to populate it with the genesis block.") ("account_create", "Insert next deterministic key in to ") ("account_get", "Get account number for the ") ("account_key", "Get the public key for ") @@ -262,7 +263,14 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map std::error_code ec; boost::filesystem::path data_path = vm.count ("data_path") ? boost::filesystem::path (vm["data_path"].as ()) : nano::working_path (); - if (vm.count ("account_create")) + if (vm.count ("initialize")) + { + auto node_flags = nano::inactive_node_flag_defaults (); + node_flags.read_only = false; + nano::update_flags (node_flags, vm); + nano::inactive_node node (data_path, node_flags); + } + else if (vm.count ("account_create")) { if (vm.count ("wallet") == 1) { diff --git a/nano/node/node.cpp b/nano/node/node.cpp index a32bdced..4e66574c 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1762,8 +1762,9 @@ void nano::node::populate_backlog () } nano::node_wrapper::node_wrapper (boost::filesystem::path const & path_a, boost::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a) : + network_params{ nano::network_constants::active_network }, io_context (std::make_shared ()), - work{ nano::dev::network_params.network, 1 } + work{ network_params.network, 1 } { boost::system::error_code error_chmod; @@ -1772,7 +1773,7 @@ nano::node_wrapper::node_wrapper (boost::filesystem::path const & path_a, boost: */ boost::filesystem::create_directories (path_a); nano::set_secure_perm_directory (path_a, error_chmod); - nano::daemon_config daemon_config{ path_a, nano::dev::network_params }; + nano::daemon_config daemon_config{ path_a, network_params }; auto error = nano::read_node_config_toml (config_path_a, daemon_config, node_flags_a.config_overrides); if (error) { diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 3bd4edf8..a6e4c508 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -223,6 +223,7 @@ public: node_wrapper (boost::filesystem::path const & path_a, boost::filesystem::path const & config_path_a, nano::node_flags const & node_flags_a); ~node_wrapper (); + nano::network_params network_params; std::shared_ptr io_context; nano::work_pool work; std::shared_ptr node; diff --git a/systest/.gitignore b/systest/.gitignore new file mode 100644 index 00000000..72d072be --- /dev/null +++ b/systest/.gitignore @@ -0,0 +1 @@ +/data.systest diff --git a/systest/RUNALL b/systest/RUNALL new file mode 100755 index 00000000..b53cb0a6 --- /dev/null +++ b/systest/RUNALL @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +for script in *.sh; do + ./$script; +done + +echo All systest passed. diff --git a/systest/cli_wallet_create.sh b/systest/cli_wallet_create.sh new file mode 100755 index 00000000..00a79461 --- /dev/null +++ b/systest/cli_wallet_create.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +set -e + +DATADIR=data.systest + +SEED=CEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEEDCEED + +# the caller should set the env var NANO_NODE_EXE to point to the nano_node executable +# if NANO_NODE_EXE is unser ot empty then "../../build/nano_node" is used +NANO_NODE_EXE=${NANO_NODE_EXE:-../../build/nano_node} + +clean_data_dir() { + rm -f $DATADIR/log/log_*.log + rm -f $DATADIR/wallets.ldb* + rm -f $DATADIR/data.ldb* + rm -f $DATADIR/config-*.toml +} + +mkdir -p $DATADIR/log +clean_data_dir + +# initialise data directory +$NANO_NODE_EXE --initialize --data_path $DATADIR + +# create a wallet and store the wallet ID +wallet_id=`$NANO_NODE_EXE --wallet_create --data_path $DATADIR --seed $SEED` + +# decrypt the wallet and check the seed +$NANO_NODE_EXE --wallet_decrypt_unsafe --wallet $wallet_id --data_path $DATADIR | grep -q "Seed: $SEED" + +# list the wallet and check the wallet ID +$NANO_NODE_EXE --wallet_list --data_path $DATADIR | grep -q "Wallet ID: $wallet_id" + +# if it got this far then it is a pass +echo $0: PASSED +exit 0 diff --git a/systest/node_initialize.sh b/systest/node_initialize.sh new file mode 100755 index 00000000..ae80e33d --- /dev/null +++ b/systest/node_initialize.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +set -e + +DATADIR=data.systest + +# the caller should set the env var NANO_NODE_EXE to point to the nano_node executable +# if NANO_NODE_EXE is unser ot empty then "../../build/nano_node" is used +NANO_NODE_EXE=${NANO_NODE_EXE:-../../build/nano_node} + +clean_data_dir() { + rm -f "$DATADIR"/log/log_*.log + rm -f "$DATADIR"/wallets.ldb* + rm -f "$DATADIR"/data.ldb* + rm -f "$DATADIR"/config-*.toml +} + +test_initialize_cmd() { + netmatch="$1" + netcmd="$2" + netarg="$3" + genesishash="$4" + + clean_data_dir + + # initialise data directory + $NANO_NODE_EXE --initialize --data_path "$DATADIR" "$netcmd" "$netarg" + + # check that it is the live network + grep -q "Active network: $netmatch" "$DATADIR"/log/log_*.log + + # check that the ledger file is created + test -e "$DATADIR/data.ldb" + $NANO_NODE_EXE --debug_block_count --data_path "$DATADIR" "$netcmd" "$netarg" | grep -q 'Block count: 1' + + # check the genesis block is correct + $NANO_NODE_EXE --debug_block_dump --data_path "$DATADIR" "$netcmd" "$netarg" | head -n 1 | grep -qi "$genesishash" +} + +mkdir -p "$DATADIR/log" + +test_initialize_cmd "live" "" "" "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948" +test_initialize_cmd "live" "--network" "live" "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948" +test_initialize_cmd "beta" "--network" "beta" "01A92459E69440D5C1088D3B31F4CA678BE944BAB3776C2E6B7665E9BD99BD5A" +test_initialize_cmd "test" "--network" "test" "B1D60C0B886B57401EF5A1DAA04340E53726AA6F4D706C085706F31BBD100CEE" + +# if it got this far then it is a pass +echo $0: PASSED +exit 0 diff --git a/systest/set_bandwidth_params.sh b/systest/set_bandwidth_params.sh index 4c02291a..e6905c34 100755 --- a/systest/set_bandwidth_params.sh +++ b/systest/set_bandwidth_params.sh @@ -1,24 +1,40 @@ #!/bin/sh +set -e + +DATADIR=data.systest + +clean_data_dir() { + rm -f "$DATADIR"/log/log_*.log + rm -f "$DATADIR"/wallets.ldb* + rm -f "$DATADIR"/data.ldb* + rm -f "$DATADIR"/config-*.toml +} + +msg() { + : + #echo "$@" +} + # the caller should set the env var NANO_NODE_EXE to point to the nano_node executable -# if NANO_NODE_EXE is unser ot empty then "../../build/nano_node" is used +# if NANO_NODE_EXE is unset ot empty then "../../build/nano_node" is used NANO_NODE_EXE=${NANO_NODE_EXE:-../../build/nano_node} -mkdir -p data/log -rm data/log/log_*.log +mkdir -p "$DATADIR/log" +clean_data_dir # start nano_node and store its pid so we can later send it # the SIGHUP signal and so we can terminate it -echo start nano_node -$NANO_NODE_EXE --daemon --data_path data & +msg start nano_node +$NANO_NODE_EXE --daemon --data_path "$DATADIR" >/dev/null & pid=$! -echo pid=$pid +msg pid=$pid # wait for the node to start-up sleep 2 # set bandwidth params 42 and 43 in the config file -cat > data/config-node.toml < "$DATADIR/config-node.toml" < data/config-node.toml < "$DATADIR/config-node.toml" <