Skip to content

Commit

Permalink
Remove priority::flush function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
clemahieu committed Sep 4, 2023
1 parent d5a0351 commit b426def
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 43 deletions.
6 changes: 2 additions & 4 deletions nano/core_test/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::election> (
node, nano::dev::genesis, [] (auto const &) {}, [] (auto const &) {}, nano::election_behavior::normal);
}

TEST (election, behavior)
Expand Down
28 changes: 0 additions & 28 deletions nano/core_test/election_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ());
}
1 change: 0 additions & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,6 @@ void nano::node::add_initial_peers ()
void nano::node::start_election (std::shared_ptr<nano::block> const & block)
{
scheduler.priority.manual (block);
scheduler.priority.flush ();
}

bool nano::node::block_confirmed (nano::block_hash const & hash_a)
Expand Down
8 changes: 0 additions & 8 deletions nano/node/scheduler/priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::mutex> lock{ mutex };
condition.wait (lock, [this] () {
return stopped || empty_locked () || node.active.vacancy () <= 0;
});
}

void nano::scheduler::priority::notify ()
{
condition.notify_all ();
Expand Down
2 changes: 0 additions & 2 deletions nano/node/scheduler/priority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class priority final
* @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;
Expand Down

0 comments on commit b426def

Please sign in to comment.