Pre-sample block rate for bootstrap connections (#2823)

This solves a Debug assert on msvc: strict weak ordering not being satisfied in `bootstrap_connections::populate_connections` due to `block_rate_cmp`
This commit is contained in:
Guilherme Lawless 2020-06-22 09:05:29 +01:00 committed by GitHub
commit a09b82261a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View file

@ -30,10 +30,11 @@ nano::bootstrap_client::~bootstrap_client ()
--connections->connections_count;
}
double nano::bootstrap_client::block_rate () const
double nano::bootstrap_client::sample_block_rate ()
{
auto elapsed = std::max (elapsed_seconds (), nano::bootstrap_limits::bootstrap_minimum_elapsed_seconds_blockrate);
return static_cast<double> (block_count.load () / elapsed);
block_rate = static_cast<double> (block_count.load ()) / elapsed;
return block_rate;
}
void nano::bootstrap_client::set_start_time (std::chrono::steady_clock::time_point start_time_a)
@ -201,7 +202,7 @@ struct block_rate_cmp
{
bool operator() (const std::shared_ptr<nano::bootstrap_client> & lhs, const std::shared_ptr<nano::bootstrap_client> & rhs) const
{
return lhs->block_rate () > rhs->block_rate ();
return lhs->block_rate > rhs->block_rate;
}
};
@ -225,7 +226,7 @@ void nano::bootstrap_connections::populate_connections (bool repeat)
new_clients.push_back (client);
endpoints.insert (socket_l->remote_endpoint ());
double elapsed_sec = client->elapsed_seconds ();
auto blocks_per_sec = client->block_rate ();
auto blocks_per_sec = client->sample_block_rate ();
rate_sum += blocks_per_sec;
if (client->elapsed_seconds () > nano::bootstrap_limits::bootstrap_connection_warmup_time_sec && client->block_count > 0)
{
@ -270,7 +271,7 @@ void nano::bootstrap_connections::populate_connections (bool repeat)
if (node.config.logging.bulk_pull_logging ())
{
node.logger.try_log (boost::str (boost::format ("Dropping peer with block rate %1%, block count %2% (%3%) ") % client->block_rate () % client->block_count % client->channel->to_string ()));
node.logger.try_log (boost::str (boost::format ("Dropping peer with block rate %1%, block count %2% (%3%) ") % client->block_rate % client->block_count % client->channel->to_string ()));
}
client->stop (false);

View file

@ -24,7 +24,7 @@ public:
~bootstrap_client ();
std::shared_ptr<nano::bootstrap_client> shared ();
void stop (bool force);
double block_rate () const;
double sample_block_rate ();
double elapsed_seconds () const;
void set_start_time (std::chrono::steady_clock::time_point start_time_a);
std::shared_ptr<nano::node> node;
@ -33,6 +33,7 @@ public:
std::shared_ptr<nano::socket> socket;
std::shared_ptr<std::vector<uint8_t>> receive_buffer;
std::atomic<uint64_t> block_count{ 0 };
std::atomic<double> block_rate{ 0 };
std::atomic<bool> pending_stop{ false };
std::atomic<bool> hard_stop{ false };