Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate election request limit on the confirmation solicitor #2504

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions nano/node/confirmation_solicitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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 ()
Expand Down
8 changes: 5 additions & 3 deletions nano/node/confirmation_solicitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
wezrule marked this conversation as resolved.
Show resolved Hide resolved

private:
nano::network & network;

int rebroadcasted{ 0 };
unsigned rebroadcasted{ 0 };
std::vector<nano::representative> representatives;
using vector_root_hashes = std::vector<std::pair<nano::block_hash, nano::root>>;
std::unordered_map<std::shared_ptr<nano::transport::channel>, vector_root_hashes> requests;
Expand Down