From f063e1bc176cff7db2b5663e49c66054ab87ab68 Mon Sep 17 00:00:00 2001 From: Guilherme Lawless Date: Tue, 21 Jan 2020 17:56:33 +0000 Subject: [PATCH] Reinstate election request limit on the confirmation solicitor --- nano/node/confirmation_solicitor.cpp | 10 ++++++---- nano/node/confirmation_solicitor.hpp | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/nano/node/confirmation_solicitor.cpp b/nano/node/confirmation_solicitor.cpp index ae1baf5b3b..34caaf2c9d 100644 --- a/nano/node/confirmation_solicitor.cpp +++ b/nano/node/confirmation_solicitor.cpp @@ -6,6 +6,7 @@ using namespace std::chrono_literals; nano::confirmation_solicitor::confirmation_solicitor (nano::network & network_a, nano::network_constants const & params_a) : max_confirm_req_batches (params_a.is_test_network () ? 1 : 20), max_block_broadcasts (params_a.is_test_network () ? 4 : 30), +max_election_requests (30), network (network_a) { } @@ -35,20 +36,21 @@ bool nano::confirmation_solicitor::add (nano::election const & election_a) { assert (prepared); auto const max_channel_requests (max_confirm_req_batches * nano::network::confirm_req_hashes_max); - bool result = true; - for (auto const & rep : representatives) + unsigned count = 0; + for (auto i (representatives.begin ()), n (representatives.end ()); i != n && count < max_election_requests; ++i) { + auto rep (*i); if (election_a.last_votes.find (rep.account) == election_a.last_votes.end ()) { auto & request_queue (requests[rep.channel]); if (request_queue.size () < max_channel_requests) { request_queue.emplace_back (election_a.status.winner->hash (), election_a.status.winner->root ()); - result = false; + ++count; } } } - return result; + return count == 0; } void nano::confirmation_solicitor::flush () diff --git a/nano/node/confirmation_solicitor.hpp b/nano/node/confirmation_solicitor.hpp index ae5c9a2797..a9fd21d896 100644 --- a/nano/node/confirmation_solicitor.hpp +++ b/nano/node/confirmation_solicitor.hpp @@ -22,15 +22,17 @@ class confirmation_solicitor final bool add (nano::election const &); /** Dispatch bundled requests to each channel*/ void flush (); - /** The maximum amount of confirmation requests (batches) to be sent to each channel */ + /** Maximum amount of confirmation requests (batches) to be sent to each channel */ size_t const max_confirm_req_batches; - /** The global maximum amount of block broadcasts */ + /** Global maximum amount of block broadcasts */ size_t const max_block_broadcasts; + /** Maximum amount of requests to be sent per election */ + size_t const max_election_requests; private: nano::network & network; - int rebroadcasted{ 0 }; + unsigned rebroadcasted{ 0 }; std::vector representatives; using vector_root_hashes = std::vector>; std::unordered_map, vector_root_hashes> requests;