From a09b82261af6ad21d48444d07e70c44785265cf2 Mon Sep 17 00:00:00 2001 From: Guilherme Lawless Date: Mon, 22 Jun 2020 09:05:29 +0100 Subject: [PATCH] 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` --- nano/node/bootstrap/bootstrap_connections.cpp | 11 ++++++----- nano/node/bootstrap/bootstrap_connections.hpp | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/nano/node/bootstrap/bootstrap_connections.cpp b/nano/node/bootstrap/bootstrap_connections.cpp index 53724f02..c8448131 100644 --- a/nano/node/bootstrap/bootstrap_connections.cpp +++ b/nano/node/bootstrap/bootstrap_connections.cpp @@ -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 (block_count.load () / elapsed); + block_rate = static_cast (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 & lhs, const std::shared_ptr & 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); diff --git a/nano/node/bootstrap/bootstrap_connections.hpp b/nano/node/bootstrap/bootstrap_connections.hpp index 85ef479a..d83f4f0f 100644 --- a/nano/node/bootstrap/bootstrap_connections.hpp +++ b/nano/node/bootstrap/bootstrap_connections.hpp @@ -24,7 +24,7 @@ public: ~bootstrap_client (); std::shared_ptr 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 node; @@ -33,6 +33,7 @@ public: std::shared_ptr socket; std::shared_ptr> receive_buffer; std::atomic block_count{ 0 }; + std::atomic block_rate{ 0 }; std::atomic pending_stop{ false }; std::atomic hard_stop{ false };