Only broadcast every 100ms or 255 votes
This commit is contained in:
parent
b7b0395a03
commit
dd08220e2c
2 changed files with 18 additions and 2 deletions
|
@ -289,11 +289,12 @@ void nano::vote_generator::run ()
|
|||
nano::unique_lock<nano::mutex> lock{ mutex };
|
||||
while (!stopped)
|
||||
{
|
||||
condition.wait_for (lock, config.vote_generator_delay, [this] () { return this->candidates.size () >= nano::network::confirm_ack_hashes_max || !requests.empty (); });
|
||||
condition.wait_for (lock, config.vote_generator_delay, [this] () { return broadcast_predicate () || !requests.empty (); });
|
||||
|
||||
if (!candidates.empty ())
|
||||
if (broadcast_predicate ())
|
||||
{
|
||||
broadcast (lock);
|
||||
next_broadcast = std::chrono::steady_clock::now () + std::chrono::milliseconds (config.vote_generator_delay);
|
||||
}
|
||||
|
||||
if (!requests.empty ())
|
||||
|
@ -305,6 +306,19 @@ void nano::vote_generator::run ()
|
|||
}
|
||||
}
|
||||
|
||||
bool nano::vote_generator::broadcast_predicate () const
|
||||
{
|
||||
if (candidates.size () >= nano::network::confirm_ack_hashes_max)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (candidates.size () > 0 && std::chrono::steady_clock::now () > next_broadcast)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
nano::container_info nano::vote_generator::container_info () const
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
|
|
|
@ -30,6 +30,7 @@ private:
|
|||
using candidate_t = std::pair<nano::root, nano::block_hash>;
|
||||
using request_t = std::pair<std::vector<candidate_t>, std::shared_ptr<nano::transport::channel>>;
|
||||
using queue_entry_t = std::pair<nano::root, nano::block_hash>;
|
||||
std::chrono::steady_clock::time_point next_broadcast = { std::chrono::steady_clock::now () };
|
||||
|
||||
public:
|
||||
vote_generator (nano::node_config const &, nano::node &, nano::ledger &, nano::wallets &, nano::vote_processor &, nano::local_vote_history &, nano::network &, nano::stats &, nano::logger &, bool is_final);
|
||||
|
@ -56,6 +57,7 @@ private:
|
|||
void broadcast_action (std::shared_ptr<nano::vote> const &) const;
|
||||
void process_batch (std::deque<queue_entry_t> & batch);
|
||||
bool should_vote (transaction_variant_t const &, nano::root const &, nano::block_hash const &) const;
|
||||
bool broadcast_predicate () const;
|
||||
|
||||
private:
|
||||
std::function<void (std::shared_ptr<nano::vote> const &, std::shared_ptr<nano::transport::channel> &)> reply_action; // must be set only during initialization by using set_reply_action
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue