diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index b54eae4a50..e8caeb2918 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -269,13 +269,13 @@ std::vector> nano::rep_crawler::prepar return { random_peers.begin (), random_peers.end () }; } -auto nano::rep_crawler::prepare_query_target () -> std::optional +auto nano::rep_crawler::prepare_query_target () const -> std::optional { constexpr int max_attempts = 4; auto transaction = node.ledger.tx_begin_read (); - std::optional> hash_root; + std::optional> hash_root; // Randomly select a block from ledger to request votes for for (auto i = 0; i < max_attempts && !hash_root; ++i) @@ -289,20 +289,10 @@ auto nano::rep_crawler::prepare_query_target () -> std::optional } } - if (!hash_root) + // Special case for dev network where number of blocks might be very low: if we can't find a block to query, just pick genesis + if (node.network_params.network.is_dev_network () && !hash_root) { - return std::nullopt; - } - - // Don't send same block multiple times in tests - if (node.network_params.network.is_dev_network ()) - { - nano::lock_guard lock{ mutex }; - - for (auto i = 0; queries.get ().count (hash_root->first) != 0 && i < max_attempts; ++i) - { - hash_root = node.ledger.hash_root_random (transaction); - } + hash_root = std::make_pair (node.network_params.ledger.genesis->hash (), node.network_params.ledger.genesis->root ()); } return hash_root; diff --git a/nano/node/repcrawler.hpp b/nano/node/repcrawler.hpp index cd9d680096..d99bae5593 100644 --- a/nano/node/repcrawler.hpp +++ b/nano/node/repcrawler.hpp @@ -107,7 +107,7 @@ class rep_crawler final /** Returns a list of endpoints to crawl. The total weight is passed in to avoid computing it twice. */ std::vector> prepare_crawl_targets (bool sufficient_weight) const; - std::optional prepare_query_target (); + std::optional prepare_query_target () const; bool track_rep_request (hash_root_t hash_root, std::shared_ptr const & channel); private: diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index d644741863..ca6fb91a62 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -936,7 +936,7 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a) return result; } -std::pair nano::ledger::hash_root_random (secure::transaction const & transaction_a) const +std::pair nano::ledger::hash_root_random (secure::transaction const & transaction_a) const { nano::block_hash hash (0); nano::root root (0); @@ -962,7 +962,7 @@ std::pair nano::ledger::hash_root_random (se root = block->root (); } } - return std::make_pair (hash, root.as_block_hash ()); + return std::make_pair (hash, root); } // Vote weight of an account diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 3171e4593c..9bb6787803 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -58,7 +58,7 @@ class ledger final nano::block_hash representative_calculated (secure::transaction const &, nano::block_hash const &); std::string block_text (char const *); std::string block_text (nano::block_hash const &); - std::pair hash_root_random (secure::transaction const &) const; + std::pair hash_root_random (secure::transaction const &) const; std::optional pending_info (secure::transaction const &, nano::pending_key const & key) const; std::deque> confirm (secure::write_transaction &, nano::block_hash const & hash, size_t max_blocks = 1024 * 128); nano::block_status process (secure::write_transaction const &, std::shared_ptr block);