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 19, 2023
1 parent 9614e24 commit e8f3367
Show file tree
Hide file tree
Showing 58 changed files with 561 additions and 299 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
24 changes: 24 additions & 0 deletions nano/store/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
add_library(
nano_store
account.hpp
block.hpp
component.hpp
confirmation_height.hpp
iterator.hpp
iterator_impl.hpp
final.hpp
frontier.hpp
lmdb/account.hpp
lmdb/block.hpp
lmdb/confirmation_height.hpp
Expand All @@ -15,6 +22,10 @@ add_library(
lmdb/pruned.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
Expand All @@ -27,8 +38,16 @@ add_library(
rocksdb/rocksdb.hpp
rocksdb/rocksdb_txn.hpp
rocksdb/version.hpp
version.hpp
versioning.hpp
account.cpp
block.cpp
component.cpp
confirmation_height.cpp
iterator.cpp
iterator_impl.cpp
final.cpp
frontier.cpp
lmdb/account.cpp
lmdb/block.cpp
lmdb/confirmation_height.cpp
Expand All @@ -43,6 +62,10 @@ 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
Expand All @@ -55,6 +78,7 @@ add_library(
rocksdb/rocksdb.cpp
rocksdb/rocksdb_txn.cpp
rocksdb/version.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>
38 changes: 38 additions & 0 deletions nano/store/block.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#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 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
32 changes: 4 additions & 28 deletions nano/store/component.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#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>
#include <nano/store/confirmation_height.hpp>
#include <nano/store/frontier.hpp>

nano::representative_visitor::representative_visitor (nano::transaction const & transaction_a, nano::store::component & store_a) :
transaction (transaction_a),
Expand Down Expand Up @@ -152,31 +156,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 e8f3367

Please sign in to comment.