From 2ce2378a50e69d037f32300b73fd30676834cda8 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 4 Sep 2023 15:41:41 +0100 Subject: [PATCH] Remove priority::flush function Fixes election.construction test where election might become active/inactive before it can be polled in the test. Removes election_scheduler.flush_vacancy which only tested the flush function. --- nano/core_test/election.cpp | 6 ++---- nano/core_test/election_scheduler.cpp | 28 --------------------------- nano/node/node.cpp | 1 - nano/node/scheduler/priority.cpp | 8 -------- nano/node/scheduler/priority.hpp | 2 -- 5 files changed, 2 insertions(+), 43 deletions(-) diff --git a/nano/core_test/election.cpp b/nano/core_test/election.cpp index e30a53d4..13fc1f1b 100644 --- a/nano/core_test/election.cpp +++ b/nano/core_test/election.cpp @@ -13,10 +13,8 @@ TEST (election, construction) { nano::test::system system (1); auto & node = *system.nodes[0]; - node.start_election (nano::dev::genesis); - ASSERT_TIMELY (5s, node.active.election (nano::dev::genesis->qualified_root ())); - auto election = node.active.election (nano::dev::genesis->qualified_root ()); - election->transition_active (); + auto election = std::make_shared ( + node, nano::dev::genesis, [] (auto const &) {}, [] (auto const &) {}, nano::election_behavior::normal); } TEST (election, behavior) diff --git a/nano/core_test/election_scheduler.cpp b/nano/core_test/election_scheduler.cpp index 3ed8e93a..7e2f132d 100644 --- a/nano/core_test/election_scheduler.cpp +++ b/nano/core_test/election_scheduler.cpp @@ -140,31 +140,3 @@ TEST (election_scheduler, no_vacancy) ASSERT_TIMELY (5s, node.active.election (block2->qualified_root ()) != nullptr); ASSERT_TRUE (node.scheduler.priority.empty ()); } - -// Ensure that election_scheduler::flush terminates even if no elections can currently be queued e.g. shutdown or no active_transactions vacancy -TEST (election_scheduler, flush_vacancy) -{ - nano::test::system system; - nano::node_config config = system.default_config (); - // No elections can be activated - config.active_elections_size = 0; - auto & node = *system.add_node (config); - nano::state_block_builder builder; - nano::keypair key; - - auto send = builder.make_block () - .account (nano::dev::genesis_key.pub) - .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis_key.pub) - .link (key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*system.work.generate (nano::dev::genesis->hash ())) - .build_shared (); - ASSERT_EQ (nano::process_result::progress, node.process (*send).code); - node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ()); - // Ensure this call does not block, even though no elections can be activated. - node.scheduler.priority.flush (); - ASSERT_EQ (0, node.active.size ()); - ASSERT_EQ (1, node.scheduler.priority.size ()); -} diff --git a/nano/node/node.cpp b/nano/node/node.cpp index e3931b09..35d93034 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1266,7 +1266,6 @@ void nano::node::add_initial_peers () void nano::node::start_election (std::shared_ptr const & block) { scheduler.priority.manual (block); - scheduler.priority.flush (); } bool nano::node::block_confirmed (nano::block_hash const & hash_a) diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index b60bc394..0499fd2a 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -69,14 +69,6 @@ bool nano::scheduler::priority::activate (nano::account const & account_a, nano: return false; // Not activated } -void nano::scheduler::priority::flush () -{ - nano::unique_lock lock{ mutex }; - condition.wait (lock, [this] () { - return stopped || empty_locked () || node.active.vacancy () <= 0; - }); -} - void nano::scheduler::priority::notify () { condition.notify_all (); diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index ad0f86e9..a1d825d3 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -36,8 +36,6 @@ public: * @return true if account was activated */ bool activate (nano::account const &, nano::transaction const &); - // Blocks until no more elections can be activated or there are no more elections to activate - void flush (); void notify (); std::size_t size () const; bool empty () const;