Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash using read-only CLI command with no ledger #2862

Merged
merged 2 commits into from Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions nano/core_test/node.cpp
Expand Up @@ -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<boost::asio::io_context> ());
Expand Down
6 changes: 3 additions & 3 deletions nano/node/node.cpp
Expand Up @@ -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);
Expand All @@ -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";
Expand Down