Adding election::behavior getter method, updating references, and adding direct unit test. (#4124)

This commit is contained in:
clemahieu 2023-02-14 14:15:29 +00:00 committed by GitHub
commit 3e0d54f7f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 7 deletions

View file

@ -16,6 +16,14 @@ TEST (election, construction)
election->transition_active ();
}
TEST (election, behavior)
{
nano::test::system system (1);
auto election = nano::test::start_election (system, *system.nodes[0], nano::dev::genesis->hash ());
ASSERT_NE (nullptr, election);
ASSERT_EQ (nano::election_behavior::normal, election->behavior ());
}
TEST (election, quorum_minimum_flip_success)
{
nano::test::system system{};

View file

@ -260,7 +260,7 @@ void nano::active_transactions::cleanup_election (nano::unique_lock<nano::mutex>
if (!election->confirmed ())
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_drop_all);
if (election->behavior == election_behavior::hinted)
if (election->behavior () == election_behavior::hinted)
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_hinted_drop);
}
@ -268,13 +268,13 @@ void nano::active_transactions::cleanup_election (nano::unique_lock<nano::mutex>
else
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_confirmed_all);
if (election->behavior == election_behavior::hinted)
if (election->behavior () == election_behavior::hinted)
{
node.stats.inc (nano::stat::type::election, nano::stat::detail::election_hinted_confirmed);
}
}
if (election->behavior == election_behavior::hinted)
if (election->behavior () == election_behavior::hinted)
{
--active_hinted_elections_count;
}
@ -799,4 +799,4 @@ std::unique_ptr<nano::container_info_component> nano::recently_cemented_cache::c
auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "cemented", cemented.size (), sizeof (decltype (cemented)::value_type) }));
return composite;
}
}

View file

@ -22,7 +22,7 @@ nano::election::election (nano::node & node_a, std::shared_ptr<nano::block> cons
confirmation_action (confirmation_action_a),
live_vote_action (live_vote_action_a),
node (node_a),
behavior (election_behavior_a),
behavior_m (election_behavior_a),
status ({ block_a, 0, 0, std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::system_clock::now ().time_since_epoch ()), std::chrono::duration_values<std::chrono::milliseconds>::zero (), 0, 1, 0, nano::election_status_type::ongoing }),
height (block_a->sideband ().height),
root (block_a->root ()),
@ -220,7 +220,7 @@ bool nano::election::transition_time (nano::confirmation_solicitor & solicitor_a
std::chrono::milliseconds nano::election::time_to_live () const
{
switch (behavior)
switch (behavior ())
{
case election_behavior::normal:
return std::chrono::milliseconds (5 * 60 * 1000);
@ -636,3 +636,8 @@ std::vector<nano::vote_with_weight_info> nano::election::votes_with_weight () co
std::transform (sorted_votes.begin (), sorted_votes.end (), std::back_inserter (result), [] (auto const & entry) { return entry.second; });
return result;
}
nano::election_behavior nano::election::behavior () const
{
return behavior_m;
}

View file

@ -142,6 +142,7 @@ public: // Information
nano::root const root;
nano::qualified_root const qualified_root;
std::vector<nano::vote_with_weight_info> votes_with_weight () const;
nano::election_behavior behavior () const;
private:
nano::tally_t tally_impl () const;
@ -170,7 +171,7 @@ private:
mutable nano::uint128_t final_weight{ 0 };
mutable std::unordered_map<nano::block_hash, nano::uint128_t> last_tally;
nano::election_behavior const behavior{ nano::election_behavior::normal };
nano::election_behavior const behavior_m{ nano::election_behavior::normal };
std::chrono::steady_clock::time_point const election_start = { std::chrono::steady_clock::now () };
mutable nano::mutex mutex;