diff --git a/nano/node/lmdb.cpp b/nano/node/lmdb.cpp index 6ade105a..cd7b749e 100644 --- a/nano/node/lmdb.cpp +++ b/nano/node/lmdb.cpp @@ -1212,7 +1212,8 @@ void nano::mdb_store::upgrade_v12_to_v13 (size_t const batch_size) size_t cost (0); nano::account account (0); auto transaction (tx_begin_write ()); - while (!stopped && account != nano::not_an_account) + auto const & not_an_account (nano::not_an_account ()); + while (!stopped && account != not_an_account) { nano::account first (0); nano::account_info second; @@ -1261,10 +1262,10 @@ void nano::mdb_store::upgrade_v12_to_v13 (size_t const batch_size) } else { - account = nano::not_an_account; + account = not_an_account; } } - if (account == nano::not_an_account) + if (account == not_an_account) { BOOST_LOG (logging.log) << boost::str (boost::format ("Completed sideband upgrade")); version_put (transaction, 13); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index b7547052..8952904e 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -3021,7 +3021,7 @@ confirmed (false), stopped (false), announcements (0) { - last_votes.insert (std::make_pair (nano::not_an_account, nano::vote_info{ std::chrono::steady_clock::now (), 0, block_a->hash () })); + last_votes.insert (std::make_pair (nano::not_an_account (), nano::vote_info{ std::chrono::steady_clock::now (), 0, block_a->hash () })); blocks.insert (std::make_pair (block_a->hash (), block_a)); } diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index 5e894b67..f8d98ad4 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -64,10 +64,6 @@ public: genesis_amount (std::numeric_limits::max ()), burn_account (0) { - CryptoPP::AutoSeededRandomPool random_pool; - // Randomly generating these mean no two nodes will ever have the same sentinel values which protects against some insecure algorithms - random_pool.GenerateBlock (not_a_block.bytes.data (), not_a_block.bytes.size ()); - random_pool.GenerateBlock (not_an_account.bytes.data (), not_an_account.bytes.size ()); } nano::keypair zero_key; nano::keypair test_genesis_key; @@ -80,9 +76,24 @@ public: nano::account genesis_account; std::string genesis_block; nano::uint128_t genesis_amount; - nano::block_hash not_a_block; - nano::account not_an_account; nano::account burn_account; + + nano::account const & not_an_account () + { + static bool is_initialized = false; + static std::mutex mutex; + std::lock_guard lk (mutex); + if (!is_initialized) + { + // Randomly generating these mean no two nodes will ever have the same sentinel values which protects against some insecure algorithms + nano::random_pool.GenerateBlock (not_an_account_m.bytes.data (), not_an_account_m.bytes.size ()); + is_initialized = true; + } + return not_an_account_m; + } + +private: + nano::account not_an_account_m; }; ledger_constants globals; } @@ -105,10 +116,11 @@ std::string const & nano::nano_live_genesis (globals.nano_live_genesis); nano::account const & nano::genesis_account (globals.genesis_account); std::string const & nano::genesis_block (globals.genesis_block); nano::uint128_t const & nano::genesis_amount (globals.genesis_amount); -nano::block_hash const & nano::not_a_block (globals.not_a_block); -nano::block_hash const & nano::not_an_account (globals.not_an_account); nano::account const & nano::burn_account (globals.burn_account); - +nano::account const & nano::not_an_account () +{ + return globals.not_an_account (); +} // Create a new random keypair nano::keypair::keypair () { diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 7b2d07fe..4af0c0d3 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -320,10 +320,8 @@ extern std::string const & genesis_block; extern nano::account const & genesis_account; extern nano::account const & burn_account; extern nano::uint128_t const & genesis_amount; -// A block hash that compares inequal to any real block hash -extern nano::block_hash const & not_a_block; // An account number that compares inequal to any real account number -extern nano::block_hash const & not_an_account; +extern nano::account const & not_an_account (); class genesis { public: