Reduce coupling to store.block.exists by using ledger::block_exists interface.

This commit is contained in:
Colin LeMahieu 2024-03-05 14:31:14 +00:00
commit d68da31abc
No known key found for this signature in database
GPG key ID: 43708520C8DFB938
14 changed files with 77 additions and 71 deletions

View file

@ -659,13 +659,13 @@ TEST (bootstrap_processor, push_diamond_pruning)
auto transaction (node1->store.tx_begin_write ());
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->store.block.exists (transaction, nano::dev::genesis->hash ()));
ASSERT_FALSE (node1->store.block.exists (transaction, send1->hash ()));
ASSERT_TRUE (node1->ledger.block_exists (transaction, nano::dev::genesis->hash ()));
ASSERT_FALSE (node1->ledger.block_exists (transaction, send1->hash ()));
ASSERT_TRUE (node1->store.pruned.exists (transaction, send1->hash ()));
ASSERT_FALSE (node1->store.block.exists (transaction, open->hash ()));
ASSERT_FALSE (node1->ledger.block_exists (transaction, open->hash ()));
ASSERT_TRUE (node1->store.pruned.exists (transaction, open->hash ()));
ASSERT_TRUE (node1->store.block.exists (transaction, send2->hash ()));
ASSERT_TRUE (node1->store.block.exists (transaction, receive->hash ()));
ASSERT_TRUE (node1->ledger.block_exists (transaction, send2->hash ()));
ASSERT_TRUE (node1->ledger.block_exists (transaction, receive->hash ()));
ASSERT_EQ (2, node1->ledger.cache.pruned_count);
ASSERT_EQ (5, node1->ledger.cache.block_count);
}

View file

@ -2382,7 +2382,7 @@ 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 (store.block.exists (transaction, send1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ()));
auto send2 = ledger.block (transaction, send1->hash ());
ASSERT_NE (nullptr, send2);
ASSERT_EQ (*send1, *send2);
@ -2405,7 +2405,7 @@ TEST (ledger, state_send_receive)
.work (*pool.generate (send1->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1));
ASSERT_TRUE (store.block.exists (transaction, receive1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, receive1->hash ()));
auto receive2 = ledger.block (transaction, receive1->hash ());
ASSERT_NE (nullptr, receive2);
ASSERT_EQ (*receive1, *receive2);
@ -2437,7 +2437,7 @@ TEST (ledger, state_receive)
.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.block_exists (transaction, send1->hash ()));
auto send2 = ledger.block (transaction, send1->hash ());
ASSERT_NE (nullptr, send2);
ASSERT_EQ (*send1, *send2);
@ -2455,7 +2455,7 @@ TEST (ledger, state_receive)
.work (*pool.generate (send1->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1));
ASSERT_TRUE (store.block.exists (transaction, receive1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, receive1->hash ()));
auto receive2 = ledger.block (transaction, receive1->hash ());
ASSERT_NE (nullptr, receive2);
ASSERT_EQ (*receive1, *receive2);
@ -2488,7 +2488,7 @@ 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 (store.block.exists (transaction, change1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, change1->hash ()));
auto change2 = ledger.block (transaction, change1->hash ());
ASSERT_NE (nullptr, change2);
ASSERT_EQ (*change1, *change2);
@ -2522,7 +2522,7 @@ TEST (ledger, state_open)
.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.block_exists (transaction, send1->hash ()));
auto send2 = ledger.block (transaction, send1->hash ());
ASSERT_NE (nullptr, send2);
ASSERT_EQ (*send1, *send2);
@ -2542,7 +2542,7 @@ TEST (ledger, state_open)
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1));
ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (destination.pub, send1->hash ())));
ASSERT_TRUE (store.block.exists (transaction, open1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, open1->hash ()));
auto open2 = ledger.block (transaction, open1->hash ());
ASSERT_NE (nullptr, open2);
ASSERT_EQ (*open1, *open2);
@ -2665,7 +2665,7 @@ 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 (store.block.exists (transaction, send1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ()));
auto send2 = ledger.block (transaction, send1->hash ());
ASSERT_NE (nullptr, send2);
ASSERT_EQ (*send1, *send2);
@ -2702,7 +2702,7 @@ 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 (store.block.exists (transaction, send1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ()));
auto send2 = ledger.block (transaction, send1->hash ());
ASSERT_NE (nullptr, send2);
ASSERT_EQ (*send1, *send2);
@ -2774,7 +2774,7 @@ 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 (store.block.exists (transaction, send1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ()));
auto send2 = ledger.block (transaction, send1->hash ());
ASSERT_NE (nullptr, send2);
ASSERT_EQ (*send1, *send2);
@ -2968,7 +2968,7 @@ 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 (store.block.exists (transaction, send1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ()));
auto send2 = ledger.block (transaction, send1->hash ());
ASSERT_NE (nullptr, send2);
ASSERT_EQ (*send1, *send2);
@ -3001,7 +3001,7 @@ 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 (store.block.exists (transaction, send1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ()));
auto send2 = ledger.block (transaction, send1->hash ());
ASSERT_NE (nullptr, send2);
ASSERT_EQ (*send1, *send2);
@ -3020,7 +3020,7 @@ TEST (ledger, state_receive_change)
.work (*pool.generate (send1->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1));
ASSERT_TRUE (store.block.exists (transaction, receive1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, receive1->hash ()));
auto receive2 = ledger.block (transaction, receive1->hash ());
ASSERT_NE (nullptr, receive2);
ASSERT_EQ (*receive1, *receive2);
@ -3140,7 +3140,7 @@ 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 (store.block.exists (transaction, send1->hash ()));
ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ()));
auto send2 = ledger.block (transaction, send1->hash ());
ASSERT_NE (nullptr, send2);
ASSERT_EQ (*send1, *send2);
@ -3151,7 +3151,7 @@ TEST (ledger, state_rollback_send)
ASSERT_EQ (nano::dev::genesis->account (), info->source);
ASSERT_EQ (nano::Gxrb_ratio, info->amount.number ());
ASSERT_FALSE (ledger.rollback (transaction, send1->hash ()));
ASSERT_FALSE (store.block.exists (transaction, send1->hash ()));
ASSERT_FALSE (ledger.block_exists (transaction, send1->hash ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ()));
ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ())));
@ -3195,7 +3195,7 @@ TEST (ledger, state_rollback_receive)
ASSERT_TRUE (info);
ASSERT_EQ (nano::dev::genesis->account (), info->source);
ASSERT_EQ (nano::Gxrb_ratio, info->amount.number ());
ASSERT_FALSE (store.block.exists (transaction, receive1->hash ()));
ASSERT_FALSE (ledger.block_exists (transaction, receive1->hash ()));
ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ()));
ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count);
@ -3235,8 +3235,8 @@ TEST (ledger, state_rollback_received_send)
ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), receive1->hash ())));
ASSERT_FALSE (ledger.rollback (transaction, send1->hash ()));
ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ())));
ASSERT_FALSE (store.block.exists (transaction, send1->hash ()));
ASSERT_FALSE (store.block.exists (transaction, receive1->hash ()));
ASSERT_FALSE (ledger.block_exists (transaction, send1->hash ()));
ASSERT_FALSE (ledger.block_exists (transaction, receive1->hash ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ()));
ASSERT_EQ (0, ledger.account_balance (transaction, key.pub));
@ -3265,7 +3265,7 @@ 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 (store.block.exists (transaction, change1->hash ()));
ASSERT_FALSE (ledger.block_exists (transaction, change1->hash ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ()));
ASSERT_EQ (0, ledger.weight (rep.pub));
@ -3303,7 +3303,7 @@ 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 (store.block.exists (transaction, open1->hash ()));
ASSERT_FALSE (ledger.block_exists (transaction, open1->hash ()));
ASSERT_EQ (0, ledger.account_balance (transaction, destination.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ()));
auto info = ledger.pending_info (transaction, nano::pending_key (destination.pub, send1->hash ()));
@ -3334,7 +3334,7 @@ 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 (store.block.exists (transaction, send1->hash ()));
ASSERT_FALSE (ledger.block_exists (transaction, send1->hash ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ()));
ASSERT_EQ (0, ledger.weight (rep.pub));
@ -3373,7 +3373,7 @@ 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 (store.block.exists (transaction, receive1->hash ()));
ASSERT_FALSE (ledger.block_exists (transaction, receive1->hash ()));
ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ()));
ASSERT_EQ (0, ledger.weight (rep.pub));
@ -4206,7 +4206,7 @@ TEST (ledger, unchecked_epoch)
}
node1.block_processor.add (send1);
node1.block_processor.add (open1);
ASSERT_TIMELY (5s, node1.store.block.exists (node1.store.tx_begin_read (), epoch1->hash ()));
ASSERT_TIMELY (5s, node1.ledger.block_exists (node1.store.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 ());
@ -4281,10 +4281,10 @@ 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.store.block.exists (node1.store.tx_begin_read (), epoch2->hash ()));
ASSERT_TIMELY (10s, node1.ledger.block_exists (node1.store.tx_begin_read (), epoch2->hash ()));
{
auto transaction = node1.store.tx_begin_read ();
ASSERT_FALSE (node1.store.block.exists (transaction, epoch1->hash ()));
ASSERT_FALSE (node1.ledger.block_exists (transaction, epoch1->hash ()));
auto unchecked_count = node1.unchecked.count ();
ASSERT_EQ (unchecked_count, 0);
ASSERT_EQ (unchecked_count, node1.unchecked.count ());
@ -4348,7 +4348,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.store.block.exists (node1.store.tx_begin_read (), open1->hash ()));
ASSERT_TIMELY (5s, node1.ledger.block_exists (node1.store.tx_begin_read (), open1->hash ()));
ASSERT_EQ (0, node1.unchecked.count ());
}
@ -4419,7 +4419,7 @@ TEST (ledger, unchecked_receive)
ASSERT_EQ (blocks.size (), 1);
}
node1.block_processor.add (send2);
ASSERT_TIMELY (10s, node1.store.block.exists (node1.store.tx_begin_read (), receive1->hash ()));
ASSERT_TIMELY (10s, node1.ledger.block_exists (node1.store.tx_begin_read (), receive1->hash ()));
ASSERT_EQ (0, node1.unchecked.count ());
}

View file

@ -668,8 +668,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.store.block.exists (transaction0, send1->hash ()));
ASSERT_TRUE (node2.store.block.exists (transaction1, send1->hash ()));
ASSERT_TRUE (node1.ledger.block_exists (transaction0, send1->hash ()));
ASSERT_TRUE (node2.ledger.block_exists (transaction1, send1->hash ()));
}
TEST (node, fork_flip)
@ -811,7 +811,7 @@ TEST (node, fork_bootstrap_flip)
// Insert but don't rebroadcast, simulating settled blocks
ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.store.tx_begin_write (), send1));
ASSERT_EQ (nano::block_status::progress, node2.ledger.process (node2.store.tx_begin_write (), send2));
ASSERT_TRUE (node2.store.block.exists (node2.store.tx_begin_read (), send2->hash ()));
ASSERT_TRUE (node2.ledger.block_exists (node2.store.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);
@ -820,7 +820,7 @@ TEST (node, fork_bootstrap_flip)
{
ASSERT_NO_ERROR (system0.poll ());
ASSERT_NO_ERROR (system1.poll ());
again = !node2.store.block.exists (node2.store.tx_begin_read (), send1->hash ());
again = !node2.ledger.block_exists (node2.store.tx_begin_read (), send1->hash ());
}
}
@ -972,9 +972,9 @@ TEST (node, fork_open_flip)
// check the correct blocks are in the ledgers
auto transaction1 (node1.store.tx_begin_read ());
auto transaction2 (node2.store.tx_begin_read ());
ASSERT_TRUE (node1.store.block.exists (transaction1, open1->hash ()));
ASSERT_TRUE (node2.store.block.exists (transaction2, open1->hash ()));
ASSERT_FALSE (node2.store.block.exists (transaction2, open2->hash ()));
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 ()));
}
TEST (node, coherent_observer)
@ -983,7 +983,7 @@ TEST (node, coherent_observer)
auto & node1 (*system.nodes[0]);
node1.observers.blocks.add ([&node1] (nano::election_status const & status_a, std::vector<nano::vote_with_weight_info> const &, nano::account const &, nano::uint128_t const &, bool, bool) {
auto transaction (node1.store.tx_begin_read ());
ASSERT_TRUE (node1.store.block.exists (transaction, status_a.winner->hash ()));
ASSERT_TRUE (node1.ledger.block_exists (transaction, status_a.winner->hash ()));
});
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
nano::keypair key;

View file

@ -1223,7 +1223,7 @@ TEST (wallet, receive_pruned)
}
ASSERT_EQ (1, node2.ledger.cache.pruned_count);
ASSERT_TRUE (node2.ledger.block_or_pruned_exists (send1->hash ()));
ASSERT_FALSE (node2.store.block.exists (node2.store.tx_begin_read (), send1->hash ()));
ASSERT_FALSE (node2.ledger.block_exists (node2.store.tx_begin_read (), send1->hash ()));
wallet2.insert_adhoc (key.prv, false);

View file

@ -363,14 +363,14 @@ void nano::bulk_pull_server::set_current_end ()
include_start = false;
debug_assert (request != nullptr);
auto transaction (node->store.tx_begin_read ());
if (!node->store.block.exists (transaction, request->end))
if (!node->ledger.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->store.block.exists (transaction, request->start.as_block_hash ()))
if (node->ledger.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 ());

View file

@ -192,7 +192,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (store::transaction const & t
{
case asc_pull_req::hash_type::block:
{
if (store.block.exists (transaction, request.start.as_block_hash ()))
if (ledger.block_exists (transaction, request.start.as_block_hash ()))
{
return prepare_response (transaction, id, request.start.as_block_hash (), count);
}

View file

@ -262,7 +262,7 @@ bool nano::confirmation_height_bounded::iterate (store::read_transaction const &
source = block->link ().as_block_hash ();
}
if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.store.block.exists (transaction_a, source))
if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source))
{
hit_receive = true;
reached_target = true;

View file

@ -221,7 +221,7 @@ void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_source
source = block->link ().as_block_hash ();
}
if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.store.block.exists (transaction_a, source))
if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source))
{
if (!hit_receive && !block_callback_data_a.empty ())
{

View file

@ -1432,7 +1432,7 @@ void nano::json_handler::block_account ()
if (!ec)
{
auto transaction (node.store.tx_begin_read ());
if (node.store.block.exists (transaction, hash))
if (node.ledger.block_exists (transaction, hash))
{
auto account (node.ledger.account (transaction, hash));
response_l.put ("account", account.to_account ());
@ -1652,7 +1652,7 @@ void nano::json_handler::block_create ()
else if (previous_text.is_initialized () && balance_text.is_initialized () && type == "send")
{
auto transaction (node.store.tx_begin_read ());
if (node.store.block.exists (transaction, previous) && node.ledger.balance (transaction, previous) != balance.number ())
if (node.ledger.block_exists (transaction, previous) && node.ledger.balance (transaction, previous) != balance.number ())
{
ec = nano::error_rpc::block_create_balance_mismatch;
}
@ -2605,7 +2605,7 @@ void nano::json_handler::account_history ()
{
if (!hash.decode_hex (*head_str))
{
if (node.store.block.exists (transaction, hash))
if (node.ledger.block_exists (transaction, hash))
{
account = node.ledger.account (transaction, hash);
}
@ -3198,7 +3198,7 @@ void nano::json_handler::process ()
{
std::shared_ptr<nano::state_block> block_state (std::static_pointer_cast<nano::state_block> (block));
auto transaction (rpc_l->node.store.tx_begin_read ());
if (!block_state->hashables.previous.is_zero () && !rpc_l->node.store.block.exists (transaction, block_state->hashables.previous))
if (!block_state->hashables.previous.is_zero () && !rpc_l->node.ledger.block_exists (transaction, block_state->hashables.previous))
{
rpc_l->ec = nano::error_process::gap_previous;
}
@ -5093,7 +5093,7 @@ void nano::json_handler::work_generate ()
{
// Fetch account from block if not given
auto transaction_l (node.store.tx_begin_read ());
if (node.store.block.exists (transaction_l, hash))
if (node.ledger.block_exists (transaction_l, hash))
{
account = node.ledger.account (transaction_l, hash);
}

View file

@ -696,7 +696,7 @@ nano_qt::block_viewer::block_viewer (nano_qt::wallet & wallet_a) :
if (!error)
{
auto transaction (this->wallet.node.store.tx_begin_read ());
if (this->wallet.node.store.block.exists (transaction, block))
if (this->wallet.node.ledger.block_exists (transaction, block))
{
rebroadcast->setEnabled (false);
this->wallet.node.background ([this, block] () {

View file

@ -389,7 +389,7 @@ TEST (wallet, DISABLED_process_block)
{
auto transaction (system.nodes[0]->store.tx_begin_read ());
system.deadline_set (10s);
while (system.nodes[0]->store.block.exists (transaction, send.hash ()))
while (system.nodes[0]->ledger.block_exists (transaction, send.hash ()))
{
ASSERT_NO_ERROR (system.poll ());
}

View file

@ -4292,7 +4292,7 @@ TEST (rpc, block_info_pruning)
{
auto transaction (node1->store.tx_begin_write ());
ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 1));
ASSERT_TRUE (node1->store.block.exists (transaction, receive1->hash ()));
ASSERT_TRUE (node1->ledger.block_exists (transaction, receive1->hash ()));
}
auto const rpc_ctx = add_rpc (system, node1);
// Pruned block
@ -4358,7 +4358,7 @@ TEST (rpc, pruned_exists)
{
auto transaction (node1->store.tx_begin_write ());
ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 1));
ASSERT_TRUE (node1->store.block.exists (transaction, receive1->hash ()));
ASSERT_TRUE (node1->ledger.block_exists (transaction, receive1->hash ()));
}
auto const rpc_ctx = add_rpc (system, node1);
// Pruned block
@ -6558,7 +6558,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->store.tx_begin_read (), key1.pub));
ASSERT_TRUE (node->store.block.exists (node->store.tx_begin_read (), send1->hash ()));
ASSERT_TRUE (node->ledger.block_exists (node->store.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;
@ -6582,7 +6582,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->store.tx_begin_read (), key2.pub));
ASSERT_TRUE (node->store.block.exists (node->store.tx_begin_read (), send2->hash ()));
ASSERT_TRUE (node->ledger.block_exists (node->store.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
@ -6617,7 +6617,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->store.tx_begin_read (), key1.pub));
ASSERT_TRUE (node->store.block.exists (node->store.tx_begin_read (), send1->hash ()));
ASSERT_TRUE (node->ledger.block_exists (node->store.tx_begin_read (), send1->hash ()));
wallet->insert_adhoc (key1.prv);
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
@ -6662,9 +6662,9 @@ TEST (rpc, receive_pruned)
}
ASSERT_EQ (2, node2->ledger.cache.pruned_count);
ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send1->hash ()));
ASSERT_FALSE (node2->store.block.exists (node2->store.tx_begin_read (), send1->hash ()));
ASSERT_FALSE (node2->ledger.block_exists (node2->store.tx_begin_read (), send1->hash ()));
ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send2->hash ()));
ASSERT_FALSE (node2->store.block.exists (node2->store.tx_begin_read (), send2->hash ()));
ASSERT_FALSE (node2->ledger.block_exists (node2->store.tx_begin_read (), send2->hash ()));
ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send3->hash ()));
auto const rpc_ctx = add_rpc (system, node2);

View file

@ -848,7 +848,7 @@ nano::uint128_t nano::ledger::balance (store::transaction const & transaction, n
nano::uint128_t nano::ledger::balance_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const
{
nano::uint128_t result (0);
if (pruning && !hash_a.is_zero () && !store.block.exists (transaction_a, hash_a))
if (pruning && !hash_a.is_zero () && !block_exists (transaction_a, hash_a))
{
error_a = true;
result = 0;
@ -865,6 +865,11 @@ std::shared_ptr<nano::block> nano::ledger::block (store::transaction const & tra
return store.block.get (transaction, hash);
}
bool nano::ledger::block_exists (store::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 (store::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a)
{
@ -935,7 +940,7 @@ nano::block_status nano::ledger::process (store::write_transaction const & trans
nano::block_hash nano::ledger::representative (store::transaction const & transaction_a, nano::block_hash const & hash_a)
{
auto result (representative_calculated (transaction_a, hash_a));
debug_assert (result.is_zero () || store.block.exists (transaction_a, result));
debug_assert (result.is_zero () || block_exists (transaction_a, result));
return result;
}
@ -957,12 +962,12 @@ bool nano::ledger::block_or_pruned_exists (store::transaction const & transactio
{
return true;
}
return store.block.exists (transaction_a, hash_a);
return block_exists (transaction_a, hash_a);
}
bool nano::ledger::root_exists (store::transaction const & transaction_a, nano::root const & root_a)
{
return store.block.exists (transaction_a, root_a.as_block_hash ()) || store.account.exists (transaction_a, root_a.as_account ());
return block_exists (transaction_a, root_a.as_block_hash ()) || store.account.exists (transaction_a, root_a.as_account ());
}
std::string nano::ledger::block_text (char const * hash_a)
@ -994,7 +999,7 @@ bool nano::ledger::is_send (store::transaction const & transaction_a, nano::bloc
* requires that the previous block exists in the database.
* This is because it must retrieve the balance of the previous block.
*/
debug_assert (block_a.has_sideband () || previous.is_zero () || store.block.exists (transaction_a, previous));
debug_assert (block_a.has_sideband () || previous.is_zero () || block_exists (transaction_a, previous));
bool result (false);
if (block_a.has_sideband ())
@ -1037,7 +1042,7 @@ nano::block_hash nano::ledger::block_source (store::transaction const & transact
* passed in exist in the database. This is because it will try
* to check account balances to determine if it is a send block.
*/
debug_assert (block_a.previous ().is_zero () || store.block.exists (transaction_a, block_a.previous ()));
debug_assert (block_a.previous ().is_zero () || block_exists (transaction_a, block_a.previous ()));
// If block_a.source () is nonzero, then we have our source.
// However, universal blocks will always return zero.
@ -1103,12 +1108,12 @@ nano::uint128_t nano::ledger::weight (nano::account const & account_a)
// Rollback blocks until `block_a' doesn't exist or it tries to penetrate the confirmation height
bool nano::ledger::rollback (store::write_transaction const & transaction_a, nano::block_hash const & block_a, std::vector<std::shared_ptr<nano::block>> & list_a)
{
debug_assert (store.block.exists (transaction_a, block_a));
debug_assert (block_exists (transaction_a, block_a));
auto account_l (account (transaction_a, block_a));
auto block_account_height (height (transaction_a, block_a));
rollback_visitor rollback (transaction_a, *this, list_a);
auto error (false);
while (!error && store.block.exists (transaction_a, block_a))
while (!error && block_exists (transaction_a, block_a))
{
nano::confirmation_height_info confirmation_height_info;
store.confirmation_height.get (transaction_a, account_l, confirmation_height_info);
@ -1301,7 +1306,7 @@ public:
result[0] = block_a.hashables.previous;
result[1] = block_a.hashables.link.as_block_hash ();
// ledger.is_send will check the sideband first, if block_a has a loaded sideband the check that previous block exists can be skipped
if (ledger.is_epoch_link (block_a.hashables.link) || ((block_a.has_sideband () || ledger.store.block.exists (transaction, block_a.hashables.previous)) && ledger.is_send (transaction, block_a)))
if (ledger.is_epoch_link (block_a.hashables.link) || ((block_a.has_sideband () || ledger.block_exists (transaction, block_a.hashables.previous)) && ledger.is_send (transaction, block_a)))
{
result[1].clear ();
}
@ -1436,9 +1441,9 @@ std::shared_ptr<nano::block> nano::ledger::successor (store::transaction const &
std::shared_ptr<nano::block> nano::ledger::forked_block (store::transaction const & transaction_a, nano::block const & block_a)
{
debug_assert (!store.block.exists (transaction_a, block_a.hash ()));
debug_assert (!block_exists (transaction_a, block_a.hash ()));
auto root (block_a.root ());
debug_assert (store.block.exists (transaction_a, root.as_block_hash ()) || store.account.exists (transaction_a, root.as_account ()));
debug_assert (block_exists (transaction_a, root.as_block_hash ()) || store.account.exists (transaction_a, root.as_account ()));
auto result = block (transaction_a, store.block.successor (transaction_a, root.as_block_hash ()));
if (result == nullptr)
{

View file

@ -52,6 +52,7 @@ public:
nano::uint128_t balance (store::transaction const &, nano::block_hash const &) const;
nano::uint128_t balance_safe (store::transaction const &, nano::block_hash const &, bool &) const;
std::shared_ptr<nano::block> block (store::transaction const & transaction, nano::block_hash const & hash) const;
bool block_exists (store::transaction const & transaction, nano::block_hash const & hash) const;
nano::uint128_t account_balance (store::transaction const &, nano::account const &, bool = false);
nano::uint128_t account_receivable (store::transaction const &, nano::account const &, bool = false);
nano::uint128_t weight (nano::account const &);