Skip to content

Commit

Permalink
election transition active one final vote
Browse files Browse the repository at this point in the history
  • Loading branch information
gr0vity committed Nov 25, 2024
1 parent 6bf83bc commit ccf0724
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion nano/lib/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class network_constants
default_rpc_port (45000),
default_ipc_port (46000),
default_websocket_port (47000),
aec_loop_interval_ms (300), // Update AEC ~3 times per second
aec_loop_interval_ms (100), // Update AEC ~3 times per second
cleanup_period (default_cleanup_period),
merge_period (std::chrono::milliseconds (250)),
keepalive_period (std::chrono::seconds (15)),
Expand Down
23 changes: 22 additions & 1 deletion nano/node/active_elections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,26 @@ void nano::active_elections::request_confirm (nano::unique_lock<nano::mutex> & l
std::size_t const this_loop_target_l (roots.size ());
auto const elections_l{ list_active_impl (this_loop_target_l) };

// Get pending solicitations and clear the queue
auto pending_solicitations_l = std::move (pending_solicitations);
pending_solicitations.clear ();

lock_a.unlock ();

// Process pending solicitations with limited representatives
if (!pending_solicitations_l.empty ())
{
nano::confirmation_solicitor solicitor_new (node.network, node.config);
solicitor_new.prepare (node.rep_crawler.principal_representatives (1)); // Only use 2 reps for new elections

for (auto const & election_l : pending_solicitations_l)
{
solicitor_new.add (*election_l);
}
solicitor_new.flush ();
}

// Process active elections with full representative set
nano::confirmation_solicitor solicitor (node.network, node.config);
solicitor.prepare (node.rep_crawler.principal_representatives (std::numeric_limits<std::size_t>::max ()));

Expand Down Expand Up @@ -398,6 +416,10 @@ nano::election_insertion_result nano::active_elections::insert (std::shared_ptr<
node.online_reps.observe (rep_a);
};
result.election = nano::make_shared<nano::election> (node, block_a, nullptr, observe_rep_cb, election_behavior_a);

// Queue for next solicitation round instead of immediate solicitation
pending_solicitations.push_back (result.election);

roots.get<tag_root> ().emplace (entry{ root, result.election, std::move (erased_callback_a) });
node.vote_router.connect (hash, result.election);

Expand Down Expand Up @@ -431,7 +453,6 @@ nano::election_insertion_result nano::active_elections::insert (std::shared_ptr<
if (result.inserted)
{
debug_assert (result.election);

node.vote_cache_processor.trigger (hash);
node.observers.active_started.notify (hash);
vacancy_updated.notify ();
Expand Down
1 change: 1 addition & 0 deletions nano/node/active_elections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class active_elections final
private:
/** Keeps track of number of elections by election behavior (normal, hinted, optimistic) */
nano::enum_array<nano::election_behavior, int64_t> count_by_behavior{};
std::vector<std::shared_ptr<nano::election>> pending_solicitations;

nano::condition_variable condition;
bool stopped{ false };
Expand Down
6 changes: 6 additions & 0 deletions nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@ nano::vote_code nano::election::vote (nano::account const & rep, uint64_t timest

nano::unique_lock<nano::mutex> lock{ mutex };

// If we receive a final vote and election is passive, transition to active
if (state_m == nano::election_state::passive && nano::vote::is_final_timestamp (timestamp_a))
{
state_change (nano::election_state::passive, nano::election_state::active);
}

auto last_vote_it (last_votes.find (rep));
if (last_vote_it != last_votes.end ())
{
Expand Down
2 changes: 1 addition & 1 deletion nano/node/transport/tcp_channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class tcp_channel_queue final
bool full (traffic_type) const;

constexpr static size_t max_size = 8;
constexpr static size_t full_size = 4 * max_size;
constexpr static size_t full_size = 4 * max_size;

private:
void seek_next ();
Expand Down
2 changes: 1 addition & 1 deletion submodules/boost
Submodule boost updated 147 files
2 changes: 1 addition & 1 deletion submodules/miniupnp
Submodule miniupnp updated 112 files
2 changes: 1 addition & 1 deletion submodules/rocksdb
Submodule rocksdb updated 358 files

0 comments on commit ccf0724

Please sign in to comment.