From a8567994fec9ab006e56a7f754a43c3eb2ef1433 Mon Sep 17 00:00:00 2001 From: Wesley Shillingford Date: Tue, 28 Jul 2020 15:06:05 +0100 Subject: [PATCH] Don't crash using read-only CLI command with no ledger (#2862) * Don't crash using read-only CLI command with no ledger * Update error message (Gui review) --- nano/core_test/node.cpp | 9 +++++++++ nano/node/node.cpp | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index c6581d1ac..709adfd2f 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -66,6 +66,15 @@ TEST (node, block_store_path_failure) node->stop (); } +TEST (node_DeathTest, readonly_block_store_not_exist) +{ + // For ASSERT_DEATH_IF_SUPPORTED + testing::FLAGS_gtest_death_test_style = "threadsafe"; + + // This is a read-only node with no ledger file + ASSERT_EXIT (nano::inactive_node (nano::unique_path (), nano::inactive_node_flag_defaults ()), ::testing::ExitedWithCode (1), ""); +} + TEST (node, password_fanout) { auto service (boost::make_shared ()); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 1c75878d6..3f4770220 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -361,9 +361,8 @@ node_seq (seq) } nano::genesis genesis; - if (!is_initialized) + if (!is_initialized && !flags.read_only) { - release_assert (!flags.read_only); auto transaction (store.tx_begin_write ({ tables::accounts, tables::blocks, tables::cached_counts, tables::confirmation_height, tables::frontiers })); // Store was empty meaning we just created it, add the genesis block store.initialize (transaction, genesis, ledger.cache); @@ -372,7 +371,8 @@ node_seq (seq) if (!ledger.block_exists (genesis.hash ())) { std::stringstream ss; - ss << "Genesis block not found. Make sure the node network ID is correct."; + ss << "Genesis block not found. This commonly indicates a configuration issue, check that the --network or --data_path command line arguments are correct, " + "and also the ledger backend node config option. If using a read-only CLI command a ledger must already exist, start the node with --daemon first."; if (network_params.network.is_beta_network ()) { ss << " Beta network may have reset, try clearing database files";