Skip to content

Commit

Permalink
Extracting classes from component.hpp in to their own files
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Sep 20, 2023
1 parent 0ae3a7d commit 76cbf5a
Show file tree
Hide file tree
Showing 72 changed files with 1,225 additions and 910 deletions.
1 change: 1 addition & 0 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <nano/node/json_handler.hpp>
#include <nano/node/node.hpp>
#include <nano/node/transport/inproc.hpp>
#include <nano/store/pending.hpp>

#include <boost/dll/runtime_symbol_info.hpp>
#include <boost/filesystem/operations.hpp>
Expand Down
2 changes: 2 additions & 0 deletions nano/node/bootstrap/bootstrap_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include <nano/node/transport/channel.hpp>
#include <nano/node/transport/transport.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/store/block.hpp>
#include <nano/store/component.hpp>
#include <nano/store/confirmation_height.hpp>

// TODO: Make threads configurable
nano::bootstrap_server::bootstrap_server (nano::store::component & store_a, nano::ledger & ledger_a, nano::network_constants const & network_constants_a, nano::stats & stats_a) :
Expand Down
2 changes: 2 additions & 0 deletions nano/node/bootstrap_ascending/iterators.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <nano/lib/utility.hpp>
#include <nano/node/bootstrap_ascending/iterators.hpp>
#include <nano/secure/common.hpp>
#include <nano/store/account.hpp>
#include <nano/store/component.hpp>
#include <nano/store/pending.hpp>

/*
* database_iterator
Expand Down
1 change: 1 addition & 0 deletions nano/node/bootstrap_ascending/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <nano/node/transport/transport.hpp>
#include <nano/secure/common.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/store/account.hpp>
#include <nano/store/component.hpp>

using namespace std::chrono_literals;
Expand Down
3 changes: 3 additions & 0 deletions nano/node/confirmation_height_bounded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <nano/node/logging.hpp>
#include <nano/node/write_database_queue.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/store/block.hpp>
#include <nano/store/confirmation_height.hpp>
#include <nano/store/pruned.hpp>

#include <boost/format.hpp>

Expand Down
3 changes: 3 additions & 0 deletions nano/node/confirmation_height_unbounded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <nano/node/logging.hpp>
#include <nano/node/write_database_queue.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/store/block.hpp>
#include <nano/store/confirmation_height.hpp>
#include <nano/store/pruned.hpp>

#include <boost/format.hpp>

Expand Down
1 change: 1 addition & 0 deletions nano/node/ledger_walker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <nano/node/ledger_walker.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/utility.hpp>
#include <nano/store/block.hpp>
#include <nano/store/component.hpp>

#include <algorithm>
Expand Down
1 change: 1 addition & 0 deletions nano/node/online_reps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <nano/node/online_reps.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/store/component.hpp>
#include <nano/store/online_weight.hpp>

nano::online_reps::online_reps (nano::ledger & ledger_a, nano::node_config const & config_a) :
ledger{ ledger_a },
Expand Down
10 changes: 10 additions & 0 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@
#include <nano/node/make_store.hpp>
#include <nano/secure/common.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/store/account.hpp>
#include <nano/store/block.hpp>
#include <nano/store/component.hpp>
#include <nano/store/confirmation_height.hpp>
#include <nano/store/final.hpp>
#include <nano/store/frontier.hpp>
#include <nano/store/online_weight.hpp>
#include <nano/store/peer.hpp>
#include <nano/store/pending.hpp>
#include <nano/store/pruned.hpp>
#include <nano/store/version.hpp>

#include <boost/filesystem.hpp>

Expand Down
33 changes: 33 additions & 0 deletions nano/store/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
add_library(
nano_store
account.hpp
block.hpp
component.hpp
confirmation_height.hpp
db_val.hpp
iterator.hpp
iterator_impl.hpp
final.hpp
frontier.hpp
lmdb/account.hpp
lmdb/block.hpp
lmdb/confirmation_height.hpp
lmdb/db_val.hpp
lmdb/final_vote.hpp
lmdb/frontier.hpp
lmdb/lmdb.hpp
Expand All @@ -17,9 +26,14 @@ add_library(
lmdb/transaction_impl.hpp
lmdb/version.hpp
lmdb/wallet_value.hpp
online_weight.hpp
peer.hpp
pending.hpp
pruned.hpp
rocksdb/account.hpp
rocksdb/block.hpp
rocksdb/confirmation_height.hpp
rocksdb/db_val.hpp
rocksdb/final_vote.hpp
rocksdb/frontier.hpp
rocksdb/iterator.hpp
Expand All @@ -30,11 +44,23 @@ add_library(
rocksdb/rocksdb.hpp
rocksdb/transaction_impl.hpp
rocksdb/version.hpp
tables.hpp
transaction.hpp
version.hpp
versioning.hpp
account.cpp
block.cpp
component.cpp
confirmation_height.cpp
db_val.cpp
iterator.cpp
iterator_impl.cpp
final.cpp
frontier.cpp
lmdb/account.cpp
lmdb/block.cpp
lmdb/confirmation_height.cpp
lmdb/db_val.cpp
lmdb/final_vote.cpp
lmdb/frontier.cpp
lmdb/lmdb.cpp
Expand All @@ -46,9 +72,14 @@ add_library(
lmdb/pruned.cpp
lmdb/version.cpp
lmdb/wallet_value.cpp
online_weight.cpp
peer.cpp
pending.cpp
pruned.cpp
rocksdb/account.cpp
rocksdb/block.cpp
rocksdb/confirmation_height.cpp
rocksdb/db_val.cpp
rocksdb/final_vote.cpp
rocksdb/frontier.cpp
rocksdb/online_weight.cpp
Expand All @@ -58,6 +89,8 @@ add_library(
rocksdb/rocksdb.cpp
rocksdb/transaction.cpp
rocksdb/version.cpp
transaction.cpp
version.cpp
versioning.cpp)

target_link_libraries(
Expand Down
15 changes: 15 additions & 0 deletions nano/store/account.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <nano/store/account.hpp>

std::optional<nano::account_info> nano::account_store::get (nano::transaction const & transaction, nano::account const & account)
{
nano::account_info info;
bool error = get (transaction, account, info);
if (!error)
{
return info;
}
else
{
return std::nullopt;
}
}
36 changes: 36 additions & 0 deletions nano/store/account.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <nano/lib/numbers.hpp>
#include <nano/store/component.hpp>
#include <nano/store/iterator.hpp>

#include <functional>

namespace nano
{
class block_hash;
class read_transaction;
class transaction;
class write_transaction;
}
namespace nano
{
/**
* Manages account storage and iteration
*/
class account_store
{
public:
virtual void put (nano::write_transaction const &, nano::account const &, nano::account_info const &) = 0;
virtual bool get (nano::transaction const &, nano::account const &, nano::account_info &) = 0;
std::optional<nano::account_info> get (nano::transaction const &, nano::account const &);
virtual void del (nano::write_transaction const &, nano::account const &) = 0;
virtual bool exists (nano::transaction const &, nano::account const &) = 0;
virtual size_t count (nano::transaction const &) = 0;
virtual nano::store_iterator<nano::account, nano::account_info> begin (nano::transaction const &, nano::account const &) const = 0;
virtual nano::store_iterator<nano::account, nano::account_info> begin (nano::transaction const &) const = 0;
virtual nano::store_iterator<nano::account, nano::account_info> rbegin (nano::transaction const &) const = 0;
virtual nano::store_iterator<nano::account, nano::account_info> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::account, nano::account_info>, nano::store_iterator<nano::account, nano::account_info>)> const &) const = 0;
};
} // namespace nano::store
1 change: 1 addition & 0 deletions nano/store/block.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <nano/store/block.hpp>
45 changes: 45 additions & 0 deletions nano/store/block.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <nano/lib/blocks.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/store/component.hpp>
#include <nano/store/iterator.hpp>

#include <functional>

namespace nano
{
class block_hash;
class read_transaction;
class transaction;
class write_transaction;
}
namespace nano
{
class block_w_sideband
{
public:
std::shared_ptr<nano::block> block;
nano::block_sideband sideband;
};
/**
* Manages block storage and iteration
*/
class block_store
{
public:
virtual void put (nano::write_transaction const &, nano::block_hash const &, nano::block const &) = 0;
virtual void raw_put (nano::write_transaction const &, std::vector<uint8_t> const &, nano::block_hash const &) = 0;
virtual nano::block_hash successor (nano::transaction const &, nano::block_hash const &) const = 0;
virtual void successor_clear (nano::write_transaction const &, nano::block_hash const &) = 0;
virtual std::shared_ptr<nano::block> get (nano::transaction const &, nano::block_hash const &) const = 0;
virtual std::shared_ptr<nano::block> random (nano::transaction const &) = 0;
virtual void del (nano::write_transaction const &, nano::block_hash const &) = 0;
virtual bool exists (nano::transaction const &, nano::block_hash const &) = 0;
virtual uint64_t count (nano::transaction const &) = 0;
virtual nano::store_iterator<nano::block_hash, block_w_sideband> begin (nano::transaction const &, nano::block_hash const &) const = 0;
virtual nano::store_iterator<nano::block_hash, block_w_sideband> begin (nano::transaction const &) const = 0;
virtual nano::store_iterator<nano::block_hash, block_w_sideband> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::block_hash, block_w_sideband>, nano::store_iterator<nano::block_hash, block_w_sideband>)> const & action_a) const = 0;
};
} // namespace nano::store
94 changes: 4 additions & 90 deletions nano/store/component.cpp
Original file line number Diff line number Diff line change
@@ -1,67 +1,9 @@
#include <nano/lib/thread_roles.hpp>
#include <nano/lib/timer.hpp>
#include <nano/store/account.hpp>
#include <nano/store/block.hpp>
#include <nano/store/component.hpp>

nano::read_transaction::read_transaction (std::unique_ptr<nano::read_transaction_impl> read_transaction_impl) :
impl (std::move (read_transaction_impl))
{
}

void * nano::read_transaction::get_handle () const
{
return impl->get_handle ();
}

void nano::read_transaction::reset () const
{
impl->reset ();
}

void nano::read_transaction::renew () const
{
impl->renew ();
}

void nano::read_transaction::refresh () const
{
reset ();
renew ();
}

nano::write_transaction::write_transaction (std::unique_ptr<nano::write_transaction_impl> write_transaction_impl) :
impl (std::move (write_transaction_impl))
{
/*
* For IO threads, we do not want them to block on creating write transactions.
*/
debug_assert (nano::thread_role::get () != nano::thread_role::name::io);
}

void * nano::write_transaction::get_handle () const
{
return impl->get_handle ();
}

void nano::write_transaction::commit ()
{
impl->commit ();
}

void nano::write_transaction::renew ()
{
impl->renew ();
}

void nano::write_transaction::refresh ()
{
impl->commit ();
impl->renew ();
}

bool nano::write_transaction::contains (nano::tables table_a) const
{
return impl->contains (table_a);
}
#include <nano/store/confirmation_height.hpp>
#include <nano/store/frontier.hpp>

// clang-format off
nano::store::component::component (
Expand Down Expand Up @@ -109,31 +51,3 @@ void nano::store::component::initialize (nano::write_transaction const & transac
ledger_cache_a.rep_weights.representation_put (constants.genesis->account (), std::numeric_limits<nano::uint128_t>::max ());
frontier.put (transaction_a, hash_l, constants.genesis->account ());
}

std::optional<nano::account_info> nano::account_store::get (const nano::transaction & transaction, const nano::account & account)
{
nano::account_info info;
bool error = get (transaction, account, info);
if (!error)
{
return info;
}
else
{
return std::nullopt;
}
}

std::optional<nano::confirmation_height_info> nano::confirmation_height_store::get (const nano::transaction & transaction, const nano::account & account)
{
nano::confirmation_height_info info;
bool error = get (transaction, account, info);
if (!error)
{
return info;
}
else
{
return std::nullopt;
}
}
Loading

0 comments on commit 76cbf5a

Please sign in to comment.