Rep crawler special handling of unit tests
This commit is contained in:
parent
b00064b5a7
commit
97868ed2ae
4 changed files with 9 additions and 19 deletions
|
@ -269,13 +269,13 @@ std::vector<std::shared_ptr<nano::transport::channel>> nano::rep_crawler::prepar
|
|||
return { random_peers.begin (), random_peers.end () };
|
||||
}
|
||||
|
||||
auto nano::rep_crawler::prepare_query_target () -> std::optional<hash_root_t>
|
||||
auto nano::rep_crawler::prepare_query_target () const -> std::optional<hash_root_t>
|
||||
{
|
||||
constexpr int max_attempts = 4;
|
||||
|
||||
auto transaction = node.ledger.tx_begin_read ();
|
||||
|
||||
std::optional<std::pair<nano::block_hash, nano::block_hash>> hash_root;
|
||||
std::optional<std::pair<nano::block_hash, nano::root>> 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<hash_root_t>
|
|||
}
|
||||
}
|
||||
|
||||
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<nano::mutex> lock{ mutex };
|
||||
|
||||
for (auto i = 0; queries.get<tag_hash> ().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;
|
||||
|
|
|
@ -107,7 +107,7 @@ private:
|
|||
|
||||
/** Returns a list of endpoints to crawl. The total weight is passed in to avoid computing it twice. */
|
||||
std::vector<std::shared_ptr<nano::transport::channel>> prepare_crawl_targets (bool sufficient_weight) const;
|
||||
std::optional<hash_root_t> prepare_query_target ();
|
||||
std::optional<hash_root_t> prepare_query_target () const;
|
||||
bool track_rep_request (hash_root_t hash_root, std::shared_ptr<nano::transport::channel> const & channel);
|
||||
|
||||
private:
|
||||
|
|
|
@ -936,7 +936,7 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a)
|
|||
return result;
|
||||
}
|
||||
|
||||
std::pair<nano::block_hash, nano::block_hash> nano::ledger::hash_root_random (secure::transaction const & transaction_a) const
|
||||
std::pair<nano::block_hash, nano::root> 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::block_hash, nano::block_hash> 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
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
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<nano::block_hash, nano::block_hash> hash_root_random (secure::transaction const &) const;
|
||||
std::pair<nano::block_hash, nano::root> hash_root_random (secure::transaction const &) const;
|
||||
std::optional<nano::pending_info> pending_info (secure::transaction const &, nano::pending_key const & key) const;
|
||||
std::deque<std::shared_ptr<nano::block>> 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<nano::block> block);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue