Reinstate election request limit on the confirmation solicitor (#2504)
This commit is contained in:
parent
df2df9bb4f
commit
0ce4b647df
2 changed files with 11 additions and 7 deletions
|
@ -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 ()
|
||||
|
|
|
@ -22,15 +22,17 @@ public:
|
|||
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<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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue