diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index 764a9d4273..fa2e6d4d40 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -253,7 +255,7 @@ TEST (inactive_votes_cache, basic) node.vote_processor.vote (vote, std::make_shared (node, node)); ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 1); node.process_active (send); - ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.ledger.tx_begin_read (), send->hash ())); + ASSERT_TIMELY (5s, node.ledger.confirmed.block_exists_or_pruned (node.ledger.tx_begin_read (), send->hash ())); ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached)); } @@ -1014,7 +1016,7 @@ TEST (active_transactions, confirmation_consistency) auto block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::public_key (), node.config.receive_minimum.number ())); ASSERT_NE (nullptr, block); system.deadline_set (5s); - while (!node.ledger.block_confirmed (node.ledger.tx_begin_read (), block->hash ())) + while (!node.ledger.confirmed.block_exists_or_pruned (node.ledger.tx_begin_read (), block->hash ())) { node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ()); ASSERT_NO_ERROR (system.poll (5ms)); diff --git a/nano/core_test/backlog.cpp b/nano/core_test/backlog.cpp index 9c83f77e1d..f13c16f1c5 100644 --- a/nano/core_test/backlog.cpp +++ b/nano/core_test/backlog.cpp @@ -21,7 +21,7 @@ TEST (backlog, population) nano::test::system system{}; auto & node = *system.add_node (); - node.backlog.activate_callback.add ([&] (nano::secure::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { + node.backlog.activate_callback.add ([&] (nano::secure::transaction const & transaction, nano::account const & account) { nano::lock_guard lock{ mutex }; activated.insert (account); diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 852a765f9b..c0e311097d 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -1116,29 +1117,29 @@ TEST (mdb_block_store, sideband_height) .work (*pool.generate (key3.pub)) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open)); - auto block1 = ledger.block (transaction, nano::dev::genesis->hash ()); + auto block1 = ledger.any.block_get (transaction, nano::dev::genesis->hash ()); ASSERT_EQ (block1->sideband ().height, 1); - auto block2 = ledger.block (transaction, send->hash ()); + auto block2 = ledger.any.block_get (transaction, send->hash ()); ASSERT_EQ (block2->sideband ().height, 2); - auto block3 = ledger.block (transaction, receive->hash ()); + auto block3 = ledger.any.block_get (transaction, receive->hash ()); ASSERT_EQ (block3->sideband ().height, 3); - auto block4 = ledger.block (transaction, change->hash ()); + auto block4 = ledger.any.block_get (transaction, change->hash ()); ASSERT_EQ (block4->sideband ().height, 4); - auto block5 = ledger.block (transaction, state_send1->hash ()); + auto block5 = ledger.any.block_get (transaction, state_send1->hash ()); ASSERT_EQ (block5->sideband ().height, 5); - auto block6 = ledger.block (transaction, state_send2->hash ()); + auto block6 = ledger.any.block_get (transaction, state_send2->hash ()); ASSERT_EQ (block6->sideband ().height, 6); - auto block7 = ledger.block (transaction, state_send3->hash ()); + auto block7 = ledger.any.block_get (transaction, state_send3->hash ()); ASSERT_EQ (block7->sideband ().height, 7); - auto block8 = ledger.block (transaction, state_open->hash ()); + auto block8 = ledger.any.block_get (transaction, state_open->hash ()); ASSERT_EQ (block8->sideband ().height, 1); - auto block9 = ledger.block (transaction, epoch->hash ()); + auto block9 = ledger.any.block_get (transaction, epoch->hash ()); ASSERT_EQ (block9->sideband ().height, 2); - auto block10 = ledger.block (transaction, epoch_open->hash ()); + auto block10 = ledger.any.block_get (transaction, epoch_open->hash ()); ASSERT_EQ (block10->sideband ().height, 1); - auto block11 = ledger.block (transaction, state_receive->hash ()); + auto block11 = ledger.any.block_get (transaction, state_receive->hash ()); ASSERT_EQ (block11->sideband ().height, 2); - auto block12 = ledger.block (transaction, open->hash ()); + auto block12 = ledger.any.block_get (transaction, open->hash ()); ASSERT_EQ (block12->sideband ().height, 1); } diff --git a/nano/core_test/blockprocessor.cpp b/nano/core_test/blockprocessor.cpp index 381cd1a915..ad7b3fffaa 100644 --- a/nano/core_test/blockprocessor.cpp +++ b/nano/core_test/blockprocessor.cpp @@ -38,5 +38,5 @@ TEST (block_processor, broadcast_block_on_arrival) // awakes process_block() -> process_batch() -> process_one() -> process_live() node1->process_active (send1); // Checks whether the block was broadcast. - ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send1->hash ())); + ASSERT_TIMELY (5s, node2->block_or_pruned_exists (send1->hash ())); } diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index aeaeec51fb..23600e035d 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -655,13 +656,13 @@ TEST (bootstrap_processor, push_diamond_pruning) node1->ledger.confirm (transaction, open->hash ()); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 2)); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, open->hash (), 1)); - ASSERT_TRUE (node1->ledger.block_exists (transaction, nano::dev::genesis->hash ())); - ASSERT_FALSE (node1->ledger.block_exists (transaction, send1->hash ())); + ASSERT_TRUE (node1->ledger.any.block_exists (transaction, nano::dev::genesis->hash ())); + ASSERT_FALSE (node1->ledger.any.block_exists (transaction, send1->hash ())); ASSERT_TRUE (node1->store.pruned.exists (transaction, send1->hash ())); - ASSERT_FALSE (node1->ledger.block_exists (transaction, open->hash ())); + ASSERT_FALSE (node1->ledger.any.block_exists (transaction, open->hash ())); ASSERT_TRUE (node1->store.pruned.exists (transaction, open->hash ())); - ASSERT_TRUE (node1->ledger.block_exists (transaction, send2->hash ())); - ASSERT_TRUE (node1->ledger.block_exists (transaction, receive->hash ())); + ASSERT_TRUE (node1->ledger.any.block_exists (transaction, send2->hash ())); + ASSERT_TRUE (node1->ledger.any.block_exists (transaction, receive->hash ())); ASSERT_EQ (2, node1->ledger.pruned_count ()); ASSERT_EQ (5, node1->ledger.block_count ()); } @@ -1293,10 +1294,10 @@ TEST (bootstrap_processor, lazy_destinations) // Check processed blocks ASSERT_TIMELY (5s, !node2->bootstrap_initiator.in_progress ()); - ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send1->hash ())); - ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send2->hash ())); - ASSERT_FALSE (node2->ledger.block_or_pruned_exists (open->hash ())); - ASSERT_FALSE (node2->ledger.block_or_pruned_exists (state_open->hash ())); + ASSERT_TIMELY (5s, node2->block_or_pruned_exists (send1->hash ())); + ASSERT_TIMELY (5s, node2->block_or_pruned_exists (send2->hash ())); + ASSERT_FALSE (node2->block_or_pruned_exists (open->hash ())); + ASSERT_FALSE (node2->block_or_pruned_exists (state_open->hash ())); } TEST (bootstrap_processor, lazy_pruning_missing_block) @@ -1517,7 +1518,7 @@ TEST (bootstrap_processor, wallet_lazy_frontier) ASSERT_EQ (key2.pub.to_account (), wallet_attempt->id); } // Check processed blocks - ASSERT_TIMELY (10s, node1->ledger.block_or_pruned_exists (receive2->hash ())); + ASSERT_TIMELY (10s, node1->block_or_pruned_exists (receive2->hash ())); } TEST (bootstrap_processor, wallet_lazy_pending) @@ -1581,7 +1582,7 @@ TEST (bootstrap_processor, wallet_lazy_pending) wallet->insert_adhoc (key2.prv); node1->bootstrap_wallet (); // Check processed blocks - ASSERT_TIMELY (10s, node1->ledger.block_or_pruned_exists (send2->hash ())); + ASSERT_TIMELY (10s, node1->block_or_pruned_exists (send2->hash ())); } TEST (bootstrap_processor, multiple_attempts) diff --git a/nano/core_test/bootstrap_ascending.cpp b/nano/core_test/bootstrap_ascending.cpp index ad18c2432f..1cd5b70073 100644 --- a/nano/core_test/bootstrap_ascending.cpp +++ b/nano/core_test/bootstrap_ascending.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -252,7 +253,7 @@ TEST (bootstrap_ascending, trace_base) // std::cerr << "--------------- Start ---------------\n"; ASSERT_EQ (nano::block_status::progress, node0.process (send1)); ASSERT_EQ (nano::block_status::progress, node0.process (receive1)); - ASSERT_EQ (node1.ledger.receivable_end (), node1.ledger.receivable_upper_bound (node1.ledger.tx_begin_read (), key.pub, 0)); + ASSERT_EQ (node1.ledger.any.receivable_end (), node1.ledger.any.receivable_upper_bound (node1.ledger.tx_begin_read (), key.pub, 0)); // std::cerr << "node0: " << node0.network.endpoint () << std::endl; // std::cerr << "node1: " << node1.network.endpoint () << std::endl; ASSERT_TIMELY (10s, node1.block (receive1->hash ()) != nullptr); diff --git a/nano/core_test/confirming_set.cpp b/nano/core_test/confirming_set.cpp index 6fe35bebfb..5c05d778d8 100644 --- a/nano/core_test/confirming_set.cpp +++ b/nano/core_test/confirming_set.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -160,7 +161,7 @@ TEST (confirmation_callback, confirmed_history) ASSERT_TRUE (node->active.empty ()); auto transaction = node->ledger.tx_begin_read (); - ASSERT_FALSE (node->ledger.block_confirmed (transaction, send->hash ())); + ASSERT_FALSE (node->ledger.confirmed.block_exists (transaction, send->hash ())); ASSERT_TIMELY (10s, node->store.write_queue.contains (nano::store::writer::confirmation_height)); @@ -171,7 +172,7 @@ TEST (confirmation_callback, confirmed_history) ASSERT_TIMELY (10s, !node->store.write_queue.contains (nano::store::writer::confirmation_height)); auto transaction = node->ledger.tx_begin_read (); - ASSERT_TRUE (node->ledger.block_confirmed (transaction, send->hash ())); + ASSERT_TRUE (node->ledger.confirmed.block_exists (transaction, send->hash ())); ASSERT_TIMELY_EQ (10s, node->active.size (), 0); ASSERT_TIMELY_EQ (10s, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out), 1); diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 64ea76f95c..a9cec4fa16 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -41,8 +43,17 @@ TEST (ledger, empty) auto & store = ctx.store (); auto transaction = ledger.tx_begin_read (); nano::account account; - auto balance (ledger.account_balance (transaction, account)); - ASSERT_TRUE (balance.is_zero ()); + auto balance (ledger.any.account_balance (transaction, account)); + ASSERT_FALSE (balance); +} + +// Ledger can be initialized and returns a basic query for an empty account +TEST (ledger, confirmed_unconfirmed_view) +{ + auto ctx = nano::test::context::ledger_empty (); + auto & ledger = ctx.ledger (); + auto & unconfirmed = ledger; + auto & confirmed = ledger.confirmed; } // Genesis account should have the max balance on empty initialization @@ -52,9 +63,9 @@ TEST (ledger, genesis_balance) auto & ledger = ctx.ledger (); auto & store = ctx.store (); auto transaction = ledger.tx_begin_write (); - auto balance = ledger.account_balance (transaction, nano::dev::genesis_key.pub); + auto balance = ledger.any.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_key.pub); + auto info = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info); ASSERT_EQ (1, ledger.account_count ()); // Frontier time should have been updated when genesis balance was added @@ -85,7 +96,7 @@ TEST (ledger, process_modifies_sideband) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (ledger.tx_begin_write (), send1)); - ASSERT_EQ (send1->sideband ().timestamp, ledger.block (ledger.tx_begin_read (), send1->hash ())->sideband ().timestamp); + ASSERT_EQ (send1->sideband ().timestamp, ledger.any.block_get (ledger.tx_begin_read (), send1->hash ())->sideband ().timestamp); } // Create a send block and publish it. @@ -96,7 +107,7 @@ TEST (ledger, process_send) auto & store = ctx.store (); auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::keypair key2; nano::block_builder builder; @@ -115,14 +126,14 @@ TEST (ledger, process_send) ASSERT_EQ (nano::block_status::progress, return1); ASSERT_EQ (nano::dev::genesis_key.pub, send->sideband ().account); ASSERT_EQ (2, send->sideband ().height); - ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.amount (transaction, hash1)); + ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.any.block_amount (transaction, hash1)); ASSERT_EQ (nano::dev::genesis_key.pub, send->account ()); - ASSERT_EQ (50, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (50, ledger.any.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); + auto info2 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info2); ASSERT_EQ (2, info2->block_count); - auto latest6 = ledger.block (transaction, info2->head); + auto latest6 = ledger.any.block_get (transaction, info2->head); ASSERT_NE (nullptr, latest6); auto latest7 = dynamic_cast (latest6.get ()); ASSERT_NE (nullptr, latest7); @@ -143,51 +154,51 @@ TEST (ledger, process_send) 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); - ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.amount (transaction, hash2)); + ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.any.block_amount (transaction, hash2)); ASSERT_EQ (nano::block_status::progress, return2); ASSERT_EQ (key2.pub, open->account ()); - ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.amount (transaction, hash2)); - ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_balance (transaction, key2.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.any.block_amount (transaction, hash2)); + ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.any.account_balance (transaction, key2.pub)); ASSERT_EQ (0, ledger.account_receivable (transaction, key2.pub)); ASSERT_EQ (50, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.weight (key2.pub)); - auto info3 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info3 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info3); - auto latest2 = ledger.block (transaction, info3->head); + auto latest2 = ledger.any.block_get (transaction, info3->head); ASSERT_NE (nullptr, latest2); auto latest3 = dynamic_cast (latest2.get ()); ASSERT_NE (nullptr, latest3); ASSERT_EQ (*send, *latest3); - auto info4 = ledger.account_info (transaction, key2.pub); + auto info4 = ledger.any.account_get (transaction, key2.pub); ASSERT_TRUE (info4); - auto latest4 = ledger.block (transaction, info4->head); + auto latest4 = ledger.any.block_get (transaction, info4->head); ASSERT_NE (nullptr, latest4); auto latest5 = dynamic_cast (latest4.get ()); ASSERT_NE (nullptr, latest5); ASSERT_EQ (*open, *latest5); ASSERT_FALSE (ledger.rollback (transaction, hash2)); - auto info5 = ledger.account_info (transaction, key2.pub); + auto info5 = ledger.any.account_get (transaction, key2.pub); ASSERT_FALSE (info5); - auto pending1 = ledger.pending_info (transaction, nano::pending_key (key2.pub, hash1)); + auto pending1 = ledger.any.pending_get (transaction, nano::pending_key (key2.pub, hash1)); ASSERT_TRUE (pending1); ASSERT_EQ (nano::dev::genesis_key.pub, pending1->source); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, pending1->amount.number ()); - ASSERT_EQ (0, ledger.account_balance (transaction, key2.pub)); + ASSERT_FALSE (ledger.any.account_balance (transaction, key2.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_receivable (transaction, key2.pub)); - ASSERT_EQ (50, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (50, ledger.any.account_balance (transaction, nano::dev::genesis_key.pub).value ().number ()); ASSERT_EQ (50, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (0, ledger.weight (key2.pub)); - auto info6 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info6 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info6); ASSERT_EQ (hash1, info6->head); ASSERT_FALSE (ledger.rollback (transaction, info6->head)); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); - auto info7 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info7 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info7); ASSERT_EQ (1, info7->block_count); ASSERT_EQ (info1->head, info7->head); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key (key2.pub, hash1))); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key (key2.pub, hash1))); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.any.account_balance (transaction, nano::dev::genesis_key.pub).value ().number ()); ASSERT_EQ (0, ledger.account_receivable (transaction, key2.pub)); ASSERT_EQ (store.account.count (transaction), ledger.account_count ()); } @@ -199,7 +210,7 @@ TEST (ledger, process_receive) auto & store = ctx.store (); auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::keypair key2; nano::block_builder builder; @@ -229,7 +240,7 @@ TEST (ledger, process_receive) 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); - ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.amount (transaction, hash2)); + ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.any.block_amount (transaction, hash2)); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.weight (key3.pub)); auto send2 = builder .send () @@ -253,22 +264,22 @@ TEST (ledger, process_receive) ASSERT_EQ (key2.pub, receive->sideband ().account); ASSERT_EQ (nano::dev::constants.genesis_amount - 25, receive->sideband ().balance.number ()); ASSERT_EQ (2, receive->sideband ().height); - ASSERT_EQ (25, ledger.amount (transaction, hash4)); + ASSERT_EQ (25, ledger.any.block_amount (transaction, hash4)); ASSERT_EQ (nano::block_status::progress, return2); 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 (hash4, ledger.any.account_head (transaction, key2.pub)); + ASSERT_EQ (25, ledger.any.account_balance (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (0, ledger.account_receivable (transaction, key2.pub)); - ASSERT_EQ (nano::dev::constants.genesis_amount - 25, ledger.account_balance (transaction, key2.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount - 25, ledger.any.account_balance (transaction, key2.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount - 25, ledger.weight (key3.pub)); ASSERT_FALSE (ledger.rollback (transaction, hash4)); - ASSERT_FALSE (ledger.successor (transaction, hash2)); - ASSERT_EQ (25, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_FALSE (ledger.any.block_successor (transaction, hash2)); + ASSERT_EQ (25, ledger.any.account_balance (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (25, ledger.account_receivable (transaction, key2.pub)); - ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_balance (transaction, key2.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.any.account_balance (transaction, key2.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.weight (key3.pub)); - ASSERT_EQ (hash2, ledger.latest (transaction, key2.pub)); - auto pending1 = ledger.pending_info (transaction, nano::pending_key (key2.pub, hash3)); + ASSERT_EQ (hash2, ledger.any.account_head (transaction, key2.pub)); + auto pending1 = ledger.any.pending_get (transaction, nano::pending_key (key2.pub, hash3)); ASSERT_TRUE (pending1); ASSERT_EQ (nano::dev::genesis_key.pub, pending1->source); ASSERT_EQ (25, pending1->amount.number ()); @@ -282,7 +293,7 @@ TEST (ledger, rollback_receiver) auto & store = ctx.store (); auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::keypair key2; nano::block_builder builder; @@ -307,21 +318,21 @@ TEST (ledger, rollback_receiver) .build (); nano::block_hash hash2 (open->hash ()); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open)); - ASSERT_EQ (hash2, ledger.latest (transaction, key2.pub)); - ASSERT_EQ (50, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); - ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_balance (transaction, key2.pub)); + ASSERT_EQ (hash2, ledger.any.account_head (transaction, key2.pub)); + ASSERT_EQ (50, ledger.any.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.any.account_balance (transaction, key2.pub)); ASSERT_EQ (50, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (0, ledger.weight (key2.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.weight (key3.pub)); ASSERT_FALSE (ledger.rollback (transaction, hash1)); - ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis_key.pub)); - ASSERT_EQ (0, ledger.account_balance (transaction, key2.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.any.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_FALSE (ledger.any.account_balance (transaction, key2.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (0, ledger.weight (key2.pub)); ASSERT_EQ (0, ledger.weight (key3.pub)); - ASSERT_FALSE (ledger.account_info (transaction, key2.pub)); + ASSERT_FALSE (ledger.any.account_get (transaction, key2.pub)); ASSERT_EQ (store.account.count (transaction), ledger.account_count ()); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ key2.pub, hash1 })); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ key2.pub, hash1 })); } TEST (ledger, rollback_representation) @@ -389,11 +400,11 @@ TEST (ledger, rollback_representation) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); ASSERT_EQ (1, ledger.weight (key3.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount - 1, ledger.weight (key4.pub)); - auto info1 = ledger.account_info (transaction, key2.pub); + auto info1 = ledger.any.account_get (transaction, key2.pub); ASSERT_TRUE (info1); ASSERT_EQ (key4.pub, info1->representative); ASSERT_FALSE (ledger.rollback (transaction, receive1->hash ())); - auto info2 = ledger.account_info (transaction, key2.pub); + auto info2 = ledger.any.account_get (transaction, key2.pub); ASSERT_TRUE (info2); ASSERT_EQ (key4.pub, info2->representative); ASSERT_EQ (0, ledger.weight (key2.pub)); @@ -403,11 +414,11 @@ TEST (ledger, rollback_representation) ASSERT_EQ (0, ledger.weight (key4.pub)); ledger.rollback (transaction, send1->hash ()); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (key3.pub)); - auto info3 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info3 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info3); ASSERT_EQ (key3.pub, info3->representative); ASSERT_FALSE (ledger.rollback (transaction, change2->hash ())); - auto info4 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info4 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info4); ASSERT_EQ (key5.pub, info4->representative); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (key5.pub)); @@ -449,7 +460,7 @@ TEST (ledger, process_duplicate) auto & store = ctx.store (); auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::keypair key2; nano::block_builder builder; @@ -482,7 +493,7 @@ TEST (ledger, representative_genesis) auto & ledger = ctx.ledger (); auto & store = ctx.store (); auto transaction = ledger.tx_begin_write (); - auto latest = ledger.latest (transaction, nano::dev::genesis_key.pub); + auto latest = ledger.any.account_head (transaction, nano::dev::genesis_key.pub); ASSERT_FALSE (latest.is_zero ()); ASSERT_EQ (nano::dev::genesis->hash (), ledger.representative (transaction, latest)); } @@ -504,7 +515,7 @@ TEST (ledger, representative_change) auto & pool = ctx.pool (); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (0, ledger.weight (key2.pub)); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::block_builder builder; auto block = builder @@ -516,15 +527,15 @@ TEST (ledger, representative_change) .build (); auto return1 (ledger.process (transaction, block)); ASSERT_EQ (nano::block_status::progress, return1); - ASSERT_EQ (0, ledger.amount (transaction, block->hash ())); + ASSERT_EQ (0, ledger.any.block_amount (transaction, block->hash ())); 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); + auto info2 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info2); ASSERT_EQ (block->hash (), info2->head); ASSERT_FALSE (ledger.rollback (transaction, info2->head)); - auto info3 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info3 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info3); ASSERT_EQ (info1->head, info3->head); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); @@ -540,7 +551,7 @@ TEST (ledger, send_fork) nano::keypair key3; auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::block_builder builder; auto block = builder @@ -572,7 +583,7 @@ TEST (ledger, receive_fork) nano::keypair key3; auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::block_builder builder; auto block = builder @@ -629,7 +640,7 @@ TEST (ledger, open_fork) nano::keypair key3; auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::block_builder builder; auto block = builder @@ -1230,9 +1241,9 @@ TEST (ledger, successor) node1.work_generate_blocking (*send1); auto transaction = node1.ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, send1)); - ASSERT_EQ (*send1, *node1.ledger.block (transaction, node1.ledger.successor (transaction, nano::qualified_root (nano::root (0), nano::dev::genesis->hash ())).value ())); - ASSERT_EQ (*nano::dev::genesis, *node1.ledger.block (transaction, node1.ledger.successor (transaction, nano::dev::genesis->qualified_root ()).value ())); - ASSERT_FALSE (node1.ledger.successor (transaction, nano::qualified_root (0))); + ASSERT_EQ (*send1, *node1.ledger.any.block_get (transaction, node1.ledger.any.block_successor (transaction, nano::qualified_root (nano::root (0), nano::dev::genesis->hash ())).value ())); + ASSERT_EQ (*nano::dev::genesis, *node1.ledger.any.block_get (transaction, node1.ledger.any.block_successor (transaction, nano::dev::genesis->qualified_root ()).value ())); + ASSERT_FALSE (node1.ledger.any.block_successor (transaction, nano::qualified_root (0))); } TEST (ledger, fail_change_old) @@ -2085,7 +2096,7 @@ TEST (ledger, latest_empty) auto & store = ctx.store (); nano::keypair key; auto transaction = ledger.tx_begin_read (); - auto latest = ledger.latest (transaction, key.pub); + auto latest = ledger.any.account_head (transaction, key.pub); ASSERT_TRUE (latest.is_zero ()); } @@ -2098,7 +2109,7 @@ TEST (ledger, latest_root) auto & pool = ctx.pool (); nano::keypair key; ASSERT_EQ (key.pub, ledger.latest_root (transaction, key.pub).as_account ()); - auto hash1 = ledger.latest (transaction, nano::dev::genesis_key.pub); + auto hash1 = ledger.any.account_head (transaction, nano::dev::genesis_key.pub); nano::block_builder builder; auto send = builder .send () @@ -2161,7 +2172,7 @@ TEST (ledger, send_open_receive_rollback) auto & store = ctx.store (); auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::keypair key1; nano::block_builder builder; @@ -2252,7 +2263,7 @@ TEST (ledger, bootstrap_rep_weight) auto & pool = ctx.pool (); { auto transaction = ledger.tx_begin_write (); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::block_builder builder; auto send = builder @@ -2273,7 +2284,7 @@ TEST (ledger, bootstrap_rep_weight) } { auto transaction = ledger.tx_begin_write (); - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::block_builder builder; auto send = builder @@ -2365,7 +2376,7 @@ TEST (ledger, block_destination_source) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, block4)); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, block5)); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, block6)); - ASSERT_EQ (balance, ledger.balance (transaction, block6->hash ())); + ASSERT_EQ (balance, ledger.any.block_balance (transaction, block6->hash ())); ASSERT_EQ (dest.pub, block1->destination ()); ASSERT_FALSE (block1->source_field ()); ASSERT_EQ (nano::dev::genesis_key.pub, block2->destination ()); @@ -2399,7 +2410,7 @@ TEST (ledger, state_account) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_EQ (nano::dev::genesis_key.pub, ledger.account (transaction, send1->hash ())); + ASSERT_EQ (nano::dev::genesis_key.pub, ledger.any.block_account (transaction, send1->hash ())); } TEST (ledger, state_send_receive) @@ -2421,14 +2432,14 @@ TEST (ledger, state_send_receive) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); - auto send2 = ledger.block (transaction, send1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); + auto send2 = ledger.any.block_get (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); 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.any.block_balance (transaction, send1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, send1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); - ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_TRUE (ledger.any.pending_get (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->is_receive ()); @@ -2444,14 +2455,14 @@ TEST (ledger, state_send_receive) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_TRUE (ledger.block_exists (transaction, receive1->hash ())); - auto receive2 = ledger.block (transaction, receive1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, receive1->hash ())); + auto receive2 = ledger.any.block_get (transaction, receive1->hash ()); ASSERT_NE (nullptr, receive2); 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.any.block_balance (transaction, receive1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, receive1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); ASSERT_EQ (store.account.count (transaction), ledger.account_count ()); ASSERT_EQ (3, receive2->sideband ().height); ASSERT_FALSE (receive2->is_send ()); @@ -2476,12 +2487,12 @@ TEST (ledger, state_receive) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); - auto send2 = ledger.block (transaction, send1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); + auto send2 = ledger.any.block_get (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); 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.any.block_balance (transaction, send1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, send1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); auto receive1 = builder .state () @@ -2494,12 +2505,12 @@ TEST (ledger, state_receive) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_TRUE (ledger.block_exists (transaction, receive1->hash ())); - auto receive2 = ledger.block (transaction, receive1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, receive1->hash ())); + auto receive2 = ledger.any.block_get (transaction, receive1->hash ()); ASSERT_NE (nullptr, receive2); 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.any.block_balance (transaction, receive1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_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->is_send ()); @@ -2527,12 +2538,12 @@ TEST (ledger, state_rep_change) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, change1)); - ASSERT_TRUE (ledger.block_exists (transaction, change1->hash ())); - auto change2 = ledger.block (transaction, change1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, change1->hash ())); + auto change2 = ledger.any.block_get (transaction, change1->hash ()); ASSERT_NE (nullptr, change2); 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 (nano::dev::constants.genesis_amount, ledger.any.block_balance (transaction, change1->hash ())); + ASSERT_EQ (0, ledger.any.block_amount (transaction, change1->hash ())); 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); @@ -2561,14 +2572,14 @@ TEST (ledger, state_open) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); - auto send2 = ledger.block (transaction, send1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); + auto send2 = ledger.any.block_get (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); 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.any.block_balance (transaction, send1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, send1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); - ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ destination.pub, send1->hash () })); + ASSERT_TRUE (ledger.any.pending_get (transaction, nano::pending_key{ destination.pub, send1->hash () })); auto open1 = builder .state () .account (destination.pub) @@ -2580,13 +2591,13 @@ TEST (ledger, state_open) .work (*pool.generate (destination.pub)) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1)); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ destination.pub, send1->hash () })); - ASSERT_TRUE (ledger.block_exists (transaction, open1->hash ())); - auto open2 = ledger.block (transaction, open1->hash ()); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ destination.pub, send1->hash () })); + ASSERT_TRUE (ledger.any.block_exists (transaction, open1->hash ())); + auto open2 = ledger.any.block_get (transaction, open1->hash ()); ASSERT_NE (nullptr, open2); 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::Gxrb_ratio, ledger.any.block_balance (transaction, open1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, open1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); ASSERT_EQ (ledger.account_count (), store.account.count (transaction)); ASSERT_EQ (1, open2->sideband ().height); @@ -2704,12 +2715,12 @@ TEST (ledger, state_unreceivable_fail) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); - auto send2 = ledger.block (transaction, send1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); + auto send2 = ledger.any.block_get (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); 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.any.block_balance (transaction, send1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, send1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); auto receive1 = builder .state () @@ -2741,12 +2752,12 @@ TEST (ledger, state_receive_bad_amount_fail) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); - auto send2 = ledger.block (transaction, send1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); + auto send2 = ledger.any.block_get (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); 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.any.block_balance (transaction, send1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, send1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); auto receive1 = builder .state () @@ -2813,12 +2824,12 @@ TEST (ledger, state_receive_wrong_account_fail) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); - auto send2 = ledger.block (transaction, send1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); + auto send2 = ledger.any.block_get (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); 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.any.block_balance (transaction, send1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, send1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); nano::keypair key; auto receive1 = builder @@ -3007,12 +3018,12 @@ TEST (ledger, state_send_change) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); - auto send2 = ledger.block (transaction, send1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); + auto send2 = ledger.any.block_get (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); 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.any.block_balance (transaction, send1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, send1->hash ())); 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); @@ -3040,12 +3051,12 @@ TEST (ledger, state_receive_change) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); - auto send2 = ledger.block (transaction, send1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); + auto send2 = ledger.any.block_get (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); 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.any.block_balance (transaction, send1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, send1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub)); nano::keypair rep; auto receive1 = builder @@ -3059,12 +3070,12 @@ TEST (ledger, state_receive_change) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_TRUE (ledger.block_exists (transaction, receive1->hash ())); - auto receive2 = ledger.block (transaction, receive1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, receive1->hash ())); + auto receive2 = ledger.any.block_get (transaction, receive1->hash ()); ASSERT_NE (nullptr, receive2); 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.any.block_balance (transaction, receive1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, receive1->hash ())); 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); @@ -3102,8 +3113,8 @@ TEST (ledger, state_open_old) .work (*pool.generate (destination.pub)) .build (); 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::Gxrb_ratio, ledger.any.block_balance (transaction, open1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, open1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); } @@ -3155,8 +3166,8 @@ TEST (ledger, state_receive_old) .work (*pool.generate (open1->hash ())) .build (); 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 (2 * nano::Gxrb_ratio, ledger.any.block_balance (transaction, receive1->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_amount (transaction, receive1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); } @@ -3179,22 +3190,22 @@ TEST (ledger, state_rollback_send) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); - auto send2 = ledger.block (transaction, send1->hash ()); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); + auto send2 = ledger.any.block_get (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_key.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.any.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 ())); + auto info = ledger.any.pending_get (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info); 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_key.pub)); + ASSERT_FALSE (ledger.any.block_exists (transaction, send1->hash ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.any.account_balance (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub)); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); - ASSERT_FALSE (ledger.successor (transaction, nano::dev::genesis->hash ())); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_FALSE (ledger.any.block_successor (transaction, nano::dev::genesis->hash ())); ASSERT_EQ (store.account.count (transaction), ledger.account_count ()); } @@ -3228,14 +3239,14 @@ TEST (ledger, state_rollback_receive) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, receive1->hash () })); + ASSERT_FALSE (ledger.any.pending_get (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_key.pub, send1->hash ())); + auto info = ledger.any.pending_get (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info); 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_key.pub)); + ASSERT_FALSE (ledger.any.block_exists (transaction, receive1->hash ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.any.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.account_count ()); } @@ -3271,14 +3282,14 @@ TEST (ledger, state_rollback_received_send) .work (*pool.generate (key.pub)) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, receive1->hash () })); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, receive1->hash () })); ASSERT_FALSE (ledger.rollback (transaction, send1->hash ())); - ASSERT_FALSE (ledger.pending_info (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_key.pub)); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_FALSE (ledger.any.block_exists (transaction, send1->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, receive1->hash ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.any.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_FALSE (ledger.any.account_balance (transaction, key.pub)); ASSERT_EQ (0, ledger.weight (key.pub)); ASSERT_EQ (store.account.count (transaction), ledger.account_count ()); } @@ -3304,8 +3315,8 @@ TEST (ledger, state_rep_change_rollback) .build (); 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_key.pub)); + ASSERT_FALSE (ledger.any.block_exists (transaction, change1->hash ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.any.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)); } @@ -3342,10 +3353,10 @@ TEST (ledger, state_open_rollback) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1)); 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_FALSE (ledger.any.block_exists (transaction, open1->hash ())); + ASSERT_FALSE (ledger.any.account_balance (transaction, destination.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 (destination.pub, send1->hash ())); + auto info = ledger.any.pending_get (transaction, nano::pending_key (destination.pub, send1->hash ())); ASSERT_TRUE (info); ASSERT_EQ (nano::dev::genesis_key.pub, info->source); ASSERT_EQ (nano::Gxrb_ratio, info->amount.number ()); @@ -3373,8 +3384,8 @@ TEST (ledger, state_send_change_rollback) .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_key.pub)); + ASSERT_FALSE (ledger.any.block_exists (transaction, send1->hash ())); + ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.any.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.account_count ()); @@ -3412,8 +3423,8 @@ TEST (ledger, state_receive_change_rollback) .build (); 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_key.pub)); + ASSERT_FALSE (ledger.any.block_exists (transaction, receive1->hash ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.any.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.account_count ()); @@ -3455,15 +3466,15 @@ TEST (ledger, epoch_blocks_v1_general) .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_key.pub); + auto genesis_info = ledger.any.account_get (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_key.pub); + genesis_info = ledger.any.account_get (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_key.pub); + genesis_info = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (genesis_info); ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_1); ASSERT_FALSE (epoch1->is_send ()); @@ -3552,9 +3563,9 @@ TEST (ledger, epoch_blocks_v1_general) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive2)); ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().source_epoch); - 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 (0, ledger.any.block_balance (transaction, epoch4->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_balance (transaction, receive2->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_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->is_send ()); @@ -3621,15 +3632,15 @@ TEST (ledger, epoch_blocks_v2_general) .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_key.pub); + auto genesis_info = ledger.any.account_get (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_key.pub); + genesis_info = ledger.any.account_get (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_key.pub); + genesis_info = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (genesis_info); ASSERT_EQ (genesis_info->epoch (), nano::epoch::epoch_1); auto change1 = builder @@ -3720,9 +3731,9 @@ TEST (ledger, epoch_blocks_v2_general) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive2)); ASSERT_EQ (nano::epoch::epoch_2, receive2->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().source_epoch); - 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 (0, ledger.any.block_balance (transaction, epoch6->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_balance (transaction, receive2->hash ())); + ASSERT_EQ (nano::Gxrb_ratio, ledger.any.block_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)); } @@ -3803,14 +3814,14 @@ TEST (ledger, epoch_blocks_receive_upgrade) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive2)); ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().source_epoch); - auto destination_info = ledger.account_info (transaction, destination.pub); + auto destination_info = ledger.any.account_get (transaction, destination.pub); ASSERT_TRUE (destination_info); ASSERT_EQ (destination_info->epoch (), nano::epoch::epoch_1); ASSERT_FALSE (ledger.rollback (transaction, receive2->hash ())); - destination_info = ledger.account_info (transaction, destination.pub); + destination_info = ledger.any.account_get (transaction, destination.pub); ASSERT_TRUE (destination_info); ASSERT_EQ (destination_info->epoch (), nano::epoch::epoch_0); - auto pending_send2 = ledger.pending_info (transaction, nano::pending_key (destination.pub, send2->hash ())); + auto pending_send2 = ledger.any.pending_get (transaction, nano::pending_key (destination.pub, send2->hash ())); ASSERT_TRUE (pending_send2); ASSERT_EQ (nano::dev::genesis_key.pub, pending_send2->source); ASSERT_EQ (nano::Gxrb_ratio, pending_send2->amount.number ()); @@ -3818,7 +3829,7 @@ TEST (ledger, epoch_blocks_receive_upgrade) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive2)); ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_1, receive2->sideband ().source_epoch); - destination_info = ledger.account_info (transaction, destination.pub); + destination_info = ledger.any.account_get (transaction, destination.pub); ASSERT_TRUE (destination_info); ASSERT_EQ (destination_info->epoch (), nano::epoch::epoch_1); nano::keypair destination2; @@ -3887,7 +3898,7 @@ TEST (ledger, epoch_blocks_receive_upgrade) .work (*pool.generate (send4->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send5)); - destination_info = ledger.account_info (transaction, destination.pub); + destination_info = ledger.any.account_get (transaction, destination.pub); ASSERT_TRUE (destination_info); ASSERT_EQ (destination_info->epoch (), nano::epoch::epoch_1); auto receive3 = builder @@ -3903,7 +3914,7 @@ TEST (ledger, epoch_blocks_receive_upgrade) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive3)); ASSERT_EQ (nano::epoch::epoch_2, receive3->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_2, receive3->sideband ().source_epoch); - destination_info = ledger.account_info (transaction, destination.pub); + destination_info = ledger.any.account_get (transaction, destination.pub); ASSERT_TRUE (destination_info); ASSERT_EQ (destination_info->epoch (), nano::epoch::epoch_2); // Upgrade an unopened account straight to epoch 2 @@ -4061,8 +4072,8 @@ TEST (ledger, successor_epoch) ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, change)); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, send2)); ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, epoch_open)); - ASSERT_EQ (*change, *node1.ledger.block (transaction, node1.ledger.successor (transaction, change->qualified_root ()).value ())); - ASSERT_EQ (*epoch_open, *node1.ledger.block (transaction, node1.ledger.successor (transaction, epoch_open->qualified_root ()).value ())); + ASSERT_EQ (*change, *node1.ledger.any.block_get (transaction, node1.ledger.any.block_successor (transaction, change->qualified_root ()).value ())); + ASSERT_EQ (*epoch_open, *node1.ledger.any.block_get (transaction, node1.ledger.any.block_successor (transaction, epoch_open->qualified_root ()).value ())); ASSERT_EQ (nano::epoch::epoch_1, epoch_open->sideband ().details.epoch); ASSERT_EQ (nano::epoch::epoch_0, epoch_open->sideband ().source_epoch); // Not used for epoch state blocks } @@ -4088,7 +4099,7 @@ TEST (ledger, epoch_open_pending) node1.block_processor.add (epoch_open); // Waits for the block to get saved in the database ASSERT_TIMELY_EQ (10s, 1, node1.unchecked.count ()); - ASSERT_FALSE (node1.ledger.block_or_pruned_exists (epoch_open->hash ())); + ASSERT_FALSE (node1.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_field ().value ()).hash); ASSERT_EQ (blocks.size (), 1); @@ -4104,7 +4115,7 @@ TEST (ledger, epoch_open_pending) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); node1.block_processor.add (send1); - ASSERT_TIMELY (10s, node1.ledger.block_or_pruned_exists (epoch_open->hash ())); + ASSERT_TIMELY (10s, node1.block_or_pruned_exists (epoch_open->hash ())); } TEST (ledger, block_hash_account_conflict) @@ -4245,11 +4256,11 @@ TEST (ledger, unchecked_epoch) } node1.block_processor.add (send1); node1.block_processor.add (open1); - ASSERT_TIMELY (5s, node1.ledger.block_exists (node1.ledger.tx_begin_read (), epoch1->hash ())); + ASSERT_TIMELY (5s, node1.ledger.any.block_exists (node1.ledger.tx_begin_read (), epoch1->hash ())); { // Waits for the last blocks to pass through block_processor and unchecked.put queues ASSERT_TIMELY_EQ (10s, 0, node1.unchecked.count ()); - auto info = node1.ledger.account_info (node1.ledger.tx_begin_read (), destination.pub); + auto info = node1.ledger.any.account_get (node1.ledger.tx_begin_read (), destination.pub); ASSERT_TRUE (info); ASSERT_EQ (info->epoch (), nano::epoch::epoch_1); } @@ -4320,17 +4331,17 @@ TEST (ledger, unchecked_epoch_invalid) node1.block_processor.add (send1); node1.block_processor.add (open1); // Waits for the last blocks to pass through block_processor and unchecked.put queues - ASSERT_TIMELY (10s, node1.ledger.block_exists (node1.ledger.tx_begin_read (), epoch2->hash ())); + ASSERT_TIMELY (10s, node1.ledger.any.block_exists (node1.ledger.tx_begin_read (), epoch2->hash ())); { auto transaction = node1.ledger.tx_begin_read (); - ASSERT_FALSE (node1.ledger.block_exists (transaction, epoch1->hash ())); + ASSERT_FALSE (node1.ledger.any.block_exists (transaction, epoch1->hash ())); auto unchecked_count = node1.unchecked.count (); ASSERT_EQ (unchecked_count, 0); ASSERT_EQ (unchecked_count, node1.unchecked.count ()); - auto info = node1.ledger.account_info (transaction, destination.pub); + auto info = node1.ledger.any.account_get (transaction, destination.pub); ASSERT_TRUE (info); ASSERT_NE (info->epoch (), nano::epoch::epoch_1); - auto epoch2_store = node1.ledger.block (transaction, epoch2->hash ()); + auto epoch2_store = node1.ledger.any.block_get (transaction, epoch2->hash ()); ASSERT_NE (nullptr, epoch2_store); ASSERT_EQ (nano::epoch::epoch_0, epoch2_store->sideband ().details.epoch); ASSERT_TRUE (epoch2_store->is_send ()); @@ -4387,7 +4398,7 @@ TEST (ledger, unchecked_open) } node1.block_processor.add (send1); // Waits for the send1 block to pass through block_processor and unchecked.put queues - ASSERT_TIMELY (5s, node1.ledger.block_exists (node1.ledger.tx_begin_read (), open1->hash ())); + ASSERT_TIMELY (5s, node1.ledger.any.block_exists (node1.ledger.tx_begin_read (), open1->hash ())); ASSERT_EQ (0, node1.unchecked.count ()); } @@ -4458,7 +4469,7 @@ TEST (ledger, unchecked_receive) ASSERT_EQ (blocks.size (), 1); } node1.block_processor.add (send2); - ASSERT_TIMELY (10s, node1.ledger.block_exists (node1.ledger.tx_begin_read (), receive1->hash ())); + ASSERT_TIMELY (10s, node1.ledger.any.block_exists (node1.ledger.tx_begin_read (), receive1->hash ())); ASSERT_EQ (0, node1.unchecked.count ()); } @@ -4469,7 +4480,7 @@ TEST (ledger, confirmation_height_not_updated) auto & store = ctx.store (); auto transaction = ledger.tx_begin_write (); auto & pool = ctx.pool (); - auto account_info = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto account_info = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (account_info); nano::keypair key; nano::block_builder builder; @@ -4720,7 +4731,7 @@ TEST (ledger, dependents_confirmed_pruning) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send2)); ledger.confirm (transaction, send2->hash ()); - ASSERT_TRUE (ledger.block_confirmed (transaction, send1->hash ())); + ASSERT_TRUE (ledger.confirmed.block_exists_or_pruned (transaction, send1->hash ())); ASSERT_EQ (2, ledger.pruning_action (transaction, send2->hash (), 1)); auto receive1 = builder.state () .account (key1.pub) @@ -4741,7 +4752,7 @@ TEST (ledger, block_confirmed) auto & store = ctx.store (); auto transaction = ledger.tx_begin_write (); nano::block_builder builder; - ASSERT_TRUE (ledger.block_confirmed (transaction, nano::dev::genesis->hash ())); + ASSERT_TRUE (ledger.confirmed.block_exists_or_pruned (transaction, nano::dev::genesis->hash ())); auto & pool = ctx.pool (); nano::keypair key1; auto send1 = builder.state () @@ -4754,11 +4765,11 @@ TEST (ledger, block_confirmed) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); // Must be safe against non-existing blocks - ASSERT_FALSE (ledger.block_confirmed (transaction, send1->hash ())); + ASSERT_FALSE (ledger.confirmed.block_exists_or_pruned (transaction, send1->hash ())); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_FALSE (ledger.block_confirmed (transaction, send1->hash ())); + ASSERT_FALSE (ledger.confirmed.block_exists_or_pruned (transaction, send1->hash ())); ledger.confirm (transaction, send1->hash ()); - ASSERT_TRUE (ledger.block_confirmed (transaction, send1->hash ())); + ASSERT_TRUE (ledger.confirmed.block_exists_or_pruned (transaction, send1->hash ())); } TEST (ledger, cache) @@ -4790,7 +4801,7 @@ TEST (ledger, cache) }; nano::keypair key; - auto const latest = ledger.latest (ledger.tx_begin_read (), nano::dev::genesis_key.pub); + auto const latest = ledger.any.account_head (ledger.tx_begin_read (), nano::dev::genesis_key.pub); auto send = builder.state () .account (nano::dev::genesis_key.pub) .previous (latest) @@ -4832,7 +4843,7 @@ TEST (ledger, cache) { auto transaction = ledger.tx_begin_write (); ledger.confirm (transaction, send->hash ()); - ASSERT_TRUE (ledger.block_confirmed (transaction, send->hash ())); + ASSERT_TRUE (ledger.confirmed.block_exists_or_pruned (transaction, send->hash ())); } ++cemented_count; @@ -4842,7 +4853,7 @@ TEST (ledger, cache) { auto transaction = ledger.tx_begin_write (); ledger.confirm (transaction, open->hash ()); - ASSERT_TRUE (ledger.block_confirmed (transaction, open->hash ())); + ASSERT_TRUE (ledger.confirmed.block_exists_or_pruned (transaction, open->hash ())); } ++cemented_count; @@ -4882,11 +4893,11 @@ TEST (ledger, pruning_action) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store->block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); auto send1_stored (store->block.get (transaction, send1->hash ())); ASSERT_NE (nullptr, send1_stored); ASSERT_EQ (*send1, *send1_stored); - ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_TRUE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); auto send2 = builder .state () .account (nano::dev::genesis_key.pub) @@ -4898,21 +4909,21 @@ TEST (ledger, pruning_action) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send2)); - ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send2->hash ())); // Pruning action ledger.confirm (transaction, send1->hash ()); ASSERT_EQ (1, ledger.pruning_action (transaction, send1->hash (), 1)); ASSERT_EQ (0, ledger.pruning_action (transaction, nano::dev::genesis->hash (), 1)); - ASSERT_TRUE (ledger.pending_info (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 ())); + ASSERT_TRUE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_FALSE (ledger.any.block_exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.any.block_exists_or_pruned (transaction, send1->hash ())); // Pruned ledger start without proper flags emulation ledger.pruning = false; - ASSERT_TRUE (ledger.block_or_pruned_exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.any.block_exists_or_pruned (transaction, send1->hash ())); ledger.pruning = true; ASSERT_TRUE (store->pruned.exists (transaction, send1->hash ())); - ASSERT_TRUE (store->block.exists (transaction, nano::dev::genesis->hash ())); - ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, nano::dev::genesis->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send2->hash ())); // Receiving pruned block auto receive1 = builder .state () @@ -4925,21 +4936,21 @@ TEST (ledger, pruning_action) .work (*pool.generate (send2->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_TRUE (store->block.exists (transaction, receive1->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, receive1->hash ())); auto receive1_stored (store->block.get (transaction, receive1->hash ())); ASSERT_NE (nullptr, receive1_stored); ASSERT_EQ (*receive1, *receive1_stored); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_FALSE (ledger.any.pending_get (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->is_receive ()); ASSERT_FALSE (receive1_stored->sideband ().details.is_epoch); // Middle block pruning - ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send2->hash ())); ledger.confirm (transaction, send2->hash ()); ASSERT_EQ (1, ledger.pruning_action (transaction, send2->hash (), 1)); ASSERT_TRUE (store->pruned.exists (transaction, send2->hash ())); - ASSERT_FALSE (store->block.exists (transaction, send2->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, send2->hash ())); ASSERT_EQ (store->account.count (transaction), ledger.account_count ()); ASSERT_EQ (store->pruned.count (transaction), ledger.pruned_count ()); ASSERT_EQ (store->block.count (transaction), ledger.block_count () - ledger.pruned_count ()); @@ -4972,7 +4983,7 @@ TEST (ledger, pruning_large_chain) .work (*pool.generate (last_hash)) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send)); - ASSERT_TRUE (store->block.exists (transaction, send->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send->hash ())); auto receive = builder .state () .account (nano::dev::genesis_key.pub) @@ -4984,7 +4995,7 @@ TEST (ledger, pruning_large_chain) .work (*pool.generate (send->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive)); - ASSERT_TRUE (store->block.exists (transaction, receive->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, receive->hash ())); last_hash = receive->hash (); } ASSERT_EQ (0, store->pruned.count (transaction)); @@ -4993,8 +5004,8 @@ TEST (ledger, pruning_large_chain) // Pruning action ASSERT_EQ (send_receive_pairs * 2, ledger.pruning_action (transaction, last_hash, 5)); ASSERT_TRUE (store->pruned.exists (transaction, last_hash)); - ASSERT_TRUE (store->block.exists (transaction, nano::dev::genesis->hash ())); - ASSERT_FALSE (store->block.exists (transaction, last_hash)); + ASSERT_TRUE (ledger.any.block_exists (transaction, nano::dev::genesis->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, last_hash)); ASSERT_EQ (store->pruned.count (transaction), ledger.pruned_count ()); ASSERT_EQ (store->block.count (transaction), ledger.block_count () - ledger.pruned_count ()); ASSERT_EQ (send_receive_pairs * 2, store->pruned.count (transaction)); @@ -5035,7 +5046,7 @@ TEST (ledger, pruning_source_rollback) .work (*pool.generate (epoch1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_TRUE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); auto send2 = builder .state () .account (nano::dev::genesis_key.pub) @@ -5047,16 +5058,16 @@ TEST (ledger, pruning_source_rollback) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send2)); - ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send2->hash ())); ledger.confirm (transaction, send1->hash ()); // Pruning action ASSERT_EQ (2, ledger.pruning_action (transaction, send1->hash (), 1)); - ASSERT_FALSE (store->block.exists (transaction, send1->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, send1->hash ())); ASSERT_TRUE (store->pruned.exists (transaction, send1->hash ())); - ASSERT_FALSE (store->block.exists (transaction, epoch1->hash ())); + ASSERT_FALSE (ledger.any.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_key.pub, send1->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, nano::dev::genesis->hash ())); + auto info = ledger.any.pending_get (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info); ASSERT_EQ (nano::dev::genesis_key.pub, info->source); ASSERT_EQ (nano::Gxrb_ratio, info->amount.number ()); @@ -5073,19 +5084,19 @@ TEST (ledger, pruning_source_rollback) .work (*pool.generate (send2->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); ASSERT_EQ (2, ledger.pruned_count ()); ASSERT_EQ (5, ledger.block_count ()); // Rollback receive block ASSERT_FALSE (ledger.rollback (transaction, receive1->hash ())); - auto info2 = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); + auto info2 = ledger.any.pending_get (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info2); 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 (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); ASSERT_EQ (2, ledger.pruned_count ()); ASSERT_EQ (5, ledger.block_count ()); } @@ -5111,7 +5122,7 @@ TEST (ledger, pruning_source_rollback_legacy) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_TRUE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); nano::keypair key1; auto send2 = builder .send () @@ -5122,8 +5133,8 @@ TEST (ledger, pruning_source_rollback_legacy) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send2)); - ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); - ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ key1.pub, send2->hash () })); + ASSERT_TRUE (ledger.any.block_exists (transaction, send2->hash ())); + ASSERT_TRUE (ledger.any.pending_get (transaction, nano::pending_key{ key1.pub, send2->hash () })); auto send3 = builder .send () .previous (send2->hash ()) @@ -5133,22 +5144,22 @@ TEST (ledger, pruning_source_rollback_legacy) .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 (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send3->hash () })); + ASSERT_TRUE (ledger.any.block_exists (transaction, send3->hash ())); + ASSERT_TRUE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send3->hash () })); ledger.confirm (transaction, send2->hash ()); // Pruning action ASSERT_EQ (2, ledger.pruning_action (transaction, send2->hash (), 1)); - ASSERT_FALSE (store->block.exists (transaction, send2->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, send2->hash ())); ASSERT_TRUE (store->pruned.exists (transaction, send2->hash ())); - ASSERT_FALSE (store->block.exists (transaction, send1->hash ())); + ASSERT_FALSE (ledger.any.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_key.pub, send1->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, nano::dev::genesis->hash ())); + auto info1 = ledger.any.pending_get (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info1); 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 ())); + auto info2 = ledger.any.pending_get (transaction, nano::pending_key (key1.pub, send2->hash ())); ASSERT_TRUE (info2); ASSERT_EQ (nano::dev::genesis_key.pub, info2->source); ASSERT_EQ (nano::Gxrb_ratio, info2->amount.number ()); @@ -5162,19 +5173,19 @@ TEST (ledger, pruning_source_rollback_legacy) .work (*pool.generate (send3->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); ASSERT_EQ (2, ledger.pruned_count ()); ASSERT_EQ (5, ledger.block_count ()); // Rollback receive block ASSERT_FALSE (ledger.rollback (transaction, receive1->hash ())); - auto info3 = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); + auto info3 = ledger.any.pending_get (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())); ASSERT_TRUE (info3); 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 (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); ASSERT_EQ (2, ledger.pruned_count ()); ASSERT_EQ (5, ledger.block_count ()); // Receiving pruned block (open) @@ -5187,19 +5198,19 @@ TEST (ledger, pruning_source_rollback_legacy) .work (*pool.generate (key1.pub)) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1)); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ key1.pub, send2->hash () })); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ key1.pub, send2->hash () })); ASSERT_EQ (2, ledger.pruned_count ()); ASSERT_EQ (6, ledger.block_count ()); // Rollback open block ASSERT_FALSE (ledger.rollback (transaction, open1->hash ())); - auto info4 = ledger.pending_info (transaction, nano::pending_key (key1.pub, send2->hash ())); + auto info4 = ledger.any.pending_get (transaction, nano::pending_key (key1.pub, send2->hash ())); ASSERT_TRUE (info4); 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 ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1)); - ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ key1.pub, send2->hash () })); + ASSERT_FALSE (ledger.any.pending_get (transaction, nano::pending_key{ key1.pub, send2->hash () })); ASSERT_EQ (2, ledger.pruned_count ()); ASSERT_EQ (6, ledger.block_count ()); } @@ -5226,7 +5237,7 @@ TEST (ledger, pruning_legacy_blocks) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); + ASSERT_TRUE (ledger.any.pending_get (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () })); auto receive1 = builder .receive () .previous (send1->hash ()) @@ -5274,17 +5285,17 @@ TEST (ledger, pruning_legacy_blocks) // Pruning action ASSERT_EQ (3, ledger.pruning_action (transaction, change1->hash (), 2)); ASSERT_EQ (1, ledger.pruning_action (transaction, open1->hash (), 1)); - ASSERT_TRUE (store->block.exists (transaction, nano::dev::genesis->hash ())); - ASSERT_FALSE (store->block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, nano::dev::genesis->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, send1->hash ())); ASSERT_TRUE (store->pruned.exists (transaction, send1->hash ())); - ASSERT_FALSE (store->block.exists (transaction, receive1->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, receive1->hash ())); ASSERT_TRUE (store->pruned.exists (transaction, receive1->hash ())); - ASSERT_FALSE (store->block.exists (transaction, change1->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, change1->hash ())); ASSERT_TRUE (store->pruned.exists (transaction, change1->hash ())); - ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); - ASSERT_FALSE (store->block.exists (transaction, open1->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send2->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, open1->hash ())); ASSERT_TRUE (store->pruned.exists (transaction, open1->hash ())); - ASSERT_TRUE (store->block.exists (transaction, send3->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send3->hash ())); ASSERT_EQ (4, ledger.pruned_count ()); ASSERT_EQ (7, ledger.block_count ()); ASSERT_EQ (store->pruned.count (transaction), ledger.pruned_count ()); @@ -5314,7 +5325,7 @@ TEST (ledger, pruning_safe_functions) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store->block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); auto send2 = builder .state () .account (nano::dev::genesis_key.pub) @@ -5326,21 +5337,21 @@ TEST (ledger, pruning_safe_functions) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send2)); - ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send2->hash ())); ledger.confirm (transaction, send1->hash ()); // Pruning action ASSERT_EQ (1, ledger.pruning_action (transaction, send1->hash (), 1)); - ASSERT_FALSE (store->block.exists (transaction, send1->hash ())); - ASSERT_TRUE (ledger.block_or_pruned_exists (transaction, send1->hash ())); // true for pruned + ASSERT_FALSE (ledger.any.block_exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.any.block_exists_or_pruned (transaction, send1->hash ())); // true for pruned ASSERT_TRUE (store->pruned.exists (transaction, send1->hash ())); - ASSERT_TRUE (store->block.exists (transaction, nano::dev::genesis->hash ())); - ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, nano::dev::genesis->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send2->hash ())); // Safe ledger actions - ASSERT_FALSE (ledger.balance (transaction, send1->hash ())); - 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_key.pub, ledger.account (transaction, send2->hash ()).value ()); + ASSERT_FALSE (ledger.any.block_balance (transaction, send1->hash ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2, ledger.any.block_balance (transaction, send2->hash ()).value ().number ()); + ASSERT_FALSE (ledger.any.block_amount (transaction, send2->hash ())); + ASSERT_FALSE (ledger.any.block_account (transaction, send1->hash ())); + ASSERT_EQ (nano::dev::genesis_key.pub, ledger.any.block_account (transaction, send2->hash ()).value ()); } TEST (ledger, hash_root_random) @@ -5366,7 +5377,7 @@ TEST (ledger, hash_root_random) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store->block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send1->hash ())); auto send2 = builder .state () .account (nano::dev::genesis_key.pub) @@ -5378,14 +5389,14 @@ TEST (ledger, hash_root_random) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send2)); - ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send2->hash ())); ledger.confirm (transaction, send1->hash ()); // Pruning action ASSERT_EQ (1, ledger.pruning_action (transaction, send1->hash (), 1)); - ASSERT_FALSE (store->block.exists (transaction, send1->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, send1->hash ())); ASSERT_TRUE (store->pruned.exists (transaction, send1->hash ())); - ASSERT_TRUE (store->block.exists (transaction, nano::dev::genesis->hash ())); - ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, nano::dev::genesis->hash ())); + ASSERT_TRUE (ledger.any.block_exists (transaction, send2->hash ())); // Test random block including pruned bool done (false); auto iteration (0); @@ -5513,14 +5524,14 @@ TEST (ledger, head_block) auto & ledger = ctx.ledger (); auto & store = ctx.store (); auto tx = ledger.tx_begin_read (); - ASSERT_EQ (*nano::dev::genesis, *ledger.head_block (tx, nano::dev::genesis_key.pub)); + ASSERT_EQ (*nano::dev::genesis, *ledger.any.block_get (tx, ledger.any.account_head (tx, nano::dev::genesis_key.pub))); } // Test that nullopt can be returned when there are no receivable entries TEST (ledger_receivable, upper_bound_account_none) { auto ctx = nano::test::context::ledger_empty (); - ASSERT_EQ (ctx.ledger ().receivable_end (), ctx.ledger ().receivable_upper_bound (ctx.ledger ().tx_begin_read (), 0)); + ASSERT_EQ (ctx.ledger ().any.receivable_end (), ctx.ledger ().any.receivable_upper_bound (ctx.ledger ().tx_begin_read (), 0)); } // Test behavior of ledger::receivable_upper_bound when there are receivable entries for multiple accounts @@ -5553,22 +5564,22 @@ TEST (ledger_receivable, upper_bound_account_key) ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.ledger ().tx_begin_write (), send2)); auto tx = ctx.ledger ().tx_begin_read (); auto & ledger = ctx.ledger (); - auto next1 = ledger.receivable_upper_bound (tx, nano::dev::genesis_key.pub); - auto next2 = ledger.receivable_upper_bound (tx, key.pub); + auto next1 = ledger.any.receivable_upper_bound (tx, nano::dev::genesis_key.pub); + auto next2 = ledger.any.receivable_upper_bound (tx, key.pub); // Depending on which is greater but only one should have a value - ASSERT_TRUE (next1 == ledger.receivable_end () xor next2 == ledger.receivable_end ()); + ASSERT_TRUE (next1 == ledger.any.receivable_end () xor next2 == ledger.any.receivable_end ()); // The account returned should be after the one we searched for - ASSERT_TRUE (next1 == ledger.receivable_end () || next1->first.account == key.pub); - ASSERT_TRUE (next2 == ledger.receivable_end () || next2->first.account == nano::dev::genesis_key.pub); - auto next3 = ledger.receivable_upper_bound (tx, nano::dev::genesis_key.pub, 0); - auto next4 = ledger.receivable_upper_bound (tx, key.pub, 0); + ASSERT_TRUE (next1 == ledger.any.receivable_end () || next1->first.account == key.pub); + ASSERT_TRUE (next2 == ledger.any.receivable_end () || next2->first.account == nano::dev::genesis_key.pub); + auto next3 = ledger.any.receivable_upper_bound (tx, nano::dev::genesis_key.pub, 0); + auto next4 = ledger.any.receivable_upper_bound (tx, key.pub, 0); // Neither account has more than one receivable - ASSERT_TRUE (next3 != ledger.receivable_end () && next4 != ledger.receivable_end ()); - auto next5 = ledger.receivable_upper_bound (tx, next3->first.account, next3->first.hash); - auto next6 = ledger.receivable_upper_bound (tx, next4->first.account, next4->first.hash); - ASSERT_TRUE (next5 == ledger.receivable_end () && next6 == ledger.receivable_end ()); - ASSERT_EQ (ledger.receivable_end (), ++next3); - ASSERT_EQ (ledger.receivable_end (), ++next4); + ASSERT_TRUE (next3 != ledger.any.receivable_end () && next4 != ledger.any.receivable_end ()); + auto next5 = ledger.any.receivable_upper_bound (tx, next3->first.account, next3->first.hash); + auto next6 = ledger.any.receivable_upper_bound (tx, next4->first.account, next4->first.hash); + ASSERT_TRUE (next5 == ledger.any.receivable_end () && next6 == ledger.any.receivable_end ()); + ASSERT_EQ (ledger.any.receivable_end (), ++next3); + ASSERT_EQ (ledger.any.receivable_end (), ++next4); } // Test that multiple receivable entries for the same account @@ -5601,20 +5612,20 @@ TEST (ledger_receivable, key_two) ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.ledger ().tx_begin_write (), send2)); auto tx = ctx.ledger ().tx_begin_read (); auto & ledger = ctx.ledger (); - auto next1 = ledger.receivable_upper_bound (tx, key.pub, 0); - ASSERT_TRUE (next1 != ledger.receivable_end () && next1->first.account == key.pub); - auto next2 = ledger.receivable_upper_bound (tx, key.pub, next1->first.hash); - ASSERT_TRUE (next2 != ledger.receivable_end () && next2->first.account == key.pub); + auto next1 = ledger.any.receivable_upper_bound (tx, key.pub, 0); + ASSERT_TRUE (next1 != ledger.any.receivable_end () && next1->first.account == key.pub); + auto next2 = ledger.any.receivable_upper_bound (tx, key.pub, next1->first.hash); + ASSERT_TRUE (next2 != ledger.any.receivable_end () && next2->first.account == key.pub); ASSERT_NE (next1->first.hash, next2->first.hash); ASSERT_EQ (next2, ++next1); - ASSERT_EQ (ledger.receivable_end (), ++next1); - ASSERT_EQ (ledger.receivable_end (), ++next2); + ASSERT_EQ (ledger.any.receivable_end (), ++next1); + ASSERT_EQ (ledger.any.receivable_end (), ++next2); } TEST (ledger_receivable, any_none) { auto ctx = nano::test::context::ledger_empty (); - ASSERT_FALSE (ctx.ledger ().receivable_any (ctx.ledger ().tx_begin_read (), nano::dev::genesis_key.pub)); + ASSERT_FALSE (ctx.ledger ().any.receivable_exists (ctx.ledger ().tx_begin_read (), nano::dev::genesis_key.pub)); } TEST (ledger_receivable, any_one) @@ -5633,6 +5644,6 @@ TEST (ledger_receivable, any_one) .work (*ctx.pool ().generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ctx.ledger ().process (ctx.ledger ().tx_begin_write (), send1)); - ASSERT_TRUE (ctx.ledger ().receivable_any (ctx.ledger ().tx_begin_read (), nano::dev::genesis_key.pub)); - ASSERT_FALSE (ctx.ledger ().receivable_any (ctx.ledger ().tx_begin_read (), key.pub)); + ASSERT_TRUE (ctx.ledger ().any.receivable_exists (ctx.ledger ().tx_begin_read (), nano::dev::genesis_key.pub)); + ASSERT_FALSE (ctx.ledger ().any.receivable_exists (ctx.ledger ().tx_begin_read (), key.pub)); } diff --git a/nano/core_test/ledger_confirm.cpp b/nano/core_test/ledger_confirm.cpp index f94b6c8b85..a6b4a393ff 100644 --- a/nano/core_test/ledger_confirm.cpp +++ b/nano/core_test/ledger_confirm.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include @@ -38,11 +40,11 @@ TEST (ledger_confirm, single) ASSERT_EQ (nano::dev::genesis->hash (), node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().frontier); ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1)); - ASSERT_FALSE (node->ledger.block_confirmed (transaction, send1->hash ())); + ASSERT_FALSE (node->ledger.confirmed.block_exists (transaction, send1->hash ())); node->ledger.confirm (transaction, send1->hash ()); - ASSERT_TRUE (node->ledger.block_confirmed (transaction, send1->hash ())); - ASSERT_EQ (2, node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().height); - ASSERT_EQ (send1->hash (), node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().frontier); + ASSERT_TRUE (node->ledger.confirmed.block_exists (transaction, send1->hash ())); + ASSERT_EQ (2, node->ledger.confirmed.account_height (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (send1->hash (), node->ledger.confirmed.account_head (transaction, nano::dev::genesis_key.pub)); // Rollbacks should fail as these blocks have been cemented ASSERT_TRUE (node->ledger.rollback (transaction, latest1)); @@ -195,30 +197,30 @@ TEST (ledger_confirm, multiple_accounts) ASSERT_EQ (10, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); ASSERT_EQ (11, node->ledger.cemented_count ()); - ASSERT_TRUE (node->ledger.block_confirmed (transaction, receive3->hash ())); - ASSERT_EQ (4, node->ledger.account_info (transaction, nano::dev::genesis_key.pub).value ().block_count); - ASSERT_EQ (4, node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().height); - ASSERT_EQ (send3->hash (), node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().frontier); - ASSERT_EQ (3, node->ledger.account_info (transaction, key1.pub).value ().block_count); - ASSERT_EQ (2, node->store.confirmation_height.get (transaction, key1.pub).value ().height); - ASSERT_EQ (send4->hash (), node->store.confirmation_height.get (transaction, key1.pub).value ().frontier); - ASSERT_EQ (4, node->ledger.account_info (transaction, key2.pub).value ().block_count); - ASSERT_EQ (3, node->store.confirmation_height.get (transaction, key2.pub).value ().height); - ASSERT_EQ (send6->hash (), node->store.confirmation_height.get (transaction, key2.pub).value ().frontier); - ASSERT_EQ (2, node->ledger.account_info (transaction, key3.pub).value ().block_count); - ASSERT_EQ (2, node->store.confirmation_height.get (transaction, key3.pub).value ().height); - ASSERT_EQ (receive3->hash (), node->store.confirmation_height.get (transaction, key3.pub).value ().frontier); + ASSERT_TRUE (node->ledger.confirmed.block_exists (transaction, receive3->hash ())); + ASSERT_EQ (4, node->ledger.any.account_get (transaction, nano::dev::genesis_key.pub).value ().block_count); + ASSERT_EQ (4, node->ledger.confirmed.account_height (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (send3->hash (), node->ledger.confirmed.account_head (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (3, node->ledger.any.account_get (transaction, key1.pub).value ().block_count); + ASSERT_EQ (2, node->ledger.confirmed.account_height (transaction, key1.pub)); + ASSERT_EQ (send4->hash (), node->ledger.confirmed.account_head (transaction, key1.pub)); + ASSERT_EQ (4, node->ledger.any.account_get (transaction, key2.pub).value ().block_count); + ASSERT_EQ (3, node->ledger.confirmed.account_height (transaction, key2.pub)); + ASSERT_EQ (send6->hash (), node->ledger.confirmed.account_head (transaction, key2.pub)); + ASSERT_EQ (2, node->ledger.any.account_get (transaction, key3.pub).value ().block_count); + ASSERT_EQ (2, node->ledger.confirmed.account_height (transaction, key3.pub)); + ASSERT_EQ (receive3->hash (), node->ledger.confirmed.account_head (transaction, key3.pub)); // The accounts for key1 and key2 have 1 more block in the chain than is confirmed. // So this can be rolled back, but the one before that cannot. Check that this is the case - ASSERT_FALSE (node->ledger.rollback (transaction, node->ledger.latest (transaction, key2.pub))); - ASSERT_FALSE (node->ledger.rollback (transaction, node->ledger.latest (transaction, key1.pub))); - ASSERT_TRUE (node->ledger.rollback (transaction, node->ledger.latest (transaction, key1.pub))); - ASSERT_TRUE (node->ledger.rollback (transaction, node->ledger.latest (transaction, key2.pub))); + ASSERT_FALSE (node->ledger.rollback (transaction, node->ledger.any.account_head (transaction, key2.pub))); + ASSERT_FALSE (node->ledger.rollback (transaction, node->ledger.any.account_head (transaction, key1.pub))); + ASSERT_TRUE (node->ledger.rollback (transaction, node->ledger.any.account_head (transaction, key1.pub))); + ASSERT_TRUE (node->ledger.rollback (transaction, node->ledger.any.account_head (transaction, key2.pub))); // Confirm the other latest can't be rolled back either - ASSERT_TRUE (node->ledger.rollback (transaction, node->ledger.latest (transaction, key3.pub))); - ASSERT_TRUE (node->ledger.rollback (transaction, node->ledger.latest (transaction, nano::dev::genesis_key.pub))); + ASSERT_TRUE (node->ledger.rollback (transaction, node->ledger.any.account_head (transaction, key3.pub))); + ASSERT_TRUE (node->ledger.rollback (transaction, node->ledger.any.account_head (transaction, nano::dev::genesis_key.pub))); // Attempt some others which have been cemented ASSERT_TRUE (node->ledger.rollback (transaction, open1->hash ())); @@ -345,14 +347,13 @@ TEST (ledger_confirm, send_receive_between_2_accounts) ASSERT_EQ (10, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); ASSERT_EQ (11, node->ledger.cemented_count ()); - ASSERT_TRUE (node->ledger.block_confirmed (transaction, receive4->hash ())); - ASSERT_EQ (7, node->ledger.account_info (transaction, nano::dev::genesis_key.pub).value ().block_count); - ASSERT_EQ (6, node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().height); - ASSERT_EQ (send5->hash (), node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().frontier); - - ASSERT_EQ (5, node->ledger.account_info (transaction, key1.pub).value ().block_count); - ASSERT_EQ (5, node->store.confirmation_height.get (transaction, key1.pub).value ().height); - ASSERT_EQ (receive4->hash (), node->store.confirmation_height.get (transaction, key1.pub).value ().frontier); + ASSERT_TRUE (node->ledger.confirmed.block_exists (transaction, receive4->hash ())); + ASSERT_EQ (7, node->ledger.any.account_get (transaction, nano::dev::genesis_key.pub).value ().block_count); + ASSERT_EQ (6, node->ledger.confirmed.account_height (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (send5->hash (), node->ledger.confirmed.account_head (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (5, node->ledger.any.account_get (transaction, key1.pub).value ().block_count); + ASSERT_EQ (5, node->ledger.confirmed.account_height (transaction, key1.pub)); + ASSERT_EQ (receive4->hash (), node->ledger.confirmed.account_head (transaction, key1.pub)); } TEST (ledger_confirm, send_receive_self) @@ -436,10 +437,10 @@ TEST (ledger_confirm, send_receive_self) ASSERT_EQ (6, confirmed.size ()); ASSERT_EQ (6, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); - ASSERT_TRUE (node->ledger.block_confirmed (transaction, receive3->hash ())); - ASSERT_EQ (8, node->ledger.account_info (transaction, nano::dev::genesis_key.pub).value ().block_count); - ASSERT_EQ (7, node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().height); - ASSERT_EQ (receive3->hash (), node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().frontier); + ASSERT_TRUE (node->ledger.confirmed.block_exists (transaction, receive3->hash ())); + ASSERT_EQ (8, node->ledger.any.account_get (transaction, nano::dev::genesis_key.pub).value ().block_count); + ASSERT_EQ (7, node->ledger.confirmed.account_height (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (receive3->hash (), node->ledger.confirmed.account_head (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (7, node->ledger.cemented_count ()); } @@ -662,19 +663,18 @@ TEST (ledger_confirm, all_block_types) ASSERT_EQ (15, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); ASSERT_EQ (16, node->ledger.cemented_count ()); - ASSERT_TRUE (node->ledger.block_confirmed (transaction, state_send2->hash ())); + ASSERT_TRUE (node->ledger.confirmed.block_exists (transaction, state_send2->hash ())); nano::confirmation_height_info confirmation_height_info; - ASSERT_LE (4, node->ledger.account_info (transaction, nano::dev::genesis_key.pub).value ().block_count); - ASSERT_EQ (3, node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().height); - ASSERT_EQ (send1->hash (), node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub).value ().frontier); - - ASSERT_LE (7, node->ledger.account_info (transaction, key1.pub).value ().block_count); - ASSERT_EQ (6, node->store.confirmation_height.get (transaction, key1.pub).value ().height); - ASSERT_EQ (state_send1->hash (), node->store.confirmation_height.get (transaction, key1.pub).value ().frontier); - - ASSERT_EQ (8, node->ledger.account_info (transaction, key2.pub).value ().block_count); - ASSERT_EQ (7, node->store.confirmation_height.get (transaction, key2.pub).value ().height); - ASSERT_EQ (state_send2->hash (), node->store.confirmation_height.get (transaction, key2.pub).value ().frontier); + ASSERT_LE (4, node->ledger.any.account_get (transaction, nano::dev::genesis_key.pub).value ().block_count); + ASSERT_EQ (3, node->ledger.confirmed.account_height (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (send1->hash (), node->ledger.confirmed.account_head (transaction, nano::dev::genesis_key.pub)); + + ASSERT_LE (7, node->ledger.any.account_get (transaction, key1.pub).value ().block_count); + ASSERT_EQ (6, node->ledger.confirmed.account_height (transaction, key1.pub)); + ASSERT_EQ (state_send1->hash (), node->ledger.confirmed.account_head (transaction, key1.pub)); + ASSERT_EQ (8, node->ledger.any.account_get (transaction, key2.pub).value ().block_count); + ASSERT_EQ (7, node->ledger.confirmed.account_height (transaction, key2.pub)); + ASSERT_EQ (state_send2->hash (), node->ledger.confirmed.account_head (transaction, key2.pub)); } // This test ensures a block that's cemented cannot be rolled back by the node @@ -747,7 +747,7 @@ TEST (ledger_confirm, observers) auto transaction = node1->ledger.tx_begin_write (); ASSERT_EQ (nano::block_status::progress, node1->ledger.process (transaction, send1)); node1->ledger.confirm (transaction, send1->hash ()); - ASSERT_TRUE (node1->ledger.block_confirmed (transaction, send1->hash ())); + ASSERT_TRUE (node1->ledger.confirmed.block_exists (transaction, send1->hash ())); ASSERT_EQ (1, node1->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); ASSERT_EQ (2, node1->ledger.cemented_count ()); } @@ -847,10 +847,10 @@ TEST (ledger_confirm, pruned_source) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open2)); ledger.confirm (transaction, send2->hash ()); ASSERT_EQ (2, ledger.pruning_action (transaction, send2->hash (), 2)); - ASSERT_FALSE (ledger.block_exists (transaction, send2->hash ())); - ASSERT_FALSE (ledger.block_confirmed (transaction, open2->hash ())); + ASSERT_FALSE (ledger.any.block_exists (transaction, send2->hash ())); + ASSERT_FALSE (ledger.confirmed.block_exists (transaction, open2->hash ())); auto confirmed = ledger.confirm (transaction, open2->hash ()); - ASSERT_TRUE (ledger.block_confirmed (transaction, open2->hash ())); + ASSERT_TRUE (ledger.confirmed.block_exists (transaction, open2->hash ())); } // Test that if a block is marked to be confirmed that doesn't exist in the ledger the program aborts diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index 15bc020785..01190f95df 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -193,12 +194,12 @@ TEST (network, send_discarded_publish) { auto transaction = node1.ledger.tx_begin_read (); node1.network.flood_block (block); - ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.latest (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.any.account_head (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::genesis->hash (), node2.latest (nano::dev::genesis_key.pub)); } ASSERT_TIMELY (10s, node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) != 0); auto transaction = node1.ledger.tx_begin_read (); - ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.latest (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.any.account_head (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::genesis->hash (), node2.latest (nano::dev::genesis_key.pub)); } @@ -219,12 +220,12 @@ TEST (network, send_invalid_publish) { auto transaction = node1.ledger.tx_begin_read (); node1.network.flood_block (block); - ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.latest (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.any.account_head (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::genesis->hash (), node2.latest (nano::dev::genesis_key.pub)); } ASSERT_TIMELY (10s, node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::in) != 0); auto transaction = node1.ledger.tx_begin_read (); - ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.latest (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::genesis->hash (), node1.ledger.any.account_head (transaction, nano::dev::genesis_key.pub)); ASSERT_EQ (nano::dev::genesis->hash (), node2.latest (nano::dev::genesis_key.pub)); } diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 3124e8e40e..b4d4b61367 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -116,7 +118,7 @@ TEST (node, balance) nano::test::system system (1); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); auto transaction = system.nodes[0]->ledger.tx_begin_write (); - ASSERT_EQ (std::numeric_limits::max (), system.nodes[0]->ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (std::numeric_limits::max (), system.nodes[0]->ledger.any.account_balance (transaction, nano::dev::genesis_key.pub)); } TEST (node, send_unkeyed) @@ -233,7 +235,7 @@ TEST (node, node_receive_quorum) .work (*system.work.generate (previous)) .build (); node1.process_active (send); - ASSERT_TIMELY (10s, node1.ledger.block_or_pruned_exists (send->hash ())); + ASSERT_TIMELY (10s, node1.block_or_pruned_exists (send->hash ())); ASSERT_TIMELY (10s, node1.active.election (nano::qualified_root (previous, previous)) != nullptr); auto election (node1.active.election (nano::qualified_root (previous, previous))); ASSERT_NE (nullptr, election); @@ -276,7 +278,7 @@ TEST (node, auto_bootstrap) ASSERT_TIMELY (10s, node1->bootstrap_initiator.in_progress ()); ASSERT_TIMELY_EQ (10s, node1->balance (key2.pub), node0->config.receive_minimum.number ()); ASSERT_TIMELY (10s, !node1->bootstrap_initiator.in_progress ()); - ASSERT_TRUE (node1->ledger.block_or_pruned_exists (send1->hash ())); + ASSERT_TRUE (node1->block_or_pruned_exists (send1->hash ())); // Wait block receive ASSERT_TIMELY_EQ (5s, node1->ledger.block_count (), 3); // Confirmation for all blocks @@ -427,7 +429,7 @@ TEST (node, search_receivable_pruned) // Confirmation ASSERT_TIMELY (10s, node1->active.empty () && node2->active.empty ()); - ASSERT_TIMELY (5s, node1->ledger.block_confirmed (node1->ledger.tx_begin_read (), send2->hash ())); + ASSERT_TIMELY (5s, node1->ledger.confirmed.block_exists_or_pruned (node1->ledger.tx_begin_read (), send2->hash ())); ASSERT_TIMELY_EQ (5s, node2->ledger.cemented_count (), 3); system.wallet (0)->store.erase (node1->wallets.tx_begin_write (), nano::dev::genesis_key.pub); @@ -437,7 +439,7 @@ TEST (node, search_receivable_pruned) ASSERT_EQ (1, node2->ledger.pruning_action (transaction, send1->hash (), 1)); } ASSERT_EQ (1, node2->ledger.pruned_count ()); - ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send1->hash ())); // true for pruned + ASSERT_TRUE (node2->block_or_pruned_exists (send1->hash ())); // true for pruned // Receive pruned block system.wallet (1)->insert_adhoc (key2.prv); @@ -659,8 +661,8 @@ TEST (node, fork_keep) auto election1 (node2.active.election (nano::qualified_root (nano::dev::genesis->hash (), nano::dev::genesis->hash ()))); ASSERT_NE (nullptr, election1); ASSERT_EQ (1, election1->votes ().size ()); - ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send1->hash ())); - ASSERT_TRUE (node2.ledger.block_or_pruned_exists (send1->hash ())); + ASSERT_TRUE (node1.block_or_pruned_exists (send1->hash ())); + ASSERT_TRUE (node2.block_or_pruned_exists (send1->hash ())); // Wait until the genesis rep makes a vote ASSERT_TIMELY (1.5min, election1->votes ().size () != 1); auto transaction0 (node1.ledger.tx_begin_read ()); @@ -669,8 +671,8 @@ TEST (node, fork_keep) auto winner (*election1->tally ().begin ()); ASSERT_EQ (*send1, *winner.second); ASSERT_EQ (nano::dev::constants.genesis_amount - 100, winner.first); - ASSERT_TRUE (node1.ledger.block_exists (transaction0, send1->hash ())); - ASSERT_TRUE (node2.ledger.block_exists (transaction1, send1->hash ())); + ASSERT_TRUE (node1.ledger.any.block_exists (transaction0, send1->hash ())); + ASSERT_TRUE (node2.ledger.any.block_exists (transaction1, send1->hash ())); } // This test is racy, there is no guarantee that the election won't be confirmed until all forks are fully processed @@ -715,13 +717,13 @@ TEST (node, fork_flip) ASSERT_EQ (1, election1->votes ().size ()); ASSERT_NE (nullptr, node1.block (publish1.block->hash ())); ASSERT_NE (nullptr, node2.block (publish2.block->hash ())); - ASSERT_TIMELY (10s, node2.ledger.block_or_pruned_exists (publish1.block->hash ())); + ASSERT_TIMELY (10s, node2.block_or_pruned_exists (publish1.block->hash ())); auto winner (*election1->tally ().begin ()); ASSERT_EQ (*publish1.block, *winner.second); ASSERT_EQ (nano::dev::constants.genesis_amount - 100, winner.first); - ASSERT_TRUE (node1.ledger.block_or_pruned_exists (publish1.block->hash ())); - ASSERT_TRUE (node2.ledger.block_or_pruned_exists (publish1.block->hash ())); - ASSERT_FALSE (node2.ledger.block_or_pruned_exists (publish2.block->hash ())); + ASSERT_TRUE (node1.block_or_pruned_exists (publish1.block->hash ())); + ASSERT_TRUE (node2.block_or_pruned_exists (publish1.block->hash ())); + ASSERT_FALSE (node2.block_or_pruned_exists (publish2.block->hash ())); } // Test that more than one block can be rolled back @@ -768,7 +770,7 @@ TEST (node, fork_multi_flip) auto election = nano::test::start_election (system, node2, send2->hash ()); ASSERT_NE (nullptr, election); - ASSERT_TIMELY (5s, node2.ledger.block_or_pruned_exists (send1->hash ())); + ASSERT_TIMELY (5s, node2.block_or_pruned_exists (send1->hash ())); ASSERT_TRUE (nano::test::block_or_pruned_none_exists (node2, { send2, send3 })); auto winner = *election->tally ().begin (); ASSERT_EQ (*send1, *winner.second); @@ -812,7 +814,7 @@ TEST (node, fork_bootstrap_flip) // Insert but don't rebroadcast, simulating settled blocks ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.ledger.tx_begin_write (), send1)); ASSERT_EQ (nano::block_status::progress, node2.ledger.process (node2.ledger.tx_begin_write (), send2)); - ASSERT_TRUE (node2.ledger.block_exists (node2.ledger.tx_begin_read (), send2->hash ())); + ASSERT_TRUE (node2.ledger.any.block_exists (node2.ledger.tx_begin_read (), send2->hash ())); node2.bootstrap_initiator.bootstrap (node1.network.endpoint ()); // Additionally add new peer to confirm & replace bootstrap block auto again (true); system0.deadline_set (50s); @@ -821,7 +823,7 @@ TEST (node, fork_bootstrap_flip) { ASSERT_NO_ERROR (system0.poll ()); ASSERT_NO_ERROR (system1.poll ()); - again = !node2.ledger.block_exists (node2.ledger.tx_begin_read (), send1->hash ()); + again = !node2.ledger.any.block_exists (node2.ledger.tx_begin_read (), send1->hash ()); } } @@ -973,9 +975,9 @@ TEST (node, fork_open_flip) // check the correct blocks are in the ledgers auto transaction1 = node1.ledger.tx_begin_read (); auto transaction2 = node2.ledger.tx_begin_read (); - ASSERT_TRUE (node1.ledger.block_exists (transaction1, open1->hash ())); - ASSERT_TRUE (node2.ledger.block_exists (transaction2, open1->hash ())); - ASSERT_FALSE (node2.ledger.block_exists (transaction2, open2->hash ())); + ASSERT_TRUE (node1.ledger.any.block_exists (transaction1, open1->hash ())); + ASSERT_TRUE (node2.ledger.any.block_exists (transaction2, open1->hash ())); + ASSERT_FALSE (node2.ledger.any.block_exists (transaction2, open2->hash ())); } TEST (node, coherent_observer) @@ -983,8 +985,7 @@ TEST (node, coherent_observer) nano::test::system system (1); auto & node1 (*system.nodes[0]); node1.observers.blocks.add ([&node1] (nano::election_status const & status_a, std::vector const &, nano::account const &, nano::uint128_t const &, bool, bool) { - auto transaction = node1.ledger.tx_begin_read (); - ASSERT_TRUE (node1.ledger.block_exists (transaction, status_a.winner->hash ())); + ASSERT_TRUE (node1.ledger.any.block_exists (node1.ledger.tx_begin_read (), status_a.winner->hash ())); }); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); nano::keypair key; @@ -1305,13 +1306,13 @@ TEST (node, DISABLED_broadcast_elected) .build (); system.wallet (2)->insert_adhoc (rep_small.prv); node2->process_active (fork1); - ASSERT_TIMELY (10s, node0->ledger.block_or_pruned_exists (fork0->hash ()) && node1->ledger.block_or_pruned_exists (fork0->hash ())); + ASSERT_TIMELY (10s, node0->block_or_pruned_exists (fork0->hash ()) && node1->block_or_pruned_exists (fork0->hash ())); system.deadline_set (50s); - while (!node2->ledger.block_or_pruned_exists (fork0->hash ())) + while (!node2->block_or_pruned_exists (fork0->hash ())) { auto ec = system.poll (); - ASSERT_TRUE (node0->ledger.block_or_pruned_exists (fork0->hash ())); - ASSERT_TRUE (node1->ledger.block_or_pruned_exists (fork0->hash ())); + ASSERT_TRUE (node0->block_or_pruned_exists (fork0->hash ())); + ASSERT_TRUE (node1->block_or_pruned_exists (fork0->hash ())); ASSERT_NO_ERROR (ec); } ASSERT_TIMELY (5s, node1->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out) != 0); @@ -1503,11 +1504,11 @@ TEST (node, bootstrap_fork_open) ASSERT_EQ (nano::block_status::progress, node0->process (open0)); ASSERT_EQ (nano::block_status::progress, node1->process (open1)); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); - ASSERT_FALSE (node1->ledger.block_or_pruned_exists (open0->hash ())); + ASSERT_FALSE (node1->block_or_pruned_exists (open0->hash ())); ASSERT_FALSE (node1->bootstrap_initiator.in_progress ()); node1->bootstrap_initiator.bootstrap (node0->network.endpoint (), false); ASSERT_TIMELY (1s, node1->active.empty ()); - ASSERT_TIMELY (10s, !node1->ledger.block_or_pruned_exists (open1->hash ()) && node1->ledger.block_or_pruned_exists (open0->hash ())); + ASSERT_TIMELY (10s, !node1->block_or_pruned_exists (open1->hash ()) && node1->block_or_pruned_exists (open0->hash ())); } // Unconfirmed blocks from bootstrap should be confirmed @@ -1544,7 +1545,7 @@ TEST (node, bootstrap_confirm_frontiers) // on 2 different systems at once and in sequence and there might be strange timing effects. system0.deadline_set (10s); system1.deadline_set (10s); - while (!node1->ledger.block_confirmed (node1->ledger.tx_begin_read (), send0->hash ())) + while (!node1->ledger.confirmed.block_exists_or_pruned (node1->ledger.tx_begin_read (), send0->hash ())) { ASSERT_NO_ERROR (system0.poll (std::chrono::milliseconds (1))); ASSERT_NO_ERROR (system1.poll (std::chrono::milliseconds (1))); @@ -1572,7 +1573,7 @@ TEST (node, unconfirmed_send) ASSERT_TIMELY (5s, node2.block_confirmed (send1->hash ())); // wait until receive1 (auto-receive created by wallet) is cemented - ASSERT_TIMELY_EQ (5s, node2.get_confirmation_height (node2.ledger.tx_begin_read (), key2.pub), 1); + ASSERT_TIMELY_EQ (5s, node2.ledger.confirmed.account_height (node2.ledger.tx_begin_read (), key2.pub), 1); ASSERT_EQ (node2.balance (key2.pub), 2 * nano::Mxrb_ratio); auto recv1 = node2.ledger.find_receive_block_by_send_hash (node2.ledger.tx_begin_read (), key2.pub, send1->hash ()); @@ -1835,9 +1836,9 @@ TEST (node, block_confirm) auto hash2 = send1_copy->hash (); node1.block_processor.add (send1); node2.block_processor.add (send1_copy); - ASSERT_TIMELY (5s, node1.ledger.block_or_pruned_exists (send1->hash ()) && node2.ledger.block_or_pruned_exists (send1_copy->hash ())); - ASSERT_TRUE (node1.ledger.block_or_pruned_exists (send1->hash ())); - ASSERT_TRUE (node2.ledger.block_or_pruned_exists (send1_copy->hash ())); + ASSERT_TIMELY (5s, node1.block_or_pruned_exists (send1->hash ()) && node2.block_or_pruned_exists (send1_copy->hash ())); + ASSERT_TRUE (node1.block_or_pruned_exists (send1->hash ())); + ASSERT_TRUE (node2.block_or_pruned_exists (send1_copy->hash ())); // Confirm send1 on node2 so it can vote for send2 node2.start_election (send1_copy); std::shared_ptr election; @@ -1979,7 +1980,7 @@ TEST (node, DISABLED_local_votes_cache_batch) .build (); ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); node.confirming_set.add (send1->hash ()); - ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.ledger.tx_begin_read (), send1->hash ())); + ASSERT_TIMELY (5s, node.ledger.confirmed.block_exists_or_pruned (node.ledger.tx_begin_read (), send1->hash ())); auto send2 = nano::state_block_builder () .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) @@ -2122,7 +2123,7 @@ TEST (node, local_votes_cache_fork) node_config.peering_port = system.get_available_port (); auto & node2 (*system.add_node (node_config, node_flags)); node2.process_active (send1_fork); - ASSERT_TIMELY (5s, node2.ledger.block_or_pruned_exists (send1->hash ())); + ASSERT_TIMELY (5s, node2.block_or_pruned_exists (send1->hash ())); } TEST (node, vote_republish) @@ -2643,10 +2644,10 @@ TEST (node, block_processor_reject_state) .work (*node.work_generate_blocking (nano::dev::genesis->hash ())) .build (); send1->signature.bytes[0] ^= 1; - ASSERT_FALSE (node.ledger.block_or_pruned_exists (send1->hash ())); + ASSERT_FALSE (node.block_or_pruned_exists (send1->hash ())); node.process_active (send1); ASSERT_TIMELY_EQ (5s, 1, node.stats.count (nano::stat::type::blockprocessor_result, nano::stat::detail::bad_signature)); - ASSERT_FALSE (node.ledger.block_or_pruned_exists (send1->hash ())); + ASSERT_FALSE (node.block_or_pruned_exists (send1->hash ())); auto send2 = builder.make_block () .account (nano::dev::genesis_key.pub) .previous (nano::dev::genesis->hash ()) @@ -2657,7 +2658,7 @@ TEST (node, block_processor_reject_state) .work (*node.work_generate_blocking (nano::dev::genesis->hash ())) .build (); node.process_active (send2); - ASSERT_TIMELY (5s, node.ledger.block_or_pruned_exists (send2->hash ())); + ASSERT_TIMELY (5s, node.block_or_pruned_exists (send2->hash ())); } TEST (node, block_processor_full) @@ -2969,7 +2970,7 @@ TEST (node, bidirectional_tcp) .work (*node1->work_generate_blocking (nano::dev::genesis->hash ())) .build (); node1->process_active (send1); - ASSERT_TIMELY (10s, node1->ledger.block_or_pruned_exists (send1->hash ()) && node2->ledger.block_or_pruned_exists (send1->hash ())); + ASSERT_TIMELY (10s, node1->block_or_pruned_exists (send1->hash ()) && node2->block_or_pruned_exists (send1->hash ())); // Test block confirmation from node 1 (add representative to node 1) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); // Wait to find new reresentative @@ -2982,7 +2983,7 @@ TEST (node, bidirectional_tcp) while (!confirmed) { auto transaction2 = node2->ledger.tx_begin_read (); - confirmed = node2->ledger.block_confirmed (transaction2, send1->hash ()); + confirmed = node2->ledger.confirmed.block_exists_or_pruned (transaction2, send1->hash ()); ASSERT_NO_ERROR (system.poll ()); } // Test block propagation & confirmation from node 2 (remove representative from node 1) @@ -3002,7 +3003,7 @@ TEST (node, bidirectional_tcp) .work (*node1->work_generate_blocking (send1->hash ())) .build (); node2->process_active (send2); - ASSERT_TIMELY (10s, node1->ledger.block_or_pruned_exists (send2->hash ()) && node2->ledger.block_or_pruned_exists (send2->hash ())); + ASSERT_TIMELY (10s, node1->block_or_pruned_exists (send2->hash ()) && node2->block_or_pruned_exists (send2->hash ())); // Test block confirmation from node 2 (add representative to node 2) system.wallet (1)->insert_adhoc (nano::dev::genesis_key.prv); // Wait to find changed reresentative @@ -3015,7 +3016,7 @@ TEST (node, bidirectional_tcp) while (!confirmed) { auto transaction1 = node1->ledger.tx_begin_read (); - confirmed = node1->ledger.block_confirmed (transaction1, send2->hash ()); + confirmed = node1->ledger.confirmed.block_exists_or_pruned (transaction1, send2->hash ()); ASSERT_NO_ERROR (system.poll ()); } } diff --git a/nano/core_test/processor_service.cpp b/nano/core_test/processor_service.cpp index 5da559f368..0bec8cf8db 100644 --- a/nano/core_test/processor_service.cpp +++ b/nano/core_test/processor_service.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,7 @@ TEST (processor_service, bad_send_signature) auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::keypair key2; nano::block_builder builder; @@ -46,7 +47,7 @@ TEST (processor_service, bad_receive_signature) auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, ledger.constants); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; - auto info1 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); nano::block_builder builder; auto send = builder @@ -59,7 +60,7 @@ TEST (processor_service, bad_receive_signature) .build (); nano::block_hash hash1 (send->hash ()); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send)); - auto info2 = ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info2 = ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info2); auto receive = builder .receive () diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index adcbaf1f5d..942e26b4b6 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -81,7 +82,7 @@ TEST (request_aggregator, one_update) .build (); ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); node.confirming_set.add (send1->hash ()); - ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.ledger.tx_begin_read (), send1->hash ())); + ASSERT_TIMELY (5s, node.ledger.confirmed.block_exists_or_pruned (node.ledger.tx_begin_read (), send1->hash ())); auto send2 = nano::state_block_builder () .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) @@ -147,7 +148,7 @@ TEST (request_aggregator, two) .build (); ASSERT_EQ (nano::block_status::progress, node.ledger.process (node.ledger.tx_begin_write (), send1)); node.confirming_set.add (send1->hash ()); - ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.ledger.tx_begin_read (), send1->hash ())); + ASSERT_TIMELY (5s, node.ledger.confirmed.block_exists_or_pruned (node.ledger.tx_begin_read (), send1->hash ())); auto send2 = builder.make_block () .account (nano::dev::genesis_key.pub) .previous (send1->hash ()) diff --git a/nano/core_test/system.cpp b/nano/core_test/system.cpp index 486a1fd543..696afceb10 100644 --- a/nano/core_test/system.cpp +++ b/nano/core_test/system.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +33,7 @@ TEST (system, system_genesis) for (auto & i : system.nodes) { auto transaction = i->ledger.tx_begin_read (); - ASSERT_EQ (nano::dev::constants.genesis_amount, i->ledger.account_balance (transaction, nano::dev::genesis_key.pub)); + ASSERT_EQ (nano::dev::constants.genesis_amount, i->ledger.any.account_balance (transaction, nano::dev::genesis_key.pub)); } } @@ -44,7 +45,7 @@ TEST (system, DISABLED_generate_send_existing) 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_key.pub, stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true)); - auto info1 = node1.ledger.account_info (node1.ledger.tx_begin_read (), nano::dev::genesis_key.pub); + auto info1 = node1.ledger.any.account_get (node1.ledger.tx_begin_read (), nano::dev::genesis_key.pub); ASSERT_TRUE (info1); std::vector accounts; accounts.push_back (nano::dev::genesis_key.pub); @@ -65,7 +66,7 @@ TEST (system, DISABLED_generate_send_existing) ASSERT_EQ (nano::block_status::progress, node1.ledger.process (transaction, open_block)); } ASSERT_GT (node1.balance (stake_preserver.pub), node1.balance (nano::dev::genesis_key.pub)); - auto info2 = node1.ledger.account_info (node1.ledger.tx_begin_read (), nano::dev::genesis_key.pub); + auto info2 = node1.ledger.any.account_get (node1.ledger.tx_begin_read (), nano::dev::genesis_key.pub); ASSERT_TRUE (info2); ASSERT_NE (info1->head, info2->head); system.deadline_set (15s); @@ -73,14 +74,13 @@ TEST (system, DISABLED_generate_send_existing) { ASSERT_NO_ERROR (system.poll ()); auto transaction = node1.ledger.tx_begin_read (); - info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub); + info2 = node1.ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info2); } ASSERT_EQ (info1->block_count + 2, info2->block_count); ASSERT_EQ (info2->balance, nano::dev::constants.genesis_amount / 3); { - auto transaction = node1.ledger.tx_begin_read (); - ASSERT_NE (node1.ledger.amount (transaction, info2->head), 0); + ASSERT_NE (node1.ledger.any.block_amount (node1.ledger.tx_begin_read (), info2->head), 0); } system.stop (); runner.join (); @@ -93,11 +93,11 @@ TEST (system, DISABLED_generate_send_new) nano::thread_runner runner (system.io_ctx, node1.config.io_threads); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); { - auto transaction (node1.store.tx_begin_read ()); - auto iterator1 (node1.store.account.begin (transaction)); - ASSERT_NE (node1.store.account.end (), iterator1); + auto transaction (node1.ledger.tx_begin_read ()); + auto iterator1 (node1.ledger.any.account_begin (transaction)); + ASSERT_NE (node1.ledger.any.account_end (), iterator1); ++iterator1; - ASSERT_EQ (node1.store.account.end (), iterator1); + ASSERT_EQ (node1.ledger.any.account_end (), iterator1); } nano::keypair stake_preserver; auto send_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true)); diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index 17284f3b2e..faa6adbe97 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -183,9 +184,9 @@ TEST (wallet, spend_all_one) nano::keypair key2; ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, std::numeric_limits::max ())); auto transaction = node1.ledger.tx_begin_read (); - auto info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info2 = node1.ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_NE (latest1, info2->head); - auto block = node1.ledger.block (transaction, info2->head); + auto block = node1.ledger.any.block_get (transaction, info2->head); ASSERT_NE (nullptr, block); ASSERT_EQ (latest1, block->previous ()); ASSERT_TRUE (info2->balance.is_zero ()); @@ -217,10 +218,10 @@ TEST (wallet, spend) ASSERT_EQ (nullptr, system.wallet (0)->send_action (0, key2.pub, 0)); ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, std::numeric_limits::max ())); auto transaction = node1.ledger.tx_begin_read (); - auto info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info2 = node1.ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info2); ASSERT_NE (latest1, info2->head); - auto block = node1.ledger.block (transaction, info2->head); + auto block = node1.ledger.any.block_get (transaction, info2->head); ASSERT_NE (nullptr, block); ASSERT_EQ (latest1, block->previous ()); ASSERT_TRUE (info2->balance.is_zero ()); @@ -242,7 +243,7 @@ TEST (wallet, spend_no_previous) { system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); auto transaction = system.nodes[0]->ledger.tx_begin_read (); - auto info1 = system.nodes[0]->ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info1 = system.nodes[0]->ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info1); for (auto i (0); i < 50; ++i) { @@ -650,7 +651,7 @@ TEST (wallet, work_generate) } nano::keypair key; auto block (wallet->send_action (nano::dev::genesis_key.pub, key.pub, 100)); - ASSERT_TIMELY (10s, node1.ledger.account_balance (node1.ledger.tx_begin_read (), nano::dev::genesis_key.pub) != amount1); + ASSERT_TIMELY (10s, node1.ledger.any.account_balance (node1.ledger.tx_begin_read (), nano::dev::genesis_key.pub) != amount1); system.deadline_set (10s); auto again (true); while (again) @@ -1188,7 +1189,7 @@ TEST (wallet, search_receivable) ASSERT_EQ (2, node.ledger.block_count ()); ASSERT_FALSE (wallet.search_receivable (wallet.wallets.tx_begin_read ())); ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount); - auto receive_hash = node.ledger.latest (node.ledger.tx_begin_read (), nano::dev::genesis_key.pub); + auto receive_hash = node.ledger.any.account_head (node.ledger.tx_begin_read (), nano::dev::genesis_key.pub); auto receive = node.block (receive_hash); ASSERT_NE (nullptr, receive); ASSERT_EQ (receive->sideband ().height, 3); @@ -1225,13 +1226,13 @@ TEST (wallet, receive_pruned) ASSERT_EQ (1, node2.ledger.pruning_action (transaction, send1->hash (), 2)); } ASSERT_EQ (1, node2.ledger.pruned_count ()); - ASSERT_TRUE (node2.ledger.block_or_pruned_exists (send1->hash ())); - ASSERT_FALSE (node2.ledger.block_exists (node2.ledger.tx_begin_read (), send1->hash ())); + ASSERT_TRUE (node2.block_or_pruned_exists (send1->hash ())); + ASSERT_FALSE (node2.ledger.any.block_exists (node2.ledger.tx_begin_read (), send1->hash ())); wallet2.insert_adhoc (key.prv, false); auto open1 = wallet2.receive_action (send1->hash (), key.pub, amount, send1->destination (), 1); ASSERT_NE (nullptr, open1); - ASSERT_EQ (amount, node2.ledger.balance (node2.ledger.tx_begin_read (), open1->hash ())); + ASSERT_EQ (amount, node2.ledger.any.block_balance (node2.ledger.tx_begin_read (), open1->hash ())); ASSERT_TIMELY_EQ (5s, node2.ledger.cemented_count (), 4); } diff --git a/nano/core_test/wallets.cpp b/nano/core_test/wallets.cpp index 8de340f84a..965c496925 100644 --- a/nano/core_test/wallets.cpp +++ b/nano/core_test/wallets.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -254,7 +255,7 @@ TEST (wallets, search_receivable) node.wallets.search_receivable (wallet_id); } ASSERT_TIMELY_EQ (3s, node.balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount); - auto receive_hash = node.ledger.latest (node.ledger.tx_begin_read (), nano::dev::genesis_key.pub); + auto receive_hash = node.ledger.any.account_head (node.ledger.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/nano_node/entry.cpp b/nano/nano_node/entry.cpp index eafd2ef6cc..09190dcfb4 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -427,9 +428,9 @@ int main (int argc, char * const * argv) std::cout << "Outputting any frontier hashes which have associated key hashes in the unchecked table (may take some time)...\n"; // Cache the account heads to make searching quicker against unchecked keys. - auto transaction (node->store.tx_begin_read ()); + auto transaction (node->ledger.tx_begin_read ()); std::unordered_set frontier_hashes; - for (auto i (node->store.account.begin (transaction)), n (node->store.account.end ()); i != n; ++i) + for (auto i (node->ledger.any.account_begin (transaction)), n (node->ledger.any.account_end ()); i != n; ++i) { frontier_hashes.insert (i->second.head); } @@ -1416,17 +1417,17 @@ int main (int argc, char * const * argv) auto hash (info.open_block); nano::block_hash calculated_hash (0); - auto block = node->ledger.block (transaction, hash); // Block data + auto block = node->ledger.any.block_get (transaction, hash); // Block data uint64_t height (0); if (node->ledger.pruning && confirmation_height_info.height != 0) { hash = confirmation_height_info.frontier; - block = node->ledger.block (transaction, hash); + block = node->ledger.any.block_get (transaction, hash); // Iteration until pruned block bool pruned_block (false); while (!pruned_block && !block->previous ().is_zero ()) { - auto previous_block = node->ledger.block (transaction, block->previous ()); + auto previous_block = node->ledger.any.block_get (transaction, block->previous ()); if (previous_block != nullptr) { hash = previous_block->hash (); @@ -1443,7 +1444,7 @@ int main (int argc, char * const * argv) } calculated_hash = block->previous (); height = block->sideband ().height - 1; - if (!node->ledger.block_or_pruned_exists (transaction, info.open_block)) + if (!node->ledger.any.block_exists_or_pruned (transaction, info.open_block)) { print_error_message (boost::str (boost::format ("Open block does not exist %1%\n") % info.open_block.to_string ())); } @@ -1499,7 +1500,7 @@ int main (int argc, char * const * argv) bool error_or_pruned (false); if (!state_block.hashables.previous.is_zero ()) { - prev_balance = node->ledger.balance (transaction, state_block.hashables.previous).value_or (0); + prev_balance = node->ledger.any.block_balance (transaction, state_block.hashables.previous).value_or (0); } if (node->ledger.is_epoch_link (state_block.hashables.link)) { @@ -1523,7 +1524,7 @@ int main (int argc, char * const * argv) } else { - auto prev_balance = node->ledger.balance (transaction, block->previous ()); + auto prev_balance = node->ledger.any.block_balance (transaction, block->previous ()); if (!node->ledger.pruning || prev_balance) { if (block->balance () < prev_balance.value ()) @@ -1547,7 +1548,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->source ()); + block_details_error |= !node->ledger.any.block_exists_or_pruned (transaction, block->source ()); } } } @@ -1591,11 +1592,11 @@ int main (int argc, char * const * argv) calculated_representative = block->representative_field ().value (); } // Retrieving successor block hash - hash = node->ledger.successor (transaction, hash).value_or (0); + hash = node->ledger.any.block_successor (transaction, hash).value_or (0); // Retrieving block data if (!hash.is_zero ()) { - block = node->ledger.block (transaction, hash); + block = node->ledger.any.block_get (transaction, hash); } } // Check if required block exists @@ -1628,7 +1629,7 @@ int main (int argc, char * const * argv) } size_t const accounts_deque_overflow (32 * 1024); auto transaction = node->ledger.tx_begin_read (); - for (auto i (node->store.account.begin (transaction)), n (node->store.account.end ()); i != n; ++i) + for (auto i (node->ledger.any.account_begin (transaction)), n (node->ledger.any.account_end ()); i != n; ++i) { { nano::unique_lock lock{ mutex }; @@ -1680,7 +1681,7 @@ int main (int argc, char * const * argv) std::cout << boost::str (boost::format ("%1% pending blocks validated\n") % count); } // Check block existance - auto block = node->ledger.block (transaction, key.hash); + auto block = node->ledger.any.block_get (transaction, key.hash); bool pruned (false); if (block == nullptr) { @@ -1697,7 +1698,7 @@ int main (int argc, char * const * argv) bool previous_pruned = node->ledger.pruning && node->store.pruned.exists (transaction, block->previous ()); if (previous_pruned) { - block = node->ledger.block (transaction, key.hash); + block = node->ledger.any.block_get (transaction, key.hash); } if (auto state = dynamic_cast (block.get ())) { @@ -1719,7 +1720,7 @@ int main (int argc, char * const * argv) print_error_message (boost::str (boost::format ("Incorrect destination for pending block %1%\n") % key.hash.to_string ())); } // Check if pending source is correct - auto account (node->ledger.account (transaction, key.hash)); + auto account (node->ledger.any.block_account (transaction, key.hash)); if (info.source != account && !pruned) { print_error_message (boost::str (boost::format ("Incorrect source for pending block %1%\n") % key.hash.to_string ())); @@ -1727,7 +1728,7 @@ int main (int argc, char * const * argv) // Check if pending amount is correct if (!pruned && !previous_pruned) { - auto amount (node->ledger.amount (transaction, key.hash)); + auto amount (node->ledger.any.block_amount (transaction, key.hash)); if (info.amount != amount) { print_error_message (boost::str (boost::format ("Incorrect amount for pending block %1%\n") % key.hash.to_string ())); @@ -1796,7 +1797,7 @@ int main (int argc, char * const * argv) auto transaction = source_node->ledger.tx_begin_read (); block_count = source_node->ledger.block_count (); std::cout << boost::str (boost::format ("Performing bootstrap emulation, %1% blocks in ledger...") % block_count) << std::endl; - for (auto i (source_node->store.account.begin (transaction)), n (source_node->store.account.end ()); i != n; ++i) + for (auto i (source_node->ledger.any.account_begin (transaction)), n (source_node->ledger.any.account_end ()); i != n; ++i) { nano::account const & account (i->first); nano::account_info const & info (i->second); @@ -1804,7 +1805,7 @@ int main (int argc, char * const * argv) while (!hash.is_zero ()) { // Retrieving block data - auto block = source_node->ledger.block (transaction, hash); + auto block = source_node->ledger.any.block_get (transaction, hash); if (block != nullptr) { ++count; diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 58b25976e4..95e77f84b1 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -126,7 +127,7 @@ void nano::active_transactions::notify_observers (nano::secure::read_transaction { auto block = status.winner; auto account = block->account (); - auto amount = node.ledger.amount (transaction, block->hash ()).value_or (0); + auto amount = node.ledger.any.block_amount (transaction, block->hash ()).value_or (0).number (); auto is_state_send = block->type () == block_type::state && block->is_send (); auto is_state_epoch = block->type () == block_type::state && block->is_epoch (); node.observers.blocks.notify (status, votes, account, amount, is_state_send, is_state_epoch); diff --git a/nano/node/backlog_population.cpp b/nano/node/backlog_population.cpp index f919f2c044..705fc2dad5 100644 --- a/nano/node/backlog_population.cpp +++ b/nano/node/backlog_population.cpp @@ -136,6 +136,6 @@ void nano::backlog_population::activate (secure::transaction const & transaction { stats.inc (nano::stat::type::backlog, nano::stat::detail::activated); - activate_callback.notify (transaction, account, account_info, conf_info); + activate_callback.notify (transaction, account); } } diff --git a/nano/node/backlog_population.hpp b/nano/node/backlog_population.hpp index 3ea9d88ec4..8cd9cd1d7a 100644 --- a/nano/node/backlog_population.hpp +++ b/nano/node/backlog_population.hpp @@ -50,7 +50,7 @@ class backlog_population final /** * Callback called for each backlogged account */ - using callback_t = nano::observer_set; + using callback_t = nano::observer_set; callback_t activate_callback; private: // Dependencies diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 9338b98d1a..7fa7ac4e3f 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -204,8 +205,8 @@ bool nano::block_processor::add_impl (context ctx, std::shared_ptrhash () != hash) { // Replace our block with the winner and roll back any dependent blocks diff --git a/nano/node/bootstrap/bootstrap_attempt.cpp b/nano/node/bootstrap/bootstrap_attempt.cpp index 032cdd3b5e..e40a9e0f89 100644 --- a/nano/node/bootstrap/bootstrap_attempt.cpp +++ b/nano/node/bootstrap/bootstrap_attempt.cpp @@ -129,7 +129,7 @@ bool nano::bootstrap_attempt::process_block (std::shared_ptr const } bool stop_pull (false); // If block already exists in the ledger, then we can avoid next part of long account chain - if (pull_blocks_processed % nano::bootstrap_limits::pull_count_per_check == 0 && node_l->ledger.block_or_pruned_exists (block_a->hash ())) + if (pull_blocks_processed % nano::bootstrap_limits::pull_count_per_check == 0 && node_l->block_or_pruned_exists (block_a->hash ())) { stop_pull = true; } diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index 53c5ead036..7eb28b9dac 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -306,7 +307,7 @@ void nano::bulk_pull_account_client::receive_pending () { if (!pending.is_zero ()) { - if (!node->ledger.block_or_pruned_exists (pending)) + if (!node->block_or_pruned_exists (pending)) { node->bootstrap_initiator.bootstrap_lazy (pending, false); } @@ -365,23 +366,23 @@ void nano::bulk_pull_server::set_current_end () include_start = false; debug_assert (request != nullptr); auto transaction = node->ledger.tx_begin_read (); - if (!node->ledger.block_exists (transaction, request->end)) + if (!node->ledger.any.block_exists (transaction, request->end)) { node->logger.debug (nano::log::type::bulk_pull_server, "Bulk pull end block doesn't exist: {}, sending everything", request->end.to_string ()); request->end.clear (); } - if (node->ledger.block_exists (transaction, request->start.as_block_hash ())) + if (node->ledger.any.block_exists (transaction, request->start.as_block_hash ())) { node->logger.debug (nano::log::type::bulk_pull_server, "Bulk pull request for block hash: {}", request->start.to_string ()); - current = ascending () ? node->ledger.successor (transaction, request->start.as_block_hash ()).value_or (0) : request->start.as_block_hash (); + current = ascending () ? node->ledger.any.block_successor (transaction, request->start.as_block_hash ()).value_or (0) : request->start.as_block_hash (); include_start = true; } else { - auto info = node->ledger.account_info (transaction, request->start.as_account ()); + auto info = node->ledger.any.account_get (transaction, request->start.as_account ()); if (!info) { node->logger.debug (nano::log::type::bulk_pull_server, "Request for unknown account: {}", request->start.to_account ()); @@ -393,7 +394,7 @@ void nano::bulk_pull_server::set_current_end () current = ascending () ? info->open_block : info->head; if (!request->end.is_zero ()) { - auto account (node->ledger.account (transaction, request->end)); + auto account (node->ledger.any.block_account (transaction, request->end)); if (account != request->start.as_account ()) { node->logger.debug (nano::log::type::bulk_pull_server, "Request for block that is not on account chain: {} not on {}", request->end.to_string (), request->start.to_account ()); @@ -653,8 +654,8 @@ void nano::bulk_pull_account_server::send_frontier () auto stream_transaction = node->ledger.tx_begin_read (); // Get account balance and frontier block hash - auto account_frontier_hash (node->ledger.latest (stream_transaction, request->account)); - auto account_frontier_balance_int (node->ledger.account_balance (stream_transaction, request->account)); + auto account_frontier_hash (node->ledger.any.account_head (stream_transaction, request->account)); + auto account_frontier_balance_int (node->ledger.any.account_balance (stream_transaction, request->account).value_or (0)); nano::uint128_union account_frontier_balance (account_frontier_balance_int); // Write the frontier block hash and balance into a buffer @@ -755,9 +756,9 @@ std::pair, std::unique_ptrledger.tx_begin_read (); auto & ledger = node->ledger; - auto stream = ledger.receivable_upper_bound (tx, current_key.account, current_key.hash); + auto stream = ledger.any.receivable_upper_bound (tx, current_key.account, current_key.hash); - if (stream == ledger.receivable_end ()) + if (stream == ledger.any.receivable_end ()) { break; } diff --git a/nano/node/bootstrap/bootstrap_frontier.cpp b/nano/node/bootstrap/bootstrap_frontier.cpp index 6380bd61a9..20c2b6803e 100644 --- a/nano/node/bootstrap/bootstrap_frontier.cpp +++ b/nano/node/bootstrap/bootstrap_frontier.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -162,7 +163,7 @@ void nano::frontier_req_client::received_frontier (boost::system::error_code con } else { - if (node->ledger.block_or_pruned_exists (latest)) + if (node->block_or_pruned_exists (latest)) { // We know about a block they don't. unsynced (frontier, latest); @@ -236,8 +237,8 @@ void nano::frontier_req_client::next () if (accounts.empty ()) { std::size_t max_size (128); - auto transaction (node->store.tx_begin_read ()); - for (auto i (node->store.account.begin (transaction, current.number () + 1)), n (node->store.account.end ()); i != n && accounts.size () != max_size; ++i) + auto transaction (node->ledger.tx_begin_read ()); + for (auto i (node->ledger.any.account_upper_bound (transaction, current.number ())), n (node->ledger.any.account_end ()); i != n && accounts.size () != max_size; ++i) { nano::account_info const & info (i->second); nano::account const & account (i->first); @@ -376,10 +377,10 @@ void nano::frontier_req_server::next () auto now (nano::seconds_since_epoch ()); bool disable_age_filter (request->age == std::numeric_limitsage)>::max ()); std::size_t max_size (128); - auto transaction (node->store.tx_begin_read ()); + auto transaction (node->ledger.tx_begin_read ()); if (!send_confirmed ()) { - for (auto i (node->store.account.begin (transaction, current.number () + 1)), n (node->store.account.end ()); i != n && accounts.size () != max_size; ++i) + for (auto i (node->ledger.any.account_upper_bound (transaction, current.number ())), n (node->ledger.any.account_end ()); i != n && accounts.size () != max_size; ++i) { nano::account_info const & info (i->second); if (disable_age_filter || (now - info.modified) <= request->age) diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index 247d003d62..30661abd7a 100644 --- a/nano/node/bootstrap/bootstrap_lazy.cpp +++ b/nano/node/bootstrap/bootstrap_lazy.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -131,7 +132,7 @@ void nano::bootstrap_attempt_lazy::lazy_pull_flush (nano::unique_lockledger.block_or_pruned_exists (transaction, pull_start.first.as_block_hash ())) + if (!lazy_blocks_processed (pull_start.first.as_block_hash ()) && !node->ledger.any.block_exists_or_pruned (transaction, pull_start.first.as_block_hash ())) { lock_a.unlock (); node->bootstrap_initiator.connections->add_pull (nano::pull_info (pull_start.first, pull_start.first.as_block_hash (), nano::block_hash (0), incremental_id, batch_count, pull_start.second)); @@ -168,7 +169,7 @@ bool nano::bootstrap_attempt_lazy::lazy_finished () auto transaction = node->ledger.tx_begin_read (); for (auto it (lazy_keys.begin ()), end (lazy_keys.end ()); it != end && !stopped;) { - if (node->ledger.block_or_pruned_exists (transaction, *it)) + if (node->ledger.any.block_exists_or_pruned (transaction, *it)) { it = lazy_keys.erase (it); } @@ -292,7 +293,7 @@ bool nano::bootstrap_attempt_lazy::process_block_lazy (std::shared_ptrsource_field () && !node->ledger.block_or_pruned_exists (block_a->source_field ().value ()) && block_a->source_field ().value () != node->network_params.ledger.genesis->account ()) + if (block_a->source_field () && !node->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_field ().value (), retry_limit); } @@ -337,7 +338,7 @@ void nano::bootstrap_attempt_lazy::lazy_block_state (std::shared_ptrhashables.balance.number ()); auto const & link (block_l->hashables.link); // If link is not epoch link or 0. And if block from link is unknown - if (!link.is_zero () && !node->ledger.is_epoch_link (link) && !lazy_blocks_processed (link.as_block_hash ()) && !node->ledger.block_or_pruned_exists (transaction, link.as_block_hash ())) + if (!link.is_zero () && !node->ledger.is_epoch_link (link) && !lazy_blocks_processed (link.as_block_hash ()) && !node->ledger.any.block_exists_or_pruned (transaction, link.as_block_hash ())) { auto const & previous (block_l->hashables.previous); // If state block previous is 0 then source block required @@ -346,12 +347,12 @@ void nano::bootstrap_attempt_lazy::lazy_block_state (std::shared_ptrledger.block_or_pruned_exists (transaction, previous)) + else if (node->ledger.any.block_exists_or_pruned (transaction, previous)) { - auto previous_balance = node->ledger.balance (transaction, previous); + auto previous_balance = node->ledger.any.block_balance (transaction, previous); if (previous_balance) { - if (previous_balance.value () <= balance) + if (previous_balance.value ().number () <= balance) { lazy_add (link, retry_limit); } @@ -421,13 +422,13 @@ void nano::bootstrap_attempt_lazy::lazy_backlog_cleanup () auto transaction = node->ledger.tx_begin_read (); for (auto it (lazy_state_backlog.begin ()), end (lazy_state_backlog.end ()); it != end && !stopped;) { - if (node->ledger.block_or_pruned_exists (transaction, it->first)) + if (node->ledger.any.block_exists_or_pruned (transaction, it->first)) { auto next_block (it->second); - auto balance = node->ledger.balance (transaction, it->first); + auto balance = node->ledger.any.block_balance (transaction, it->first); if (balance) { - if (balance.value () <= next_block.balance) // balance + if (balance.value ().number () <= next_block.balance) // balance { lazy_add (next_block.link, next_block.retry_limit); // link } @@ -495,7 +496,7 @@ bool nano::bootstrap_attempt_lazy::lazy_processed_or_exists (nano::block_hash co else { lock.unlock (); - if (node->ledger.block_or_pruned_exists (hash_a)) + if (node->block_or_pruned_exists (hash_a)) { result = true; } diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index b1fba6195f..a1645c54c0 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -258,7 +259,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const & { case asc_pull_req::hash_type::block: { - if (ledger.block_exists (transaction, request.start.as_block_hash ())) + if (ledger.any.block_exists (transaction, request.start.as_block_hash ())) { return prepare_response (transaction, id, request.start.as_block_hash (), count); } @@ -266,7 +267,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const & break; case asc_pull_req::hash_type::account: { - auto info = ledger.account_info (transaction, request.start.as_account ()); + auto info = ledger.any.account_get (transaction, request.start.as_account ()); if (info) { // Start from open block if pulling by account @@ -319,13 +320,13 @@ std::vector> nano::bootstrap_server::prepare_blocks std::vector> result; if (!start_block.is_zero ()) { - std::shared_ptr current = ledger.block (transaction, start_block); + std::shared_ptr current = ledger.any.block_get (transaction, start_block); while (current && result.size () < count) { result.push_back (current); auto successor = current->sideband ().successor; - current = ledger.block (transaction, successor); + current = ledger.any.block_get (transaction, successor); } } return result; @@ -352,7 +353,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const & case asc_pull_req::hash_type::block: { // Try to lookup account assuming target is block hash - target = ledger.account (transaction, request.target.as_block_hash ()).value_or (0); + target = ledger.any.block_account (transaction, request.target.as_block_hash ()).value_or (0); } break; } @@ -360,7 +361,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const & nano::asc_pull_ack::account_info_payload response_payload{}; response_payload.account = target; - auto account_info = ledger.account_info (transaction, target); + auto account_info = ledger.any.account_get (transaction, target); if (account_info) { response_payload.account_open = account_info->open_block; @@ -395,7 +396,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const & nano::asc_pull_ack::frontiers_payload response_payload{}; - for (auto it = store.account.begin (transaction, request.start), end = store.account.end (); it != end && response_payload.frontiers.size () < request.count; ++it) + for (auto it = ledger.any.account_lower_bound (transaction, request.start), end = ledger.any.account_end (); it != end && response_payload.frontiers.size () < request.count; ++it) { response_payload.frontiers.emplace_back (it->first, it->second.head); } diff --git a/nano/node/bootstrap_ascending/iterators.cpp b/nano/node/bootstrap_ascending/iterators.cpp index 708906b84e..265cfe9601 100644 --- a/nano/node/bootstrap_ascending/iterators.cpp +++ b/nano/node/bootstrap_ascending/iterators.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -27,9 +28,8 @@ void nano::bootstrap_ascending::database_iterator::next (secure::transaction & t { case table_type::account: { - auto i = current.number () + 1; - auto item = ledger.store.account.begin (tx, i); - if (item != ledger.store.account.end ()) + auto item = ledger.any.account_upper_bound (tx, current.number ()); + if (item != ledger.any.account_end ()) { current = item->first; } @@ -41,8 +41,8 @@ void nano::bootstrap_ascending::database_iterator::next (secure::transaction & t } case table_type::pending: { - auto item = ledger.receivable_upper_bound (tx, current); - if (item != ledger.receivable_end ()) + auto item = ledger.any.receivable_upper_bound (tx, current); + if (item != ledger.any.receivable_end ()) { current = item->first.account; } diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index cae6d4effd..89bc36d5e0 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -151,7 +152,7 @@ void nano::bootstrap_ascending::service::inspect (secure::transaction const & tx break; 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 account = block.previous ().is_zero () ? block.account_field ().value () : ledger.any.block_account (tx, block.previous ()).value (); const auto source = block.source_field ().value_or (block.link_field ().value_or (0).as_block_hash ()); // Mark account as blocked because it is missing the source block diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index 7ca417439c..d39cf5791d 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include diff --git a/nano/node/epoch_upgrader.cpp b/nano/node/epoch_upgrader.cpp index d5a23cad4e..c662313ef1 100644 --- a/nano/node/epoch_upgrader.cpp +++ b/nano/node/epoch_upgrader.cpp @@ -3,6 +3,7 @@ #include #include #include +#include nano::epoch_upgrader::epoch_upgrader (nano::node & node_a, nano::ledger & ledger_a, nano::store::component & store_a, nano::network_params & network_params_a, nano::logger & logger_a) : node{ node_a }, @@ -113,9 +114,9 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc while (!finished_accounts && count_limit != 0 && !stopped) { { - auto transaction (store.tx_begin_read ()); + auto transaction (ledger.tx_begin_read ()); // Collect accounts to upgrade - for (auto i (store.account.begin (transaction)), n (store.account.end ()); i != n && accounts_list.size () < count_limit; ++i) + for (auto i (ledger.any.account_begin (transaction)), n (ledger.any.account_end ()); i != n && accounts_list.size () < count_limit; ++i) { nano::account const & account (i->first); nano::account_info const & info (i->second); @@ -135,7 +136,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc for (auto i (accounts_list.get ().begin ()), n (accounts_list.get ().end ()); i != n && attempts < upgrade_batch_size && attempts < count_limit && !stopped; ++i) { nano::account const & account (i->account); - auto info = ledger.account_info (ledger.tx_begin_read (), account); + auto info = ledger.any.account_get (ledger.tx_begin_read (), account); if (info && info->epoch () < epoch_a) { ++attempts; @@ -209,7 +210,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc std::atomic upgraded_pending (0); uint64_t workers (0); uint64_t attempts (0); - for (auto current = ledger.receivable_upper_bound (ledger.tx_begin_read (), 0), end = ledger.receivable_end (); current != end && attempts < upgrade_batch_size && attempts < count_limit && !stopped;) + for (auto current = ledger.any.receivable_upper_bound (ledger.tx_begin_read (), 0), end = ledger.any.receivable_end (); current != end && attempts < upgrade_batch_size && attempts < count_limit && !stopped;) { auto const & [key, info] = *current; if (!store.account.exists (ledger.tx_begin_read (), key.account)) @@ -255,7 +256,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc } } // Move to next pending item - current = ledger.receivable_upper_bound (ledger.tx_begin_read (), key.account, key.hash); + current = ledger.any.receivable_upper_bound (ledger.tx_begin_read (), key.account, key.hash); } else { @@ -266,7 +267,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc } else { - current = ledger.receivable_upper_bound (ledger.tx_begin_read (), key.account); + current = ledger.any.receivable_upper_bound (ledger.tx_begin_read (), key.account); } } } diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 66bdaa6c55..e44937720e 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include @@ -267,7 +269,7 @@ nano::account_info nano::json_handler::account_info_impl (secure::transaction co nano::account_info result; if (!ec) { - auto info = node.ledger.account_info (transaction_a, account_a); + auto info = node.ledger.any.account_get (transaction_a, account_a); if (!info) { ec = nano::error_common::account_not_found; @@ -402,12 +404,12 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a) auto previous (block_a.previous ()); if (!previous.is_zero ()) { - block_previous = node.ledger.block (transaction, previous); + block_previous = node.ledger.any.block_get (transaction, previous); } // Send check if (block_previous != nullptr) { - details.is_send = node.ledger.balance (transaction, previous) > block_a.balance_field ().value ().number (); + details.is_send = node.ledger.any.block_balance (transaction, previous) > block_a.balance_field ().value ().number (); details_found = true; } // Epoch check @@ -418,9 +420,9 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a) 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 block_link = node.ledger.any.block_get (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.ledger.pending_info (transaction, nano::pending_key{ account, link.value ().as_block_hash () })) + if (block_link != nullptr && node.ledger.any.pending_get (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; @@ -647,7 +649,7 @@ void nano::json_handler::account_info () { if (info.block_count != confirmation_height_info.height) { - confirmed_balance_l = node.ledger.balance (transaction, confirmation_height_info.frontier).value_or (0); + confirmed_balance_l = node.ledger.any.block_balance (transaction, confirmation_height_info.frontier).value_or (0); } else { @@ -678,7 +680,7 @@ void nano::json_handler::account_info () std::shared_ptr confirmed_frontier_block; if (include_confirmed && confirmation_height_info.height > 0) { - confirmed_frontier_block = node.ledger.block (transaction, confirmation_height_info.frontier); + confirmed_frontier_block = node.ledger.any.block_get (transaction, confirmation_height_info.frontier); } if (representative) @@ -692,7 +694,7 @@ void nano::json_handler::account_info () 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_field ().value (); + confirmed_representative = node.ledger.any.block_get (transaction, node.ledger.representative (transaction, confirmation_height_info.frontier))->representative_field ().value (); } } @@ -1002,7 +1004,7 @@ void nano::json_handler::accounts_frontiers () auto account = account_impl (account_from_request.second.data ()); if (!ec) { - auto latest = node.ledger.latest (transaction, account); + auto latest = node.ledger.any.account_head (transaction, account); if (!latest.is_zero ()) { frontiers.put (account.to_account (), latest.to_string ()); @@ -1051,10 +1053,10 @@ void nano::json_handler::accounts_receivable () if (!ec) { boost::property_tree::ptree peers_l; - for (auto current = node.ledger.receivable_upper_bound (transaction, account, 0), end = node.ledger.receivable_end (); current != end && peers_l.size () < count; ++current) + for (auto current = node.ledger.any.receivable_upper_bound (transaction, account, 0), end = node.ledger.any.receivable_end (); current != end && peers_l.size () < count; ++current) { auto const & [key, info] = *current; - if (include_only_confirmed && !node.ledger.block_confirmed (transaction, key.hash)) + if (include_only_confirmed && !node.ledger.confirmed.block_exists_or_pruned (transaction, key.hash)) { continue; } @@ -1150,22 +1152,22 @@ void nano::json_handler::block_info () if (!ec) { auto transaction = node.ledger.tx_begin_read (); - auto block = node.ledger.block (transaction, hash); + auto block = node.ledger.any.block_get (transaction, hash); if (block != nullptr) { auto account = block->account (); response_l.put ("block_account", account.to_account ()); - auto amount = node.ledger.amount (transaction, hash); + auto amount = node.ledger.any.block_amount (transaction, hash); if (amount) { - response_l.put ("amount", amount.value ().convert_to ()); + response_l.put ("amount", amount.value ().number ().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 ()); - auto confirmed (node.ledger.block_confirmed (transaction, hash)); + auto confirmed (node.ledger.confirmed.block_exists_or_pruned (transaction, hash)); response_l.put ("confirmed", confirmed); bool json_block_l = request.get ("json_block", false); @@ -1201,10 +1203,10 @@ void nano::json_handler::block_confirm () if (!ec) { auto transaction = node.ledger.tx_begin_read (); - auto block_l = node.ledger.block (transaction, hash); + auto block_l = node.ledger.any.block_get (transaction, hash); if (block_l != nullptr) { - if (!node.ledger.block_confirmed (transaction, hash)) + if (!node.ledger.confirmed.block_exists_or_pruned (transaction, hash)) { // Start new confirmation for unconfirmed (or not being confirmed) block if (!node.confirming_set.exists (hash)) @@ -1219,7 +1221,7 @@ void nano::json_handler::block_confirm () node.active.recently_cemented.put (status); // Trigger callback for confirmed block auto account = block_l->account (); - auto amount = node.ledger.amount (transaction, hash); + auto amount = node.ledger.any.block_amount (transaction, hash); bool is_state_send (false); bool is_state_epoch (false); if (amount) @@ -1230,7 +1232,7 @@ void nano::json_handler::block_confirm () 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); + node.observers.blocks.notify (status, {}, account, amount ? amount.value ().number () : 0, is_state_send, is_state_epoch); } response_l.put ("started", "1"); } @@ -1255,7 +1257,7 @@ void nano::json_handler::blocks () nano::block_hash hash; if (!hash.decode_hex (hash_text)) { - auto block = node.ledger.block (transaction, hash); + auto block = node.ledger.any.block_get (transaction, hash); if (block != nullptr) { if (json_block_l) @@ -1306,23 +1308,23 @@ void nano::json_handler::blocks_info () nano::block_hash hash; if (!hash.decode_hex (hash_text)) { - auto block = node.ledger.block (transaction, hash); + auto block = node.ledger.any.block_get (transaction, hash); if (block != nullptr) { boost::property_tree::ptree entry; auto account = block->account (); entry.put ("block_account", account.to_account ()); - auto amount = node.ledger.amount (transaction, hash); + auto amount = node.ledger.any.block_amount (transaction, hash); if (amount) { - entry.put ("amount", amount.value ().convert_to ()); + entry.put ("amount", amount.value ().number ().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 ()); - auto confirmed (node.ledger.block_confirmed (transaction, hash)); + auto confirmed (node.ledger.confirmed.block_exists_or_pruned (transaction, hash)); entry.put ("confirmed", confirmed); if (json_block_l) @@ -1356,7 +1358,7 @@ void nano::json_handler::blocks_info () entry.put ("receive_hash", nano::block_hash (0).to_string ()); } } - else if (node.ledger.pending_info (transaction, nano::pending_key{ block->destination (), hash })) + else if (node.ledger.any.pending_get (transaction, nano::pending_key{ block->destination (), hash })) { if (receivable) { @@ -1385,13 +1387,13 @@ void nano::json_handler::blocks_info () } if (source) { - if (!block->is_receive () || !node.ledger.block_exists (transaction, block->source ())) + if (!block->is_receive () || !node.ledger.any.block_exists (transaction, block->source ())) { entry.put ("source_account", "0"); } else { - auto block_a = node.ledger.block (transaction, block->source ()); + auto block_a = node.ledger.any.block_get (transaction, block->source ()); release_assert (block_a); entry.put ("source_account", block_a->account ().to_account ()); } @@ -1432,7 +1434,7 @@ void nano::json_handler::block_account () if (!ec) { auto transaction = node.ledger.tx_begin_read (); - auto block = node.ledger.block (transaction, hash); + auto block = node.ledger.any.block_get (transaction, hash); if (block) { response_l.put ("account", block->account ().to_account ()); @@ -1530,8 +1532,8 @@ void nano::json_handler::block_create () if (!ec) { existing->second->store.fetch (transaction, account, prv); - previous = node.ledger.latest (block_transaction, account); - balance = node.ledger.account_balance (block_transaction, account); + previous = node.ledger.any.account_head (block_transaction, account); + balance = node.ledger.any.account_balance (block_transaction, account).value_or (0); } } else @@ -1645,14 +1647,14 @@ void nano::json_handler::block_create () if (!previous_text.is_initialized () && !balance_text.is_initialized ()) { auto transaction = node.ledger.tx_begin_read (); - previous = node.ledger.latest (transaction, pub); - balance = node.ledger.account_balance (transaction, pub); + previous = node.ledger.any.account_head (transaction, pub); + balance = node.ledger.any.account_balance (transaction, pub).value_or (0); } // Double check current balance if previous block is specified else if (previous_text.is_initialized () && balance_text.is_initialized () && type == "send") { auto transaction = node.ledger.tx_begin_read (); - if (node.ledger.block_exists (transaction, previous) && node.ledger.balance (transaction, previous) != balance.number ()) + if (node.ledger.any.block_exists (transaction, previous) && node.ledger.any.block_balance (transaction, previous) != balance.number ()) { ec = nano::error_rpc::block_create_balance_mismatch; } @@ -1945,7 +1947,7 @@ void nano::json_handler::chain (bool successors) auto transaction = node.ledger.tx_begin_read (); while (!hash.is_zero () && blocks.size () < count) { - auto block_l = node.ledger.block (transaction, hash); + auto block_l = node.ledger.any.block_get (transaction, hash); if (block_l != nullptr) { if (offset > 0) @@ -1958,7 +1960,7 @@ void nano::json_handler::chain (bool successors) entry.put ("", hash.to_string ()); blocks.push_back (std::make_pair ("", entry)); } - hash = successors ? node.ledger.successor (transaction, hash).value_or (0) : block_l->previous (); + hash = successors ? node.ledger.any.block_successor (transaction, hash).value_or (0) : block_l->previous (); } else { @@ -2253,9 +2255,9 @@ void nano::json_handler::delegators () if (!ec) { - auto transaction (node.store.tx_begin_read ()); + auto transaction (node.ledger.tx_begin_read ()); boost::property_tree::ptree delegators; - for (auto i (node.store.account.begin (transaction, start_account.number () + 1)), n (node.store.account.end ()); i != n && delegators.size () < count; ++i) + for (auto i (node.ledger.any.account_upper_bound (transaction, start_account)), n (node.ledger.any.account_end ()); i != n && delegators.size () < count; ++i) { nano::account_info const & info (i->second); if (info.representative == representative) @@ -2280,8 +2282,8 @@ void nano::json_handler::delegators_count () if (!ec) { uint64_t count (0); - auto transaction (node.store.tx_begin_read ()); - for (auto i (node.store.account.begin (transaction)), n (node.store.account.end ()); i != n; ++i) + auto transaction (node.ledger.tx_begin_read ()); + for (auto i (node.ledger.any.account_begin (transaction)), n (node.ledger.any.account_end ()); i != n; ++i) { nano::account_info const & info (i->second); if (info.representative == account) @@ -2391,8 +2393,8 @@ void nano::json_handler::frontiers () if (!ec) { boost::property_tree::ptree frontiers; - auto transaction (node.store.tx_begin_read ()); - for (auto i (node.store.account.begin (transaction, start)), n (node.store.account.end ()); i != n && frontiers.size () < count; ++i) + auto transaction (node.ledger.tx_begin_read ()); + for (auto i (node.ledger.any.account_lower_bound (transaction, start)), n (node.ledger.any.account_end ()); i != n && frontiers.size () < count; ++i) { frontiers.put (i->first.to_account (), i->second.head.to_string ()); } @@ -2432,10 +2434,10 @@ class history_visitor : public nano::block_visitor tree.put ("type", "send"); auto account (block_a.hashables.destination.to_account ()); tree.put ("account", account); - auto amount = handler.node.ledger.amount (transaction, hash); + auto amount = handler.node.ledger.any.block_amount (transaction, hash); if (amount) { - tree.put ("amount", amount.value ().convert_to ()); + tree.put ("amount", amount.value ().number ().convert_to ()); } if (raw) { @@ -2447,15 +2449,15 @@ class history_visitor : public nano::block_visitor void receive_block (nano::receive_block const & block_a) { tree.put ("type", "receive"); - auto amount = handler.node.ledger.amount (transaction, hash); + auto amount = handler.node.ledger.any.block_amount (transaction, hash); if (amount) { - auto source_account = handler.node.ledger.account (transaction, block_a.hashables.source); + auto source_account = handler.node.ledger.any.block_account (transaction, block_a.hashables.source); if (source_account) { tree.put ("account", source_account.value ().to_account ()); } - tree.put ("amount", amount.value ().convert_to ()); + tree.put ("amount", amount.value ().number ().convert_to ()); } if (raw) { @@ -2480,15 +2482,15 @@ class history_visitor : public nano::block_visitor if (block_a.hashables.source != handler.node.ledger.constants.genesis->account ()) { bool error_or_pruned (false); - auto amount = handler.node.ledger.amount (transaction, hash); + auto amount = handler.node.ledger.any.block_amount (transaction, hash); if (amount) { - auto source_account = handler.node.ledger.account (transaction, block_a.hashables.source); + auto source_account = handler.node.ledger.any.block_account (transaction, block_a.hashables.source); if (source_account) { tree.put ("account", source_account.value ().to_account ()); } - tree.put ("amount", amount.value ().convert_to ()); + tree.put ("amount", amount.value ().number ().convert_to ()); } } else @@ -2517,7 +2519,7 @@ class history_visitor : public nano::block_visitor tree.put ("previous", block_a.hashables.previous.to_string ()); } auto balance (block_a.hashables.balance.number ()); - auto previous_balance = handler.node.ledger.balance (transaction, block_a.hashables.previous); + auto previous_balance = handler.node.ledger.any.block_balance (transaction, block_a.hashables.previous); if (!previous_balance) { if (raw) @@ -2529,7 +2531,7 @@ class history_visitor : public nano::block_visitor tree.put ("type", "unknown"); } } - else if (balance < previous_balance.value ()) + else if (balance < previous_balance.value ().number ()) { if (should_ignore_account (block_a.hashables.link.as_account ())) { @@ -2545,7 +2547,7 @@ class history_visitor : public nano::block_visitor tree.put ("type", "send"); } tree.put ("account", block_a.hashables.link.to_account ()); - tree.put ("amount", (previous_balance.value () - balance).convert_to ()); + tree.put ("amount", (previous_balance.value ().number () - balance).convert_to ()); } else { @@ -2566,7 +2568,7 @@ class history_visitor : public nano::block_visitor } else { - auto source_account = handler.node.ledger.account (transaction, block_a.hashables.link.as_block_hash ()); + auto source_account = handler.node.ledger.any.block_account (transaction, block_a.hashables.link.as_block_hash ()); if (source_account && should_ignore_account (source_account.value ())) { tree.clear (); @@ -2584,7 +2586,7 @@ class history_visitor : public nano::block_visitor { tree.put ("account", source_account.value ().to_account ()); } - tree.put ("amount", (balance - previous_balance.value ()).convert_to ()); + tree.put ("amount", (balance - previous_balance.value ().number ()).convert_to ()); } } } @@ -2639,9 +2641,9 @@ void nano::json_handler::account_history () { if (!hash.decode_hex (*head_str)) { - if (node.ledger.block_exists (transaction, hash)) + if (node.ledger.any.block_exists (transaction, hash)) { - account = node.ledger.account (transaction, hash).value (); + account = node.ledger.any.block_account (transaction, hash).value (); } else { @@ -2668,7 +2670,7 @@ void nano::json_handler::account_history () } else { - hash = node.ledger.latest (transaction, account); + hash = node.ledger.any.account_head (transaction, account); } } } @@ -2677,7 +2679,7 @@ void nano::json_handler::account_history () boost::property_tree::ptree history; bool output_raw (request.get_optional ("raw") == true); response_l.put ("account", account.to_account ()); - auto block = node.ledger.block (transaction, hash); + auto block = node.ledger.any.block_get (transaction, hash); while (block != nullptr && count > 0) { if (offset > 0) @@ -2694,7 +2696,7 @@ void nano::json_handler::account_history () entry.put ("local_timestamp", std::to_string (block->sideband ().timestamp)); entry.put ("height", std::to_string (block->sideband ().height)); entry.put ("hash", hash.to_string ()); - entry.put ("confirmed", node.ledger.block_confirmed (transaction, hash)); + entry.put ("confirmed", node.ledger.confirmed.block_exists_or_pruned (transaction, hash)); if (output_raw) { entry.put ("work", nano::to_string_hex (block->block_work ())); @@ -2704,8 +2706,8 @@ void nano::json_handler::account_history () --count; } } - hash = reverse ? node.ledger.successor (transaction, hash).value_or (0) : block->previous (); - block = node.ledger.block (transaction, hash); + hash = reverse ? node.ledger.any.block_successor (transaction, hash).value_or (0) : block->previous (); + block = node.ledger.any.block_get (transaction, hash); } response_l.add_child ("history", history); if (!hash.is_zero ()) @@ -2793,7 +2795,7 @@ void nano::json_handler::ledger () auto transaction = node.ledger.tx_begin_read (); if (!ec && !sorting) // Simple { - for (auto i (node.store.account.begin (transaction, start)), n (node.store.account.end ()); i != n && accounts.size () < count; ++i) + for (auto i (node.ledger.any.account_lower_bound (transaction, start)), n (node.ledger.any.account_end ()); i != n && accounts.size () < count; ++i) { nano::account_info const & info (i->second); if (info.modified >= modified_since && (receivable || info.balance.number () >= threshold.number ())) @@ -2834,7 +2836,7 @@ void nano::json_handler::ledger () else if (!ec) // Sorting { std::vector> ledger_l; - for (auto i (node.store.account.begin (transaction, start)), n (node.store.account.end ()); i != n; ++i) + for (auto i (node.ledger.any.account_lower_bound (transaction, start)), n (node.ledger.any.account_end ()); i != n; ++i) { nano::account_info const & info (i->second); nano::uint128_union balance (info.balance); @@ -3095,10 +3097,10 @@ void nano::json_handler::receivable () // The ptree container is used if there are any children nodes (e.g source/min_version) otherwise the amount container is used. std::vector> hash_ptree_pairs; std::vector> hash_amount_pairs; - for (auto current = node.ledger.receivable_upper_bound (transaction, account, 0), end = node.ledger.receivable_end (); current != end && (should_sort || peers_l.size () < count); ++current) + for (auto current = node.ledger.any.receivable_upper_bound (transaction, account, 0), end = node.ledger.any.receivable_end (); current != end && (should_sort || peers_l.size () < count); ++current) { auto const & [key, info] = *current; - if (include_only_confirmed && !node.ledger.block_confirmed (transaction, key.hash)) + if (include_only_confirmed && !node.ledger.confirmed.block_exists_or_pruned (transaction, key.hash)) { continue; } @@ -3196,13 +3198,13 @@ void nano::json_handler::receivable_exists () if (!ec) { auto transaction = node.ledger.tx_begin_read (); - auto block = node.ledger.block (transaction, hash); + auto block = node.ledger.any.block_get (transaction, hash); if (block != nullptr) { auto exists (false); if (block->is_send ()) { - exists = node.ledger.pending_info (transaction, nano::pending_key{ block->destination (), hash }).has_value (); + exists = node.ledger.any.pending_get (transaction, nano::pending_key{ block->destination (), hash }).has_value (); } exists = exists && (block_confirmed (node, transaction, block->hash (), include_active, include_only_confirmed)); response_l.put ("exists", exists ? "1" : "0"); @@ -3229,13 +3231,13 @@ void nano::json_handler::process () { std::shared_ptr block_state (std::static_pointer_cast (block)); auto transaction = rpc_l->node.ledger.tx_begin_read (); - if (!block_state->hashables.previous.is_zero () && !rpc_l->node.ledger.block_exists (transaction, block_state->hashables.previous)) + if (!block_state->hashables.previous.is_zero () && !rpc_l->node.ledger.any.block_exists (transaction, block_state->hashables.previous)) { rpc_l->ec = nano::error_process::gap_previous; } else { - auto balance (rpc_l->node.ledger.account_balance (transaction, block_state->hashables.account)); + auto balance (rpc_l->node.ledger.any.account_balance (transaction, block_state->hashables.account).value_or (0).number ()); if (subtype_text == "send") { if (balance <= block_state->hashables.balance.number ()) @@ -3440,9 +3442,9 @@ void nano::json_handler::receive () if (!ec) { auto block_transaction = node.ledger.tx_begin_read (); - if (node.ledger.block_or_pruned_exists (block_transaction, hash)) + if (node.ledger.any.block_exists_or_pruned (block_transaction, hash)) { - auto pending_info = node.ledger.pending_info (block_transaction, nano::pending_key (account, hash)); + auto pending_info = node.ledger.any.pending_get (block_transaction, nano::pending_key (account, hash)); if (pending_info) { auto work (work_optional_impl ()); @@ -3450,7 +3452,7 @@ void nano::json_handler::receive () { nano::root head; nano::epoch epoch = pending_info->epoch; - auto info = node.ledger.account_info (block_transaction, account); + auto info = node.ledger.any.account_get (block_transaction, account); if (info) { head = info->head; @@ -3669,28 +3671,28 @@ void nano::json_handler::republish () { boost::property_tree::ptree blocks; auto transaction = node.ledger.tx_begin_read (); - auto block = node.ledger.block (transaction, hash); + auto block = node.ledger.any.block_get (transaction, hash); if (block != nullptr) { std::deque> republish_bundle; for (auto i (0); !hash.is_zero () && i < count; ++i) { - block = node.ledger.block (transaction, hash); + block = node.ledger.any.block_get (transaction, hash); if (sources != 0) // Republish source chain { 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); + auto block_a = node.ledger.any.block_get (transaction, source); std::vector hashes; while (block_a != nullptr && hashes.size () < sources) { hashes.push_back (source); source = block_a->previous (); - block_a = node.ledger.block (transaction, source); + block_a = node.ledger.any.block_get (transaction, source); } std::reverse (hashes.begin (), hashes.end ()); for (auto & hash_l : hashes) { - block_a = node.ledger.block (transaction, hash_l); + block_a = node.ledger.any.block_get (transaction, hash_l); republish_bundle.push_back (std::move (block_a)); boost::property_tree::ptree entry_l; entry_l.put ("", hash_l.to_string ()); @@ -3703,14 +3705,14 @@ void nano::json_handler::republish () blocks.push_back (std::make_pair ("", entry)); if (destinations != 0) // Republish destination chain { - auto block_b = node.ledger.block (transaction, hash); + auto block_b = node.ledger.any.block_get (transaction, hash); auto destination = block_b->destination (); if (!destination.is_zero ()) { - if (!node.ledger.pending_info (transaction, nano::pending_key{ destination, hash })) + if (!node.ledger.any.pending_get (transaction, nano::pending_key{ destination, hash })) { - nano::block_hash previous (node.ledger.latest (transaction, destination)); - auto block_d = node.ledger.block (transaction, previous); + nano::block_hash previous (node.ledger.any.account_head (transaction, destination)); + auto block_d = node.ledger.any.block_get (transaction, previous); nano::block_hash source; std::vector hashes; while (block_d != nullptr && hash != source) @@ -3718,7 +3720,7 @@ void nano::json_handler::republish () hashes.push_back (previous); 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); + block_d = node.ledger.any.block_get (transaction, previous); } std::reverse (hashes.begin (), hashes.end ()); if (hashes.size () > destinations) @@ -3727,7 +3729,7 @@ void nano::json_handler::republish () } for (auto & hash_l : hashes) { - block_d = node.ledger.block (transaction, hash_l); + block_d = node.ledger.any.block_get (transaction, hash_l); republish_bundle.push_back (std::move (block_d)); boost::property_tree::ptree entry_l; entry_l.put ("", hash_l.to_string ()); @@ -3736,7 +3738,7 @@ void nano::json_handler::republish () } } } - hash = node.ledger.successor (transaction, hash).value_or (0); + hash = node.ledger.any.block_successor (transaction, hash).value_or (0); } node.network.flood_block_many (std::move (republish_bundle), nullptr, 25); response_l.put ("success", ""); // obsolete @@ -4289,7 +4291,7 @@ void nano::json_handler::unopened () auto transaction = node.ledger.tx_begin_read (); auto & ledger = node.ledger; boost::property_tree::ptree accounts; - for (auto iterator = ledger.receivable_upper_bound (transaction, start, 0), end = ledger.receivable_end (); iterator != end && accounts.size () < count;) + for (auto iterator = ledger.any.receivable_upper_bound (transaction, start, 0), end = ledger.any.receivable_end (); iterator != end && accounts.size () < count;) { auto const & [key, info] = *iterator; nano::account account = key.account; @@ -4307,7 +4309,7 @@ void nano::json_handler::unopened () accounts.put (account.to_account (), current_account_sum.convert_to ()); } } - iterator = ledger.receivable_upper_bound (transaction, account); + iterator = ledger.any.receivable_upper_bound (transaction, account); } response_l.add_child ("accounts", accounts); } @@ -4420,12 +4422,11 @@ void nano::json_handler::wallet_info () uint64_t adhoc_count (0); auto transaction (node.wallets.tx_begin_read ()); auto block_transaction = node.ledger.tx_begin_read (); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); - auto account_info = node.ledger.account_info (block_transaction, account); + auto account_info = node.ledger.any.account_get (block_transaction, account); if (account_info) { block_count += account_info->block_count; @@ -4480,7 +4481,7 @@ void nano::json_handler::wallet_balances () for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); - nano::uint128_t balance = node.ledger.account_balance (block_transaction, account); + nano::uint128_t balance = node.ledger.any.account_balance (block_transaction, account).value_or (0).number (); if (balance >= threshold.number ()) { boost::property_tree::ptree entry; @@ -4631,7 +4632,7 @@ void nano::json_handler::wallet_frontiers () for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); - auto latest (node.ledger.latest (block_transaction, account)); + auto latest (node.ledger.any.account_head (block_transaction, account)); if (!latest.is_zero ()) { frontiers.put (account.to_account (), latest.to_string ()); @@ -4662,14 +4663,14 @@ void nano::json_handler::wallet_history () for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); - auto info = node.ledger.account_info (block_transaction, account); + auto info = node.ledger.any.account_get (block_transaction, account); if (info) { auto timestamp (info->modified); auto hash (info->head); while (timestamp >= modified_since && !hash.is_zero ()) { - auto block = node.ledger.block (block_transaction, hash); + auto block = node.ledger.any.block_get (block_transaction, hash); timestamp = block->sideband ().timestamp; if (block != nullptr && timestamp >= modified_since) { @@ -4736,7 +4737,7 @@ void nano::json_handler::wallet_ledger () for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); - auto info = node.ledger.account_info (block_transaction, account); + auto info = node.ledger.any.account_get (block_transaction, account); if (info) { if (info->modified >= modified_since) @@ -4813,10 +4814,10 @@ void nano::json_handler::wallet_receivable () { nano::account const & account (i->first); boost::property_tree::ptree peers_l; - for (auto current = node.ledger.receivable_upper_bound (block_transaction, account, 0), end = node.ledger.receivable_end (); current != end && (peers_l.size () < count); ++current) + for (auto current = node.ledger.any.receivable_upper_bound (block_transaction, account, 0), end = node.ledger.any.receivable_end (); current != end && (peers_l.size () < count); ++current) { auto const & [key, info] = *current; - if (include_only_confirmed && !node.ledger.block_confirmed (block_transaction, key.hash)) + if (include_only_confirmed && !node.ledger.confirmed.block_exists_or_pruned (block_transaction, key.hash)) { continue; } @@ -4902,7 +4903,7 @@ void nano::json_handler::wallet_representative_set () for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); - auto info = rpc_l->node.ledger.account_info (block_transaction, account); + auto info = rpc_l->node.ledger.any.account_get (block_transaction, account); if (info) { if (info->representative != representative) @@ -4936,13 +4937,13 @@ void nano::json_handler::wallet_republish () for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) { nano::account const & account (i->first); - auto latest (node.ledger.latest (block_transaction, account)); + auto latest (node.ledger.any.account_head (block_transaction, account)); std::shared_ptr block; std::vector hashes; while (!latest.is_zero () && hashes.size () < count) { hashes.push_back (latest); - block = node.ledger.block (block_transaction, latest); + block = node.ledger.any.block_get (block_transaction, latest); if (block != nullptr) { latest = block->previous (); @@ -4955,7 +4956,7 @@ void nano::json_handler::wallet_republish () std::reverse (hashes.begin (), hashes.end ()); for (auto & hash : hashes) { - block = node.ledger.block (block_transaction, hash); + block = node.ledger.any.block_get (block_transaction, hash); republish_bundle.push_back (std::move (block)); boost::property_tree::ptree entry; entry.put ("", hash.to_string ()); @@ -5103,9 +5104,9 @@ void nano::json_handler::work_generate () { // Fetch account from block if not given auto transaction_l = node.ledger.tx_begin_read (); - if (node.ledger.block_exists (transaction_l, hash)) + if (node.ledger.any.block_exists (transaction_l, hash)) { - account = node.ledger.account (transaction_l, hash).value (); + account = node.ledger.any.block_account (transaction_l, hash).value (); } } auto secondary_work_peers_l (request.get ("secondary_work_peers", false)); @@ -5466,14 +5467,14 @@ bool block_confirmed (nano::node & node, nano::secure::transaction & transaction is_confirmed = true; } // Check whether the confirmation height is set - else if (node.ledger.block_confirmed (transaction, hash)) + else if (node.ledger.confirmed.block_exists_or_pruned (transaction, hash)) { is_confirmed = true; } // This just checks it's not currently undergoing an active transaction else if (!include_only_confirmed) { - auto block = node.ledger.block (transaction, hash); + auto block = node.ledger.any.block_get (transaction, hash); is_confirmed = (block != nullptr && !node.active.active (*block)); } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index a15d7e03eb..a815235254 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include @@ -219,9 +221,9 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy return ledger.weight (rep); }; - backlog.activate_callback.add ([this] (secure::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) { + backlog.activate_callback.add ([this] (secure::transaction const & transaction, nano::account const & account) { scheduler.priority.activate (account, transaction); - scheduler.optimistic.activate (account, account_info, conf_info); + scheduler.optimistic.activate (transaction, account); }); active.vote_processed.add ([this] (std::shared_ptr const & vote, nano::vote_source source, std::unordered_map const & results) { @@ -400,7 +402,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy store.initialize (transaction, ledger.cache, ledger.constants); } - if (!ledger.block_or_pruned_exists (config.network_params.ledger.genesis->hash ())) + if (!block_or_pruned_exists (config.network_params.ledger.genesis->hash ())) { logger.critical (nano::log::type::node, "Genesis block not found. This commonly indicates a configuration issue, check that the --network or --data_path command line arguments are correct, and also the ledger backend node config option. If using a read-only CLI command a ledger must already exist, start the node with --daemon first."); @@ -769,24 +771,29 @@ void nano::node::keepalive_preconfigured () nano::block_hash nano::node::latest (nano::account const & account_a) { - return ledger.latest (ledger.tx_begin_read (), account_a); + return ledger.any.account_head (ledger.tx_begin_read (), account_a); } nano::uint128_t nano::node::balance (nano::account const & account_a) { - return ledger.account_balance (ledger.tx_begin_read (), account_a); + return ledger.any.account_balance (ledger.tx_begin_read (), account_a).value_or (0).number (); } std::shared_ptr nano::node::block (nano::block_hash const & hash_a) { - return ledger.block (ledger.tx_begin_read (), hash_a); + return ledger.any.block_get (ledger.tx_begin_read (), hash_a); +} + +bool nano::node::block_or_pruned_exists (nano::block_hash const & hash_a) const +{ + return ledger.any.block_exists_or_pruned (ledger.tx_begin_read (), hash_a); } std::pair nano::node::balance_pending (nano::account const & account_a, bool only_confirmed_a) { std::pair result; auto const transaction = ledger.tx_begin_read (); - result.first = ledger.account_balance (transaction, account_a, only_confirmed_a); + result.first = only_confirmed_a ? ledger.confirmed.account_balance (transaction, account_a).value_or (0).number () : ledger.any.account_balance (transaction, account_a).value_or (0).number (); result.second = ledger.account_receivable (transaction, account_a, only_confirmed_a); return result; } @@ -948,7 +955,7 @@ bool nano::node::collect_ledger_pruning_targets (std::deque & uint64_t depth (0); while (!hash.is_zero () && depth < max_depth_a) { - auto block = ledger.block (transaction, hash); + auto block = ledger.any.block_get (transaction, hash); if (block != nullptr) { if (block->sideband ().timestamp > cutoff_time_a || depth == 0) @@ -1177,12 +1184,12 @@ void nano::node::start_election (std::shared_ptr const & block) bool nano::node::block_confirmed (nano::block_hash const & hash_a) { - return ledger.block_confirmed (ledger.tx_begin_read (), hash_a); + return ledger.confirmed.block_exists_or_pruned (ledger.tx_begin_read (), hash_a); } bool nano::node::block_confirmed_or_being_confirmed (nano::secure::transaction const & transaction, nano::block_hash const & hash_a) { - return confirming_set.exists (hash_a) || ledger.block_confirmed (transaction, hash_a); + return confirming_set.exists (hash_a) || ledger.confirmed.block_exists_or_pruned (transaction, hash_a); } bool nano::node::block_confirmed_or_being_confirmed (nano::block_hash const & hash_a) @@ -1216,7 +1223,7 @@ void nano::node::process_confirmed (nano::election_status const & status_a, uint { auto hash (status_a.winner->hash ()); decltype (iteration_a) const num_iters = (config.block_processor_batch_max_time / network_params.node.process_confirmed_interval) * 4; - if (auto block_l = ledger.block (ledger.tx_begin_read (), hash)) + if (auto block_l = ledger.any.block_get (ledger.tx_begin_read (), hash)) { logger.trace (nano::log::type::node, nano::log::detail::process_confirmed, nano::log::arg{ "block", block_l }); @@ -1295,14 +1302,6 @@ void nano::node::bootstrap_block (const nano::block_hash & hash) } } -/** Convenience function to easily return the confirmation height of an account. */ -uint64_t nano::node::get_confirmation_height (store::transaction const & transaction_a, nano::account & account_a) -{ - nano::confirmation_height_info info; - store.confirmation_height.get (transaction_a, account_a, info); - return info.height; -} - nano::account nano::node::get_node_id () const { return node_id.pub; diff --git a/nano/node/node.hpp b/nano/node/node.hpp index ea8d801956..be4941bba2 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -94,6 +94,7 @@ class node final : public std::enable_shared_from_this void process_local_async (std::shared_ptr const &); void keepalive_preconfigured (); std::shared_ptr block (nano::block_hash const &); + bool block_or_pruned_exists (nano::block_hash const &) const; std::pair balance_pending (nano::account const &, bool only_confirmed); nano::uint128_t weight (nano::account const &); nano::uint128_t minimum_principal_weight (); @@ -126,7 +127,6 @@ class node final : public std::enable_shared_from_this bool online () const; bool init_error () const; std::pair> get_bootstrap_weights () const; - uint64_t get_confirmation_height (store::transaction const &, nano::account &); /* * Attempts to bootstrap block. This is the best effort, there is no guarantee that the block will be bootstrapped. */ diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index 698c1a244d..87097c38f5 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include nano::request_aggregator::request_aggregator (nano::node_config const & config_a, nano::stats & stats_a, nano::vote_generator & generator_a, nano::vote_generator & final_generator_a, nano::local_vote_history & history_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::active_transactions & active_a) : @@ -214,12 +215,12 @@ std::pair>, std::vector 1) { to_generate_final.push_back (block); - block = ledger.block (transaction, final_vote_hashes[1]); + block = ledger.any.block_get (transaction, final_vote_hashes[1]); debug_assert (final_vote_hashes.size () == 2); } } @@ -233,7 +234,7 @@ std::pair>, std::vector>, std::vector #include #include +#include /* * hinted @@ -84,7 +85,7 @@ void nano::scheduler::hinted::activate (secure::read_transaction const & transac stack.pop (); // Check if block exists - if (auto block = node.ledger.block (transaction, current_hash); block) + if (auto block = node.ledger.any.block_get (transaction, current_hash); block) { // Ensure block is not already confirmed if (node.block_confirmed_or_being_confirmed (transaction, current_hash)) diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index 7714dce73d..e72dec0ac2 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include nano::scheduler::optimistic::optimistic (optimistic_config const & config_a, nano::node & node_a, nano::ledger & ledger_a, nano::active_transactions & active_a, nano::network_constants const & network_constants_a, nano::stats & stats_a) : config{ config_a }, @@ -53,30 +55,31 @@ void nano::scheduler::optimistic::notify () condition.notify_all (); } -bool nano::scheduler::optimistic::activate_predicate (const nano::account_info & account_info, const nano::confirmation_height_info & conf_info) const +bool nano::scheduler::optimistic::activate_predicate (nano::secure::transaction const & transaction, nano::account const & account) const { - // Chain with a big enough gap between account frontier and confirmation frontier - if (account_info.block_count - conf_info.height > config.gap_threshold) + auto unconfirmed_height = ledger.any.account_height (transaction, account); + auto confirmed_height = ledger.confirmed.account_height (transaction, account); + // Account with nothing confirmed yet + if (confirmed_height == 0) { return true; } - // Account with nothing confirmed yet - if (conf_info.height == 0) + // Chain with a big enough gap between account frontier and confirmation frontier + if (unconfirmed_height - confirmed_height > config.gap_threshold) { return true; } return false; } -bool nano::scheduler::optimistic::activate (const nano::account & account, const nano::account_info & account_info, const nano::confirmation_height_info & conf_info) +bool nano::scheduler::optimistic::activate (nano::secure::transaction const & transaction, nano::account const & account) { if (!config.enabled) { return false; } - debug_assert (account_info.block_count >= conf_info.height); - if (activate_predicate (account_info, conf_info)) + if (activate_predicate (transaction, account)) { { nano::lock_guard lock{ mutex }; @@ -151,7 +154,7 @@ void nano::scheduler::optimistic::run () void nano::scheduler::optimistic::run_one (secure::transaction const & transaction, entry const & candidate) { - auto block = ledger.head_block (transaction, candidate.account); + auto block = ledger.any.block_get (transaction, ledger.any.account_head (transaction, candidate.account)); if (block) { // Ensure block is not already confirmed diff --git a/nano/node/scheduler/optimistic.hpp b/nano/node/scheduler/optimistic.hpp index f7093f23cd..58531ddb4a 100644 --- a/nano/node/scheduler/optimistic.hpp +++ b/nano/node/scheduler/optimistic.hpp @@ -60,7 +60,7 @@ class optimistic final /** * Called from backlog population to process accounts with unconfirmed blocks */ - bool activate (nano::account const &, nano::account_info const &, nano::confirmation_height_info const &); + bool activate (nano::secure::transaction const & transaction, nano::account const & account); /** * Notify about changes in AEC vacancy @@ -70,7 +70,7 @@ class optimistic final std::unique_ptr collect_container_info (std::string const & name) const; private: - bool activate_predicate (nano::account_info const &, nano::confirmation_height_info const &) const; + bool activate_predicate (nano::secure::transaction const & transaction, nano::account const & account) const; bool predicate () const; void run (); diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index c83a209bdf..d35fb7b105 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include nano::scheduler::priority::priority (nano::node & node_a, nano::stats & stats_a) : node{ node_a }, @@ -39,42 +41,34 @@ void nano::scheduler::priority::stop () nano::join_or_pass (thread); } -bool nano::scheduler::priority::activate (nano::account const & account_a, secure::transaction const & transaction) +bool nano::scheduler::priority::activate (nano::account const & account, secure::transaction const & transaction) { - debug_assert (!account_a.is_zero ()); - auto info = node.ledger.account_info (transaction, account_a); - if (info) + debug_assert (!account.is_zero ()); + auto head = node.ledger.confirmed.account_head (transaction, account); + if (node.ledger.any.account_head (transaction, account) == head) { - nano::confirmation_height_info conf_info; - node.store.confirmation_height.get (transaction, account_a, conf_info); - if (conf_info.height < info->block_count) - { - debug_assert (conf_info.frontier != info->head); - auto hash = conf_info.height == 0 ? info->open_block : node.ledger.successor (transaction, conf_info.frontier).value_or (0); - auto block = node.ledger.block (transaction, hash); - debug_assert (block != nullptr); - if (node.ledger.dependents_confirmed (transaction, *block)) - { - auto const balance = node.ledger.balance (transaction, hash).value (); - auto const previous_balance = node.ledger.balance (transaction, conf_info.frontier).value_or (0); - auto const balance_priority = std::max (balance, previous_balance); - - node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated); - node.logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated, - nano::log::arg{ "account", account_a.to_account () }, // TODO: Convert to lazy eval - nano::log::arg{ "block", block }, - nano::log::arg{ "time", info->modified }, - nano::log::arg{ "priority", balance_priority }); - - nano::lock_guard lock{ mutex }; - buckets->push (info->modified, block, balance_priority); - notify (); - - return true; // Activated - } - } + return false; + } + auto block = node.ledger.any.block_get (transaction, node.ledger.any.block_successor (transaction, { head.is_zero () ? static_cast (account) : head, head }).value ()); + if (!node.ledger.dependents_confirmed (transaction, *block)) + { + return false; } - return false; // Not activated + auto const balance_priority = std::max (block->balance ().number (), node.ledger.confirmed.block_balance (transaction, head).value_or (0).number ()); + auto const time_priority = !head.is_zero () ? node.ledger.confirmed.block_get (transaction, head)->sideband ().timestamp : nano::seconds_since_epoch (); // New accounts get current timestamp i.e. lowest priority + + node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated); + node.logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated, + nano::log::arg{ "account", account.to_account () }, // TODO: Convert to lazy eval + nano::log::arg{ "block", block }, + nano::log::arg{ "time", time_priority }, + nano::log::arg{ "priority", balance_priority }); + + nano::lock_guard lock{ mutex }; + buckets->push (time_priority, block, balance_priority); + notify (); + + return true; // Activated } void nano::scheduler::priority::notify () diff --git a/nano/node/vote_generator.cpp b/nano/node/vote_generator.cpp index bcaf7cd37f..df1fec32b7 100644 --- a/nano/node/vote_generator.cpp +++ b/nano/node/vote_generator.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ nano::vote_generator::~vote_generator () bool nano::vote_generator::should_vote (secure::write_transaction const & transaction, nano::root const & root_a, nano::block_hash const & hash_a) { - auto block = ledger.block (transaction, hash_a); + auto block = ledger.any.block_get (transaction, hash_a); bool should_vote = false; if (is_final) { diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 96d5b1e993..e8fc2473c8 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -843,9 +845,9 @@ std::shared_ptr nano::wallet::receive_action (nano::block_hash cons { auto block_transaction = wallets.node.ledger.tx_begin_read (); auto transaction (wallets.tx_begin_read ()); - if (wallets.node.ledger.block_or_pruned_exists (block_transaction, send_hash_a)) + if (wallets.node.ledger.any.block_exists_or_pruned (block_transaction, send_hash_a)) { - auto pending_info = wallets.node.ledger.pending_info (block_transaction, nano::pending_key (account_a, send_hash_a)); + auto pending_info = wallets.node.ledger.any.pending_get (block_transaction, nano::pending_key (account_a, send_hash_a)); if (pending_info) { nano::raw_key prv; @@ -855,7 +857,7 @@ std::shared_ptr nano::wallet::receive_action (nano::block_hash cons { store.work_get (transaction, account_a, work_a); } - auto info = wallets.node.ledger.account_info (block_transaction, account_a); + auto info = wallets.node.ledger.any.account_get (block_transaction, account_a); if (info) { block = std::make_shared (account_a, info->head, info->representative, info->balance.number () + pending_info->amount.number (), send_hash_a, prv, account_a, work_a); @@ -908,9 +910,9 @@ std::shared_ptr nano::wallet::change_action (nano::account const & if (store.valid_password (transaction)) { auto existing (store.find (transaction, source_a)); - if (existing != store.end () && !wallets.node.ledger.latest (block_transaction, source_a).is_zero ()) + if (existing != store.end () && !wallets.node.ledger.any.account_head (block_transaction, source_a).is_zero ()) { - auto info = wallets.node.ledger.account_info (block_transaction, source_a); + auto info = wallets.node.ledger.any.account_get (block_transaction, source_a); debug_assert (info); nano::raw_key prv; auto error2 (store.fetch (transaction, source_a, prv)); @@ -958,7 +960,7 @@ std::shared_ptr nano::wallet::send_action (nano::account const & so if (status == 0) { nano::block_hash hash (result); - block = wallets.node.ledger.block (block_transaction, hash); + block = wallets.node.ledger.any.block_get (block_transaction, hash); if (block != nullptr) { cached_block = true; @@ -977,10 +979,10 @@ std::shared_ptr nano::wallet::send_action (nano::account const & so auto existing (store.find (transaction, source_a)); if (existing != store.end ()) { - auto balance (wallets.node.ledger.account_balance (block_transaction, source_a)); - if (!balance.is_zero () && balance >= amount_a) + auto balance (wallets.node.ledger.any.account_balance (block_transaction, source_a)); + if (balance && balance.value ().number () >= amount_a) { - auto info = wallets.node.ledger.account_info (block_transaction, source_a); + auto info = wallets.node.ledger.any.account_get (block_transaction, source_a); debug_assert (info); nano::raw_key prv; auto error2 (store.fetch (transaction, source_a, prv)); @@ -990,7 +992,7 @@ std::shared_ptr nano::wallet::send_action (nano::account const & so { store.work_get (transaction, source_a, work_a); } - block = std::make_shared (source_a, info->head, info->representative, balance - amount_a, account_a, prv, source_a, work_a); + block = std::make_shared (source_a, info->head, info->representative, balance.value ().number () - amount_a, account_a, prv, source_a, work_a); details.epoch = info->epoch (); if (id_mdb_val && block != nullptr) { @@ -1183,7 +1185,7 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact // Don't search pending for watch-only accounts if (!nano::wallet_value (i->second).key.is_zero ()) { - for (auto i = wallets.node.ledger.receivable_upper_bound (block_transaction, account, 0), n = wallets.node.ledger.receivable_end (); i != n; ++i) + for (auto i = wallets.node.ledger.any.receivable_upper_bound (block_transaction, account, 0), n = wallets.node.ledger.any.receivable_end (); i != n; ++i) { auto const & [key, info] = *i; auto hash = key.hash; @@ -1192,7 +1194,7 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact { wallets.node.logger.info (nano::log::type::wallet, "Found a receivable block {} for account {}", hash.to_string (), info.source.to_account ()); - if (wallets.node.ledger.block_confirmed (block_transaction, hash)) + if (wallets.node.ledger.confirmed.block_exists_or_pruned (block_transaction, hash)) { auto representative = store.representative (wallet_transaction_a); // Receive confirmed block @@ -1200,7 +1202,7 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact } else if (!wallets.node.confirming_set.exists (hash)) { - auto block = wallets.node.ledger.block (block_transaction, hash); + auto block = wallets.node.ledger.any.block_get (block_transaction, hash); if (block) { // Request confirmation for block which is not being processed yet @@ -1238,7 +1240,7 @@ uint32_t nano::wallet::deterministic_check (store::transaction const & transacti auto prv = store.deterministic_key (transaction_a, i); nano::keypair pair (prv.to_string ()); // Check if account received at least 1 block - auto latest (wallets.node.ledger.latest (block_transaction, pair.pub)); + auto latest (wallets.node.ledger.any.account_head (block_transaction, pair.pub)); if (!latest.is_zero ()) { index = i; @@ -1249,8 +1251,8 @@ uint32_t nano::wallet::deterministic_check (store::transaction const & transacti else { // Check if there are pending blocks for account - auto current = wallets.node.ledger.receivable_upper_bound (block_transaction, pair.pub, 0); - if (current != wallets.node.ledger.receivable_end ()) + auto current = wallets.node.ledger.any.receivable_upper_bound (block_transaction, pair.pub, 0); + if (current != wallets.node.ledger.any.receivable_end ()) { index = i; n = i + 64 + (i / 64); @@ -1719,7 +1721,7 @@ void nano::wallets::receive_confirmed (nano::block_hash const & hash_a, nano::ac { nano::account representative; representative = wallet->store.representative (wallet_transaction); - auto pending = node.ledger.pending_info (node.ledger.tx_begin_read (), nano::pending_key (destination_a, hash_a)); + auto pending = node.ledger.any.pending_get (node.ledger.tx_begin_read (), nano::pending_key (destination_a, hash_a)); if (pending) { auto amount (pending->amount.number ()); @@ -1727,7 +1729,7 @@ void nano::wallets::receive_confirmed (nano::block_hash const & hash_a, nano::ac } else { - if (!node.ledger.block_or_pruned_exists (node.ledger.tx_begin_read (), hash_a)) + if (!node.ledger.confirmed.block_exists_or_pruned (node.ledger.tx_begin_read (), hash_a)) { node.logger.warn (nano::log::type::wallet, "Confirmed block is missing: {}", hash_a.to_string ()); debug_assert (false, "Confirmed block is missing"); diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 07b5963baf..176875d3af 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -269,7 +270,7 @@ void nano_qt::accounts::refresh_wallet_balance () for (auto i (this->wallet.wallet_m->store.begin (transaction)), j (this->wallet.wallet_m->store.end ()); i != j; ++i) { nano::public_key const & key (i->first); - balance = balance + (this->wallet.node.ledger.account_balance (block_transaction, key)); + balance = balance + this->wallet.node.ledger.any.account_balance (block_transaction, key).value_or (0).number (); pending = pending + (this->wallet.node.ledger.account_receivable (block_transaction, key)); } auto final_text (std::string ("Balance: ") + wallet.format_balance (balance)); @@ -294,7 +295,7 @@ void nano_qt::accounts::refresh () for (auto i (wallet.wallet_m->store.begin (transaction)), j (wallet.wallet_m->store.end ()); i != j; ++i) { nano::public_key key (i->first); - auto balance_amount (wallet.node.ledger.account_balance (block_transaction, key)); + auto balance_amount = wallet.node.ledger.any.account_balance (block_transaction, key).value_or (0).number (); bool display (true); switch (wallet.wallet_m->store.key_type (i->second)) { @@ -525,21 +526,21 @@ class short_text_visitor : public nano::block_visitor { type = "Send"; account = block_a.hashables.destination; - auto amount_l = ledger.amount (transaction, block_a.hash ()); + auto amount_l = ledger.any.block_amount (transaction, block_a.hash ()); if (!amount_l) { type = "Send (pruned)"; } else { - amount = amount_l.value (); + amount = amount_l.value ().number (); } } void receive_block (nano::receive_block const & block_a) { type = "Receive"; - auto account_l = ledger.account (transaction, block_a.hashables.source); - auto amount_l = ledger.amount (transaction, block_a.hash ()); + auto account_l = ledger.any.block_account (transaction, block_a.hashables.source); + auto amount_l = ledger.any.block_amount (transaction, block_a.hash ()); if (!account_l || !amount_l) { type = "Receive (pruned)"; @@ -547,7 +548,7 @@ class short_text_visitor : public nano::block_visitor else { account = account_l.value (); - amount = amount_l.value (); + amount = amount_l.value ().number (); } } void open_block (nano::open_block const & block_a) @@ -555,8 +556,8 @@ class short_text_visitor : public nano::block_visitor type = "Receive"; if (block_a.hashables.source != ledger.constants.genesis->account ()) { - auto account_l = ledger.account (transaction, block_a.hashables.source); - auto amount_l = ledger.amount (transaction, block_a.hash ()); + auto account_l = ledger.any.block_account (transaction, block_a.hashables.source); + auto amount_l = ledger.any.block_amount (transaction, block_a.hash ()); if (!account_l || !amount_l) { type = "Receive (pruned)"; @@ -564,7 +565,7 @@ class short_text_visitor : public nano::block_visitor else { account = account_l.value (); - amount = amount_l.value (); + amount = amount_l.value ().number (); } } else @@ -582,17 +583,17 @@ class short_text_visitor : public nano::block_visitor void state_block (nano::state_block const & block_a) { auto balance (block_a.hashables.balance.number ()); - auto previous_balance = ledger.balance (transaction, block_a.hashables.previous); + auto previous_balance = ledger.any.block_balance (transaction, block_a.hashables.previous); if (!previous_balance) { type = "Unknown (pruned)"; amount = 0; account = block_a.hashables.account; } - else if (balance < previous_balance) + else if (balance < previous_balance.value ().number ()) { type = "Send"; - amount = previous_balance.value () - balance; + amount = previous_balance.value ().number () - balance; account = block_a.hashables.link.as_account (); } else @@ -610,7 +611,7 @@ class short_text_visitor : public nano::block_visitor else { type = "Receive"; - auto account_l = ledger.account (transaction, block_a.hashables.link.as_block_hash ()); + auto account_l = ledger.any.block_account (transaction, block_a.hashables.link.as_block_hash ()); if (!account_l) { type = "Receive (pruned)"; @@ -620,7 +621,7 @@ class short_text_visitor : public nano::block_visitor account = account_l.value (); } } - amount = balance - previous_balance.value (); + amount = balance - previous_balance.value ().number (); } } nano::secure::transaction const & transaction; @@ -635,12 +636,12 @@ void nano_qt::history::refresh () { auto transaction = ledger.tx_begin_read (); model->removeRows (0, model->rowCount ()); - auto hash (ledger.latest (transaction, account)); + auto hash (ledger.any.account_head (transaction, account)); short_text_visitor visitor (transaction, ledger); for (auto i (0), n (tx_count->value ()); i < n && !hash.is_zero (); ++i) { QList items; - auto block (ledger.block (transaction, hash)); + auto block (ledger.any.block_get (transaction, hash)); if (block != nullptr) { block->visit (visitor); @@ -689,13 +690,13 @@ nano_qt::block_viewer::block_viewer (nano_qt::wallet & wallet_a) : if (!hash_l.decode_hex (hash->text ().toStdString ())) { auto transaction = this->wallet.node.ledger.tx_begin_read (); - auto block_l (this->wallet.node.ledger.block (transaction, hash_l)); + auto block_l (this->wallet.node.ledger.any.block_get (transaction, hash_l)); if (block_l != nullptr) { std::string contents; block_l->serialize_json (contents); block->setPlainText (contents.c_str ()); - auto successor_l = this->wallet.node.ledger.successor (transaction, hash_l).value_or (0); + auto successor_l = this->wallet.node.ledger.any.block_successor (transaction, hash_l).value_or (0); successor->setText (successor_l.to_string ().c_str ()); } else @@ -714,7 +715,7 @@ nano_qt::block_viewer::block_viewer (nano_qt::wallet & wallet_a) : if (!error) { auto transaction = this->wallet.node.ledger.tx_begin_read (); - if (this->wallet.node.ledger.block_exists (transaction, block)) + if (this->wallet.node.ledger.any.block_exists (transaction, block)) { rebroadcast->setEnabled (false); this->wallet.node.background ([this, block] () { @@ -735,11 +736,11 @@ void nano_qt::block_viewer::rebroadcast_action (nano::block_hash const & hash_a) { auto done (true); auto transaction = wallet.node.ledger.tx_begin_read (); - auto block (wallet.node.ledger.block (transaction, hash_a)); + auto block (wallet.node.ledger.any.block_get (transaction, hash_a)); if (block != nullptr) { wallet.node.network.flood_block (block); - auto successor = wallet.node.ledger.successor (transaction, hash_a); + auto successor = wallet.node.ledger.any.block_successor (transaction, hash_a); if (successor) { done = false; @@ -1970,8 +1971,8 @@ void nano_qt::advanced_actions::refresh_peers () void nano_qt::advanced_actions::refresh_ledger () { ledger_model->removeRows (0, ledger_model->rowCount ()); - auto transaction (wallet.node.store.tx_begin_read ()); - for (auto i (wallet.node.ledger.store.account.begin (transaction)), j (wallet.node.ledger.store.account.end ()); i != j; ++i) + auto transaction (wallet.node.ledger.tx_begin_read ()); + for (auto i (wallet.node.ledger.any.account_begin (transaction)), j (wallet.node.ledger.any.account_end ()); i != j; ++i) { QList items; items.push_back (new QStandardItem (QString (i->first.to_account ().c_str ()))); @@ -2244,7 +2245,7 @@ void nano_qt::block_creation::create_send () nano::raw_key key; if (!wallet.wallet_m->store.fetch (transaction, account_l, key)) { - auto balance (wallet.node.ledger.account_balance (block_transaction, account_l)); + auto balance = wallet.node.ledger.any.account_balance (block_transaction, account_l).value_or (0).number (); if (amount_l.number () <= balance) { nano::account_info info; @@ -2317,14 +2318,14 @@ void nano_qt::block_creation::create_receive () { auto transaction (wallet.node.wallets.tx_begin_read ()); auto block_transaction = wallet.node.ledger.tx_begin_read (); - auto block_l (wallet.node.ledger.block (block_transaction, source_l)); + auto block_l (wallet.node.ledger.any.block_get (block_transaction, source_l)); if (block_l != nullptr) { auto destination = block_l->destination (); if (!destination.is_zero ()) { nano::pending_key pending_key (destination, source_l); - if (auto pending = wallet.node.ledger.pending_info (block_transaction, pending_key)) + if (auto pending = wallet.node.ledger.any.pending_get (block_transaction, pending_key)) { nano::account_info info; auto error (wallet.node.store.account.get (block_transaction, pending_key.account, info)); @@ -2481,14 +2482,14 @@ void nano_qt::block_creation::create_open () { auto transaction (wallet.node.wallets.tx_begin_read ()); auto block_transaction = wallet.node.ledger.tx_begin_read (); - auto block_l (wallet.node.ledger.block (block_transaction, source_l)); + auto block_l (wallet.node.ledger.any.block_get (block_transaction, source_l)); if (block_l != nullptr) { auto destination = block_l->destination (); if (!destination.is_zero ()) { nano::pending_key pending_key (destination, source_l); - if (auto pending = wallet.node.ledger.pending_info (block_transaction, pending_key)) + if (auto pending = wallet.node.ledger.any.pending_get (block_transaction, pending_key)) { nano::account_info info; auto error (wallet.node.store.account.get (block_transaction, pending_key.account, info)); diff --git a/nano/qt_test/qt.cpp b/nano/qt_test/qt.cpp index e458eda32a..aafeda279d 100644 --- a/nano/qt_test/qt.cpp +++ b/nano/qt_test/qt.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -391,7 +392,7 @@ TEST (wallet, DISABLED_process_block) { auto transaction (system.nodes[0]->ledger.tx_begin_read ()); system.deadline_set (10s); - while (system.nodes[0]->ledger.block_exists (transaction, send.hash ())) + while (system.nodes[0]->ledger.any.block_exists (transaction, send.hash ())) { ASSERT_NO_ERROR (system.poll ()); } @@ -532,7 +533,7 @@ TEST (history, short_text) auto transaction (ledger.tx_begin_write ()); store->initialize (transaction, ledger.cache, ledger.constants); nano::keypair key; - auto latest (ledger.latest (transaction, nano::dev::genesis_key.pub)); + auto latest (ledger.any.account_head (transaction, nano::dev::genesis_key.pub)); auto send = std::make_shared (latest, nano::dev::genesis_key.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (latest)); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send)); auto receive = std::make_shared (send->hash (), send->hash (), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (send->hash ())); @@ -572,7 +573,7 @@ TEST (history, pruned_source) { auto transaction = ledger.tx_begin_write (); store->initialize (transaction, ledger.cache, nano::dev::constants); - auto latest (ledger.latest (transaction, nano::dev::genesis_key.pub)); + auto latest (ledger.any.account_head (transaction, nano::dev::genesis_key.pub)); auto send1 = std::make_shared (latest, nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - 100, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (latest)); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); auto send2 = std::make_shared (send1->hash (), key.pub, nano::dev::constants.genesis_amount - 200, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (send1->hash ())); @@ -604,10 +605,10 @@ TEST (history, pruned_source) // Pruning for state blocks. Previous block is pruned, source is pruned { auto transaction = ledger.tx_begin_write (); - auto latest (ledger.latest (transaction, nano::dev::genesis_key.pub)); + auto latest (ledger.any.account_head (transaction, nano::dev::genesis_key.pub)); auto send = std::make_shared (nano::dev::genesis_key.pub, latest, nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - 200, key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (latest)); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send)); - auto latest_key (ledger.latest (transaction, key.pub)); + auto latest_key (ledger.any.account_head (transaction, key.pub)); auto receive = std::make_shared (key.pub, latest_key, key.pub, 200, send->hash (), key.prv, key.pub, *system.work.generate (latest_key)); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive)); ledger.confirm (transaction, latest); @@ -721,7 +722,7 @@ TEST (wallet, republish) nano::block_hash hash; { auto transaction = system.nodes[0]->ledger.tx_begin_write (); - auto latest (system.nodes[0]->ledger.latest (transaction, nano::dev::genesis_key.pub)); + auto latest (system.nodes[0]->ledger.any.account_head (transaction, nano::dev::genesis_key.pub)); auto block = std::make_shared (latest, key.pub, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *system.work.generate (latest)); hash = block->hash (); ASSERT_EQ (nano::block_status::progress, system.nodes[0]->ledger.process (transaction, block)); @@ -921,7 +922,7 @@ TEST (wallet, DISABLED_synchronizing) wallet->start (); { auto transaction = system1.nodes[0]->ledger.tx_begin_write (); - auto latest (system1.nodes[0]->ledger.latest (transaction, nano::dev::genesis_key.pub)); + auto latest (system1.nodes[0]->ledger.any.account_head (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/rpc.cpp b/nano/rpc_test/rpc.cpp index f69ce1d36d..fd832bcd84 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -255,7 +257,7 @@ TEST (rpc, send) std::string block_text (response.get ("block")); nano::block_hash block; ASSERT_FALSE (block.decode_hex (block_text)); - ASSERT_TRUE (node->ledger.block_or_pruned_exists (block)); + ASSERT_TRUE (node->block_or_pruned_exists (block)); ASSERT_EQ (node->latest (nano::dev::genesis_key.pub), block); ASSERT_NE (node->balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount); } @@ -300,7 +302,7 @@ TEST (rpc, send_work) std::string block_text (response2.get ("block")); nano::block_hash block; ASSERT_FALSE (block.decode_hex (block_text)); - ASSERT_TRUE (node->ledger.block_or_pruned_exists (block)); + ASSERT_TRUE (node->block_or_pruned_exists (block)); ASSERT_EQ (node->latest (nano::dev::genesis_key.pub), block); } @@ -343,7 +345,7 @@ TEST (rpc, send_idempotent) std::string block_text (response.get ("block")); nano::block_hash block; ASSERT_FALSE (block.decode_hex (block_text)); - ASSERT_TRUE (node->ledger.block_or_pruned_exists (block)); + ASSERT_TRUE (node->block_or_pruned_exists (block)); ASSERT_EQ (node->balance (nano::dev::genesis_key.pub), nano::dev::constants.genesis_amount / 4); auto response2 (wait_response (system, rpc_ctx, request)); ASSERT_EQ ("", response2.get ("error", "")); @@ -556,7 +558,7 @@ TEST (rpc, wallet_representative_set_force) while (representative != key.pub) { auto transaction = node->ledger.tx_begin_read (); - auto info = node->ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info = node->ledger.any.account_get (transaction, nano::dev::genesis_key.pub); if (info) { representative = info->representative; @@ -2399,8 +2401,8 @@ TEST (rpc, account_representative_set) nano::keypair key2; wallet.insert_adhoc (key2.prv); 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->ledger.tx_begin_read (), key2_open_block_hash)); - auto key2_open_block = node->ledger.block (node->ledger.tx_begin_read (), key2_open_block_hash); + ASSERT_TIMELY (5s, node->ledger.confirmed.block_exists_or_pruned (node->ledger.tx_begin_read (), key2_open_block_hash)); + auto key2_open_block = node->ledger.any.block_get (node->ledger.tx_begin_read (), key2_open_block_hash); ASSERT_EQ (nano::dev::genesis_key.pub, key2_open_block->representative_field ().value ()); // now change the representative of key2 to be genesis @@ -2417,9 +2419,9 @@ TEST (rpc, account_representative_set) nano::block_hash hash; ASSERT_FALSE (hash.decode_hex (block_text1)); ASSERT_FALSE (hash.is_zero ()); - auto block = node->ledger.block (node->ledger.tx_begin_read (), hash); + auto block = node->ledger.any.block_get (node->ledger.tx_begin_read (), hash); ASSERT_NE (block, nullptr); - ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), hash)); + ASSERT_TIMELY (5s, node->ledger.confirmed.block_exists_or_pruned (node->ledger.tx_begin_read (), hash)); ASSERT_EQ (key2.pub, block->representative_field ().value ()); } @@ -2457,7 +2459,7 @@ TEST (rpc, account_representative_set_epoch_2_insufficient_work) node->scheduler.priority.activate (nano::dev::genesis_key.pub, node->ledger.tx_begin_read ()); // wait for the epoch blocks to be cemented - ASSERT_TIMELY_EQ (5s, node->get_confirmation_height (node->store.tx_begin_read (), nano::dev::genesis_key.pub), 3); + ASSERT_TIMELY_EQ (5s, node->ledger.confirmed.account_height (node->ledger.tx_begin_read (), nano::dev::genesis_key.pub), 3); auto target_difficulty = nano::dev::network_params.work.threshold (nano::work_version::work_1, nano::block_details (nano::epoch::epoch_2, false, false, false)); ASSERT_LT (node->network_params.work.entry, target_difficulty); @@ -2473,7 +2475,7 @@ TEST (rpc, account_representative_set_epoch_2_insufficient_work) request.put ("representative", nano::keypair ().pub.to_account ()); // Test that the correct error is given if there is insufficient work - auto latest = node->ledger.latest (node->ledger.tx_begin_read (), nano::dev::genesis_key.pub); + auto latest = node->ledger.any.account_head (node->ledger.tx_begin_read (), nano::dev::genesis_key.pub); auto insufficient = system.work_generate_limited (latest, min_difficulty, target_difficulty); request.put ("work", nano::to_string_hex (insufficient)); { @@ -3313,7 +3315,7 @@ TEST (rpc, pending_exists) request.put ("hash", hash0.to_string ()); ASSERT_TRUE (pending_exists ("0")); - node->ledger.pending_info (node->ledger.tx_begin_read (), nano::pending_key{ nano::dev::genesis_key.pub, block1->hash () }); + node->ledger.any.pending_get (node->ledger.tx_begin_read (), nano::pending_key{ nano::dev::genesis_key.pub, block1->hash () }); request.put ("hash", block1->hash ().to_string ()); ASSERT_TRUE (pending_exists ("1")); @@ -3332,7 +3334,7 @@ TEST (rpc, wallet_pending) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); system.wallet (0)->insert_adhoc (key1.prv); auto block1 = system.wallet (0)->send_action (nano::dev::genesis_key.pub, key1.pub, 100); - ASSERT_TIMELY_EQ (5s, node->get_confirmation_height (node->store.tx_begin_read (), nano::dev::genesis_key.pub), 2); + ASSERT_TIMELY_EQ (5s, node->ledger.confirmed.account_height (node->ledger.tx_begin_read (), nano::dev::genesis_key.pub), 2); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "wallet_pending"); @@ -4142,7 +4144,7 @@ TEST (rpc, blocks_info_receive_hash) }; ASSERT_TIMELY (5s, all_blocks_cemented ()); - ASSERT_EQ (node->ledger.account_balance (node->ledger.tx_begin_read (), key1.pub, true), 10); + ASSERT_EQ (node->ledger.confirmed.account_balance (node->ledger.tx_begin_read (), key1.pub), 10); // create the RPC request boost::property_tree::ptree request; @@ -4293,7 +4295,7 @@ TEST (rpc, block_info_pruning) { auto transaction = node1->ledger.tx_begin_write (); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 1)); - ASSERT_TRUE (node1->ledger.block_exists (transaction, receive1->hash ())); + ASSERT_TRUE (node1->ledger.any.block_exists (transaction, receive1->hash ())); } auto const rpc_ctx = add_rpc (system, node1); // Pruned block @@ -4359,7 +4361,7 @@ TEST (rpc, pruned_exists) { auto transaction = node1->ledger.tx_begin_write (); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 1)); - ASSERT_TRUE (node1->ledger.block_exists (transaction, receive1->hash ())); + ASSERT_TRUE (node1->ledger.any.block_exists (transaction, receive1->hash ())); } auto const rpc_ctx = add_rpc (system, node1); // Pruned block @@ -5312,7 +5314,7 @@ TEST (rpc, block_confirm_confirmed) auto node = add_ipc_enabled_node (system, config); { auto transaction = node->ledger.tx_begin_read (); - ASSERT_TRUE (node->ledger.block_confirmed (transaction, nano::dev::genesis->hash ())); + ASSERT_TRUE (node->ledger.confirmed.block_exists_or_pruned (transaction, nano::dev::genesis->hash ())); } ASSERT_EQ (0, node->stats.count (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out)); auto const rpc_ctx = add_rpc (system, node); @@ -5771,7 +5773,7 @@ TEST (rpc, block_confirmed) // Open an account directly in the ledger { auto transaction = node->ledger.tx_begin_write (); - nano::block_hash latest (node->ledger.latest (transaction, nano::dev::genesis_key.pub)); + nano::block_hash latest (node->ledger.any.account_head (transaction, nano::dev::genesis_key.pub)); auto send1 = builder .send () .previous (latest) @@ -5812,7 +5814,7 @@ TEST (rpc, block_confirmed) ASSERT_TRUE (nano::test::start_elections (system, *node, { send }, true)); // Wait until the confirmation height has been set - ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), send->hash ()) && !node->confirming_set.exists (send->hash ())); + ASSERT_TIMELY (5s, node->ledger.confirmed.block_exists_or_pruned (node->ledger.tx_begin_read (), send->hash ()) && !node->confirming_set.exists (send->hash ())); // Requesting confirmation for this should now succeed request.put ("hash", send->hash ().to_string ()); @@ -6119,9 +6121,9 @@ TEST (rpc, epoch_upgrade) ASSERT_EQ (nano::block_status::progress, node->process (open)); // Check accounts epochs { - auto transaction (node->store.tx_begin_read ()); + auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (2, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->ledger.any.account_begin (transaction)); i != node->ledger.any.account_end (); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_0); @@ -6137,9 +6139,9 @@ TEST (rpc, epoch_upgrade) ASSERT_TIMELY_EQ (10s, 4, node->store.account.count (node->store.tx_begin_read ())); // Check upgrade { - auto transaction (node->store.tx_begin_read ()); + auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (4, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->ledger.any.account_begin (transaction)); i != node->ledger.any.account_end (); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_1); @@ -6189,7 +6191,7 @@ TEST (rpc, epoch_upgrade) { // Check pending entry auto transaction = node->ledger.tx_begin_read (); - auto info = node->ledger.pending_info (transaction, nano::pending_key (key3.pub, send7->hash ())); + auto info = node->ledger.any.pending_get (transaction, nano::pending_key (key3.pub, send7->hash ())); ASSERT_TRUE (info); ASSERT_EQ (nano::epoch::epoch_1, info->epoch); } @@ -6200,9 +6202,9 @@ TEST (rpc, epoch_upgrade) ASSERT_TIMELY_EQ (10s, 5, node->store.account.count (node->store.tx_begin_read ())); // Check upgrade { - auto transaction (node->store.tx_begin_read ()); + auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (5, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->ledger.any.account_begin (transaction)); i != node->ledger.any.account_end (); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_2); @@ -6282,9 +6284,9 @@ TEST (rpc, epoch_upgrade_multithreaded) ASSERT_EQ (nano::block_status::progress, node->process (open)); // Check accounts epochs { - auto transaction (node->store.tx_begin_read ()); + auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (2, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->ledger.any.account_begin (transaction)); i != node->ledger.any.account_end (); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_0); @@ -6301,9 +6303,9 @@ TEST (rpc, epoch_upgrade_multithreaded) ASSERT_TIMELY_EQ (5s, 4, node->store.account.count (node->store.tx_begin_read ())); // Check upgrade { - auto transaction (node->store.tx_begin_read ()); + auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (4, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->ledger.any.account_begin (transaction)); i != node->ledger.any.account_end (); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_1); @@ -6353,7 +6355,7 @@ TEST (rpc, epoch_upgrade_multithreaded) { // Check pending entry auto transaction = node->ledger.tx_begin_read (); - auto info = node->ledger.pending_info (transaction, nano::pending_key (key3.pub, send7->hash ())); + auto info = node->ledger.any.pending_get (transaction, nano::pending_key (key3.pub, send7->hash ())); ASSERT_TRUE (info); ASSERT_EQ (nano::epoch::epoch_1, info->epoch); } @@ -6364,9 +6366,9 @@ TEST (rpc, epoch_upgrade_multithreaded) ASSERT_TIMELY_EQ (5s, 5, node->store.account.count (node->store.tx_begin_read ())); // Check upgrade { - auto transaction (node->store.tx_begin_read ()); + auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (5, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->ledger.any.account_begin (transaction)); i != node->ledger.any.account_end (); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_2); @@ -6455,7 +6457,7 @@ TEST (rpc, receive) { auto response (wait_response (system, rpc_ctx, request)); auto receive_text (response.get ("block")); - auto info = node->ledger.account_info (node->ledger.tx_begin_read (), key1.pub); + auto info = node->ledger.any.account_get (node->ledger.tx_begin_read (), key1.pub); ASSERT_TRUE (info); ASSERT_EQ (info->head, nano::block_hash{ receive_text }); } @@ -6485,7 +6487,7 @@ TEST (rpc, receive_unopened) auto send1 (wallet->send_action (nano::dev::genesis_key.pub, key1.pub, node->config.receive_minimum.number () - 1, *node->work_generate_blocking (nano::dev::genesis->hash ()))); ASSERT_TIMELY (5s, !node->balance (nano::dev::genesis_key.pub) != nano::dev::constants.genesis_amount); ASSERT_FALSE (node->store.account.exists (node->ledger.tx_begin_read (), key1.pub)); - ASSERT_TRUE (node->ledger.block_exists (node->ledger.tx_begin_read (), send1->hash ())); + ASSERT_TRUE (node->ledger.any.block_exists (node->ledger.tx_begin_read (), send1->hash ())); wallet->insert_adhoc (key1.prv); // should not auto receive, amount sent was lower than minimum auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; @@ -6496,7 +6498,7 @@ TEST (rpc, receive_unopened) { auto response (wait_response (system, rpc_ctx, request)); auto receive_text (response.get ("block")); - auto info = node->ledger.account_info (node->ledger.tx_begin_read (), key1.pub); + auto info = node->ledger.any.account_get (node->ledger.tx_begin_read (), key1.pub); ASSERT_TRUE (info); ASSERT_EQ (info->head, info->open_block); ASSERT_EQ (info->head.to_string (), receive_text); @@ -6509,7 +6511,7 @@ TEST (rpc, receive_unopened) auto send2 (wallet->send_action (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number () - 1, *node->work_generate_blocking (send1->hash ()))); ASSERT_TIMELY (5s, !node->balance (nano::dev::genesis_key.pub) != prev_amount); ASSERT_FALSE (node->store.account.exists (node->ledger.tx_begin_read (), key2.pub)); - ASSERT_TRUE (node->ledger.block_exists (node->ledger.tx_begin_read (), send2->hash ())); + ASSERT_TRUE (node->ledger.any.block_exists (node->ledger.tx_begin_read (), send2->hash ())); nano::public_key rep; wallet->store.representative_set (node->wallets.tx_begin_write (), rep); wallet->insert_adhoc (key2.prv); // should not auto receive, amount sent was lower than minimum @@ -6518,7 +6520,7 @@ TEST (rpc, receive_unopened) { auto response (wait_response (system, rpc_ctx, request)); auto receive_text (response.get ("block")); - auto info = node->ledger.account_info (node->ledger.tx_begin_read (), key2.pub); + auto info = node->ledger.any.account_get (node->ledger.tx_begin_read (), key2.pub); ASSERT_TRUE (info); ASSERT_EQ (info->head, info->open_block); ASSERT_EQ (info->head.to_string (), receive_text); @@ -6544,7 +6546,7 @@ TEST (rpc, receive_work_disabled) ASSERT_NE (send1, nullptr); ASSERT_TIMELY (5s, node->balance (nano::dev::genesis_key.pub) != nano::dev::constants.genesis_amount); ASSERT_FALSE (node->store.account.exists (node->ledger.tx_begin_read (), key1.pub)); - ASSERT_TRUE (node->ledger.block_exists (node->ledger.tx_begin_read (), send1->hash ())); + ASSERT_TRUE (node->ledger.any.block_exists (node->ledger.tx_begin_read (), send1->hash ())); wallet->insert_adhoc (key1.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; @@ -6588,11 +6590,11 @@ TEST (rpc, receive_pruned) ASSERT_EQ (2, node2->ledger.pruning_action (transaction, send2->hash (), 1)); } ASSERT_EQ (2, node2->ledger.pruned_count ()); - ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send1->hash ())); - ASSERT_FALSE (node2->ledger.block_exists (node2->ledger.tx_begin_read (), send1->hash ())); - ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send2->hash ())); - ASSERT_FALSE (node2->ledger.block_exists (node2->ledger.tx_begin_read (), send2->hash ())); - ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send3->hash ())); + ASSERT_TRUE (node2->block_or_pruned_exists (send1->hash ())); + ASSERT_FALSE (node2->ledger.any.block_exists (node2->ledger.tx_begin_read (), send1->hash ())); + ASSERT_TRUE (node2->block_or_pruned_exists (send2->hash ())); + ASSERT_FALSE (node2->ledger.any.block_exists (node2->ledger.tx_begin_read (), send2->hash ())); + ASSERT_TRUE (node2->block_or_pruned_exists (send3->hash ())); auto const rpc_ctx = add_rpc (system, node2); boost::property_tree::ptree request; @@ -6603,7 +6605,7 @@ TEST (rpc, receive_pruned) { auto response (wait_response (system, rpc_ctx, request)); auto receive_text (response.get ("block")); - auto info = node2->ledger.account_info (node2->ledger.tx_begin_read (), key1.pub); + auto info = node2->ledger.any.account_get (node2->ledger.tx_begin_read (), key1.pub); ASSERT_TRUE (info); ASSERT_EQ (info->head, nano::block_hash{ receive_text }); } diff --git a/nano/secure/CMakeLists.txt b/nano/secure/CMakeLists.txt index 2825a08c84..7b97291e90 100644 --- a/nano/secure/CMakeLists.txt +++ b/nano/secure/CMakeLists.txt @@ -41,6 +41,9 @@ add_library( ${CMAKE_BINARY_DIR}/bootstrap_weights_beta.cpp account_info.hpp account_info.cpp + account_iterator.cpp + account_iterator.hpp + account_iterator_impl.hpp common.hpp common.cpp generate_cache_flags.hpp @@ -49,10 +52,17 @@ add_library( ledger.cpp ledger_cache.hpp ledger_cache.cpp + ledger_set_any.hpp + ledger_set_any.cpp + ledger_set_confirmed.hpp + ledger_set_confirmed.cpp network_filter.hpp network_filter.cpp pending_info.hpp pending_info.cpp + receivable_iterator.cpp + receivable_iterator.hpp + receivable_iterator_impl.hpp rep_weights.hpp rep_weights.cpp transaction.hpp diff --git a/nano/secure/account_iterator.cpp b/nano/secure/account_iterator.cpp new file mode 100644 index 0000000000..e61ad5783d --- /dev/null +++ b/nano/secure/account_iterator.cpp @@ -0,0 +1,4 @@ +#include +#include + +template class nano::account_iterator; diff --git a/nano/secure/account_iterator.hpp b/nano/secure/account_iterator.hpp new file mode 100644 index 0000000000..f0a02da0a9 --- /dev/null +++ b/nano/secure/account_iterator.hpp @@ -0,0 +1,43 @@ +#pragma once +#include +#include + +#include +#include + +namespace nano::secure +{ +class transaction; +} + +namespace nano +{ +// This class iterates account entries +template +class account_iterator +{ +public: + // Creates an end () iterator + // 'transaction' and 'set' are nullptr so all end () iterators compare equal + account_iterator (); + account_iterator (secure::transaction const & transaction, Set const & set, std::optional> const & item); + + // Compares if these iterators hold the same 'item'. + // Undefined behavior if this and other don't hold the same 'set' and 'transaction' + bool operator== (account_iterator const & other) const; + +public: // Dereferencing, undefined behavior when called on an end () iterator + // Advances the iterator to the next greater nano::account + // If there are no more accounts, convert this to an end () iterator + account_iterator & operator++ (); + std::pair const & operator* () const; + std::pair const * operator->() const; + +private: + secure::transaction const * transaction; + Set const * set{ nullptr }; + // Current item at the position of the iterator + // std::nullopt if an end () iterator + std::optional> item; +}; +} diff --git a/nano/secure/account_iterator_impl.hpp b/nano/secure/account_iterator_impl.hpp new file mode 100644 index 0000000000..a68f70b352 --- /dev/null +++ b/nano/secure/account_iterator_impl.hpp @@ -0,0 +1,51 @@ +#include +#include + +template +nano::account_iterator::account_iterator () +{ +} + +template +nano::account_iterator::account_iterator (secure::transaction const & transaction, Set const & set, std::optional> const & item) : + transaction{ &transaction }, + set{ &set }, + item{ item } +{ +} + +template +bool nano::account_iterator::operator== (account_iterator const & other) const +{ + debug_assert (set == nullptr || other.set == nullptr || set == other.set); + return item == other.item; +} + +// Iteration is performed by calling set->account_lower_bound (tx, next) where next is one higher than the current iterator +template +auto nano::account_iterator::operator++ () -> account_iterator & +{ + auto next = item.value ().first.number () + 1; + if (next != 0) + { + *this = set->account_lower_bound (*transaction, next); + } + else + { + // Convert to and end iterator if there are no more items + *this = account_iterator{}; + } + return *this; +} + +template +std::pair const & nano::account_iterator::operator* () const +{ + return item.value (); +} + +template +std::pair const * nano::account_iterator::operator->() const +{ + return &item.value (); +} diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 4ca2bb3da1..254b2944b7 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -46,16 +48,16 @@ class rollback_visitor : public nano::block_visitor auto pending = ledger.store.pending.get (transaction, key); while (!error && !pending.has_value ()) { - error = ledger.rollback (transaction, ledger.latest (transaction, block_a.hashables.destination), list); + error = ledger.rollback (transaction, ledger.any.account_head (transaction, block_a.hashables.destination), list); pending = ledger.store.pending.get (transaction, key); } if (!error) { - auto info = ledger.account_info (transaction, pending.value ().source); + auto info = ledger.any.account_get (transaction, pending.value ().source); debug_assert (info); ledger.store.pending.del (transaction, key); ledger.cache.rep_weights.representation_add (transaction, info->representative, pending.value ().amount.number ()); - nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.balance (transaction, block_a.hashables.previous).value (), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); + nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.any.block_balance (transaction, block_a.hashables.previous).value (), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); ledger.update_account (transaction, pending.value ().source, *info, new_info); ledger.store.block.del (transaction, hash); ledger.store.block.successor_clear (transaction, block_a.hashables.previous); @@ -65,14 +67,14 @@ class rollback_visitor : public nano::block_visitor void receive_block (nano::receive_block const & block_a) override { auto hash (block_a.hash ()); - auto amount = ledger.amount (transaction, hash).value (); + auto amount = ledger.any.block_amount (transaction, hash).value ().number (); 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); + auto source_account = ledger.any.block_account (transaction, block_a.hashables.source); + auto info = ledger.any.account_get (transaction, destination_account); debug_assert (info); ledger.cache.rep_weights.representation_add (transaction, info->representative, 0 - amount); - nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.balance (transaction, block_a.hashables.previous).value (), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); + nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.any.block_balance (transaction, block_a.hashables.previous).value (), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); ledger.update_account (transaction, destination_account, *info, new_info); ledger.store.block.del (transaction, hash); ledger.store.pending.put (transaction, nano::pending_key (destination_account, block_a.hashables.source), { source_account.value_or (0), amount, nano::epoch::epoch_0 }); @@ -82,9 +84,9 @@ class rollback_visitor : public nano::block_visitor void open_block (nano::open_block const & block_a) override { auto hash (block_a.hash ()); - auto amount = ledger.amount (transaction, hash).value (); + auto amount = ledger.any.block_amount (transaction, hash).value ().number (); auto destination_account = block_a.account (); - auto source_account = ledger.account (transaction, block_a.hashables.source); + auto source_account = ledger.any.block_account (transaction, block_a.hashables.source); ledger.cache.rep_weights.representation_add (transaction, block_a.representative_field ().value (), 0 - amount); nano::account_info new_info; ledger.update_account (transaction, destination_account, new_info, new_info); @@ -97,13 +99,13 @@ class rollback_visitor : public nano::block_visitor auto hash (block_a.hash ()); auto rep_block (ledger.representative (transaction, block_a.hashables.previous)); auto account = block_a.account (); - auto info = ledger.account_info (transaction, account); + auto info = ledger.any.account_get (transaction, account); debug_assert (info); - auto balance = ledger.balance (transaction, block_a.hashables.previous).value (); + auto balance = ledger.any.block_balance (transaction, block_a.hashables.previous).value (); auto block = ledger.store.block.get (transaction, rep_block); release_assert (block != nullptr); auto representative = block->representative_field ().value (); - ledger.cache.rep_weights.representation_add_dual (transaction, block_a.hashables.representative, 0 - balance, representative, balance); + ledger.cache.rep_weights.representation_add_dual (transaction, block_a.hashables.representative, 0 - balance.number (), representative, balance.number ()); 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); @@ -118,7 +120,7 @@ class rollback_visitor : public nano::block_visitor { rep_block_hash = ledger.representative (transaction, block_a.hashables.previous); } - nano::uint128_t balance = ledger.balance (transaction, block_a.hashables.previous).value_or (0); + nano::uint128_t balance = ledger.any.block_balance (transaction, block_a.hashables.previous).value_or (0).number (); auto is_send (block_a.hashables.balance < balance); nano::account representative{}; if (!rep_block_hash.is_zero ()) @@ -135,15 +137,15 @@ class rollback_visitor : public nano::block_visitor ledger.cache.rep_weights.representation_add (transaction, block_a.hashables.representative, 0 - block_a.hashables.balance.number ()); } - auto info = ledger.account_info (transaction, block_a.hashables.account); + auto info = ledger.any.account_get (transaction, block_a.hashables.account); debug_assert (info); if (is_send) { nano::pending_key key (block_a.hashables.link.as_account (), hash); - while (!error && !ledger.pending_info (transaction, key)) + while (!error && !ledger.any.pending_get (transaction, key)) { - error = ledger.rollback (transaction, ledger.latest (transaction, block_a.hashables.link.as_account ()), list); + error = ledger.rollback (transaction, ledger.any.account_head (transaction, block_a.hashables.link.as_account ()), list); } ledger.store.pending.del (transaction, key); ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::send); @@ -151,7 +153,7 @@ class rollback_visitor : public nano::block_visitor else if (!block_a.hashables.link.is_zero () && !ledger.is_epoch_link (block_a.hashables.link)) { // 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.link.as_block_hash ()); + auto source_account = ledger.any.block_account (transaction, block_a.hashables.link.as_block_hash ()); nano::pending_info pending_info (source_account.value_or (0), block_a.hashables.balance.number () - balance, block_a.sideband ().source_epoch); ledger.store.pending.put (transaction, nano::pending_key (block_a.hashables.account, block_a.hashables.link.as_block_hash ()), pending_info); ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::receive); @@ -209,7 +211,7 @@ bool ledger_processor::validate_epoch_block (nano::state_block const & block_a) result = ledger.store.block.exists (transaction, block_a.hashables.previous) ? nano::block_status::progress : nano::block_status::gap_previous; if (result == nano::block_status::progress) { - prev_balance = ledger.balance (transaction, block_a.hashables.previous).value (); + prev_balance = ledger.any.block_balance (transaction, block_a.hashables.previous).value (); } else { @@ -253,7 +255,7 @@ void ledger_processor::state_block (nano::state_block & block_a) void ledger_processor::state_block_impl (nano::state_block & block_a) { auto hash (block_a.hash ()); - auto existing (ledger.block_or_pruned_exists (transaction, hash)); + auto existing = ledger.any.block_exists_or_pruned (transaction, hash); result = existing ? nano::block_status::old : nano::block_status::progress; // Have we seen this block before? (Unambiguous) if (result == nano::block_status::progress) { @@ -304,7 +306,7 @@ void ledger_processor::state_block_impl (nano::state_block & block_a) { if (!block_a.hashables.link.is_zero ()) { - result = ledger.block_or_pruned_exists (transaction, block_a.hashables.link.as_block_hash ()) ? nano::block_status::progress : nano::block_status::gap_source; // Have we seen the source block already? (Harmless) + result = ledger.any.block_exists_or_pruned (transaction, block_a.hashables.link.as_block_hash ()) ? nano::block_status::progress : nano::block_status::gap_source; // Have we seen the source block already? (Harmless) if (result == nano::block_status::progress) { nano::pending_key key (block_a.hashables.account, block_a.hashables.link.as_block_hash ()); @@ -369,7 +371,7 @@ void ledger_processor::state_block_impl (nano::state_block & block_a) void ledger_processor::epoch_block_impl (nano::state_block & block_a) { auto hash (block_a.hash ()); - auto existing (ledger.block_or_pruned_exists (transaction, hash)); + auto existing = ledger.any.block_exists_or_pruned (transaction, hash); result = existing ? nano::block_status::old : nano::block_status::progress; // Have we seen this block before? (Unambiguous) if (result == nano::block_status::progress) { @@ -401,7 +403,7 @@ void ledger_processor::epoch_block_impl (nano::state_block & block_a) // Non-exisitng account should have pending entries if (result == nano::block_status::progress) { - bool pending_exists = ledger.receivable_any (transaction, block_a.hashables.account); + bool pending_exists = ledger.any.receivable_exists (transaction, block_a.hashables.account); result = pending_exists ? nano::block_status::progress : nano::block_status::gap_epoch_open_pending; } } @@ -437,7 +439,7 @@ void ledger_processor::epoch_block_impl (nano::state_block & block_a) void ledger_processor::change_block (nano::change_block & block_a) { auto hash (block_a.hash ()); - auto existing (ledger.block_or_pruned_exists (transaction, hash)); + auto existing = ledger.any.block_exists_or_pruned (transaction, hash); result = existing ? nano::block_status::old : nano::block_status::progress; // Have we seen this block before? (Harmless) if (result == nano::block_status::progress) { @@ -449,7 +451,7 @@ void ledger_processor::change_block (nano::change_block & block_a) if (result == nano::block_status::progress) { auto account = previous->account (); - auto info = ledger.account_info (transaction, account); + auto info = ledger.any.account_get (transaction, account); debug_assert (info); result = info->head != block_a.hashables.previous ? nano::block_status::fork : nano::block_status::progress; if (result == nano::block_status::progress) @@ -481,7 +483,7 @@ void ledger_processor::change_block (nano::change_block & block_a) void ledger_processor::send_block (nano::send_block & block_a) { auto hash (block_a.hash ()); - auto existing (ledger.block_or_pruned_exists (transaction, hash)); + auto existing = ledger.any.block_exists_or_pruned (transaction, hash); result = existing ? nano::block_status::old : nano::block_status::progress; // Have we seen this block before? (Harmless) if (result == nano::block_status::progress) { @@ -493,7 +495,7 @@ void ledger_processor::send_block (nano::send_block & block_a) if (result == nano::block_status::progress) { auto account = previous->account (); - auto info = ledger.account_info (transaction, account); + auto info = ledger.any.account_get (transaction, account); debug_assert (info); result = info->head != block_a.hashables.previous ? nano::block_status::fork : nano::block_status::progress; if (result == nano::block_status::progress) @@ -530,7 +532,7 @@ void ledger_processor::send_block (nano::send_block & block_a) void ledger_processor::receive_block (nano::receive_block & block_a) { auto hash (block_a.hash ()); - auto existing (ledger.block_or_pruned_exists (transaction, hash)); + auto existing = ledger.any.block_exists_or_pruned (transaction, hash); result = existing ? nano::block_status::old : nano::block_status::progress; // Have we seen this block already? (Harmless) if (result == nano::block_status::progress) { @@ -542,7 +544,7 @@ void ledger_processor::receive_block (nano::receive_block & block_a) if (result == nano::block_status::progress) { auto account = previous->account (); - auto info = ledger.account_info (transaction, account); + auto info = ledger.any.account_get (transaction, account); debug_assert (info); result = info->head != block_a.hashables.previous ? nano::block_status::fork : nano::block_status::progress; // If we have the block but it's not the latest we have a signed fork (Malicious) if (result == nano::block_status::progress) @@ -551,7 +553,7 @@ void ledger_processor::receive_block (nano::receive_block & block_a) if (result == nano::block_status::progress) { debug_assert (!validate_message (account, hash, block_a.signature)); - result = ledger.block_or_pruned_exists (transaction, block_a.hashables.source) ? nano::block_status::progress : nano::block_status::gap_source; // Have we seen the source block already? (Harmless) + result = ledger.any.block_exists_or_pruned (transaction, block_a.hashables.source) ? nano::block_status::progress : nano::block_status::gap_source; // Have we seen the source block already? (Harmless) if (result == nano::block_status::progress) { result = info->head == block_a.hashables.previous ? nano::block_status::progress : nano::block_status::gap_previous; // Block doesn't immediately follow latest block (Harmless) @@ -592,7 +594,7 @@ void ledger_processor::receive_block (nano::receive_block & block_a) void ledger_processor::open_block (nano::open_block & block_a) { auto hash (block_a.hash ()); - auto existing (ledger.block_or_pruned_exists (transaction, hash)); + auto existing = ledger.any.block_exists_or_pruned (transaction, hash); result = existing ? nano::block_status::old : nano::block_status::progress; // Have we seen this block already? (Harmless) if (result == nano::block_status::progress) { @@ -600,7 +602,7 @@ void ledger_processor::open_block (nano::open_block & block_a) if (result == nano::block_status::progress) { debug_assert (!validate_message (block_a.hashables.account, hash, block_a.signature)); - result = ledger.block_or_pruned_exists (transaction, block_a.hashables.source) ? nano::block_status::progress : nano::block_status::gap_source; // Have we seen the source block? (Harmless) + result = ledger.any.block_exists_or_pruned (transaction, block_a.hashables.source) ? nano::block_status::progress : nano::block_status::gap_source; // Have we seen the source block? (Harmless) if (result == nano::block_status::progress) { nano::account_info info; @@ -677,7 +679,7 @@ void representative_visitor::compute (nano::block_hash const & hash_a) current = hash_a; while (result.is_zero ()) { - auto block_l = ledger.block (transaction, current); + auto block_l = ledger.any.block_get (transaction, current); debug_assert (block_l != nullptr); block_l->visit (*this); } @@ -714,7 +716,11 @@ nano::ledger::ledger (nano::store::component & store_a, nano::stats & stat_a, na store{ store_a }, cache{ store_a.rep_weight, min_rep_weight_a }, stats{ stat_a }, - check_bootstrap_weights{ true } + check_bootstrap_weights{ true }, + any_impl{ std::make_unique (*this) }, + confirmed_impl{ std::make_unique (*this) }, + any{ *any_impl }, + confirmed{ *confirmed_impl } { if (!store.init_error ()) { @@ -722,6 +728,10 @@ nano::ledger::ledger (nano::store::component & store_a, nano::stats & stat_a, na } } +nano::ledger::~ledger () +{ +} + auto nano::ledger::tx_begin_write (std::vector const & tables_to_lock, std::vector const & tables_no_lock) const -> secure::write_transaction { return secure::write_transaction{ store.tx_begin_write (tables_to_lock, tables_no_lock) }; @@ -778,61 +788,13 @@ void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache cache.pruned_count = store.pruned.count (transaction); } -// Balance for account containing hash -std::optional nano::ledger::balance (secure::transaction const & transaction, nano::block_hash const & hash) const -{ - if (hash.is_zero ()) - { - return std::nullopt; - } - auto block = store.block.get (transaction, hash); - if (!block) - { - return std::nullopt; - } - return block->balance ().number (); -} - -std::shared_ptr nano::ledger::block (secure::transaction const & transaction, nano::block_hash const & hash) const -{ - return store.block.get (transaction, hash); -} - -bool nano::ledger::block_exists (secure::transaction const & transaction, nano::block_hash const & hash) const -{ - return store.block.exists (transaction, hash); -} - -// Balance for an account by account number -nano::uint128_t nano::ledger::account_balance (secure::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) const -{ - nano::uint128_t result (0); - if (only_confirmed_a) - { - nano::confirmation_height_info info; - if (!store.confirmation_height.get (transaction_a, account_a, info)) - { - result = balance (transaction_a, info.frontier).value (); - } - } - else - { - auto info = account_info (transaction_a, account_a); - if (info) - { - result = info->balance.number (); - } - } - return result; -} - nano::uint128_t nano::ledger::account_receivable (secure::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) { nano::uint128_t result{ 0 }; - for (auto i = receivable_upper_bound (transaction_a, account_a, 0), n = receivable_end (); i != n; ++i) + for (auto i = any.receivable_upper_bound (transaction_a, account_a, 0), n = any.receivable_end (); i != n; ++i) { auto const & [key, info] = *i; - if (!only_confirmed_a || block_confirmed (transaction_a, key.hash)) + if (!only_confirmed_a || confirmed.block_exists_or_pruned (transaction_a, key.hash)) { result += info.amount.number (); } @@ -840,11 +802,6 @@ nano::uint128_t nano::ledger::account_receivable (secure::transaction const & tr return result; } -std::optional nano::ledger::pending_info (secure::transaction const & transaction, nano::pending_key const & key) const -{ - return store.pending.get (transaction, key); -} - std::deque> nano::ledger::confirm (secure::write_transaction const & transaction, nano::block_hash const & hash) { std::deque> result; @@ -853,12 +810,12 @@ std::deque> nano::ledger::confirm (secure::write_tr while (!stack.empty ()) { auto hash = stack.top (); - auto block = this->block (transaction, hash); + auto block = any.block_get (transaction, hash); release_assert (block); auto dependents = dependent_blocks (transaction, *block); for (auto const & dependent : dependents) { - if (!dependent.is_zero () && !block_confirmed (transaction, dependent)) + if (!dependent.is_zero () && !confirmed.block_exists_or_pruned (transaction, dependent)) { stack.push (dependent); } @@ -866,7 +823,7 @@ std::deque> nano::ledger::confirm (secure::write_tr if (stack.top () == hash) { stack.pop (); - if (!block_confirmed (transaction, hash)) + if (!confirmed.block_exists_or_pruned (transaction, hash)) { result.push_back (block); confirm (transaction, *block); @@ -904,7 +861,7 @@ nano::block_status nano::ledger::process (secure::write_transaction const & tran nano::block_hash nano::ledger::representative (secure::transaction const & transaction_a, nano::block_hash const & hash_a) { auto result (representative_calculated (transaction_a, hash_a)); - debug_assert (result.is_zero () || block_exists (transaction_a, result)); + debug_assert (result.is_zero () || any.block_exists (transaction_a, result)); return result; } @@ -915,20 +872,6 @@ nano::block_hash nano::ledger::representative_calculated (secure::transaction co return visitor.result; } -bool nano::ledger::block_or_pruned_exists (nano::block_hash const & hash_a) const -{ - return block_or_pruned_exists (tx_begin_read (), hash_a); -} - -bool nano::ledger::block_or_pruned_exists (secure::transaction const & transaction_a, nano::block_hash const & hash_a) const -{ - if (store.pruned.exists (transaction_a, hash_a)) - { - return true; - } - return block_exists (transaction_a, hash_a); -} - std::string nano::ledger::block_text (char const * hash_a) { return block_text (nano::block_hash (hash_a)); @@ -938,7 +881,7 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a) { std::string result; auto transaction = tx_begin_read (); - auto block_l = block (transaction, hash_a); + auto block_l = any.block_get (transaction, hash_a); if (block_l != nullptr) { block_l->serialize_json (result); @@ -1004,20 +947,20 @@ nano::uint128_t nano::ledger::weight_exact (secure::transaction const & txn_a, n // Rollback blocks until `block_a' doesn't exist or it tries to penetrate the confirmation height bool nano::ledger::rollback (secure::write_transaction const & transaction_a, nano::block_hash const & block_a, std::vector> & list_a) { - debug_assert (block_exists (transaction_a, block_a)); - auto account_l = account (transaction_a, block_a).value (); - auto block_account_height (height (transaction_a, block_a)); + debug_assert (any.block_exists (transaction_a, block_a)); + auto account_l = any.block_account (transaction_a, block_a).value (); + auto block_account_height (any.block_height (transaction_a, block_a)); rollback_visitor rollback (transaction_a, *this, list_a); auto error (false); - while (!error && block_exists (transaction_a, block_a)) + while (!error && any.block_exists (transaction_a, block_a)) { nano::confirmation_height_info confirmation_height_info; store.confirmation_height.get (transaction_a, account_l, confirmation_height_info); if (block_account_height > confirmation_height_info.height) { - auto info = account_info (transaction_a, account_l); + auto info = any.account_get (transaction_a, account_l); debug_assert (info); - auto block_l = block (transaction_a, info->head); + auto block_l = any.block_get (transaction_a, info->head); list_a.push_back (block_l); block_l->visit (rollback); error = rollback.error; @@ -1040,52 +983,10 @@ bool nano::ledger::rollback (secure::write_transaction const & transaction_a, na return rollback (transaction_a, block_a, rollback_list); } -std::optional nano::ledger::account (secure::transaction const & transaction, nano::block_hash const & hash) const -{ - auto block_l = block (transaction, hash); - if (!block_l) - { - return std::nullopt; - } - return block_l->account (); -} - -std::optional nano::ledger::account_info (secure::transaction const & transaction, nano::account const & account) const -{ - return store.account.get (transaction, account); -} - -std::optional nano::ledger::amount (secure::transaction const & transaction_a, nano::block_hash const & hash_a) -{ - auto block_l = block (transaction_a, hash_a); - if (!block_l) - { - return std::nullopt; - } - auto block_balance = block_l->balance (); - if (block_l->previous ().is_zero ()) - { - 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.number () - previous_balance.value () : previous_balance.value () - block_balance.number (); -} - -// Return latest block for account -nano::block_hash nano::ledger::latest (secure::transaction const & transaction_a, nano::account const & account_a) -{ - auto info = account_info (transaction_a, account_a); - return !info ? 0 : info->head; -} - // Return latest root for account, account number if there are no blocks for this account. nano::root nano::ledger::latest_root (secure::transaction const & transaction_a, nano::account const & account_a) { - auto info = account_info (transaction_a, account_a); + auto info = any.account_get (transaction_a, account_a); if (!info) { return account_a; @@ -1099,10 +1000,10 @@ nano::root nano::ledger::latest_root (secure::transaction const & transaction_a, void nano::ledger::dump_account_chain (nano::account const & account_a, std::ostream & stream) { auto transaction = tx_begin_read (); - auto hash (latest (transaction, account_a)); + auto hash (any.account_head (transaction, account_a)); while (!hash.is_zero ()) { - auto block_l = block (transaction, hash); + auto block_l = any.block_get (transaction, hash); debug_assert (block_l != nullptr); stream << hash.to_string () << std::endl; hash = block_l->previous (); @@ -1116,7 +1017,7 @@ bool nano::ledger::dependents_confirmed (secure::transaction const & transaction auto result (hash_a.is_zero ()); if (!result) { - result = block_confirmed (transaction_a, hash_a); + result = confirmed.block_exists_or_pruned (transaction_a, hash_a); } return result; }); @@ -1178,7 +1079,7 @@ class dependent_block_visitor : public nano::block_visitor { return block.sideband ().details.is_send; } - return block.balance_field ().value () < ledger.balance (transaction, block.previous ()); + return block.balance_field ().value () < ledger.any.block_balance (transaction, block.previous ()); } nano::ledger const & ledger; nano::secure::transaction const & transaction; @@ -1207,7 +1108,7 @@ std::shared_ptr nano::ledger::find_receive_block_by_send_hash (secu { return nullptr; } - auto possible_receive_block = block (transaction, info.frontier); + auto possible_receive_block = any.block_get (transaction, info.frontier); // walk down the chain until the source field of a receive block matches the send block hash while (possible_receive_block != nullptr) @@ -1219,7 +1120,7 @@ std::shared_ptr nano::ledger::find_receive_block_by_send_hash (secu break; } - possible_receive_block = block (transaction, possible_receive_block->previous ()); + possible_receive_block = any.block_get (transaction, possible_receive_block->previous ()); } return result; @@ -1259,89 +1160,37 @@ void nano::ledger::update_account (secure::write_transaction const & transaction } } -std::optional nano::ledger::successor (secure::transaction const & transaction_a, nano::qualified_root const & root_a) const noexcept -{ - if (!root_a.previous ().is_zero ()) - { - return store.block.successor (transaction_a, root_a.previous ()); - } - else - { - auto info = account_info (transaction_a, root_a.root ().as_account ()); - if (info) - { - return info.value ().open_block; - } - else - { - return std::nullopt; - } - } -} - -std::optional nano::ledger::successor (secure::transaction const & transaction, nano::block_hash const & hash) const noexcept -{ - return successor (transaction, { hash, hash }); -} - std::shared_ptr nano::ledger::forked_block (secure::transaction const & transaction_a, nano::block const & block_a) { - debug_assert (!block_exists (transaction_a, block_a.hash ())); + debug_assert (!any.block_exists (transaction_a, block_a.hash ())); auto root (block_a.root ()); - debug_assert (block_exists (transaction_a, root.as_block_hash ()) || store.account.exists (transaction_a, root.as_account ())); + debug_assert (any.block_exists (transaction_a, root.as_block_hash ()) || store.account.exists (transaction_a, root.as_account ())); std::shared_ptr result; - auto successor_l = successor (transaction_a, root.as_block_hash ()); + auto successor_l = any.block_successor (transaction_a, root.as_block_hash ()); if (successor_l) { - result = block (transaction_a, successor_l.value ()); + result = any.block_get (transaction_a, successor_l.value ()); } if (result == nullptr) { - auto info = account_info (transaction_a, root.as_account ()); + auto info = any.account_get (transaction_a, root.as_account ()); debug_assert (info); - result = block (transaction_a, info->open_block); + result = any.block_get (transaction_a, info->open_block); debug_assert (result != nullptr); } return result; } -std::shared_ptr nano::ledger::head_block (secure::transaction const & transaction, nano::account const & account) -{ - auto info = store.account.get (transaction, account); - if (info) - { - return block (transaction, info->head); - } - return nullptr; -} - -bool nano::ledger::block_confirmed (secure::transaction const & transaction_a, nano::block_hash const & hash_a) const -{ - if (store.pruned.exists (transaction_a, hash_a)) - { - return true; - } - auto block_l = block (transaction_a, hash_a); - if (block_l) - { - nano::confirmation_height_info 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; - } - return false; -} - uint64_t nano::ledger::pruning_action (secure::write_transaction & transaction_a, nano::block_hash const & hash_a, uint64_t const batch_size_a) { uint64_t pruned_count (0); nano::block_hash hash (hash_a); while (!hash.is_zero () && hash != constants.genesis->hash ()) { - auto block_l = block (transaction_a, hash); + auto block_l = any.block_get (transaction_a, hash); if (block_l != nullptr) { - release_assert (block_confirmed (transaction_a, hash)); + release_assert (confirmed.block_exists (transaction_a, hash)); store.block.del (transaction_a, hash); store.pruned.put (transaction_a, hash); hash = block_l->previous (); @@ -1515,7 +1364,7 @@ nano::epoch nano::ledger::version (nano::block const & block) nano::epoch nano::ledger::version (secure::transaction const & transaction, nano::block_hash const & hash) const { - auto block_l = block (transaction, hash); + auto block_l = any.block_get (transaction, hash); if (block_l == nullptr) { return nano::epoch::epoch_0; @@ -1523,48 +1372,6 @@ nano::epoch nano::ledger::version (secure::transaction const & transaction, nano return version (*block_l); } -uint64_t nano::ledger::height (secure::transaction const & transaction, nano::block_hash const & hash) const -{ - auto block_l = block (transaction, hash); - return block_l->sideband ().height; -} - -bool nano::ledger::receivable_any (secure::transaction const & tx, nano::account const & account) const -{ - auto next = receivable_upper_bound (tx, account, 0); - return next != receivable_end (); -} - -std::optional> nano::ledger::receivable_lower_bound (secure::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const -{ - auto result = store.pending.begin (tx, { account, hash }); - if (result == store.pending.end ()) - { - return std::nullopt; - } - return *result; -} - -nano::receivable_iterator nano::ledger::receivable_end () const -{ - return nano::receivable_iterator{}; -} - -nano::receivable_iterator nano::ledger::receivable_upper_bound (secure::transaction const & tx, nano::account const & account) const -{ - return receivable_iterator{ *this, tx, receivable_lower_bound (tx, account.number () + 1, 0) }; -} - -nano::receivable_iterator nano::ledger::receivable_upper_bound (secure::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const -{ - auto result = receivable_lower_bound (tx, account, hash.number () + 1); - if (!result || result.value ().first.account != account) - { - return nano::receivable_iterator{ *this, tx, std::nullopt }; - } - return nano::receivable_iterator{ *this, tx, result }; -} - uint64_t nano::ledger::cemented_count () const { return cache.cemented_count; diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index db7a7a6ae1..201f95060d 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -10,6 +10,7 @@ #include #include +#include namespace nano::store { @@ -22,32 +23,26 @@ class block; enum class block_status; enum class epoch : uint8_t; class ledger_constants; +class ledger_set_any; +class ledger_set_confirmed; class pending_info; class pending_key; class stats; class ledger final { + template friend class receivable_iterator; public: ledger (nano::store::component &, nano::stats &, nano::ledger_constants & constants, nano::generate_cache_flags const & = nano::generate_cache_flags{}, nano::uint128_t min_rep_weight_a = 0); + ~ledger (); /** Start read-write transaction */ secure::write_transaction tx_begin_write (std::vector const & tables_to_lock = {}, std::vector const & tables_no_lock = {}) const; /** Start read-only transaction */ secure::read_transaction tx_begin_read () const; - /** - * Returns the account for a given hash - * Returns std::nullopt if the block doesn't exist or has been pruned - */ - std::optional account (secure::transaction const &, nano::block_hash const &) const; - std::optional account_info (secure::transaction const & transaction, nano::account const & account) const; - std::optional amount (secure::transaction const &, nano::block_hash const &); - std::optional balance (secure::transaction const &, nano::block_hash const &) const; - std::shared_ptr block (secure::transaction const & transaction, nano::block_hash const & hash) const; - bool block_exists (secure::transaction const & transaction, nano::block_hash const & hash) const; - nano::uint128_t account_balance (secure::transaction const &, nano::account const &, bool = false) const; + nano::uint128_t account_receivable (secure::transaction const &, nano::account const &, bool = false); /** * Returns the cached vote weight for the given representative. @@ -55,19 +50,12 @@ class ledger final * During bootstrap it returns the preconfigured bootstrap weights. */ nano::uint128_t weight (nano::account const &) const; - std::optional successor (secure::transaction const &, nano::qualified_root const &) const noexcept; - std::optional successor (secure::transaction const & transaction, nano::block_hash const & hash) const noexcept; /* Returns the exact vote weight for the given representative by doing a database lookup */ nano::uint128_t weight_exact (secure::transaction const &, nano::account const &) const; std::shared_ptr forked_block (secure::transaction const &, nano::block const &); - std::shared_ptr head_block (secure::transaction const &, nano::account const &); - bool block_confirmed (secure::transaction const &, nano::block_hash const &) const; - nano::block_hash latest (secure::transaction const &, nano::account const &); nano::root latest_root (secure::transaction const &, nano::account const &); nano::block_hash representative (secure::transaction const &, nano::block_hash const &); nano::block_hash representative_calculated (secure::transaction const &, nano::block_hash const &); - bool block_or_pruned_exists (nano::block_hash const &) const; - bool block_or_pruned_exists (secure::transaction const &, nano::block_hash const &) const; std::string block_text (char const *); std::string block_text (nano::block_hash const &); std::pair hash_root_random (secure::transaction const &) const; @@ -89,14 +77,6 @@ class ledger final bool bootstrap_weight_reached () const; static nano::epoch version (nano::block const & block); nano::epoch version (secure::transaction const & transaction, nano::block_hash const & hash) const; - uint64_t height (secure::transaction const & transaction, nano::block_hash const & hash) const; - // Returns whether there are any receivable entries for 'account' - bool receivable_any (secure::transaction const & tx, nano::account const & account) const; - nano::receivable_iterator receivable_end () const; - // Returns the next receivable entry for an account greater than 'account' - nano::receivable_iterator receivable_upper_bound (secure::transaction const & tx, nano::account const & account) const; - // Returns the next receivable entry for the account 'account' with hash greater than 'hash' - nano::receivable_iterator receivable_upper_bound (secure::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const; std::unique_ptr collect_container_info (std::string const & name) const; uint64_t cemented_count () const; uint64_t block_count () const; @@ -113,11 +93,16 @@ class ledger final bool pruning{ false }; private: - // Returns the next receivable entry equal or greater than 'key' - std::optional> receivable_lower_bound (secure::transaction const & tx, nano::account const & account, nano::block_hash const & hash) const; void initialize (nano::generate_cache_flags const &); void confirm (secure::write_transaction const & transaction, nano::block const & block); + std::unique_ptr any_impl; + std::unique_ptr confirmed_impl; + +public: + ledger_set_any & any; + ledger_set_confirmed & confirmed; + public: // Only used in tests void force_confirm (secure::write_transaction const & transaction, nano::block const & block); }; diff --git a/nano/secure/ledger_set_any.cpp b/nano/secure/ledger_set_any.cpp new file mode 100644 index 0000000000..69bcdbe0f0 --- /dev/null +++ b/nano/secure/ledger_set_any.cpp @@ -0,0 +1,213 @@ +#include +#include +#include +#include +#include +#include + +nano::ledger_set_any::ledger_set_any (nano::ledger const & ledger) : + ledger{ ledger } +{ +} + +std::optional nano::ledger_set_any::account_balance (secure::transaction const & transaction, nano::account const & account_a) const +{ + auto block = block_get (transaction, ledger.any.account_head (transaction, account_a)); + if (!block) + { + return std::nullopt; + } + return block->balance (); +} + +auto nano::ledger_set_any::account_begin (secure::transaction const & transaction) const -> account_iterator +{ + return account_lower_bound (transaction, 0); +} + +auto nano::ledger_set_any::account_end () const -> account_iterator +{ + return account_iterator{}; +} + +std::optional nano::ledger_set_any::account_get (secure::transaction const & transaction, nano::account const & account) const +{ + return ledger.store.account.get (transaction, account); +} + +nano::block_hash nano::ledger_set_any::account_head (secure::transaction const & transaction, nano::account const & account) const +{ + auto info = account_get (transaction, account); + if (!info) + { + return 0; + } + return info.value ().head; +} + +uint64_t nano::ledger_set_any::account_height (secure::transaction const & transaction, nano::account const & account) const +{ + auto head_l = account_head (transaction, account); + if (head_l.is_zero ()) + { + return 0; + } + auto block = block_get (transaction, head_l); + release_assert (block); // Head block must be in ledger + return block->sideband ().height; +} + +auto nano::ledger_set_any::account_lower_bound (secure::transaction const & transaction, nano::account const & account) const -> account_iterator +{ + auto disk = ledger.store.account.begin (transaction, account); + if (disk == ledger.store.account.end ()) + { + return account_iterator{}; + } + return account_iterator{ transaction, *this, *disk }; +} + +auto nano::ledger_set_any::account_upper_bound (secure::transaction const & transaction, nano::account const & account) const -> account_iterator +{ + return account_lower_bound (transaction, account.number () + 1); +} + +std::optional nano::ledger_set_any::block_account (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + auto block_l = block_get (transaction, hash); + if (!block_l) + { + return std::nullopt; + } + return block_l->account (); +} + +std::optional nano::ledger_set_any::block_amount (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + auto block_l = block_get (transaction, hash); + if (!block_l) + { + return std::nullopt; + } + auto block_balance = block_l->balance (); + if (block_l->previous ().is_zero ()) + { + return block_balance.number (); + } + auto previous_balance = this->block_balance (transaction, block_l->previous ()); + if (!previous_balance) + { + return std::nullopt; + } + return block_balance > previous_balance.value () ? block_balance.number () - previous_balance.value ().number () : previous_balance.value ().number () - block_balance.number (); +} + +// Balance for account containing hash +std::optional nano::ledger_set_any::block_balance (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + if (hash.is_zero ()) + { + return std::nullopt; + } + auto block = block_get (transaction, hash); + if (!block) + { + return std::nullopt; + } + return block->balance (); +} + +bool nano::ledger_set_any::block_exists (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + return ledger.store.block.exists (transaction, hash); +} + +bool nano::ledger_set_any::block_exists_or_pruned (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + if (ledger.store.pruned.exists (transaction, hash)) + { + return true; + } + return ledger.store.block.exists (transaction, hash); +} + +std::shared_ptr nano::ledger_set_any::block_get (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + return ledger.store.block.get (transaction, hash); +} + +uint64_t nano::ledger_set_any::block_height (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + auto block = block_get (transaction, hash); + if (!block) + { + return 0; + } + return block->sideband ().height; +} + +std::optional> nano::ledger_set_any::receivable_lower_bound (secure::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const +{ + auto result = ledger.store.pending.begin (transaction, { account, hash }); + if (result == ledger.store.pending.end ()) + { + return std::nullopt; + } + return *result; +} + +auto nano::ledger_set_any::receivable_end () const -> receivable_iterator +{ + return receivable_iterator{}; +} + +bool nano::ledger_set_any::receivable_exists (secure::transaction const & transaction, nano::account const & account) const +{ + auto next = receivable_upper_bound (transaction, account, 0); + return next != receivable_end (); +} + +auto nano::ledger_set_any::receivable_upper_bound (secure::transaction const & transaction, nano::account const & account) const -> receivable_iterator +{ + return receivable_iterator{ transaction, *this, receivable_lower_bound (transaction, account.number () + 1, 0) }; +} + +auto nano::ledger_set_any::receivable_upper_bound (secure::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const -> receivable_iterator +{ + auto result = receivable_lower_bound (transaction, account, hash.number () + 1); + if (!result || result.value ().first.account != account) + { + return receivable_iterator{ transaction, *this, std::nullopt }; + } + return receivable_iterator{ transaction, *this, result }; +} + +std::optional nano::ledger_set_any::block_successor (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + return block_successor (transaction, { hash, hash }); +} + +std::optional nano::ledger_set_any::block_successor (secure::transaction const & transaction, nano::qualified_root const & root) const +{ + if (!root.previous ().is_zero ()) + { + return ledger.store.block.successor (transaction, root.previous ()); + } + else + { + auto info = account_get (transaction, root.root ().as_account ()); + if (info) + { + return info->open_block; + } + else + { + return std::nullopt; + } + } +} + +std::optional nano::ledger_set_any::pending_get (secure::transaction const & transaction, nano::pending_key const & key) const +{ + return ledger.store.pending.get (transaction, key); +} diff --git a/nano/secure/ledger_set_any.hpp b/nano/secure/ledger_set_any.hpp new file mode 100644 index 0000000000..c1d032efdf --- /dev/null +++ b/nano/secure/ledger_set_any.hpp @@ -0,0 +1,79 @@ +#pragma once + +#include +#include + +#include + +namespace nano +{ +class account_info; +class block; +class block_hash; +class ledger; +class pending_info; +class pending_key; +class qualified_root; +} +namespace nano::store +{ +class transaction; +} + +namespace nano +{ +class ledger_set_any +{ +public: + using account_iterator = nano::account_iterator; + using receivable_iterator = nano::receivable_iterator; + + ledger_set_any (nano::ledger const & ledger); + +public: // Operations on accounts + std::optional account_balance (secure::transaction const & transaction, nano::account const & account) const; + account_iterator account_begin (secure::transaction const & transaction) const; + account_iterator account_end () const; + std::optional account_get (secure::transaction const & transaction, nano::account const & account) const; + nano::block_hash account_head (secure::transaction const & transaction, nano::account const & account) const; + uint64_t account_height (secure::transaction const & transaction, nano::account const & account) const; + // Returns the next account entry equal or greater than 'account' + // Mirrors std::map::lower_bound + account_iterator account_lower_bound (secure::transaction const & transaction, nano::account const & account) const; + // Returns the next account entry greater than 'account' + // Returns account_lower_bound (transaction, account + 1) + // Mirrors std::map::upper_bound + account_iterator account_upper_bound (secure::transaction const & transaction, nano::account const & account) const; + +public: // Operations on blocks + std::optional block_account (secure::transaction const & transaction, nano::block_hash const & hash) const; + std::optional block_amount (secure::transaction const & transaction, nano::block_hash const & hash) const; + std::optional block_balance (secure::transaction const & transaction, nano::block_hash const & hash) const; + bool block_exists (secure::transaction const & transaction, nano::block_hash const & hash) const; + bool block_exists_or_pruned (secure::transaction const & transaction, nano::block_hash const & hash) const; + std::shared_ptr block_get (secure::transaction const & transaction, nano::block_hash const & hash) const; + uint64_t block_height (secure::transaction const & transaction, nano::block_hash const & hash) const; + std::optional block_successor (secure::transaction const & transaction, nano::block_hash const & hash) const; + std::optional block_successor (secure::transaction const & transaction, nano::qualified_root const & root) const; + +public: // Operations on pending entries + std::optional pending_get (secure::transaction const & transaction, nano::pending_key const & key) const; + bool receivable_any (secure::transaction const & transaction, nano::account const & account) const; + receivable_iterator receivable_end () const; + bool receivable_exists (secure::transaction const & transaction, nano::account const & account) const; + // Returns the next receivable entry equal or greater than 'key' + // Mirrors std::map::lower_bound + std::optional> receivable_lower_bound (secure::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const; + // Returns the next receivable entry for an account greater than 'account' + // Returns receivable_lower_bound (transaction, account + 1, 0) + // Mirrors std::map::upper_bound + receivable_iterator receivable_upper_bound (secure::transaction const & transaction, nano::account const & account) const; + // Returns the next receivable entry for the account 'account' with hash greater than 'hash' + // Returns receivable_lower_bound (transaction, account + 1, hash) + // Mirrors std::map::upper_bound + receivable_iterator receivable_upper_bound (secure::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const; + +private: + nano::ledger const & ledger; +}; // class ledger_set_any +} // namespace nano diff --git a/nano/secure/ledger_set_confirmed.cpp b/nano/secure/ledger_set_confirmed.cpp new file mode 100644 index 0000000000..066e2eacbd --- /dev/null +++ b/nano/secure/ledger_set_confirmed.cpp @@ -0,0 +1,121 @@ +#include +#include +#include +#include +#include +#include +#include + +nano::ledger_set_confirmed::ledger_set_confirmed (nano::ledger const & ledger) : + ledger{ ledger } +{ +} + +std::optional nano::ledger_set_confirmed::account_balance (secure::transaction const & transaction, nano::account const & account_a) const +{ + auto block = block_get (transaction, account_head (transaction, account_a)); + if (!block) + { + return std::nullopt; + } + return block->balance (); +} + +nano::block_hash nano::ledger_set_confirmed::account_head (secure::transaction const & transaction, nano::account const & account) const +{ + auto info = ledger.store.confirmation_height.get (transaction, account); + if (!info) + { + return 0; + } + return info.value ().frontier; +} + +uint64_t nano::ledger_set_confirmed::account_height (secure::transaction const & transaction, nano::account const & account) const +{ + auto head_l = account_head (transaction, account); + if (head_l.is_zero ()) + { + return 0; + } + auto block = block_get (transaction, head_l); + release_assert (block); // Head block must be in ledger + return block->sideband ().height; +} + +// Balance for account containing hash +std::optional nano::ledger_set_confirmed::block_balance (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + if (hash.is_zero ()) + { + return std::nullopt; + } + auto block = block_get (transaction, hash); + if (!block) + { + return std::nullopt; + } + return block->balance (); +} + +bool nano::ledger_set_confirmed::block_exists (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + return block_get (transaction, hash) != nullptr; +} + +bool nano::ledger_set_confirmed::block_exists_or_pruned (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + if (ledger.store.pruned.exists (transaction, hash)) + { + return true; + } + return block_exists (transaction, hash); +} + +std::shared_ptr nano::ledger_set_confirmed::block_get (secure::transaction const & transaction, nano::block_hash const & hash) const +{ + auto block = ledger.store.block.get (transaction, hash); + if (!block) + { + return nullptr; + } + auto info = ledger.store.confirmation_height.get (transaction, block->account ()); + if (!info) + { + return nullptr; + } + return block->sideband ().height <= info.value ().height ? block : nullptr; +} +auto nano::ledger_set_confirmed::receivable_end () const -> receivable_iterator +{ + return receivable_iterator{}; +} + +auto nano::ledger_set_confirmed::receivable_upper_bound (secure::transaction const & transaction, nano::account const & account) const -> receivable_iterator +{ + return receivable_iterator{ transaction, *this, receivable_lower_bound (transaction, account.number () + 1, 0) }; +} + +auto nano::ledger_set_confirmed::receivable_upper_bound (secure::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const -> receivable_iterator +{ + auto result = receivable_lower_bound (transaction, account, hash.number () + 1); + if (!result || result.value ().first.account != account) + { + return receivable_iterator{ transaction, *this, std::nullopt }; + } + return receivable_iterator{ transaction, *this, result }; +} + +std::optional> nano::ledger_set_confirmed::receivable_lower_bound (secure::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const +{ + auto result = ledger.store.pending.begin (transaction, { account, hash }); + while (result != ledger.store.pending.end () && !block_exists (transaction, result->first.hash)) + { + ++result; + } + if (result == ledger.store.pending.end ()) + { + return std::nullopt; + } + return *result; +} diff --git a/nano/secure/ledger_set_confirmed.hpp b/nano/secure/ledger_set_confirmed.hpp new file mode 100644 index 0000000000..87ab89a301 --- /dev/null +++ b/nano/secure/ledger_set_confirmed.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include + +#include + +namespace nano +{ +class account_info; +class block; +class block_hash; +class ledger; +class qualified_root; +} +namespace nano::store +{ +class transaction; +} + +namespace nano +{ +class ledger_set_confirmed +{ +public: + using receivable_iterator = nano::receivable_iterator; + + ledger_set_confirmed (nano::ledger const & ledger); + +public: // Operations on accounts + std::optional account_balance (secure::transaction const & transaction, nano::account const & account) const; + nano::block_hash account_head (secure::transaction const & transaction, nano::account const & account) const; + uint64_t account_height (secure::transaction const & transaction, nano::account const & account) const; + +public: // Operations on blocks + std::optional block_balance (secure::transaction const & transaction, nano::block_hash const & hash) const; + bool block_exists (secure::transaction const & transaction, nano::block_hash const & hash) const; + bool block_exists_or_pruned (secure::transaction const & transaction, nano::block_hash const & hash) const; + std::shared_ptr block_get (secure::transaction const & transaction, nano::block_hash const & hash) const; + +public: // Operations on pending entries + receivable_iterator receivable_end () const; + // Returns the next receivable entry equal or greater than 'key' + // Mirrors std::map::lower_bound + std::optional> receivable_lower_bound (secure::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const; + // Returns the next receivable entry for an account greater than 'account' + // Returns receivable_lower_bound (transaction, account + 1, 0) + // Mirrors std::map::upper_bound + receivable_iterator receivable_upper_bound (secure::transaction const & transaction, nano::account const & account) const; + // Returns the next receivable entry for the account 'account' with hash greater than 'hash' + // Returns receivable_lower_bound (transaction, account + 1, hash) + // Mirrors std::map::upper_bound + receivable_iterator receivable_upper_bound (secure::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const; + +private: + nano::ledger const & ledger; +}; // class ledger_set_confirmed +} // namespace nano diff --git a/nano/secure/pending_info.cpp b/nano/secure/pending_info.cpp index 72c8ed3735..a9d52588a6 100644 --- a/nano/secure/pending_info.cpp +++ b/nano/secure/pending_info.cpp @@ -71,47 +71,3 @@ bool nano::pending_key::operator< (nano::pending_key const & other_a) const { return account == other_a.account ? hash < other_a.hash : account < other_a.account; } - -nano::receivable_iterator::receivable_iterator (nano::ledger const & ledger, nano::secure::transaction const & tx, std::optional> item) : - ledger{ &ledger }, - tx{ &tx }, - item{ item } -{ - if (item.has_value ()) - { - account = item.value ().first.account; - } -} - -bool nano::receivable_iterator::operator== (receivable_iterator const & other) const -{ - debug_assert (ledger == nullptr || other.ledger == nullptr || ledger == other.ledger); - debug_assert (tx == nullptr || other.tx == nullptr || tx == other.tx); - debug_assert (account.is_zero () || other.account.is_zero () || account == other.account); - return item == other.item; -} - -bool nano::receivable_iterator::operator!= (receivable_iterator const & other) const -{ - return !(*this == other); -} - -nano::receivable_iterator & nano::receivable_iterator::operator++ () -{ - item = ledger->receivable_lower_bound (*tx, item.value ().first.account, item.value ().first.hash.number () + 1); - if (item && item.value ().first.account != account) - { - item = std::nullopt; - } - return *this; -} - -std::pair const & nano::receivable_iterator::operator* () const -{ - return item.value (); -} - -std::pair const * nano::receivable_iterator::operator->() const -{ - return &item.value (); -} diff --git a/nano/secure/pending_info.hpp b/nano/secure/pending_info.hpp index 30faff2d11..2d57df9ba2 100644 --- a/nano/secure/pending_info.hpp +++ b/nano/secure/pending_info.hpp @@ -60,27 +60,7 @@ class pending_key final return os; } }; - -// This class iterates receivable enttries for an account -class receivable_iterator -{ -public: - receivable_iterator () = default; - receivable_iterator (nano::ledger const & ledger, nano::secure::transaction const & tx, std::optional> item); - bool operator== (receivable_iterator const & other) const; - bool operator!= (receivable_iterator const & other) const; - // Advances to the next receivable entry for the same account - receivable_iterator & operator++ (); - std::pair const & operator* () const; - std::pair const * operator->() const; - -private: - nano::ledger const * ledger{ nullptr }; - nano::secure::transaction const * tx{ nullptr }; - nano::account account{ 0 }; - std::optional> item; -}; -} // namespace nano +} namespace std { diff --git a/nano/secure/receivable_iterator.cpp b/nano/secure/receivable_iterator.cpp new file mode 100644 index 0000000000..c0246c59c7 --- /dev/null +++ b/nano/secure/receivable_iterator.cpp @@ -0,0 +1,6 @@ +#include +#include +#include + +template class nano::receivable_iterator; +template class nano::receivable_iterator; diff --git a/nano/secure/receivable_iterator.hpp b/nano/secure/receivable_iterator.hpp new file mode 100644 index 0000000000..087622640a --- /dev/null +++ b/nano/secure/receivable_iterator.hpp @@ -0,0 +1,38 @@ +#pragma once +#include +#include + +#include +#include + +namespace nano +{ +// This class iterates receivable enttries for an account +template +class receivable_iterator +{ +public: + // Creates an end () iterator + // 'transaction' and 'set' are nullptr so all end () iterators compare equal + // 'account' is set to 0 so all end () iterators compare equal. + receivable_iterator (); + // Constructs an iterator to the first equal to pending_key.account and equal or greater than pending_key.hash + receivable_iterator (secure::transaction const & transaction, Set const & set, std::optional> const & item); + bool operator== (receivable_iterator const & other) const; + +public: // Dereferencing, undefined behavior when called on an end () iterator + // Advances to the next receivable entry + // This will not advance past the account in the pending_key it was constructed with + // Not advancing past an account is intentional to prevent + // If there are no more pending entries, convert this to an end () iterator. + receivable_iterator & operator++ (); + std::pair const & operator* () const; + std::pair const * operator->() const; + +private: + secure::transaction const * transaction; + Set const * set{ nullptr }; + nano::account account{ 0 }; + std::optional> item; +}; +} diff --git a/nano/secure/receivable_iterator_impl.hpp b/nano/secure/receivable_iterator_impl.hpp new file mode 100644 index 0000000000..b2cbebef72 --- /dev/null +++ b/nano/secure/receivable_iterator_impl.hpp @@ -0,0 +1,50 @@ +#include +#include + +template +nano::receivable_iterator::receivable_iterator () +{ +} + +template +nano::receivable_iterator::receivable_iterator (secure::transaction const & transaction, Set const & set, std::optional> const & item) : + transaction{ &transaction }, + set{ &set }, + item{ item } +{ + if (item.has_value ()) + { + account = item.value ().first.account; + } +} + +template +bool nano::receivable_iterator::operator== (receivable_iterator const & other) const +{ + debug_assert (set == nullptr || other.set == nullptr || set == other.set); + debug_assert (account.is_zero () || other.account.is_zero () || account == other.account); + return item == other.item; +} + +template +auto nano::receivable_iterator::operator++ () -> receivable_iterator & +{ + item = set->receivable_lower_bound (*transaction, item.value ().first.account, item.value ().first.hash.number () + 1); + if (item && item.value ().first.account != account) + { + item = std::nullopt; + } + return *this; +} + +template +std::pair const & nano::receivable_iterator::operator* () const +{ + return item.value (); +} + +template +std::pair const * nano::receivable_iterator::operator->() const +{ + return &item.value (); +} diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index fe22bb3868..dccc4c4a16 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -50,8 +52,8 @@ TEST (system, generate_mass_activity) system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); uint32_t count (20); system.generate_mass_activity (count, *system.nodes[0]); - auto transaction (system.nodes[0]->store.tx_begin_read ()); - for (auto i (system.nodes[0]->store.account.begin (transaction)), n (system.nodes[0]->store.account.end ()); i != n; ++i) + auto transaction (system.nodes[0]->ledger.tx_begin_read ()); + for (auto i (system.nodes[0]->ledger.any.account_begin (transaction)), n (system.nodes[0]->ledger.any.account_end ()); i != n; ++i) { } } @@ -72,8 +74,8 @@ TEST (system, generate_mass_activity_long) std::cout << "count override due to env variable set, count=" << count << std::endl; } system.generate_mass_activity (count, *system.nodes[0]); - auto transaction (system.nodes[0]->store.tx_begin_read ()); - for (auto i (system.nodes[0]->store.account.begin (transaction)), n (system.nodes[0]->store.account.end ()); i != n; ++i) + auto transaction (system.nodes[0]->ledger.tx_begin_read ()); + for (auto i (system.nodes[0]->ledger.any.account_begin (transaction)), n (system.nodes[0]->ledger.any.account_end ()); i != n; ++i) { } system.stop (); @@ -104,7 +106,7 @@ TEST (system, receive_while_synchronizing) node1->workers.add_timed_task (std::chrono::steady_clock::now () + std::chrono::milliseconds (200), ([&system, &key] () { auto hash (system.wallet (0)->send_sync (nano::dev::genesis_key.pub, key.pub, system.nodes[0]->config.receive_minimum.number ())); auto transaction = system.nodes[0]->ledger.tx_begin_read (); - auto block = system.nodes[0]->ledger.block (transaction, hash); + auto block = system.nodes[0]->ledger.any.block_get (transaction, hash); std::string block_text; block->serialize_json (block_text); })); @@ -178,8 +180,8 @@ TEST (ledger, deep_account_compute) { std::cerr << i << ' '; } - ledger.account (transaction, sprevious); - ledger.balance (transaction, rprevious); + ledger.any.block_account (transaction, sprevious); + ledger.any.block_balance (transaction, rprevious); } } @@ -687,11 +689,11 @@ TEST (confirmation_height, many_accounts_single_confirmation) election->force_confirm (); } - ASSERT_TIMELY (120s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), last_open_hash)); + ASSERT_TIMELY (120s, node->ledger.confirmed.block_exists_or_pruned (node->ledger.tx_begin_read (), last_open_hash)); // All frontiers (except last) should have 2 blocks and both should be confirmed - auto transaction = node->store.tx_begin_read (); - for (auto i (node->store.account.begin (transaction)), n (node->store.account.end ()); i != n; ++i) + auto transaction = node->ledger.tx_begin_read (); + for (auto i (node->ledger.any.account_begin (transaction)), n (node->ledger.any.account_end ()); i != n; ++i) { auto & account = i->first; auto & account_info = i->second; @@ -908,17 +910,17 @@ TEST (confirmation_height, long_chains) election->force_confirm (); } - ASSERT_TIMELY (30s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), receive1->hash ())); + ASSERT_TIMELY (30s, node->ledger.confirmed.block_exists_or_pruned (node->ledger.tx_begin_read (), receive1->hash ())); auto transaction = node->ledger.tx_begin_read (); - auto info = node->ledger.account_info (transaction, nano::dev::genesis_key.pub); + auto info = node->ledger.any.account_get (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info); nano::confirmation_height_info confirmation_height_info; ASSERT_FALSE (node->store.confirmation_height.get (transaction, nano::dev::genesis_key.pub, confirmation_height_info)); ASSERT_EQ (num_blocks + 2, confirmation_height_info.height); ASSERT_EQ (num_blocks + 3, info->block_count); // Includes the unpocketed send - info = node->ledger.account_info (transaction, key1.pub); + info = node->ledger.any.account_get (transaction, key1.pub); ASSERT_TRUE (info); ASSERT_FALSE (node->store.confirmation_height.get (transaction, key1.pub, confirmation_height_info)); ASSERT_EQ (num_blocks + 1, confirmation_height_info.height); @@ -1750,9 +1752,9 @@ TEST (node, mass_epoch_upgrader) ASSERT_EQ (expected_blocks, node.ledger.block_count ()); // Check upgrade { - auto transaction (node.store.tx_begin_read ()); + auto transaction (node.ledger.tx_begin_read ()); size_t block_count_sum = 0; - for (auto i (node.store.account.begin (transaction)); i != node.store.account.end (); ++i) + for (auto i (node.ledger.any.account_begin (transaction)); i != node.ledger.any.account_end (); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_1); @@ -1964,7 +1966,7 @@ TEST (node, aggressive_flooding) auto all_received = [&nodes_wallets] () { return std::all_of (nodes_wallets.begin (), nodes_wallets.end (), [] (auto const & node_wallet) { auto local_representative (node_wallet.second->store.representative (node_wallet.first->wallets.tx_begin_read ())); - return node_wallet.first->ledger.account_balance (node_wallet.first->ledger.tx_begin_read (), local_representative) > 0; + return node_wallet.first->ledger.any.account_balance (node_wallet.first->ledger.tx_begin_read (), local_representative) > 0; }); }; @@ -1983,11 +1985,11 @@ TEST (node, aggressive_flooding) block = builder.make_block () .account (nano::dev::genesis_key.pub) .representative (nano::dev::genesis_key.pub) - .previous (node1.ledger.latest (transaction, nano::dev::genesis_key.pub)) - .balance (node1.ledger.account_balance (transaction, nano::dev::genesis_key.pub) - 1) + .previous (node1.ledger.any.account_head (transaction, nano::dev::genesis_key.pub)) + .balance (node1.ledger.any.account_balance (transaction, nano::dev::genesis_key.pub).value ().number () - 1) .link (nano::dev::genesis_key.pub) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*node1.work_generate_blocking (node1.ledger.latest (transaction, nano::dev::genesis_key.pub))) + .work (*node1.work_generate_blocking (node1.ledger.any.account_head (transaction, nano::dev::genesis_key.pub))) .build (); } // Processing locally goes through the aggressive block flooding path @@ -2070,14 +2072,14 @@ TEST (node, wallet_create_block_confirm_conflicts) // Call block confirm on the top level send block which will confirm everything underneath on both accounts. { - auto block = node->ledger.block (node->ledger.tx_begin_read (), latest); + auto block = node->ledger.any.block_get (node->ledger.tx_begin_read (), latest); node->scheduler.manual.push (block); std::shared_ptr election; ASSERT_TIMELY (10s, (election = node->active.election (block->qualified_root ())) != nullptr); election->force_confirm (); } - ASSERT_TIMELY (120s, node->ledger.block_confirmed (node->ledger.tx_begin_read (), latest) && node->confirming_set.size () == 0); + ASSERT_TIMELY (120s, node->ledger.confirmed.block_exists_or_pruned (node->ledger.tx_begin_read (), latest) && node->confirming_set.size () == 0); done = true; t.join (); } diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 87115b7550..c8810eda75 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -302,8 +303,8 @@ std::shared_ptr nano::test::upgrade_epoch (nano::work_pool & auto transaction = ledger_a.tx_begin_write (); auto dev_genesis_key = nano::dev::genesis_key; auto account = dev_genesis_key.pub; - auto latest = ledger_a.latest (transaction, account); - auto balance = ledger_a.account_balance (transaction, account); + auto latest = ledger_a.any.account_head (transaction, account); + auto balance = ledger_a.any.account_balance (transaction, account).value_or (0); nano::state_block_builder builder; std::error_code ec; @@ -445,7 +446,7 @@ void nano::test::system::generate_rollback (nano::node & node_a, std::vector::max () > accounts_a.size ()); auto index (random_pool::generate_word32 (0, static_cast (accounts_a.size () - 1))); auto account (accounts_a[index]); - auto info = node_a.ledger.account_info (transaction, account); + auto info = node_a.ledger.any.account_get (transaction, account); if (info) { auto hash (info->open_block); @@ -472,10 +473,10 @@ void nano::test::system::generate_receive (nano::node & node_a) auto transaction = node_a.ledger.tx_begin_read (); nano::account random_account; random_pool::generate_block (random_account.bytes.data (), sizeof (random_account.bytes)); - auto item = node_a.ledger.receivable_upper_bound (transaction, random_account); - if (item != node_a.ledger.receivable_end ()) + auto item = node_a.ledger.any.receivable_upper_bound (transaction, random_account); + if (item != node_a.ledger.any.receivable_end ()) { - send_block = node_a.ledger.block (transaction, item->first.hash); + send_block = node_a.ledger.any.block_get (transaction, item->first.hash); } } if (send_block != nullptr) @@ -524,7 +525,7 @@ nano::account nano::test::system::get_random_account (std::vector nano::uint128_t nano::test::system::get_random_amount (secure::transaction const & transaction_a, nano::node & node_a, nano::account const & account_a) { - nano::uint128_t balance (node_a.ledger.account_balance (transaction_a, account_a)); + nano::uint128_t balance = node_a.ledger.any.account_balance (transaction_a, account_a).value_or (0).number (); nano::uint128_union random_amount; nano::random_pool::generate_block (random_amount.bytes.data (), sizeof (random_amount.bytes)); return (((nano::uint256_t{ random_amount.number () } * balance) / nano::uint256_t{ std::numeric_limits::max () }).convert_to ()); @@ -539,12 +540,12 @@ void nano::test::system::generate_send_existing (nano::node & node_a, std::vecto nano::account account; random_pool::generate_block (account.bytes.data (), sizeof (account.bytes)); auto transaction = node_a.ledger.tx_begin_read (); - store::iterator entry (node_a.store.account.begin (transaction, account)); - if (entry == node_a.store.account.end ()) + auto entry = node_a.ledger.any.account_lower_bound (transaction, account); + if (entry == node_a.ledger.any.account_end ()) { - entry = node_a.store.account.begin (transaction); + entry = node_a.ledger.any.account_lower_bound (transaction, 0); } - debug_assert (entry != node_a.store.account.end ()); + debug_assert (entry != node_a.ledger.any.account_end ()); destination = nano::account (entry->first); source = get_random_account (accounts_a); amount = get_random_amount (transaction, node_a, source); diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 9e1469afa0..d8500fdf47 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -7,7 +7,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -134,7 +135,7 @@ bool nano::test::block_or_pruned_all_exists (nano::node & node, std::vector