Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nano::genesis class #3391

Merged
merged 6 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 68 additions & 81 deletions nano/core_test/active_transactions.cpp

Large diffs are not rendered by default.

90 changes: 36 additions & 54 deletions nano/core_test/block_store.cpp

Large diffs are not rendered by default.

155 changes: 66 additions & 89 deletions nano/core_test/bootstrap.cpp

Large diffs are not rendered by default.

104 changes: 48 additions & 56 deletions nano/core_test/confirmation_height.cpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions nano/core_test/confirmation_solicitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST (confirmation_solicitor, batches)
auto & node2 = *system.add_node (node_flags);
auto channel1 (node2.network.udp_channels.create (node1.network.endpoint ()));
// Solicitor will only solicit from this representative
nano::representative representative (nano::dev::genesis_key.pub, nano::dev::genesis_amount, channel1);
nano::representative representative (nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount, channel1);
std::vector<nano::representative> representatives{ representative };
nano::confirmation_solicitor solicitor (node2.network, node2.config);
solicitor.prepare (representatives);
Expand All @@ -28,7 +28,7 @@ TEST (confirmation_solicitor, batches)
ASSERT_EQ (channel1, representatives.front ().channel);
ASSERT_EQ (nano::dev::genesis_key.pub, representatives.front ().account);
ASSERT_TIMELY (3s, node2.network.size () == 1);
auto send (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), nano::keypair ().pub, nano::dev::genesis_amount - 100, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (nano::dev::genesis->hash ())));
auto send (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), nano::keypair ().pub, nano::dev::constants.genesis_amount - 100, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (nano::dev::genesis->hash ())));
send->sideband_set ({});
{
nano::lock_guard<nano::mutex> guard (node2.active.mutex);
Expand Down Expand Up @@ -63,7 +63,7 @@ TEST (confirmation_solicitor, different_hash)
auto & node2 = *system.add_node (node_flags);
auto channel1 (node2.network.udp_channels.create (node1.network.endpoint ()));
// Solicitor will only solicit from this representative
nano::representative representative (nano::dev::genesis_key.pub, nano::dev::genesis_amount, channel1);
nano::representative representative (nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount, channel1);
std::vector<nano::representative> representatives{ representative };
nano::confirmation_solicitor solicitor (node2.network, node2.config);
solicitor.prepare (representatives);
Expand All @@ -72,7 +72,7 @@ TEST (confirmation_solicitor, different_hash)
ASSERT_EQ (channel1, representatives.front ().channel);
ASSERT_EQ (nano::dev::genesis_key.pub, representatives.front ().account);
ASSERT_TIMELY (3s, node2.network.size () == 1);
auto send (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), nano::keypair ().pub, nano::dev::genesis_amount - 100, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (nano::dev::genesis->hash ())));
auto send (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), nano::keypair ().pub, nano::dev::constants.genesis_amount - 100, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (nano::dev::genesis->hash ())));
send->sideband_set ({});
auto election (std::make_shared<nano::election> (node2, send, nullptr, nullptr, nano::election_behavior::normal));
// Add a vote for something else, not the winner
Expand Down Expand Up @@ -108,7 +108,7 @@ TEST (confirmation_solicitor, bypass_max_requests_cap)
ASSERT_EQ (max_representatives + 1, representatives.size ());
solicitor.prepare (representatives);
ASSERT_TIMELY (3s, node2.network.size () == 1);
auto send (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), nano::keypair ().pub, nano::dev::genesis_amount - 100, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (nano::dev::genesis->hash ())));
auto send (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), nano::keypair ().pub, nano::dev::constants.genesis_amount - 100, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (nano::dev::genesis->hash ())));
send->sideband_set ({});
auto election (std::make_shared<nano::election> (node2, send, nullptr, nullptr, nano::election_behavior::normal));
// Add a vote for something else, not the winner
Expand Down
11 changes: 4 additions & 7 deletions nano/core_test/conflicts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ TEST (conflicts, start_stop)
{
nano::system system (1);
auto & node1 (*system.nodes[0]);
nano::genesis genesis;
nano::keypair key1;
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key1.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, 0));
auto send1 (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), key1.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, 0));
node1.work_generate_blocking (*send1);
ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code);
ASSERT_EQ (0, node1.active.size ());
Expand All @@ -30,14 +29,13 @@ TEST (conflicts, add_existing)
{
nano::system system (1);
auto & node1 (*system.nodes[0]);
nano::genesis genesis;
nano::keypair key1;
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key1.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, 0));
auto send1 (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), key1.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, 0));
node1.work_generate_blocking (*send1);
ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code);
node1.scheduler.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
nano::keypair key2;
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, 0));
auto send2 (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), key2.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, 0));
send2->sideband_set ({});
node1.scheduler.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.flush ();
Expand All @@ -55,9 +53,8 @@ TEST (conflicts, add_two)
{
nano::system system (1);
auto & node1 (*system.nodes[0]);
nano::genesis genesis;
nano::keypair key1;
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key1.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, 0));
auto send1 (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), key1.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, 0));
node1.work_generate_blocking (*send1);
ASSERT_EQ (nano::process_result::progress, node1.process (*send1).code);
node1.block_confirm (send1);
Expand Down
16 changes: 7 additions & 9 deletions nano/core_test/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ using namespace std::chrono_literals;
TEST (election, construction)
{
nano::system system (1);
nano::genesis genesis;
auto & node = *system.nodes[0];
genesis.open->sideband_set (nano::block_sideband (nano::dev::genesis->account (), 0, nano::dev::genesis_amount, 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0));
node.block_confirm (genesis.open);
node.block_confirm (nano::dev::genesis);
node.scheduler.flush ();
auto election = node.active.election (genesis.open->qualified_root ());
auto election = node.active.election (nano::dev::genesis->qualified_root ());
election->transition_active ();
}

TEST (election, quorum_minimum_flip_success)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.online_weight_minimum = nano::dev::genesis_amount;
node_config.online_weight_minimum = nano::dev::constants.genesis_amount;
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto & node1 = *system.add_node (node_config);
nano::keypair key1;
Expand Down Expand Up @@ -68,7 +66,7 @@ TEST (election, quorum_minimum_flip_fail)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.online_weight_minimum = nano::dev::genesis_amount;
node_config.online_weight_minimum = nano::dev::constants.genesis_amount;
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto & node1 = *system.add_node (node_config);
nano::keypair key1;
Expand Down Expand Up @@ -114,7 +112,7 @@ TEST (election, quorum_minimum_confirm_success)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.online_weight_minimum = nano::dev::genesis_amount;
node_config.online_weight_minimum = nano::dev::constants.genesis_amount;
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto & node1 = *system.add_node (node_config);
nano::keypair key1;
Expand Down Expand Up @@ -147,7 +145,7 @@ TEST (election, quorum_minimum_confirm_fail)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.online_weight_minimum = nano::dev::genesis_amount;
node_config.online_weight_minimum = nano::dev::constants.genesis_amount;
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto & node1 = *system.add_node (node_config);
nano::keypair key1;
Expand Down Expand Up @@ -202,7 +200,7 @@ TEST (election, quorum_minimum_update_weight_before_quorum_checks)
.account (key1.pub)
.previous (0)
.representative (key1.pub)
.balance (nano::dev::genesis_amount - amount)
.balance (nano::dev::constants.genesis_amount - amount)
.link (send1->hash ())
.work (0)
.sign (key1.prv, key1.pub)
Expand Down
10 changes: 5 additions & 5 deletions nano/core_test/election_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST (election_scheduler, activate_one_timely)
.account (nano::dev::genesis_key.pub)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::genesis_amount - nano::Gxrb_ratio)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (nano::dev::genesis_key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
Expand All @@ -39,7 +39,7 @@ TEST (election_scheduler, activate_one_flush)
.account (nano::dev::genesis_key.pub)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::genesis_amount - nano::Gxrb_ratio)
.balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio)
.link (nano::dev::genesis_key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
Expand All @@ -65,7 +65,7 @@ TEST (election_scheduler, no_vacancy)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis_key.pub)
.link (key.pub)
.balance (nano::dev::genesis_amount - nano::Gxrb_ratio)
.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 ();
Expand All @@ -91,7 +91,7 @@ TEST (election_scheduler, no_vacancy)
.previous (send->hash ())
.representative (nano::dev::genesis_key.pub)
.link (nano::dev::genesis_key.pub)
.balance (nano::dev::genesis_amount - 2 * nano::Gxrb_ratio)
.balance (nano::dev::constants.genesis_amount - 2 * nano::Gxrb_ratio)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (send->hash ()))
.build_shared ();
Expand Down Expand Up @@ -138,7 +138,7 @@ TEST (election_scheduler, flush_vacancy)
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis_key.pub)
.link (key.pub)
.balance (nano::dev::genesis_amount - nano::Gxrb_ratio)
.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 ();
Expand Down
7 changes: 3 additions & 4 deletions nano/core_test/frontiers_confirmation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ TEST (frontiers_confirmation, expired_optimistic_elections_removal)

TEST (frontiers_confirmation, mode)
{
nano::genesis genesis;
nano::keypair key;
nano::node_flags node_flags;
// Always mode
Expand All @@ -219,7 +218,7 @@ TEST (frontiers_confirmation, mode)
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::always;
auto node = system.add_node (node_config, node_flags);
nano::state_block send (nano::dev::genesis_key.pub, genesis.hash (), nano::dev::genesis_key.pub, nano::dev::genesis_amount - nano::Gxrb_ratio, key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *node->work_generate_blocking (genesis.hash ()));
nano::state_block send (nano::dev::genesis_key.pub, nano::dev::genesis->hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *node->work_generate_blocking (nano::dev::genesis->hash ()));
{
auto transaction = node->store.tx_begin_write ();
ASSERT_EQ (nano::process_result::progress, node->ledger.process (transaction, send).code);
Expand All @@ -232,7 +231,7 @@ TEST (frontiers_confirmation, mode)
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::automatic;
auto node = system.add_node (node_config, node_flags);
nano::state_block send (nano::dev::genesis_key.pub, genesis.hash (), nano::dev::genesis_key.pub, nano::dev::genesis_amount - nano::Gxrb_ratio, key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *node->work_generate_blocking (genesis.hash ()));
nano::state_block send (nano::dev::genesis_key.pub, nano::dev::genesis->hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *node->work_generate_blocking (nano::dev::genesis->hash ()));
{
auto transaction = node->store.tx_begin_write ();
ASSERT_EQ (nano::process_result::progress, node->ledger.process (transaction, send).code);
Expand All @@ -245,7 +244,7 @@ TEST (frontiers_confirmation, mode)
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto node = system.add_node (node_config, node_flags);
nano::state_block send (nano::dev::genesis_key.pub, genesis.hash (), nano::dev::genesis_key.pub, nano::dev::genesis_amount - nano::Gxrb_ratio, key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *node->work_generate_blocking (genesis.hash ()));
nano::state_block send (nano::dev::genesis_key.pub, nano::dev::genesis->hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *node->work_generate_blocking (nano::dev::genesis->hash ()));
{
auto transaction = node->store.tx_begin_write ();
ASSERT_EQ (nano::process_result::progress, node->ledger.process (transaction, send).code);
Expand Down
15 changes: 7 additions & 8 deletions nano/core_test/gap_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ TEST (gap_cache, gap_bootstrap)
auto & node2 (*system.nodes[1]);
nano::block_hash latest (node1.latest (nano::dev::genesis_key.pub));
nano::keypair key;
auto send (std::make_shared<nano::send_block> (latest, key.pub, nano::dev::genesis_amount - 100, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (latest)));
auto send (std::make_shared<nano::send_block> (latest, key.pub, nano::dev::constants.genesis_amount - 100, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (latest)));
node1.process (*send);
ASSERT_EQ (nano::dev::genesis_amount - 100, node1.balance (nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::genesis_amount, node2.balance (nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount - 100, node1.balance (nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, node2.balance (nano::dev::genesis->account ()));
// Confirm send block, allowing voting on the upcoming block
node1.block_confirm (send);
auto election = node1.active.election (send->qualified_root ());
Expand All @@ -81,18 +81,17 @@ TEST (gap_cache, gap_bootstrap)
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
auto latest_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key.pub, 100));
ASSERT_NE (nullptr, latest_block);
ASSERT_EQ (nano::dev::genesis_amount - 200, node1.balance (nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::genesis_amount, node2.balance (nano::dev::genesis->account ()));
ASSERT_TIMELY (10s, node2.balance (nano::dev::genesis->account ()) == nano::dev::genesis_amount - 200);
ASSERT_EQ (nano::dev::constants.genesis_amount - 200, node1.balance (nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, node2.balance (nano::dev::genesis->account ()));
ASSERT_TIMELY (10s, node2.balance (nano::dev::genesis->account ()) == nano::dev::constants.genesis_amount - 200);
}

TEST (gap_cache, two_dependencies)
{
nano::system system (1);
auto & node1 (*system.nodes[0]);
nano::keypair key;
nano::genesis genesis;
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key.pub, 1, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (genesis.hash ())));
auto send1 (std::make_shared<nano::send_block> (nano::dev::genesis->hash (), key.pub, 1, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (nano::dev::genesis->hash ())));
auto send2 (std::make_shared<nano::send_block> (send1->hash (), key.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (send1->hash ())));
auto open (std::make_shared<nano::open_block> (send1->hash (), key.pub, key.pub, key.prv, key.pub, *system.work.generate (key.pub)));
ASSERT_EQ (0, node1.gap_cache.size ());
Expand Down
Loading