From 5678e8ccb75b8489d465d95b92957bf94177b61c Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 6 Mar 2024 15:03:43 +0000 Subject: [PATCH 01/17] Directly use genesis_key.pub for obtaining the genesis account, rather than querying the genesis block. --- nano/core_test/block_store.cpp | 6 +- nano/core_test/bootstrap.cpp | 12 +- nano/core_test/confirmation_height.cpp | 56 +-- nano/core_test/ledger.cpp | 644 ++++++++++++------------- nano/core_test/node.cpp | 12 +- nano/core_test/system.cpp | 14 +- nano/core_test/wallet.cpp | 66 +-- nano/core_test/wallets.cpp | 12 +- nano/load_test/entry.cpp | 2 +- nano/qt_test/qt.cpp | 6 +- nano/rpc_test/receivable.cpp | 2 +- nano/rpc_test/rpc.cpp | 126 ++--- nano/slow_test/node.cpp | 8 +- nano/test_common/system.cpp | 2 +- 14 files changed, 484 insertions(+), 484 deletions(-) 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/ledger.cpp b/nano/core_test/ledger.cpp index ac26b842b..9b776a165 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 (); @@ -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) @@ -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) @@ -2330,13 +2330,13 @@ TEST (ledger, block_destination_source) 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_EQ (nano::dev::genesis_key.pub, ledger.block_destination (transaction, *block2)); ASSERT_TRUE (ledger.block_source (transaction, *block2).is_zero ()); ASSERT_EQ (ledger.block_destination (transaction, *block3), nullptr); ASSERT_EQ (block2->hash (), ledger.block_source (transaction, *block3)); 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_EQ (nano::dev::genesis_key.pub, ledger.block_destination (transaction, *block5)); ASSERT_TRUE (ledger.block_source (transaction, *block5).is_zero ()); ASSERT_EQ (ledger.block_destination (transaction, *block6), nullptr); ASSERT_EQ (block5->hash (), ledger.block_source (transaction, *block6)); @@ -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_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,8 +2412,8 @@ 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); @@ -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,7 +2462,7 @@ 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); @@ -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,7 +2495,7 @@ 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); @@ -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,7 +2549,7 @@ 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); @@ -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,7 +2975,7 @@ 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); @@ -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,7 +3027,7 @@ 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); @@ -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,9 +3392,9 @@ 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) @@ -3408,24 +3408,24 @@ TEST (ledger, epoch_blocks_v1_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_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); @@ -3436,16 +3436,16 @@ TEST (ledger, epoch_blocks_v1_general) 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) @@ -3460,7 +3460,7 @@ TEST (ledger, epoch_blocks_v1_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)) @@ -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) @@ -3517,7 +3517,7 @@ 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); @@ -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) @@ -4057,9 +4057,9 @@ TEST (ledger, epoch_open_pending) 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) @@ -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) @@ -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) @@ -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,7 +4914,7 @@ 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); @@ -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); @@ -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 28dcae3dd..c4b600f0e 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -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 track nodes that have rep weight for priority broadcasting @@ -2567,9 +2567,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) 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/wallet.cpp b/nano/core_test/wallet.cpp index 079eb007c..ab107d56a 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; @@ -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,8 +1185,8 @@ 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); diff --git a/nano/core_test/wallets.cpp b/nano/core_test/wallets.cpp index f624f70de..bbff7d287 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,8 +249,8 @@ 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); 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/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..236165745 100644 --- a/nano/rpc_test/receivable.cpp +++ b/nano/rpc_test/receivable.cpp @@ -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 ()); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index f6fe1b065..bbd88b8fa 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 ()); @@ -928,19 +928,19 @@ TEST (rpc, history) 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) @@ -1012,19 +1012,19 @@ TEST (rpc, account_history) 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)); @@ -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) @@ -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) @@ -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); { @@ -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/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 efbd13dd4..f7107d9bd 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -422,7 +422,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; } } From 76ebe9afa8c25d24d210b330b1467d68021192c5 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 6 Mar 2024 15:39:50 +0000 Subject: [PATCH 02/17] Convert boost::optional to std::optional for distributed work generation. --- nano/core_test/distributed_work.cpp | 38 +++++++++++++------------- nano/core_test/node.cpp | 14 +++++----- nano/core_test/websocket.cpp | 4 +-- nano/node/distributed_work.cpp | 12 ++++---- nano/node/distributed_work.hpp | 8 ++++-- nano/node/distributed_work_factory.cpp | 2 +- nano/node/distributed_work_factory.hpp | 3 +- nano/node/json_handler.cpp | 8 +++--- nano/node/node.cpp | 22 +++++++-------- nano/node/node.hpp | 13 +++++---- nano/node/wallet.cpp | 6 ++-- nano/qt/qt.cpp | 8 +++--- nano/rpc_test/rpc.cpp | 14 +++++----- 13 files changed, 78 insertions(+), 74 deletions(-) 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/node.cpp b/nano/core_test/node.cpp index c4b600f0e..493e8c52a 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); } } 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/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/json_handler.cpp b/nano/node/json_handler.cpp index 2639aa44b..eb2db379a 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -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); @@ -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 09d119f26..0af8e6da7 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1078,50 +1078,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 ()) + 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); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index d4105e61e..205436a60 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -43,6 +43,7 @@ #include #include +#include #include namespace nano @@ -111,9 +112,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 &); @@ -199,11 +200,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/wallet.cpp b/nano/node/wallet.cpp index 53380f4b3..fde737b85 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) { @@ -1298,12 +1298,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/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/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index bbd88b8fa..16fd73146 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -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)) From 122a935306d33f1fc6031ec65e37b6cdb41cbd54 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 6 Mar 2024 15:58:23 +0000 Subject: [PATCH 03/17] Change block::account to return an std::optional if the block actually contains the field. Fixes up call sites that checked against the old sentinel value 0. Convert many call sites to using ledger::account(block&) when possible. --- nano/core_test/active_transactions.cpp | 4 ++-- nano/core_test/backlog.cpp | 4 +--- nano/core_test/ledger.cpp | 2 +- nano/lib/blocks.cpp | 9 ++++----- nano/lib/blocks.hpp | 9 ++++++--- nano/node/active_transactions.cpp | 2 +- nano/node/blockprocessor.cpp | 2 +- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 2 +- nano/node/bootstrap_ascending/service.cpp | 2 +- nano/node/cli.cpp | 2 +- nano/node/confirmation_height_bounded.cpp | 6 +----- nano/node/confirmation_height_unbounded.cpp | 6 +----- nano/node/ipc/flatbuffers_util.cpp | 4 ++-- nano/node/json_handler.cpp | 10 +++++----- nano/node/node.cpp | 6 +----- nano/node/nodeconfig.cpp | 4 ++-- nano/node/process_live_dispatcher.cpp | 3 +-- nano/node/request_aggregator.cpp | 4 ++-- nano/qt/qt.cpp | 2 +- nano/rpc_test/rpc.cpp | 4 ++-- nano/secure/common.cpp | 10 +++++----- nano/secure/ledger.cpp | 12 +++--------- nano/store/component.cpp | 8 ++++---- 23 files changed, 49 insertions(+), 68 deletions(-) diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index 2b1bc50d0..85fc7a1ef 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -1534,7 +1534,7 @@ TEST (active_transactions, allow_limited_overflow) // Insert the first part of the blocks into normal election scheduler for (auto const & block : blocks1) { - node.scheduler.priority.activate (block->account (), node.store.tx_begin_read ()); + node.scheduler.priority.activate (block->account ().value (), node.store.tx_begin_read ()); } // Ensure number of active elections reaches AEC limit and there is no overfill @@ -1596,7 +1596,7 @@ TEST (active_transactions, allow_limited_overflow_adapt) // Insert the first part of the blocks into normal election scheduler for (auto const & block : blocks1) { - node.scheduler.priority.activate (block->account (), node.store.tx_begin_read ()); + node.scheduler.priority.activate (block->account ().value (), node.store.tx_begin_read ()); } // Ensure number of active elections reaches AEC limit and there is no overfill diff --git a/nano/core_test/backlog.cpp b/nano/core_test/backlog.cpp index fa58f702c..70ccb6b28 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 ().value ()) != 0; }); }; ASSERT_TIMELY (5s, all_activated ()); diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 9b776a165..2e6115132 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -4052,7 +4052,7 @@ 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 ().value ()).hash); ASSERT_EQ (blocks.size (), 1); ASSERT_EQ (blocks[0].block->full_hash (), epoch_open->full_hash ()); // New block to process epoch open diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 688e614d1..253ecaa7e 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -185,10 +185,9 @@ nano::link const & nano::block::link () const return link; } -nano::account const & nano::block::account () const +std::optional nano::block::account () const { - static nano::account account{}; - return account; + return std::nullopt; } nano::qualified_root nano::block::qualified_root () const @@ -643,7 +642,7 @@ nano::block_hash const & nano::open_block::previous () const return result; } -nano::account const & nano::open_block::account () const +std::optional nano::open_block::account () const { return hashables.account; } @@ -1213,7 +1212,7 @@ nano::block_hash const & nano::state_block::previous () const return hashables.previous; } -nano::account const & nano::state_block::account () const +std::optional nano::state_block::account () const { return hashables.account; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index e89f2dddb..18514a907 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -33,7 +33,6 @@ 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. @@ -64,6 +63,10 @@ public: // If there are any changes to the hashables, call this to update the cached hash void refresh (); +public: // Direct access to the block fields or nullopt if the block type does not have the specified field + // Account field for open/state blocks + virtual std::optional account () const; + protected: mutable nano::block_hash cached_hash{ 0 }; /** @@ -210,7 +213,7 @@ public: 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; + std::optional account () const override; nano::block_hash const & source () const override; nano::root const & root () const override; nano::account const & representative () const override; @@ -325,7 +328,7 @@ public: 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; + std::optional account () const override; nano::root const & root () const override; nano::link const & link () const override; nano::account const & representative () const override; diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 2545c5d41..b5c4a83df 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -186,7 +186,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 = node.ledger.account (*block); 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..54297c733 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -362,7 +362,7 @@ nano::block_status nano::block_processor::process_one (store::write_transaction } 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 ().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..00e9a8ece 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -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 ().value_or (0); } if (connection->block_count++ == 0) { diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 2db59429d..aad14eb00 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -167,7 +167,7 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, break; case nano::block_status::gap_source: { - const auto account = block.previous ().is_zero () ? block.account () : ledger.account (tx, block.previous ()).value (); + const auto account = block.previous ().is_zero () ? block.account ().value () : ledger.account (tx, block.previous ()).value (); const auto source = block.source ().is_zero () ? block.link ().as_block_hash () : block.source (); // Mark account as blocked because it is missing the source block diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 984f1656f..2f3372e40 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -1324,7 +1324,7 @@ void reset_confirmation_heights (nano::store::write_transaction const & transact store.confirmation_height.clear (transaction); // Then make sure the confirmation height of the genesis account open block is 1 - store.confirmation_height.put (transaction, constants.genesis->account (), { 1, constants.genesis->hash () }); + store.confirmation_height.put (transaction, constants.genesis->account ().value (), { 1, constants.genesis->hash () }); } bool is_using_rocksdb (std::filesystem::path const & data_path, boost::program_options::variables_map const & vm, std::error_code & ec) diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index 53c3ffbf3..4d221a3f5 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 = ledger.account (*block); // 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; diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index 03c4c42a2..cae1ec5cf 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 = ledger.account (*block); auto block_height = block->sideband ().height; uint64_t confirmation_height = 0; diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index 8cf1fe5e4..eb90c4731 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -6,7 +6,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano::state_block const & block_a, nano::amount const & amount_a, bool is_state_send_a, bool is_state_epoch_a) { auto block (std::make_unique ()); - block->account = block_a.account ().to_account (); + block->account = block_a.account ().value ().to_account (); block->hash = block_a.hash ().to_string (); block->previous = block_a.previous ().to_string (); block->representative = block_a.representative ().to_account (); @@ -63,7 +63,7 @@ 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->account = block_a.account ().to_account (); + block->account = block_a.account ().value ().to_account (); block->representative = block_a.representative ().to_account (); block_a.signature.encode_hex (block->signature); block->work = nano::to_string_hex (block_a.work); diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index eb2db379a..f6afe32f7 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -415,7 +415,7 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a) if (!link.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 ()))) + if (block_link != nullptr && node.store.pending.exists (transaction, nano::pending_key (block_a.account ().value (), link.as_block_hash ()))) { details.epoch = std::max (details.epoch, block_link->sideband ().details.epoch); details.is_receive = true; @@ -1131,7 +1131,7 @@ void nano::json_handler::active_difficulty () void nano::json_handler::available_supply () { - auto genesis_balance (node.balance (node.network_params.ledger.genesis->account ())); // Cold storage genesis + auto genesis_balance (node.balance (node.network_params.ledger.genesis->account ().value ())); // Cold storage genesis auto landing_balance (node.balance (nano::account ("059F68AAB29DE0D3A27443625C7EA9CDDB6517A8B76FE37727EF6A4D76832AD5"))); // Active unavailable account auto faucet_balance (node.balance (nano::account ("8E319CE6F3025E5B2DF66DA7AB1467FE48F1679C13DD43BFDB29FA2E9FC40D3B"))); // Faucet account auto burned_balance ((node.balance_pending (nano::account{}, false)).second); // Burning 0 account @@ -1149,7 +1149,7 @@ 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 = node.ledger.account (*block); response_l.put ("block_account", account.to_account ()); auto amount = node.ledger.amount (transaction, hash); if (amount) @@ -1306,7 +1306,7 @@ 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 = node.ledger.account (*block); entry.put ("block_account", account.to_account ()); auto amount = node.ledger.amount (transaction, hash); if (amount) @@ -2454,7 +2454,7 @@ public: } else { - tree.put ("account", handler.node.ledger.constants.genesis->account ().to_account ()); + tree.put ("account", handler.node.ledger.constants.genesis->account ().value ().to_account ()); tree.put ("amount", nano::dev::constants.genesis_amount.convert_to ()); } } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 0af8e6da7..bcf845bf9 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1226,11 +1226,7 @@ void nano::node::receive_confirmed (store::transaction const & block_transaction void nano::node::process_confirmed_data (store::transaction const & transaction_a, std::shared_ptr const & block_a, nano::block_hash const & hash_a, nano::account & account_a, nano::uint128_t & amount_a, bool & is_state_send_a, bool & is_state_epoch_a, nano::account & pending_account_a) { // Faster account calculation - account_a = block_a->account (); - if (account_a.is_zero ()) - { - account_a = block_a->sideband ().account; - } + account_a = ledger.account (*block_a); // Faster amount calculation auto previous (block_a->previous ()); auto previous_balance = ledger.balance (transaction_a, previous); diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index beb93cb4f..edd039d82 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -49,7 +49,7 @@ nano::node_config::node_config (const std::optional & peering_port_a, { case nano::networks::nano_dev_network: enable_voting = true; - preconfigured_representatives.push_back (network_params.ledger.genesis->account ()); + preconfigured_representatives.push_back (network_params.ledger.genesis->account ().value ()); break; case nano::networks::nano_beta_network: { @@ -72,7 +72,7 @@ nano::node_config::node_config (const std::optional & peering_port_a, break; case nano::networks::nano_test_network: preconfigured_peers.push_back (default_test_peer_network); - preconfigured_representatives.push_back (network_params.ledger.genesis->account ()); + preconfigured_representatives.push_back (network_params.ledger.genesis->account ().value ()); break; default: debug_assert (false); diff --git a/nano/node/process_live_dispatcher.cpp b/nano/node/process_live_dispatcher.cpp index 8411851d4..4fd77e3c3 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 (ledger.account (block), 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..43e417219 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, ledger.account (*block), 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, ledger.account (*block), confirmation_height_info); generate_final_vote = (confirmation_height_info.height >= block->sideband ().height); } } diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 640080b55..4942294f3 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -566,7 +566,7 @@ public: } else { - account = ledger.constants.genesis->account (); + account = ledger.constants.genesis->account ().value (); amount = nano::dev::constants.genesis_amount; } } diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 16fd73146..9045fc413 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -3314,7 +3314,7 @@ TEST (rpc, pending_exists) ASSERT_TRUE (pending_exists ("1")); ASSERT_TRUE (pending_exists ("1")); - reset_confirmation_height (node->store, block1->account ()); + reset_confirmation_height (node->store, block1->account ().value ()); ASSERT_TRUE (pending_exists ("0")); request.put ("include_only_confirmed", "false"); ASSERT_TRUE (pending_exists ("1")); @@ -3419,7 +3419,7 @@ TEST (rpc, wallet_receivable) ASSERT_EQ (sources[block1->hash ()], nano::dev::genesis_key.pub); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1)); - reset_confirmation_height (system.nodes.front ()->store, block1->account ()); + reset_confirmation_height (system.nodes.front ()->store, block1->account ().value ()); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 0)); request.put ("include_only_confirmed", "false"); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1)); diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index 091e45fcc..0812ee4ea 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -127,15 +127,15 @@ 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 ().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 ().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 ().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 ().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"); strncpy ((char *)epoch_link_v1.bytes.data (), epoch_message_v1, epoch_link_v1.bytes.size ()); - epochs.add (nano::epoch::epoch_1, genesis->account (), epoch_link_v1); + epochs.add (nano::epoch::epoch_1, genesis->account ().value (), epoch_link_v1); nano::link epoch_link_v2; nano::account nano_live_epoch_v2_signer; diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 561a87c07..be4afa8d2 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1132,13 +1132,7 @@ bool nano::ledger::rollback (store::write_transaction const & transaction_a, nan 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; + return block.account ().value_or (block.sideband ().account); } std::optional nano::ledger::account (store::transaction const & transaction, nano::block_hash const & hash) const @@ -1431,7 +1425,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, account (*block_l), confirmation_height_info); auto confirmed (confirmation_height_info.height >= block_l->sideband ().height); return confirmed; } @@ -1616,7 +1610,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 = this->account (*random_block); nano::account_info account_info; error |= rocksdb_store->account.get (rocksdb_transaction, account, account_info); diff --git a/nano/store/component.cpp b/nano/store/component.cpp index 67826f634..c95c16a19 100644 --- a/nano/store/component.cpp +++ b/nano/store/component.cpp @@ -31,11 +31,11 @@ void nano::store::component::initialize (store::write_transaction const & transa auto hash_l (constants.genesis->hash ()); block.put (transaction_a, hash_l, *constants.genesis); ++ledger_cache_a.block_count; - confirmation_height.put (transaction_a, constants.genesis->account (), nano::confirmation_height_info{ 1, constants.genesis->hash () }); + confirmation_height.put (transaction_a, constants.genesis->account ().value (), nano::confirmation_height_info{ 1, constants.genesis->hash () }); ++ledger_cache_a.cemented_count; ledger_cache_a.final_votes_confirmation_canary = (constants.final_votes_canary_account == constants.genesis->account () && 1 >= constants.final_votes_canary_height); - account.put (transaction_a, constants.genesis->account (), { hash_l, constants.genesis->account (), constants.genesis->hash (), std::numeric_limits::max (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0 }); + account.put (transaction_a, constants.genesis->account ().value (), { hash_l, constants.genesis->account ().value (), constants.genesis->hash (), std::numeric_limits::max (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0 }); ++ledger_cache_a.account_count; - ledger_cache_a.rep_weights.representation_put (constants.genesis->account (), std::numeric_limits::max ()); - frontier.put (transaction_a, hash_l, constants.genesis->account ()); + ledger_cache_a.rep_weights.representation_put (constants.genesis->account ().value (), std::numeric_limits::max ()); + frontier.put (transaction_a, hash_l, constants.genesis->account ().value ()); } From a7cab75095c8c77c06f43d9a4646b6dd09e703cb Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 6 Mar 2024 17:14:00 +0000 Subject: [PATCH 04/17] ledger::account is moved to block::account and block::account which accesses the account field is renamed to block::account_field. --- nano/core_test/active_transactions.cpp | 4 ++-- nano/core_test/backlog.cpp | 2 +- nano/core_test/ledger.cpp | 12 +++++------ nano/lib/blocks.cpp | 23 ++++++++++++++++++--- nano/lib/blocks.hpp | 12 ++++++++--- nano/node/active_transactions.cpp | 2 +- nano/node/blockprocessor.cpp | 2 +- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 4 ++-- nano/node/bootstrap_ascending/service.cpp | 6 +++--- nano/node/cli.cpp | 2 +- nano/node/confirmation_height_bounded.cpp | 2 +- nano/node/confirmation_height_unbounded.cpp | 2 +- nano/node/ipc/flatbuffers_util.cpp | 4 ++-- nano/node/json_handler.cpp | 18 ++++++++-------- nano/node/node.cpp | 4 ++-- nano/node/nodeconfig.cpp | 4 ++-- nano/node/process_live_dispatcher.cpp | 2 +- nano/node/request_aggregator.cpp | 4 ++-- nano/qt/qt.cpp | 2 +- nano/rpc_test/rpc.cpp | 4 ++-- nano/secure/common.cpp | 10 ++++----- nano/secure/ledger.cpp | 18 ++++++---------- nano/secure/ledger.hpp | 4 ---- nano/store/component.cpp | 8 +++---- 24 files changed, 84 insertions(+), 71 deletions(-) diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index 85fc7a1ef..2b1bc50d0 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -1534,7 +1534,7 @@ TEST (active_transactions, allow_limited_overflow) // Insert the first part of the blocks into normal election scheduler for (auto const & block : blocks1) { - node.scheduler.priority.activate (block->account ().value (), node.store.tx_begin_read ()); + node.scheduler.priority.activate (block->account (), node.store.tx_begin_read ()); } // Ensure number of active elections reaches AEC limit and there is no overfill @@ -1596,7 +1596,7 @@ TEST (active_transactions, allow_limited_overflow_adapt) // Insert the first part of the blocks into normal election scheduler for (auto const & block : blocks1) { - node.scheduler.priority.activate (block->account ().value (), node.store.tx_begin_read ()); + node.scheduler.priority.activate (block->account (), node.store.tx_begin_read ()); } // Ensure number of active elections reaches AEC limit and there is no overfill diff --git a/nano/core_test/backlog.cpp b/nano/core_test/backlog.cpp index 70ccb6b28..26d5680a8 100644 --- a/nano/core_test/backlog.cpp +++ b/nano/core_test/backlog.cpp @@ -33,7 +33,7 @@ TEST (backlog, population) auto all_activated = [&] () { nano::lock_guard lock{ mutex }; return std::all_of (blocks.begin (), blocks.end (), [&] (auto const & item) { - return activated.count (item->account ().value ()) != 0; + return activated.count (item->account ()) != 0; }); }; ASSERT_TIMELY (5s, all_activated ()); diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 2e6115132..be50f1eec 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -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)); @@ -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); @@ -4052,7 +4052,7 @@ 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 ().value ()).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 diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 253ecaa7e..c2f5cbc2f 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -185,7 +185,24 @@ nano::link const & nano::block::link () const return link; } -std::optional nano::block::account () const +nano::account nano::block::account () const noexcept +{ + 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); + } +} + +std::optional nano::block::account_field () const { return std::nullopt; } @@ -642,7 +659,7 @@ nano::block_hash const & nano::open_block::previous () const return result; } -std::optional nano::open_block::account () const +std::optional nano::open_block::account_field () const { return hashables.account; } @@ -1212,7 +1229,7 @@ nano::block_hash const & nano::state_block::previous () const return hashables.previous; } -std::optional nano::state_block::account () const +std::optional nano::state_block::account_field () const { return hashables.account; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 18514a907..f4a47650e 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -64,8 +64,10 @@ public: void refresh (); 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 () const; + virtual std::optional account_field () const; protected: mutable nano::block_hash cached_hash{ 0 }; @@ -213,7 +215,6 @@ public: uint64_t block_work () const override; void block_work_set (uint64_t) override; nano::block_hash const & previous () const override; - std::optional account () const override; nano::block_hash const & source () const override; nano::root const & root () const override; nano::account const & representative () const override; @@ -235,6 +236,9 @@ 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; + public: // Logging void operator() (nano::object_stream &) const override; }; @@ -328,7 +332,6 @@ public: uint64_t block_work () const override; void block_work_set (uint64_t) override; nano::block_hash const & previous () const override; - std::optional account () const override; nano::root const & root () const override; nano::link const & link () const override; nano::account const & representative () const override; @@ -351,6 +354,9 @@ 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; + public: // Logging void operator() (nano::object_stream &) const override; }; diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index b5c4a83df..0b39a6c67 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -186,7 +186,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 account = node.ledger.account (*block); + 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 54297c733..ecbd66985 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -362,7 +362,7 @@ nano::block_status nano::block_processor::process_one (store::write_transaction } case nano::block_status::gap_epoch_open_pending: { - node.unchecked.put (block->account ().value_or (0), 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 00e9a8ece..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 ().value_or (0); + known_account = block->account_field ().value_or (0); } if (connection->block_count++ == 0) { diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index aad14eb00..33746a1d6 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -133,7 +133,7 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, { case nano::block_status::progress: { - const auto account = ledger.account (block); + const auto account = block.account (); const auto is_send = ledger.is_send (tx, block); // If we've inserted any block in to an account, unmark it as blocked @@ -167,7 +167,7 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, break; case nano::block_status::gap_source: { - const auto account = block.previous ().is_zero () ? block.account ().value () : ledger.account (tx, block.previous ()).value (); + const auto account = block.previous ().is_zero () ? block.account_field ().value () : ledger.account (tx, block.previous ()).value (); const auto source = block.source ().is_zero () ? block.link ().as_block_hash () : block.source (); // Mark account as blocked because it is missing the source block @@ -456,7 +456,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/cli.cpp b/nano/node/cli.cpp index 2f3372e40..984f1656f 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -1324,7 +1324,7 @@ void reset_confirmation_heights (nano::store::write_transaction const & transact store.confirmation_height.clear (transaction); // Then make sure the confirmation height of the genesis account open block is 1 - store.confirmation_height.put (transaction, constants.genesis->account ().value (), { 1, constants.genesis->hash () }); + store.confirmation_height.put (transaction, constants.genesis->account (), { 1, constants.genesis->hash () }); } bool is_using_rocksdb (std::filesystem::path const & data_path, boost::program_options::variables_map const & vm, std::error_code & ec) diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index 4d221a3f5..68faaf07a 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -104,7 +104,7 @@ void nano::confirmation_height_bounded::process (std::shared_ptr or release_assert (block); } } - auto account = ledger.account (*block); + 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; diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index cae1ec5cf..b93fc6354 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -79,7 +79,7 @@ void nano::confirmation_height_unbounded::process (std::shared_ptr } release_assert (block); - auto account = ledger.account (*block); + auto account = block->account (); auto block_height = block->sideband ().height; uint64_t confirmation_height = 0; diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index eb90c4731..8cf1fe5e4 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -6,7 +6,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano::state_block const & block_a, nano::amount const & amount_a, bool is_state_send_a, bool is_state_epoch_a) { auto block (std::make_unique ()); - block->account = block_a.account ().value ().to_account (); + 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 (); @@ -63,7 +63,7 @@ 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->account = block_a.account ().value ().to_account (); + block->account = block_a.account ().to_account (); block->representative = block_a.representative ().to_account (); block_a.signature.encode_hex (block->signature); block->work = nano::to_string_hex (block_a.work); diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index f6afe32f7..5b271232b 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -415,7 +415,8 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a) if (!link.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 ().value (), link.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.as_block_hash ()))) { details.epoch = std::max (details.epoch, block_link->sideband ().details.epoch); details.is_receive = true; @@ -1131,7 +1132,7 @@ void nano::json_handler::active_difficulty () void nano::json_handler::available_supply () { - auto genesis_balance (node.balance (node.network_params.ledger.genesis->account ().value ())); // Cold storage genesis + auto genesis_balance (node.balance (node.network_params.ledger.genesis->account ())); // Cold storage genesis auto landing_balance (node.balance (nano::account ("059F68AAB29DE0D3A27443625C7EA9CDDB6517A8B76FE37727EF6A4D76832AD5"))); // Active unavailable account auto faucet_balance (node.balance (nano::account ("8E319CE6F3025E5B2DF66DA7AB1467FE48F1679C13DD43BFDB29FA2E9FC40D3B"))); // Faucet account auto burned_balance ((node.balance_pending (nano::account{}, false)).second); // Burning 0 account @@ -1149,7 +1150,7 @@ void nano::json_handler::block_info () auto block = node.ledger.block (transaction, hash); if (block != nullptr) { - auto account = node.ledger.account (*block); + auto account = block->account (); response_l.put ("block_account", account.to_account ()); auto amount = node.ledger.amount (transaction, hash); if (amount) @@ -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); @@ -1306,7 +1307,7 @@ void nano::json_handler::blocks_info () if (block != nullptr) { boost::property_tree::ptree entry; - auto account = node.ledger.account (*block); + auto account = block->account (); entry.put ("block_account", account.to_account ()); auto amount = node.ledger.amount (transaction, hash); if (amount) @@ -1386,8 +1387,7 @@ void nano::json_handler::blocks_info () auto block_a = node.ledger.block (transaction, source_hash); if (block_a != nullptr) { - auto source_account (node.ledger.account (*block_a)); - entry.put ("source_account", source_account.to_account ()); + entry.put ("source_account", block_a->account ().to_account ()); } else { @@ -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 { @@ -2454,7 +2454,7 @@ public: } else { - tree.put ("account", handler.node.ledger.constants.genesis->account ().value ().to_account ()); + tree.put ("account", handler.node.ledger.constants.genesis->account ().to_account ()); tree.put ("amount", nano::dev::constants.genesis_amount.convert_to ()); } } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index bcf845bf9..61a1c7fe1 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1080,7 +1080,7 @@ bool nano::node::work_generation_enabled (std::vector 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 ())); + 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.value ()); @@ -1226,7 +1226,7 @@ void nano::node::receive_confirmed (store::transaction const & block_transaction void nano::node::process_confirmed_data (store::transaction const & transaction_a, std::shared_ptr const & block_a, nano::block_hash const & hash_a, nano::account & account_a, nano::uint128_t & amount_a, bool & is_state_send_a, bool & is_state_epoch_a, nano::account & pending_account_a) { // Faster account calculation - account_a = ledger.account (*block_a); + account_a = block_a->account (); // Faster amount calculation auto previous (block_a->previous ()); auto previous_balance = ledger.balance (transaction_a, previous); diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index edd039d82..beb93cb4f 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -49,7 +49,7 @@ nano::node_config::node_config (const std::optional & peering_port_a, { case nano::networks::nano_dev_network: enable_voting = true; - preconfigured_representatives.push_back (network_params.ledger.genesis->account ().value ()); + preconfigured_representatives.push_back (network_params.ledger.genesis->account ()); break; case nano::networks::nano_beta_network: { @@ -72,7 +72,7 @@ nano::node_config::node_config (const std::optional & peering_port_a, break; case nano::networks::nano_test_network: preconfigured_peers.push_back (default_test_peer_network); - preconfigured_representatives.push_back (network_params.ledger.genesis->account ().value ()); + preconfigured_representatives.push_back (network_params.ledger.genesis->account ()); break; default: debug_assert (false); diff --git a/nano/node/process_live_dispatcher.cpp b/nano/node/process_live_dispatcher.cpp index 4fd77e3c3..f0d457dbe 100644 --- a/nano/node/process_live_dispatcher.cpp +++ b/nano/node/process_live_dispatcher.cpp @@ -45,7 +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)) { - scheduler.activate (ledger.account (block), 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 43e417219..0e61195e8 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -229,7 +229,7 @@ std::pair>, std::vectoraccount (), confirmation_height_info); generate_final_vote = (confirmation_height_info.height >= block->sideband ().height); } } @@ -265,7 +265,7 @@ std::pair>, std::vectoraccount (), confirmation_height_info); generate_final_vote = (confirmation_height_info.height >= block->sideband ().height); } } diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 4942294f3..640080b55 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -566,7 +566,7 @@ public: } else { - account = ledger.constants.genesis->account ().value (); + account = ledger.constants.genesis->account (); amount = nano::dev::constants.genesis_amount; } } diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 9045fc413..16fd73146 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -3314,7 +3314,7 @@ TEST (rpc, pending_exists) ASSERT_TRUE (pending_exists ("1")); ASSERT_TRUE (pending_exists ("1")); - reset_confirmation_height (node->store, block1->account ().value ()); + reset_confirmation_height (node->store, block1->account ()); ASSERT_TRUE (pending_exists ("0")); request.put ("include_only_confirmed", "false"); ASSERT_TRUE (pending_exists ("1")); @@ -3419,7 +3419,7 @@ TEST (rpc, wallet_receivable) ASSERT_EQ (sources[block1->hash ()], nano::dev::genesis_key.pub); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1)); - reset_confirmation_height (system.nodes.front ()->store, block1->account ().value ()); + reset_confirmation_height (system.nodes.front ()->store, block1->account ()); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 0)); request.put ("include_only_confirmed", "false"); ASSERT_TRUE (check_block_response_count (system, rpc_ctx, request, 1)); diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index 0812ee4ea..6b91dd676 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -127,15 +127,15 @@ 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 ().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 ().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 ().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 ().value (), 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"); strncpy ((char *)epoch_link_v1.bytes.data (), epoch_message_v1, epoch_link_v1.bytes.size ()); - epochs.add (nano::epoch::epoch_1, genesis->account ().value (), epoch_link_v1); + epochs.add (nano::epoch::epoch_1, genesis->account (), epoch_link_v1); nano::link epoch_link_v2; nano::account nano_live_epoch_v2_signer; diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index be4afa8d2..7477722ed 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,7 +83,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 (); auto source_account = ledger.account (transaction, block_a.hashables.source); ledger.cache.rep_weights.representation_add (block_a.representative (), 0 - amount); nano::account_info new_info; @@ -97,7 +97,7 @@ 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 (); @@ -1129,12 +1129,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 ()); - return block.account ().value_or (block.sideband ().account); -} - std::optional nano::ledger::account (store::transaction const & transaction, nano::block_hash const & hash) const { auto block_l = block (transaction, hash); @@ -1142,7 +1136,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 @@ -1425,7 +1419,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, account (*block_l), 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; } @@ -1610,7 +1604,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 = this->account (*random_block); + 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..bfc1681dc 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 diff --git a/nano/store/component.cpp b/nano/store/component.cpp index c95c16a19..67826f634 100644 --- a/nano/store/component.cpp +++ b/nano/store/component.cpp @@ -31,11 +31,11 @@ void nano::store::component::initialize (store::write_transaction const & transa auto hash_l (constants.genesis->hash ()); block.put (transaction_a, hash_l, *constants.genesis); ++ledger_cache_a.block_count; - confirmation_height.put (transaction_a, constants.genesis->account ().value (), nano::confirmation_height_info{ 1, constants.genesis->hash () }); + confirmation_height.put (transaction_a, constants.genesis->account (), nano::confirmation_height_info{ 1, constants.genesis->hash () }); ++ledger_cache_a.cemented_count; ledger_cache_a.final_votes_confirmation_canary = (constants.final_votes_canary_account == constants.genesis->account () && 1 >= constants.final_votes_canary_height); - account.put (transaction_a, constants.genesis->account ().value (), { hash_l, constants.genesis->account ().value (), constants.genesis->hash (), std::numeric_limits::max (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0 }); + account.put (transaction_a, constants.genesis->account (), { hash_l, constants.genesis->account (), constants.genesis->hash (), std::numeric_limits::max (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0 }); ++ledger_cache_a.account_count; - ledger_cache_a.rep_weights.representation_put (constants.genesis->account ().value (), std::numeric_limits::max ()); - frontier.put (transaction_a, hash_l, constants.genesis->account ().value ()); + ledger_cache_a.rep_weights.representation_put (constants.genesis->account (), std::numeric_limits::max ()); + frontier.put (transaction_a, hash_l, constants.genesis->account ()); } From deb5bf9017b2bcd2300c1e310f39bde12c031fc0 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 6 Mar 2024 23:14:19 +0000 Subject: [PATCH 05/17] Change block::balance to return an std::optional if the block actually contains the field. --- nano/core_test/active_transactions.cpp | 4 ++-- nano/core_test/node.cpp | 32 +++++++++++++------------- nano/core_test/request_aggregator.cpp | 2 +- nano/lib/blocks.cpp | 9 ++++---- nano/lib/blocks.hpp | 9 +++++--- nano/node/bootstrap/bootstrap_lazy.cpp | 4 ++-- nano/node/ipc/flatbuffers_util.cpp | 4 ++-- nano/node/json_handler.cpp | 2 +- nano/secure/ledger.cpp | 4 ++-- 9 files changed, 36 insertions(+), 34 deletions(-) diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index 2b1bc50d0..9f55c4018 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -502,14 +502,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 ().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 ().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/node.cpp b/nano/core_test/node.cpp index 493e8c52a..0e065baf9 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -3322,7 +3322,7 @@ TEST (node, rollback_vote_self) auto send2 = builder.make_block () .from (*send1) .previous (send1->hash ()) - .balance (send1->balance ().number () - 1) + .balance (send1->balance ().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 ())) @@ -3331,7 +3331,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 ().value ().number () - 2) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .build (); @@ -3419,7 +3419,7 @@ TEST (node, rollback_gap_source) auto send2 = builder.make_block () .from (*send1) .previous (send1->hash ()) - .balance (send1->balance ().number () - 1) + .balance (send1->balance ().value ().number () - 1) .link (key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (send1->hash ())) @@ -3510,7 +3510,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 ().value ().number () - 2) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (gen_receive->hash ())) .build (); @@ -3549,7 +3549,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 ().value ().number () - 1) .sign (key2.prv, key2.pub) .work (*system.work.generate (key2_send1->hash ())) .build (); @@ -3558,7 +3558,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 ().value ().number () + 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_send1->hash ())) .build (); @@ -3567,7 +3567,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 ().value ().number () - 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_receive->hash ())) .build (); @@ -3576,7 +3576,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 ().value ().number () + 1) .sign (key3.prv, key3.pub) .work (*system.work.generate (key3_open->hash ())) .build (); @@ -3585,7 +3585,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 ().value ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (key3_receive->hash ())) .build (); @@ -3711,7 +3711,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 ().value ().number () - 2) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (gen_receive->hash ())) .build (); @@ -3750,7 +3750,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 ().value ().number () - 1) .sign (key2.prv, key2.pub) .work (*system.work.generate (key2_send1->hash ())) .build (); @@ -3759,7 +3759,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 ().value ().number () + 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_send1->hash ())) .build (); @@ -3768,7 +3768,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 ().value ().number () - 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_receive->hash ())) .build (); @@ -3777,7 +3777,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 ().value ().number () + 1) .sign (key3.prv, key3.pub) .work (*system.work.generate (key3_open->hash ())) .build (); @@ -3786,7 +3786,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 ().value ()) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (key3_receive->hash ())) .build (); @@ -3856,7 +3856,7 @@ TEST (node, deferred_dependent_elections) auto send2 = builder.make_block () .from (*send1) .previous (send1->hash ()) - .balance (send1->balance ().number () - 1) + .balance (send1->balance ().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..7f7a4cabf 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 ().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/lib/blocks.cpp b/nano/lib/blocks.cpp index c2f5cbc2f..4256b2415 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -212,10 +212,9 @@ nano::qualified_root nano::block::qualified_root () const return { root (), previous () }; } -nano::amount const & nano::block::balance () const +std::optional nano::block::balance () const { - static nano::amount amount{ 0 }; - return amount; + return std::nullopt; } void nano::block::operator() (nano::object_stream & obs) const @@ -498,7 +497,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 () const { return hashables.balance; } @@ -1389,7 +1388,7 @@ nano::account const & nano::state_block::representative () const return hashables.representative; } -nano::amount const & nano::state_block::balance () const +std::optional nano::state_block::balance () const { return hashables.balance; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index f4a47650e..d492fb89c 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -46,7 +46,6 @@ public: // 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; @@ -68,6 +67,8 @@ public: // Direct access to the block fields or nullopt if the block type does n nano::account account () const noexcept; // Account field for open/state blocks virtual std::optional account_field () const; + // Balance field for open/send/state blocks + virtual std::optional balance () const; protected: mutable nano::block_hash cached_hash{ 0 }; @@ -114,7 +115,6 @@ public: 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; @@ -133,6 +133,9 @@ 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 () const override; + public: // Logging void operator() (nano::object_stream &) const override; }; @@ -335,7 +338,6 @@ public: 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; @@ -356,6 +358,7 @@ public: public: // State block fields std::optional account_field () const override; + std::optional balance () const override; public: // Logging void operator() (nano::object_stream &) const override; diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index 143937983..978973385 100644 --- a/nano/node/bootstrap/bootstrap_lazy.cpp +++ b/nano/node/bootstrap/bootstrap_lazy.cpp @@ -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 ().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 ().value ().number () <= next_block.balance) // balance { lazy_add (next_block.link, next_block.retry_limit); // link } diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index 8cf1fe5e4..1a902a402 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -10,7 +10,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano block->hash = block_a.hash ().to_string (); block->previous = block_a.previous ().to_string (); block->representative = block_a.representative ().to_account (); - block->balance = block_a.balance ().to_string_dec (); + block->balance = block_a.balance ().value ().to_string_dec (); block->link = block_a.link ().to_string (); block->link_as_account = block_a.link ().to_account (); block_a.signature.encode_hex (block->signature); @@ -39,7 +39,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano: { auto block (std::make_unique ()); block->hash = block_a.hash ().to_string (); - block->balance = block_a.balance ().to_string_dec (); + block->balance = block_a.balance ().value ().to_string_dec (); block->destination = block_a.hashables.destination.to_account (); block->previous = block_a.previous ().to_string (); block_a.signature.encode_hex (block->signature); diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 5b271232b..fcb298655 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 ().value ().number (); details_found = true; } // Epoch check diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 7477722ed..7d2da04b2 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -820,7 +820,7 @@ nano::uint128_t nano::ledger::balance (nano::block const & block) break; case nano::block_type::send: case nano::block_type::state: - result = block.balance ().number (); + result = block.balance ().value ().number (); break; case nano::block_type::invalid: case nano::block_type::not_a_block: @@ -995,7 +995,7 @@ bool nano::ledger::is_send (store::transaction const & transaction_a, nano::bloc { if (!previous.is_zero ()) { - if (block_a.balance () < balance (transaction_a, previous)) + if (block_a.balance ().value () < balance (transaction_a, previous)) { result = true; } From c6f506c5f96cc8e93540379922481bf129577576 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 6 Mar 2024 23:38:01 +0000 Subject: [PATCH 06/17] ledger::balance is moved to block::balance and block::balance which accesses the account field is renamed to block::balance_field. --- nano/core_test/active_transactions.cpp | 4 +-- nano/core_test/node.cpp | 32 +++++++++++------------ nano/core_test/request_aggregator.cpp | 2 +- nano/lib/blocks.cpp | 23 +++++++++++++--- nano/lib/blocks.hpp | 8 +++--- nano/node/bootstrap/bootstrap_lazy.cpp | 4 +-- nano/node/ipc/flatbuffers_util.cpp | 4 +-- nano/node/json_handler.cpp | 10 +++---- nano/node/node.cpp | 4 +-- nano/secure/ledger.cpp | 36 +++++--------------------- nano/secure/ledger.hpp | 1 - 11 files changed, 62 insertions(+), 66 deletions(-) diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index 9f55c4018..a831f9b1b 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -502,14 +502,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 ().value ().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 ().value ().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/node.cpp b/nano/core_test/node.cpp index 0e065baf9..6510565cb 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -3322,7 +3322,7 @@ TEST (node, rollback_vote_self) auto send2 = builder.make_block () .from (*send1) .previous (send1->hash ()) - .balance (send1->balance ().value ().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 ())) @@ -3331,7 +3331,7 @@ TEST (node, rollback_vote_self) // fork of send2 block auto fork = builder.make_block () .from (*send2) - .balance (send1->balance ().value ().number () - 2) + .balance (send1->balance_field ().value ().number () - 2) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .build (); @@ -3419,7 +3419,7 @@ TEST (node, rollback_gap_source) auto send2 = builder.make_block () .from (*send1) .previous (send1->hash ()) - .balance (send1->balance ().value ().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 ())) @@ -3510,7 +3510,7 @@ TEST (node, dependency_graph) .from (*gen_receive) .previous (gen_receive->hash ()) .link (key2.pub) - .balance (gen_receive->balance ().value ().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 (); @@ -3549,7 +3549,7 @@ TEST (node, dependency_graph) .from (*key2_send1) .previous (key2_send1->hash ()) .link (key1.pub) - .balance (key2_send1->balance ().value ().number () - 1) + .balance (key2_send1->balance_field ().value ().number () - 1) .sign (key2.prv, key2.pub) .work (*system.work.generate (key2_send1->hash ())) .build (); @@ -3558,7 +3558,7 @@ TEST (node, dependency_graph) .from (*key1_send1) .previous (key1_send1->hash ()) .link (key2_send2->hash ()) - .balance (key1_send1->balance ().value ().number () + 1) + .balance (key1_send1->balance_field ().value ().number () + 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_send1->hash ())) .build (); @@ -3567,7 +3567,7 @@ TEST (node, dependency_graph) .from (*key1_receive) .previous (key1_receive->hash ()) .link (key3.pub) - .balance (key1_receive->balance ().value ().number () - 1) + .balance (key1_receive->balance_field ().value ().number () - 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_receive->hash ())) .build (); @@ -3576,7 +3576,7 @@ TEST (node, dependency_graph) .from (*key3_open) .previous (key3_open->hash ()) .link (key1_send2->hash ()) - .balance (key3_open->balance ().value ().number () + 1) + .balance (key3_open->balance_field ().value ().number () + 1) .sign (key3.prv, key3.pub) .work (*system.work.generate (key3_open->hash ())) .build (); @@ -3585,7 +3585,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 ().value ()) + .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 (); @@ -3711,7 +3711,7 @@ TEST (node, dependency_graph_frontier) .from (*gen_receive) .previous (gen_receive->hash ()) .link (key2.pub) - .balance (gen_receive->balance ().value ().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 (); @@ -3750,7 +3750,7 @@ TEST (node, dependency_graph_frontier) .from (*key2_send1) .previous (key2_send1->hash ()) .link (key1.pub) - .balance (key2_send1->balance ().value ().number () - 1) + .balance (key2_send1->balance_field ().value ().number () - 1) .sign (key2.prv, key2.pub) .work (*system.work.generate (key2_send1->hash ())) .build (); @@ -3759,7 +3759,7 @@ TEST (node, dependency_graph_frontier) .from (*key1_send1) .previous (key1_send1->hash ()) .link (key2_send2->hash ()) - .balance (key1_send1->balance ().value ().number () + 1) + .balance (key1_send1->balance_field ().value ().number () + 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_send1->hash ())) .build (); @@ -3768,7 +3768,7 @@ TEST (node, dependency_graph_frontier) .from (*key1_receive) .previous (key1_receive->hash ()) .link (key3.pub) - .balance (key1_receive->balance ().value ().number () - 1) + .balance (key1_receive->balance_field ().value ().number () - 1) .sign (key1.prv, key1.pub) .work (*system.work.generate (key1_receive->hash ())) .build (); @@ -3777,7 +3777,7 @@ TEST (node, dependency_graph_frontier) .from (*key3_open) .previous (key3_open->hash ()) .link (key1_send2->hash ()) - .balance (key3_open->balance ().value ().number () + 1) + .balance (key3_open->balance_field ().value ().number () + 1) .sign (key3.prv, key3.pub) .work (*system.work.generate (key3_open->hash ())) .build (); @@ -3786,7 +3786,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 ().value ()) + .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 (); @@ -3856,7 +3856,7 @@ TEST (node, deferred_dependent_elections) auto send2 = builder.make_block () .from (*send1) .previous (send1->hash ()) - .balance (send1->balance ().value ().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 7f7a4cabf..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 ().value ().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/lib/blocks.cpp b/nano/lib/blocks.cpp index 4256b2415..50b222da5 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -202,6 +202,23 @@ nano::account nano::block::account () const noexcept } } +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); + } +} + std::optional nano::block::account_field () const { return std::nullopt; @@ -212,7 +229,7 @@ nano::qualified_root nano::block::qualified_root () const return { root (), previous () }; } -std::optional nano::block::balance () const +std::optional nano::block::balance_field () const { return std::nullopt; } @@ -497,7 +514,7 @@ nano::root const & nano::send_block::root () const return hashables.previous; } -std::optional nano::send_block::balance () const +std::optional nano::send_block::balance_field () const { return hashables.balance; } @@ -1388,7 +1405,7 @@ nano::account const & nano::state_block::representative () const return hashables.representative; } -std::optional nano::state_block::balance () const +std::optional nano::state_block::balance_field () const { return hashables.balance; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index d492fb89c..b7b609574 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -67,8 +67,10 @@ public: // Direct access to the block fields or nullopt if the block type does n 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 () const; + virtual std::optional balance_field () const; protected: mutable nano::block_hash cached_hash{ 0 }; @@ -134,7 +136,7 @@ public: static std::size_t constexpr size = nano::send_hashables::size + sizeof (signature) + sizeof (work); public: // Send block fields - std::optional balance () const override; + std::optional balance_field () const override; public: // Logging void operator() (nano::object_stream &) const override; @@ -358,7 +360,7 @@ public: public: // State block fields std::optional account_field () const override; - std::optional balance () const override; + std::optional balance_field () const override; public: // Logging void operator() (nano::object_stream &) const override; diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index 978973385..edfb5d647 100644 --- a/nano/node/bootstrap/bootstrap_lazy.cpp +++ b/nano/node/bootstrap/bootstrap_lazy.cpp @@ -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 ().value ().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 ().value ().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/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index 1a902a402..8cf1fe5e4 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -10,7 +10,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano block->hash = block_a.hash ().to_string (); block->previous = block_a.previous ().to_string (); block->representative = block_a.representative ().to_account (); - block->balance = block_a.balance ().value ().to_string_dec (); + 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_a.signature.encode_hex (block->signature); @@ -39,7 +39,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano: { auto block (std::make_unique ()); block->hash = block_a.hash ().to_string (); - block->balance = block_a.balance ().value ().to_string_dec (); + block->balance = block_a.balance ().to_string_dec (); block->destination = block_a.hashables.destination.to_account (); block->previous = block_a.previous ().to_string (); block_a.signature.encode_hex (block->signature); diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index fcb298655..3486188a0 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 ().value ().number (); + details.is_send = node.ledger.balance (transaction, previous) > block_a.balance_field ().value ().number (); details_found = true; } // Epoch check @@ -1157,8 +1157,8 @@ void nano::json_handler::block_info () { 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 ()); @@ -1314,8 +1314,8 @@ void nano::json_handler::blocks_info () { 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 ()); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 61a1c7fe1..fe292f7f7 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1230,12 +1230,12 @@ void nano::node::process_confirmed_data (store::transaction const & transaction_ // 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 { diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 7d2da04b2..d8deeeb15 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -480,8 +480,8 @@ 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); + auto balance = previous->balance (); + ledger.cache.rep_weights.representation_add_dual (block_a.representative (), balance.number (), info->representative, 0 - balance.number ()); 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); ledger.update_account (transaction, account, *info, new_info); ledger.store.frontier.del (transaction, block_a.hashables.previous); @@ -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 ().value ().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 @@ -995,7 +973,7 @@ bool nano::ledger::is_send (store::transaction const & transaction_a, nano::bloc { if (!previous.is_zero ()) { - if (block_a.balance ().value () < balance (transaction_a, previous)) + if (block_a.balance_field ().value () < balance (transaction_a, previous)) { result = true; } @@ -1151,17 +1129,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 diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index bfc1681dc..fda78dc68 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -37,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; From 5dad3a2c563d68bba004f2f4d50e91f98f09b364 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 12:19:49 +0000 Subject: [PATCH 07/17] Change block::destination to return an std::optional if the block actually contains the field. --- nano/core_test/block.cpp | 10 +++++----- nano/lib/blocks.cpp | 7 +++---- nano/lib/blocks.hpp | 6 +++--- nano/node/active_transactions.cpp | 2 +- nano/node/blockprocessor.cpp | 2 +- nano/node/bootstrap_ascending/service.cpp | 2 +- nano/node/wallet.cpp | 2 +- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index b187f63bb..74ff333f7 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -658,7 +658,7 @@ TEST (block_builder, state) .build (ec); ASSERT_EQ (block->hash ().to_string (), "2D243F8F92CDD0AD94A1D456A6B15F3BE7A6FCBD98D4C5831D06D15C818CD81F"); ASSERT_TRUE (block->source ().is_zero ()); - ASSERT_TRUE (block->destination ().is_zero ()); + ASSERT_FALSE (block->destination ()); ASSERT_EQ (block->link ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86"); } @@ -731,7 +731,7 @@ TEST (block_builder, open) .build (ec); ASSERT_EQ (block->hash ().to_string (), "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"); ASSERT_EQ (block->source ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"); - ASSERT_TRUE (block->destination ().is_zero ()); + ASSERT_FALSE (block->destination ()); ASSERT_TRUE (block->link ().is_zero ()); } @@ -770,7 +770,7 @@ TEST (block_builder, change) .build (ec); ASSERT_EQ (block->hash ().to_string (), "13552AC3928E93B5C6C215F61879358E248D4A5246B8B3D1EEC5A566EDCEE077"); ASSERT_TRUE (block->source ().is_zero ()); - ASSERT_TRUE (block->destination ().is_zero ()); + ASSERT_FALSE (block->destination ()); ASSERT_TRUE (block->link ().is_zero ()); } @@ -809,7 +809,7 @@ TEST (block_builder, send) .build (ec); ASSERT_EQ (block->hash ().to_string (), "4560E7B1F3735D082700CFC2852F5D1F378F7418FD24CEF1AD45AB69316F15CD"); ASSERT_TRUE (block->source ().is_zero ()); - ASSERT_EQ (block->destination ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb"); + ASSERT_EQ (block->destination ().value ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb"); ASSERT_TRUE (block->link ().is_zero ()); } @@ -871,6 +871,6 @@ TEST (block_builder, receive) .build (ec); ASSERT_EQ (block->hash ().to_string (), "6C004BF911D9CF2ED75CF6EC45E795122AD5D093FF5A83EDFBA43EC4A3EDC722"); ASSERT_EQ (block->source ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135"); - ASSERT_TRUE (block->destination ().is_zero ()); + ASSERT_FALSE (block->destination ()); ASSERT_TRUE (block->link ().is_zero ()); } diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 50b222da5..d42a32c6b 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -173,10 +173,9 @@ nano::block_hash const & nano::block::source () const return source; } -nano::account const & nano::block::destination () const +std::optional nano::block::destination () const { - static nano::account destination{}; - return destination; + return std::nullopt; } nano::link const & nano::block::link () const @@ -504,7 +503,7 @@ nano::block_hash const & nano::send_block::previous () const return hashables.previous; } -nano::account const & nano::send_block::destination () const +std::optional nano::send_block::destination () const { return hashables.destination; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index b7b609574..fe6264967 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -37,8 +37,6 @@ public: 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() @@ -71,6 +69,8 @@ public: // Direct access to the block fields or nullopt if the block type does n nano::amount balance () const noexcept; // Balance field for open/send/state blocks virtual std::optional balance_field () const; + // Destination account for send blocks + virtual std::optional destination () const; protected: mutable nano::block_hash cached_hash{ 0 }; @@ -115,7 +115,6 @@ public: 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; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); @@ -137,6 +136,7 @@ public: public: // Send block fields std::optional balance_field () const override; + std::optional destination () const override; public: // Logging void operator() (nano::object_stream &) const override; diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 0b39a6c67..29d47251e 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -165,7 +165,7 @@ 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 (); + auto destination = block->destination () ? block->destination ().value () : block->link ().as_account (); node.receive_confirmed (transaction, hash, destination); node.process_confirmed_data (transaction, block, hash, account, amount, is_state_send, is_state_epoch, pending_account); } diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index ecbd66985..beb9f1463 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -344,7 +344,7 @@ nano::block_status nano::block_processor::process_one (store::write_transaction { /* 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 () ? block->link () : block->destination ().value ()); } break; } diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 33746a1d6..2ea4d02c8 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -148,7 +148,7 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, switch (block.type ()) { case nano::block_type::send: - destination = block.destination (); + destination = block.destination ().value (); break; case nano::block_type::state: destination = block.link ().as_account (); diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index fde737b85..6814069ff 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1092,7 +1092,7 @@ 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 ()); + auto destination (block_a->link ().is_zero () ? block_a->destination ().value () : block_a->link ().as_account ()); receive_async ( block_a->hash (), representative_a, amount_a, destination, [&result] (std::shared_ptr const & block_a) { result.set_value (block_a == nullptr); From 61ad874e112358ad55c328f7d6bd52707c93ece7 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 12:37:53 +0000 Subject: [PATCH 08/17] ledger::destination is moved to block::destination_field and block::destination is created which accesses the the destination field for send blocks. --- nano/core_test/block.cpp | 10 +++++----- nano/lib/blocks.cpp | 19 +++++++++++++++++-- nano/lib/blocks.hpp | 6 ++++-- nano/node/active_transactions.cpp | 6 ++++-- nano/node/blockprocessor.cpp | 2 +- nano/node/bootstrap_ascending/service.cpp | 22 +++------------------- nano/node/wallet.cpp | 3 +-- 7 files changed, 35 insertions(+), 33 deletions(-) diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index 74ff333f7..102ace012 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -658,7 +658,7 @@ TEST (block_builder, state) .build (ec); ASSERT_EQ (block->hash ().to_string (), "2D243F8F92CDD0AD94A1D456A6B15F3BE7A6FCBD98D4C5831D06D15C818CD81F"); ASSERT_TRUE (block->source ().is_zero ()); - ASSERT_FALSE (block->destination ()); + ASSERT_FALSE (block->destination_field ()); ASSERT_EQ (block->link ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86"); } @@ -731,7 +731,7 @@ TEST (block_builder, open) .build (ec); ASSERT_EQ (block->hash ().to_string (), "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"); ASSERT_EQ (block->source ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"); - ASSERT_FALSE (block->destination ()); + ASSERT_FALSE (block->destination_field ()); ASSERT_TRUE (block->link ().is_zero ()); } @@ -770,7 +770,7 @@ TEST (block_builder, change) .build (ec); ASSERT_EQ (block->hash ().to_string (), "13552AC3928E93B5C6C215F61879358E248D4A5246B8B3D1EEC5A566EDCEE077"); ASSERT_TRUE (block->source ().is_zero ()); - ASSERT_FALSE (block->destination ()); + ASSERT_FALSE (block->destination_field ()); ASSERT_TRUE (block->link ().is_zero ()); } @@ -809,7 +809,7 @@ TEST (block_builder, send) .build (ec); ASSERT_EQ (block->hash ().to_string (), "4560E7B1F3735D082700CFC2852F5D1F378F7418FD24CEF1AD45AB69316F15CD"); ASSERT_TRUE (block->source ().is_zero ()); - ASSERT_EQ (block->destination ().value ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb"); + ASSERT_EQ (block->destination_field ().value ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb"); ASSERT_TRUE (block->link ().is_zero ()); } @@ -871,6 +871,6 @@ TEST (block_builder, receive) .build (ec); ASSERT_EQ (block->hash ().to_string (), "6C004BF911D9CF2ED75CF6EC45E795122AD5D093FF5A83EDFBA43EC4A3EDC722"); ASSERT_EQ (block->source ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135"); - ASSERT_FALSE (block->destination ()); + ASSERT_FALSE (block->destination_field ()); ASSERT_TRUE (block->link ().is_zero ()); } diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index d42a32c6b..cf475af78 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -173,7 +173,7 @@ nano::block_hash const & nano::block::source () const return source; } -std::optional nano::block::destination () const +std::optional nano::block::destination_field () const { return std::nullopt; } @@ -218,6 +218,21 @@ nano::amount nano::block::balance () const noexcept } } +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 ().as_account (); + default: + release_assert (false); + } +} + std::optional nano::block::account_field () const { return std::nullopt; @@ -503,7 +518,7 @@ nano::block_hash const & nano::send_block::previous () const return hashables.previous; } -std::optional nano::send_block::destination () const +std::optional nano::send_block::destination_field () const { return hashables.destination; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index fe6264967..515e610e5 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -69,8 +69,10 @@ public: // Direct access to the block fields or nullopt if the block type does n 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 () const; + virtual std::optional destination_field () const; protected: mutable nano::block_hash cached_hash{ 0 }; @@ -136,7 +138,7 @@ public: public: // Send block fields std::optional balance_field () const override; - std::optional destination () const override; + std::optional destination_field () const override; public: // Logging void operator() (nano::object_stream &) const override; diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 29d47251e..22600bfc6 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->destination () ? block->destination ().value () : block->link ().as_account (); - node.receive_confirmed (transaction, hash, destination); + if (block->sideband ().details.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); } diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index beb9f1463..823429552 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -344,7 +344,7 @@ nano::block_status nano::block_processor::process_one (store::write_transaction { /* block->destination () for legacy send blocks block->link () for state blocks (send subtype) */ - queue_unchecked (transaction_a, !block->destination () ? block->link () : block->destination ().value ()); + queue_unchecked (transaction_a, block->destination ()); } break; } diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 2ea4d02c8..7a0a3a34a 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -143,25 +143,9 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, if (is_send) { - // TODO: Encapsulate this as a helper somewhere - nano::account destination{ 0 }; - switch (block.type ()) - { - case nano::block_type::send: - destination = block.destination ().value (); - 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; diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 6814069ff..e155ecb6c 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -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 ().value () : 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); From fa81fc01ccef77b90c2ba271c8efe84c5112afc3 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 13:19:52 +0000 Subject: [PATCH 09/17] Change block::source to return an std::optional if the block actually contains the field. --- nano/core_test/block.cpp | 10 +++++----- nano/core_test/ledger.cpp | 6 +++--- nano/core_test/unchecked_map.cpp | 4 ++-- nano/lib/blocks.cpp | 9 ++++----- nano/lib/blocks.hpp | 10 ++++++---- nano/node/bootstrap/bootstrap_lazy.cpp | 4 ++-- nano/node/bootstrap_ascending/service.cpp | 2 +- nano/node/confirmation_height_bounded.cpp | 7 +------ nano/node/confirmation_height_unbounded.cpp | 7 +------ nano/node/ipc/flatbuffers_util.cpp | 4 ++-- nano/secure/ledger.cpp | 8 ++++---- 11 files changed, 31 insertions(+), 40 deletions(-) diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index 102ace012..d6640ffe9 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -657,7 +657,7 @@ TEST (block_builder, state) .link_hex ("E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86") .build (ec); ASSERT_EQ (block->hash ().to_string (), "2D243F8F92CDD0AD94A1D456A6B15F3BE7A6FCBD98D4C5831D06D15C818CD81F"); - ASSERT_TRUE (block->source ().is_zero ()); + ASSERT_FALSE (block->source ()); ASSERT_FALSE (block->destination_field ()); ASSERT_EQ (block->link ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86"); } @@ -730,7 +730,7 @@ TEST (block_builder, open) .source_hex ("E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA") .build (ec); ASSERT_EQ (block->hash ().to_string (), "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"); - ASSERT_EQ (block->source ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"); + ASSERT_EQ (block->source ().value ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"); ASSERT_FALSE (block->destination_field ()); ASSERT_TRUE (block->link ().is_zero ()); } @@ -769,7 +769,7 @@ TEST (block_builder, change) .previous_hex ("088EE46429CA936F76C4EAA20B97F6D33E5D872971433EE0C1311BCB98764456") .build (ec); ASSERT_EQ (block->hash ().to_string (), "13552AC3928E93B5C6C215F61879358E248D4A5246B8B3D1EEC5A566EDCEE077"); - ASSERT_TRUE (block->source ().is_zero ()); + ASSERT_FALSE (block->source ()); ASSERT_FALSE (block->destination_field ()); ASSERT_TRUE (block->link ().is_zero ()); } @@ -808,7 +808,7 @@ TEST (block_builder, send) .balance_hex ("00F035A9C7D818E7C34148C524FFFFEE") .build (ec); ASSERT_EQ (block->hash ().to_string (), "4560E7B1F3735D082700CFC2852F5D1F378F7418FD24CEF1AD45AB69316F15CD"); - ASSERT_TRUE (block->source ().is_zero ()); + ASSERT_FALSE (block->source ()); ASSERT_EQ (block->destination_field ().value ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb"); ASSERT_TRUE (block->link ().is_zero ()); } @@ -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_EQ (block->source ().value ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135"); ASSERT_FALSE (block->destination_field ()); ASSERT_TRUE (block->link ().is_zero ()); } diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index be50f1eec..ffdecf668 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -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 ().value ()); ASSERT_EQ (blocks.size (), 1); } node1.block_processor.add (send1); @@ -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 ().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 ().value ())); ASSERT_EQ (blocks.size (), 1); } node1.block_processor.add (send2); 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/lib/blocks.cpp b/nano/lib/blocks.cpp index cf475af78..07af4a1a3 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -167,10 +167,9 @@ nano::account const & nano::block::representative () const return representative; } -nano::block_hash const & nano::block::source () const +std::optional nano::block::source () const { - static nano::block_hash source{ 0 }; - return source; + return std::nullopt; } std::optional nano::block::destination_field () const @@ -809,7 +808,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 () const { return hashables.source; } @@ -1746,7 +1745,7 @@ nano::block_hash const & nano::receive_block::previous () const return hashables.previous; } -nano::block_hash const & nano::receive_block::source () const +std::optional nano::receive_block::source () const { return hashables.source; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 515e610e5..0e9760763 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -35,8 +35,6 @@ public: virtual void block_work_set (uint64_t) = 0; // 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; // Previous block or account number for open blocks virtual nano::root const & root () const = 0; // Qualified root value based on previous() and root() @@ -73,6 +71,8 @@ public: // Direct access to the block fields or nullopt if the block type does n nano::account destination () const noexcept; // Destination account for send blocks virtual std::optional destination_field () const; + // Source block for open/receive blocks + virtual std::optional source () const; protected: mutable nano::block_hash cached_hash{ 0 }; @@ -170,7 +170,6 @@ public: 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 &); @@ -190,6 +189,9 @@ public: uint64_t work; static std::size_t constexpr size = nano::receive_hashables::size + sizeof (signature) + sizeof (work); +public: // Receive block fields + std::optional source () const override; + public: // Logging void operator() (nano::object_stream &) const override; }; @@ -222,7 +224,6 @@ public: 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; nano::account const & representative () const override; void serialize (nano::stream &) const override; @@ -245,6 +246,7 @@ public: public: // Open block fields std::optional account_field () const override; + std::optional source () const override; public: // Logging void operator() (nano::object_stream &) const override; diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index edfb5d647..36b73eadb 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 () && !node->ledger.block_or_pruned_exists (block_a->source ().value ()) && block_a->source ().value () != node->network_params.ledger.genesis->account ()) { - lazy_add (block_a->source (), retry_limit); + lazy_add (block_a->source ().value (), retry_limit); } else if (block_a->type () == nano::block_type::state) { diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 7a0a3a34a..945b263ab 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -152,7 +152,7 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, case nano::block_status::gap_source: { const auto account = block.previous ().is_zero () ? block.account_field ().value () : ledger.account (tx, block.previous ()).value (); - const auto source = block.source ().is_zero () ? block.link ().as_block_hash () : block.source (); + const auto source = !block.source () ? block.link ().as_block_hash () : block.source ().value (); // Mark account as blocked because it is missing the source block accounts.block (account, source); diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index 68faaf07a..866dc2521 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -253,12 +253,7 @@ 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 (); - } - + auto source = block->source ().value_or (block->link ().as_block_hash ()); if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source)) { hit_receive = true; diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index b93fc6354..d1975d6e1 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -212,12 +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 (); - } - + auto source = block->source ().value_or (block->link ().as_block_hash ()); if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source)) { if (!hit_receive && !block_callback_data_a.empty ()) diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index 8cf1fe5e4..a7785467b 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -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 ().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,7 +62,7 @@ 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 ().value ().to_string (); block->account = block_a.account ().to_account (); block->representative = block_a.representative ().to_account (); block_a.signature.encode_hex (block->signature); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index d8deeeb15..1f0a65238 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1009,7 +1009,7 @@ nano::block_hash nano::ledger::block_source (store::transaction const & transact // 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::block_hash result = block_a.source ().value_or (0); nano::state_block const * state_block (dynamic_cast (&block_a)); if (state_block != nullptr && !is_send (transaction_a, *state_block)) { @@ -1210,13 +1210,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 ().value (); } void open_block (nano::open_block const & block_a) override { if (block_a.source () != ledger.constants.genesis->account ()) { - result[0] = block_a.source (); + result[0] = block_a.source ().value (); } } void change_block (nano::change_block const & block_a) override @@ -1266,7 +1266,7 @@ std::shared_ptr nano::ledger::find_receive_block_by_send_hash (stor 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 (); + nano::block_hash source = possible_receive_block->source ().value_or (0); // 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 ()); From b66bfe2a2c0ef0485b5343aff32f171f948e601a Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 14:17:06 +0000 Subject: [PATCH 10/17] ledger::source is moved to block::source_field and ledger::block_source is moved to block::source which accesses the source field for open/receive/state blocks that are receives. --- nano/core_test/block.cpp | 10 ++--- nano/core_test/ledger.cpp | 18 ++++----- nano/lib/blocks.cpp | 22 +++++++++-- nano/lib/blocks.hpp | 8 ++-- nano/node/blockprocessor.cpp | 2 +- nano/node/bootstrap/bootstrap_lazy.cpp | 4 +- nano/node/bootstrap_ascending/service.cpp | 2 +- nano/node/confirmation_height_bounded.cpp | 2 +- nano/node/confirmation_height_unbounded.cpp | 2 +- nano/node/ipc/flatbuffers_util.cpp | 4 +- nano/node/json_handler.cpp | 14 +++---- nano/secure/ledger.cpp | 43 ++------------------- nano/secure/ledger.hpp | 1 - 13 files changed, 57 insertions(+), 75 deletions(-) diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index d6640ffe9..1f04bb680 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -657,7 +657,7 @@ TEST (block_builder, state) .link_hex ("E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86") .build (ec); ASSERT_EQ (block->hash ().to_string (), "2D243F8F92CDD0AD94A1D456A6B15F3BE7A6FCBD98D4C5831D06D15C818CD81F"); - ASSERT_FALSE (block->source ()); + ASSERT_FALSE (block->source_field ()); ASSERT_FALSE (block->destination_field ()); ASSERT_EQ (block->link ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86"); } @@ -730,7 +730,7 @@ TEST (block_builder, open) .source_hex ("E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA") .build (ec); ASSERT_EQ (block->hash ().to_string (), "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"); - ASSERT_EQ (block->source ().value ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"); + ASSERT_EQ (block->source_field ().value ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"); ASSERT_FALSE (block->destination_field ()); ASSERT_TRUE (block->link ().is_zero ()); } @@ -769,7 +769,7 @@ TEST (block_builder, change) .previous_hex ("088EE46429CA936F76C4EAA20B97F6D33E5D872971433EE0C1311BCB98764456") .build (ec); ASSERT_EQ (block->hash ().to_string (), "13552AC3928E93B5C6C215F61879358E248D4A5246B8B3D1EEC5A566EDCEE077"); - ASSERT_FALSE (block->source ()); + ASSERT_FALSE (block->source_field ()); ASSERT_FALSE (block->destination_field ()); ASSERT_TRUE (block->link ().is_zero ()); } @@ -808,7 +808,7 @@ TEST (block_builder, send) .balance_hex ("00F035A9C7D818E7C34148C524FFFFEE") .build (ec); ASSERT_EQ (block->hash ().to_string (), "4560E7B1F3735D082700CFC2852F5D1F378F7418FD24CEF1AD45AB69316F15CD"); - ASSERT_FALSE (block->source ()); + ASSERT_FALSE (block->source_field ()); ASSERT_EQ (block->destination_field ().value ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb"); ASSERT_TRUE (block->link ().is_zero ()); } @@ -870,7 +870,7 @@ TEST (block_builder, receive) .source_hex ("7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135") .build (ec); ASSERT_EQ (block->hash ().to_string (), "6C004BF911D9CF2ED75CF6EC45E795122AD5D093FF5A83EDFBA43EC4A3EDC722"); - ASSERT_EQ (block->source ().value ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135"); + ASSERT_EQ (block->source_field ().value ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135"); ASSERT_FALSE (block->destination_field ()); ASSERT_TRUE (block->link ().is_zero ()); } diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index ffdecf668..35c44d4fa 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -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_FALSE (block1->source_field ()); ASSERT_EQ (nano::dev::genesis_key.pub, ledger.block_destination (transaction, *block2)); - ASSERT_TRUE (ledger.block_source (transaction, *block2).is_zero ()); + 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_FALSE (block4->source_field ()); ASSERT_EQ (nano::dev::genesis_key.pub, ledger.block_destination (transaction, *block5)); - ASSERT_TRUE (ledger.block_source (transaction, *block5).is_zero ()); + 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) @@ -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 ().value ()); + auto blocks = node1.unchecked.get (open1->source_field ().value ()); ASSERT_EQ (blocks.size (), 1); } node1.block_processor.add (send1); @@ -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 ().value ())); + 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 ().value ())); + auto blocks (node1.unchecked.get (receive1->source_field ().value ())); ASSERT_EQ (blocks.size (), 1); } node1.block_processor.add (send2); diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 07af4a1a3..22022cad6 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -167,7 +167,7 @@ nano::account const & nano::block::representative () const return representative; } -std::optional nano::block::source () const +std::optional nano::block::source_field () const { return std::nullopt; } @@ -232,6 +232,22 @@ nano::account nano::block::destination () const noexcept } } +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 ().as_block_hash (); + default: + release_assert (false); + } +} + std::optional nano::block::account_field () const { return std::nullopt; @@ -808,7 +824,7 @@ bool nano::open_block::valid_predecessor (nano::block const & block_a) const return false; } -std::optional nano::open_block::source () const +std::optional nano::open_block::source_field () const { return hashables.source; } @@ -1745,7 +1761,7 @@ nano::block_hash const & nano::receive_block::previous () const return hashables.previous; } -std::optional 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 0e9760763..081d20438 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -71,8 +71,10 @@ public: // Direct access to the block fields or nullopt if the block type does n nano::account destination () const noexcept; // Destination account for send blocks virtual std::optional destination_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 () const; + virtual std::optional source_field () const; protected: mutable nano::block_hash cached_hash{ 0 }; @@ -190,7 +192,7 @@ public: static std::size_t constexpr size = nano::receive_hashables::size + sizeof (signature) + sizeof (work); public: // Receive block fields - std::optional source () const override; + std::optional source_field () const override; public: // Logging void operator() (nano::object_stream &) const override; @@ -246,7 +248,7 @@ public: public: // Open block fields std::optional account_field () const override; - std::optional source () const override; + std::optional source_field () const override; public: // Logging void operator() (nano::object_stream &) const override; diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 823429552..2ad55c09c 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -356,7 +356,7 @@ 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); + node.unchecked.put (block->source_field ().value_or (block->link ().as_block_hash ()), block); node.stats.inc (nano::stat::type::ledger, nano::stat::detail::gap_source); break; } diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index 36b73eadb..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 () && !node->ledger.block_or_pruned_exists (block_a->source ().value ()) && block_a->source ().value () != 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 ().value (), retry_limit); + lazy_add (block_a->source_field ().value (), retry_limit); } else if (block_a->type () == nano::block_type::state) { diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 945b263ab..0643fd314 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -152,7 +152,7 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, case nano::block_status::gap_source: { const auto account = block.previous ().is_zero () ? block.account_field ().value () : ledger.account (tx, block.previous ()).value (); - const auto source = !block.source () ? block.link ().as_block_hash () : block.source ().value (); + const auto source = block.source_field ().value_or (block.link ().as_block_hash ()); // Mark account as blocked because it is missing the source block accounts.block (account, source); diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index 866dc2521..cce7747a9 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -253,7 +253,7 @@ 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 ().value_or (block->link ().as_block_hash ()); + auto source = block->source_field ().value_or (block->link ().as_block_hash ()); if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source)) { hit_receive = true; diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index d1975d6e1..61aa6a959 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -212,7 +212,7 @@ void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_source if (block) { - auto source = block->source ().value_or (block->link ().as_block_hash ()); + auto source = block->source_field ().value_or (block->link ().as_block_hash ()); if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source)) { if (!hit_receive && !block_callback_data_a.empty ()) diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index a7785467b..57afdecf3 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -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 ().value ().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,7 +62,7 @@ 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 ().value ().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_a.signature.encode_hex (block->signature); diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 3486188a0..8c5acd755 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1383,15 +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->sideband ().details.is_receive || !node.ledger.block_exists (transaction, block->source ())) { - entry.put ("source_account", block_a->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)); @@ -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 ().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->sideband ().details.is_send ? 0 : block_d->link ().as_block_hash ()); previous = block_d->previous (); block_d = node.ledger.block (transaction, previous); } diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 1f0a65238..d35a03d40 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -998,26 +998,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 ().value_or (0); - 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); @@ -1210,13 +1190,13 @@ public: void receive_block (nano::receive_block const & block_a) override { result[0] = block_a.previous (); - result[1] = block_a.source ().value (); + 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 ().value (); + result[0] = block_a.source_field ().value (); } } void change_block (nano::change_block const & block_a) override @@ -1265,22 +1245,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 ().value_or (0); - - // 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->sideband ().details.is_receive && send_block_hash == possible_receive_block->source ()) { // we have a match result = possible_receive_block; diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index fda78dc68..229c86b8d 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -58,7 +58,6 @@ public: 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); From 4b2f574c8a2496431986a7c01cb0f2fd91b22430 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 15:29:53 +0000 Subject: [PATCH 11/17] Change block::link to return an std::optional if the block actually contains the field. --- nano/core_test/block.cpp | 10 +++---- nano/core_test/wallet.cpp | 12 ++++----- nano/core_test/wallets.cpp | 2 +- nano/lib/blocks.cpp | 11 ++++---- nano/lib/blocks.hpp | 6 ++--- nano/nano_node/entry.cpp | 12 ++++----- nano/node/blockprocessor.cpp | 3 ++- nano/node/bootstrap_ascending/service.cpp | 2 +- nano/node/confirmation_height_bounded.cpp | 2 +- nano/node/confirmation_height_unbounded.cpp | 2 +- nano/node/ipc/flatbuffers_util.cpp | 6 ++--- nano/node/json_handler.cpp | 16 +++++------ nano/node/node.cpp | 6 ++--- nano/node/websocket.cpp | 4 +-- nano/rpc_test/receivable.cpp | 30 ++++++++++----------- nano/rpc_test/rpc.cpp | 22 +++++++-------- nano/secure/ledger.cpp | 2 +- 17 files changed, 74 insertions(+), 74 deletions(-) diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index 1f04bb680..cab5e34a2 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -659,7 +659,7 @@ TEST (block_builder, state) ASSERT_EQ (block->hash ().to_string (), "2D243F8F92CDD0AD94A1D456A6B15F3BE7A6FCBD98D4C5831D06D15C818CD81F"); ASSERT_FALSE (block->source_field ()); ASSERT_FALSE (block->destination_field ()); - ASSERT_EQ (block->link ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86"); + ASSERT_EQ (block->link ().value ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86"); } TEST (block_builder, state_missing_rep) @@ -732,7 +732,7 @@ TEST (block_builder, open) ASSERT_EQ (block->hash ().to_string (), "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"); ASSERT_EQ (block->source_field ().value ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"); ASSERT_FALSE (block->destination_field ()); - ASSERT_TRUE (block->link ().is_zero ()); + ASSERT_FALSE (block->link ()); } TEST (block_builder, open_equality) @@ -771,7 +771,7 @@ TEST (block_builder, change) ASSERT_EQ (block->hash ().to_string (), "13552AC3928E93B5C6C215F61879358E248D4A5246B8B3D1EEC5A566EDCEE077"); ASSERT_FALSE (block->source_field ()); ASSERT_FALSE (block->destination_field ()); - ASSERT_TRUE (block->link ().is_zero ()); + ASSERT_FALSE (block->link ()); } TEST (block_builder, change_equality) @@ -810,7 +810,7 @@ TEST (block_builder, send) ASSERT_EQ (block->hash ().to_string (), "4560E7B1F3735D082700CFC2852F5D1F378F7418FD24CEF1AD45AB69316F15CD"); ASSERT_FALSE (block->source_field ()); ASSERT_EQ (block->destination_field ().value ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb"); - ASSERT_TRUE (block->link ().is_zero ()); + ASSERT_FALSE (block->link ()); } TEST (block_builder, send_equality) @@ -872,5 +872,5 @@ TEST (block_builder, receive) ASSERT_EQ (block->hash ().to_string (), "6C004BF911D9CF2ED75CF6EC45E795122AD5D093FF5A83EDFBA43EC4A3EDC722"); ASSERT_EQ (block->source_field ().value ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135"); ASSERT_FALSE (block->destination_field ()); - ASSERT_TRUE (block->link ().is_zero ()); + ASSERT_FALSE (block->link ()); } diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index ab107d56a..c1a56fc5d 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -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->link ().value ().as_account (), 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->link ().value ().as_account (), 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->link ().value ().as_account (), 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->link ().value ().as_account (), 1); ASSERT_NE (nullptr, receive1); if (nano::dev::network_params.work.difficulty (*receive1) < node.network_params.work.base) { @@ -1190,7 +1190,7 @@ TEST (wallet, search_receivable) 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->link ().value ().as_block_hash ()); } 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->link ().value ().as_account (), 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 bbff7d287..c596cad9c 100644 --- a/nano/core_test/wallets.cpp +++ b/nano/core_test/wallets.cpp @@ -254,6 +254,6 @@ TEST (wallets, search_receivable) 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->link ().value ().as_block_hash ()); } } diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 22022cad6..1d1f19e3d 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -177,10 +177,9 @@ std::optional nano::block::destination_field () const return std::nullopt; } -nano::link const & nano::block::link () const +std::optional nano::block::link () const { - static nano::link link{ 0 }; - return link; + return std::nullopt; } nano::account nano::block::account () const noexcept @@ -226,7 +225,7 @@ nano::account nano::block::destination () const noexcept return destination_field ().value (); case nano::block_type::state: release_assert (sideband ().details.is_send); - return link ().as_account (); + return link ().value ().as_account (); default: release_assert (false); } @@ -242,7 +241,7 @@ nano::block_hash nano::block::source () const noexcept return source_field ().value (); case nano::block_type::state: release_assert (sideband ().details.is_receive); - return link ().as_block_hash (); + return link ().value ().as_block_hash (); default: release_assert (false); } @@ -1424,7 +1423,7 @@ nano::root const & nano::state_block::root () const } } -nano::link const & nano::state_block::link () const +std::optional nano::state_block::link () const { return hashables.link; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 081d20438..b67bf3c91 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -39,8 +39,6 @@ public: 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 void serialize (nano::stream &) const = 0; virtual void serialize_json (std::string &, bool = false) const = 0; @@ -71,6 +69,8 @@ public: // Direct access to the block fields or nullopt if the block type does n 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 () 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 @@ -344,7 +344,6 @@ public: void block_work_set (uint64_t) override; nano::block_hash const & previous () const override; nano::root const & root () const override; - nano::link const & link () const override; nano::account const & representative () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); @@ -367,6 +366,7 @@ public: public: // State block fields std::optional account_field () const override; std::optional balance_field () const override; + std::optional link () const override; public: // Logging void operator() (nano::object_stream &) const override; diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 3c5b79a6b..a01d25b1f 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 ().value ()), hash, block->block_signature ()); } } } @@ -1529,12 +1529,12 @@ int main (int argc, char * const * argv) } else { - if (block->link ().is_zero ()) + if (block->link ().value ().is_zero ()) { // 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 ().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->link ().value ().as_block_hash ()); } } } @@ -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)) { @@ -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 ().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/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 2ad55c09c..d968a312e 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -356,7 +356,8 @@ nano::block_status nano::block_processor::process_one (store::write_transaction } case nano::block_status::gap_source: { - node.unchecked.put (block->source_field ().value_or (block->link ().as_block_hash ()), block); + release_assert (block->source_field () || block->link ()); + node.unchecked.put (block->source_field ().value_or (block->link ().value_or (0).as_block_hash ()), block); node.stats.inc (nano::stat::type::ledger, nano::stat::detail::gap_source); break; } diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 0643fd314..a614f0e34 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -152,7 +152,7 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, case nano::block_status::gap_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 ().as_block_hash ()); + const auto source = block.source_field ().value_or (block.link ().value_or (0).as_block_hash ()); // Mark account as blocked because it is missing the source block accounts.block (account, source); diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index cce7747a9..459b835ab 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -253,7 +253,7 @@ 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_field ().value_or (block->link ().as_block_hash ()); + auto source = block->source_field ().value_or (block->link ().value_or (0).as_block_hash ()); if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source)) { hit_receive = true; diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index 61aa6a959..807743b76 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -212,7 +212,7 @@ void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_source if (block) { - auto source = block->source_field ().value_or (block->link ().as_block_hash ()); + auto source = block->source_field ().value_or (block->link ().value_or (0).as_block_hash ()); if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source)) { if (!hit_receive && !block_callback_data_a.empty ()) diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index 57afdecf3..de252a079 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -11,8 +11,8 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano block->previous = block_a.previous ().to_string (); block->representative = block_a.representative ().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 ().value ().to_string (); + block->link_as_account = block_a.link ().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.link ().value ().is_zero ()) { block->subtype = nanoapi::BlockSubType::BlockSubType_change; } diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 8c5acd755..8a5e185fc 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -411,12 +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 (); + if (link && !details.is_send) { - auto block_link = node.ledger.block (transaction, 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.as_block_hash ()))) + 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; @@ -1224,7 +1224,7 @@ 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_epoch = amount.value () == 0 && node.ledger.is_epoch_link (state->link ().value ()); } } node.observers.blocks.notify (status, {}, account, amount ? amount.value () : 0, is_state_send, is_state_epoch); @@ -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 ().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 = block->source_field ().value_or (block->link ().as_block_hash ()); + nano::block_hash source = block->source_field ().value_or (block->link ().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 = block_d->source_field ().value_or (block_d->sideband ().details.is_send ? 0 : block_d->link ().as_block_hash ()); + source = block_d->source_field ().value_or (block_d->sideband ().details.is_send ? 0 : block_d->link ().value_or (0).as_block_hash ()); previous = block_d->previous (); block_d = node.ledger.block (transaction, previous); } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index fe292f7f7..608fb375c 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -260,13 +260,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->link ().value ().is_zero ()) { 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 ().value ())); event.add ("subtype", "epoch"); } else @@ -1252,7 +1252,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 ().value ())) { is_state_epoch_a = true; } diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index dbd16637a..eee9297fe 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->link ().value ().is_zero ()) { 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 ().value ())); subtype = "epoch"; } else diff --git a/nano/rpc_test/receivable.cpp b/nano/rpc_test/receivable.cpp index 236165745..f7a0a45cb 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->link ().value ().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->link ().value ().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->link ().value ().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->link ().value ().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->link ().value ().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->link ().value ().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)); @@ -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->link ().value ().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->link ().value ().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->link ().value ().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->link ().value ().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->link ().value ().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->link ().value ().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->link ().value ().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->link ().value ().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->link ().value ().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 16fd73146..b188faae1 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -923,7 +923,7 @@ 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->link ().value ().as_account ())); ASSERT_NE (nullptr, receive); nano::block_builder builder; auto usend = builder @@ -1007,7 +1007,7 @@ 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->link ().value ().as_account ())); ASSERT_NE (nullptr, receive); nano::block_builder builder; auto usend = builder @@ -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->link ().value ().as_account ())); // 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->link ().value ().as_account ())); ASSERT_NE (nullptr, receive); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; @@ -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->link ().value ().as_account ())); + auto recv4 (system.wallet (0)->receive_action (send4->hash (), key1.pub, node->config.receive_minimum.number (), send4->link ().value ().as_account ())); + auto recv3 (system.wallet (0)->receive_action (send3->hash (), key1.pub, node->config.receive_minimum.number (), send3->link ().value ().as_account ())); + auto recv2 (system.wallet (0)->receive_action (send2->hash (), key1.pub, node->config.receive_minimum.number (), send2->link ().value ().as_account ())); // 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->link ().value ().as_account ())); ASSERT_NE (nullptr, receive); auto change (system.wallet (0)->change_action (nano::dev::genesis_key.pub, key.pub)); ASSERT_NE (nullptr, change); @@ -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->link ().value ().as_account ())); 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->link ().value ().as_account ())); ASSERT_NE (nullptr, receive); nano::keypair key; auto timestamp3 = nano::seconds_since_epoch (); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index d35a03d40..49efbeae5 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -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 ().value ()), block_a.hash (), block_a.signature)) { result = nano::block_status::bad_signature; } From 9bcb65ca2434ce3bc78f37544e4ffaf2d673a326 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 17:12:10 +0000 Subject: [PATCH 12/17] Moving ledger::is_send to block::is_send. A specialised variant of is_send for state blocks that do not have sideband was added to dependent_block_visitor so the value can be calculated even if the block does not yet have sideband. --- nano/core_test/ledger.cpp | 38 ++++++++--------- nano/lib/blocks.cpp | 14 +++++++ nano/lib/blocks.hpp | 1 + nano/nano_node/entry.cpp | 2 +- nano/node/active_transactions.cpp | 2 +- nano/node/blockprocessor.cpp | 2 +- nano/node/bootstrap_ascending/service.cpp | 3 +- nano/node/json_handler.cpp | 4 +- nano/rpc_test/rpc.cpp | 2 +- nano/secure/ledger.cpp | 50 ++++++++--------------- nano/secure/ledger.hpp | 1 - 11 files changed, 57 insertions(+), 62 deletions(-) diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 35c44d4fa..55913060f 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -2392,7 +2392,7 @@ TEST (ledger, state_send_receive) 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_TRUE (send2->is_send ()); ASSERT_FALSE (send2->sideband ().details.is_receive); ASSERT_FALSE (send2->sideband ().details.is_epoch); auto receive1 = builder @@ -2416,7 +2416,7 @@ TEST (ledger, state_send_receive) 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_FALSE (receive2->is_send ()); ASSERT_TRUE (receive2->sideband ().details.is_receive); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -2464,7 +2464,7 @@ TEST (ledger, state_receive) ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, receive1->hash ())); 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_FALSE (receive2->is_send ()); ASSERT_TRUE (receive2->sideband ().details.is_receive); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -2498,7 +2498,7 @@ TEST (ledger, state_rep_change) 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->is_send ()); ASSERT_FALSE (change2->sideband ().details.is_receive); ASSERT_FALSE (change2->sideband ().details.is_epoch); } @@ -2552,7 +2552,7 @@ TEST (ledger, state_open) 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_FALSE (open2->is_send ()); ASSERT_TRUE (open2->sideband ().details.is_receive); ASSERT_FALSE (open2->sideband ().details.is_epoch); } @@ -2978,7 +2978,7 @@ TEST (ledger, state_send_change) 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_TRUE (send2->is_send ()); ASSERT_FALSE (send2->sideband ().details.is_receive); ASSERT_FALSE (send2->sideband ().details.is_epoch); } @@ -3030,7 +3030,7 @@ TEST (ledger, state_receive_change) 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_FALSE (receive2->is_send ()); ASSERT_TRUE (receive2->sideband ().details.is_receive); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -3401,7 +3401,7 @@ TEST (ledger, epoch_blocks_v1_general) .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->is_send ()); ASSERT_FALSE (epoch1->sideband ().details.is_receive); ASSERT_TRUE (epoch1->sideband ().details.is_epoch); ASSERT_EQ (nano::epoch::epoch_1, epoch1->sideband ().details.epoch); @@ -3428,7 +3428,7 @@ TEST (ledger, epoch_blocks_v1_general) 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->is_send ()); ASSERT_FALSE (epoch1->sideband ().details.is_receive); ASSERT_TRUE (epoch1->sideband ().details.is_epoch); ASSERT_EQ (nano::epoch::epoch_1, epoch1->sideband ().details.epoch); @@ -3452,7 +3452,7 @@ TEST (ledger, epoch_blocks_v1_general) .work (*pool.generate (epoch1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (send1->sideband ().details.is_send); + ASSERT_TRUE (send1->is_send ()); ASSERT_FALSE (send1->sideband ().details.is_receive); ASSERT_FALSE (send1->sideband ().details.is_epoch); ASSERT_EQ (nano::epoch::epoch_1, send1->sideband ().details.epoch); @@ -3488,7 +3488,7 @@ 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->is_send ()); ASSERT_FALSE (epoch4->sideband ().details.is_receive); ASSERT_TRUE (epoch4->sideband ().details.is_epoch); ASSERT_EQ (nano::epoch::epoch_1, epoch4->sideband ().details.epoch); @@ -3519,7 +3519,7 @@ TEST (ledger, epoch_blocks_v1_general) 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_key.pub)); ASSERT_EQ (nano::Gxrb_ratio, ledger.weight (destination.pub)); - ASSERT_FALSE (receive2->sideband ().details.is_send); + ASSERT_FALSE (receive2->is_send ()); ASSERT_TRUE (receive2->sideband ().details.is_receive); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -4295,7 +4295,7 @@ 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); } @@ -4916,7 +4916,7 @@ TEST (ledger, pruning_action) ASSERT_EQ (*receive1, *receive1_stored); 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_FALSE (receive1_stored->is_send ()); ASSERT_TRUE (receive1_stored->sideband ().details.is_receive); ASSERT_FALSE (receive1_stored->sideband ().details.is_epoch); // Middle block pruning @@ -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) diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 1d1f19e3d..713196e5c 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -115,6 +115,20 @@ 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; + } +} + nano::block_hash const & nano::block::hash () const { if (!cached_hash.is_zero ()) diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index b67bf3c91..2c0c2d179 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -55,6 +55,7 @@ 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; 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 diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index a01d25b1f..4153f923e 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -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 (); } diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 22600bfc6..d2df96e36 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -165,7 +165,7 @@ 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) { - if (block->sideband ().details.is_send) + if (block->is_send ()) { node.receive_confirmed (transaction, hash, block->destination ()); } diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index d968a312e..53e6fe06e 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -340,7 +340,7 @@ 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) */ diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index a614f0e34..37f01746a 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -134,14 +134,13 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, case nano::block_status::progress: { const auto account = block.account (); - const auto is_send = ledger.is_send (tx, block); // 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 ()) { auto destination = block.destination (); accounts.unblock (destination, hash); // Unblocking automatically inserts account into priority set diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 8a5e185fc..4c4934560 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1223,7 +1223,7 @@ 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_send = state->is_send (); is_state_epoch = amount.value () == 0 && node.ledger.is_epoch_link (state->link ().value ()); } } @@ -3679,7 +3679,7 @@ void nano::json_handler::republish () while (block_d != nullptr && hash != source) { hashes.push_back (previous); - source = block_d->source_field ().value_or (block_d->sideband ().details.is_send ? 0 : block_d->link ().value_or (0).as_block_hash ()); + source = block_d->source_field ().value_or (block_d->is_send () ? 0 : block_d->link ().value_or (0).as_block_hash ()); previous = block_d->previous (); block_d = node.ledger.block (transaction, previous); } diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index b188faae1..b74fe6eec 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -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 ()); } diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 49efbeae5..836370e33 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -950,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_field ().value () < 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)); @@ -990,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 (); } @@ -1208,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; diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 229c86b8d..5f1b1e49b 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -56,7 +56,6 @@ 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 &); std::pair hash_root_random (store::transaction const &) const; std::optional pending_info (store::transaction const & transaction, nano::pending_key const & key) const; From a60a16b338afd2ed48337ff5c665910f28580b40 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Fri, 8 Mar 2024 00:04:10 +0000 Subject: [PATCH 13/17] Creating block::is_receive function to determine if a block is a receive/open/state block that's a receive --- nano/core_test/ledger.cpp | 28 ++++++++++++++-------------- nano/lib/blocks.cpp | 15 +++++++++++++++ nano/lib/blocks.hpp | 1 + nano/node/json_handler.cpp | 2 +- nano/rpc_test/rpc.cpp | 6 +++--- nano/secure/ledger.cpp | 2 +- 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 55913060f..a08eb2422 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -2393,7 +2393,7 @@ TEST (ledger, state_send_receive) 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->is_send ()); - ASSERT_FALSE (send2->sideband ().details.is_receive); + ASSERT_FALSE (send2->is_receive ()); ASSERT_FALSE (send2->sideband ().details.is_epoch); auto receive1 = builder .state () @@ -2417,7 +2417,7 @@ TEST (ledger, state_send_receive) ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count); ASSERT_EQ (3, receive2->sideband ().height); ASSERT_FALSE (receive2->is_send ()); - ASSERT_TRUE (receive2->sideband ().details.is_receive); + ASSERT_TRUE (receive2->is_receive ()); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -2465,7 +2465,7 @@ TEST (ledger, state_receive) ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (3, receive2->sideband ().height); ASSERT_FALSE (receive2->is_send ()); - ASSERT_TRUE (receive2->sideband ().details.is_receive); + ASSERT_TRUE (receive2->is_receive ()); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -2499,7 +2499,7 @@ TEST (ledger, state_rep_change) ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (rep.pub)); ASSERT_EQ (2, change2->sideband ().height); ASSERT_FALSE (change2->is_send ()); - ASSERT_FALSE (change2->sideband ().details.is_receive); + ASSERT_FALSE (change2->is_receive ()); ASSERT_FALSE (change2->sideband ().details.is_epoch); } @@ -2553,7 +2553,7 @@ TEST (ledger, state_open) ASSERT_EQ (ledger.cache.account_count, store.account.count (transaction)); ASSERT_EQ (1, open2->sideband ().height); ASSERT_FALSE (open2->is_send ()); - ASSERT_TRUE (open2->sideband ().details.is_receive); + ASSERT_TRUE (open2->is_receive ()); ASSERT_FALSE (open2->sideband ().details.is_epoch); } @@ -2979,7 +2979,7 @@ TEST (ledger, state_send_change) ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (rep.pub)); ASSERT_EQ (2, send2->sideband ().height); ASSERT_TRUE (send2->is_send ()); - ASSERT_FALSE (send2->sideband ().details.is_receive); + ASSERT_FALSE (send2->is_receive ()); ASSERT_FALSE (send2->sideband ().details.is_epoch); } @@ -3031,7 +3031,7 @@ TEST (ledger, state_receive_change) ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (rep.pub)); ASSERT_EQ (3, receive2->sideband ().height); ASSERT_FALSE (receive2->is_send ()); - ASSERT_TRUE (receive2->sideband ().details.is_receive); + ASSERT_TRUE (receive2->is_receive ()); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -3402,7 +3402,7 @@ TEST (ledger, epoch_blocks_v1_general) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, epoch1)); ASSERT_FALSE (epoch1->is_send ()); - ASSERT_FALSE (epoch1->sideband ().details.is_receive); + 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 @@ -3429,7 +3429,7 @@ TEST (ledger, epoch_blocks_v1_general) ASSERT_TRUE (genesis_info); ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_1); ASSERT_FALSE (epoch1->is_send ()); - ASSERT_FALSE (epoch1->sideband ().details.is_receive); + 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 @@ -3453,7 +3453,7 @@ TEST (ledger, epoch_blocks_v1_general) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (send1->is_send ()); - ASSERT_FALSE (send1->sideband ().details.is_receive); + 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 @@ -3489,7 +3489,7 @@ TEST (ledger, epoch_blocks_v1_general) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, epoch4)); ASSERT_FALSE (epoch4->is_send ()); - ASSERT_FALSE (epoch4->sideband ().details.is_receive); + 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 @@ -3520,7 +3520,7 @@ TEST (ledger, epoch_blocks_v1_general) 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->is_send ()); - ASSERT_TRUE (receive2->sideband ().details.is_receive); + ASSERT_TRUE (receive2->is_receive ()); ASSERT_FALSE (receive2->sideband ().details.is_epoch); } @@ -4297,7 +4297,7 @@ TEST (ledger, unchecked_epoch_invalid) ASSERT_EQ (nano::epoch::epoch_0, epoch2_store->sideband ().details.epoch); 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 ()); } } @@ -4917,7 +4917,7 @@ TEST (ledger, pruning_action) 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->is_send ()); - ASSERT_TRUE (receive1_stored->sideband ().details.is_receive); + 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 ())); diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 713196e5c..2a644a615 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -129,6 +129,21 @@ bool nano::block::is_send () const noexcept } } +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; + } +} + nano::block_hash const & nano::block::hash () const { if (!cached_hash.is_zero ()) diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 2c0c2d179..b93582c55 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -56,6 +56,7 @@ public: // 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; 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 diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 4c4934560..894234ce7 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1383,7 +1383,7 @@ void nano::json_handler::blocks_info () } if (source) { - if (!block->sideband ().details.is_receive || !node.ledger.block_exists (transaction, block->source ())) + if (!block->is_receive () || !node.ledger.block_exists (transaction, block->source ())) { entry.put ("source_account", "0"); } diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index b74fe6eec..bfda4364a 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -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 ()); } diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 836370e33..ce6ceb105 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1227,7 +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 (possible_receive_block->sideband ().details.is_receive && send_block_hash == possible_receive_block->source ()) + if (possible_receive_block->is_receive () && send_block_hash == possible_receive_block->source ()) { // we have a match result = possible_receive_block; From dece1bcb10eb084908b682a5f299291197199e51 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Fri, 8 Mar 2024 00:32:17 +0000 Subject: [PATCH 14/17] Create block::is_change function which determines if a block is a change block or a state block with a zero link field. --- nano/lib/blocks.cpp | 18 ++++++++++++++++++ nano/lib/blocks.hpp | 1 + nano/nano_node/entry.cpp | 2 +- nano/node/ipc/flatbuffers_util.cpp | 2 +- nano/node/node.cpp | 2 +- nano/node/websocket.cpp | 2 +- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 2a644a615..3caf2f51b 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -144,6 +144,24 @@ bool nano::block::is_receive () const noexcept } } +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 ().value ().is_zero ()) + { + return true; + } + return false; + default: + return false; + } +} + nano::block_hash const & nano::block::hash () const { if (!cached_hash.is_zero ()) diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index b93582c55..f1a7b56c8 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -57,6 +57,7 @@ public: 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 diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 4153f923e..4ce7a3002 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1529,7 +1529,7 @@ int main (int argc, char * const * argv) } else { - if (block->link ().value ().is_zero ()) + if (block->is_change ()) { // State change block_details_error = sideband.details.is_send || sideband.details.is_receive || sideband.details.is_epoch; diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index de252a079..a36a0d2d4 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -20,7 +20,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano { block->subtype = nanoapi::BlockSubType::BlockSubType_send; } - else if (block_a.link ().value ().is_zero ()) + else if (block_a.is_change ()) { block->subtype = nanoapi::BlockSubType::BlockSubType_change; } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 608fb375c..8b1a3e86c 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -260,7 +260,7 @@ 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 ().value ().is_zero ()) + if (block_a->is_change ()) { event.add ("subtype", "change"); } diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index eee9297fe..f9de5a6c6 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -1012,7 +1012,7 @@ nano::websocket_server::websocket_server (nano::websocket::config & config_a, na } else if (block_a->type () == nano::block_type::state) { - if (block_a->link ().value ().is_zero ()) + if (block_a->is_change ()) { subtype = "change"; } From 17e502d543a96dd85acb8b387cd1201ea57b68e3 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Fri, 8 Mar 2024 09:46:25 +0000 Subject: [PATCH 15/17] Renaming block::link to block::link_field. Usages that converted this number to an account number are replaced with calls to block::destination (). Usages that converted this number to a block_hash are replaced with calls to block::source, and usages that check this number for being an epoch directly access the link field. --- nano/core_test/block.cpp | 10 +++---- nano/core_test/wallet.cpp | 12 ++++----- nano/core_test/wallets.cpp | 2 +- nano/lib/blocks.cpp | 10 +++---- nano/lib/blocks.hpp | 4 +-- nano/nano_node/entry.cpp | 8 +++--- nano/node/blockprocessor.cpp | 4 +-- nano/node/bootstrap_ascending/service.cpp | 2 +- nano/node/confirmation_height_bounded.cpp | 5 ++-- nano/node/confirmation_height_unbounded.cpp | 5 ++-- nano/node/ipc/flatbuffers_util.cpp | 4 +-- nano/node/json_handler.cpp | 12 ++++----- nano/node/node.cpp | 4 +-- nano/node/websocket.cpp | 2 +- nano/rpc_test/receivable.cpp | 30 ++++++++++----------- nano/rpc_test/rpc.cpp | 22 +++++++-------- nano/secure/ledger.cpp | 2 +- 17 files changed, 68 insertions(+), 70 deletions(-) diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index cab5e34a2..f5dd614b3 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -659,7 +659,7 @@ TEST (block_builder, state) ASSERT_EQ (block->hash ().to_string (), "2D243F8F92CDD0AD94A1D456A6B15F3BE7A6FCBD98D4C5831D06D15C818CD81F"); ASSERT_FALSE (block->source_field ()); ASSERT_FALSE (block->destination_field ()); - ASSERT_EQ (block->link ().value ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86"); + ASSERT_EQ (block->link_field ().value ().to_string (), "E16DD58C1EFA8B521545B0A74375AA994D9FC43828A4266D75ECF57F07A7EE86"); } TEST (block_builder, state_missing_rep) @@ -732,7 +732,7 @@ TEST (block_builder, open) ASSERT_EQ (block->hash ().to_string (), "991CF190094C00F0B68E2E5F75F6BEE95A2E0BD93CEAA4A6734DB9F19B728948"); ASSERT_EQ (block->source_field ().value ().to_string (), "E89208DD038FBB269987689621D52292AE9C35941A7484756ECCED92A65093BA"); ASSERT_FALSE (block->destination_field ()); - ASSERT_FALSE (block->link ()); + ASSERT_FALSE (block->link_field ()); } TEST (block_builder, open_equality) @@ -771,7 +771,7 @@ TEST (block_builder, change) ASSERT_EQ (block->hash ().to_string (), "13552AC3928E93B5C6C215F61879358E248D4A5246B8B3D1EEC5A566EDCEE077"); ASSERT_FALSE (block->source_field ()); ASSERT_FALSE (block->destination_field ()); - ASSERT_FALSE (block->link ()); + ASSERT_FALSE (block->link_field ()); } TEST (block_builder, change_equality) @@ -810,7 +810,7 @@ TEST (block_builder, send) ASSERT_EQ (block->hash ().to_string (), "4560E7B1F3735D082700CFC2852F5D1F378F7418FD24CEF1AD45AB69316F15CD"); ASSERT_FALSE (block->source_field ()); ASSERT_EQ (block->destination_field ().value ().to_account (), "nano_1gys8r4crpxhp94n4uho5cshaho81na6454qni5gu9n53gksoyy1wcd4udyb"); - ASSERT_FALSE (block->link ()); + ASSERT_FALSE (block->link_field ()); } TEST (block_builder, send_equality) @@ -872,5 +872,5 @@ TEST (block_builder, receive) ASSERT_EQ (block->hash ().to_string (), "6C004BF911D9CF2ED75CF6EC45E795122AD5D093FF5A83EDFBA43EC4A3EDC722"); ASSERT_EQ (block->source_field ().value ().to_string (), "7B2B0A29C1B235FDF9B4DEF2984BB3573BD1A52D28246396FBB3E4C5FE662135"); ASSERT_FALSE (block->destination_field ()); - ASSERT_FALSE (block->link ()); + ASSERT_FALSE (block->link_field ()); } diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index c1a56fc5d..0250f291d 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -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 ().value ().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 ().value ().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 ().value ().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 ().value ().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) { @@ -1190,7 +1190,7 @@ TEST (wallet, search_receivable) auto receive = node.block (receive_hash); ASSERT_NE (nullptr, receive); ASSERT_EQ (receive->sideband ().height, 3); - ASSERT_EQ (send->hash (), receive->link ().value ().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 ().value ().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 c596cad9c..606fa18f4 100644 --- a/nano/core_test/wallets.cpp +++ b/nano/core_test/wallets.cpp @@ -254,6 +254,6 @@ TEST (wallets, search_receivable) auto receive = node.block (receive_hash); ASSERT_NE (nullptr, receive); ASSERT_EQ (receive->sideband ().height, 3); - ASSERT_EQ (send->hash (), receive->link ().value ().as_block_hash ()); + ASSERT_EQ (send->hash (), receive->source ()); } } diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 3caf2f51b..8be4273a6 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -152,7 +152,7 @@ bool nano::block::is_change () const noexcept case nano::block_type::change: return true; case nano::block_type::state: - if (link ().value ().is_zero ()) + if (link_field ().value ().is_zero ()) { return true; } @@ -224,7 +224,7 @@ std::optional nano::block::destination_field () const return std::nullopt; } -std::optional nano::block::link () const +std::optional nano::block::link_field () const { return std::nullopt; } @@ -272,7 +272,7 @@ nano::account nano::block::destination () const noexcept return destination_field ().value (); case nano::block_type::state: release_assert (sideband ().details.is_send); - return link ().value ().as_account (); + return link_field ().value ().as_account (); default: release_assert (false); } @@ -288,7 +288,7 @@ nano::block_hash nano::block::source () const noexcept return source_field ().value (); case nano::block_type::state: release_assert (sideband ().details.is_receive); - return link ().value ().as_block_hash (); + return link_field ().value ().as_block_hash (); default: release_assert (false); } @@ -1470,7 +1470,7 @@ nano::root const & nano::state_block::root () const } } -std::optional nano::state_block::link () const +std::optional nano::state_block::link_field () const { return hashables.link; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index f1a7b56c8..eb6bc4a07 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -73,7 +73,7 @@ public: // Direct access to the block fields or nullopt if the block type does n // Destination account for send blocks virtual std::optional destination_field () const; // Link field for state blocks - virtual std::optional link () const; + virtual std::optional link_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 @@ -369,7 +369,7 @@ public: public: // State block fields std::optional account_field () const override; std::optional balance_field () const override; - std::optional link () const override; + std::optional link_field () const override; public: // Logging void operator() (nano::object_stream &) const override; diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 4ce7a3002..31105b7ac 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 ().value ()), hash, block->block_signature ()); + invalid = validate_message (node->ledger.epoch_signer (block->link_field ().value ()), hash, block->block_signature ()); } } } @@ -1534,7 +1534,7 @@ int main (int argc, char * const * argv) // 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 ().value ())) + 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 ().value ().as_block_hash ()); + block_details_error |= !node->ledger.block_or_pruned_exists (transaction, block->source ()); } } } @@ -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 ().value ())) + 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/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 53e6fe06e..92efa88e2 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -356,8 +356,8 @@ nano::block_status nano::block_processor::process_one (store::write_transaction } case nano::block_status::gap_source: { - release_assert (block->source_field () || block->link ()); - node.unchecked.put (block->source_field ().value_or (block->link ().value_or (0).as_block_hash ()), 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; } diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 37f01746a..e75a26c24 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -151,7 +151,7 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, case nano::block_status::gap_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 ().value_or (0).as_block_hash ()); + 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); diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index 459b835ab..dfb7dea6d 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -253,14 +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_field ().value_or (block->link ().value_or (0).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 807743b76..20e7101c1 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -212,8 +212,7 @@ void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_source if (block) { - auto source = block->source_field ().value_or (block->link ().value_or (0).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 ()) { @@ -228,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/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index a36a0d2d4..cd95d848f 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -11,8 +11,8 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano block->previous = block_a.previous ().to_string (); block->representative = block_a.representative ().to_account (); block->balance = block_a.balance ().to_string_dec (); - block->link = block_a.link ().value ().to_string (); - block->link_as_account = block_a.link ().value ().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); diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 894234ce7..386eb7c48 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -411,8 +411,8 @@ 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 && !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.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; @@ -1224,7 +1224,7 @@ void nano::json_handler::block_confirm () if (auto state = dynamic_cast (block_l.get ())) { is_state_send = state->is_send (); - is_state_epoch = amount.value () == 0 && node.ledger.is_epoch_link (state->link ().value ()); + 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); @@ -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 ().value ()).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 = block->source_field ().value_or (block->link ().value_or (0).as_block_hash ()); + 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 = block_d->source_field ().value_or (block_d->is_send () ? 0 : block_d->link ().value_or (0).as_block_hash ()); + 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); } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 8b1a3e86c..e9fa0e2d6 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -266,7 +266,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons } else if (is_state_epoch_a) { - debug_assert (amount_a == 0 && node_l->ledger.is_epoch_link (block_a->link ().value ())); + debug_assert (amount_a == 0 && node_l->ledger.is_epoch_link (block_a->link_field ().value ())); event.add ("subtype", "epoch"); } else @@ -1252,7 +1252,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 ().value ())) + 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/websocket.cpp b/nano/node/websocket.cpp index f9de5a6c6..e33d1c889 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -1018,7 +1018,7 @@ nano::websocket_server::websocket_server (nano::websocket::config & config_a, na } else if (is_state_epoch_a) { - debug_assert (amount_a == 0 && ledger.is_epoch_link (block_a->link ().value ())); + debug_assert (amount_a == 0 && ledger.is_epoch_link (block_a->link_field ().value ())); subtype = "epoch"; } else diff --git a/nano/rpc_test/receivable.cpp b/nano/rpc_test/receivable.cpp index f7a0a45cb..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 ().value ().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 ().value ().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 ().value ().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 ().value ().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 ().value ().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 ().value ().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)); @@ -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 ().value ().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 ().value ().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 ().value ().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 ().value ().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 ().value ().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 ().value ().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 ().value ().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 ().value ().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 ().value ().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 bfda4364a..500675268 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -923,7 +923,7 @@ 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 ().value ().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 @@ -1007,7 +1007,7 @@ 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 ().value ().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 @@ -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 ().value ().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 ().value ().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; @@ -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 ().value ().as_account ())); - auto recv4 (system.wallet (0)->receive_action (send4->hash (), key1.pub, node->config.receive_minimum.number (), send4->link ().value ().as_account ())); - auto recv3 (system.wallet (0)->receive_action (send3->hash (), key1.pub, node->config.receive_minimum.number (), send3->link ().value ().as_account ())); - auto recv2 (system.wallet (0)->receive_action (send2->hash (), key1.pub, node->config.receive_minimum.number (), send2->link ().value ().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 ().value ().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); @@ -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 ().value ().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 ().value ().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 (); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index ce6ceb105..02447c33f 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -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 ().value ()), 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; } From e75fb68b05de3cee9cc7156be46383c1bb79e8c4 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Fri, 8 Mar 2024 10:17:43 +0000 Subject: [PATCH 16/17] Change block::representative to return an std::optional if the block actually contains the field. --- nano/lib/blocks.cpp | 17 ++++++++--------- nano/lib/blocks.hpp | 11 +++++++---- nano/nano_node/entry.cpp | 2 +- nano/node/ipc/flatbuffers_util.cpp | 6 +++--- nano/node/json_handler.cpp | 4 ++-- nano/rpc_test/rpc.cpp | 4 ++-- nano/secure/ledger.cpp | 28 ++++++++++++++-------------- 7 files changed, 37 insertions(+), 35 deletions(-) diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 8be4273a6..c174a6d99 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -208,10 +208,9 @@ 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; } std::optional nano::block::source_field () const @@ -796,7 +795,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); @@ -880,7 +879,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; } @@ -1060,7 +1059,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); @@ -1146,7 +1145,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; } @@ -1372,7 +1371,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 ()); @@ -1475,7 +1474,7 @@ 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; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index eb6bc4a07..ad860a1bc 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -39,7 +39,6 @@ public: virtual nano::root const & root () const = 0; // Qualified root value based on previous() and root() virtual nano::qualified_root qualified_root () const; - virtual nano::account const & representative () 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; @@ -74,6 +73,8 @@ public: // Direct access to the block fields or nullopt if the block type does n virtual std::optional destination_field () const; // Link field for state blocks virtual std::optional link_field () const; + // 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 @@ -230,7 +231,6 @@ public: 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; @@ -251,6 +251,7 @@ public: public: // Open block fields std::optional account_field () const override; + std::optional representative_field () const override; std::optional source_field () const override; public: // Logging @@ -284,7 +285,6 @@ public: 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; @@ -303,6 +303,9 @@ public: uint64_t work; static std::size_t constexpr size = nano::change_hashables::size + sizeof (signature) + sizeof (work); +public: // Change block fields + std::optional representative_field () const override; + public: // Logging void operator() (nano::object_stream &) const override; }; @@ -347,7 +350,6 @@ public: 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; @@ -370,6 +372,7 @@ public: // State block fields std::optional account_field () const override; std::optional balance_field () const override; std::optional link_field () const override; + std::optional representative_field () const override; public: // Logging void operator() (nano::object_stream &) const override; diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 31105b7ac..a18d22af3 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -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); diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index cd95d848f..f8265733f 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -9,7 +9,7 @@ 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_field ().value ().to_string (); block->link_as_account = block_a.link_field ().value ().to_account (); @@ -64,7 +64,7 @@ std::unique_ptr nano::ipc::flatbuffers_builder::from (nano: block->hash = block_a.hash ().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 386eb7c48..2442a23c3 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -685,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 (); } } diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 500675268..3e7f70346 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -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) diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 02447c33f..74b70e6e2 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -85,7 +85,7 @@ public: auto amount = ledger.amount (transaction, hash).value (); 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); @@ -103,8 +103,8 @@ public: 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); @@ -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 ()) { @@ -481,8 +481,8 @@ void ledger_processor::change_block (nano::change_block & block_a) 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 = previous->balance (); - ledger.cache.rep_weights.representation_add_dual (block_a.representative (), balance.number (), info->representative, 0 - balance.number ()); - 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); + 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); } From 5332f2c3f5240977221c9c0263450602d8b798ec Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Fri, 8 Mar 2024 14:27:59 +0000 Subject: [PATCH 17/17] Change block::previous to block::previous_field and return std::optional depending if the block has the field. Add block::previous with backwards compatibility and a todo to fix up usages to not check for sentinel values. --- nano/lib/blocks.cpp | 27 ++++++++++++++++++++------- nano/lib/blocks.hpp | 16 +++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index c174a6d99..060681ac1 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -293,6 +293,20 @@ nano::block_hash nano::block::source () const noexcept } } +// 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; @@ -573,7 +587,7 @@ 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; } @@ -743,10 +757,9 @@ 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; } std::optional nano::open_block::account_field () const @@ -1015,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; } @@ -1314,7 +1327,7 @@ 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; } @@ -1801,7 +1814,7 @@ 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; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index ad860a1bc..d6cca7437 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -33,8 +33,6 @@ public: virtual void hash (blake2b_state &) const = 0; virtual uint64_t block_work () const = 0; virtual void block_work_set (uint64_t) = 0; - // Previous block in account's chain, zero for open block - virtual nano::block_hash const & previous () const = 0; // Previous block or account number for open blocks virtual nano::root const & root () const = 0; // Qualified root value based on previous() and root() @@ -73,6 +71,10 @@ public: // Direct access to the block fields or nullopt if the block type does n 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 @@ -122,7 +124,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::root const & root () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); @@ -145,6 +146,7 @@ public: 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; @@ -175,7 +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::root const & root () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); @@ -196,6 +197,7 @@ public: 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 @@ -229,7 +231,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::root const & root () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); @@ -251,6 +252,7 @@ public: 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; @@ -283,7 +285,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::root const & root () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); @@ -304,6 +305,7 @@ public: 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 @@ -348,7 +350,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::root const & root () const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); @@ -372,6 +373,7 @@ 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