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)
This commit is contained in:
Wesley Shillingford 2020-07-28 15:06:05 +01:00 committed by GitHub
commit a8567994fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -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> ());

View file

@ -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";