Skip to content

Commit

Permalink
Block store break up (#3329)
Browse files Browse the repository at this point in the history
As part of the issue #3255:
* Moves out version methods from the block store class
* Splits block_store class into store/block_store classes
  • Loading branch information
thsfs committed Jun 14, 2021
1 parent df5072e commit 4d915c1
Show file tree
Hide file tree
Showing 69 changed files with 1,438 additions and 1,228 deletions.
254 changes: 127 additions & 127 deletions nano/core_test/block_store.cpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions nano/core_test/bootstrap.cpp
Expand Up @@ -441,13 +441,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, latest));
ASSERT_FALSE (node1->store.block_exists (transaction, send1->hash ()));
ASSERT_TRUE (node1->store.block.exists (transaction, latest));
ASSERT_FALSE (node1->store.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->store.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->store.block.exists (transaction, send2->hash ()));
ASSERT_TRUE (node1->store.block.exists (transaction, receive->hash ()));
ASSERT_EQ (2, node1->ledger.cache.pruned_count);
ASSERT_EQ (5, node1->ledger.cache.block_count);
}
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/confirmation_height.cpp
Expand Up @@ -682,12 +682,12 @@ TEST (confirmation_height, conflict_rollback_cemented)
// Force blocks to be cemented on both nodes
{
auto transaction (node1->store.tx_begin_write ());
ASSERT_TRUE (node1->store.block_exists (transaction, publish1.block->hash ()));
ASSERT_TRUE (node1->store.block.exists (transaction, publish1.block->hash ()));
node1->store.confirmation_height.put (transaction, nano::genesis_account, nano::confirmation_height_info{ 2, send2->hash () });
}
{
auto transaction (node2->store.tx_begin_write ());
ASSERT_TRUE (node2->store.block_exists (transaction, publish2.block->hash ()));
ASSERT_TRUE (node2->store.block.exists (transaction, publish2.block->hash ()));
node2->store.confirmation_height.put (transaction, nano::genesis_account, nano::confirmation_height_info{ 2, send2->hash () });
}

Expand Down
6 changes: 3 additions & 3 deletions nano/core_test/gap_cache.cpp
Expand Up @@ -106,7 +106,7 @@ TEST (gap_cache, two_dependencies)
node1.block_processor.flush ();
ASSERT_EQ (0, node1.gap_cache.size ());
auto transaction (node1.store.tx_begin_read ());
ASSERT_TRUE (node1.store.block_exists (transaction, send1->hash ()));
ASSERT_TRUE (node1.store.block_exists (transaction, send2->hash ()));
ASSERT_TRUE (node1.store.block_exists (transaction, open->hash ()));
ASSERT_TRUE (node1.store.block.exists (transaction, send1->hash ()));
ASSERT_TRUE (node1.store.block.exists (transaction, send2->hash ()));
ASSERT_TRUE (node1.store.block.exists (transaction, open->hash ()));
}
206 changes: 103 additions & 103 deletions nano/core_test/ledger.cpp

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions nano/core_test/node.cpp
Expand Up @@ -113,7 +113,7 @@ TEST (node, representative)
auto block1 (system.nodes[0]->rep_block (nano::dev_genesis_key.pub));
{
auto transaction (system.nodes[0]->store.tx_begin_read ());
ASSERT_TRUE (system.nodes[0]->ledger.store.block_exists (transaction, block1));
ASSERT_TRUE (system.nodes[0]->ledger.store.block.exists (transaction, block1));
}
nano::keypair key;
ASSERT_TRUE (system.nodes[0]->rep_block (key.pub).is_zero ());
Expand Down Expand Up @@ -1179,8 +1179,8 @@ TEST (node, fork_keep)
auto winner (*election1->tally ().begin ());
ASSERT_EQ (*send1, *winner.second);
ASSERT_EQ (nano::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.store.block.exists (transaction0, send1->hash ()));
ASSERT_TRUE (node2.store.block.exists (transaction1, send1->hash ()));
}

TEST (node, fork_flip)
Expand Down Expand Up @@ -1353,15 +1353,15 @@ TEST (node, fork_bootstrap_flip)
// Insert but don't rebroadcast, simulating settled blocks
ASSERT_EQ (nano::process_result::progress, node1.ledger.process (node1.store.tx_begin_write (), *send1).code);
ASSERT_EQ (nano::process_result::progress, node2.ledger.process (node2.store.tx_begin_write (), *send2).code);
ASSERT_TRUE (node2.store.block_exists (node2.store.tx_begin_read (), send2->hash ()));
ASSERT_TRUE (node2.store.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);
system1.deadline_set (50s);
while (again)
{
ASSERT_NO_ERROR (system0.poll ());
ASSERT_NO_ERROR (system1.poll ());
again = !node2.store.block_exists (node2.store.tx_begin_read (), send1->hash ());
again = !node2.store.block.exists (node2.store.tx_begin_read (), send1->hash ());
}
}

Expand Down Expand Up @@ -1488,9 +1488,9 @@ TEST (node, fork_open_flip)
auto winner (*election1->tally ().begin ());
ASSERT_EQ (*open1, *winner.second);
ASSERT_EQ (nano::genesis_amount - 1, winner.first);
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.store.block.exists (transaction1, open1->hash ()));
ASSERT_TRUE (node2.store.block.exists (transaction2, open1->hash ()));
ASSERT_FALSE (node2.store.block.exists (transaction2, open2->hash ()));
}

TEST (node, coherent_observer)
Expand All @@ -1499,7 +1499,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) {
auto transaction (node1.store.tx_begin_read ());
ASSERT_TRUE (node1.store.block_exists (transaction, status_a.winner->hash ()));
ASSERT_TRUE (node1.store.block.exists (transaction, status_a.winner->hash ()));
});
system.wallet (0)->insert_adhoc (nano::dev_genesis_key.prv);
nano::keypair key;
Expand Down Expand Up @@ -3172,8 +3172,8 @@ TEST (node, epoch_conflict_confirm)
ASSERT_TIMELY (5s, node0->active.empty ());
{
auto transaction (node0->store.tx_begin_read ());
ASSERT_TRUE (node0->ledger.store.block_exists (transaction, change->hash ()));
ASSERT_TRUE (node0->ledger.store.block_exists (transaction, epoch_open->hash ()));
ASSERT_TRUE (node0->ledger.store.block.exists (transaction, change->hash ()));
ASSERT_TRUE (node0->ledger.store.block.exists (transaction, epoch_open->hash ()));
}
}

Expand Down Expand Up @@ -3372,14 +3372,14 @@ TEST (node, block_processor_signatures)
node1.block_processor.force (send5);
node1.block_processor.flush ();
auto transaction (node1.store.tx_begin_read ());
ASSERT_TRUE (node1.store.block_exists (transaction, send1->hash ()));
ASSERT_TRUE (node1.store.block_exists (transaction, send2->hash ()));
ASSERT_TRUE (node1.store.block_exists (transaction, send3->hash ()));
ASSERT_FALSE (node1.store.block_exists (transaction, send4->hash ()));
ASSERT_FALSE (node1.store.block_exists (transaction, send5->hash ()));
ASSERT_TRUE (node1.store.block_exists (transaction, receive1->hash ()));
ASSERT_TRUE (node1.store.block_exists (transaction, receive2->hash ()));
ASSERT_FALSE (node1.store.block_exists (transaction, receive3->hash ()));
ASSERT_TRUE (node1.store.block.exists (transaction, send1->hash ()));
ASSERT_TRUE (node1.store.block.exists (transaction, send2->hash ()));
ASSERT_TRUE (node1.store.block.exists (transaction, send3->hash ()));
ASSERT_FALSE (node1.store.block.exists (transaction, send4->hash ()));
ASSERT_FALSE (node1.store.block.exists (transaction, send5->hash ()));
ASSERT_TRUE (node1.store.block.exists (transaction, receive1->hash ()));
ASSERT_TRUE (node1.store.block.exists (transaction, receive2->hash ()));
ASSERT_FALSE (node1.store.block.exists (transaction, receive3->hash ()));
}

/*
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/processor_service.cpp
@@ -1,7 +1,7 @@
#include <nano/lib/stats.hpp>
#include <nano/lib/work.hpp>
#include <nano/secure/blockstore.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/store.hpp>
#include <nano/secure/utility.hpp>
#include <nano/test_common/testutil.hpp>

Expand Down
10 changes: 5 additions & 5 deletions nano/core_test/wallet.cpp
Expand Up @@ -185,7 +185,7 @@ TEST (wallet, spend_all_one)
auto transaction (node1.store.tx_begin_read ());
node1.store.account.get (transaction, nano::dev_genesis_key.pub, info2);
ASSERT_NE (latest1, info2.head);
auto block (node1.store.block_get (transaction, info2.head));
auto block (node1.store.block.get (transaction, info2.head));
ASSERT_NE (nullptr, block);
ASSERT_EQ (latest1, block->previous ());
}
Expand Down Expand Up @@ -222,7 +222,7 @@ TEST (wallet, spend)
auto transaction (node1.store.tx_begin_read ());
node1.store.account.get (transaction, nano::dev_genesis_key.pub, info2);
ASSERT_NE (latest1, info2.head);
auto block (node1.store.block_get (transaction, info2.head));
auto block (node1.store.block.get (transaction, info2.head));
ASSERT_NE (nullptr, block);
ASSERT_EQ (latest1, block->previous ());
}
Expand Down Expand Up @@ -1077,7 +1077,7 @@ TEST (wallet, epoch_2_receive_propagation)
if (receive2->difficulty () < node.network_params.network.publish_thresholds.base)
{
ASSERT_GE (receive2->difficulty (), node.network_params.network.publish_thresholds.epoch_2_receive);
ASSERT_EQ (nano::epoch::epoch_2, node.store.block_version (node.store.tx_begin_read (), receive2->hash ()));
ASSERT_EQ (nano::epoch::epoch_2, node.store.block.version (node.store.tx_begin_read (), receive2->hash ()));
ASSERT_EQ (nano::epoch::epoch_2, receive2->sideband ().source_epoch);
break;
}
Expand Down Expand Up @@ -1122,7 +1122,7 @@ TEST (wallet, epoch_2_receive_unopened)
if (receive1->difficulty () < node.network_params.network.publish_thresholds.base)
{
ASSERT_GE (receive1->difficulty (), node.network_params.network.publish_thresholds.epoch_2_receive);
ASSERT_EQ (nano::epoch::epoch_2, node.store.block_version (node.store.tx_begin_read (), receive1->hash ()));
ASSERT_EQ (nano::epoch::epoch_2, node.store.block.version (node.store.tx_begin_read (), receive1->hash ()));
ASSERT_EQ (nano::epoch::epoch_1, receive1->sideband ().source_epoch);
break;
}
Expand Down Expand Up @@ -1232,7 +1232,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.store.block.exists (node2.store.tx_begin_read (), send1->hash ()));

wallet2.insert_adhoc (key.prv, false);

Expand Down
2 changes: 1 addition & 1 deletion nano/lib/rep_weights.cpp
@@ -1,5 +1,5 @@
#include <nano/lib/rep_weights.hpp>
#include <nano/secure/blockstore.hpp>
#include <nano/secure/store.hpp>

void nano::rep_weights::representation_add (nano::account const & source_rep_a, nano::uint128_t const & amount_a)
{
Expand Down
2 changes: 1 addition & 1 deletion nano/lib/rep_weights.hpp
Expand Up @@ -9,7 +9,7 @@

namespace nano
{
class block_store;
class store;
class transaction;

class rep_weights
Expand Down
20 changes: 10 additions & 10 deletions nano/nano_node/entry.cpp
Expand Up @@ -1418,17 +1418,17 @@ int main (int argc, char * const * argv)

auto hash (info.open_block);
nano::block_hash calculated_hash (0);
auto block (node->store.block_get (transaction, hash)); // Block data
auto block (node->store.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->store.block_get (transaction, hash);
block = node->store.block.get (transaction, hash);
// Iteration until pruned block
bool pruned_block (false);
while (!pruned_block && !block->previous ().is_zero ())
{
auto previous_block (node->store.block_get (transaction, block->previous ()));
auto previous_block (node->store.block.get (transaction, block->previous ()));
if (previous_block != nullptr)
{
hash = previous_block->hash ();
Expand Down Expand Up @@ -1566,7 +1566,7 @@ int main (int argc, char * const * argv)
// Check link epoch version
if (sideband.details.is_receive && (!node->ledger.pruning || !node->store.pruned.exists (transaction, block->link ().as_block_hash ())))
{
if (sideband.source_epoch != node->store.block_version (transaction, block->link ().as_block_hash ()))
if (sideband.source_epoch != node->store.block.version (transaction, block->link ().as_block_hash ()))
{
print_error_message (boost::str (boost::format ("Incorrect source epoch for block %1%\n") % hash.to_string ()));
}
Expand Down Expand Up @@ -1594,11 +1594,11 @@ int main (int argc, char * const * argv)
calculated_representative = block->representative ();
}
// Retrieving successor block hash
hash = node->store.block_successor (transaction, hash);
hash = node->store.block.successor (transaction, hash);
// Retrieving block data
if (!hash.is_zero ())
{
block = node->store.block_get (transaction, hash);
block = node->store.block.get (transaction, hash);
}
}
// Check if required block exists
Expand Down Expand Up @@ -1661,7 +1661,7 @@ int main (int argc, char * const * argv)
}

// Validate total block count
auto ledger_block_count (node->store.block_count (transaction));
auto ledger_block_count (node->store.block.count (transaction));
if (node->flags.enable_pruning)
{
block_count += 1; // Add disconnected genesis block
Expand All @@ -1683,7 +1683,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->store.block_get_no_sideband (transaction, key.hash));
auto block (node->store.block.get_no_sideband (transaction, key.hash));
bool pruned (false);
if (block == nullptr)
{
Expand All @@ -1700,7 +1700,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->store.block_get (transaction, key.hash);
block = node->store.block.get (transaction, key.hash);
}
if (auto state = dynamic_cast<nano::state_block *> (block.get ()))
{
Expand Down Expand Up @@ -1808,7 +1808,7 @@ int main (int argc, char * const * argv)
while (!hash.is_zero ())
{
// Retrieving block data
auto block (source_node->store.block_get_no_sideband (transaction, hash));
auto block (source_node->store.block.get_no_sideband (transaction, hash));
if (block != nullptr)
{
++count;
Expand Down
14 changes: 7 additions & 7 deletions nano/node/active_transactions.cpp
Expand Up @@ -5,7 +5,7 @@
#include <nano/node/election.hpp>
#include <nano/node/node.hpp>
#include <nano/node/repcrawler.hpp>
#include <nano/secure/blockstore.hpp>
#include <nano/secure/store.hpp>

#include <boost/format.hpp>
#include <boost/variant/get.hpp>
Expand Down Expand Up @@ -142,7 +142,7 @@ void nano::active_transactions::confirm_prioritized_frontiers (nano::transaction

if (info.block_count > confirmation_height_info.height)
{
auto block (this->node.store.block_get (transaction_a, info.head));
auto block (this->node.store.block.get (transaction_a, info.head));
auto previous_balance (this->node.ledger.balance (transaction_a, block->previous ()));
auto inserted_election = this->insert_election_from_frontiers_confirmation (block, cementable_account.account, previous_balance, nano::election_behavior::optimistic);
if (inserted_election)
Expand Down Expand Up @@ -500,12 +500,12 @@ void nano::active_transactions::confirm_expired_frontiers_pessimistically (nano:
std::shared_ptr<nano::block> block;
if (confirmation_height_info.height == 0)
{
block = node.store.block_get (transaction_a, account_info.open_block);
block = node.store.block.get (transaction_a, account_info.open_block);
}
else
{
previous_block = node.store.block_get (transaction_a, confirmation_height_info.frontier);
block = node.store.block_get (transaction_a, previous_block->sideband ().successor);
previous_block = node.store.block.get (transaction_a, confirmation_height_info.frontier);
block = node.store.block.get (transaction_a, previous_block->sideband ().successor);
}

if (block && !node.confirmation_height_processor.is_processing_block (block->hash ()) && node.ledger.dependents_confirmed (transaction_a, *block))
Expand Down Expand Up @@ -812,7 +812,7 @@ nano::election_insertion_result nano::active_transactions::insert_impl (nano::un
if (!previous_balance_a.is_initialized () && !block_a->previous ().is_zero ())
{
auto transaction (node.store.tx_begin_read ());
if (node.store.block_exists (transaction, block_a->previous ()))
if (node.store.block.exists (transaction, block_a->previous ()))
{
previous_balance = node.ledger.balance (transaction, block_a->previous ());
}
Expand Down Expand Up @@ -1276,7 +1276,7 @@ nano::inactive_cache_status nano::active_transactions::inactive_votes_bootstrap_
if ((status.election_started && !previously_a.election_started) || (status.bootstrap_started && !previously_a.bootstrap_started))
{
auto transaction (node.store.tx_begin_read ());
auto block = node.store.block_get (transaction, hash_a);
auto block = node.store.block.get (transaction, hash_a);
if (block && status.election_started && !previously_a.election_started && !node.block_confirmed_or_being_confirmed (transaction, hash_a))
{
lock_a.lock ();
Expand Down
4 changes: 2 additions & 2 deletions nano/node/blockprocessor.cpp
Expand Up @@ -4,7 +4,7 @@
#include <nano/node/election.hpp>
#include <nano/node/node.hpp>
#include <nano/node/websocket.hpp>
#include <nano/secure/blockstore.hpp>
#include <nano/secure/store.hpp>

#include <boost/format.hpp>

Expand Down Expand Up @@ -343,7 +343,7 @@ nano::process_return nano::block_processor::process_one (nano::write_transaction
{
case nano::process_result::progress:
{
release_assert (info_a.account.is_zero () || info_a.account == node.store.block_account_calculated (*block));
release_assert (info_a.account.is_zero () || info_a.account == node.store.block.account_calculated (*block));
if (node.config.logging.ledger_logging ())
{
std::string block_string;
Expand Down
4 changes: 2 additions & 2 deletions nano/node/bootstrap/bootstrap_bulk_pull.cpp
Expand Up @@ -419,7 +419,7 @@ void nano::bulk_pull_server::set_current_end ()
include_start = false;
debug_assert (request != nullptr);
auto transaction (connection->node->store.tx_begin_read ());
if (!connection->node->store.block_exists (transaction, request->end))
if (!connection->node->store.block.exists (transaction, request->end))
{
if (connection->node->config.logging.bulk_pull_logging ())
{
Expand All @@ -428,7 +428,7 @@ void nano::bulk_pull_server::set_current_end ()
request->end.clear ();
}

if (connection->node->store.block_exists (transaction, request->start.as_block_hash ()))
if (connection->node->store.block.exists (transaction, request->start.as_block_hash ()))
{
if (connection->node->config.logging.bulk_pull_logging ())
{
Expand Down
4 changes: 2 additions & 2 deletions nano/node/cli.cpp
Expand Up @@ -9,7 +9,7 @@

namespace
{
void reset_confirmation_heights (nano::write_transaction const & transaction, nano::block_store & store);
void reset_confirmation_heights (nano::write_transaction const & transaction, nano::store & store);
bool is_using_rocksdb (boost::filesystem::path const & data_path, boost::program_options::variables_map const & vm, std::error_code & ec);
}

Expand Down Expand Up @@ -1300,7 +1300,7 @@ std::unique_ptr<nano::inactive_node> nano::default_inactive_node (boost::filesys

namespace
{
void reset_confirmation_heights (nano::write_transaction const & transaction, nano::block_store & store)
void reset_confirmation_heights (nano::write_transaction const & transaction, nano::store & store)
{
// First do a clean sweep
store.confirmation_height.clear (transaction);
Expand Down

0 comments on commit 4d915c1

Please sign in to comment.