Skip to content

Commit

Permalink
Rename the class nano::scheduler::buckets to nano::scheduler::priorit…
Browse files Browse the repository at this point in the history
…y. (#4272)

Naming it "priority scheduler" matches the naming of other scheduler strategies like hinted scheduler and optimistic scheduler.
  • Loading branch information
clemahieu authored Sep 1, 2023
1 parent 162643c commit 5389072
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 116 deletions.
28 changes: 14 additions & 14 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <nano/lib/jsonconfig.hpp>
#include <nano/node/election.hpp>
#include <nano/node/scheduler/buckets.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/node/transport/inproc.hpp>
#include <nano/test_common/chains.hpp>
#include <nano/test_common/system.hpp>
Expand Down Expand Up @@ -418,7 +418,7 @@ TEST (active_transactions, inactive_votes_cache_multiple_votes)
ASSERT_TIMELY (5s, node.inactive_vote_cache.find (send1->hash ()));
ASSERT_TIMELY (5s, node.inactive_vote_cache.find (send1->hash ())->voters.size () == 2);
ASSERT_EQ (1, node.inactive_vote_cache.cache_size ());
node.scheduler.buckets.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
std::shared_ptr<nano::election> election;
ASSERT_TIMELY (5s, election = node.active.election (send1->qualified_root ()));
ASSERT_EQ (3, election->votes ().size ()); // 2 votes and 1 default not_an_acount
Expand Down Expand Up @@ -996,7 +996,7 @@ TEST (active_transactions, confirmation_consistency)
system.deadline_set (5s);
while (!node.ledger.block_confirmed (node.store.tx_begin_read (), block->hash ()))
{
node.scheduler.buckets.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
ASSERT_NO_ERROR (system.poll (5ms));
}
ASSERT_NO_ERROR (system.poll_until_true (1s, [&node, &block, i] {
Expand Down Expand Up @@ -1140,19 +1140,19 @@ TEST (active_transactions, activate_account_chain)
ASSERT_EQ (nano::process_result::progress, node.process (*open).code);
ASSERT_EQ (nano::process_result::progress, node.process (*receive).code);

node.scheduler.buckets.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
ASSERT_TIMELY (5s, node.active.election (send->qualified_root ()));
auto election1 = node.active.election (send->qualified_root ());
ASSERT_EQ (1, node.active.size ());
ASSERT_EQ (1, election1->blocks ().count (send->hash ()));
node.scheduler.buckets.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
auto election2 = node.active.election (send->qualified_root ());
ASSERT_EQ (election2, election1);
election1->force_confirm ();
ASSERT_TIMELY (3s, node.block_confirmed (send->hash ()));
// On cementing, the next election is started
ASSERT_TIMELY (3s, node.active.active (send2->qualified_root ()));
node.scheduler.buckets.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
auto election3 = node.active.election (send2->qualified_root ());
ASSERT_NE (nullptr, election3);
ASSERT_EQ (1, election3->blocks ().count (send2->hash ()));
Expand All @@ -1161,19 +1161,19 @@ TEST (active_transactions, activate_account_chain)
// On cementing, the next election is started
ASSERT_TIMELY (3s, node.active.active (open->qualified_root ()));
ASSERT_TIMELY (3s, node.active.active (send3->qualified_root ()));
node.scheduler.buckets.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
auto election4 = node.active.election (send3->qualified_root ());
ASSERT_NE (nullptr, election4);
ASSERT_EQ (1, election4->blocks ().count (send3->hash ()));
node.scheduler.buckets.activate (key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (key.pub, node.store.tx_begin_read ());
auto election5 = node.active.election (open->qualified_root ());
ASSERT_NE (nullptr, election5);
ASSERT_EQ (1, election5->blocks ().count (open->hash ()));
election5->force_confirm ();
ASSERT_TIMELY (3s, node.block_confirmed (open->hash ()));
// Until send3 is also confirmed, the receive block should not activate
std::this_thread::sleep_for (200ms);
node.scheduler.buckets.activate (key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (key.pub, node.store.tx_begin_read ());
election4->force_confirm ();
ASSERT_TIMELY (3s, node.block_confirmed (send3->hash ()));
ASSERT_TIMELY (3s, node.active.active (receive->qualified_root ()));
Expand Down Expand Up @@ -1314,7 +1314,7 @@ TEST (active_transactions, vacancy)
ASSERT_EQ (nano::process_result::progress, node.process (*send).code);
ASSERT_EQ (1, node.active.vacancy ());
ASSERT_EQ (0, node.active.size ());
node.scheduler.buckets.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
ASSERT_TIMELY (1s, updated);
updated = false;
ASSERT_EQ (0, node.active.vacancy ());
Expand Down Expand Up @@ -1393,11 +1393,11 @@ TEST (active_transactions, fifo)
ASSERT_EQ (nano::process_result::progress, node.process (*receive2).code);

// Ensure first transaction becomes active
node.scheduler.buckets.manual (receive1);
node.scheduler.priority.manual (receive1);
ASSERT_TIMELY (5s, node.active.election (receive1->qualified_root ()) != nullptr);

// Ensure second transaction becomes active
node.scheduler.buckets.manual (receive2);
node.scheduler.priority.manual (receive2);
ASSERT_TIMELY (5s, node.active.election (receive2->qualified_root ()) != nullptr);

// Ensure excess transactions get trimmed
Expand Down Expand Up @@ -1503,7 +1503,7 @@ TEST (active_transactions, allow_limited_overflow)
// Insert the first part of the blocks into normal election scheduler
for (auto const & block : blocks1)
{
node.scheduler.buckets.activate (block->account (), node.store.tx_begin_read ());
node.scheduler.priority.activate (block->account (), node.store.tx_begin_read ());
}

// Ensure number of active elections reaches AEC limit and there is no overfill
Expand Down Expand Up @@ -1565,7 +1565,7 @@ TEST (active_transactions, allow_limited_overflow_adapt)
// Insert the first part of the blocks into normal election scheduler
for (auto const & block : blocks1)
{
node.scheduler.buckets.activate (block->account (), node.store.tx_begin_read ());
node.scheduler.priority.activate (block->account (), node.store.tx_begin_read ());
}

// Ensure number of active elections reaches AEC limit and there is no overfill
Expand Down
8 changes: 4 additions & 4 deletions nano/core_test/conflicts.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <nano/node/election.hpp>
#include <nano/node/scheduler/buckets.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>

Expand All @@ -27,7 +27,7 @@ TEST (conflicts, start_stop)
node1.work_generate_blocking (*send1);
ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code);
ASSERT_EQ (0, node1.active.size ());
node1.scheduler.buckets.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ()));
auto election1 = node1.active.election (send1->qualified_root ());
ASSERT_EQ (1, node1.active.size ());
Expand Down Expand Up @@ -60,7 +60,7 @@ TEST (conflicts, add_existing)
ASSERT_TIMELY (5s, node1.block (send1->hash ()));

// instruct the election scheduler to trigger an election for send1
node1.scheduler.buckets.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());

// wait for election to be started before processing send2
ASSERT_TIMELY (5s, node1.active.active (*send1));
Expand Down Expand Up @@ -167,7 +167,7 @@ TEST (conflicts, add_two)

// activate elections for the previous two send blocks (to account3) that we did not forcefully confirm
//
node->scheduler.buckets.activate (account3.pub, node->store.tx_begin_read ());
node->scheduler.priority.activate (account3.pub, node->store.tx_begin_read ());
ASSERT_TIMELY (5s, node->active.election ((*send3)->qualified_root ()) != nullptr);
ASSERT_TIMELY (5s, node->active.election ((*send4)->qualified_root ()) != nullptr);

Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/election.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <nano/node/election.hpp>
#include <nano/node/scheduler/buckets.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/test_common/chains.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>
Expand Down Expand Up @@ -150,7 +150,7 @@ TEST (election, quorum_minimum_confirm_success)
.build_shared ();
node1.work_generate_blocking (*send1);
node1.process_active (send1);
node1.scheduler.buckets.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ()));
auto election = node1.active.election (send1->qualified_root ());
ASSERT_NE (nullptr, election);
Expand Down
20 changes: 10 additions & 10 deletions nano/core_test/election_scheduler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <nano/node/scheduler/buckets.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>

Expand Down Expand Up @@ -28,7 +28,7 @@ TEST (election_scheduler, activate_one_timely)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build_shared ();
system.nodes[0]->ledger.process (system.nodes[0]->store.tx_begin_write (), *send1);
system.nodes[0]->scheduler.buckets.activate (nano::dev::genesis_key.pub, system.nodes[0]->store.tx_begin_read ());
system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->store.tx_begin_read ());
ASSERT_TIMELY (5s, system.nodes[0]->active.election (send1->qualified_root ()));
}

Expand All @@ -46,7 +46,7 @@ TEST (election_scheduler, activate_one_flush)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build_shared ();
system.nodes[0]->ledger.process (system.nodes[0]->store.tx_begin_write (), *send1);
system.nodes[0]->scheduler.buckets.activate (nano::dev::genesis_key.pub, system.nodes[0]->store.tx_begin_read ());
system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->store.tx_begin_read ());
ASSERT_TIMELY (5s, system.nodes[0]->active.election (send1->qualified_root ()));
}

Expand Down Expand Up @@ -115,7 +115,7 @@ TEST (election_scheduler, no_vacancy)
ASSERT_EQ (nano::process_result::progress, node.process (*block1).code);

// There is vacancy so it should be inserted
node.scheduler.buckets.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
std::shared_ptr<nano::election> election{};
ASSERT_TIMELY (5s, (election = node.active.election (block1->qualified_root ())) != nullptr);

Expand All @@ -131,14 +131,14 @@ TEST (election_scheduler, no_vacancy)
ASSERT_EQ (nano::process_result::progress, node.process (*block2).code);

// There is no vacancy so it should stay queued
node.scheduler.buckets.activate (key.pub, node.store.tx_begin_read ());
ASSERT_TIMELY (5s, node.scheduler.buckets.size () == 1);
node.scheduler.priority.activate (key.pub, node.store.tx_begin_read ());
ASSERT_TIMELY (5s, node.scheduler.priority.size () == 1);
ASSERT_TRUE (node.active.election (block2->qualified_root ()) == nullptr);

// Election confirmed, next in queue should begin
election->force_confirm ();
ASSERT_TIMELY (5s, node.active.election (block2->qualified_root ()) != nullptr);
ASSERT_TRUE (node.scheduler.buckets.empty ());
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
Expand All @@ -162,9 +162,9 @@ TEST (election_scheduler, flush_vacancy)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build_shared ();
ASSERT_EQ (nano::process_result::progress, node.process (*send).code);
node.scheduler.buckets.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
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.buckets.flush ();
node.scheduler.priority.flush ();
ASSERT_EQ (0, node.active.size ());
ASSERT_EQ (1, node.scheduler.buckets.size ());
ASSERT_EQ (1, node.scheduler.priority.size ());
}
6 changes: 3 additions & 3 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <nano/lib/threading.hpp>
#include <nano/node/election.hpp>
#include <nano/node/rocksdb/rocksdb.hpp>
#include <nano/node/scheduler/buckets.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/node/transport/inproc.hpp>
#include <nano/test_common/ledger.hpp>
#include <nano/test_common/system.hpp>
Expand Down Expand Up @@ -913,7 +913,7 @@ TEST (votes, check_signature)
auto transaction (node1.store.tx_begin_write ());
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (transaction, *send1).code);
}
node1.scheduler.buckets.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ()));
auto election1 = node1.active.election (send1->qualified_root ());
ASSERT_EQ (1, election1->votes ().size ());
Expand Down Expand Up @@ -984,7 +984,7 @@ TEST (votes, add_existing)
.build ();
node1.work_generate_blocking (*send1);
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (node1.store.tx_begin_write (), *send1).code);
node1.scheduler.buckets.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ()));
auto election1 = node1.active.election (send1->qualified_root ());
auto vote1 (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::vote::timestamp_min * 1, 0, std::vector<nano::block_hash>{ send1->hash () }));
Expand Down
6 changes: 3 additions & 3 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <nano/node/network.hpp>
#include <nano/node/nodeconfig.hpp>
#include <nano/node/scheduler/buckets.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/node/transport/inproc.hpp>
#include <nano/node/transport/socket.hpp>
#include <nano/test_common/network.hpp>
Expand Down Expand Up @@ -366,7 +366,7 @@ TEST (receivable_processor, confirm_insufficient_pos)
.build_shared ();
node1.work_generate_blocking (*block1);
ASSERT_EQ (nano::process_result::progress, node1.process (*block1).code);
node1.scheduler.buckets.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
nano::keypair key1;
auto vote (std::make_shared<nano::vote> (key1.pub, key1.prv, 0, 0, std::vector<nano::block_hash>{ block1->hash () }));
nano::confirm_ack con1{ nano::dev::network_params.network, vote };
Expand All @@ -389,7 +389,7 @@ TEST (receivable_processor, confirm_sufficient_pos)
.build_shared ();
node1.work_generate_blocking (*block1);
ASSERT_EQ (nano::process_result::progress, node1.process (*block1).code);
node1.scheduler.buckets.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
auto vote (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash>{ block1->hash () }));
nano::confirm_ack con1{ nano::dev::network_params.network, vote };
auto channel1 = std::make_shared<nano::transport::inproc::channel> (node1, node1);
Expand Down
8 changes: 4 additions & 4 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <nano/lib/config.hpp>
#include <nano/node/election.hpp>
#include <nano/node/scheduler/buckets.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/node/transport/fake.hpp>
#include <nano/node/transport/inproc.hpp>
#include <nano/test_common/network.hpp>
Expand Down Expand Up @@ -987,7 +987,7 @@ TEST (node, fork_open_flip)
// give block open1 to node1, manually trigger an election for open1 and ensure it is in the ledger
node1.process_active (open1);
ASSERT_TIMELY (5s, node1.block (open1->hash ()) != nullptr);
node1.scheduler.buckets.manual (open1);
node1.scheduler.priority.manual (open1);
ASSERT_TIMELY (5s, (election = node1.active.election (open1->qualified_root ())) != nullptr);
election->transition_active ();

Expand All @@ -1000,7 +1000,7 @@ TEST (node, fork_open_flip)

// ensure open2 is in node2 ledger (and therefore has sideband) and manually trigger an election for open2
ASSERT_TIMELY (5s, node2.block (open2->hash ()) != nullptr);
node2.scheduler.buckets.manual (open2);
node2.scheduler.priority.manual (open2);
ASSERT_TIMELY (5s, (election = node2.active.election (open2->qualified_root ())) != nullptr);
election->transition_active ();

Expand Down Expand Up @@ -1415,7 +1415,7 @@ TEST (node, rep_self_vote)
ASSERT_EQ (nano::process_result::progress, node0->process (*block0).code);
auto & active = node0->active;
auto & scheduler = node0->scheduler;
scheduler.buckets.activate (nano::dev::genesis_key.pub, node0->store.tx_begin_read ());
scheduler.priority.activate (nano::dev::genesis_key.pub, node0->store.tx_begin_read ());
ASSERT_TIMELY (5s, active.election (block0->qualified_root ()));
auto election1 = active.election (block0->qualified_root ());
ASSERT_NE (nullptr, election1);
Expand Down
4 changes: 2 additions & 2 deletions nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ add_library(
rocksdb/rocksdb_iterator.hpp
rocksdb/rocksdb_txn.hpp
rocksdb/rocksdb_txn.cpp
scheduler/buckets.hpp
scheduler/buckets.cpp
scheduler/component.hpp
scheduler/component.cpp
scheduler/hinted.hpp
scheduler/hinted.cpp
scheduler/optimistic.hpp
scheduler/optimistic.cpp
scheduler/priority.hpp
scheduler/priority.cpp
signatures.hpp
signatures.cpp
state_block_signature_verification.hpp
Expand Down
6 changes: 3 additions & 3 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <nano/node/election.hpp>
#include <nano/node/node.hpp>
#include <nano/node/repcrawler.hpp>
#include <nano/node/scheduler/buckets.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/secure/store.hpp>

#include <boost/format.hpp>
Expand Down Expand Up @@ -151,13 +151,13 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptr<nano::b
if (cemented_bootstrap_count_reached && was_active)
{
// Start or vote for the next unconfirmed block
node.scheduler.buckets.activate (account, transaction);
node.scheduler.priority.activate (account, transaction);

// Start or vote for the next unconfirmed block in the destination account
auto const & destination (node.ledger.block_destination (transaction, *block_a));
if (!destination.is_zero () && destination != account)
{
node.scheduler.buckets.activate (destination, transaction);
node.scheduler.priority.activate (destination, transaction);
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions nano/node/active_transactions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ class transaction;
class confirmation_height_processor;
class stats;

namespace scheduler
{
class buckets;
}

class recently_confirmed_cache final
{
public:
Expand Down
2 changes: 1 addition & 1 deletion nano/node/backlog_population.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <nano/lib/threading.hpp>
#include <nano/node/backlog_population.hpp>
#include <nano/node/nodeconfig.hpp>
#include <nano/node/scheduler/buckets.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/secure/store.hpp>

nano::backlog_population::backlog_population (const config & config_a, nano::store & store_a, nano::stats & stats_a) :
Expand Down
Loading

0 comments on commit 5389072

Please sign in to comment.