Skip to content

Commit

Permalink
Adjust election block rebroadcasting
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 12, 2023
1 parent 8582a54 commit 8b734d1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
11 changes: 7 additions & 4 deletions nano/lib/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ class network_constants
max_peers_per_subnetwork (default_max_peers_per_ip * 4),
ipv6_subnetwork_prefix_for_limiting (64), // Equivalent to network prefix /64.
peer_dump_interval (std::chrono::seconds (5 * 60)),
vote_broadcast_interval (15 * 1000)
vote_broadcast_interval (15 * 1000),
block_broadcast_interval (150 * 1000)
{
if (is_live_network ())
{
Expand Down Expand Up @@ -239,7 +240,8 @@ class network_constants
max_peers_per_ip = 20;
max_peers_per_subnetwork = max_peers_per_ip * 4;
peer_dump_interval = std::chrono::seconds (1);
vote_broadcast_interval = 500;
vote_broadcast_interval = 500ms;
block_broadcast_interval = 500ms;
telemetry_request_cooldown = 500ms;
telemetry_cache_cutoff = 2000ms;
telemetry_request_interval = 500ms;
Expand Down Expand Up @@ -284,8 +286,9 @@ class network_constants
size_t max_peers_per_subnetwork;
size_t ipv6_subnetwork_prefix_for_limiting;
std::chrono::seconds peer_dump_interval;
/** Time to wait before vote rebroadcasts for active elections (milliseconds) */
uint64_t vote_broadcast_interval;
/** Time to wait before vote rebroadcasts for active elections */
std::chrono::milliseconds vote_broadcast_interval;
std::chrono::milliseconds block_broadcast_interval;

/** We do not reply to telemetry requests made within cooldown period */
std::chrono::milliseconds telemetry_request_cooldown{ 1000 * 15 };
Expand Down
2 changes: 2 additions & 0 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ enum class detail : uint8_t
generate_vote,
generate_vote_normal,
generate_vote_final,
broadcast_block_initial,
broadcast_block_repeat,

// election types
normal,
Expand Down
13 changes: 11 additions & 2 deletions nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,20 @@ bool nano::election::failed () const

void nano::election::broadcast_block (nano::confirmation_solicitor & solicitor_a)
{
if (base_latency () * 15 < std::chrono::steady_clock::now () - last_block)
if (last_block + node.config.network_params.network.block_broadcast_interval < std::chrono::steady_clock::now ())
{
nano::lock_guard<nano::mutex> guard{ mutex };
if (!solicitor_a.broadcast (*this))
{
if (last_block == std::chrono::steady_clock::time_point{})
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::broadcast_block_initial);
}
else
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::broadcast_block_repeat);
}

last_block = std::chrono::steady_clock::now ();
}
}
Expand All @@ -181,7 +190,7 @@ void nano::election::broadcast_block (nano::confirmation_solicitor & solicitor_a
void nano::election::broadcast_vote ()
{
nano::unique_lock<nano::mutex> lock{ mutex };
if (last_vote + std::chrono::milliseconds (node.config.network_params.network.vote_broadcast_interval) < std::chrono::steady_clock::now ())
if (last_vote + node.config.network_params.network.vote_broadcast_interval < std::chrono::steady_clock::now ())
{
broadcast_vote_impl ();
last_vote = std::chrono::steady_clock::now ();
Expand Down
6 changes: 3 additions & 3 deletions nano/node/election.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ class election final : public std::enable_shared_from_this<nano::election>
std::atomic<std::chrono::steady_clock::duration> state_start{ std::chrono::steady_clock::now ().time_since_epoch () };

// These are modified while not holding the mutex from transition_time only
std::chrono::steady_clock::time_point last_block = { std::chrono::steady_clock::now () };
std::chrono::steady_clock::time_point last_req = {};
std::chrono::steady_clock::time_point last_block{};
std::chrono::steady_clock::time_point last_req{};
/** The last time vote for this election was generated */
std::chrono::steady_clock::time_point last_vote = {};
std::chrono::steady_clock::time_point last_vote{};

bool valid_change (nano::election::state_t, nano::election::state_t) const;
bool state_change (nano::election::state_t, nano::election::state_t);
Expand Down

0 comments on commit 8b734d1

Please sign in to comment.