diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index 79b35d560..c1f46b969 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -490,14 +490,14 @@ TEST (active_transactions, inactive_votes_cache_election_start) auto send3 = send_block_builder.make_block () .previous (send2->hash ()) .destination (nano::keypair ().pub) - .balance (send2->balance ().number () - 1) + .balance (send2->balance_field ().value ().number () - 1) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (send2->hash ())) .build (); auto send4 = send_block_builder.make_block () .previous (send3->hash ()) .destination (nano::keypair ().pub) - .balance (send3->balance ().number () - 1) + .balance (send3->balance_field ().value ().number () - 1) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (send3->hash ())) .build (); diff --git a/nano/core_test/backlog.cpp b/nano/core_test/backlog.cpp index fa58f702c..26d5680a8 100644 --- a/nano/core_test/backlog.cpp +++ b/nano/core_test/backlog.cpp @@ -33,9 +33,7 @@ TEST (backlog, population) auto all_activated = [&] () { nano::lock_guard lock{ mutex }; return std::all_of (blocks.begin (), blocks.end (), [&] (auto const & item) { - auto account = item->account (); - debug_assert (!account.is_zero ()); - return activated.count (account) != 0; + return activated.count (item->account ()) != 0; }); }; ASSERT_TIMELY (5s, all_activated ()); diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index b187f63bb..f5dd614b3 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -657,9 +657,9 @@ TEST (block_builder, state) .link_hex ("E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86") .build (ec); ASSERT_EQ (block->hash ().to_string (), "2D243F8F92CDD0AD94A1D456A6B15F3BE7A6FCBD98D4C5831D06D15C818CD81F"); - ASSERT_TRUE (block->source ().is_zero ()); - ASSERT_TRUE (block->destination ().is_zero ()); - ASSERT_EQ (block->link ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86"); + ASSERT_FALSE (block->source_field ()); + ASSERT_FALSE (block->destination_field ()); + ASSERT_EQ (block->link_field ().value ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86"); } TEST (block_builder, state_missing_rep) @@ -730,9 +730,9 @@ TEST (block_builder, open) .source_hex ("E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA") .build (ec); ASSERT_EQ (block->hash ().to_string (), "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"); - ASSERT_EQ (block->source ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"); - ASSERT_TRUE (block->destination ().is_zero ()); - ASSERT_TRUE (block->link ().is_zero ()); + ASSERT_EQ (block->source_field ().value ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"); + ASSERT_FALSE (block->destination_field ()); + ASSERT_FALSE (block->link_field ()); } TEST (block_builder, open_equality) @@ -769,9 +769,9 @@ TEST (block_builder, change) .previous_hex ("088EE46429CA936F76C4EAA20B97F6D33E5D872971433EE0C1311BCB98764456") .build (ec); ASSERT_EQ (block->hash ().to_string (), "13552AC3928E93B5C6C215F61879358E248D4A5246B8B3D1EEC5A566EDCEE077"); - ASSERT_TRUE (block->source ().is_zero ()); - ASSERT_TRUE (block->destination ().is_zero ()); - ASSERT_TRUE (block->link ().is_zero ()); + ASSERT_FALSE (block->source_field ()); + ASSERT_FALSE (block->destination_field ()); + ASSERT_FALSE (block->link_field ()); } TEST (block_builder, change_equality) @@ -808,9 +808,9 @@ TEST (block_builder, send) .balance_hex ("00F035A9C7D818E7C34148C524FFFFEE") .build (ec); ASSERT_EQ (block->hash ().to_string (), "4560E7B1F3735D082700CFC2852F5D1F378F7418FD24CEF1AD45AB69316F15CD"); - ASSERT_TRUE (block->source ().is_zero ()); - ASSERT_EQ (block->destination ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb"); - ASSERT_TRUE (block->link ().is_zero ()); + ASSERT_FALSE (block->source_field ()); + ASSERT_EQ (block->destination_field ().value ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb"); + ASSERT_FALSE (block->link_field ()); } TEST (block_builder, send_equality) @@ -870,7 +870,7 @@ TEST (block_builder, receive) .source_hex ("7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135") .build (ec); ASSERT_EQ (block->hash ().to_string (), "6C004BF911D9CF2ED75CF6EC45E795122AD5D093FF5A83EDFBA43EC4A3EDC722"); - ASSERT_EQ (block->source ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135"); - ASSERT_TRUE (block->destination ().is_zero ()); - ASSERT_TRUE (block->link ().is_zero ()); + ASSERT_EQ (block->source_field ().value ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135"); + ASSERT_FALSE (block->destination_field ()); + ASSERT_FALSE (block->link_field ()); } diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 2b96b65b2..08e267716 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -383,7 +383,7 @@ TEST (block_store, genesis) auto transaction (store->tx_begin_write ()); store->initialize (transaction, ledger_cache, nano::dev::constants); nano::account_info info; - ASSERT_FALSE (store->account.get (transaction, nano::dev::genesis->account (), info)); + ASSERT_FALSE (store->account.get (transaction, nano::dev::genesis_key.pub, info)); ASSERT_EQ (nano::dev::genesis->hash (), info.head); auto block1 (store->block.get (transaction, info.head)); ASSERT_NE (nullptr, block1); @@ -393,13 +393,13 @@ TEST (block_store, genesis) ASSERT_EQ (info.block_count, 1); // Genesis block should be confirmed by default nano::confirmation_height_info confirmation_height_info; - ASSERT_FALSE (store->confirmation_height.get (transaction, nano::dev::genesis->account (), confirmation_height_info)); + ASSERT_FALSE (store->confirmation_height.get (transaction, nano::dev::genesis_key.pub, confirmation_height_info)); ASSERT_EQ (confirmation_height_info.height, 1); ASSERT_EQ (confirmation_height_info.frontier, nano::dev::genesis->hash ()); auto dev_pub_text (nano::dev::genesis_key.pub.to_string ()); auto dev_pub_account (nano::dev::genesis_key.pub.to_account ()); auto dev_prv_text (nano::dev::genesis_key.prv.to_string ()); - ASSERT_EQ (nano::dev::genesis->account (), nano::dev::genesis_key.pub); + ASSERT_EQ (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub); } TEST (block_store, empty_accounts) diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index 27c78bb20..57aeae26f 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -159,7 +159,7 @@ TEST (bulk_pull, ascending_two_account) auto socket = std::make_shared (node, nano::transport::socket::endpoint_type_t::server); auto connection = std::make_shared (socket, system.nodes[0]); auto req = std::make_unique (nano::dev::network_params.network); - req->start = nano::dev::genesis->account (); + req->start = nano::dev::genesis_key.pub; req->end.clear (); req->header.flag_set (nano::message_header::bulk_pull_ascending_flag); auto request = std::make_shared (connection, std::move (req)); @@ -2123,9 +2123,9 @@ TEST (bulk_pull_account, basics) nano::keypair key1; system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); system.wallet (0)->insert_adhoc (key1.prv); - auto send1 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 25)); - auto send2 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 10)); - auto send3 (system.wallet (0)->send_action (nano::dev::genesis->account (), key1.pub, 2)); + auto send1 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 25)); + auto send2 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 10)); + auto send3 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 2)); ASSERT_TIMELY_EQ (5s, system.nodes[0]->balance (key1.pub), 25); auto connection (std::make_shared (std::make_shared (*system.nodes[0], nano::transport::socket::endpoint_type_t::server), system.nodes[0])); @@ -2143,7 +2143,7 @@ TEST (bulk_pull_account, basics) auto block_data (request->get_next ()); ASSERT_EQ (send2->hash (), block_data.first.get ()->hash); ASSERT_EQ (nano::uint128_union (10), block_data.second.get ()->amount); - ASSERT_EQ (nano::dev::genesis->account (), block_data.second.get ()->source); + ASSERT_EQ (nano::dev::genesis_key.pub, block_data.second.get ()->source); ASSERT_EQ (nullptr, request->get_next ().first.get ()); } @@ -2157,7 +2157,7 @@ TEST (bulk_pull_account, basics) auto block_data (request->get_next ()); ASSERT_NE (nullptr, block_data.first.get ()); ASSERT_NE (nullptr, block_data.second.get ()); - ASSERT_EQ (nano::dev::genesis->account (), block_data.second.get ()->source); + ASSERT_EQ (nano::dev::genesis_key.pub, block_data.second.get ()->source); block_data = request->get_next (); ASSERT_EQ (nullptr, block_data.first.get ()); ASSERT_EQ (nullptr, block_data.second.get ()); diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index 52723aaeb..db2e46fd0 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -133,7 +133,7 @@ TEST (confirmation_height, multiple_accounts) auto open1 = builder .open () .source (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key1.pub) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1.pub)) @@ -141,7 +141,7 @@ TEST (confirmation_height, multiple_accounts) auto open2 = builder .open () .source (send2->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key2.pub) .sign (key2.prv, key2.pub) .work (*system.work.generate (key2.pub)) @@ -149,7 +149,7 @@ TEST (confirmation_height, multiple_accounts) auto open3 = builder .open () .source (send3->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key3.pub) .sign (key3.prv, key3.pub) .work (*system.work.generate (key3.pub)) @@ -320,9 +320,9 @@ TEST (confirmation_height, gap_bootstrap) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -331,9 +331,9 @@ TEST (confirmation_height, gap_bootstrap) node1.work_generate_blocking (*send1); auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 2 * nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -342,9 +342,9 @@ TEST (confirmation_height, gap_bootstrap) node1.work_generate_blocking (*send2); auto send3 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send2->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 3 * nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -453,9 +453,9 @@ TEST (confirmation_height, gap_live) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 1) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -464,9 +464,9 @@ TEST (confirmation_height, gap_live) node->work_generate_blocking (*send1); auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 2) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -475,9 +475,9 @@ TEST (confirmation_height, gap_live) node->work_generate_blocking (*send2); auto send3 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send2->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 3) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -593,7 +593,7 @@ TEST (confirmation_height, send_receive_between_2_accounts) auto open1 = builder .open () .source (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key1.pub) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1.pub)) @@ -601,7 +601,7 @@ TEST (confirmation_height, send_receive_between_2_accounts) auto send2 = builder .send () .previous (open1->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (1000) .sign (key1.prv, key1.pub) .work (*system.work.generate (open1->hash ())) @@ -609,7 +609,7 @@ TEST (confirmation_height, send_receive_between_2_accounts) auto send3 = builder .send () .previous (send2->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (900) .sign (key1.prv, key1.pub) .work (*system.work.generate (send2->hash ())) @@ -617,7 +617,7 @@ TEST (confirmation_height, send_receive_between_2_accounts) auto send4 = builder .send () .previous (send3->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (500) .sign (key1.prv, key1.pub) .work (*system.work.generate (send3->hash ())) @@ -1013,9 +1013,9 @@ TEST (confirmation_height, all_block_types) .build (); auto state_receive3 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2 + 1) .link (state_send4->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -1292,7 +1292,7 @@ TEST (confirmation_heightDeathTest, modified_chain) } ASSERT_EQ (nano::block_status::progress, ledger.process (store->tx_begin_write (), send)); - store->confirmation_height.put (store->tx_begin_write (), nano::dev::genesis->account (), { 1, nano::dev::genesis->hash () }); + store->confirmation_height.put (store->tx_begin_write (), nano::dev::genesis_key.pub, { 1, nano::dev::genesis->hash () }); nano::confirmation_height_unbounded unbounded_processor ( ledger, write_database_queue, 10ms, logger, stopped, batch_write_size, [] (auto const &) {}, [] (auto const &) {}, [] () { return 0; }); @@ -1381,7 +1381,7 @@ TEST (confirmation_heightDeathTest, modified_chain_account_removed) // Reset conditions and test with the bounded processor ASSERT_EQ (nano::block_status::progress, ledger.process (store->tx_begin_write (), open)); - store->confirmation_height.put (store->tx_begin_write (), nano::dev::genesis->account (), { 1, nano::dev::genesis->hash () }); + store->confirmation_height.put (store->tx_begin_write (), nano::dev::genesis_key.pub, { 1, nano::dev::genesis->hash () }); nano::confirmation_height_bounded bounded_processor ( ledger, write_database_queue, 10ms, logger, stopped, batch_write_size, [] (auto const &) {}, [] (auto const &) {}, [] () { return 0; }); @@ -1663,7 +1663,7 @@ TEST (confirmation_height, cemented_gap_below_receive) auto open = builder .open () .source (send->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key1.pub) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1.pub)) @@ -1722,7 +1722,7 @@ TEST (confirmation_height, cemented_gap_below_receive) auto open1 = builder .open () .source (send3->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key2.pub) .sign (key2.prv, key2.pub) .work (*system.work.generate (key2.pub)) @@ -1823,7 +1823,7 @@ TEST (confirmation_height, cemented_gap_below_no_cache) auto open = builder .open () .source (send->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key1.pub) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1.pub)) @@ -1882,7 +1882,7 @@ TEST (confirmation_height, cemented_gap_below_no_cache) auto open1 = builder .open () .source (send3->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key2.pub) .sign (key2.prv, key2.pub) .work (*system.work.generate (key2.pub)) @@ -1910,7 +1910,7 @@ TEST (confirmation_height, cemented_gap_below_no_cache) // Force some blocks to be cemented so that the cached confirmed info variable is empty { auto transaction (node->store.tx_begin_write ()); - node->store.confirmation_height.put (transaction, nano::dev::genesis->account (), nano::confirmation_height_info{ 3, send1->hash () }); + node->store.confirmation_height.put (transaction, nano::dev::genesis_key.pub, nano::confirmation_height_info{ 3, send1->hash () }); node->store.confirmation_height.put (transaction, key1.pub, nano::confirmation_height_info{ 2, receive1->hash () }); } diff --git a/nano/core_test/distributed_work.cpp b/nano/core_test/distributed_work.cpp index 115293bd6..1e5e5ed4a 100644 --- a/nano/core_test/distributed_work.cpp +++ b/nano/core_test/distributed_work.cpp @@ -18,10 +18,10 @@ TEST (distributed_work, no_peers) nano::test::system system (1); auto node (system.nodes[0]); nano::block_hash hash{ 1 }; - boost::optional work; + std::optional work; std::atomic done{ false }; - auto callback = [&work, &done] (boost::optional work_a) { - ASSERT_TRUE (work_a.is_initialized ()); + auto callback = [&work, &done] (std::optional work_a) { + ASSERT_TRUE (work_a.has_value ()); work = work_a; done = true; }; @@ -54,8 +54,8 @@ TEST (distributed_work, no_peers_cancel) auto & node = *system.add_node (node_config); nano::block_hash hash{ 1 }; bool done{ false }; - auto callback_to_cancel = [&done] (boost::optional work_a) { - ASSERT_FALSE (work_a.is_initialized ()); + auto callback_to_cancel = [&done] (std::optional work_a) { + ASSERT_FALSE (work_a.has_value ()); done = true; }; ASSERT_FALSE (node.distributed_work.make (nano::work_version::work_1, hash, node.config.work_peers, nano::difficulty::from_multiplier (1e6, node.network_params.work.base), callback_to_cancel)); @@ -83,8 +83,8 @@ TEST (distributed_work, no_peers_multi) nano::block_hash hash{ 1 }; unsigned total{ 10 }; std::atomic count{ 0 }; - auto callback = [&count] (boost::optional work_a) { - ASSERT_TRUE (work_a.is_initialized ()); + auto callback = [&count] (std::optional work_a) { + ASSERT_TRUE (work_a.has_value ()); ++count; }; // Test many works for the same root @@ -125,10 +125,10 @@ TEST (distributed_work, peer) auto node (system.add_node (node_config)); ASSERT_FALSE (node->local_work_generation_enabled ()); nano::block_hash hash{ 1 }; - boost::optional work; + std::optional work; std::atomic done{ false }; - auto callback = [&work, &done] (boost::optional work_a) { - ASSERT_TRUE (work_a.is_initialized ()); + auto callback = [&work, &done] (std::optional work_a) { + ASSERT_TRUE (work_a.has_value ()); work = work_a; done = true; }; @@ -151,10 +151,10 @@ TEST (distributed_work, peer_malicious) auto node (system.nodes[0]); ASSERT_TRUE (node->local_work_generation_enabled ()); nano::block_hash hash{ 1 }; - boost::optional work; + std::optional work; std::atomic done{ false }; - auto callback = [&work, &done] (boost::optional work_a) { - ASSERT_TRUE (work_a.is_initialized ()); + auto callback = [&work, &done] (std::optional work_a) { + ASSERT_TRUE (work_a.has_value ()); work = work_a; done = true; }; @@ -194,10 +194,10 @@ TEST (distributed_work, DISABLED_peer_multi) auto node (system.nodes[0]); ASSERT_TRUE (node->local_work_generation_enabled ()); nano::block_hash hash{ 1 }; - boost::optional work; + std::optional work; std::atomic done{ false }; - auto callback = [&work, &done] (boost::optional work_a) { - ASSERT_TRUE (work_a.is_initialized ()); + auto callback = [&work, &done] (std::optional work_a) { + ASSERT_TRUE (work_a.has_value ()); work = work_a; done = true; }; @@ -233,10 +233,10 @@ TEST (distributed_work, fail_resolve) nano::test::system system (1); auto node (system.nodes[0]); nano::block_hash hash{ 1 }; - boost::optional work; + std::optional work; std::atomic done{ false }; - auto callback = [&work, &done] (boost::optional work_a) { - ASSERT_TRUE (work_a.is_initialized ()); + auto callback = [&work, &done] (std::optional work_a) { + ASSERT_TRUE (work_a.has_value ()); work = work_a; done = true; }; diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index ac26b842b..a08eb2422 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -46,9 +46,9 @@ TEST (ledger, genesis_balance) auto & ledger = ctx.ledger (); auto & store = ctx.store (); auto transaction = store.tx_begin_write (); - auto balance = ledger.account_balance (transaction, nano::dev::genesis->account ()); + auto balance = ledger.account_balance (transaction, nano::dev::genesis_key.pub); ASSERT_EQ (nano::dev::constants.genesis_amount, balance); - auto info = ledger.account_info (transaction, nano::dev::genesis->account ()); + auto info = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info); ASSERT_EQ (1, ledger.cache.account_count); // Frontier time should have been updated when genesis balance was added @@ -56,7 +56,7 @@ TEST (ledger, genesis_balance) ASSERT_LT (nano::seconds_since_epoch () - info->modified, 10); // Genesis block should be confirmed by default nano::confirmation_height_info confirmation_height_info; - ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (), confirmation_height_info)); + ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, confirmation_height_info)); ASSERT_EQ (confirmation_height_info.height, 1); ASSERT_EQ (confirmation_height_info.frontier, nano::dev::genesis->hash ()); } @@ -70,11 +70,11 @@ TEST (ledger, process_modifies_sideband) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -113,7 +113,7 @@ TEST (ledger, process_send) ASSERT_TRUE (store.frontier.get (transaction, info1->head).is_zero ()); ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, hash1)); ASSERT_EQ (nano::block_status::progress, return1); - ASSERT_EQ (nano::dev::genesis_key.pub, ledger.account (*send)); + ASSERT_EQ (nano::dev::genesis_key.pub, send->account ()); ASSERT_EQ (50, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_receivable (transaction, key2.pub)); auto info2 = ledger.account_info (transaction, nano::dev::genesis_key.pub); @@ -142,7 +142,7 @@ TEST (ledger, process_send) ASSERT_EQ (1, open->sideband ().height); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.amount (transaction, hash2)); ASSERT_EQ (nano::block_status::progress, return2); - ASSERT_EQ (key2.pub, ledger.account (*open)); + ASSERT_EQ (key2.pub, open->account ()); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.amount (transaction, hash2)); ASSERT_EQ (key2.pub, store.frontier.get (transaction, hash2)); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_balance (transaction, key2.pub)); @@ -226,7 +226,7 @@ TEST (ledger, process_receive) nano::block_hash hash2 (open->hash ()); auto return1 = ledger.process (transaction, open); ASSERT_EQ (nano::block_status::progress, return1); - ASSERT_EQ (key2.pub, ledger.account (*open)); + ASSERT_EQ (key2.pub, open->account ()); ASSERT_EQ (key2.pub, open->sideband ().account); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, open->sideband ().balance.number ()); ASSERT_EQ (1, open->sideband ().height); @@ -259,7 +259,7 @@ TEST (ledger, process_receive) ASSERT_TRUE (store.frontier.get (transaction, hash2).is_zero ()); ASSERT_EQ (key2.pub, store.frontier.get (transaction, hash4)); ASSERT_EQ (nano::block_status::progress, return2); - ASSERT_EQ (key2.pub, ledger.account (*receive)); + ASSERT_EQ (key2.pub, receive->account ()); ASSERT_EQ (hash4, ledger.latest (transaction, key2.pub)); ASSERT_EQ (25, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (0, ledger.account_receivable (transaction, key2.pub)); @@ -497,7 +497,7 @@ TEST (ledger, weight) { auto ctx = nano::test::context::ledger_empty (); auto & ledger = ctx.ledger (); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); } TEST (ledger, representative_change) @@ -526,7 +526,7 @@ TEST (ledger, representative_change) ASSERT_TRUE (store.frontier.get (transaction, info1->head).is_zero ()); ASSERT_EQ (nano::dev::genesis_key.pub, store.frontier.get (transaction, block->hash ())); ASSERT_EQ (nano::block_status::progress, return1); - ASSERT_EQ (nano::dev::genesis_key.pub, ledger.account (*block)); + ASSERT_EQ (nano::dev::genesis_key.pub, block->account ()); ASSERT_EQ (0, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (key2.pub)); auto info2 = ledger.account_info (transaction, nano::dev::genesis_key.pub); @@ -2275,7 +2275,7 @@ TEST (ledger, block_destination_source) auto block2 = builder .send () .previous (block1->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (balance) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (block1->hash ())) @@ -2291,9 +2291,9 @@ TEST (ledger, block_destination_source) balance -= nano::Gxrb_ratio; auto block4 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (block3->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (balance) .link (dest.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2302,20 +2302,20 @@ TEST (ledger, block_destination_source) balance -= nano::Gxrb_ratio; auto block5 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (block4->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (balance) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (block4->hash ())) .build (); balance += nano::Gxrb_ratio; auto block6 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (block5->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (balance) .link (block5->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2329,17 +2329,17 @@ TEST (ledger, block_destination_source) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, block6)); ASSERT_EQ (balance, ledger.balance (transaction, block6->hash ())); ASSERT_EQ (dest.pub, ledger.block_destination (transaction, *block1)); - ASSERT_TRUE (ledger.block_source (transaction, *block1).is_zero ()); - ASSERT_EQ (nano::dev::genesis->account (), ledger.block_destination (transaction, *block2)); - ASSERT_TRUE (ledger.block_source (transaction, *block2).is_zero ()); + ASSERT_FALSE (block1->source_field ()); + ASSERT_EQ (nano::dev::genesis_key.pub, ledger.block_destination (transaction, *block2)); + ASSERT_FALSE (block2->source_field ()); ASSERT_EQ (ledger.block_destination (transaction, *block3), nullptr); - ASSERT_EQ (block2->hash (), ledger.block_source (transaction, *block3)); + ASSERT_EQ (block2->hash (), block3->source ()); ASSERT_EQ (dest.pub, ledger.block_destination (transaction, *block4)); - ASSERT_TRUE (ledger.block_source (transaction, *block4).is_zero ()); - ASSERT_EQ (nano::dev::genesis->account (), ledger.block_destination (transaction, *block5)); - ASSERT_TRUE (ledger.block_source (transaction, *block5).is_zero ()); + ASSERT_FALSE (block4->source_field ()); + ASSERT_EQ (nano::dev::genesis_key.pub, ledger.block_destination (transaction, *block5)); + ASSERT_FALSE (block5->source_field ()); ASSERT_EQ (ledger.block_destination (transaction, *block6), nullptr); - ASSERT_EQ (block5->hash (), ledger.block_source (transaction, *block6)); + ASSERT_EQ (block5->hash (), block6->source ()); } TEST (ledger, state_account) @@ -2352,16 +2352,16 @@ TEST (ledger, state_account) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_EQ (nano::dev::genesis->account (), ledger.account (transaction, send1->hash ())); + ASSERT_EQ (nano::dev::genesis_key.pub, ledger.account (transaction, send1->hash ())); } TEST (ledger, state_send_receive) @@ -2374,11 +2374,11 @@ TEST (ledger, state_send_receive) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -2389,17 +2389,17 @@ TEST (ledger, state_send_receive) ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, send1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); - ASSERT_TRUE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); + ASSERT_TRUE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); ASSERT_EQ (2, send2->sideband ().height); - ASSERT_TRUE (send2->sideband ().details.is_send); - ASSERT_FALSE (send2->sideband ().details.is_receive); + ASSERT_TRUE (send2->is_send ()); + ASSERT_FALSE (send2->is_receive ()); ASSERT_FALSE (send2->sideband ().details.is_epoch); auto receive1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (send1->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2412,12 +2412,12 @@ TEST (ledger, state_send_receive) ASSERT_EQ (*receive1, *receive2); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.balance (transaction, receive1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, receive1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); - ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); + ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count); ASSERT_EQ (3, receive2->sideband ().height); - ASSERT_FALSE (receive2->sideband ().details.is_send); - ASSERT_TRUE (receive2->sideband ().details.is_receive); + ASSERT_FALSE (receive2->is_send ()); + ASSERT_TRUE (receive2->is_receive ()); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -2432,7 +2432,7 @@ TEST (ledger, state_receive) auto send1 = builder .send () .previous (nano::dev::genesis->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) @@ -2444,12 +2444,12 @@ TEST (ledger, state_receive) ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, send1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); auto receive1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (send1->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2462,10 +2462,10 @@ TEST (ledger, state_receive) ASSERT_EQ (*receive1, *receive2); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.balance (transaction, receive1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, receive1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (3, receive2->sideband ().height); - ASSERT_FALSE (receive2->sideband ().details.is_send); - ASSERT_TRUE (receive2->sideband ().details.is_receive); + ASSERT_FALSE (receive2->is_send ()); + ASSERT_TRUE (receive2->is_receive ()); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -2480,7 +2480,7 @@ TEST (ledger, state_rep_change) nano::block_builder builder; auto change1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) .representative (rep.pub) .balance (nano::dev::constants.genesis_amount) @@ -2495,11 +2495,11 @@ TEST (ledger, state_rep_change) ASSERT_EQ (*change1, *change2); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.balance (transaction, change1->hash ())); ASSERT_EQ (0, ledger.amount (transaction, change1->hash ())); - ASSERT_EQ (0, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (0, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (rep.pub)); ASSERT_EQ (2, change2->sideband ().height); - ASSERT_FALSE (change2->sideband ().details.is_send); - ASSERT_FALSE (change2->sideband ().details.is_receive); + ASSERT_FALSE (change2->is_send ()); + ASSERT_FALSE (change2->is_receive ()); ASSERT_FALSE (change2->sideband ().details.is_epoch); } @@ -2514,9 +2514,9 @@ TEST (ledger, state_open) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2529,13 +2529,13 @@ TEST (ledger, state_open) ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, send1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_TRUE (store.pending.exists (transaction, nano::pending_key (destination.pub, send1->hash ()))); auto open1 = builder .state () .account (destination.pub) .previous (0) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::Gxrb_ratio) .link (send1->hash ()) .sign (destination.prv, destination.pub) @@ -2549,11 +2549,11 @@ TEST (ledger, state_open) ASSERT_EQ (*open1, *open2); ASSERT_EQ (nano::Gxrb_ratio, ledger.balance (transaction, open1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, open1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (ledger.cache.account_count, store.account.count (transaction)); ASSERT_EQ (1, open2->sideband ().height); - ASSERT_FALSE (open2->sideband ().details.is_send); - ASSERT_TRUE (open2->sideband ().details.is_receive); + ASSERT_FALSE (open2->is_send ()); + ASSERT_TRUE (open2->is_receive ()); ASSERT_FALSE (open2->sideband ().details.is_epoch); } @@ -2568,11 +2568,11 @@ TEST (ledger, send_after_state_fail) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -2580,7 +2580,7 @@ TEST (ledger, send_after_state_fail) auto send2 = builder .send () .previous (send1->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - (2 * nano::Gxrb_ratio)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (send1->hash ())) @@ -2599,11 +2599,11 @@ TEST (ledger, receive_after_state_fail) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -2629,11 +2629,11 @@ TEST (ledger, change_after_state_fail) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -2660,7 +2660,7 @@ TEST (ledger, state_unreceivable_fail) auto send1 = builder .send () .previous (nano::dev::genesis->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) @@ -2672,12 +2672,12 @@ TEST (ledger, state_unreceivable_fail) ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, send1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); auto receive1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (1) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2697,7 +2697,7 @@ TEST (ledger, state_receive_bad_amount_fail) auto send1 = builder .send () .previous (nano::dev::genesis->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) @@ -2709,12 +2709,12 @@ TEST (ledger, state_receive_bad_amount_fail) ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, send1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); auto receive1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (send1->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2733,11 +2733,11 @@ TEST (ledger, state_no_link_amount_fail) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -2745,7 +2745,7 @@ TEST (ledger, state_no_link_amount_fail) nano::keypair rep; auto change1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) .representative (rep.pub) .balance (nano::dev::constants.genesis_amount) @@ -2766,11 +2766,11 @@ TEST (ledger, state_receive_wrong_account_fail) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -2781,13 +2781,13 @@ TEST (ledger, state_receive_wrong_account_fail) ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, send1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); nano::keypair key; auto receive1 = builder .state () .account (key.pub) .previous (0) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::Gxrb_ratio) .link (send1->hash ()) .sign (key.prv, key.pub) @@ -2807,9 +2807,9 @@ TEST (ledger, state_open_state_fork) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2820,7 +2820,7 @@ TEST (ledger, state_open_state_fork) .state () .account (destination.pub) .previous (0) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::Gxrb_ratio) .link (send1->hash ()) .sign (destination.prv, destination.pub) @@ -2830,7 +2830,7 @@ TEST (ledger, state_open_state_fork) auto open2 = builder .open () .source (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (destination.pub) .sign (destination.prv, destination.pub) .work (*pool.generate (destination.pub)) @@ -2850,9 +2850,9 @@ TEST (ledger, state_state_open_fork) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2862,7 +2862,7 @@ TEST (ledger, state_state_open_fork) auto open1 = builder .open () .source (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (destination.pub) .sign (destination.prv, destination.pub) .work (*pool.generate (destination.pub)) @@ -2872,7 +2872,7 @@ TEST (ledger, state_state_open_fork) .state () .account (destination.pub) .previous (0) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::Gxrb_ratio) .link (send1->hash ()) .sign (destination.prv, destination.pub) @@ -2894,9 +2894,9 @@ TEST (ledger, state_open_previous_fail) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2907,7 +2907,7 @@ TEST (ledger, state_open_previous_fail) .state () .account (destination.pub) .previous (1) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::Gxrb_ratio) .link (send1->hash ()) .sign (destination.prv, destination.pub) @@ -2927,9 +2927,9 @@ TEST (ledger, state_open_source_fail) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -2940,7 +2940,7 @@ TEST (ledger, state_open_source_fail) .state () .account (destination.pub) .previous (0) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (0) .link (0) .sign (destination.prv, destination.pub) @@ -2960,11 +2960,11 @@ TEST (ledger, state_send_change) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) .representative (rep.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -2975,11 +2975,11 @@ TEST (ledger, state_send_change) ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, send1->hash ())); - ASSERT_EQ (0, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (0, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (rep.pub)); ASSERT_EQ (2, send2->sideband ().height); - ASSERT_TRUE (send2->sideband ().details.is_send); - ASSERT_FALSE (send2->sideband ().details.is_receive); + ASSERT_TRUE (send2->is_send ()); + ASSERT_FALSE (send2->is_receive ()); ASSERT_FALSE (send2->sideband ().details.is_epoch); } @@ -2993,11 +2993,11 @@ TEST (ledger, state_receive_change) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -3008,11 +3008,11 @@ TEST (ledger, state_receive_change) ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, send1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); nano::keypair rep; auto receive1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) .representative (rep.pub) .balance (nano::dev::constants.genesis_amount) @@ -3027,11 +3027,11 @@ TEST (ledger, state_receive_change) ASSERT_EQ (*receive1, *receive2); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.balance (transaction, receive1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, receive1->hash ())); - ASSERT_EQ (0, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (0, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (rep.pub)); ASSERT_EQ (3, receive2->sideband ().height); - ASSERT_FALSE (receive2->sideband ().details.is_send); - ASSERT_TRUE (receive2->sideband ().details.is_receive); + ASSERT_FALSE (receive2->is_send ()); + ASSERT_TRUE (receive2->is_receive ()); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -3046,9 +3046,9 @@ TEST (ledger, state_open_old) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3058,7 +3058,7 @@ TEST (ledger, state_open_old) auto open1 = builder .open () .source (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (destination.pub) .sign (destination.prv, destination.pub) .work (*pool.generate (destination.pub)) @@ -3066,7 +3066,7 @@ TEST (ledger, state_open_old) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1)); ASSERT_EQ (nano::Gxrb_ratio, ledger.balance (transaction, open1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, open1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); } TEST (ledger, state_receive_old) @@ -3080,9 +3080,9 @@ TEST (ledger, state_receive_old) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3091,9 +3091,9 @@ TEST (ledger, state_receive_old) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - (2 * nano::Gxrb_ratio)) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3103,7 +3103,7 @@ TEST (ledger, state_receive_old) auto open1 = builder .open () .source (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (destination.pub) .sign (destination.prv, destination.pub) .work (*pool.generate (destination.pub)) @@ -3119,7 +3119,7 @@ TEST (ledger, state_receive_old) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); ASSERT_EQ (2 * nano::Gxrb_ratio, ledger.balance (transaction, receive1->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, receive1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); } TEST (ledger, state_rollback_send) @@ -3132,11 +3132,11 @@ TEST (ledger, state_rollback_send) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -3145,17 +3145,17 @@ TEST (ledger, state_rollback_send) auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis->account ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); - auto info = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); + auto info = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info); - ASSERT_EQ (nano::dev::genesis->account (), info->source); + ASSERT_EQ (nano::dev::genesis_key.pub, info->source); ASSERT_EQ (nano::Gxrb_ratio, info->amount.number ()); ASSERT_FALSE (ledger.rollback (transaction, send1->hash ())); ASSERT_FALSE (ledger.block_exists (transaction, send1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); - ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); + ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); ASSERT_TRUE (store.block.successor (transaction, nano::dev::genesis->hash ()).is_zero ()); ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count); } @@ -3170,35 +3170,35 @@ TEST (ledger, state_rollback_receive) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); auto receive1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (send1->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), receive1->hash ()))); + ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, receive1->hash ()))); ASSERT_FALSE (ledger.rollback (transaction, receive1->hash ())); - auto info = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ())); + auto info = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info); - ASSERT_EQ (nano::dev::genesis->account (), info->source); + ASSERT_EQ (nano::dev::genesis_key.pub, info->source); ASSERT_EQ (nano::Gxrb_ratio, info->amount.number ()); ASSERT_FALSE (ledger.block_exists (transaction, receive1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis->account ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count); } @@ -3213,9 +3213,9 @@ TEST (ledger, state_rollback_received_send) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3233,13 +3233,13 @@ TEST (ledger, state_rollback_received_send) .work (*pool.generate (key.pub)) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), receive1->hash ()))); + ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, receive1->hash ()))); ASSERT_FALSE (ledger.rollback (transaction, send1->hash ())); - ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); ASSERT_FALSE (ledger.block_exists (transaction, send1->hash ())); ASSERT_FALSE (ledger.block_exists (transaction, receive1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (0, ledger.account_balance (transaction, key.pub)); ASSERT_EQ (0, ledger.weight (key.pub)); ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count); @@ -3256,7 +3256,7 @@ TEST (ledger, state_rep_change_rollback) nano::block_builder builder; auto change1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) .representative (rep.pub) .balance (nano::dev::constants.genesis_amount) @@ -3267,8 +3267,8 @@ TEST (ledger, state_rep_change_rollback) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, change1)); ASSERT_FALSE (ledger.rollback (transaction, change1->hash ())); ASSERT_FALSE (ledger.block_exists (transaction, change1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (0, ledger.weight (rep.pub)); } @@ -3283,9 +3283,9 @@ TEST (ledger, state_open_rollback) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3296,7 +3296,7 @@ TEST (ledger, state_open_rollback) .state () .account (destination.pub) .previous (0) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::Gxrb_ratio) .link (send1->hash ()) .sign (destination.prv, destination.pub) @@ -3306,10 +3306,10 @@ TEST (ledger, state_open_rollback) ASSERT_FALSE (ledger.rollback (transaction, open1->hash ())); ASSERT_FALSE (ledger.block_exists (transaction, open1->hash ())); ASSERT_EQ (0, ledger.account_balance (transaction, destination.pub)); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); auto info = ledger.pending_info (transaction, nano::pending_key (destination.pub, send1->hash ())); ASSERT_TRUE (info); - ASSERT_EQ (nano::dev::genesis->account (), info->source); + ASSERT_EQ (nano::dev::genesis_key.pub, info->source); ASSERT_EQ (nano::Gxrb_ratio, info->amount.number ()); ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count); } @@ -3325,19 +3325,19 @@ TEST (ledger, state_send_change_rollback) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) .representative (rep.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_FALSE (ledger.rollback (transaction, send1->hash ())); ASSERT_FALSE (ledger.block_exists (transaction, send1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ())); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (0, ledger.weight (rep.pub)); ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count); } @@ -3352,11 +3352,11 @@ TEST (ledger, state_receive_change_rollback) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -3364,7 +3364,7 @@ TEST (ledger, state_receive_change_rollback) nano::keypair rep; auto receive1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) .representative (rep.pub) .balance (nano::dev::constants.genesis_amount) @@ -3375,8 +3375,8 @@ TEST (ledger, state_receive_change_rollback) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); ASSERT_FALSE (ledger.rollback (transaction, receive1->hash ())); ASSERT_FALSE (ledger.block_exists (transaction, receive1->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis->account ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (0, ledger.weight (rep.pub)); ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count); } @@ -3392,75 +3392,75 @@ TEST (ledger, epoch_blocks_v1_general) nano::block_builder builder; auto epoch1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_1)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, epoch1)); - ASSERT_FALSE (epoch1->sideband ().details.is_send); - ASSERT_FALSE (epoch1->sideband ().details.is_receive); + ASSERT_FALSE (epoch1->is_send ()); + ASSERT_FALSE (epoch1->is_receive ()); ASSERT_TRUE (epoch1->sideband ().details.is_epoch); ASSERT_EQ (nano::epoch::epoch_1, epoch1->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_0, epoch1->sideband ().source_epoch); // Not used for epoch blocks auto epoch2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (epoch1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_1)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (epoch1->hash ())) .build (); ASSERT_EQ (nano::block_status::block_position, ledger.process (transaction, epoch2)); - auto genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ()); + auto genesis_info = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (genesis_info); ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_1); ASSERT_FALSE (ledger.rollback (transaction, epoch1->hash ())); - genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ()); + genesis_info = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (genesis_info); ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_0); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, epoch1)); - genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ()); + genesis_info = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (genesis_info); ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_1); - ASSERT_FALSE (epoch1->sideband ().details.is_send); - ASSERT_FALSE (epoch1->sideband ().details.is_receive); + ASSERT_FALSE (epoch1->is_send ()); + ASSERT_FALSE (epoch1->is_receive ()); ASSERT_TRUE (epoch1->sideband ().details.is_epoch); ASSERT_EQ (nano::epoch::epoch_1, epoch1->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_0, epoch1->sideband ().source_epoch); // Not used for epoch blocks auto change1 = builder .change () .previous (epoch1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (epoch1->hash ())) .build (); ASSERT_EQ (nano::block_status::block_position, ledger.process (transaction, change1)); auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (epoch1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (epoch1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (send1->sideband ().details.is_send); - ASSERT_FALSE (send1->sideband ().details.is_receive); + ASSERT_TRUE (send1->is_send ()); + ASSERT_FALSE (send1->is_receive ()); ASSERT_FALSE (send1->sideband ().details.is_epoch); ASSERT_EQ (nano::epoch::epoch_1, send1->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_0, send1->sideband ().source_epoch); // Not used for send blocks auto open1 = builder .open () .source (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (destination.pub) .sign (destination.prv, destination.pub) .work (*pool.generate (destination.pub)) @@ -3470,7 +3470,7 @@ TEST (ledger, epoch_blocks_v1_general) .state () .account (destination.pub) .previous (0) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (0) .link (ledger.epoch_link (nano::epoch::epoch_1)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3488,8 +3488,8 @@ TEST (ledger, epoch_blocks_v1_general) .work (*pool.generate (destination.pub)) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, epoch4)); - ASSERT_FALSE (epoch4->sideband ().details.is_send); - ASSERT_FALSE (epoch4->sideband ().details.is_receive); + ASSERT_FALSE (epoch4->is_send ()); + ASSERT_FALSE (epoch4->is_receive ()); ASSERT_TRUE (epoch4->sideband ().details.is_epoch); ASSERT_EQ (nano::epoch::epoch_1, epoch4->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_0, epoch4->sideband ().source_epoch); // Not used for epoch blocks @@ -3517,10 +3517,10 @@ TEST (ledger, epoch_blocks_v1_general) ASSERT_EQ (0, ledger.balance (transaction, epoch4->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.balance (transaction, receive2->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, receive2->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (nano::Gxrb_ratio, ledger.weight (destination.pub)); - ASSERT_FALSE (receive2->sideband ().details.is_send); - ASSERT_TRUE (receive2->sideband ().details.is_receive); + ASSERT_FALSE (receive2->is_send ()); + ASSERT_TRUE (receive2->is_receive ()); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -3535,9 +3535,9 @@ TEST (ledger, epoch_blocks_v2_general) nano::block_builder builder; auto epoch1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_2)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3548,9 +3548,9 @@ TEST (ledger, epoch_blocks_v2_general) // Set it to the first epoch and it should now succeed epoch1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_1)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3561,9 +3561,9 @@ TEST (ledger, epoch_blocks_v2_general) ASSERT_EQ (nano::epoch::epoch_0, epoch1->sideband ().source_epoch); // Not used for epoch blocks auto epoch2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (epoch1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_2)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3574,39 +3574,39 @@ TEST (ledger, epoch_blocks_v2_general) ASSERT_EQ (nano::epoch::epoch_0, epoch2->sideband ().source_epoch); // Not used for epoch blocks auto epoch3 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (epoch2->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_2)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (epoch2->hash ())) .build (); ASSERT_EQ (nano::block_status::block_position, ledger.process (transaction, epoch3)); - auto genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ()); + auto genesis_info = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (genesis_info); ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_2); ASSERT_FALSE (ledger.rollback (transaction, epoch1->hash ())); - genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ()); + genesis_info = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (genesis_info); ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_0); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, epoch1)); - genesis_info = ledger.account_info (transaction, nano::dev::genesis->account ()); + genesis_info = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (genesis_info); ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_1); auto change1 = builder .change () .previous (epoch1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (epoch1->hash ())) .build (); ASSERT_EQ (nano::block_status::block_position, ledger.process (transaction, change1)); auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (epoch1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3618,7 +3618,7 @@ TEST (ledger, epoch_blocks_v2_general) auto open1 = builder .open () .source (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (destination.pub) .sign (destination.prv, destination.pub) .work (*pool.generate (destination.pub)) @@ -3641,7 +3641,7 @@ TEST (ledger, epoch_blocks_v2_general) .state () .account (destination.pub) .previous (epoch4->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (0) .link (ledger.epoch_link (nano::epoch::epoch_2)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3685,7 +3685,7 @@ TEST (ledger, epoch_blocks_v2_general) ASSERT_EQ (0, ledger.balance (transaction, epoch6->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.balance (transaction, receive2->hash ())); ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, receive2->hash ())); - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (nano::Gxrb_ratio, ledger.weight (destination.pub)); } @@ -3700,9 +3700,9 @@ TEST (ledger, epoch_blocks_receive_upgrade) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3711,9 +3711,9 @@ TEST (ledger, epoch_blocks_receive_upgrade) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); auto epoch1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (ledger.epoch_link (nano::epoch::epoch_1)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3722,9 +3722,9 @@ TEST (ledger, epoch_blocks_receive_upgrade) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, epoch1)); auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (epoch1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3808,9 +3808,9 @@ TEST (ledger, epoch_blocks_receive_upgrade) nano::keypair destination3; auto epoch2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send2->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) .link (ledger.epoch_link (nano::epoch::epoch_2)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3819,9 +3819,9 @@ TEST (ledger, epoch_blocks_receive_upgrade) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, epoch2)); auto send4 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (epoch2->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 3) .link (destination3.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3840,9 +3840,9 @@ TEST (ledger, epoch_blocks_receive_upgrade) // Send it to an epoch 1 account auto send5 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send4->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 4) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3872,9 +3872,9 @@ TEST (ledger, epoch_blocks_receive_upgrade) nano::keypair destination4; auto send6 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send5->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 5) .link (destination4.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3917,9 +3917,9 @@ TEST (ledger, epoch_blocks_fork) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); auto epoch1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_1)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3928,9 +3928,9 @@ TEST (ledger, epoch_blocks_fork) ASSERT_EQ (nano::block_status::fork, ledger.process (transaction, epoch1)); auto epoch2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_2)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3939,9 +3939,9 @@ TEST (ledger, epoch_blocks_fork) ASSERT_EQ (nano::block_status::fork, ledger.process (transaction, epoch2)); auto epoch3 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_1)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3952,9 +3952,9 @@ TEST (ledger, epoch_blocks_fork) ASSERT_EQ (nano::epoch::epoch_0, epoch3->sideband ().source_epoch); // Not used for epoch state blocks auto epoch4 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_2)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4052,14 +4052,14 @@ TEST (ledger, epoch_open_pending) ASSERT_TIMELY_EQ (10s, 1, node1.unchecked.count ()); ASSERT_FALSE (node1.ledger.block_or_pruned_exists (epoch_open->hash ())); // Open block should be inserted into unchecked - auto blocks = node1.unchecked.get (nano::hash_or_account (epoch_open->account ()).hash); + auto blocks = node1.unchecked.get (nano::hash_or_account (epoch_open->account_field ().value ()).hash); ASSERT_EQ (blocks.size (), 1); ASSERT_EQ (blocks[0].block->full_hash (), epoch_open->full_hash ()); // New block to process epoch open auto send1 = builder.state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 100) .link (key1.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4083,9 +4083,9 @@ TEST (ledger, block_hash_account_conflict) * in the ledger and not an account */ auto send1 = builder.state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 100) .link (key1.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4095,7 +4095,7 @@ TEST (ledger, block_hash_account_conflict) auto receive1 = builder.state () .account (key1.pub) .previous (0) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (100) .link (send1->hash ()) .sign (key1.prv, key1.pub) @@ -4111,7 +4111,7 @@ TEST (ledger, block_hash_account_conflict) auto send2 = builder.state () .account (key1.pub) .previous (receive1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (90) .link (receive1->hash ()) .sign (key1.prv, key1.pub) @@ -4167,9 +4167,9 @@ TEST (ledger, unchecked_epoch) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4227,9 +4227,9 @@ TEST (ledger, unchecked_epoch_invalid) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4295,9 +4295,9 @@ TEST (ledger, unchecked_epoch_invalid) auto epoch2_store = node1.ledger.block (transaction, epoch2->hash ()); ASSERT_NE (nullptr, epoch2_store); ASSERT_EQ (nano::epoch::epoch_0, epoch2_store->sideband ().details.epoch); - ASSERT_TRUE (epoch2_store->sideband ().details.is_send); + ASSERT_TRUE (epoch2_store->is_send ()); ASSERT_FALSE (epoch2_store->sideband ().details.is_epoch); - ASSERT_FALSE (epoch2_store->sideband ().details.is_receive); + ASSERT_FALSE (epoch2_store->is_receive ()); } } @@ -4309,9 +4309,9 @@ TEST (ledger, unchecked_open) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4344,7 +4344,7 @@ TEST (ledger, unchecked_open) // Waits for the last blocks to pass through block_processor and unchecked.put queues ASSERT_TIMELY_EQ (10s, 1, node1.unchecked.count ()); // Get the next peer for attempting a tcp bootstrap connection - auto blocks = node1.unchecked.get (open1->source ()); + auto blocks = node1.unchecked.get (open1->source_field ().value ()); ASSERT_EQ (blocks.size (), 1); } node1.block_processor.add (send1); @@ -4361,9 +4361,9 @@ TEST (ledger, unchecked_receive) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4372,9 +4372,9 @@ TEST (ledger, unchecked_receive) node1.work_generate_blocking (*send1); auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 2 * nano::Gxrb_ratio) .link (destination.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4412,11 +4412,11 @@ TEST (ledger, unchecked_receive) } // Waits for the open1 block to pass through block_processor and unchecked.put queues node1.block_processor.add (open1); - ASSERT_TIMELY (15s, check_block_is_listed (node1.store.tx_begin_read (), receive1->source ())); + ASSERT_TIMELY (15s, check_block_is_listed (node1.store.tx_begin_read (), receive1->source_field ().value ())); // Previous block for receive1 is known, signature was validated { auto transaction = node1.store.tx_begin_read (); - auto blocks (node1.unchecked.get (receive1->source ())); + auto blocks (node1.unchecked.get (receive1->source_field ().value ())); ASSERT_EQ (blocks.size (), 1); } node1.block_processor.add (send2); @@ -4444,17 +4444,17 @@ TEST (ledger, confirmation_height_not_updated) .work (*pool.generate (account_info->head)) .build (); nano::confirmation_height_info confirmation_height_info; - ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (), confirmation_height_info)); + ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, confirmation_height_info)); ASSERT_EQ (1, confirmation_height_info.height); ASSERT_EQ (nano::dev::genesis->hash (), confirmation_height_info.frontier); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis->account (), confirmation_height_info)); + ASSERT_FALSE (store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, confirmation_height_info)); ASSERT_EQ (1, confirmation_height_info.height); ASSERT_EQ (nano::dev::genesis->hash (), confirmation_height_info.frontier); auto open1 = builder .open () .source (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key.pub) .sign (key.prv, key.pub) .work (*pool.generate (key.pub)) @@ -4597,9 +4597,9 @@ TEST (ledger, dependents_confirmed) nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key1; auto send1 = builder.state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 100) .link (key1.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4608,9 +4608,9 @@ TEST (ledger, dependents_confirmed) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (ledger.dependents_confirmed (transaction, *send1)); auto send2 = builder.state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 200) .link (key1.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4621,7 +4621,7 @@ TEST (ledger, dependents_confirmed) auto receive1 = builder.state () .account (key1.pub) .previous (0) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (100) .link (send1->hash ()) .sign (key1.prv, key1.pub) @@ -4630,14 +4630,14 @@ TEST (ledger, dependents_confirmed) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); ASSERT_FALSE (ledger.dependents_confirmed (transaction, *receive1)); nano::confirmation_height_info height; - ASSERT_FALSE (ledger.store.confirmation_height.get (transaction, nano::dev::genesis->account (), height)); + ASSERT_FALSE (ledger.store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, height)); height.height += 1; - ledger.store.confirmation_height.put (transaction, nano::dev::genesis->account (), height); + ledger.store.confirmation_height.put (transaction, nano::dev::genesis_key.pub, height); ASSERT_TRUE (ledger.dependents_confirmed (transaction, *receive1)); auto receive2 = builder.state () .account (key1.pub) .previous (receive1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (200) .link (send2->hash ()) .sign (key1.prv, key1.pub) @@ -4649,9 +4649,9 @@ TEST (ledger, dependents_confirmed) height.height += 1; ledger.store.confirmation_height.put (transaction, key1.pub, height); ASSERT_FALSE (ledger.dependents_confirmed (transaction, *receive2)); - ASSERT_FALSE (ledger.store.confirmation_height.get (transaction, nano::dev::genesis->account (), height)); + ASSERT_FALSE (ledger.store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, height)); height.height += 1; - ledger.store.confirmation_height.put (transaction, nano::dev::genesis->account (), height); + ledger.store.confirmation_height.put (transaction, nano::dev::genesis_key.pub, height); ASSERT_TRUE (ledger.dependents_confirmed (transaction, *receive2)); } @@ -4669,9 +4669,9 @@ TEST (ledger, dependents_confirmed_pruning) nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key1; auto send1 = builder.state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 100) .link (key1.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4679,9 +4679,9 @@ TEST (ledger, dependents_confirmed_pruning) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); auto send2 = builder.state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 200) .link (key1.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4689,15 +4689,15 @@ TEST (ledger, dependents_confirmed_pruning) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send2)); nano::confirmation_height_info height; - ASSERT_FALSE (ledger.store.confirmation_height.get (transaction, nano::dev::genesis->account (), height)); + ASSERT_FALSE (ledger.store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, height)); height.height = 3; - ledger.store.confirmation_height.put (transaction, nano::dev::genesis->account (), height); + ledger.store.confirmation_height.put (transaction, nano::dev::genesis_key.pub, height); ASSERT_TRUE (ledger.block_confirmed (transaction, send1->hash ())); ASSERT_EQ (2, ledger.pruning_action (transaction, send2->hash (), 1)); auto receive1 = builder.state () .account (key1.pub) .previous (0) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (100) .link (send1->hash ()) .sign (key1.prv, key1.pub) @@ -4717,9 +4717,9 @@ TEST (ledger, block_confirmed) nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair key1; auto send1 = builder.state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 100) .link (key1.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4730,9 +4730,9 @@ TEST (ledger, block_confirmed) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_FALSE (ledger.block_confirmed (transaction, send1->hash ())); nano::confirmation_height_info height; - ASSERT_FALSE (ledger.store.confirmation_height.get (transaction, nano::dev::genesis->account (), height)); + ASSERT_FALSE (ledger.store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, height)); ++height.height; - ledger.store.confirmation_height.put (transaction, nano::dev::genesis->account (), height); + ledger.store.confirmation_height.put (transaction, nano::dev::genesis_key.pub, height); ASSERT_TRUE (ledger.block_confirmed (transaction, send1->hash ())); } @@ -4760,16 +4760,16 @@ TEST (ledger, cache) ASSERT_EQ (account_count, cache_a.account_count); ASSERT_EQ (block_count, cache_a.block_count); ASSERT_EQ (cemented_count, cache_a.cemented_count); - ASSERT_EQ (genesis_weight, cache_a.rep_weights.representation_get (nano::dev::genesis->account ())); + ASSERT_EQ (genesis_weight, cache_a.rep_weights.representation_get (nano::dev::genesis_key.pub)); ASSERT_EQ (pruned_count, cache_a.pruned_count); }; nano::keypair key; - auto const latest = ledger.latest (store.tx_begin_read (), nano::dev::genesis->account ()); + auto const latest = ledger.latest (store.tx_begin_read (), nano::dev::genesis_key.pub); auto send = builder.state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (latest) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - (i + 1)) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4807,10 +4807,10 @@ TEST (ledger, cache) { auto transaction (store.tx_begin_write ()); nano::confirmation_height_info height; - ASSERT_FALSE (ledger.store.confirmation_height.get (transaction, nano::dev::genesis->account (), height)); + ASSERT_FALSE (ledger.store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, height)); ++height.height; height.frontier = send->hash (); - ledger.store.confirmation_height.put (transaction, nano::dev::genesis->account (), height); + ledger.store.confirmation_height.put (transaction, nano::dev::genesis_key.pub, height); ASSERT_TRUE (ledger.block_confirmed (transaction, send->hash ())); ++ledger.cache.cemented_count; } @@ -4859,11 +4859,11 @@ TEST (ledger, pruning_action) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -4872,14 +4872,14 @@ TEST (ledger, pruning_action) auto send1_stored (store->block.get (transaction, send1->hash ())); ASSERT_NE (nullptr, send1_stored); ASSERT_EQ (*send1, *send1_stored); - ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (send1->hash ())) .build (); @@ -4888,7 +4888,7 @@ TEST (ledger, pruning_action) // Pruning action ASSERT_EQ (1, ledger.pruning_action (transaction, send1->hash (), 1)); ASSERT_EQ (0, ledger.pruning_action (transaction, nano::dev::genesis->hash (), 1)); - ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); ASSERT_FALSE (store->block.exists (transaction, send1->hash ())); ASSERT_TRUE (ledger.block_or_pruned_exists (transaction, send1->hash ())); // Pruned ledger start without proper flags emulation @@ -4901,9 +4901,9 @@ TEST (ledger, pruning_action) // Receiving pruned block auto receive1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send2->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (send1->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4914,10 +4914,10 @@ TEST (ledger, pruning_action) auto receive1_stored (store->block.get (transaction, receive1->hash ())); ASSERT_NE (nullptr, receive1_stored); ASSERT_EQ (*receive1, *receive1_stored); - ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); ASSERT_EQ (4, receive1_stored->sideband ().height); - ASSERT_FALSE (receive1_stored->sideband ().details.is_send); - ASSERT_TRUE (receive1_stored->sideband ().details.is_receive); + ASSERT_FALSE (receive1_stored->is_send ()); + ASSERT_TRUE (receive1_stored->is_receive ()); ASSERT_FALSE (receive1_stored->sideband ().details.is_epoch); // Middle block pruning ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); @@ -4947,11 +4947,11 @@ TEST (ledger, pruning_large_chain) { auto send = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (last_hash) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (last_hash)) .build (); @@ -4959,9 +4959,9 @@ TEST (ledger, pruning_large_chain) ASSERT_TRUE (store->block.exists (transaction, send->hash ())); auto receive = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (send->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4998,9 +4998,9 @@ TEST (ledger, pruning_source_rollback) nano::block_builder builder; auto epoch1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (ledger.epoch_link (nano::epoch::epoch_1)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -5009,23 +5009,23 @@ TEST (ledger, pruning_source_rollback) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, epoch1)); auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (epoch1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (epoch1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (send1->hash ())) .build (); @@ -5038,36 +5038,36 @@ TEST (ledger, pruning_source_rollback) ASSERT_FALSE (store->block.exists (transaction, epoch1->hash ())); ASSERT_TRUE (store->pruned.exists (transaction, epoch1->hash ())); ASSERT_TRUE (store->block.exists (transaction, nano::dev::genesis->hash ())); - auto info = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ())); + auto info = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info); - ASSERT_EQ (nano::dev::genesis->account (), info->source); + ASSERT_EQ (nano::dev::genesis_key.pub, info->source); ASSERT_EQ (nano::Gxrb_ratio, info->amount.number ()); ASSERT_EQ (nano::epoch::epoch_1, info->epoch); // Receiving pruned block auto receive1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send2->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (send1->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (send2->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); ASSERT_EQ (2, ledger.cache.pruned_count); ASSERT_EQ (5, ledger.cache.block_count); // Rollback receive block ASSERT_FALSE (ledger.rollback (transaction, receive1->hash ())); - auto info2 = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ())); + auto info2 = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info2); - ASSERT_NE (nano::dev::genesis->account (), info2->source); // Tradeoff to not store pruned blocks accounts + ASSERT_NE (nano::dev::genesis_key.pub, info2->source); // Tradeoff to not store pruned blocks accounts ASSERT_EQ (nano::Gxrb_ratio, info2->amount.number ()); ASSERT_EQ (nano::epoch::epoch_1, info2->epoch); // Process receive block again ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); ASSERT_EQ (2, ledger.cache.pruned_count); ASSERT_EQ (5, ledger.cache.block_count); } @@ -5087,13 +5087,13 @@ TEST (ledger, pruning_source_rollback_legacy) auto send1 = builder .send () .previous (nano::dev::genesis->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); nano::keypair key1; auto send2 = builder .send () @@ -5109,14 +5109,14 @@ TEST (ledger, pruning_source_rollback_legacy) auto send3 = builder .send () .previous (send2->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 3 * nano::Gxrb_ratio) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (send2->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send3)); ASSERT_TRUE (store->block.exists (transaction, send3->hash ())); - ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send3->hash ()))); + ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send3->hash ()))); // Pruning action ASSERT_EQ (2, ledger.pruning_action (transaction, send2->hash (), 1)); ASSERT_FALSE (store->block.exists (transaction, send2->hash ())); @@ -5124,14 +5124,14 @@ TEST (ledger, pruning_source_rollback_legacy) ASSERT_FALSE (store->block.exists (transaction, send1->hash ())); ASSERT_TRUE (store->pruned.exists (transaction, send1->hash ())); ASSERT_TRUE (store->block.exists (transaction, nano::dev::genesis->hash ())); - auto info1 = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ())); + auto info1 = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info1); - ASSERT_EQ (nano::dev::genesis->account (), info1->source); + ASSERT_EQ (nano::dev::genesis_key.pub, info1->source); ASSERT_EQ (nano::Gxrb_ratio, info1->amount.number ()); ASSERT_EQ (nano::epoch::epoch_0, info1->epoch); auto info2 = ledger.pending_info (transaction, nano::pending_key (key1.pub, send2->hash ())); ASSERT_TRUE (info2); - ASSERT_EQ (nano::dev::genesis->account (), info2->source); + ASSERT_EQ (nano::dev::genesis_key.pub, info2->source); ASSERT_EQ (nano::Gxrb_ratio, info2->amount.number ()); ASSERT_EQ (nano::epoch::epoch_0, info2->epoch); // Receiving pruned block @@ -5143,26 +5143,26 @@ TEST (ledger, pruning_source_rollback_legacy) .work (*pool.generate (send3->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); ASSERT_EQ (2, ledger.cache.pruned_count); ASSERT_EQ (5, ledger.cache.block_count); // Rollback receive block ASSERT_FALSE (ledger.rollback (transaction, receive1->hash ())); - auto info3 = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ())); + auto info3 = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info3); - ASSERT_NE (nano::dev::genesis->account (), info3->source); // Tradeoff to not store pruned blocks accounts + ASSERT_NE (nano::dev::genesis_key.pub, info3->source); // Tradeoff to not store pruned blocks accounts ASSERT_EQ (nano::Gxrb_ratio, info3->amount.number ()); ASSERT_EQ (nano::epoch::epoch_0, info3->epoch); // Process receive block again ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); ASSERT_EQ (2, ledger.cache.pruned_count); ASSERT_EQ (5, ledger.cache.block_count); // Receiving pruned block (open) auto open1 = builder .open () .source (send2->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key1.pub) .sign (key1.prv, key1.pub) .work (*pool.generate (key1.pub)) @@ -5175,7 +5175,7 @@ TEST (ledger, pruning_source_rollback_legacy) ASSERT_FALSE (ledger.rollback (transaction, open1->hash ())); auto info4 = ledger.pending_info (transaction, nano::pending_key (key1.pub, send2->hash ())); ASSERT_TRUE (info4); - ASSERT_NE (nano::dev::genesis->account (), info4->source); // Tradeoff to not store pruned blocks accounts + ASSERT_NE (nano::dev::genesis_key.pub, info4->source); // Tradeoff to not store pruned blocks accounts ASSERT_EQ (nano::Gxrb_ratio, info4->amount.number ()); ASSERT_EQ (nano::epoch::epoch_0, info4->epoch); // Process open block again @@ -5199,11 +5199,11 @@ TEST (ledger, pruning_process_error) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -5219,11 +5219,11 @@ TEST (ledger, pruning_process_error) // Attept to process new block after pruned auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (send1->hash ())) .build (); @@ -5248,13 +5248,13 @@ TEST (ledger, pruning_legacy_blocks) auto send1 = builder .send () .previous (nano::dev::genesis->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); + ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()))); auto receive1 = builder .receive () .previous (send1->hash ()) @@ -5283,7 +5283,7 @@ TEST (ledger, pruning_legacy_blocks) auto open1 = builder .open () .source (send2->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key1.pub) .sign (key1.prv, key1.pub) .work (*pool.generate (key1.pub)) @@ -5292,7 +5292,7 @@ TEST (ledger, pruning_legacy_blocks) auto send3 = builder .send () .previous (open1->hash ()) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (0) .sign (key1.prv, key1.pub) .work (*pool.generate (open1->hash ())) @@ -5332,11 +5332,11 @@ TEST (ledger, pruning_safe_functions) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -5344,11 +5344,11 @@ TEST (ledger, pruning_safe_functions) ASSERT_TRUE (store->block.exists (transaction, send1->hash ())); auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (send1->hash ())) .build (); @@ -5366,7 +5366,7 @@ TEST (ledger, pruning_safe_functions) ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2, ledger.balance (transaction, send2->hash ()).value ()); ASSERT_FALSE (ledger.amount (transaction, send2->hash ())); ASSERT_FALSE (ledger.account (transaction, send1->hash ())); - ASSERT_EQ (nano::dev::genesis->account (), ledger.account (transaction, send2->hash ()).value ()); + ASSERT_EQ (nano::dev::genesis_key.pub, ledger.account (transaction, send2->hash ()).value ()); } TEST (ledger, hash_root_random) @@ -5383,11 +5383,11 @@ TEST (ledger, hash_root_random) nano::block_builder builder; auto send1 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); @@ -5395,11 +5395,11 @@ TEST (ledger, hash_root_random) ASSERT_TRUE (store->block.exists (transaction, send1->hash ())); auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*pool.generate (send1->hash ())) .build (); @@ -5461,13 +5461,13 @@ TEST (ledger, migrate_lmdb_to_rocksdb) ASSERT_FALSE (store.init_error ()); // Lower the database to the max version unsupported for upgrades - store.confirmation_height.put (transaction, nano::dev::genesis->account (), { 2, send->hash () }); + store.confirmation_height.put (transaction, nano::dev::genesis_key.pub, { 2, send->hash () }); store.online_weight.put (transaction, 100, nano::amount (2)); store.frontier.put (transaction, nano::block_hash (2), nano::account (5)); store.peer.put (transaction, endpoint_key); - store.pending.put (transaction, nano::pending_key (nano::dev::genesis->account (), send->hash ()), nano::pending_info (nano::dev::genesis->account (), 100, nano::epoch::epoch_0)); + store.pending.put (transaction, nano::pending_key (nano::dev::genesis_key.pub, send->hash ()), nano::pending_info (nano::dev::genesis_key.pub, 100, nano::epoch::epoch_0)); store.pruned.put (transaction, send->hash ()); store.version.put (transaction, version); send->sideband_set ({}); @@ -5482,7 +5482,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb) auto rocksdb_transaction (rocksdb_store.tx_begin_read ()); nano::pending_info pending_info{}; - ASSERT_FALSE (rocksdb_store.pending.get (rocksdb_transaction, nano::pending_key (nano::dev::genesis->account (), send->hash ()), pending_info)); + ASSERT_FALSE (rocksdb_store.pending.get (rocksdb_transaction, nano::pending_key (nano::dev::genesis_key.pub, send->hash ()), pending_info)); for (auto i = rocksdb_store.online_weight.begin (rocksdb_transaction); i != rocksdb_store.online_weight.end (); ++i) { @@ -5499,7 +5499,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb) ASSERT_EQ (rocksdb_store.version.get (rocksdb_transaction), version); ASSERT_EQ (rocksdb_store.frontier.get (rocksdb_transaction, 2), 5); nano::confirmation_height_info confirmation_height_info; - ASSERT_FALSE (rocksdb_store.confirmation_height.get (rocksdb_transaction, nano::dev::genesis->account (), confirmation_height_info)); + ASSERT_FALSE (rocksdb_store.confirmation_height.get (rocksdb_transaction, nano::dev::genesis_key.pub, confirmation_height_info)); ASSERT_EQ (confirmation_height_info.height, 2); ASSERT_EQ (confirmation_height_info.frontier, send->hash ()); ASSERT_EQ (rocksdb_store.final_vote.get (rocksdb_transaction, nano::root (send->previous ())).size (), 1); @@ -5518,11 +5518,11 @@ TEST (ledger, unconfirmed_frontiers) nano::state_block_builder builder; nano::keypair key; - auto const latest = ledger.latest (store.tx_begin_read (), nano::dev::genesis->account ()); + auto const latest = ledger.latest (store.tx_begin_read (), nano::dev::genesis_key.pub); auto send = builder.make_block () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (latest) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - 100) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -5534,7 +5534,7 @@ TEST (ledger, unconfirmed_frontiers) unconfirmed_frontiers = ledger.unconfirmed_frontiers (); ASSERT_EQ (unconfirmed_frontiers.size (), 1); ASSERT_EQ (unconfirmed_frontiers.begin ()->first, 1); - nano::uncemented_info uncemented_info1{ latest, send->hash (), nano::dev::genesis->account () }; + nano::uncemented_info uncemented_info1{ latest, send->hash (), nano::dev::genesis_key.pub }; auto uncemented_info2 = unconfirmed_frontiers.begin ()->second; ASSERT_EQ (uncemented_info1.account, uncemented_info2.account); ASSERT_EQ (uncemented_info1.cemented_frontier, uncemented_info2.cemented_frontier); @@ -5547,7 +5547,7 @@ TEST (ledger, is_send_genesis) auto & ledger = ctx.ledger (); auto & store = ctx.store (); auto tx = store.tx_begin_read (); - ASSERT_FALSE (ledger.is_send (tx, *nano::dev::genesis)); + ASSERT_FALSE (nano::dev::genesis->is_send ()); } TEST (ledger, is_send_state) @@ -5556,8 +5556,8 @@ TEST (ledger, is_send_state) auto & ledger = ctx.ledger (); auto & store = ctx.store (); auto tx = store.tx_begin_read (); - ASSERT_TRUE (ledger.is_send (tx, *ctx.blocks ()[0])); - ASSERT_FALSE (ledger.is_send (tx, *ctx.blocks ()[1])); + ASSERT_TRUE (ctx.blocks ()[0]->is_send ()); + ASSERT_FALSE (ctx.blocks ()[1]->is_send ()); } TEST (ledger, is_send_legacy) @@ -5566,8 +5566,8 @@ TEST (ledger, is_send_legacy) auto & ledger = ctx.ledger (); auto & store = ctx.store (); auto tx = store.tx_begin_read (); - ASSERT_TRUE (ledger.is_send (tx, *ctx.blocks ()[0])); - ASSERT_FALSE (ledger.is_send (tx, *ctx.blocks ()[1])); + ASSERT_TRUE (ctx.blocks ()[0]->is_send ()); + ASSERT_FALSE (ctx.blocks ()[1]->is_send ()); } TEST (ledger, head_block) @@ -5576,5 +5576,5 @@ TEST (ledger, head_block) auto & ledger = ctx.ledger (); auto & store = ctx.store (); auto tx = store.tx_begin_read (); - ASSERT_EQ (*nano::dev::genesis, *ledger.head_block (tx, nano::dev::genesis->account ())); + ASSERT_EQ (*nano::dev::genesis, *ledger.head_block (tx, nano::dev::genesis_key.pub)); } diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index d341b36ed..b1bb5bf5e 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -48,19 +48,19 @@ TEST (node, work_generate) { auto difficulty = nano::difficulty::from_multiplier (1.5, node.network_params.work.base); auto work = node.work_generate_blocking (version, root, difficulty); - ASSERT_TRUE (work.is_initialized ()); - ASSERT_GE (nano::dev::network_params.work.difficulty (version, root, *work), difficulty); + ASSERT_TRUE (work.has_value ()); + ASSERT_GE (nano::dev::network_params.work.difficulty (version, root, work.value ()), difficulty); } { auto difficulty = nano::difficulty::from_multiplier (0.5, node.network_params.work.base); - boost::optional work; + std::optional work; do { work = node.work_generate_blocking (version, root, difficulty); - } while (nano::dev::network_params.work.difficulty (version, root, *work) >= node.network_params.work.base); - ASSERT_TRUE (work.is_initialized ()); - ASSERT_GE (nano::dev::network_params.work.difficulty (version, root, *work), difficulty); - ASSERT_FALSE (nano::dev::network_params.work.difficulty (version, root, *work) >= node.network_params.work.base); + } while (nano::dev::network_params.work.difficulty (version, root, work.value ()) >= node.network_params.work.base); + ASSERT_TRUE (work.has_value ()); + ASSERT_GE (nano::dev::network_params.work.difficulty (version, root, work.value ()), difficulty); + ASSERT_FALSE (nano::dev::network_params.work.difficulty (version, root, work.value ()) >= node.network_params.work.base); } } @@ -1567,7 +1567,7 @@ TEST (node, unconfirmed_send) // firstly, send two units from node1 to node2 and expect that both nodes see the block as confirmed // (node1 will start an election for it, vote on it and node2 gets synced up) - auto send1 = wallet1->send_action (nano::dev::genesis->account (), key2.pub, 2 * nano::Mxrb_ratio); + auto send1 = wallet1->send_action (nano::dev::genesis_key.pub, key2.pub, 2 * nano::Mxrb_ratio); ASSERT_TIMELY (5s, node1.block_confirmed (send1->hash ())); ASSERT_TIMELY (5s, node2.block_confirmed (send1->hash ())); @@ -1583,19 +1583,19 @@ TEST (node, unconfirmed_send) .previous (recv1->hash ()) .representative (nano::dev::genesis_key.pub) .balance (nano::Mxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (key2.prv, key2.pub) .work (*system.work.generate (recv1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, node2.process (send2)); - auto send3 = wallet2->send_action (key2.pub, nano::dev::genesis->account (), nano::Mxrb_ratio); + auto send3 = wallet2->send_action (key2.pub, nano::dev::genesis_key.pub, nano::Mxrb_ratio); ASSERT_TIMELY (5s, node2.block_confirmed (send2->hash ())); ASSERT_TIMELY (5s, node1.block_confirmed (send2->hash ())); ASSERT_TIMELY (5s, node2.block_confirmed (send3->hash ())); ASSERT_TIMELY (5s, node1.block_confirmed (send3->hash ())); ASSERT_TIMELY_EQ (5s, node2.ledger.cache.cemented_count, 7); - ASSERT_TIMELY_EQ (5s, node1.balance (nano::dev::genesis->account ()), nano::dev::constants.genesis_amount); + ASSERT_TIMELY_EQ (5s, node1.balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount); } // Test that nodes can disable representative voting @@ -2312,9 +2312,9 @@ TEST (node, DISABLED_vote_by_hash_epoch_block_republish) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); auto epoch1 = nano::state_block_builder () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (node1.ledger.epoch_link (nano::epoch::epoch_1)) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -3067,7 +3067,7 @@ TEST (node, rollback_vote_self) auto send2 = builder.make_block () .from (*send1) .previous (send1->hash ()) - .balance (send1->balance ().number () - 1) + .balance (send1->balance_field ().value ().number () - 1) .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (send1->hash ())) @@ -3076,7 +3076,7 @@ TEST (node, rollback_vote_self) // fork of send2 block auto fork = builder.make_block () .from (*send2) - .balance (send1->balance ().number () - 2) + .balance (send1->balance_field ().value ().number () - 2) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .build (); @@ -3164,7 +3164,7 @@ TEST (node, rollback_gap_source) auto send2 = builder.make_block () .from (*send1) .previous (send1->hash ()) - .balance (send1->balance ().number () - 1) + .balance (send1->balance_field ().value ().number () - 1) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (send1->hash ())) @@ -3255,7 +3255,7 @@ TEST (node, dependency_graph) .from (*gen_receive) .previous (gen_receive->hash ()) .link (key2.pub) - .balance (gen_receive->balance ().number () - 2) + .balance (gen_receive->balance_field ().value ().number () - 2) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (gen_receive->hash ())) .build (); @@ -3294,7 +3294,7 @@ TEST (node, dependency_graph) .from (*key2_send1) .previous (key2_send1->hash ()) .link (key1.pub) - .balance (key2_send1->balance ().number () - 1) + .balance (key2_send1->balance_field ().value ().number () - 1) .sign (key2.prv, key2.pub) .work (*system.work.generate (key2_send1->hash ())) .build (); @@ -3303,7 +3303,7 @@ TEST (node, dependency_graph) .from (*key1_send1) .previous (key1_send1->hash ()) .link (key2_send2->hash ()) - .balance (key1_send1->balance ().number () + 1) + .balance (key1_send1->balance_field ().value ().number () + 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_send1->hash ())) .build (); @@ -3312,7 +3312,7 @@ TEST (node, dependency_graph) .from (*key1_receive) .previous (key1_receive->hash ()) .link (key3.pub) - .balance (key1_receive->balance ().number () - 1) + .balance (key1_receive->balance_field ().value ().number () - 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_receive->hash ())) .build (); @@ -3321,7 +3321,7 @@ TEST (node, dependency_graph) .from (*key3_open) .previous (key3_open->hash ()) .link (key1_send2->hash ()) - .balance (key3_open->balance ().number () + 1) + .balance (key3_open->balance_field ().value ().number () + 1) .sign (key3.prv, key3.pub) .work (*system.work.generate (key3_open->hash ())) .build (); @@ -3330,7 +3330,7 @@ TEST (node, dependency_graph) .from (*key3_receive) .previous (key3_receive->hash ()) .link (node.ledger.epoch_link (nano::epoch::epoch_1)) - .balance (key3_receive->balance ()) + .balance (key3_receive->balance_field ().value ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (key3_receive->hash ())) .build (); @@ -3456,7 +3456,7 @@ TEST (node, dependency_graph_frontier) .from (*gen_receive) .previous (gen_receive->hash ()) .link (key2.pub) - .balance (gen_receive->balance ().number () - 2) + .balance (gen_receive->balance_field ().value ().number () - 2) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (gen_receive->hash ())) .build (); @@ -3495,7 +3495,7 @@ TEST (node, dependency_graph_frontier) .from (*key2_send1) .previous (key2_send1->hash ()) .link (key1.pub) - .balance (key2_send1->balance ().number () - 1) + .balance (key2_send1->balance_field ().value ().number () - 1) .sign (key2.prv, key2.pub) .work (*system.work.generate (key2_send1->hash ())) .build (); @@ -3504,7 +3504,7 @@ TEST (node, dependency_graph_frontier) .from (*key1_send1) .previous (key1_send1->hash ()) .link (key2_send2->hash ()) - .balance (key1_send1->balance ().number () + 1) + .balance (key1_send1->balance_field ().value ().number () + 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_send1->hash ())) .build (); @@ -3513,7 +3513,7 @@ TEST (node, dependency_graph_frontier) .from (*key1_receive) .previous (key1_receive->hash ()) .link (key3.pub) - .balance (key1_receive->balance ().number () - 1) + .balance (key1_receive->balance_field ().value ().number () - 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_receive->hash ())) .build (); @@ -3522,7 +3522,7 @@ TEST (node, dependency_graph_frontier) .from (*key3_open) .previous (key3_open->hash ()) .link (key1_send2->hash ()) - .balance (key3_open->balance ().number () + 1) + .balance (key3_open->balance_field ().value ().number () + 1) .sign (key3.prv, key3.pub) .work (*system.work.generate (key3_open->hash ())) .build (); @@ -3531,7 +3531,7 @@ TEST (node, dependency_graph_frontier) .from (*key3_receive) .previous (key3_receive->hash ()) .link (node1.ledger.epoch_link (nano::epoch::epoch_1)) - .balance (key3_receive->balance ()) + .balance (key3_receive->balance_field ().value ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (key3_receive->hash ())) .build (); @@ -3601,7 +3601,7 @@ TEST (node, deferred_dependent_elections) auto send2 = builder.make_block () .from (*send1) .previous (send1->hash ()) - .balance (send1->balance ().number () - 1) + .balance (send1->balance_field ().value ().number () - 1) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (send1->hash ())) diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index 94f6d8c1b..f569c3494 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -461,7 +461,7 @@ TEST (request_aggregator, cannot_vote) auto send2 = builder.make_block () .from (*send1) .previous (send1->hash ()) - .balance (send1->balance ().number () - 1) + .balance (send1->balance_field ().value ().number () - 1) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (send1->hash ())) .build (); diff --git a/nano/core_test/system.cpp b/nano/core_test/system.cpp index b89524e8d..9fd891248 100644 --- a/nano/core_test/system.cpp +++ b/nano/core_test/system.cpp @@ -31,7 +31,7 @@ TEST (system, system_genesis) for (auto & i : system.nodes) { auto transaction (i->store.tx_begin_read ()); - ASSERT_EQ (nano::dev::constants.genesis_amount, i->ledger.account_balance (transaction, nano::dev::genesis->account ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, i->ledger.account_balance (transaction, nano::dev::genesis_key.pub)); } } @@ -42,7 +42,7 @@ TEST (system, DISABLED_generate_send_existing) nano::thread_runner runner (system.io_ctx, node1.config.io_threads); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); nano::keypair stake_preserver; - auto send_block (system.wallet (0)->send_action (nano::dev::genesis->account (), stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true)); + auto send_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true)); auto info1 = node1.ledger.account_info (node1.store.tx_begin_read (), nano::dev::genesis_key.pub); ASSERT_TRUE (info1); std::vector accounts; @@ -55,7 +55,7 @@ TEST (system, DISABLED_generate_send_existing) auto open_block = builder .open () .source (send_block->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (stake_preserver.pub) .sign (stake_preserver.prv, stake_preserver.pub) .work (0) @@ -63,7 +63,7 @@ TEST (system, DISABLED_generate_send_existing) node1.work_generate_blocking (*open_block); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, open_block)); } - ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis->account ())); + ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis_key.pub)); auto info2 = node1.ledger.account_info (node1.store.tx_begin_read (), nano::dev::genesis_key.pub); ASSERT_TRUE (info2); ASSERT_NE (info1->head, info2->head); @@ -99,14 +99,14 @@ TEST (system, DISABLED_generate_send_new) ASSERT_EQ (node1.store.account.end (), iterator1); } nano::keypair stake_preserver; - auto send_block (system.wallet (0)->send_action (nano::dev::genesis->account (), stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true)); + auto send_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true)); { auto transaction (node1.store.tx_begin_write ()); nano::block_builder builder; auto open_block = builder .open () .source (send_block->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (stake_preserver.pub) .sign (stake_preserver.prv, stake_preserver.pub) .work (0) @@ -114,7 +114,7 @@ TEST (system, DISABLED_generate_send_new) node1.work_generate_blocking (*open_block); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, open_block)); } - ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis->account ())); + ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis_key.pub)); std::vector accounts; accounts.push_back (nano::dev::genesis_key.pub); // This indirectly waits for online weight to stabilize, required to prevent intermittent failures diff --git a/nano/core_test/unchecked_map.cpp b/nano/core_test/unchecked_map.cpp index 105ee3131..99777f653 100644 --- a/nano/core_test/unchecked_map.cpp +++ b/nano/core_test/unchecked_map.cpp @@ -147,14 +147,14 @@ TEST (unchecked, multiple) // Enqueues the first block unchecked.put (block->previous (), nano::unchecked_info (block)); // Enqueues a second block - unchecked.put (block->source (), nano::unchecked_info (block)); + unchecked.put (6, nano::unchecked_info (block)); auto check_block_is_listed = [&] (nano::block_hash const & block_hash_a) { return unchecked.get (block_hash_a).size () > 0; }; // Waits for and asserts the first block gets saved in the database ASSERT_TIMELY (5s, check_block_is_listed (block->previous ())); // Waits for and asserts the second block gets saved in the database - ASSERT_TIMELY (5s, check_block_is_listed (block->source ())); + ASSERT_TIMELY (5s, check_block_is_listed (6)); } // This test ensures that a block can't occur twice in the unchecked table. diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index 079eb007c..0250f291d 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -17,7 +17,7 @@ TEST (wallet, no_special_keys_accounts) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); nano::keypair key1; ASSERT_FALSE (wallet.exists (transaction, key1.pub)); @@ -38,7 +38,7 @@ TEST (wallet, no_key) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); nano::keypair key1; nano::raw_key prv1; @@ -53,7 +53,7 @@ TEST (wallet, fetch_locked) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_TRUE (wallet.valid_password (transaction)); nano::keypair key1; ASSERT_EQ (key1.pub, wallet.insert_adhoc (transaction, key1.prv)); @@ -75,7 +75,7 @@ TEST (wallet, retrieval) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); nano::keypair key1; ASSERT_TRUE (wallet.valid_password (transaction)); @@ -97,7 +97,7 @@ TEST (wallet, empty_iteration) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); auto i (wallet.begin (transaction)); auto j (wallet.end ()); @@ -111,7 +111,7 @@ TEST (wallet, one_item_iteration) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); nano::keypair key1; wallet.insert_adhoc (transaction, key1.prv); @@ -139,7 +139,7 @@ TEST (wallet, two_item_iteration) nano::kdf kdf{ nano::dev::network_params.kdf_work }; { auto transaction (env.tx_begin_write ()); - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); wallet.insert_adhoc (transaction, key1.prv); wallet.insert_adhoc (transaction, key2.prv); @@ -259,7 +259,7 @@ TEST (wallet, find_none) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); nano::account account (1000); ASSERT_EQ (wallet.end (), wallet.find (transaction, account)); @@ -272,7 +272,7 @@ TEST (wallet, find_existing) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); nano::keypair key1; ASSERT_FALSE (wallet.exists (transaction, key1.pub)); @@ -291,7 +291,7 @@ TEST (wallet, rekey) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); nano::raw_key password; wallet.password.value (password); @@ -363,7 +363,7 @@ TEST (wallet, hash_password) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); nano::raw_key hash1; wallet.derive_key (hash1, transaction, ""); @@ -413,25 +413,25 @@ TEST (wallet, reopen_default_password) ASSERT_FALSE (init); nano::kdf kdf{ nano::dev::network_params.kdf_work }; { - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); ASSERT_TRUE (wallet.valid_password (transaction)); } { bool init; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); ASSERT_TRUE (wallet.valid_password (transaction)); } { - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); wallet.rekey (transaction, ""); ASSERT_TRUE (wallet.valid_password (transaction)); } { bool init; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); ASSERT_FALSE (wallet.valid_password (transaction)); wallet.attempt_password (transaction, " "); @@ -448,10 +448,10 @@ TEST (wallet, representative) ASSERT_FALSE (error); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (error); ASSERT_FALSE (wallet.is_representative (transaction)); - ASSERT_EQ (nano::dev::genesis->account (), wallet.representative (transaction)); + ASSERT_EQ (nano::dev::genesis_key.pub, wallet.representative (transaction)); ASSERT_FALSE (wallet.is_representative (transaction)); nano::keypair key; wallet.representative_set (transaction, key.pub); @@ -469,11 +469,11 @@ TEST (wallet, serialize_json_empty) ASSERT_FALSE (error); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (error); std::string serialized; wallet1.serialize_json (transaction, serialized); - nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "1", serialized); + nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "1", serialized); ASSERT_FALSE (error); nano::raw_key password1; nano::raw_key password2; @@ -494,13 +494,13 @@ TEST (wallet, serialize_json_one) ASSERT_FALSE (error); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (error); nano::keypair key; wallet1.insert_adhoc (transaction, key.prv); std::string serialized; wallet1.serialize_json (transaction, serialized); - nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "1", serialized); + nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "1", serialized); ASSERT_FALSE (error); nano::raw_key password1; nano::raw_key password2; @@ -523,14 +523,14 @@ TEST (wallet, serialize_json_password) ASSERT_FALSE (error); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (error); nano::keypair key; wallet1.rekey (transaction, "password"); wallet1.insert_adhoc (transaction, key.prv); std::string serialized; wallet1.serialize_json (transaction, serialized); - nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "1", serialized); + nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "1", serialized); ASSERT_FALSE (error); ASSERT_FALSE (wallet2.valid_password (transaction)); ASSERT_FALSE (wallet2.attempt_password (transaction, "password")); @@ -556,11 +556,11 @@ TEST (wallet_store, move) ASSERT_FALSE (error); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet1 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (error); nano::keypair key1; wallet1.insert_adhoc (transaction, key1.prv); - nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis->account (), 1, "1"); + nano::wallet_store wallet2 (error, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "1"); ASSERT_FALSE (error); nano::keypair key2; wallet2.insert_adhoc (transaction, key2.prv); @@ -714,7 +714,7 @@ TEST (wallet, deterministic_keys) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); auto key1 = wallet.deterministic_key (transaction, 0); auto key2 = wallet.deterministic_key (transaction, 0); ASSERT_EQ (key1, key2); @@ -757,7 +757,7 @@ TEST (wallet, reseed) ASSERT_FALSE (init); auto transaction (env.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis->account (), 1, "0"); + nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); nano::raw_key seed1; seed1 = 1; nano::raw_key seed2; @@ -1001,7 +1001,7 @@ TEST (wallet, epoch_2_validation) ASSERT_EQ (nano::epoch::epoch_2, send->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_0, send->sideband ().source_epoch); // Not used for send state blocks - auto receive = wallet.receive_action (send->hash (), nano::dev::genesis_key.pub, amount, send->link ().as_account (), 1); + auto receive = wallet.receive_action (send->hash (), nano::dev::genesis_key.pub, amount, send->destination (), 1); ASSERT_NE (nullptr, receive); if (nano::dev::network_params.work.difficulty (*receive) < node.network_params.work.base) { @@ -1043,7 +1043,7 @@ TEST (wallet, epoch_2_receive_propagation) auto amount = node.config.receive_minimum.number (); auto send1 = wallet.send_action (nano::dev::genesis_key.pub, key.pub, amount, 1); ASSERT_NE (nullptr, send1); - ASSERT_NE (nullptr, wallet.receive_action (send1->hash (), nano::dev::genesis_key.pub, amount, send1->link ().as_account (), 1)); + ASSERT_NE (nullptr, wallet.receive_action (send1->hash (), nano::dev::genesis_key.pub, amount, send1->destination (), 1)); // Upgrade the genesis account to epoch 2 auto epoch2 = system.upgrade_genesis_epoch (node, nano::epoch::epoch_2); @@ -1053,7 +1053,7 @@ TEST (wallet, epoch_2_receive_propagation) auto send2 = wallet.send_action (nano::dev::genesis_key.pub, key.pub, amount, 1); ASSERT_NE (nullptr, send2); - auto receive2 = wallet.receive_action (send2->hash (), key.pub, amount, send2->link ().as_account (), 1); + auto receive2 = wallet.receive_action (send2->hash (), key.pub, amount, send2->destination (), 1); ASSERT_NE (nullptr, receive2); if (nano::dev::network_params.work.difficulty (*receive2) < node.network_params.work.base) { @@ -1106,7 +1106,7 @@ TEST (wallet, epoch_2_receive_unopened) wallet.insert_adhoc (key.prv, false); - auto receive1 = wallet.receive_action (send1->hash (), key.pub, amount, send1->link ().as_account (), 1); + auto receive1 = wallet.receive_action (send1->hash (), key.pub, amount, send1->destination (), 1); ASSERT_NE (nullptr, receive1); if (nano::dev::network_params.work.difficulty (*receive1) < node.network_params.work.base) { @@ -1155,11 +1155,11 @@ TEST (wallet, search_receivable) wallet.insert_adhoc (nano::dev::genesis_key.prv); nano::block_builder builder; auto send = builder.state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - node.config.receive_minimum.number ()) - .link (nano::dev::genesis->account ()) + .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 ())) .build (); @@ -1172,7 +1172,7 @@ TEST (wallet, search_receivable) ASSERT_TIMELY (5s, election = node.active.election (send->qualified_root ())); // Erase the key so the confirmation does not trigger an automatic receive - wallet.store.erase (node.wallets.tx_begin_write (), nano::dev::genesis->account ()); + wallet.store.erase (node.wallets.tx_begin_write (), nano::dev::genesis_key.pub); // Now confirm the election election->force_confirm (); @@ -1185,12 +1185,12 @@ TEST (wallet, search_receivable) // Pending search should create the receive block ASSERT_EQ (2, node.ledger.cache.block_count); ASSERT_FALSE (wallet.search_receivable (wallet.wallets.tx_begin_read ())); - ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis->account ()), nano::dev::constants.genesis_amount); - auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis->account ()); + ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount); + auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis_key.pub); auto receive = node.block (receive_hash); ASSERT_NE (nullptr, receive); ASSERT_EQ (receive->sideband ().height, 3); - ASSERT_EQ (send->hash (), receive->link ().as_block_hash ()); + ASSERT_EQ (send->hash (), receive->source ()); } TEST (wallet, receive_pruned) @@ -1228,7 +1228,7 @@ TEST (wallet, receive_pruned) wallet2.insert_adhoc (key.prv, false); - auto open1 = wallet2.receive_action (send1->hash (), key.pub, amount, send1->link ().as_account (), 1); + auto open1 = wallet2.receive_action (send1->hash (), key.pub, amount, send1->destination (), 1); ASSERT_NE (nullptr, open1); ASSERT_EQ (amount, node2.ledger.balance (node2.store.tx_begin_read (), open1->hash ())); ASSERT_TIMELY_EQ (5s, node2.ledger.cache.cemented_count, 4); diff --git a/nano/core_test/wallets.cpp b/nano/core_test/wallets.cpp index f624f70de..606fa18f4 100644 --- a/nano/core_test/wallets.cpp +++ b/nano/core_test/wallets.cpp @@ -205,11 +205,11 @@ TEST (wallets, search_receivable) wallet->insert_adhoc (nano::dev::genesis_key.prv); nano::block_builder builder; auto send = builder.state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - node.config.receive_minimum.number ()) - .link (nano::dev::genesis->account ()) + .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 ())) .build (); @@ -229,7 +229,7 @@ TEST (wallets, search_receivable) ASSERT_TIMELY (5s, election = node.active.election (send->qualified_root ())); // Erase the key so the confirmation does not trigger an automatic receive - wallet->store.erase (node.wallets.tx_begin_write (), nano::dev::genesis->account ()); + wallet->store.erase (node.wallets.tx_begin_write (), nano::dev::genesis_key.pub); // Now confirm the election election->force_confirm (); @@ -249,11 +249,11 @@ TEST (wallets, search_receivable) { node.wallets.search_receivable (wallet_id); } - ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis->account ()), nano::dev::constants.genesis_amount); - auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis->account ()); + ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount); + auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis_key.pub); auto receive = node.block (receive_hash); ASSERT_NE (nullptr, receive); ASSERT_EQ (receive->sideband ().height, 3); - ASSERT_EQ (send->hash (), receive->link ().as_block_hash ()); + ASSERT_EQ (send->hash (), receive->source ()); } } diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index 0735b5e4d..0d147dba4 100644 --- a/nano/core_test/websocket.cpp +++ b/nano/core_test/websocket.cpp @@ -796,7 +796,7 @@ TEST (websocket, work) // Generate work nano::block_hash hash{ 1 }; auto work (node1->work_generate_blocking (hash)); - ASSERT_TRUE (work.is_initialized ()); + ASSERT_TRUE (work.has_value ()); // Wait for the work notification ASSERT_TIMELY_EQ (5s, future.wait_for (0s), std::future_status::ready); @@ -827,7 +827,7 @@ TEST (websocket, work) nano::from_string_hex (result.get ("difficulty"), result_difficulty); ASSERT_GE (result_difficulty, node1->default_difficulty (nano::work_version::work_1)); ASSERT_NEAR (result.get ("multiplier"), nano::difficulty::to_multiplier (result_difficulty, node1->default_difficulty (nano::work_version::work_1)), 1e-6); - ASSERT_EQ (result.get ("work"), nano::to_string_hex (work.get ())); + ASSERT_EQ (result.get ("work"), nano::to_string_hex (work.value ())); ASSERT_EQ (1, contents.count ("bad_peers")); auto & bad_peers = contents.get_child ("bad_peers"); diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 688e614d1..060681ac1 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -115,6 +115,53 @@ void nano::block::refresh () } } +bool nano::block::is_send () const noexcept +{ + release_assert (has_sideband ()); + switch (type ()) + { + case nano::block_type::send: + return true; + case nano::block_type::state: + return sideband ().details.is_send; + default: + return false; + } +} + +bool nano::block::is_receive () const noexcept +{ + release_assert (has_sideband ()); + switch (type ()) + { + case nano::block_type::receive: + case nano::block_type::open: + return true; + case nano::block_type::state: + return sideband ().details.is_receive; + default: + return false; + } +} + +bool nano::block::is_change () const noexcept +{ + release_assert (has_sideband ()); + switch (type ()) + { + case nano::block_type::change: + return true; + case nano::block_type::state: + if (link_field ().value ().is_zero ()) + { + return true; + } + return false; + default: + return false; + } +} + nano::block_hash const & nano::block::hash () const { if (!cached_hash.is_zero ()) @@ -161,34 +208,108 @@ bool nano::block::has_sideband () const return sideband_m.is_initialized (); } -nano::account const & nano::block::representative () const +std::optional nano::block::representative_field () const { - static nano::account representative{}; - return representative; + return std::nullopt; } -nano::block_hash const & nano::block::source () const +std::optional nano::block::source_field () const { - static nano::block_hash source{ 0 }; - return source; + return std::nullopt; } -nano::account const & nano::block::destination () const +std::optional nano::block::destination_field () const { - static nano::account destination{}; - return destination; + return std::nullopt; } -nano::link const & nano::block::link () const +std::optional nano::block::link_field () const { - static nano::link link{ 0 }; - return link; + return std::nullopt; } -nano::account const & nano::block::account () const +nano::account nano::block::account () const noexcept { - static nano::account account{}; - return account; + release_assert (has_sideband ()); + switch (type ()) + { + case block_type::open: + case block_type::state: + return account_field ().value (); + case block_type::change: + case block_type::send: + case block_type::receive: + return sideband ().account; + default: + release_assert (false); + } +} + +nano::amount nano::block::balance () const noexcept +{ + release_assert (has_sideband ()); + switch (type ()) + { + case nano::block_type::open: + case nano::block_type::receive: + case nano::block_type::change: + return sideband ().balance; + case nano::block_type::send: + case nano::block_type::state: + return balance_field ().value (); + default: + release_assert (false); + } +} + +nano::account nano::block::destination () const noexcept +{ + release_assert (has_sideband ()); + switch (type ()) + { + case nano::block_type::send: + return destination_field ().value (); + case nano::block_type::state: + release_assert (sideband ().details.is_send); + return link_field ().value ().as_account (); + default: + release_assert (false); + } +} + +nano::block_hash nano::block::source () const noexcept +{ + release_assert (has_sideband ()); + switch (type ()) + { + case nano::block_type::open: + case nano::block_type::receive: + return source_field ().value (); + case nano::block_type::state: + release_assert (sideband ().details.is_receive); + return link_field ().value ().as_block_hash (); + default: + release_assert (false); + } +} + +// TODO - Remove comments below and fixup usages to not need to check .is_zero () +// std::optional nano::block::previous () const +nano::block_hash nano::block::previous () const noexcept +{ + std::optional result = previous_field (); + /* + if (result && result.value ().is_zero ()) + { + return std::nullopt; + } + return result;*/ + return result.value_or (0); +} + +std::optional nano::block::account_field () const +{ + return std::nullopt; } nano::qualified_root nano::block::qualified_root () const @@ -196,10 +317,9 @@ nano::qualified_root nano::block::qualified_root () const return { root (), previous () }; } -nano::amount const & nano::block::balance () const +std::optional nano::block::balance_field () const { - static nano::amount amount{ 0 }; - return amount; + return std::nullopt; } void nano::block::operator() (nano::object_stream & obs) const @@ -467,12 +587,12 @@ bool nano::send_block::operator== (nano::send_block const & other_a) const return result; } -nano::block_hash const & nano::send_block::previous () const +std::optional nano::send_block::previous_field () const { return hashables.previous; } -nano::account const & nano::send_block::destination () const +std::optional nano::send_block::destination_field () const { return hashables.destination; } @@ -482,7 +602,7 @@ nano::root const & nano::send_block::root () const return hashables.previous; } -nano::amount const & nano::send_block::balance () const +std::optional nano::send_block::balance_field () const { return hashables.balance; } @@ -637,13 +757,12 @@ void nano::open_block::block_work_set (uint64_t work_a) work = work_a; } -nano::block_hash const & nano::open_block::previous () const +std::optional nano::open_block::previous_field () const { - static nano::block_hash result{ 0 }; - return result; + return std::nullopt; } -nano::account const & nano::open_block::account () const +std::optional nano::open_block::account_field () const { return hashables.account; } @@ -689,7 +808,7 @@ void nano::open_block::serialize_json (boost::property_tree::ptree & tree) const { tree.put ("type", "open"); tree.put ("source", hashables.source.to_string ()); - tree.put ("representative", representative ().to_account ()); + tree.put ("representative", hashables.representative.to_account ()); tree.put ("account", hashables.account.to_account ()); std::string signature_l; signature.encode_hex (signature_l); @@ -763,7 +882,7 @@ bool nano::open_block::valid_predecessor (nano::block const & block_a) const return false; } -nano::block_hash const & nano::open_block::source () const +std::optional nano::open_block::source_field () const { return hashables.source; } @@ -773,7 +892,7 @@ nano::root const & nano::open_block::root () const return hashables.account; } -nano::account const & nano::open_block::representative () const +std::optional nano::open_block::representative_field () const { return hashables.representative; } @@ -909,7 +1028,7 @@ void nano::change_block::block_work_set (uint64_t work_a) work = work_a; } -nano::block_hash const & nano::change_block::previous () const +std::optional nano::change_block::previous_field () const { return hashables.previous; } @@ -953,7 +1072,7 @@ void nano::change_block::serialize_json (boost::property_tree::ptree & tree) con { tree.put ("type", "change"); tree.put ("previous", hashables.previous.to_string ()); - tree.put ("representative", representative ().to_account ()); + tree.put ("representative", hashables.representative.to_account ()); tree.put ("work", nano::to_string_hex (work)); std::string signature_l; signature.encode_hex (signature_l); @@ -1039,7 +1158,7 @@ nano::root const & nano::change_block::root () const return hashables.previous; } -nano::account const & nano::change_block::representative () const +std::optional nano::change_block::representative_field () const { return hashables.representative; } @@ -1208,12 +1327,12 @@ void nano::state_block::block_work_set (uint64_t work_a) work = work_a; } -nano::block_hash const & nano::state_block::previous () const +std::optional nano::state_block::previous_field () const { return hashables.previous; } -nano::account const & nano::state_block::account () const +std::optional nano::state_block::account_field () const { return hashables.account; } @@ -1265,7 +1384,7 @@ void nano::state_block::serialize_json (boost::property_tree::ptree & tree) cons tree.put ("type", "state"); tree.put ("account", hashables.account.to_account ()); tree.put ("previous", hashables.previous.to_string ()); - tree.put ("representative", representative ().to_account ()); + tree.put ("representative", hashables.representative.to_account ()); tree.put ("balance", hashables.balance.to_string_dec ()); tree.put ("link", hashables.link.to_string ()); tree.put ("link_as_account", hashables.link.to_account ()); @@ -1363,17 +1482,17 @@ nano::root const & nano::state_block::root () const } } -nano::link const & nano::state_block::link () const +std::optional nano::state_block::link_field () const { return hashables.link; } -nano::account const & nano::state_block::representative () const +std::optional nano::state_block::representative_field () const { return hashables.representative; } -nano::amount const & nano::state_block::balance () const +std::optional nano::state_block::balance_field () const { return hashables.balance; } @@ -1695,12 +1814,12 @@ bool nano::receive_block::valid_predecessor (nano::block const & block_a) const return result; } -nano::block_hash const & nano::receive_block::previous () const +std::optional nano::receive_block::previous_field () const { return hashables.previous; } -nano::block_hash const & nano::receive_block::source () const +std::optional nano::receive_block::source_field () const { return hashables.source; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index e89f2dddb..d6cca7437 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -33,21 +33,10 @@ public: virtual void hash (blake2b_state &) const = 0; virtual uint64_t block_work () const = 0; virtual void block_work_set (uint64_t) = 0; - virtual nano::account const & account () const; - // Previous block in account's chain, zero for open block - virtual nano::block_hash const & previous () const = 0; - // Source block for open/receive blocks, zero otherwise. - virtual nano::block_hash const & source () const; - // Destination account for send blocks, zero otherwise. - virtual nano::account const & destination () const; // Previous block or account number for open blocks virtual nano::root const & root () const = 0; // Qualified root value based on previous() and root() virtual nano::qualified_root qualified_root () const; - // Link field for state blocks, zero otherwise. - virtual nano::link const & link () const; - virtual nano::account const & representative () const; - virtual nano::amount const & balance () const; virtual void serialize (nano::stream &) const = 0; virtual void serialize_json (std::string &, bool = false) const = 0; virtual void serialize_json (boost::property_tree::ptree &) const = 0; @@ -63,6 +52,35 @@ public: virtual nano::work_version work_version () const; // If there are any changes to the hashables, call this to update the cached hash void refresh (); + bool is_send () const noexcept; + bool is_receive () const noexcept; + bool is_change () const noexcept; + +public: // Direct access to the block fields or nullopt if the block type does not have the specified field + // Returns account field or account from sideband + nano::account account () const noexcept; + // Account field for open/state blocks + virtual std::optional account_field () const; + // Returns the balance field or balance from sideband + nano::amount balance () const noexcept; + // Balance field for open/send/state blocks + virtual std::optional balance_field () const; + // Returns the destination account for send/state blocks that are sends + nano::account destination () const noexcept; + // Destination account for send blocks + virtual std::optional destination_field () const; + // Link field for state blocks + virtual std::optional link_field () const; + // Previous block if field exists or 0 + nano::block_hash previous () const noexcept; + // Previous block in chain if the field exists + virtual std::optional previous_field () const = 0; + // Representative field for open/change blocks + virtual std::optional representative_field () const; + // Returns the source block hash for open/receive/state blocks that are receives + nano::block_hash source () const noexcept; + // Source block for open/receive blocks + virtual std::optional source_field () const; protected: mutable nano::block_hash cached_hash{ 0 }; @@ -106,10 +124,7 @@ public: void hash (blake2b_state &) const override; uint64_t block_work () const override; void block_work_set (uint64_t) override; - nano::block_hash const & previous () const override; - nano::account const & destination () const override; nano::root const & root () const override; - nano::amount const & balance () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); void serialize_json (std::string &, bool = false) const override; @@ -128,6 +143,11 @@ public: uint64_t work; static std::size_t constexpr size = nano::send_hashables::size + sizeof (signature) + sizeof (work); +public: // Send block fields + std::optional balance_field () const override; + std::optional destination_field () const override; + std::optional previous_field () const override; + public: // Logging void operator() (nano::object_stream &) const override; }; @@ -157,8 +177,6 @@ public: void hash (blake2b_state &) const override; uint64_t block_work () const override; void block_work_set (uint64_t) override; - nano::block_hash const & previous () const override; - nano::block_hash const & source () const override; nano::root const & root () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); @@ -178,6 +196,10 @@ public: uint64_t work; static std::size_t constexpr size = nano::receive_hashables::size + sizeof (signature) + sizeof (work); +public: // Receive block fields + std::optional previous_field () const override; + std::optional source_field () const override; + public: // Logging void operator() (nano::object_stream &) const override; }; @@ -209,11 +231,7 @@ public: void hash (blake2b_state &) const override; uint64_t block_work () const override; void block_work_set (uint64_t) override; - nano::block_hash const & previous () const override; - nano::account const & account () const override; - nano::block_hash const & source () const override; nano::root const & root () const override; - nano::account const & representative () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); void serialize_json (std::string &, bool = false) const override; @@ -232,6 +250,12 @@ public: uint64_t work; static std::size_t constexpr size = nano::open_hashables::size + sizeof (signature) + sizeof (work); +public: // Open block fields + std::optional account_field () const override; + std::optional previous_field () const override; + std::optional representative_field () const override; + std::optional source_field () const override; + public: // Logging void operator() (nano::object_stream &) const override; }; @@ -261,9 +285,7 @@ public: void hash (blake2b_state &) const override; uint64_t block_work () const override; void block_work_set (uint64_t) override; - nano::block_hash const & previous () const override; nano::root const & root () const override; - nano::account const & representative () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); void serialize_json (std::string &, bool = false) const override; @@ -282,6 +304,10 @@ public: uint64_t work; static std::size_t constexpr size = nano::change_hashables::size + sizeof (signature) + sizeof (work); +public: // Change block fields + std::optional previous_field () const override; + std::optional representative_field () const override; + public: // Logging void operator() (nano::object_stream &) const override; }; @@ -324,12 +350,7 @@ public: void hash (blake2b_state &) const override; uint64_t block_work () const override; void block_work_set (uint64_t) override; - nano::block_hash const & previous () const override; - nano::account const & account () const override; nano::root const & root () const override; - nano::link const & link () const override; - nano::account const & representative () const override; - nano::amount const & balance () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); void serialize_json (std::string &, bool = false) const override; @@ -348,6 +369,13 @@ public: uint64_t work; static std::size_t constexpr size = nano::state_hashables::size + sizeof (signature) + sizeof (work); +public: // State block fields + std::optional account_field () const override; + std::optional balance_field () const override; + std::optional link_field () const override; + std::optional previous_field () const override; + std::optional representative_field () const override; + public: // Logging void operator() (nano::object_stream &) const override; }; diff --git a/nano/load_test/entry.cpp b/nano/load_test/entry.cpp index 13f56e38c..7a012fdeb 100644 --- a/nano/load_test/entry.cpp +++ b/nano/load_test/entry.cpp @@ -653,7 +653,7 @@ int main (int argc, char * const * argv) } // Send from genesis account to different accounts and receive the funds - auto send_receive = std::make_shared (ioc, wallet, nano::dev::genesis->account ().to_account (), destination_account->as_string, send_calls_remaining, primary_node_results); + auto send_receive = std::make_shared (ioc, wallet, nano::dev::genesis_key.pub.to_account (), destination_account->as_string, send_calls_remaining, primary_node_results); boost::asio::strand strand{ ioc.get_executor () }; boost::asio::post (strand, [send_receive] () { diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 3c5b79a6b..a18d22af3 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1501,7 +1501,7 @@ int main (int argc, char * const * argv) { if ((state_block.hashables.balance == prev_balance && !error_or_pruned) || (node->ledger.pruning && error_or_pruned && block->sideband ().details.is_epoch)) { - invalid = validate_message (node->ledger.epoch_signer (block->link ()), hash, block->block_signature ()); + invalid = validate_message (node->ledger.epoch_signer (block->link_field ().value ()), hash, block->block_signature ()); } } } @@ -1529,12 +1529,12 @@ int main (int argc, char * const * argv) } else { - if (block->link ().is_zero ()) + if (block->is_change ()) { // State change block_details_error = sideband.details.is_send || sideband.details.is_receive || sideband.details.is_epoch; } - else if (block->balance () == prev_balance.value () && node->ledger.is_epoch_link (block->link ())) + else if (block->balance () == prev_balance.value () && node->ledger.is_epoch_link (block->link_field ().value ())) { // State epoch block_details_error = !sideband.details.is_epoch || sideband.details.is_send || sideband.details.is_receive; @@ -1543,7 +1543,7 @@ int main (int argc, char * const * argv) { // State receive block_details_error = !sideband.details.is_receive || sideband.details.is_send || sideband.details.is_epoch; - block_details_error |= !node->ledger.block_or_pruned_exists (transaction, block->link ().as_block_hash ()); + block_details_error |= !node->ledger.block_or_pruned_exists (transaction, block->source ()); } } } @@ -1557,7 +1557,7 @@ int main (int argc, char * const * argv) print_error_message (boost::str (boost::format ("Incorrect sideband block details for block %1%\n") % hash.to_string ())); } // Check link epoch version - if (sideband.details.is_receive && (!node->ledger.pruning || !node->store.pruned.exists (transaction, block->link ().as_block_hash ()))) + if (sideband.details.is_receive && (!node->ledger.pruning || !node->store.pruned.exists (transaction, block->source ()))) { if (sideband.source_epoch != node->ledger.version (*block)) { @@ -1584,7 +1584,7 @@ int main (int argc, char * const * argv) // Calculate representative block if (block->type () == nano::block_type::open || block->type () == nano::block_type::change || block->type () == nano::block_type::state) { - calculated_representative = block->representative (); + calculated_representative = block->representative_field ().value (); } // Retrieving successor block hash hash = node->store.block.successor (transaction, hash); @@ -1697,7 +1697,7 @@ int main (int argc, char * const * argv) } if (auto state = dynamic_cast (block.get ())) { - if (node->ledger.is_send (transaction, *state)) + if (state->is_send ()) { destination = state->hashables.link.as_account (); } @@ -1809,7 +1809,7 @@ int main (int argc, char * const * argv) std::cout << boost::str (boost::format ("%1% blocks retrieved") % count) << std::endl; } node.node->block_processor.add (block); - if (block->type () == nano::block_type::state && block->previous ().is_zero () && source_node->ledger.is_epoch_link (block->link ())) + if (block->type () == nano::block_type::state && block->previous ().is_zero () && source_node->ledger.is_epoch_link (block->link_field ().value ())) { // Epoch open blocks can be rejected without processed pending blocks to account, push it later again epoch_open_blocks.push_back (block); diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 2545c5d41..d2df96e36 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -165,8 +165,10 @@ void nano::active_transactions::handle_confirmation (nano::store::read_transacti void nano::active_transactions::handle_block_confirmation (nano::store::read_transaction const & transaction, std::shared_ptr const & block, nano::block_hash const & hash, nano::account & account, nano::uint128_t & amount, bool & is_state_send, bool & is_state_epoch, nano::account & pending_account) { - auto destination = block->link ().is_zero () ? block->destination () : block->link ().as_account (); - node.receive_confirmed (transaction, hash, destination); + if (block->is_send ()) + { + node.receive_confirmed (transaction, hash, block->destination ()); + } node.process_confirmed_data (transaction, block, hash, account, amount, is_state_send, is_state_epoch, pending_account); } @@ -186,7 +188,7 @@ void nano::active_transactions::notify_observers (nano::election_status const & void nano::active_transactions::handle_final_votes_confirmation (std::shared_ptr const & block, nano::store::read_transaction const & transaction, nano::election_status_type status) { - auto const & account = !block->account ().is_zero () ? block->account () : block->sideband ().account; + auto account = block->account (); bool is_canary_not_set = !node.ledger.cache.final_votes_confirmation_canary.load (); bool is_canary_account = account == node.network_params.ledger.final_votes_canary_account; diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 731a000f7..92efa88e2 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -340,11 +340,11 @@ nano::block_status nano::block_processor::process_one (store::write_transaction /* For send blocks check epoch open unchecked (gap pending). For state blocks check only send subtype and only if block epoch is not last epoch. If epoch is last, then pending entry shouldn't trigger same epoch open block for destination account. */ - if (block->type () == nano::block_type::send || (block->type () == nano::block_type::state && block->sideband ().details.is_send && std::underlying_type_t (block->sideband ().details.epoch) < std::underlying_type_t (nano::epoch::max))) + if (block->type () == nano::block_type::send || (block->type () == nano::block_type::state && block->is_send () && std::underlying_type_t (block->sideband ().details.epoch) < std::underlying_type_t (nano::epoch::max))) { /* block->destination () for legacy send blocks block->link () for state blocks (send subtype) */ - queue_unchecked (transaction_a, block->destination ().is_zero () ? block->link () : block->destination ()); + queue_unchecked (transaction_a, block->destination ()); } break; } @@ -356,13 +356,14 @@ nano::block_status nano::block_processor::process_one (store::write_transaction } case nano::block_status::gap_source: { - node.unchecked.put (node.ledger.block_source (transaction_a, *block), block); + release_assert (block->source_field () || block->link_field ()); + node.unchecked.put (block->source_field ().value_or (block->link_field ().value_or (0).as_block_hash ()), block); node.stats.inc (nano::stat::type::ledger, nano::stat::detail::gap_source); break; } case nano::block_status::gap_epoch_open_pending: { - node.unchecked.put (block->account (), block); // Specific unchecked key starting with epoch open block account public key + node.unchecked.put (block->account_field ().value_or (0), block); // Specific unchecked key starting with epoch open block account public key node.stats.inc (nano::stat::type::ledger, nano::stat::detail::gap_source); break; } diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index cad42863b..d4b4e1321 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -176,7 +176,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code ec, std:: // Is block expected? bool block_expected (false); // Unconfirmed head is used only for lazy destinations if legacy bootstrap is not available, see nano::bootstrap_attempt::lazy_destinations_increment (...) - bool unconfirmed_account_head = node->flags.disable_legacy_bootstrap && pull_blocks == 0 && pull.retry_limit <= node->network_params.bootstrap.lazy_retry_limit && (expected == pull.account_or_head.as_block_hash ()) && (block->account () == pull.account_or_head.as_account ()); + bool unconfirmed_account_head = node->flags.disable_legacy_bootstrap && pull_blocks == 0 && pull.retry_limit <= node->network_params.bootstrap.lazy_retry_limit && (expected == pull.account_or_head.as_block_hash ()) && (block->account_field () == pull.account_or_head.as_account ()); if (hash == expected || unconfirmed_account_head) { expected = block->previous (); @@ -188,7 +188,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code ec, std:: } if (pull_blocks == 0 && block_expected) { - known_account = block->account (); + known_account = block->account_field ().value_or (0); } if (connection->block_count++ == 0) { diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index 143937983..45e9cab61 100644 --- a/nano/node/bootstrap/bootstrap_lazy.cpp +++ b/nano/node/bootstrap/bootstrap_lazy.cpp @@ -291,9 +291,9 @@ bool nano::bootstrap_attempt_lazy::process_block_lazy (std::shared_ptrsource ().is_zero () && !node->ledger.block_or_pruned_exists (block_a->source ()) && block_a->source () != node->network_params.ledger.genesis->account ()) + if (block_a->source_field () && !node->ledger.block_or_pruned_exists (block_a->source_field ().value ()) && block_a->source_field ().value () != node->network_params.ledger.genesis->account ()) { - lazy_add (block_a->source (), retry_limit); + lazy_add (block_a->source_field ().value (), retry_limit); } else if (block_a->type () == nano::block_type::state) { @@ -303,7 +303,7 @@ bool nano::bootstrap_attempt_lazy::process_block_lazy (std::shared_ptrtype () == nano::block_type::state || block_a->type () == nano::block_type::send)) { - lazy_balances.emplace (hash, block_a->balance ().number ()); + lazy_balances.emplace (hash, block_a->balance_field ().value ().number ()); } // Clearing lazy balances for previous block if (!block_a->previous ().is_zero () && lazy_balances.find (block_a->previous ()) != lazy_balances.end ()) @@ -394,7 +394,7 @@ void nano::bootstrap_attempt_lazy::lazy_block_state_backlog_check (std::shared_p // Retrieve balance for previous state & send blocks if (block_a->type () == nano::block_type::state || block_a->type () == nano::block_type::send) { - if (block_a->balance ().number () <= next_block.balance) // balance + if (block_a->balance_field ().value ().number () <= next_block.balance) // balance { lazy_add (next_block.link, next_block.retry_limit); // link } diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 2db59429d..e75a26c24 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -133,42 +133,25 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, { case nano::block_status::progress: { - const auto account = ledger.account (block); - const auto is_send = ledger.is_send (tx, block); + const auto account = block.account (); // If we've inserted any block in to an account, unmark it as blocked accounts.unblock (account); accounts.priority_up (account); accounts.timestamp (account, /* reset timestamp */ true); - if (is_send) + if (block.is_send ()) { - // TODO: Encapsulate this as a helper somewhere - nano::account destination{ 0 }; - switch (block.type ()) - { - case nano::block_type::send: - destination = block.destination (); - break; - case nano::block_type::state: - destination = block.link ().as_account (); - break; - default: - debug_assert (false, "unexpected block type"); - break; - } - if (!destination.is_zero ()) - { - accounts.unblock (destination, hash); // Unblocking automatically inserts account into priority set - accounts.priority_up (destination); - } + auto destination = block.destination (); + accounts.unblock (destination, hash); // Unblocking automatically inserts account into priority set + accounts.priority_up (destination); } } break; case nano::block_status::gap_source: { - const auto account = block.previous ().is_zero () ? block.account () : ledger.account (tx, block.previous ()).value (); - const auto source = block.source ().is_zero () ? block.link ().as_block_hash () : block.source (); + const auto account = block.previous ().is_zero () ? block.account_field ().value () : ledger.account (tx, block.previous ()).value (); + const auto source = block.source_field ().value_or (block.link_field ().value_or (0).as_block_hash ()); // Mark account as blocked because it is missing the source block accounts.block (account, source); @@ -456,7 +439,7 @@ nano::bootstrap_ascending::service::verify_result nano::bootstrap_ascending::ser case async_tag::query_type::blocks_by_account: { // Open & state blocks always contain account field - if (first->account () != tag.start.as_account ()) + if (first->account_field () != tag.start.as_account ()) { // TODO: Stat & log return verify_result::invalid; diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index 53c3ffbf3..dfb7dea6d 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -104,11 +104,7 @@ void nano::confirmation_height_bounded::process (std::shared_ptr or release_assert (block); } } - nano::account account (block->account ()); - if (account.is_zero ()) - { - account = block->sideband ().account; - } + auto account = block->account (); // Checks if we have encountered this account before but not commited changes yet, if so then update the cached confirmation height nano::confirmation_height_info confirmation_height_info; @@ -257,19 +253,13 @@ bool nano::confirmation_height_bounded::iterate (store::read_transaction const & // Once a receive is cemented, we can cement all blocks above it until the next receive, so store those details for later. ++num_blocks; auto block = ledger.block (transaction_a, hash); - auto source (block->source ()); - if (source.is_zero ()) - { - source = block->link ().as_block_hash (); - } - - if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source)) + if (block->is_receive () && ledger.block_exists (transaction_a, block->source ())) { hit_receive = true; reached_target = true; auto const & sideband (block->sideband ()); auto next = !sideband.successor.is_zero () && sideband.successor != top_level_hash_a ? boost::optional (sideband.successor) : boost::none; - receive_source_pairs_a.push_back ({ receive_chain_details{ account_a, sideband.height, hash, top_level_hash_a, next, bottom_height_a, bottom_hash_a }, source }); + receive_source_pairs_a.push_back ({ receive_chain_details{ account_a, sideband.height, hash, top_level_hash_a, next, bottom_height_a, bottom_hash_a }, block->source () }); // Store a checkpoint every max_items so that we can always traverse a long number of accounts to genesis if (receive_source_pairs_a.size () % max_items == 0) { diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index 03c4c42a2..20e7101c1 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -79,11 +79,7 @@ void nano::confirmation_height_unbounded::process (std::shared_ptr } release_assert (block); - nano::account account (block->account ()); - if (account.is_zero ()) - { - account = block->sideband ().account; - } + auto account = block->account (); auto block_height = block->sideband ().height; uint64_t confirmation_height = 0; @@ -216,13 +212,7 @@ void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_source if (block) { - auto source (block->source ()); - if (source.is_zero ()) - { - source = block->link ().as_block_hash (); - } - - if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source)) + if (block->is_receive () && ledger.block_exists (transaction_a, block->source ())) { if (!hit_receive && !block_callback_data_a.empty ()) { @@ -237,7 +227,7 @@ void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_source hit_receive = true; auto block_height = confirmation_height_a + num_to_confirm; - receive_source_pairs_a.emplace_back (std::make_shared (account_a, hash, block_height, 1, std::vector{ hash }), source); + receive_source_pairs_a.emplace_back (std::make_shared (account_a, hash, block_height, 1, std::vector{ hash }), block->source ()); } else if (is_original_block) { diff --git a/nano/node/distributed_work.cpp b/nano/node/distributed_work.cpp index 7d1849fb9..3f2ffcb2d 100644 --- a/nano/node/distributed_work.cpp +++ b/nano/node/distributed_work.cpp @@ -68,7 +68,7 @@ void nano::distributed_work::start () else if (need_resolve.empty () && request.callback) { status = work_generation_status::failure_local; - request.callback (boost::none); + request.callback (std::nullopt); } for (auto const & peer : need_resolve) { @@ -117,7 +117,7 @@ void nano::distributed_work::start_local () this_l->status = work_generation_status::failure_local; if (this_l->request.callback) { - this_l->request.callback (boost::none); + this_l->request.callback (std::nullopt); } } this_l->stop_once (false); @@ -143,9 +143,9 @@ void nano::distributed_work::do_request (nano::tcp_endpoint const & endpoint_a) rpc_request.put ("action", "work_generate"); rpc_request.put ("hash", this_l->request.root.to_string ()); rpc_request.put ("difficulty", nano::to_string_hex (this_l->request.difficulty)); - if (this_l->request.account.is_initialized ()) + if (this_l->request.account.has_value ()) { - rpc_request.put ("account", this_l->request.account.get ().to_account ()); + rpc_request.put ("account", this_l->request.account.value ().to_account ()); } std::stringstream ostream; boost::property_tree::write_json (ostream, rpc_request); @@ -373,7 +373,7 @@ void nano::distributed_work::cancel () status = work_generation_status::cancelled; if (request.callback) { - request.callback (boost::none); + request.callback (std::nullopt); } stop_once (true); } @@ -411,7 +411,7 @@ void nano::distributed_work::handle_failure () } if (error_l && request_l.callback) { - request_l.callback (boost::none); + request_l.callback (std::nullopt); } }); } diff --git a/nano/node/distributed_work.hpp b/nano/node/distributed_work.hpp index e8772b3c6..17edecc60 100644 --- a/nano/node/distributed_work.hpp +++ b/nano/node/distributed_work.hpp @@ -9,6 +9,8 @@ #include #include +#include + using request_type = boost::beast::http::request; namespace boost @@ -28,8 +30,8 @@ struct work_request final nano::work_version version; nano::root root; uint64_t difficulty; - boost::optional const account; - std::function)> callback; + std::optional const account; + std::function)> callback; std::vector> const peers; }; @@ -107,4 +109,4 @@ private: std::atomic stopped{ false }; std::atomic local_generation_started{ false }; }; -} \ No newline at end of file +} diff --git a/nano/node/distributed_work_factory.cpp b/nano/node/distributed_work_factory.cpp index 2fd41aaf5..a0c1ac64c 100644 --- a/nano/node/distributed_work_factory.cpp +++ b/nano/node/distributed_work_factory.cpp @@ -12,7 +12,7 @@ nano::distributed_work_factory::~distributed_work_factory () stop (); } -bool nano::distributed_work_factory::make (nano::work_version const version_a, nano::root const & root_a, std::vector> const & peers_a, uint64_t difficulty_a, std::function)> const & callback_a, boost::optional const & account_a) +bool nano::distributed_work_factory::make (nano::work_version const version_a, nano::root const & root_a, std::vector> const & peers_a, uint64_t difficulty_a, std::function)> const & callback_a, std::optional const & account_a) { return make (std::chrono::seconds (1), nano::work_request{ version_a, root_a, difficulty_a, account_a, callback_a, peers_a }); } diff --git a/nano/node/distributed_work_factory.hpp b/nano/node/distributed_work_factory.hpp index ae626ead0..97c697aa9 100644 --- a/nano/node/distributed_work_factory.hpp +++ b/nano/node/distributed_work_factory.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -20,7 +21,7 @@ class distributed_work_factory final public: distributed_work_factory (nano::node &); ~distributed_work_factory (); - bool make (nano::work_version const, nano::root const &, std::vector> const &, uint64_t, std::function)> const &, boost::optional const & = boost::none); + bool make (nano::work_version const, nano::root const &, std::vector> const &, uint64_t, std::function)> const &, std::optional const & = std::nullopt); bool make (std::chrono::seconds const &, nano::work_request const &); void cancel (nano::root const &); void cleanup_finished (); diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index 8cf1fe5e4..f8265733f 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -9,10 +9,10 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano block->account = block_a.account ().to_account (); block->hash = block_a.hash ().to_string (); block->previous = block_a.previous ().to_string (); - block->representative = block_a.representative ().to_account (); + block->representative = block_a.representative_field ().value ().to_account (); block->balance = block_a.balance ().to_string_dec (); - block->link = block_a.link ().to_string (); - block->link_as_account = block_a.link ().to_account (); + block->link = block_a.link_field ().value ().to_string (); + block->link_as_account = block_a.link_field ().value ().to_account (); block_a.signature.encode_hex (block->signature); block->work = nano::to_string_hex (block_a.work); @@ -20,7 +20,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano { block->subtype = nanoapi::BlockSubType::BlockSubType_send; } - else if (block_a.link ().is_zero ()) + else if (block_a.is_change ()) { block->subtype = nanoapi::BlockSubType::BlockSubType_change; } @@ -51,7 +51,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (na { auto block (std::make_unique ()); block->hash = block_a.hash ().to_string (); - block->source = block_a.source ().to_string (); + block->source = block_a.source_field ().value ().to_string (); block->previous = block_a.previous ().to_string (); block_a.signature.encode_hex (block->signature); block->work = nano::to_string_hex (block_a.work); @@ -62,9 +62,9 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano: { auto block (std::make_unique ()); block->hash = block_a.hash ().to_string (); - block->source = block_a.source ().to_string (); + block->source = block_a.source_field ().value ().to_string (); block->account = block_a.account ().to_account (); - block->representative = block_a.representative ().to_account (); + block->representative = block_a.representative_field ().value ().to_account (); block_a.signature.encode_hex (block->signature); block->work = nano::to_string_hex (block_a.work); return block; @@ -75,7 +75,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nan auto block (std::make_unique ()); block->hash = block_a.hash ().to_string (); block->previous = block_a.previous ().to_string (); - block->representative = block_a.representative ().to_account (); + block->representative = block_a.representative_field ().value ().to_account (); block_a.signature.encode_hex (block->signature); block->work = nano::to_string_hex (block_a.work); return block; diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 2639aa44b..2442a23c3 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -403,7 +403,7 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a) // Send check if (block_previous != nullptr) { - details.is_send = node.ledger.balance (transaction, previous) > block_a.balance ().number (); + details.is_send = node.ledger.balance (transaction, previous) > block_a.balance_field ().value ().number (); details_found = true; } // Epoch check @@ -411,11 +411,12 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a) { details.epoch = block_previous->sideband ().details.epoch; } - auto link (block_a.link ()); - if (!link.is_zero () && !details.is_send) + auto link = block_a.link_field (); + if (link && !link.value ().is_zero () && !details.is_send) { - auto block_link = node.ledger.block (transaction, link.as_block_hash ()); - if (block_link != nullptr && node.store.pending.exists (transaction, nano::pending_key (block_a.account (), link.as_block_hash ()))) + auto block_link = node.ledger.block (transaction, link.value ().as_block_hash ()); + auto account = block_a.account_field ().value (); // Link is non-zero therefore it's a state block and has an account field; + if (block_link != nullptr && node.store.pending.exists (transaction, nano::pending_key (account, link.value ().as_block_hash ()))) { details.epoch = std::max (details.epoch, block_link->sideband ().details.epoch); details.is_receive = true; @@ -684,10 +685,10 @@ void nano::json_handler::account_info () nano::account confirmed_representative{}; if (confirmed_frontier_block) { - confirmed_representative = confirmed_frontier_block->representative (); + confirmed_representative = confirmed_frontier_block->representative_field ().value_or (0); if (confirmed_representative.is_zero ()) { - confirmed_representative = node.ledger.block (transaction, node.ledger.representative (transaction, confirmation_height_info.frontier))->representative (); + confirmed_representative = node.ledger.block (transaction, node.ledger.representative (transaction, confirmation_height_info.frontier))->representative_field ().value (); } } @@ -1149,15 +1150,15 @@ void nano::json_handler::block_info () auto block = node.ledger.block (transaction, hash); if (block != nullptr) { - nano::account account (block->account ().is_zero () ? block->sideband ().account : block->account ()); + auto account = block->account (); response_l.put ("block_account", account.to_account ()); auto amount = node.ledger.amount (transaction, hash); if (amount) { response_l.put ("amount", amount.value ().convert_to ()); } - auto balance = node.ledger.balance (*block); - response_l.put ("balance", balance.convert_to ()); + auto balance = block->balance (); + response_l.put ("balance", balance.number ().convert_to ()); response_l.put ("height", std::to_string (block->sideband ().height)); response_l.put ("local_timestamp", std::to_string (block->sideband ().timestamp)); response_l.put ("successor", block->sideband ().successor.to_string ()); @@ -1214,7 +1215,7 @@ void nano::json_handler::block_confirm () nano::election_status status{ block_l, 0, 0, std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()), std::chrono::duration_values::zero (), 0, 1, 0, nano::election_status_type::active_confirmation_height }; node.active.recently_cemented.put (status); // Trigger callback for confirmed block - auto account = node.ledger.account (*block_l); + auto account = block_l->account (); auto amount = node.ledger.amount (transaction, hash); bool is_state_send (false); bool is_state_epoch (false); @@ -1222,8 +1223,8 @@ void nano::json_handler::block_confirm () { if (auto state = dynamic_cast (block_l.get ())) { - is_state_send = node.ledger.is_send (transaction, *state); - is_state_epoch = amount.value () == 0 && node.ledger.is_epoch_link (state->link ()); + is_state_send = state->is_send (); + is_state_epoch = amount.value () == 0 && node.ledger.is_epoch_link (state->link_field ().value ()); } } node.observers.blocks.notify (status, {}, account, amount ? amount.value () : 0, is_state_send, is_state_epoch); @@ -1306,15 +1307,15 @@ void nano::json_handler::blocks_info () if (block != nullptr) { boost::property_tree::ptree entry; - nano::account account (block->account ().is_zero () ? block->sideband ().account : block->account ()); + auto account = block->account (); entry.put ("block_account", account.to_account ()); auto amount = node.ledger.amount (transaction, hash); if (amount) { entry.put ("amount", amount.value ().convert_to ()); } - auto balance = node.ledger.balance (*block); - entry.put ("balance", balance.convert_to ()); + auto balance = block->balance (); + entry.put ("balance", balance.number ().convert_to ()); entry.put ("height", std::to_string (block->sideband ().height)); entry.put ("local_timestamp", std::to_string (block->sideband ().timestamp)); entry.put ("successor", block->sideband ().successor.to_string ()); @@ -1382,16 +1383,15 @@ void nano::json_handler::blocks_info () } if (source) { - nano::block_hash source_hash (node.ledger.block_source (transaction, *block)); - auto block_a = node.ledger.block (transaction, source_hash); - if (block_a != nullptr) + if (!block->is_receive () || !node.ledger.block_exists (transaction, block->source ())) { - auto source_account (node.ledger.account (*block_a)); - entry.put ("source_account", source_account.to_account ()); + entry.put ("source_account", "0"); } else { - entry.put ("source_account", "0"); + auto block_a = node.ledger.block (transaction, block->source ()); + release_assert (block_a); + entry.put ("source_account", block_a->account ().to_account ()); } } blocks.push_back (std::make_pair (hash_text, entry)); @@ -1433,7 +1433,7 @@ void nano::json_handler::block_account () auto block = node.ledger.block (transaction, hash); if (block) { - response_l.put ("account", node.ledger.account (*block).to_account ()); + response_l.put ("account", block->account ().to_account ()); } else { @@ -1613,10 +1613,10 @@ void nano::json_handler::block_create () // Wrapper from argument to lambda capture, to extend the block's scope auto get_callback_l = [rpc_l, block_response_put_l] (std::shared_ptr const & block_a) { // Callback upon work generation success or failure - return [block_a, rpc_l, block_response_put_l] (boost::optional const & work_a) { + return [block_a, rpc_l, block_response_put_l] (std::optional const & work_a) { if (block_a != nullptr) { - if (work_a.is_initialized ()) + if (work_a.has_value ()) { block_a->block_work_set (*work_a); block_response_put_l (*block_a); @@ -2522,7 +2522,7 @@ public: if (raw && accounts_filter.empty ()) { tree.put ("subtype", "epoch"); - tree.put ("account", handler.node.ledger.epoch_signer (block_a.link ()).to_account ()); + tree.put ("account", handler.node.ledger.epoch_signer (block_a.link_field ().value ()).to_account ()); } } else @@ -3641,7 +3641,7 @@ void nano::json_handler::republish () block = node.ledger.block (transaction, hash); if (sources != 0) // Republish source chain { - nano::block_hash source (node.ledger.block_source (transaction, *block)); + nano::block_hash source = block->source_field ().value_or (block->link_field ().value_or (0).as_block_hash ()); auto block_a = node.ledger.block (transaction, source); std::vector hashes; while (block_a != nullptr && hashes.size () < sources) @@ -3679,7 +3679,7 @@ void nano::json_handler::republish () while (block_d != nullptr && hash != source) { hashes.push_back (previous); - source = node.ledger.block_source (transaction, *block_d); + source = block_d->source_field ().value_or (block_d->is_send () ? 0 : block_d->link_field ().value_or (0).as_block_hash ()); previous = block_d->previous (); block_d = node.ledger.block (transaction, previous); } @@ -4994,7 +4994,7 @@ void nano::json_handler::wallet_work_get () void nano::json_handler::work_generate () { - boost::optional account; + std::optional account; auto account_opt (request.get_optional ("account")); // Default to work_1 if not specified auto work_version (work_version_optional_impl (nano::work_version::work_1)); @@ -5046,7 +5046,7 @@ void nano::json_handler::work_generate () { auto use_peers (request.get ("use_peers", false)); auto rpc_l (shared_from_this ()); - auto callback = [rpc_l, hash, work_version, this] (boost::optional const & work_a) { + auto callback = [rpc_l, hash, work_version, this] (std::optional const & work_a) { if (work_a) { boost::property_tree::ptree response_l; diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 241c66eaa..0a49c4c74 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -246,13 +246,13 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons // Subtype field else if (block_a->type () == nano::block_type::state) { - if (block_a->link ().is_zero ()) + if (block_a->is_change ()) { event.add ("subtype", "change"); } else if (is_state_epoch_a) { - debug_assert (amount_a == 0 && node_l->ledger.is_epoch_link (block_a->link ())); + debug_assert (amount_a == 0 && node_l->ledger.is_epoch_link (block_a->link_field ().value ())); event.add ("subtype", "epoch"); } else @@ -1066,50 +1066,50 @@ bool nano::node::work_generation_enabled (std::vector nano::node::work_generate_blocking (nano::block & block_a, uint64_t difficulty_a) +std::optional nano::node::work_generate_blocking (nano::block & block_a, uint64_t difficulty_a) { - auto opt_work_l (work_generate_blocking (block_a.work_version (), block_a.root (), difficulty_a, block_a.account ())); - if (opt_work_l.is_initialized ()) + auto opt_work_l (work_generate_blocking (block_a.work_version (), block_a.root (), difficulty_a, block_a.account_field ())); + if (opt_work_l.has_value ()) { - block_a.block_work_set (*opt_work_l); + block_a.block_work_set (opt_work_l.value ()); } return opt_work_l; } -void nano::node::work_generate (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::function)> callback_a, boost::optional const & account_a, bool secondary_work_peers_a) +void nano::node::work_generate (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::function)> callback_a, std::optional const & account_a, bool secondary_work_peers_a) { auto const & peers_l (secondary_work_peers_a ? config.secondary_work_peers : config.work_peers); if (distributed_work.make (version_a, root_a, peers_l, difficulty_a, callback_a, account_a)) { // Error in creating the job (either stopped or work generation is not possible) - callback_a (boost::none); + callback_a (std::nullopt); } } -boost::optional nano::node::work_generate_blocking (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, boost::optional const & account_a) +std::optional nano::node::work_generate_blocking (nano::work_version const version_a, nano::root const & root_a, uint64_t difficulty_a, std::optional const & account_a) { - std::promise> promise; + std::promise> promise; work_generate ( - version_a, root_a, difficulty_a, [&promise] (boost::optional opt_work_a) { + version_a, root_a, difficulty_a, [&promise] (std::optional opt_work_a) { promise.set_value (opt_work_a); }, account_a); return promise.get_future ().get (); } -boost::optional nano::node::work_generate_blocking (nano::block & block_a) +std::optional nano::node::work_generate_blocking (nano::block & block_a) { debug_assert (network_params.network.is_dev_network ()); return work_generate_blocking (block_a, default_difficulty (nano::work_version::work_1)); } -boost::optional nano::node::work_generate_blocking (nano::root const & root_a) +std::optional nano::node::work_generate_blocking (nano::root const & root_a) { debug_assert (network_params.network.is_dev_network ()); return work_generate_blocking (root_a, default_difficulty (nano::work_version::work_1)); } -boost::optional nano::node::work_generate_blocking (nano::root const & root_a, uint64_t difficulty_a) +std::optional nano::node::work_generate_blocking (nano::root const & root_a, uint64_t difficulty_a) { debug_assert (network_params.network.is_dev_network ()); return work_generate_blocking (nano::work_version::work_1, root_a, difficulty_a); @@ -1215,19 +1215,15 @@ void nano::node::process_confirmed_data (store::transaction const & transaction_ { // Faster account calculation account_a = block_a->account (); - if (account_a.is_zero ()) - { - account_a = block_a->sideband ().account; - } // Faster amount calculation auto previous (block_a->previous ()); auto previous_balance = ledger.balance (transaction_a, previous); - auto block_balance = ledger.balance (*block_a); + auto block_balance = block_a->balance (); if (hash_a != ledger.constants.genesis->account ()) { if (previous_balance) { - amount_a = block_balance > previous_balance.value () ? block_balance - previous_balance.value () : previous_balance.value () - block_balance; + amount_a = block_balance > previous_balance.value () ? block_balance.number () - previous_balance.value () : previous_balance.value () - block_balance.number (); } else { @@ -1244,7 +1240,7 @@ void nano::node::process_confirmed_data (store::transaction const & transaction_ { is_state_send_a = true; } - if (amount_a == 0 && network_params.ledger.epochs.is_epoch_link (state->link ())) + if (amount_a == 0 && network_params.ledger.epochs.is_epoch_link (state->link_field ().value ())) { is_state_epoch_a = true; } diff --git a/nano/node/node.hpp b/nano/node/node.hpp index dec8f964a..3c09cff68 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -43,6 +43,7 @@ #include #include +#include #include namespace nano @@ -109,9 +110,9 @@ public: bool local_work_generation_enabled () const; bool work_generation_enabled () const; bool work_generation_enabled (std::vector> const &) const; - boost::optional work_generate_blocking (nano::block &, uint64_t); - boost::optional work_generate_blocking (nano::work_version const, nano::root const &, uint64_t, boost::optional const & = boost::none); - void work_generate (nano::work_version const, nano::root const &, uint64_t, std::function)>, boost::optional const & = boost::none, bool const = false); + std::optional work_generate_blocking (nano::block &, uint64_t); + std::optional work_generate_blocking (nano::work_version const, nano::root const &, uint64_t, std::optional const & = std::nullopt); + void work_generate (nano::work_version const, nano::root const &, uint64_t, std::function)>, std::optional const & = std::nullopt, bool const = false); void add_initial_peers (); void start_election (std::shared_ptr const & block); bool block_confirmed (nano::block_hash const &); @@ -197,11 +198,11 @@ public: // For tests only unsigned node_seq; // For tests only - boost::optional work_generate_blocking (nano::block &); + std::optional work_generate_blocking (nano::block &); // For tests only - boost::optional work_generate_blocking (nano::root const &, uint64_t); + std::optional work_generate_blocking (nano::root const &, uint64_t); // For tests only - boost::optional work_generate_blocking (nano::root const &); + std::optional work_generate_blocking (nano::root const &); public: // Testing convenience functions /** diff --git a/nano/node/process_live_dispatcher.cpp b/nano/node/process_live_dispatcher.cpp index 8411851d4..f0d457dbe 100644 --- a/nano/node/process_live_dispatcher.cpp +++ b/nano/node/process_live_dispatcher.cpp @@ -45,8 +45,7 @@ void nano::process_live_dispatcher::process_live (nano::block const & block, sto // Start collecting quorum on block if (ledger.dependents_confirmed (transaction, block)) { - auto account = block.account ().is_zero () ? block.sideband ().account : block.account (); - scheduler.activate (account, transaction); + scheduler.activate (block.account (), transaction); } if (websocket.server && websocket.server->any_subscriber (nano::websocket::topic::new_unconfirmed_block)) diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index f822ace91..0e61195e8 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -229,7 +229,7 @@ std::pair>, std::vectoraccount ().is_zero () ? block->sideband ().account : block->account (), confirmation_height_info); + ledger.store.confirmation_height.get (transaction, block->account (), confirmation_height_info); generate_final_vote = (confirmation_height_info.height >= block->sideband ().height); } } @@ -265,7 +265,7 @@ std::pair>, std::vectoraccount ().is_zero () ? block->sideband ().account : block->account (), confirmation_height_info); + ledger.store.confirmation_height.get (transaction, block->account (), confirmation_height_info); generate_final_vote = (confirmation_height_info.height >= block->sideband ().height); } } diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 53380f4b3..e155ecb6c 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1050,7 +1050,7 @@ bool nano::wallet::action_complete (std::shared_ptr const & block_a account_a.to_account ()); debug_assert (required_difficulty <= wallets.node.max_work_generate_difficulty (block_a->work_version ())); - error = !wallets.node.work_generate_blocking (*block_a, required_difficulty).is_initialized (); + error = !wallets.node.work_generate_blocking (*block_a, required_difficulty).has_value (); } if (!error) { @@ -1092,9 +1092,8 @@ bool nano::wallet::receive_sync (std::shared_ptr const & block_a, n { std::promise result; std::future future = result.get_future (); - auto destination (block_a->link ().is_zero () ? block_a->destination () : block_a->link ().as_account ()); receive_async ( - block_a->hash (), representative_a, amount_a, destination, [&result] (std::shared_ptr const & block_a) { + block_a->hash (), representative_a, amount_a, block_a->destination (), [&result] (std::shared_ptr const & block_a) { result.set_value (block_a == nullptr); }, true); @@ -1298,12 +1297,12 @@ void nano::wallet::work_cache_blocking (nano::account const & account_a, nano::r { auto difficulty (wallets.node.default_difficulty (nano::work_version::work_1)); auto opt_work_l (wallets.node.work_generate_blocking (nano::work_version::work_1, root_a, difficulty, account_a)); - if (opt_work_l.is_initialized ()) + if (opt_work_l.has_value ()) { auto transaction_l (wallets.tx_begin_write ()); if (live () && store.exists (transaction_l, account_a)) { - work_update (transaction_l, account_a, root_a, *opt_work_l); + work_update (transaction_l, account_a, root_a, opt_work_l.value ()); } } else if (!wallets.node.stopped) diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index dbd16637a..e33d1c889 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -1012,13 +1012,13 @@ nano::websocket_server::websocket_server (nano::websocket::config & config_a, na } else if (block_a->type () == nano::block_type::state) { - if (block_a->link ().is_zero ()) + if (block_a->is_change ()) { subtype = "change"; } else if (is_state_epoch_a) { - debug_assert (amount_a == 0 && ledger.is_epoch_link (block_a->link ())); + debug_assert (amount_a == 0 && ledger.is_epoch_link (block_a->link_field ().value ())); subtype = "epoch"; } else diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 22c4221ca..640080b55 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -2253,7 +2253,7 @@ void nano_qt::block_creation::create_send () details.is_send = true; details.epoch = info.epoch (); auto const required_difficulty{ wallet.node.network_params.work.threshold (send.work_version (), details) }; - if (wallet.node.work_generate_blocking (send, required_difficulty).is_initialized ()) + if (wallet.node.work_generate_blocking (send, required_difficulty).has_value ()) { std::string block_l; send.serialize_json (block_l); @@ -2337,7 +2337,7 @@ void nano_qt::block_creation::create_receive () details.is_receive = true; details.epoch = std::max (info.epoch (), pending.epoch); auto required_difficulty{ wallet.node.network_params.work.threshold (receive.work_version (), details) }; - if (wallet.node.work_generate_blocking (receive, required_difficulty).is_initialized ()) + if (wallet.node.work_generate_blocking (receive, required_difficulty).has_value ()) { std::string block_l; receive.serialize_json (block_l); @@ -2420,7 +2420,7 @@ void nano_qt::block_creation::create_change () nano::block_details details; details.epoch = info.epoch (); auto const required_difficulty{ wallet.node.network_params.work.threshold (change.work_version (), details) }; - if (wallet.node.work_generate_blocking (change, required_difficulty).is_initialized ()) + if (wallet.node.work_generate_blocking (change, required_difficulty).has_value ()) { std::string block_l; change.serialize_json (block_l); @@ -2502,7 +2502,7 @@ void nano_qt::block_creation::create_open () details.is_receive = true; details.epoch = pending.epoch; auto const required_difficulty{ wallet.node.network_params.work.threshold (open.work_version (), details) }; - if (wallet.node.work_generate_blocking (open, required_difficulty).is_initialized ()) + if (wallet.node.work_generate_blocking (open, required_difficulty).has_value ()) { std::string block_l; open.serialize_json (block_l); diff --git a/nano/qt_test/qt.cpp b/nano/qt_test/qt.cpp index 6ff9e931f..313378e0f 100644 --- a/nano/qt_test/qt.cpp +++ b/nano/qt_test/qt.cpp @@ -360,7 +360,7 @@ TEST (wallet, DISABLED_process_block) nano_qt::eventloop_processor processor; nano::test::system system (1); nano::account account; - nano::block_hash latest (system.nodes[0]->latest (nano::dev::genesis->account ())); + nano::block_hash latest (system.nodes[0]->latest (nano::dev::genesis_key.pub)); system.wallet (0)->insert_adhoc (nano::keypair ().prv); { auto transaction (system.nodes[0]->wallets.tx_begin_read ()); @@ -665,7 +665,7 @@ TEST (wallet, block_viewer) ASSERT_NE (-1, wallet->advanced.layout->indexOf (wallet->advanced.block_viewer)); QTest::mouseClick (wallet->advanced.block_viewer, Qt::LeftButton); ASSERT_EQ (wallet->block_viewer.window, wallet->main_stack->currentWidget ()); - nano::block_hash latest (system.nodes[0]->latest (nano::dev::genesis->account ())); + nano::block_hash latest (system.nodes[0]->latest (nano::dev::genesis_key.pub)); QTest::keyClicks (wallet->block_viewer.hash, latest.to_string ().c_str ()); QTest::mouseClick (wallet->block_viewer.retrieve, Qt::LeftButton); ASSERT_FALSE (wallet->block_viewer.block->toPlainText ().toStdString ().empty ()); @@ -916,7 +916,7 @@ TEST (wallet, DISABLED_synchronizing) wallet->start (); { auto transaction (system1.nodes[0]->store.tx_begin_write ()); - auto latest (system1.nodes[0]->ledger.latest (transaction, nano::dev::genesis->account ())); + auto latest (system1.nodes[0]->ledger.latest (transaction, nano::dev::genesis_key.pub)); auto send = std::make_shared (latest, key1, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system1.work.generate (latest)); system1.nodes[0]->ledger.process (transaction, send); } diff --git a/nano/rpc_test/receivable.cpp b/nano/rpc_test/receivable.cpp index 658216169..d2659aac1 100644 --- a/nano/rpc_test/receivable.cpp +++ b/nano/rpc_test/receivable.cpp @@ -21,7 +21,7 @@ TEST (rpc, receivable) auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "receivable"); - request.put ("account", block1->link ().to_account ()); + request.put ("account", block1->destination ().to_account ()); auto response = wait_response (system, rpc_ctx, request); auto & blocks_node = response.get_child ("blocks"); ASSERT_EQ (1, blocks_node.size ()); @@ -39,7 +39,7 @@ TEST (rpc, receivable_sorting) auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "receivable"); - request.put ("account", block1->link ().to_account ()); + request.put ("account", block1->destination ().to_account ()); request.put ("sorting", "true"); // Sorting test auto response = wait_response (system, rpc_ctx, request); auto & blocks_node = response.get_child ("blocks"); @@ -60,7 +60,7 @@ TEST (rpc, receivable_threshold_sufficient) auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "receivable"); - request.put ("account", block1->link ().to_account ()); + request.put ("account", block1->destination ().to_account ()); request.put ("threshold", "1"); // Threshold test auto response = wait_response (system, rpc_ctx, request); auto & blocks_node = response.get_child ("blocks"); @@ -91,7 +91,7 @@ TEST (rpc, receivable_threshold_insufficient) auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "receivable"); - request.put ("account", block1->link ().to_account ()); + request.put ("account", block1->destination ().to_account ()); request.put ("threshold", "2"); // Chains are set up with 1 raw transfers therefore all blocks are less than 2 raw. auto response = wait_response (system, rpc_ctx, request, 10s); auto & blocks_node = response.get_child ("blocks"); @@ -108,7 +108,7 @@ TEST (rpc, receivable_source_min_version) auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "receivable"); - request.put ("account", block1->link ().to_account ()); + request.put ("account", block1->destination ().to_account ()); request.put ("source", "true"); request.put ("min_version", "true"); auto response (wait_response (system, rpc_ctx, request)); @@ -140,7 +140,7 @@ TEST (rpc, receivable_unconfirmed) auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "receivable"); - request.put ("account", block1->link ().to_account ()); + request.put ("account", block1->destination ().to_account ()); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 0)); request.put ("include_only_confirmed", "true"); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 0)); @@ -197,7 +197,7 @@ TEST (rpc, receivable_offset_and_sorting) // check confirmation height is as expected, there is no perfect clarity yet when confirmation height updates after a block get confirmed nano::confirmation_height_info confirmation_height_info; - ASSERT_FALSE (node->store.confirmation_height.get (node->store.tx_begin_read (), nano::dev::genesis->account (), confirmation_height_info)); + ASSERT_FALSE (node->store.confirmation_height.get (node->store.tx_begin_read (), nano::dev::genesis_key.pub, confirmation_height_info)); ASSERT_EQ (confirmation_height_info.height, 7); ASSERT_EQ (confirmation_height_info.frontier, block6->hash ()); @@ -410,14 +410,14 @@ TEST (rpc, accounts_receivable_blocks) request.put ("action", "accounts_receivable"); boost::property_tree::ptree entry; boost::property_tree::ptree peers_l; - entry.put ("", block1->link ().to_account ()); + entry.put ("", block1->destination ().to_account ()); peers_l.push_back (std::make_pair ("", entry)); request.add_child ("accounts", peers_l); auto response = wait_response (system, rpc_ctx, request); for (auto & blocks : response.get_child ("blocks")) { std::string account_text{ blocks.first }; - ASSERT_EQ (block1->link ().to_account (), account_text); + ASSERT_EQ (block1->destination ().to_account (), account_text); nano::block_hash hash1{ blocks.second.begin ()->second.get ("") }; ASSERT_EQ (block1->hash (), hash1); } @@ -436,7 +436,7 @@ TEST (rpc, accounts_receivable_sorting) request.put ("action", "accounts_receivable"); boost::property_tree::ptree entry; boost::property_tree::ptree peers_l; - entry.put ("", block1->link ().to_account ()); + entry.put ("", block1->destination ().to_account ()); peers_l.push_back (std::make_pair ("", entry)); request.add_child ("accounts", peers_l); request.put ("sorting", "true"); // Sorting test @@ -444,7 +444,7 @@ TEST (rpc, accounts_receivable_sorting) for (auto & blocks : response.get_child ("blocks")) { std::string account_text{ blocks.first }; - ASSERT_EQ (block1->link ().to_account (), account_text); + ASSERT_EQ (block1->destination ().to_account (), account_text); nano::block_hash hash1{ blocks.second.begin ()->first }; ASSERT_EQ (block1->hash (), hash1); std::string amount{ blocks.second.begin ()->second.get ("") }; @@ -465,7 +465,7 @@ TEST (rpc, accounts_receivable_threshold) request.put ("action", "accounts_receivable"); boost::property_tree::ptree entry; boost::property_tree::ptree peers_l; - entry.put ("", block1->link ().to_account ()); + entry.put ("", block1->destination ().to_account ()); peers_l.push_back (std::make_pair ("", entry)); request.add_child ("accounts", peers_l); request.put ("threshold", "1"); // Threshold test @@ -474,7 +474,7 @@ TEST (rpc, accounts_receivable_threshold) for (auto & pending : response.get_child ("blocks")) { std::string account_text{ pending.first }; - ASSERT_EQ (block1->link ().to_account (), account_text); + ASSERT_EQ (block1->destination ().to_account (), account_text); for (auto i (pending.second.begin ()), j (pending.second.end ()); i != j; ++i) { nano::block_hash hash; @@ -501,7 +501,7 @@ TEST (rpc, accounts_receivable_source) request.put ("action", "accounts_receivable"); boost::property_tree::ptree entry; boost::property_tree::ptree peers_l; - entry.put ("", block1->link ().to_account ()); + entry.put ("", block1->destination ().to_account ()); peers_l.push_back (std::make_pair ("", entry)); request.add_child ("accounts", peers_l); request.put ("source", "true"); @@ -512,7 +512,7 @@ TEST (rpc, accounts_receivable_source) for (auto & pending : response.get_child ("blocks")) { std::string account_text (pending.first); - ASSERT_EQ (block1->link ().to_account (), account_text); + ASSERT_EQ (block1->destination ().to_account (), account_text); for (auto i (pending.second.begin ()), j (pending.second.end ()); i != j; ++i) { nano::block_hash hash; @@ -540,7 +540,7 @@ TEST (rpc, accounts_receivable_confirmed) request.put ("action", "accounts_receivable"); boost::property_tree::ptree entry; boost::property_tree::ptree peers_l; - entry.put ("", block1->link ().to_account ()); + entry.put ("", block1->destination ().to_account ()); peers_l.push_back (std::make_pair ("", entry)); request.add_child ("accounts", peers_l); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index f6fe1b065..3e7f70346 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -505,7 +505,7 @@ TEST (rpc, wallet_representative) request.put ("action", "wallet_representative"); auto response (wait_response (system, rpc_ctx, request)); std::string account_text1 (response.get ("representative")); - ASSERT_EQ (account_text1, nano::dev::genesis->account ().to_account ()); + ASSERT_EQ (account_text1, nano::dev::genesis_key.pub.to_account ()); } TEST (rpc, wallet_representative_set) @@ -663,7 +663,7 @@ TEST (rpc, wallet_export) bool error (false); auto transaction (node->wallets.tx_begin_write ()); nano::kdf kdf{ nano::dev::network_params.kdf_work }; - nano::wallet_store store (error, kdf, transaction, node->wallets.env, nano::dev::genesis->account (), 1, "0", wallet_json); + nano::wallet_store store (error, kdf, transaction, node->wallets.env, nano::dev::genesis_key.pub, 1, "0", wallet_json); ASSERT_FALSE (error); ASSERT_TRUE (store.exists (transaction, nano::dev::genesis_key.pub)); } @@ -718,7 +718,7 @@ TEST (rpc, block) auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "block"); - request.put ("hash", node->latest (nano::dev::genesis->account ()).to_string ()); + request.put ("hash", node->latest (nano::dev::genesis_key.pub).to_string ()); auto response (wait_response (system, rpc_ctx, request)); auto contents (response.get ("contents")); ASSERT_FALSE (contents.empty ()); @@ -923,24 +923,24 @@ TEST (rpc, history) ASSERT_NE (nullptr, change); auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, node0->config.receive_minimum.number ())); ASSERT_NE (nullptr, send); - auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node0->config.receive_minimum.number (), send->link ().as_account ())); + auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node0->config.receive_minimum.number (), send->destination ())); ASSERT_NE (nullptr, receive); nano::block_builder builder; auto usend = builder .state () - .account (nano::dev::genesis->account ()) - .previous (node0->latest (nano::dev::genesis->account ())) - .representative (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) + .previous (node0->latest (nano::dev::genesis_key.pub)) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*node0->work_generate_blocking (node0->latest (nano::dev::genesis->account ()))) + .work (*node0->work_generate_blocking (node0->latest (nano::dev::genesis_key.pub))) .build (); auto ureceive = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (usend->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (usend->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -948,7 +948,7 @@ TEST (rpc, history) .build (); auto uchange = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (ureceive->hash ()) .representative (nano::keypair ().pub) .balance (nano::dev::constants.genesis_amount) @@ -1007,24 +1007,24 @@ TEST (rpc, account_history) ASSERT_NE (nullptr, change); auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, node0->config.receive_minimum.number ())); ASSERT_NE (nullptr, send); - auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node0->config.receive_minimum.number (), send->link ().as_account ())); + auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node0->config.receive_minimum.number (), send->destination ())); ASSERT_NE (nullptr, receive); nano::block_builder builder; auto usend = builder .state () - .account (nano::dev::genesis->account ()) - .previous (node0->latest (nano::dev::genesis->account ())) - .representative (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) + .previous (node0->latest (nano::dev::genesis_key.pub)) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*node0->work_generate_blocking (node0->latest (nano::dev::genesis->account ()))) + .work (*node0->work_generate_blocking (node0->latest (nano::dev::genesis_key.pub))) .build (); auto ureceive = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (usend->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (usend->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -1032,7 +1032,7 @@ TEST (rpc, account_history) .build (); auto uchange = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (ureceive->hash ()) .representative (nano::keypair ().pub) .balance (nano::dev::constants.genesis_amount) @@ -1050,7 +1050,7 @@ TEST (rpc, account_history) { boost::property_tree::ptree request; request.put ("action", "account_history"); - request.put ("account", nano::dev::genesis->account ().to_account ()); + request.put ("account", nano::dev::genesis_key.pub.to_account ()); request.put ("count", 100); auto response (wait_response (system, rpc_ctx, request, 10s)); std::vector> history_l; @@ -1096,7 +1096,7 @@ TEST (rpc, account_history) { boost::property_tree::ptree request; request.put ("action", "account_history"); - request.put ("account", nano::dev::genesis->account ().to_account ()); + request.put ("account", nano::dev::genesis_key.pub.to_account ()); request.put ("reverse", true); request.put ("count", 1); auto response (wait_response (system, rpc_ctx, request, 10s)); @@ -1110,7 +1110,7 @@ TEST (rpc, account_history) auto account2 (system.wallet (0)->deterministic_insert ()); auto send2 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, account2, node0->config.receive_minimum.number ())); ASSERT_NE (nullptr, send2); - auto receive2 (system.wallet (0)->receive_action (send2->hash (), account2, node0->config.receive_minimum.number (), send2->link ().as_account ())); + auto receive2 (system.wallet (0)->receive_action (send2->hash (), account2, node0->config.receive_minimum.number (), send2->destination ())); // Test filter for send state blocks ASSERT_NE (nullptr, receive2); { @@ -1153,7 +1153,7 @@ TEST (rpc, history_count) ASSERT_NE (nullptr, change); auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, node->config.receive_minimum.number ())); ASSERT_NE (nullptr, send); - auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node->config.receive_minimum.number (), send->link ().as_account ())); + auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node->config.receive_minimum.number (), send->destination ())); ASSERT_NE (nullptr, receive); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; @@ -1211,11 +1211,11 @@ TEST (rpc, history_pruning) // non legacy self send auto usend = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (receive->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) - .link (nano::dev::genesis->account ()) + .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node0->work_generate_blocking (receive->hash ())) .build (); @@ -1224,9 +1224,9 @@ TEST (rpc, history_pruning) // non legacy receive of the non legacy self send auto ureceive = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (usend->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount) .link (usend->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -1237,7 +1237,7 @@ TEST (rpc, history_pruning) // change genesis to a random rep auto uchange = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (ureceive->hash ()) .representative (nano::keypair ().pub) .balance (nano::dev::constants.genesis_amount) @@ -1514,9 +1514,9 @@ TEST (rpc, process_subtype_send) nano::block_builder builder; auto send = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (latest) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -1550,9 +1550,9 @@ TEST (rpc, process_subtype_open) nano::block_builder builder; auto send = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (latest) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -1599,9 +1599,9 @@ TEST (rpc, process_subtype_receive) nano::block_builder builder; auto send = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (latest) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .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) @@ -1652,9 +1652,9 @@ TEST (rpc, process_ledger_insufficient_work) nano::block_builder builder; auto send = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (latest) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .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) @@ -2088,9 +2088,9 @@ TEST (rpc, work_peer_bad) auto const rpc_ctx = add_rpc (system, node1); nano::block_hash hash1 (1); std::atomic work (0); - node2.work_generate (nano::work_version::work_1, hash1, node2.network_params.work.base, [&work] (boost::optional work_a) { - ASSERT_TRUE (work_a.is_initialized ()); - work = *work_a; + node2.work_generate (nano::work_version::work_1, hash1, node2.network_params.work.base, [&work] (std::optional work_a) { + ASSERT_TRUE (work_a.has_value ()); + work = work_a.value (); }); ASSERT_TIMELY (5s, nano::dev::network_params.work.difficulty (nano::work_version::work_1, hash1, work) >= nano::dev::network_params.work.threshold_base (nano::work_version::work_1)); } @@ -2107,9 +2107,9 @@ TEST (rpc, DISABLED_work_peer_one) node2.config.work_peers.emplace_back (node1->network.endpoint ().address ().to_string (), rpc_ctx.rpc->listening_port ()); nano::keypair key1; std::atomic work (0); - node2.work_generate (nano::work_version::work_1, key1.pub, node1->network_params.work.base, [&work] (boost::optional work_a) { - ASSERT_TRUE (work_a.is_initialized ()); - work = *work_a; + node2.work_generate (nano::work_version::work_1, key1.pub, node1->network_params.work.base, [&work] (std::optional work_a) { + ASSERT_TRUE (work_a.has_value ()); + work = work_a.value (); }); ASSERT_TIMELY (5s, nano::dev::network_params.work.difficulty (nano::work_version::work_1, key1.pub, work) >= nano::dev::network_params.work.threshold_base (nano::work_version::work_1)); } @@ -2138,7 +2138,7 @@ TEST (rpc, DISABLED_work_peer_many) for (auto & work : works) { nano::keypair key1; - node1.work_generate (nano::work_version::work_1, key1.pub, node1.network_params.work.base, [&work] (boost::optional work_a) { + node1.work_generate (nano::work_version::work_1, key1.pub, node1.network_params.work.base, [&work] (std::optional work_a) { work = *work_a; }); while (nano::dev::network_params.work.difficulty (nano::work_version::work_1, key1.pub, work) < nano::dev::network_params.work.threshold_base (nano::work_version::work_1)) @@ -2377,11 +2377,11 @@ TEST (rpc, account_representative) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; - request.put ("account", nano::dev::genesis->account ().to_account ()); + request.put ("account", nano::dev::genesis_key.pub.to_account ()); request.put ("action", "account_representative"); auto response (wait_response (system, rpc_ctx, request)); std::string account_text1 (response.get ("representative")); - ASSERT_EQ (account_text1, nano::dev::genesis->account ().to_account ()); + ASSERT_EQ (account_text1, nano::dev::genesis_key.pub.to_account ()); } TEST (rpc, account_representative_set) @@ -2397,7 +2397,7 @@ TEST (rpc, account_representative_set) auto key2_open_block_hash = wallet.send_sync (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number ()); ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), key2_open_block_hash)); auto key2_open_block = node->ledger.block (node->store.tx_begin_read (), key2_open_block_hash); - ASSERT_EQ (nano::dev::genesis_key.pub, key2_open_block->representative ()); + ASSERT_EQ (nano::dev::genesis_key.pub, key2_open_block->representative_field ().value ()); // now change the representative of key2 to be genesis auto const rpc_ctx = add_rpc (system, node); @@ -2416,7 +2416,7 @@ TEST (rpc, account_representative_set) auto block = node->ledger.block (node->store.tx_begin_read (), hash); ASSERT_NE (block, nullptr); ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), hash)); - ASSERT_EQ (key2.pub, block->representative ()); + ASSERT_EQ (key2.pub, block->representative_field ().value ()); } TEST (rpc, account_representative_set_work_disabled) @@ -2429,7 +2429,7 @@ TEST (rpc, account_representative_set_work_disabled) auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; nano::keypair rep; - request.put ("account", nano::dev::genesis->account ().to_account ()); + request.put ("account", nano::dev::genesis_key.pub.to_account ()); request.put ("representative", rep.pub.to_account ()); request.put ("wallet", node->wallets.items.begin ()->first.to_string ()); request.put ("action", "account_representative_set"); @@ -2491,7 +2491,7 @@ TEST (rpc, bootstrap) auto send = builder .send () .previous (latest) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (100) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node1->work_generate_blocking (latest)) @@ -2511,7 +2511,7 @@ TEST (rpc, bootstrap) system0.poll (); } system1.deadline_set (10s); - while (node->latest (nano::dev::genesis->account ()) != node1->latest (nano::dev::genesis->account ())) + while (node->latest (nano::dev::genesis_key.pub) != node1->latest (nano::dev::genesis_key.pub)) { ASSERT_NO_ERROR (system0.poll ()); ASSERT_NO_ERROR (system1.poll ()); @@ -2550,7 +2550,7 @@ TEST (rpc, representatives) representatives.push_back (account); } ASSERT_EQ (1, representatives.size ()); - ASSERT_EQ (nano::dev::genesis->account (), representatives[0]); + ASSERT_EQ (nano::dev::genesis_key.pub, representatives[0]); } // wallet_seed is only available over IPC's unsafe encoding, and when running on test network @@ -2626,7 +2626,7 @@ TEST (rpc, wallet_frontiers) frontiers.push_back (nano::account (i->second.get (""))); } ASSERT_EQ (1, frontiers.size ()); - ASSERT_EQ (node->latest (nano::dev::genesis->account ()), frontiers[0]); + ASSERT_EQ (node->latest (nano::dev::genesis_key.pub), frontiers[0]); } TEST (rpc, work_validate) @@ -2776,7 +2776,7 @@ TEST (rpc, bootstrap_any) auto send = builder .send () .previous (latest) - .destination (nano::dev::genesis->account ()) + .destination (nano::dev::genesis_key.pub) .balance (100) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system1.nodes[0]->work_generate_blocking (latest)) @@ -3051,8 +3051,8 @@ TEST (rpc, accounts_representatives) request.add_child ("accounts", accounts); auto response (wait_response (system, rpc_ctx, request)); // Ensures the response is correct. - auto response_representative (response.get_child ("representatives").get (nano::dev::genesis->account ().to_account ())); - ASSERT_EQ (response_representative, nano::dev::genesis->account ().to_account ()); + auto response_representative (response.get_child ("representatives").get (nano::dev::genesis_key.pub.to_account ())); + ASSERT_EQ (response_representative, nano::dev::genesis_key.pub.to_account ()); ASSERT_EQ (response.count ("errors"), 0); } @@ -3093,7 +3093,7 @@ TEST (rpc, accounts_representatives_with_errors) ASSERT_EQ (response.get_child ("representatives").size (), 1); ASSERT_EQ (response.get_child ("representatives").count (nano::dev::genesis_key.pub.to_account ()), 1); auto rep_text = response.get_child ("representatives").get (nano::dev::genesis_key.pub.to_account ()); - ASSERT_EQ (rep_text, nano::dev::genesis->account ().to_account ()); + ASSERT_EQ (rep_text, nano::dev::genesis_key.pub.to_account ()); ASSERT_EQ (response.count ("errors"), 1); ASSERT_EQ (response.get_child ("errors").size (), 2); @@ -3126,7 +3126,7 @@ TEST (rpc, accounts_frontiers) ASSERT_EQ (response.get_child ("frontiers").size (), 1); ASSERT_EQ (response.get_child ("frontiers").count (nano::dev::genesis_key.pub.to_account ()), 1); auto frontier_text = response.get_child ("frontiers").get (nano::dev::genesis_key.pub.to_account ()); - ASSERT_EQ (nano::block_hash{ frontier_text }, node->latest (nano::dev::genesis->account ())); + ASSERT_EQ (nano::block_hash{ frontier_text }, node->latest (nano::dev::genesis_key.pub)); ASSERT_EQ (response.count ("errors"), 0); } @@ -3166,7 +3166,7 @@ TEST (rpc, accounts_frontiers_with_errors) ASSERT_EQ (response.get_child ("frontiers").size (), 1); ASSERT_EQ (response.get_child ("frontiers").count (nano::dev::genesis_key.pub.to_account ()), 1); auto frontier_text = response.get_child ("frontiers").get (nano::dev::genesis_key.pub.to_account ()); - ASSERT_EQ (nano::block_hash{ frontier_text }, node->latest (nano::dev::genesis->account ())); + ASSERT_EQ (nano::block_hash{ frontier_text }, node->latest (nano::dev::genesis_key.pub)); ASSERT_EQ (response.count ("errors"), 1); ASSERT_EQ (response.get_child ("errors").size (), 2); @@ -3185,14 +3185,14 @@ TEST (rpc, blocks) request.put ("action", "blocks"); boost::property_tree::ptree entry; boost::property_tree::ptree peers_l; - entry.put ("", node->latest (nano::dev::genesis->account ()).to_string ()); + entry.put ("", node->latest (nano::dev::genesis_key.pub).to_string ()); peers_l.push_back (std::make_pair ("", entry)); request.add_child ("hashes", peers_l); auto response (wait_response (system, rpc_ctx, request)); for (auto & blocks : response.get_child ("blocks")) { std::string hash_text (blocks.first); - ASSERT_EQ (node->latest (nano::dev::genesis->account ()).to_string (), hash_text); + ASSERT_EQ (node->latest (nano::dev::genesis_key.pub).to_string (), hash_text); std::string blocks_text (blocks.second.get ("")); ASSERT_FALSE (blocks_text.empty ()); } @@ -3291,7 +3291,7 @@ TEST (rpc, pending_exists) auto node = add_ipc_enabled_node (system, config); nano::keypair key1; system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); - auto hash0 (node->latest (nano::dev::genesis->account ())); + auto hash0 (node->latest (nano::dev::genesis_key.pub)); auto block1 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 100)); ASSERT_TIMELY (5s, node->block_confirmed (block1->hash ())); ASSERT_TIMELY (5s, !node->active.active (*block1)); @@ -3467,7 +3467,7 @@ TEST (rpc, work_get) std::string work_text (response.get ("work")); uint64_t work (1); auto transaction (node->wallets.tx_begin_read ()); - node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis->account (), work); + node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis_key.pub, work); ASSERT_EQ (nano::to_string_hex (work), work_text); } @@ -3489,7 +3489,7 @@ TEST (rpc, wallet_work_get) ASSERT_EQ (nano::dev::genesis_key.pub.to_account (), account_text); std::string work_text (works.second.get ("")); uint64_t work (1); - node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis->account (), work); + node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis_key.pub, work); ASSERT_EQ (nano::to_string_hex (work), work_text); } } @@ -3511,7 +3511,7 @@ TEST (rpc, work_set) ASSERT_TRUE (success.empty ()); uint64_t work1 (1); auto transaction (node->wallets.tx_begin_read ()); - node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis->account (), work1); + node->wallets.items.begin ()->second->store.work_get (transaction, nano::dev::genesis_key.pub, work1); ASSERT_EQ (work1, work0); } @@ -3973,9 +3973,9 @@ TEST (rpc, json_block_input) nano::block_builder builder; auto send = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (node1->latest (nano::dev::genesis_key.pub)) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -4042,7 +4042,7 @@ TEST (rpc, blocks_info) for (auto & blocks : response.get_child ("blocks")) { std::string hash_text (blocks.first); - ASSERT_EQ (node->latest (nano::dev::genesis->account ()).to_string (), hash_text); + ASSERT_EQ (node->latest (nano::dev::genesis_key.pub).to_string (), hash_text); std::string account_text (blocks.second.get ("block_account")); ASSERT_EQ (nano::dev::genesis_key.pub.to_account (), account_text); std::string amount_text (blocks.second.get ("amount")); @@ -4066,7 +4066,7 @@ TEST (rpc, blocks_info) request.put ("action", "blocks_info"); boost::property_tree::ptree entry; boost::property_tree::ptree hashes; - entry.put ("", node->latest (nano::dev::genesis->account ()).to_string ()); + entry.put ("", node->latest (nano::dev::genesis_key.pub).to_string ()); hashes.push_back (std::make_pair ("", entry)); request.add_child ("hashes", hashes); { @@ -4126,10 +4126,10 @@ TEST (rpc, blocks_info_receive_hash) auto send4 = system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 4); // do 4 receives, mix up the ordering a little - auto recv1 (system.wallet (0)->receive_action (send1->hash (), key1.pub, node->config.receive_minimum.number (), send1->link ().as_account ())); - auto recv4 (system.wallet (0)->receive_action (send4->hash (), key1.pub, node->config.receive_minimum.number (), send4->link ().as_account ())); - auto recv3 (system.wallet (0)->receive_action (send3->hash (), key1.pub, node->config.receive_minimum.number (), send3->link ().as_account ())); - auto recv2 (system.wallet (0)->receive_action (send2->hash (), key1.pub, node->config.receive_minimum.number (), send2->link ().as_account ())); + auto recv1 (system.wallet (0)->receive_action (send1->hash (), key1.pub, node->config.receive_minimum.number (), send1->destination ())); + auto recv4 (system.wallet (0)->receive_action (send4->hash (), key1.pub, node->config.receive_minimum.number (), send4->destination ())); + auto recv3 (system.wallet (0)->receive_action (send3->hash (), key1.pub, node->config.receive_minimum.number (), send3->destination ())); + auto recv2 (system.wallet (0)->receive_action (send2->hash (), key1.pub, node->config.receive_minimum.number (), send2->destination ())); // function to check that all 4 receive blocks are cemented auto all_blocks_cemented = [node, &key1] () -> bool { @@ -4192,7 +4192,7 @@ TEST (rpc, blocks_info_subtype) system.wallet (0)->insert_adhoc (key.prv); auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, nano::Gxrb_ratio)); ASSERT_NE (nullptr, send); - auto receive (system.wallet (0)->receive_action (send->hash (), key.pub, nano::Gxrb_ratio, send->link ().as_account ())); + auto receive (system.wallet (0)->receive_action (send->hash (), key.pub, nano::Gxrb_ratio, send->destination ())); ASSERT_NE (nullptr, receive); auto change (system.wallet (0)->change_action (nano::dev::genesis_key.pub, key.pub)); ASSERT_NE (nullptr, change); @@ -4769,7 +4769,7 @@ TEST (rpc, block_create_state_open) auto process_result (node->process (state_block)); ASSERT_EQ (nano::block_status::progress, process_result); ASSERT_EQ (state_block->sideband ().details.epoch, nano::epoch::epoch_0); - ASSERT_TRUE (state_block->sideband ().details.is_receive); + ASSERT_TRUE (state_block->is_receive ()); ASSERT_FALSE (node->latest (key.pub).is_zero ()); } @@ -4848,7 +4848,7 @@ TEST (rpc, block_create_open_epoch_v2) auto process_result (node->process (state_block)); ASSERT_EQ (nano::block_status::progress, process_result); ASSERT_EQ (state_block->sideband ().details.epoch, nano::epoch::epoch_2); - ASSERT_TRUE (state_block->sideband ().details.is_receive); + ASSERT_TRUE (state_block->is_receive ()); ASSERT_FALSE (node->latest (key.pub).is_zero ()); } @@ -4900,7 +4900,7 @@ TEST (rpc, block_create_receive_epoch_v2) auto process_result (node->process (state_block)); ASSERT_EQ (nano::block_status::progress, process_result); ASSERT_EQ (state_block->sideband ().details.epoch, nano::epoch::epoch_2); - ASSERT_TRUE (state_block->sideband ().details.is_receive); + ASSERT_TRUE (state_block->is_receive ()); ASSERT_FALSE (node->latest (key.pub).is_zero ()); } @@ -4951,7 +4951,7 @@ TEST (rpc, block_create_send_epoch_v2) auto process_result (node->process (state_block)); ASSERT_EQ (nano::block_status::progress, process_result); ASSERT_EQ (state_block->sideband ().details.epoch, nano::epoch::epoch_2); - ASSERT_TRUE (state_block->sideband ().details.is_send); + ASSERT_TRUE (state_block->is_send ()); ASSERT_FALSE (node->latest (key.pub).is_zero ()); } @@ -5177,7 +5177,7 @@ TEST (rpc, online_reps) auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, new_rep, node1->config.receive_minimum.number ())); ASSERT_NE (nullptr, send); ASSERT_TIMELY (10s, node2->block (send->hash ())); - auto receive (system.wallet (1)->receive_action (send->hash (), new_rep, node1->config.receive_minimum.number (), send->link ().as_account ())); + auto receive (system.wallet (1)->receive_action (send->hash (), new_rep, node1->config.receive_minimum.number (), send->destination ())); ASSERT_NE (nullptr, receive); ASSERT_TIMELY (5s, node2->block (receive->hash ())); auto change (system.wallet (0)->change_action (nano::dev::genesis_key.pub, new_rep)); @@ -5666,7 +5666,7 @@ TEST (rpc, DISABLED_wallet_history) auto send (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::genesis_key.pub, node->config.receive_minimum.number ())); ASSERT_NE (nullptr, send); auto timestamp2 = nano::seconds_since_epoch (); - auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node->config.receive_minimum.number (), send->link ().as_account ())); + auto receive (system.wallet (0)->receive_action (send->hash (), nano::dev::genesis_key.pub, node->config.receive_minimum.number (), send->destination ())); ASSERT_NE (nullptr, receive); nano::keypair key; auto timestamp3 = nano::seconds_since_epoch (); @@ -5719,9 +5719,9 @@ TEST (rpc, sign_hash) nano::block_builder builder; auto send = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (node1->latest (nano::dev::genesis_key.pub)) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -5752,9 +5752,9 @@ TEST (rpc, sign_block) nano::block_builder builder; auto send = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (node1->latest (nano::dev::genesis_key.pub)) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -5855,7 +5855,7 @@ TEST (rpc, block_confirmed) auto open1 = builder .open () .source (send1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key.pub) .sign (key.prv, key.pub) .work (*system.work.generate (key.pub)) diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index 091e45fcc..6b91dd676 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -127,10 +127,10 @@ nano::ledger_constants::ledger_constants (nano::work_thresholds & work, nano::ne : network_a == nano::networks::nano_test_network ? nano_test_final_votes_canary_height : nano_live_final_votes_canary_height) { - nano_beta_genesis->sideband_set (nano::block_sideband (nano_beta_genesis->account (), 0, std::numeric_limits::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0)); - nano_dev_genesis->sideband_set (nano::block_sideband (nano_dev_genesis->account (), 0, std::numeric_limits::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0)); - nano_live_genesis->sideband_set (nano::block_sideband (nano_live_genesis->account (), 0, std::numeric_limits::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0)); - nano_test_genesis->sideband_set (nano::block_sideband (nano_test_genesis->account (), 0, std::numeric_limits::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0)); + nano_beta_genesis->sideband_set (nano::block_sideband (nano_beta_genesis->account_field ().value (), 0, std::numeric_limits::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0)); + nano_dev_genesis->sideband_set (nano::block_sideband (nano_dev_genesis->account_field ().value (), 0, std::numeric_limits::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0)); + nano_live_genesis->sideband_set (nano::block_sideband (nano_live_genesis->account_field ().value (), 0, std::numeric_limits::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0)); + nano_test_genesis->sideband_set (nano::block_sideband (nano_test_genesis->account_field ().value (), 0, std::numeric_limits::max (), 1, nano::seconds_since_epoch (), nano::epoch::epoch_0, false, false, false, nano::epoch::epoch_0)); nano::link epoch_link_v1; char const * epoch_message_v1 ("epoch v1 block"); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 561a87c07..74b70e6e2 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -64,7 +64,7 @@ public: { auto hash (block_a.hash ()); auto amount = ledger.amount (transaction, hash).value (); - auto destination_account = ledger.account (block_a); + auto destination_account = block_a.account (); // Pending account entry can be incorrect if source block was pruned. But it's not affecting correct ledger processing auto source_account = ledger.account (transaction, block_a.hashables.source); auto info = ledger.account_info (transaction, destination_account); @@ -83,9 +83,9 @@ public: { auto hash (block_a.hash ()); auto amount = ledger.amount (transaction, hash).value (); - auto destination_account = ledger.account (block_a); + auto destination_account = block_a.account (); auto source_account = ledger.account (transaction, block_a.hashables.source); - ledger.cache.rep_weights.representation_add (block_a.representative (), 0 - amount); + ledger.cache.rep_weights.representation_add (block_a.representative_field ().value (), 0 - amount); nano::account_info new_info; ledger.update_account (transaction, destination_account, new_info, new_info); ledger.store.block.del (transaction, hash); @@ -97,14 +97,14 @@ public: { auto hash (block_a.hash ()); auto rep_block (ledger.representative (transaction, block_a.hashables.previous)); - auto account = ledger.account (block_a); + auto account = block_a.account (); auto info = ledger.account_info (transaction, account); debug_assert (info); auto balance = ledger.balance (transaction, block_a.hashables.previous).value (); auto block = ledger.store.block.get (transaction, rep_block); release_assert (block != nullptr); - auto representative = block->representative (); - ledger.cache.rep_weights.representation_add_dual (block_a.representative (), 0 - balance, representative, balance); + auto representative = block->representative_field ().value (); + ledger.cache.rep_weights.representation_add_dual (block_a.hashables.representative, 0 - balance, representative, balance); ledger.store.block.del (transaction, hash); nano::account_info new_info (block_a.hashables.previous, representative, info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); ledger.update_account (transaction, account, *info, new_info); @@ -129,13 +129,13 @@ public: // Move existing representation & add in amount delta auto block (ledger.store.block.get (transaction, rep_block_hash)); debug_assert (block != nullptr); - representative = block->representative (); - ledger.cache.rep_weights.representation_add_dual (representative, balance, block_a.representative (), 0 - block_a.hashables.balance.number ()); + representative = block->representative_field ().value (); + ledger.cache.rep_weights.representation_add_dual (representative, balance, block_a.hashables.representative, 0 - block_a.hashables.balance.number ()); } else { // Add in amount delta only - ledger.cache.rep_weights.representation_add (block_a.representative (), 0 - block_a.hashables.balance.number ()); + ledger.cache.rep_weights.representation_add (block_a.hashables.representative, 0 - block_a.hashables.balance.number ()); } auto info = ledger.account_info (transaction, block_a.hashables.account); @@ -224,7 +224,7 @@ bool ledger_processor::validate_epoch_block (nano::state_block const & block_a) if (validate_message (block_a.hashables.account, block_a.hash (), block_a.signature)) { // Is epoch block signed correctly - if (validate_message (ledger.epoch_signer (block_a.link ()), block_a.hash (), block_a.signature)) + if (validate_message (ledger.epoch_signer (block_a.link_field ().value ()), block_a.hash (), block_a.signature)) { result = nano::block_status::bad_signature; } @@ -345,12 +345,12 @@ void ledger_processor::state_block_impl (nano::state_block & block_a) if (!info.head.is_zero ()) { // Move existing representation & add in amount delta - ledger.cache.rep_weights.representation_add_dual (info.representative, 0 - info.balance.number (), block_a.representative (), block_a.hashables.balance.number ()); + ledger.cache.rep_weights.representation_add_dual (info.representative, 0 - info.balance.number (), block_a.hashables.representative, block_a.hashables.balance.number ()); } else { // Add in amount delta only - ledger.cache.rep_weights.representation_add (block_a.representative (), block_a.hashables.balance.number ()); + ledger.cache.rep_weights.representation_add (block_a.hashables.representative, block_a.hashables.balance.number ()); } if (is_send) @@ -364,7 +364,7 @@ void ledger_processor::state_block_impl (nano::state_block & block_a) ledger.store.pending.del (transaction, nano::pending_key (block_a.hashables.account, block_a.hashables.link.as_block_hash ())); } - nano::account_info new_info (hash, block_a.representative (), info.open_block.is_zero () ? hash : info.open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch); + nano::account_info new_info (hash, block_a.hashables.representative, info.open_block.is_zero () ? hash : info.open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch); ledger.update_account (transaction, block_a.hashables.account, info, new_info); if (!ledger.store.frontier.get (transaction, info.head).is_zero ()) { @@ -434,7 +434,7 @@ void ledger_processor::epoch_block_impl (nano::state_block & block_a) ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::epoch_block); block_a.sideband_set (nano::block_sideband (block_a.hashables.account /* unused */, 0, 0 /* unused */, info.block_count + 1, nano::seconds_since_epoch (), block_details, nano::epoch::epoch_0 /* unused */)); ledger.store.block.put (transaction, hash, block_a); - nano::account_info new_info (hash, block_a.representative (), info.open_block.is_zero () ? hash : info.open_block, info.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch); + nano::account_info new_info (hash, block_a.hashables.representative, info.open_block.is_zero () ? hash : info.open_block, info.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch); ledger.update_account (transaction, block_a.hashables.account, info, new_info); if (!ledger.store.frontier.get (transaction, info.head).is_zero ()) { @@ -480,9 +480,9 @@ void ledger_processor::change_block (nano::change_block & block_a) debug_assert (!validate_message (account, hash, block_a.signature)); block_a.sideband_set (nano::block_sideband (account, 0, info->balance, info->block_count + 1, nano::seconds_since_epoch (), block_details, nano::epoch::epoch_0 /* unused */)); ledger.store.block.put (transaction, hash, block_a); - auto balance = ledger.balance (*previous); - ledger.cache.rep_weights.representation_add_dual (block_a.representative (), balance, info->representative, 0 - balance); - nano::account_info new_info (hash, block_a.representative (), info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0); + auto balance = previous->balance (); + ledger.cache.rep_weights.representation_add_dual (block_a.hashables.representative, balance.number (), info->representative, 0 - balance.number ()); + nano::account_info new_info (hash, block_a.hashables.representative, info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0); ledger.update_account (transaction, account, *info, new_info); ledger.store.frontier.del (transaction, block_a.hashables.previous); ledger.store.frontier.put (transaction, hash, account); @@ -665,9 +665,9 @@ void ledger_processor::open_block (nano::open_block & block_a) ledger.store.pending.del (transaction, key); block_a.sideband_set (nano::block_sideband (block_a.hashables.account, 0, pending.amount, 1, nano::seconds_since_epoch (), block_details, nano::epoch::epoch_0 /* unused */)); ledger.store.block.put (transaction, hash, block_a); - nano::account_info new_info (hash, block_a.representative (), hash, pending.amount.number (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0); + nano::account_info new_info (hash, block_a.representative_field ().value (), hash, pending.amount.number (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0); ledger.update_account (transaction, block_a.hashables.account, info, new_info); - ledger.cache.rep_weights.representation_add (block_a.representative (), pending.amount.number ()); + ledger.cache.rep_weights.representation_add (block_a.representative_field ().value (), pending.amount.number ()); ledger.store.frontier.put (transaction, hash, block_a.hashables.account); ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::open); } @@ -808,28 +808,6 @@ void nano::ledger::initialize (nano::generate_cache const & generate_cache_a) } } -nano::uint128_t nano::ledger::balance (nano::block const & block) -{ - nano::uint128_t result; - switch (block.type ()) - { - case nano::block_type::open: - case nano::block_type::receive: - case nano::block_type::change: - result = block.sideband ().balance.number (); - break; - case nano::block_type::send: - case nano::block_type::state: - result = block.balance ().number (); - break; - case nano::block_type::invalid: - case nano::block_type::not_a_block: - release_assert (false); - break; - } - return result; -} - // Balance for account containing hash std::optional nano::ledger::balance (store::transaction const & transaction, nano::block_hash const & hash) const { @@ -842,7 +820,7 @@ std::optional nano::ledger::balance (store::transaction const & { return std::nullopt; } - return balance (*block); + return block->balance ().number (); } std::shared_ptr nano::ledger::block (store::transaction const & transaction, nano::block_hash const & hash) const @@ -972,38 +950,6 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a) return result; } -bool nano::ledger::is_send (store::transaction const & transaction_a, nano::block const & block_a) const -{ - if (block_a.type () != nano::block_type::state) - { - return block_a.type () == nano::block_type::send; - } - nano::block_hash previous = block_a.previous (); - /* - * if block_a does not have a sideband, then is_send() - * requires that the previous block exists in the database. - * This is because it must retrieve the balance of the previous block. - */ - debug_assert (block_a.has_sideband () || previous.is_zero () || block_exists (transaction_a, previous)); - - bool result (false); - if (block_a.has_sideband ()) - { - result = block_a.sideband ().details.is_send; - } - else - { - if (!previous.is_zero ()) - { - if (block_a.balance () < balance (transaction_a, previous)) - { - result = true; - } - } - } - return result; -} - nano::account const & nano::ledger::block_destination (store::transaction const & transaction_a, nano::block const & block_a) { nano::send_block const * send_block (dynamic_cast (&block_a)); @@ -1012,7 +958,7 @@ nano::account const & nano::ledger::block_destination (store::transaction const { return send_block->hashables.destination; } - else if (state_block != nullptr && is_send (transaction_a, *state_block)) + else if (state_block != nullptr && block_a.is_send ()) { return state_block->hashables.link.as_account (); } @@ -1020,26 +966,6 @@ nano::account const & nano::ledger::block_destination (store::transaction const return nano::account::null (); } -nano::block_hash nano::ledger::block_source (store::transaction const & transaction_a, nano::block const & block_a) -{ - /* - * block_source() requires that the previous block of the block - * passed in exist in the database. This is because it will try - * to check account balances to determine if it is a send block. - */ - debug_assert (block_a.previous ().is_zero () || block_exists (transaction_a, block_a.previous ())); - - // If block_a.source () is nonzero, then we have our source. - // However, universal blocks will always return zero. - nano::block_hash result (block_a.source ()); - nano::state_block const * state_block (dynamic_cast (&block_a)); - if (state_block != nullptr && !is_send (transaction_a, *state_block)) - { - result = state_block->hashables.link.as_block_hash (); - } - return result; -} - std::pair nano::ledger::hash_root_random (store::transaction const & transaction_a) const { nano::block_hash hash (0); @@ -1129,18 +1055,6 @@ bool nano::ledger::rollback (store::write_transaction const & transaction_a, nan return rollback (transaction_a, block_a, rollback_list); } -nano::account nano::ledger::account (nano::block const & block) -{ - debug_assert (block.has_sideband ()); - nano::account result (block.account ()); - if (result.is_zero ()) - { - result = block.sideband ().account; - } - debug_assert (!result.is_zero ()); - return result; -} - std::optional nano::ledger::account (store::transaction const & transaction, nano::block_hash const & hash) const { auto block_l = block (transaction, hash); @@ -1148,7 +1062,7 @@ std::optional nano::ledger::account (store::transaction const & t { return std::nullopt; } - return account (*block_l); + return block_l->account (); } std::optional nano::ledger::account_info (store::transaction const & transaction, nano::account const & account) const @@ -1163,17 +1077,17 @@ std::optional nano::ledger::amount (store::transaction const & { return std::nullopt; } - auto block_balance = balance (*block_l); + auto block_balance = block_l->balance (); if (block_l->previous ().is_zero ()) { - return block_balance; + return block_balance.number (); } auto previous_balance = balance (transaction_a, block_l->previous ()); if (!previous_balance) { return std::nullopt; } - return block_balance > previous_balance.value () ? block_balance - previous_balance.value () : previous_balance.value () - block_balance; + return block_balance > previous_balance.value () ? block_balance.number () - previous_balance.value () : previous_balance.value () - block_balance.number (); } // Return latest block for account @@ -1244,13 +1158,13 @@ public: void receive_block (nano::receive_block const & block_a) override { result[0] = block_a.previous (); - result[1] = block_a.source (); + result[1] = block_a.source_field ().value (); } void open_block (nano::open_block const & block_a) override { - if (block_a.source () != ledger.constants.genesis->account ()) + if (block_a.source_field ().value () != ledger.constants.genesis->account ()) { - result[0] = block_a.source (); + result[0] = block_a.source_field ().value (); } } void change_block (nano::change_block const & block_a) override @@ -1262,11 +1176,25 @@ public: result[0] = block_a.hashables.previous; result[1] = block_a.hashables.link.as_block_hash (); // ledger.is_send will check the sideband first, if block_a has a loaded sideband the check that previous block exists can be skipped - if (ledger.is_epoch_link (block_a.hashables.link) || ((block_a.has_sideband () || ledger.block_exists (transaction, block_a.hashables.previous)) && ledger.is_send (transaction, block_a))) + if (ledger.is_epoch_link (block_a.hashables.link) || is_send (transaction, block_a)) { result[1].clear (); } } + // This function is used in place of block->is_send () as it is tolerant to the block not having the sideband information loaded + // This is needed for instance in vote generation on forks which have not yet had sideband information attached + bool is_send (nano::store::transaction const & transaction, nano::state_block const & block) const + { + if (block.previous ().is_zero ()) + { + return false; + } + if (block.has_sideband ()) + { + return block.sideband ().details.is_send; + } + return block.balance_field ().value () < ledger.balance (transaction, block.previous ()); + } nano::ledger const & ledger; nano::store::transaction const & transaction; std::array result; @@ -1299,22 +1227,7 @@ std::shared_ptr nano::ledger::find_receive_block_by_send_hash (stor // walk down the chain until the source field of a receive block matches the send block hash while (possible_receive_block != nullptr) { - // if source is non-zero then it is a legacy receive or open block - nano::block_hash source = possible_receive_block->source (); - - // if source is zero then it could be a state block, which needs a different kind of access - auto state_block = dynamic_cast (possible_receive_block.get ()); - if (state_block != nullptr) - { - // we read the block from the database, so we expect it to have sideband - debug_assert (state_block->has_sideband ()); - if (state_block->sideband ().details.is_receive) - { - source = state_block->hashables.link.as_block_hash (); - } - } - - if (send_block_hash == source) + if (possible_receive_block->is_receive () && send_block_hash == possible_receive_block->source ()) { // we have a match result = possible_receive_block; @@ -1431,7 +1344,7 @@ bool nano::ledger::block_confirmed (store::transaction const & transaction_a, na if (block_l) { nano::confirmation_height_info confirmation_height_info; - store.confirmation_height.get (transaction_a, block_l->account ().is_zero () ? block_l->sideband ().account : block_l->account (), confirmation_height_info); + store.confirmation_height.get (transaction_a, block_l->account (), confirmation_height_info); auto confirmed (confirmation_height_info.height >= block_l->sideband ().height); return confirmed; } @@ -1616,7 +1529,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p auto random_block (store.block.random (lmdb_transaction)); error |= rocksdb_store->block.get (rocksdb_transaction, random_block->hash ()) == nullptr; - auto account = random_block->account ().is_zero () ? random_block->sideband ().account : random_block->account (); + auto account = random_block->account (); nano::account_info account_info; error |= rocksdb_store->account.get (rocksdb_transaction, account, account_info); diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 6b3eddd69..5f1b1e49b 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -30,10 +30,6 @@ class ledger final { public: ledger (nano::store::component &, nano::stats &, nano::ledger_constants & constants, nano::generate_cache const & = nano::generate_cache ()); - /** - * Return account containing hash, expects that block hash exists in ledger - */ - static nano::account account (nano::block const & block); /** * Returns the account for a given hash * Returns std::nullopt if the block doesn't exist or has been pruned @@ -41,7 +37,6 @@ public: std::optional account (store::transaction const &, nano::block_hash const &) const; std::optional account_info (store::transaction const & transaction, nano::account const & account) const; std::optional amount (store::transaction const &, nano::block_hash const &); - static nano::uint128_t balance (nano::block const & block); std::optional balance (store::transaction const &, nano::block_hash const &) const; std::shared_ptr block (store::transaction const & transaction, nano::block_hash const & hash) const; bool block_exists (store::transaction const & transaction, nano::block_hash const & hash) const; @@ -61,9 +56,7 @@ public: bool root_exists (store::transaction const &, nano::root const &); std::string block_text (char const *); std::string block_text (nano::block_hash const &); - bool is_send (store::transaction const &, nano::block const &) const; nano::account const & block_destination (store::transaction const &, nano::block const &); - nano::block_hash block_source (store::transaction const &, nano::block const &); std::pair hash_root_random (store::transaction const &) const; std::optional pending_info (store::transaction const & transaction, nano::pending_key const & key) const; nano::block_status process (store::write_transaction const & transaction, std::shared_ptr block); diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 7aa3a4d34..0ac1ee294 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -820,7 +820,7 @@ TEST (confirmation_height, long_chains) auto open = builder .open () .source (send->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .account (key1.pub) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1.pub)) @@ -874,7 +874,7 @@ TEST (confirmation_height, long_chains) .state () .account (nano::dev::genesis_key.pub) .previous (previous_genesis_chain_hash) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio + 1) .link (send1->hash ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) @@ -885,9 +885,9 @@ TEST (confirmation_height, long_chains) nano::keypair key2; auto send2 = builder .state () - .account (nano::dev::genesis->account ()) + .account (nano::dev::genesis_key.pub) .previous (receive1->hash ()) - .representative (nano::dev::genesis->account ()) + .representative (nano::dev::genesis_key.pub) .balance (nano::dev::constants.genesis_amount - nano::Gxrb_ratio) .link (key2.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 5aa5752dd..4d99cc904 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -424,7 +424,7 @@ void nano::test::system::generate_receive (nano::node & node_a) } if (send_block != nullptr) { - auto receive_error (wallet (0)->receive_sync (send_block, nano::dev::genesis->account (), std::numeric_limits::max ())); + auto receive_error (wallet (0)->receive_sync (send_block, nano::dev::genesis_key.pub, std::numeric_limits::max ())); (void)receive_error; } }