From e8f33678a9af3ac43717bc3149c2c9b6e9059f21 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 19 Sep 2023 00:27:30 +0100 Subject: [PATCH] Extracting classes from component.hpp in to their own files --- nano/nano_node/entry.cpp | 1 + nano/node/bootstrap/bootstrap_server.cpp | 2 + nano/node/bootstrap_ascending/iterators.cpp | 2 + nano/node/bootstrap_ascending/service.cpp | 1 + nano/node/confirmation_height_bounded.cpp | 3 + nano/node/confirmation_height_unbounded.cpp | 3 + nano/node/ledger_walker.cpp | 1 + nano/node/online_reps.cpp | 1 + nano/secure/ledger.cpp | 10 + nano/store/CMakeLists.txt | 24 ++ nano/store/account.cpp | 15 ++ nano/store/account.hpp | 36 +++ nano/store/block.cpp | 1 + nano/store/block.hpp | 38 +++ nano/store/component.cpp | 32 +-- nano/store/component.hpp | 260 +------------------- nano/store/confirmation_height.cpp | 15 ++ nano/store/confirmation_height.hpp | 43 ++++ nano/store/final.cpp | 1 + nano/store/final.hpp | 35 +++ nano/store/frontier.cpp | 1 + nano/store/frontier.hpp | 32 +++ nano/store/iterator.cpp | 1 + nano/store/iterator.hpp | 65 +++++ nano/store/iterator_impl.cpp | 1 + nano/store/iterator_impl.hpp | 27 ++ nano/store/lmdb/account.hpp | 2 +- nano/store/lmdb/block.hpp | 2 +- nano/store/lmdb/confirmation_height.hpp | 2 +- nano/store/lmdb/final_vote.hpp | 2 +- nano/store/lmdb/frontier.hpp | 2 +- nano/store/lmdb/lmdb.cpp | 2 +- nano/store/lmdb/online_weight.hpp | 2 +- nano/store/lmdb/peer.hpp | 2 +- nano/store/lmdb/pending.hpp | 2 +- nano/store/lmdb/pruned.hpp | 2 +- nano/store/lmdb/version.hpp | 2 +- nano/store/online_weight.cpp | 1 + nano/store/online_weight.hpp | 32 +++ nano/store/peer.cpp | 1 + nano/store/peer.hpp | 32 +++ nano/store/pending.cpp | 1 + nano/store/pending.hpp | 34 +++ nano/store/pruned.cpp | 1 + nano/store/pruned.hpp | 35 +++ nano/store/rocksdb/account.hpp | 2 +- nano/store/rocksdb/block.hpp | 2 +- nano/store/rocksdb/confirmation_height.hpp | 2 +- nano/store/rocksdb/final_vote.hpp | 2 +- nano/store/rocksdb/frontier.hpp | 3 +- nano/store/rocksdb/online_weight.hpp | 2 +- nano/store/rocksdb/peer.hpp | 2 +- nano/store/rocksdb/pending.hpp | 2 +- nano/store/rocksdb/pruned.hpp | 2 +- nano/store/rocksdb/rocksdb.cpp | 1 + nano/store/rocksdb/version.hpp | 2 +- nano/store/version.cpp | 1 + nano/store/version.hpp | 27 ++ 58 files changed, 561 insertions(+), 299 deletions(-) create mode 100644 nano/store/account.cpp create mode 100644 nano/store/account.hpp create mode 100644 nano/store/block.cpp create mode 100644 nano/store/block.hpp create mode 100644 nano/store/confirmation_height.cpp create mode 100644 nano/store/confirmation_height.hpp create mode 100644 nano/store/final.cpp create mode 100644 nano/store/final.hpp create mode 100644 nano/store/frontier.cpp create mode 100644 nano/store/frontier.hpp create mode 100644 nano/store/iterator.cpp create mode 100644 nano/store/iterator.hpp create mode 100644 nano/store/iterator_impl.cpp create mode 100644 nano/store/iterator_impl.hpp create mode 100644 nano/store/online_weight.cpp create mode 100644 nano/store/online_weight.hpp create mode 100644 nano/store/peer.cpp create mode 100644 nano/store/peer.hpp create mode 100644 nano/store/pending.cpp create mode 100644 nano/store/pending.hpp create mode 100644 nano/store/pruned.cpp create mode 100644 nano/store/pruned.hpp create mode 100644 nano/store/version.cpp create mode 100644 nano/store/version.hpp diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index f16fd1c922..ae1dcb795f 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index 9a70a93fb0..bb6dcf3000 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -2,7 +2,9 @@ #include #include #include +#include #include +#include // 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) : diff --git a/nano/node/bootstrap_ascending/iterators.cpp b/nano/node/bootstrap_ascending/iterators.cpp index 3a8391bd30..9f29f98bd8 100644 --- a/nano/node/bootstrap_ascending/iterators.cpp +++ b/nano/node/bootstrap_ascending/iterators.cpp @@ -1,7 +1,9 @@ #include #include #include +#include #include +#include /* * database_iterator diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 87682a04f0..e7d2117931 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include using namespace std::chrono_literals; diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index e1ce791347..cec0958410 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include #include diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index 62f1036bab..e443a96a8f 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include #include diff --git a/nano/node/ledger_walker.cpp b/nano/node/ledger_walker.cpp index a2484d5ad0..7c58592af4 100644 --- a/nano/node/ledger_walker.cpp +++ b/nano/node/ledger_walker.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include diff --git a/nano/node/online_reps.cpp b/nano/node/online_reps.cpp index bbf1299bb4..370aaa6790 100644 --- a/nano/node/online_reps.cpp +++ b/nano/node/online_reps.cpp @@ -2,6 +2,7 @@ #include #include #include +#include nano::online_reps::online_reps (nano::ledger & ledger_a, nano::node_config const & config_a) : ledger{ ledger_a }, diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 442a73a85e..5e35539216 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -5,7 +5,17 @@ #include #include #include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include #include diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index c48a5d6ecc..322726890d 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -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 @@ -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 @@ -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 @@ -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 @@ -55,6 +78,7 @@ add_library( rocksdb/rocksdb.cpp rocksdb/rocksdb_txn.cpp rocksdb/version.cpp + version.cpp versioning.cpp) target_link_libraries( diff --git a/nano/store/account.cpp b/nano/store/account.cpp new file mode 100644 index 0000000000..d08002c148 --- /dev/null +++ b/nano/store/account.cpp @@ -0,0 +1,15 @@ +#include + +std::optional 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; + } +} diff --git a/nano/store/account.hpp b/nano/store/account.hpp new file mode 100644 index 0000000000..ad5da11e0b --- /dev/null +++ b/nano/store/account.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include + +#include + +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 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 begin (nano::transaction const &, nano::account const &) const = 0; + virtual nano::store_iterator begin (nano::transaction const &) const = 0; + virtual nano::store_iterator rbegin (nano::transaction const &) const = 0; + virtual nano::store_iterator end () const = 0; + virtual void for_each_par (std::function, nano::store_iterator)> const &) const = 0; +}; +} // namespace nano::store diff --git a/nano/store/block.cpp b/nano/store/block.cpp new file mode 100644 index 0000000000..40d128b96e --- /dev/null +++ b/nano/store/block.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/block.hpp b/nano/store/block.hpp new file mode 100644 index 0000000000..6c851a9f57 --- /dev/null +++ b/nano/store/block.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + +#include + +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 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 get (nano::transaction const &, nano::block_hash const &) const = 0; + virtual std::shared_ptr 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 begin (nano::transaction const &, nano::block_hash const &) const = 0; + virtual nano::store_iterator begin (nano::transaction const &) const = 0; + virtual nano::store_iterator end () const = 0; + virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; +}; +} // namespace nano::store diff --git a/nano/store/component.cpp b/nano/store/component.cpp index eee80745f3..4cf5e76513 100644 --- a/nano/store/component.cpp +++ b/nano/store/component.cpp @@ -1,6 +1,10 @@ #include #include +#include +#include #include +#include +#include nano::representative_visitor::representative_visitor (nano::transaction const & transaction_a, nano::store::component & store_a) : transaction (transaction_a), @@ -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::max ()); frontier.put (transaction_a, hash_l, constants.genesis->account ()); } - -std::optional 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_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; - } -} diff --git a/nano/store/component.hpp b/nano/store/component.hpp index eb6ce22e2b..06ef90cb2b 100644 --- a/nano/store/component.hpp +++ b/nano/store/component.hpp @@ -419,82 +419,6 @@ class representative_visitor final : public nano::block_visitor nano::block_hash current; nano::block_hash result; }; -template -class store_iterator_impl -{ -public: - virtual ~store_iterator_impl () = default; - virtual nano::store_iterator_impl & operator++ () = 0; - virtual nano::store_iterator_impl & operator-- () = 0; - virtual bool operator== (nano::store_iterator_impl const & other_a) const = 0; - virtual bool is_end_sentinal () const = 0; - virtual void fill (std::pair &) const = 0; - nano::store_iterator_impl & operator= (nano::store_iterator_impl const &) = delete; - bool operator== (nano::store_iterator_impl const * other_a) const - { - return (other_a != nullptr && *this == *other_a) || (other_a == nullptr && is_end_sentinal ()); - } - bool operator!= (nano::store_iterator_impl const & other_a) const - { - return !(*this == other_a); - } -}; -/** - * Iterates the key/value pairs of a transaction - */ -template -class store_iterator final -{ -public: - store_iterator (std::nullptr_t) - { - } - store_iterator (std::unique_ptr> impl_a) : - impl (std::move (impl_a)) - { - impl->fill (current); - } - store_iterator (nano::store_iterator && other_a) : - current (std::move (other_a.current)), - impl (std::move (other_a.impl)) - { - } - nano::store_iterator & operator++ () - { - ++*impl; - impl->fill (current); - return *this; - } - nano::store_iterator & operator-- () - { - --*impl; - impl->fill (current); - return *this; - } - nano::store_iterator & operator= (nano::store_iterator && other_a) noexcept - { - impl = std::move (other_a.impl); - current = std::move (other_a.current); - return *this; - } - nano::store_iterator & operator= (nano::store_iterator const &) = delete; - std::pair * operator-> () - { - return ¤t; - } - bool operator== (nano::store_iterator const & other_a) const - { - return (impl == nullptr && other_a.impl == nullptr) || (impl != nullptr && *impl == other_a.impl.get ()) || (other_a.impl != nullptr && *other_a.impl == impl.get ()); - } - bool operator!= (nano::store_iterator const & other_a) const - { - return !(*this == other_a); - } - -private: - std::pair current; - std::unique_ptr> impl; -}; // Keep this in alphabetical order enum class tables @@ -577,181 +501,17 @@ class write_transaction final : public transaction std::unique_ptr impl; }; +class account_store; +class block_store; +class confirmation_height_store; +class final_vote_store; +class frontier_store; class ledger_cache; - -/** - * Manages frontier storage and iteration - */ -class frontier_store -{ -public: - virtual void put (nano::write_transaction const &, nano::block_hash const &, nano::account const &) = 0; - virtual nano::account get (nano::transaction const &, nano::block_hash const &) const = 0; - virtual void del (nano::write_transaction const &, nano::block_hash const &) = 0; - virtual nano::store_iterator begin (nano::transaction const &) const = 0; - virtual nano::store_iterator begin (nano::transaction const &, nano::block_hash const &) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; -}; - -/** - * 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 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 begin (nano::transaction const &, nano::account const &) const = 0; - virtual nano::store_iterator begin (nano::transaction const &) const = 0; - virtual nano::store_iterator rbegin (nano::transaction const &) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const &) const = 0; -}; - -/** - * Manages pending storage and iteration - */ -class pending_store -{ -public: - virtual void put (nano::write_transaction const &, nano::pending_key const &, nano::pending_info const &) = 0; - virtual void del (nano::write_transaction const &, nano::pending_key const &) = 0; - virtual bool get (nano::transaction const &, nano::pending_key const &, nano::pending_info &) = 0; - virtual bool exists (nano::transaction const &, nano::pending_key const &) = 0; - virtual bool any (nano::transaction const &, nano::account const &) = 0; - virtual nano::store_iterator begin (nano::transaction const &, nano::pending_key const &) const = 0; - virtual nano::store_iterator begin (nano::transaction const &) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; -}; - -/** - * Manages peer storage and iteration - */ -class peer_store -{ -public: - virtual void put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0; - virtual void del (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0; - virtual bool exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const = 0; - virtual size_t count (nano::transaction const & transaction_a) const = 0; - virtual void clear (nano::write_transaction const & transaction_a) = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; - virtual nano::store_iterator end () const = 0; -}; - -/** - * Manages online weight storage and iteration - */ -class online_weight_store -{ -public: - virtual void put (nano::write_transaction const &, uint64_t, nano::amount const &) = 0; - virtual void del (nano::write_transaction const &, uint64_t) = 0; - virtual nano::store_iterator begin (nano::transaction const &) const = 0; - virtual nano::store_iterator rbegin (nano::transaction const &) const = 0; - virtual nano::store_iterator end () const = 0; - virtual size_t count (nano::transaction const &) const = 0; - virtual void clear (nano::write_transaction const &) = 0; -}; - -/** - * Manages pruned storage and iteration - */ -class pruned_store -{ -public: - virtual void put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; - virtual void del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; - virtual bool exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; - virtual nano::block_hash random (nano::transaction const & transaction_a) = 0; - virtual size_t count (nano::transaction const & transaction_a) const = 0; - virtual void clear (nano::write_transaction const &) = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; -}; - -/** - * Manages confirmation height storage and iteration - */ -class confirmation_height_store -{ -public: - virtual void put (nano::write_transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a) = 0; - - /** Retrieves confirmation height info relating to an account. - * The parameter confirmation_height_info_a is always written. - * On error, the confirmation height and frontier hash are set to 0. - * Ruturns true on error, false on success. - */ - virtual bool get (nano::transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info & confirmation_height_info_a) = 0; - std::optional get (nano::transaction const & transaction_a, nano::account const & account_a); - virtual bool exists (nano::transaction const & transaction_a, nano::account const & account_a) const = 0; - virtual void del (nano::write_transaction const & transaction_a, nano::account const & account_a) = 0; - virtual uint64_t count (nano::transaction const & transaction_a) = 0; - virtual void clear (nano::write_transaction const &, nano::account const &) = 0; - virtual void clear (nano::write_transaction const &) = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a, nano::account const & account_a) const = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const &) const = 0; -}; - -/** - * Manages final vote storage and iteration - */ -class final_vote_store -{ -public: - virtual bool put (nano::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) = 0; - virtual std::vector get (nano::transaction const & transaction_a, nano::root const & root_a) = 0; - virtual void del (nano::write_transaction const & transaction_a, nano::root const & root_a) = 0; - virtual size_t count (nano::transaction const & transaction_a) const = 0; - virtual void clear (nano::write_transaction const &, nano::root const &) = 0; - virtual void clear (nano::write_transaction const &) = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0; - virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; -}; - -/** - * Manages version storage - */ -class version_store -{ -public: - virtual void put (nano::write_transaction const &, int) = 0; - virtual int get (nano::transaction const &) const = 0; -}; - -/** - * 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 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 get (nano::transaction const &, nano::block_hash const &) const = 0; - virtual std::shared_ptr 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 begin (nano::transaction const &, nano::block_hash const &) const = 0; - virtual nano::store_iterator begin (nano::transaction const &) const = 0; - virtual nano::store_iterator end () const = 0; - virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; -}; +class online_weight_store; +class peer_store; +class pending_store; +class pruned_store; +class version_store; namespace store { diff --git a/nano/store/confirmation_height.cpp b/nano/store/confirmation_height.cpp new file mode 100644 index 0000000000..1398f73108 --- /dev/null +++ b/nano/store/confirmation_height.cpp @@ -0,0 +1,15 @@ +#include + +std::optional nano::confirmation_height_store::get (nano::transaction const & transaction, nano::account const & account) +{ + nano::confirmation_height_info info; + bool error = get (transaction, account, info); + if (!error) + { + return info; + } + else + { + return std::nullopt; + } +} diff --git a/nano/store/confirmation_height.hpp b/nano/store/confirmation_height.hpp new file mode 100644 index 0000000000..2a35fb0785 --- /dev/null +++ b/nano/store/confirmation_height.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include +#include +#include + +#include + +namespace nano +{ +class block_hash; +class read_transaction; +class transaction; +class write_transaction; +} +namespace nano +{ +/** + * Manages confirmation height storage and iteration + */ +class confirmation_height_store +{ +public: + virtual void put (nano::write_transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a) = 0; + + /** Retrieves confirmation height info relating to an account. + * The parameter confirmation_height_info_a is always written. + * On error, the confirmation height and frontier hash are set to 0. + * Ruturns true on error, false on success. + */ + virtual bool get (nano::transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info & confirmation_height_info_a) = 0; + std::optional get (nano::transaction const & transaction_a, nano::account const & account_a); + virtual bool exists (nano::transaction const & transaction_a, nano::account const & account_a) const = 0; + virtual void del (nano::write_transaction const & transaction_a, nano::account const & account_a) = 0; + virtual uint64_t count (nano::transaction const & transaction_a) = 0; + virtual void clear (nano::write_transaction const &, nano::account const &) = 0; + virtual void clear (nano::write_transaction const &) = 0; + virtual nano::store_iterator begin (nano::transaction const & transaction_a, nano::account const & account_a) const = 0; + virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; + virtual nano::store_iterator end () const = 0; + virtual void for_each_par (std::function, nano::store_iterator)> const &) const = 0; +}; +} // namespace nano::store diff --git a/nano/store/final.cpp b/nano/store/final.cpp new file mode 100644 index 0000000000..69d469dc76 --- /dev/null +++ b/nano/store/final.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/final.hpp b/nano/store/final.hpp new file mode 100644 index 0000000000..b51cbe4cf9 --- /dev/null +++ b/nano/store/final.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include +#include +#include + +#include + +namespace nano +{ +class block_hash; +class read_transaction; +class transaction; +class write_transaction; +} +namespace nano +{ +/** + * Manages final vote storage and iteration + */ +class final_vote_store +{ +public: + virtual bool put (nano::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) = 0; + virtual std::vector get (nano::transaction const & transaction_a, nano::root const & root_a) = 0; + virtual void del (nano::write_transaction const & transaction_a, nano::root const & root_a) = 0; + virtual size_t count (nano::transaction const & transaction_a) const = 0; + virtual void clear (nano::write_transaction const &, nano::root const &) = 0; + virtual void clear (nano::write_transaction const &) = 0; + virtual nano::store_iterator begin (nano::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0; + virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; + virtual nano::store_iterator end () const = 0; + virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; +}; +} // namespace nano::store diff --git a/nano/store/frontier.cpp b/nano/store/frontier.cpp new file mode 100644 index 0000000000..2d12551d59 --- /dev/null +++ b/nano/store/frontier.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/frontier.hpp b/nano/store/frontier.hpp new file mode 100644 index 0000000000..56eb8d2563 --- /dev/null +++ b/nano/store/frontier.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include + +#include + +namespace nano +{ +class block_hash; +class read_transaction; +class transaction; +class write_transaction; +} +namespace nano +{ +/** + * Manages frontier storage and iteration + */ +class frontier_store +{ +public: + virtual void put (nano::write_transaction const &, nano::block_hash const &, nano::account const &) = 0; + virtual nano::account get (nano::transaction const &, nano::block_hash const &) const = 0; + virtual void del (nano::write_transaction const &, nano::block_hash const &) = 0; + virtual nano::store_iterator begin (nano::transaction const &) const = 0; + virtual nano::store_iterator begin (nano::transaction const &, nano::block_hash const &) const = 0; + virtual nano::store_iterator end () const = 0; + virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; +}; +} // namespace nano::store diff --git a/nano/store/iterator.cpp b/nano/store/iterator.cpp new file mode 100644 index 0000000000..15bf18facf --- /dev/null +++ b/nano/store/iterator.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/iterator.hpp b/nano/store/iterator.hpp new file mode 100644 index 0000000000..bf88b5861c --- /dev/null +++ b/nano/store/iterator.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include + +#include + +namespace nano +{ +/** + * Iterates the key/value pairs of a transaction + */ +template +class store_iterator final +{ +public: + store_iterator (std::nullptr_t) + { + } + store_iterator (std::unique_ptr> impl_a) : + impl (std::move (impl_a)) + { + impl->fill (current); + } + store_iterator (nano::store_iterator && other_a) : + current (std::move (other_a.current)), + impl (std::move (other_a.impl)) + { + } + nano::store_iterator & operator++ () + { + ++*impl; + impl->fill (current); + return *this; + } + nano::store_iterator & operator-- () + { + --*impl; + impl->fill (current); + return *this; + } + nano::store_iterator & operator= (nano::store_iterator && other_a) noexcept + { + impl = std::move (other_a.impl); + current = std::move (other_a.current); + return *this; + } + nano::store_iterator & operator= (nano::store_iterator const &) = delete; + std::pair * operator-> () + { + return ¤t; + } + bool operator== (nano::store_iterator const & other_a) const + { + return (impl == nullptr && other_a.impl == nullptr) || (impl != nullptr && *impl == other_a.impl.get ()) || (other_a.impl != nullptr && *other_a.impl == impl.get ()); + } + bool operator!= (nano::store_iterator const & other_a) const + { + return !(*this == other_a); + } + +private: + std::pair current; + std::unique_ptr> impl; +}; +} // namespace nano::store diff --git a/nano/store/iterator_impl.cpp b/nano/store/iterator_impl.cpp new file mode 100644 index 0000000000..4abbeb3f2a --- /dev/null +++ b/nano/store/iterator_impl.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/iterator_impl.hpp b/nano/store/iterator_impl.hpp new file mode 100644 index 0000000000..16e958ef14 --- /dev/null +++ b/nano/store/iterator_impl.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include + +namespace nano +{ +template +class store_iterator_impl +{ +public: + virtual ~store_iterator_impl () = default; + virtual nano::store_iterator_impl & operator++ () = 0; + virtual nano::store_iterator_impl & operator-- () = 0; + virtual bool operator== (nano::store_iterator_impl const & other_a) const = 0; + virtual bool is_end_sentinal () const = 0; + virtual void fill (std::pair &) const = 0; + nano::store_iterator_impl & operator= (nano::store_iterator_impl const &) = delete; + bool operator== (nano::store_iterator_impl const * other_a) const + { + return (other_a != nullptr && *this == *other_a) || (other_a == nullptr && is_end_sentinal ()); + } + bool operator!= (nano::store_iterator_impl const & other_a) const + { + return !(*this == other_a); + } +}; +} // namespace nano::store diff --git a/nano/store/lmdb/account.hpp b/nano/store/lmdb/account.hpp index e78947c558..d15c2ce887 100644 --- a/nano/store/lmdb/account.hpp +++ b/nano/store/lmdb/account.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/lmdb/block.hpp b/nano/store/lmdb/block.hpp index c690d853ee..cab61eadca 100644 --- a/nano/store/lmdb/block.hpp +++ b/nano/store/lmdb/block.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/lmdb/confirmation_height.hpp b/nano/store/lmdb/confirmation_height.hpp index 68ca1a1560..ff29a4eae8 100644 --- a/nano/store/lmdb/confirmation_height.hpp +++ b/nano/store/lmdb/confirmation_height.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/lmdb/final_vote.hpp b/nano/store/lmdb/final_vote.hpp index 5612fab943..40bdfdb406 100644 --- a/nano/store/lmdb/final_vote.hpp +++ b/nano/store/lmdb/final_vote.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/lmdb/frontier.hpp b/nano/store/lmdb/frontier.hpp index b493f339cd..b8af5b2f23 100644 --- a/nano/store/lmdb/frontier.hpp +++ b/nano/store/lmdb/frontier.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/lmdb/lmdb.cpp b/nano/store/lmdb/lmdb.cpp index f667ab6fdb..a91ba1af79 100644 --- a/nano/store/lmdb/lmdb.cpp +++ b/nano/store/lmdb/lmdb.cpp @@ -1,10 +1,10 @@ #include -#include #include #include #include #include #include +#include #include #include diff --git a/nano/store/lmdb/online_weight.hpp b/nano/store/lmdb/online_weight.hpp index 7827b36f43..9a1c527f53 100644 --- a/nano/store/lmdb/online_weight.hpp +++ b/nano/store/lmdb/online_weight.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/lmdb/peer.hpp b/nano/store/lmdb/peer.hpp index 2cbc274ae9..83fd1ee785 100644 --- a/nano/store/lmdb/peer.hpp +++ b/nano/store/lmdb/peer.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/lmdb/pending.hpp b/nano/store/lmdb/pending.hpp index bc3d7115f8..86fd1c1e5b 100644 --- a/nano/store/lmdb/pending.hpp +++ b/nano/store/lmdb/pending.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/lmdb/pruned.hpp b/nano/store/lmdb/pruned.hpp index b166f11d7e..0ad8f07e5b 100644 --- a/nano/store/lmdb/pruned.hpp +++ b/nano/store/lmdb/pruned.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/lmdb/version.hpp b/nano/store/lmdb/version.hpp index 47300a9d46..ff9b723564 100644 --- a/nano/store/lmdb/version.hpp +++ b/nano/store/lmdb/version.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano { diff --git a/nano/store/online_weight.cpp b/nano/store/online_weight.cpp new file mode 100644 index 0000000000..230a4f266d --- /dev/null +++ b/nano/store/online_weight.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/online_weight.hpp b/nano/store/online_weight.hpp new file mode 100644 index 0000000000..ee65a9b02e --- /dev/null +++ b/nano/store/online_weight.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include + +#include + +namespace nano +{ +class block_hash; +class read_transaction; +class transaction; +class write_transaction; +} +namespace nano +{ +/** + * Manages online weight storage and iteration + */ +class online_weight_store +{ +public: + virtual void put (nano::write_transaction const &, uint64_t, nano::amount const &) = 0; + virtual void del (nano::write_transaction const &, uint64_t) = 0; + virtual nano::store_iterator begin (nano::transaction const &) const = 0; + virtual nano::store_iterator rbegin (nano::transaction const &) const = 0; + virtual nano::store_iterator end () const = 0; + virtual size_t count (nano::transaction const &) const = 0; + virtual void clear (nano::write_transaction const &) = 0; +}; +} // namespace nano::store diff --git a/nano/store/peer.cpp b/nano/store/peer.cpp new file mode 100644 index 0000000000..e442b57549 --- /dev/null +++ b/nano/store/peer.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/peer.hpp b/nano/store/peer.hpp new file mode 100644 index 0000000000..64d36796af --- /dev/null +++ b/nano/store/peer.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include + +#include + +namespace nano +{ +class block_hash; +class read_transaction; +class transaction; +class write_transaction; +} +namespace nano +{ +/** + * Manages peer storage and iteration + */ +class peer_store +{ +public: + virtual void put (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0; + virtual void del (nano::write_transaction const & transaction_a, nano::endpoint_key const & endpoint_a) = 0; + virtual bool exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const = 0; + virtual size_t count (nano::transaction const & transaction_a) const = 0; + virtual void clear (nano::write_transaction const & transaction_a) = 0; + virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; + virtual nano::store_iterator end () const = 0; +}; +} // namespace nano::store diff --git a/nano/store/pending.cpp b/nano/store/pending.cpp new file mode 100644 index 0000000000..dd80f3579b --- /dev/null +++ b/nano/store/pending.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/pending.hpp b/nano/store/pending.hpp new file mode 100644 index 0000000000..8944d2cb76 --- /dev/null +++ b/nano/store/pending.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include + +#include + +namespace nano +{ +class block_hash; +class read_transaction; +class transaction; +class write_transaction; +} +namespace nano +{ +/** + * Manages pending storage and iteration + */ +class pending_store +{ +public: + virtual void put (nano::write_transaction const &, nano::pending_key const &, nano::pending_info const &) = 0; + virtual void del (nano::write_transaction const &, nano::pending_key const &) = 0; + virtual bool get (nano::transaction const &, nano::pending_key const &, nano::pending_info &) = 0; + virtual bool exists (nano::transaction const &, nano::pending_key const &) = 0; + virtual bool any (nano::transaction const &, nano::account const &) = 0; + virtual nano::store_iterator begin (nano::transaction const &, nano::pending_key const &) const = 0; + virtual nano::store_iterator begin (nano::transaction const &) const = 0; + virtual nano::store_iterator end () const = 0; + virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; +}; +} // namespace nano::store diff --git a/nano/store/pruned.cpp b/nano/store/pruned.cpp new file mode 100644 index 0000000000..e4342c7b4d --- /dev/null +++ b/nano/store/pruned.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/pruned.hpp b/nano/store/pruned.hpp new file mode 100644 index 0000000000..f9b48a22c9 --- /dev/null +++ b/nano/store/pruned.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include +#include +#include + +#include + +namespace nano +{ +class block_hash; +class read_transaction; +class transaction; +class write_transaction; +} +namespace nano +{ +/** + * Manages pruned storage and iteration + */ +class pruned_store +{ +public: + virtual void put (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; + virtual void del (nano::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; + virtual bool exists (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; + virtual nano::block_hash random (nano::transaction const & transaction_a) = 0; + virtual size_t count (nano::transaction const & transaction_a) const = 0; + virtual void clear (nano::write_transaction const &) = 0; + virtual nano::store_iterator begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; + virtual nano::store_iterator begin (nano::transaction const & transaction_a) const = 0; + virtual nano::store_iterator end () const = 0; + virtual void for_each_par (std::function, nano::store_iterator)> const & action_a) const = 0; +}; +} // namespace nano::store diff --git a/nano/store/rocksdb/account.hpp b/nano/store/rocksdb/account.hpp index 445ee5abed..dfac80e1d0 100644 --- a/nano/store/rocksdb/account.hpp +++ b/nano/store/rocksdb/account.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano { diff --git a/nano/store/rocksdb/block.hpp b/nano/store/rocksdb/block.hpp index cc9ad528dd..05c38f7d51 100644 --- a/nano/store/rocksdb/block.hpp +++ b/nano/store/rocksdb/block.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/rocksdb/confirmation_height.hpp b/nano/store/rocksdb/confirmation_height.hpp index a4e7f7260b..abb4668ba4 100644 --- a/nano/store/rocksdb/confirmation_height.hpp +++ b/nano/store/rocksdb/confirmation_height.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano { diff --git a/nano/store/rocksdb/final_vote.hpp b/nano/store/rocksdb/final_vote.hpp index f8af2c2376..10b8a4ede0 100644 --- a/nano/store/rocksdb/final_vote.hpp +++ b/nano/store/rocksdb/final_vote.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano { diff --git a/nano/store/rocksdb/frontier.hpp b/nano/store/rocksdb/frontier.hpp index d0d346a2bc..e6b68ae95c 100644 --- a/nano/store/rocksdb/frontier.hpp +++ b/nano/store/rocksdb/frontier.hpp @@ -1,6 +1,7 @@ #pragma once -#include +#include +#include namespace nano { diff --git a/nano/store/rocksdb/online_weight.hpp b/nano/store/rocksdb/online_weight.hpp index fbc9f05690..ab4325328b 100644 --- a/nano/store/rocksdb/online_weight.hpp +++ b/nano/store/rocksdb/online_weight.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano { diff --git a/nano/store/rocksdb/peer.hpp b/nano/store/rocksdb/peer.hpp index 66b6da1918..16dbabf543 100644 --- a/nano/store/rocksdb/peer.hpp +++ b/nano/store/rocksdb/peer.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano { diff --git a/nano/store/rocksdb/pending.hpp b/nano/store/rocksdb/pending.hpp index 256197de51..afd773b02f 100644 --- a/nano/store/rocksdb/pending.hpp +++ b/nano/store/rocksdb/pending.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano { diff --git a/nano/store/rocksdb/pruned.hpp b/nano/store/rocksdb/pruned.hpp index ad8b6e1eba..29c03d7766 100644 --- a/nano/store/rocksdb/pruned.hpp +++ b/nano/store/rocksdb/pruned.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano { diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index a191ee769d..d7c74dd145 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include diff --git a/nano/store/rocksdb/version.hpp b/nano/store/rocksdb/version.hpp index 73d69bc765..4aaf0e0d5f 100644 --- a/nano/store/rocksdb/version.hpp +++ b/nano/store/rocksdb/version.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano { diff --git a/nano/store/version.cpp b/nano/store/version.cpp new file mode 100644 index 0000000000..d8917be835 --- /dev/null +++ b/nano/store/version.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/version.hpp b/nano/store/version.hpp new file mode 100644 index 0000000000..192cb032a8 --- /dev/null +++ b/nano/store/version.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +#include + +namespace nano +{ +class block_hash; +class read_transaction; +class transaction; +class write_transaction; +} +namespace nano +{ +/** + * Manages version storage + */ +class version_store +{ +public: + virtual void put (nano::write_transaction const &, int) = 0; + virtual int get (nano::transaction const &) const = 0; +}; + +} // namespace nano::store