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

Separate election state for the broadcasting block fallback #2720

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
28 changes: 24 additions & 4 deletions nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
using namespace std::chrono;

int constexpr nano::election::passive_duration_factor;
int constexpr nano::election::active_duration_factor;
int constexpr nano::election::active_request_count_min;
int constexpr nano::election::active_broadcasting_duration_factor;
int constexpr nano::election::confirmed_duration_factor;

std::chrono::milliseconds nano::election::base_latency () const
Expand Down Expand Up @@ -98,6 +99,18 @@ bool nano::election::valid_change (nano::election::state_t expected_a, nano::ele
}
break;
case nano::election::state_t::active:
switch (desired_a)
{
case nano::election::state_t::idle:
case nano::election::state_t::broadcasting:
case nano::election::state_t::confirmed:
case nano::election::state_t::expired_unconfirmed:
result = true;
break;
default:
break;
}
case nano::election::state_t::broadcasting:
switch (desired_a)
{
case nano::election::state_t::idle:
Expand Down Expand Up @@ -246,7 +259,7 @@ void nano::election::activate_dependencies ()

void nano::election::broadcast_block (nano::confirmation_solicitor & solicitor_a)
{
if (base_latency () * 20 < std::chrono::steady_clock::now () - last_block)
if (base_latency () * 15 < std::chrono::steady_clock::now () - last_block)
{
if (!solicitor_a.broadcast (*this))
{
Expand All @@ -273,11 +286,18 @@ bool nano::election::transition_time (nano::confirmation_solicitor & solicitor_a
break;
}
case nano::election::state_t::active:
send_confirm_req (solicitor_a);
if (confirmation_request_count > active_request_count_min)
{
state_change (nano::election::state_t::active, nano::election::state_t::broadcasting);
}
break;
case nano::election::state_t::broadcasting:
broadcast_block (solicitor_a);
send_confirm_req (solicitor_a);
if (base_latency () * active_duration_factor < std::chrono::steady_clock::now () - state_start)
if (base_latency () * active_broadcasting_duration_factor < std::chrono::steady_clock::now () - state_start)
{
state_change (nano::election::state_t::active, nano::election::state_t::backtracking);
state_change (nano::election::state_t::broadcasting, nano::election::state_t::backtracking);
lock.unlock ();
activate_dependencies ();
lock.lock ();
Expand Down
12 changes: 7 additions & 5 deletions nano/node/election.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ class election final : public std::enable_shared_from_this<nano::election>
enum class state_t
{
idle,
passive,
active,
backtracking,
confirmed,
passive, // only listening for incoming votes
active, // actively request confirmations
broadcasting, // request confirmations and broadcast the winner
backtracking, // start an election for unconfirmed dependent blocks
confirmed, // confirmed but still listening for votes
expired_confirmed,
expired_unconfirmed
};
static int constexpr passive_duration_factor = 5;
static int constexpr active_duration_factor = 30;
static int constexpr active_request_count_min = 2;
static int constexpr active_broadcasting_duration_factor = 30;
static int constexpr confirmed_duration_factor = 5;
std::atomic<nano::election::state_t> state_m = { state_t::idle };

Expand Down