Extracting classes in to their own files

This commit is contained in:
Colin LeMahieu 2023-09-19 00:27:30 +01:00
commit 41feb779b9
No known key found for this signature in database
GPG key ID: 43708520C8DFB938
72 changed files with 1225 additions and 910 deletions

View file

@ -9,6 +9,7 @@
#include <nano/node/json_handler.hpp> #include <nano/node/json_handler.hpp>
#include <nano/node/node.hpp> #include <nano/node/node.hpp>
#include <nano/node/transport/inproc.hpp> #include <nano/node/transport/inproc.hpp>
#include <nano/store/pending.hpp>
#include <boost/dll/runtime_symbol_info.hpp> #include <boost/dll/runtime_symbol_info.hpp>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>

View file

@ -2,7 +2,9 @@
#include <nano/node/transport/channel.hpp> #include <nano/node/transport/channel.hpp>
#include <nano/node/transport/transport.hpp> #include <nano/node/transport/transport.hpp>
#include <nano/secure/ledger.hpp> #include <nano/secure/ledger.hpp>
#include <nano/store/block.hpp>
#include <nano/store/component.hpp> #include <nano/store/component.hpp>
#include <nano/store/confirmation_height.hpp>
// TODO: Make threads configurable // 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) : 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) :

View file

@ -1,7 +1,9 @@
#include <nano/lib/utility.hpp> #include <nano/lib/utility.hpp>
#include <nano/node/bootstrap_ascending/iterators.hpp> #include <nano/node/bootstrap_ascending/iterators.hpp>
#include <nano/secure/common.hpp> #include <nano/secure/common.hpp>
#include <nano/store/account.hpp>
#include <nano/store/component.hpp> #include <nano/store/component.hpp>
#include <nano/store/pending.hpp>
/* /*
* database_iterator * database_iterator

View file

@ -6,6 +6,7 @@
#include <nano/node/transport/transport.hpp> #include <nano/node/transport/transport.hpp>
#include <nano/secure/common.hpp> #include <nano/secure/common.hpp>
#include <nano/secure/ledger.hpp> #include <nano/secure/ledger.hpp>
#include <nano/store/account.hpp>
#include <nano/store/component.hpp> #include <nano/store/component.hpp>
using namespace std::chrono_literals; using namespace std::chrono_literals;

View file

@ -4,6 +4,9 @@
#include <nano/node/logging.hpp> #include <nano/node/logging.hpp>
#include <nano/node/write_database_queue.hpp> #include <nano/node/write_database_queue.hpp>
#include <nano/secure/ledger.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> #include <boost/format.hpp>

View file

@ -4,6 +4,9 @@
#include <nano/node/logging.hpp> #include <nano/node/logging.hpp>
#include <nano/node/write_database_queue.hpp> #include <nano/node/write_database_queue.hpp>
#include <nano/secure/ledger.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> #include <boost/format.hpp>

View file

@ -6,6 +6,7 @@
#include <nano/node/ledger_walker.hpp> #include <nano/node/ledger_walker.hpp>
#include <nano/secure/ledger.hpp> #include <nano/secure/ledger.hpp>
#include <nano/secure/utility.hpp> #include <nano/secure/utility.hpp>
#include <nano/store/block.hpp>
#include <nano/store/component.hpp> #include <nano/store/component.hpp>
#include <algorithm> #include <algorithm>

View file

@ -2,6 +2,7 @@
#include <nano/node/online_reps.hpp> #include <nano/node/online_reps.hpp>
#include <nano/secure/ledger.hpp> #include <nano/secure/ledger.hpp>
#include <nano/store/component.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) : nano::online_reps::online_reps (nano::ledger & ledger_a, nano::node_config const & config_a) :
ledger{ ledger_a }, ledger{ ledger_a },

View file

@ -5,7 +5,17 @@
#include <nano/node/make_store.hpp> #include <nano/node/make_store.hpp>
#include <nano/secure/common.hpp> #include <nano/secure/common.hpp>
#include <nano/secure/ledger.hpp> #include <nano/secure/ledger.hpp>
#include <nano/store/account.hpp>
#include <nano/store/block.hpp>
#include <nano/store/component.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> #include <boost/filesystem.hpp>

View file

@ -1,9 +1,18 @@
add_library( add_library(
nano_store nano_store
account.hpp
block.hpp
component.hpp component.hpp
confirmation_height.hpp
db_val.hpp
iterator.hpp
iterator_impl.hpp
final.hpp
frontier.hpp
lmdb/account.hpp lmdb/account.hpp
lmdb/block.hpp lmdb/block.hpp
lmdb/confirmation_height.hpp lmdb/confirmation_height.hpp
lmdb/db_val.hpp
lmdb/final_vote.hpp lmdb/final_vote.hpp
lmdb/frontier.hpp lmdb/frontier.hpp
lmdb/lmdb.hpp lmdb/lmdb.hpp
@ -17,9 +26,14 @@ add_library(
lmdb/transaction_impl.hpp lmdb/transaction_impl.hpp
lmdb/version.hpp lmdb/version.hpp
lmdb/wallet_value.hpp lmdb/wallet_value.hpp
online_weight.hpp
peer.hpp
pending.hpp
pruned.hpp
rocksdb/account.hpp rocksdb/account.hpp
rocksdb/block.hpp rocksdb/block.hpp
rocksdb/confirmation_height.hpp rocksdb/confirmation_height.hpp
rocksdb/db_val.hpp
rocksdb/final_vote.hpp rocksdb/final_vote.hpp
rocksdb/frontier.hpp rocksdb/frontier.hpp
rocksdb/iterator.hpp rocksdb/iterator.hpp
@ -30,11 +44,23 @@ add_library(
rocksdb/rocksdb.hpp rocksdb/rocksdb.hpp
rocksdb/transaction_impl.hpp rocksdb/transaction_impl.hpp
rocksdb/version.hpp rocksdb/version.hpp
tables.hpp
transaction.hpp
version.hpp
versioning.hpp versioning.hpp
account.cpp
block.cpp
component.cpp component.cpp
confirmation_height.cpp
db_val.cpp
iterator.cpp
iterator_impl.cpp
final.cpp
frontier.cpp
lmdb/account.cpp lmdb/account.cpp
lmdb/block.cpp lmdb/block.cpp
lmdb/confirmation_height.cpp lmdb/confirmation_height.cpp
lmdb/db_val.cpp
lmdb/final_vote.cpp lmdb/final_vote.cpp
lmdb/frontier.cpp lmdb/frontier.cpp
lmdb/lmdb.cpp lmdb/lmdb.cpp
@ -46,9 +72,14 @@ add_library(
lmdb/pruned.cpp lmdb/pruned.cpp
lmdb/version.cpp lmdb/version.cpp
lmdb/wallet_value.cpp lmdb/wallet_value.cpp
online_weight.cpp
peer.cpp
pending.cpp
pruned.cpp
rocksdb/account.cpp rocksdb/account.cpp
rocksdb/block.cpp rocksdb/block.cpp
rocksdb/confirmation_height.cpp rocksdb/confirmation_height.cpp
rocksdb/db_val.cpp
rocksdb/final_vote.cpp rocksdb/final_vote.cpp
rocksdb/frontier.cpp rocksdb/frontier.cpp
rocksdb/online_weight.cpp rocksdb/online_weight.cpp
@ -58,6 +89,8 @@ add_library(
rocksdb/rocksdb.cpp rocksdb/rocksdb.cpp
rocksdb/transaction.cpp rocksdb/transaction.cpp
rocksdb/version.cpp rocksdb/version.cpp
transaction.cpp
version.cpp
versioning.cpp) versioning.cpp)
target_link_libraries( target_link_libraries(

15
nano/store/account.cpp Normal file
View file

@ -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
nano/store/account.hpp Normal file
View file

@ -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
nano/store/block.cpp Normal file
View file

@ -0,0 +1 @@
#include <nano/store/block.hpp>

45
nano/store/block.hpp Normal file
View file

@ -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

View file

@ -1,67 +1,9 @@
#include <nano/lib/thread_roles.hpp>
#include <nano/lib/timer.hpp> #include <nano/lib/timer.hpp>
#include <nano/store/account.hpp>
#include <nano/store/block.hpp>
#include <nano/store/component.hpp> #include <nano/store/component.hpp>
#include <nano/store/confirmation_height.hpp>
nano::read_transaction::read_transaction (std::unique_ptr<nano::read_transaction_impl> read_transaction_impl) : #include <nano/store/frontier.hpp>
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);
}
// clang-format off // clang-format off
nano::store::component::component ( nano::store::component::component (
@ -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 ()); 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 ()); 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;
}
}

View file

@ -4,6 +4,8 @@
#include <nano/lib/memory.hpp> #include <nano/lib/memory.hpp>
#include <nano/secure/buffer.hpp> #include <nano/secure/buffer.hpp>
#include <nano/secure/common.hpp> #include <nano/secure/common.hpp>
#include <nano/store/tables.hpp>
#include <nano/store/transaction.hpp>
#include <nano/store/versioning.hpp> #include <nano/store/versioning.hpp>
#include <boost/endian/conversion.hpp> #include <boost/endian/conversion.hpp>
@ -13,723 +15,17 @@
namespace nano namespace nano
{ {
// Move to versioning with a specific version if required for a future upgrade class account_store;
template <typename T> class block_store;
class block_w_sideband_v18 class confirmation_height_store;
{ class final_vote_store;
public: class frontier_store;
std::shared_ptr<T> block;
nano::block_sideband_v18 sideband;
};
class block_w_sideband
{
public:
std::shared_ptr<nano::block> block;
nano::block_sideband sideband;
};
/**
* Encapsulates database specific container
*/
template <typename Val>
class db_val
{
public:
db_val (Val const & value_a) :
value (value_a)
{
}
db_val () :
db_val (0, nullptr)
{
}
db_val (std::nullptr_t) :
db_val (0, this)
{
}
db_val (nano::uint128_union const & val_a) :
db_val (sizeof (val_a), const_cast<nano::uint128_union *> (&val_a))
{
}
db_val (nano::uint256_union const & val_a) :
db_val (sizeof (val_a), const_cast<nano::uint256_union *> (&val_a))
{
}
db_val (nano::uint512_union const & val_a) :
db_val (sizeof (val_a), const_cast<nano::uint512_union *> (&val_a))
{
}
db_val (nano::qualified_root const & val_a) :
db_val (sizeof (val_a), const_cast<nano::qualified_root *> (&val_a))
{
}
db_val (nano::account_info const & val_a) :
db_val (val_a.db_size (), const_cast<nano::account_info *> (&val_a))
{
}
db_val (nano::account_info_v14 const & val_a) :
db_val (val_a.db_size (), const_cast<nano::account_info_v14 *> (&val_a))
{
}
db_val (nano::pending_info const & val_a) :
db_val (val_a.db_size (), const_cast<nano::pending_info *> (&val_a))
{
static_assert (std::is_standard_layout<nano::pending_info>::value, "Standard layout is required");
}
db_val (nano::pending_info_v14 const & val_a) :
db_val (val_a.db_size (), const_cast<nano::pending_info_v14 *> (&val_a))
{
static_assert (std::is_standard_layout<nano::pending_info_v14>::value, "Standard layout is required");
}
db_val (nano::pending_key const & val_a) :
db_val (sizeof (val_a), const_cast<nano::pending_key *> (&val_a))
{
static_assert (std::is_standard_layout<nano::pending_key>::value, "Standard layout is required");
}
db_val (nano::confirmation_height_info const & val_a) :
buffer (std::make_shared<std::vector<uint8_t>> ())
{
{
nano::vectorstream stream (*buffer);
val_a.serialize (stream);
}
convert_buffer_to_value ();
}
db_val (nano::block_info const & val_a) :
db_val (sizeof (val_a), const_cast<nano::block_info *> (&val_a))
{
static_assert (std::is_standard_layout<nano::block_info>::value, "Standard layout is required");
}
db_val (nano::endpoint_key const & val_a) :
db_val (sizeof (val_a), const_cast<nano::endpoint_key *> (&val_a))
{
static_assert (std::is_standard_layout<nano::endpoint_key>::value, "Standard layout is required");
}
db_val (std::shared_ptr<nano::block> const & val_a) :
buffer (std::make_shared<std::vector<uint8_t>> ())
{
{
nano::vectorstream stream (*buffer);
nano::serialize_block (stream, *val_a);
}
convert_buffer_to_value ();
}
db_val (uint64_t val_a) :
buffer (std::make_shared<std::vector<uint8_t>> ())
{
{
boost::endian::native_to_big_inplace (val_a);
nano::vectorstream stream (*buffer);
nano::write (stream, val_a);
}
convert_buffer_to_value ();
}
explicit operator nano::account_info () const
{
nano::account_info result;
debug_assert (size () == result.db_size ());
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + result.db_size (), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::account_info_v14 () const
{
nano::account_info_v14 result;
debug_assert (size () == result.db_size ());
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + result.db_size (), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::block_info () const
{
nano::block_info result;
debug_assert (size () == sizeof (result));
static_assert (sizeof (nano::block_info::account) + sizeof (nano::block_info::balance) == sizeof (result), "Packed class");
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::pending_info_v14 () const
{
nano::pending_info_v14 result;
debug_assert (size () == result.db_size ());
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + result.db_size (), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::pending_info () const
{
nano::pending_info result;
debug_assert (size () == result.db_size ());
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + result.db_size (), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::pending_key () const
{
nano::pending_key result;
debug_assert (size () == sizeof (result));
static_assert (sizeof (nano::pending_key::account) + sizeof (nano::pending_key::hash) == sizeof (result), "Packed class");
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::confirmation_height_info () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
nano::confirmation_height_info result;
bool error (result.deserialize (stream));
(void)error;
debug_assert (!error);
return result;
}
explicit operator nano::uint128_union () const
{
return convert<nano::uint128_union> ();
}
explicit operator nano::amount () const
{
return convert<nano::amount> ();
}
explicit operator nano::block_hash () const
{
return convert<nano::block_hash> ();
}
explicit operator nano::public_key () const
{
return convert<nano::public_key> ();
}
explicit operator nano::qualified_root () const
{
return convert<nano::qualified_root> ();
}
explicit operator nano::uint256_union () const
{
return convert<nano::uint256_union> ();
}
explicit operator nano::uint512_union () const
{
return convert<nano::uint512_union> ();
}
explicit operator std::array<char, 64> () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
std::array<char, 64> result;
auto error = nano::try_read (stream, result);
(void)error;
debug_assert (!error);
return result;
}
explicit operator nano::endpoint_key () const
{
nano::endpoint_key result;
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), reinterpret_cast<uint8_t *> (&result));
return result;
}
template <class Block>
explicit operator block_w_sideband_v18<Block> () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
auto error (false);
block_w_sideband_v18<Block> block_w_sideband;
block_w_sideband.block = std::make_shared<Block> (error, stream);
release_assert (!error);
error = block_w_sideband.sideband.deserialize (stream, block_w_sideband.block->type ());
release_assert (!error);
return block_w_sideband;
}
explicit operator block_w_sideband () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
nano::block_w_sideband block_w_sideband;
block_w_sideband.block = (nano::deserialize_block (stream));
auto error = block_w_sideband.sideband.deserialize (stream, block_w_sideband.block->type ());
release_assert (!error);
block_w_sideband.block->sideband_set (block_w_sideband.sideband);
return block_w_sideband;
}
explicit operator state_block_w_sideband_v14 () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
auto error (false);
nano::state_block_w_sideband_v14 block_w_sideband;
block_w_sideband.state_block = std::make_shared<nano::state_block> (error, stream);
debug_assert (!error);
block_w_sideband.sideband.type = nano::block_type::state;
error = block_w_sideband.sideband.deserialize (stream);
debug_assert (!error);
return block_w_sideband;
}
explicit operator std::nullptr_t () const
{
return nullptr;
}
explicit operator nano::no_value () const
{
return no_value::dummy;
}
explicit operator std::shared_ptr<nano::block> () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
std::shared_ptr<nano::block> result (nano::deserialize_block (stream));
return result;
}
template <typename Block>
std::shared_ptr<Block> convert_to_block () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
auto error (false);
auto result (std::make_shared<Block> (error, stream));
debug_assert (!error);
return result;
}
explicit operator std::shared_ptr<nano::send_block> () const
{
return convert_to_block<nano::send_block> ();
}
explicit operator std::shared_ptr<nano::receive_block> () const
{
return convert_to_block<nano::receive_block> ();
}
explicit operator std::shared_ptr<nano::open_block> () const
{
return convert_to_block<nano::open_block> ();
}
explicit operator std::shared_ptr<nano::change_block> () const
{
return convert_to_block<nano::change_block> ();
}
explicit operator std::shared_ptr<nano::state_block> () const
{
return convert_to_block<nano::state_block> ();
}
explicit operator std::shared_ptr<nano::vote> () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
auto error (false);
auto result (nano::make_shared<nano::vote> (error, stream));
debug_assert (!error);
return result;
}
explicit operator uint64_t () const
{
uint64_t result;
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
auto error (nano::try_read (stream, result));
(void)error;
debug_assert (!error);
boost::endian::big_to_native_inplace (result);
return result;
}
operator Val * () const
{
// Allow passing a temporary to a non-c++ function which doesn't have constness
return const_cast<Val *> (&value);
}
operator Val const & () const
{
return value;
}
// Must be specialized
void * data () const;
size_t size () const;
db_val (size_t size_a, void * data_a);
void convert_buffer_to_value ();
Val value;
std::shared_ptr<std::vector<uint8_t>> buffer;
private:
template <typename T>
T convert () const
{
T result;
debug_assert (size () == sizeof (result));
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), result.bytes.data ());
return result;
}
};
template <typename T, typename U>
class store_iterator_impl
{
public:
virtual ~store_iterator_impl () = default;
virtual nano::store_iterator_impl<T, U> & operator++ () = 0;
virtual nano::store_iterator_impl<T, U> & operator-- () = 0;
virtual bool operator== (nano::store_iterator_impl<T, U> const & other_a) const = 0;
virtual bool is_end_sentinal () const = 0;
virtual void fill (std::pair<T, U> &) const = 0;
nano::store_iterator_impl<T, U> & operator= (nano::store_iterator_impl<T, U> const &) = delete;
bool operator== (nano::store_iterator_impl<T, U> const * other_a) const
{
return (other_a != nullptr && *this == *other_a) || (other_a == nullptr && is_end_sentinal ());
}
bool operator!= (nano::store_iterator_impl<T, U> const & other_a) const
{
return !(*this == other_a);
}
};
/**
* Iterates the key/value pairs of a transaction
*/
template <typename T, typename U>
class store_iterator final
{
public:
store_iterator (std::nullptr_t)
{
}
store_iterator (std::unique_ptr<nano::store_iterator_impl<T, U>> impl_a) :
impl (std::move (impl_a))
{
impl->fill (current);
}
store_iterator (nano::store_iterator<T, U> && other_a) :
current (std::move (other_a.current)),
impl (std::move (other_a.impl))
{
}
nano::store_iterator<T, U> & operator++ ()
{
++*impl;
impl->fill (current);
return *this;
}
nano::store_iterator<T, U> & operator-- ()
{
--*impl;
impl->fill (current);
return *this;
}
nano::store_iterator<T, U> & operator= (nano::store_iterator<T, U> && other_a) noexcept
{
impl = std::move (other_a.impl);
current = std::move (other_a.current);
return *this;
}
nano::store_iterator<T, U> & operator= (nano::store_iterator<T, U> const &) = delete;
std::pair<T, U> * operator-> ()
{
return &current;
}
bool operator== (nano::store_iterator<T, U> 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<T, U> const & other_a) const
{
return !(*this == other_a);
}
private:
std::pair<T, U> current;
std::unique_ptr<nano::store_iterator_impl<T, U>> impl;
};
// Keep this in alphabetical order
enum class tables
{
accounts,
blocks,
confirmation_height,
default_unused, // RocksDB only
final_votes,
frontiers,
meta,
online_weight,
peers,
pending,
pruned,
vote
};
class transaction_impl
{
public:
virtual ~transaction_impl () = default;
virtual void * get_handle () const = 0;
};
class read_transaction_impl : public transaction_impl
{
public:
virtual void reset () = 0;
virtual void renew () = 0;
};
class write_transaction_impl : public transaction_impl
{
public:
virtual void commit () = 0;
virtual void renew () = 0;
virtual bool contains (nano::tables table_a) const = 0;
};
class transaction
{
public:
virtual ~transaction () = default;
virtual void * get_handle () const = 0;
};
/**
* RAII wrapper of a read MDB_txn where the constructor starts the transaction
* and the destructor aborts it.
*/
class read_transaction final : public transaction
{
public:
explicit read_transaction (std::unique_ptr<nano::read_transaction_impl> read_transaction_impl);
void * get_handle () const override;
void reset () const;
void renew () const;
void refresh () const;
private:
std::unique_ptr<nano::read_transaction_impl> impl;
};
/**
* RAII wrapper of a read-write MDB_txn where the constructor starts the transaction
* and the destructor commits it.
*/
class write_transaction final : public transaction
{
public:
explicit write_transaction (std::unique_ptr<nano::write_transaction_impl> write_transaction_impl);
void * get_handle () const override;
void commit ();
void renew ();
void refresh ();
bool contains (nano::tables table_a) const;
private:
std::unique_ptr<nano::write_transaction_impl> impl;
};
class ledger_cache; class ledger_cache;
class online_weight_store;
/** class peer_store;
* Manages frontier storage and iteration class pending_store;
*/ class pruned_store;
class frontier_store class version_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<nano::block_hash, nano::account> begin (nano::transaction const &) const = 0;
virtual nano::store_iterator<nano::block_hash, nano::account> begin (nano::transaction const &, nano::block_hash const &) const = 0;
virtual nano::store_iterator<nano::block_hash, nano::account> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::block_hash, nano::account>, nano::store_iterator<nano::block_hash, nano::account>)> 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<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;
};
/**
* 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<nano::pending_key, nano::pending_info> begin (nano::transaction const &, nano::pending_key const &) const = 0;
virtual nano::store_iterator<nano::pending_key, nano::pending_info> begin (nano::transaction const &) const = 0;
virtual nano::store_iterator<nano::pending_key, nano::pending_info> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::pending_key, nano::pending_info>, nano::store_iterator<nano::pending_key, nano::pending_info>)> 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<nano::endpoint_key, nano::no_value> begin (nano::transaction const & transaction_a) const = 0;
virtual nano::store_iterator<nano::endpoint_key, nano::no_value> 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<uint64_t, nano::amount> begin (nano::transaction const &) const = 0;
virtual nano::store_iterator<uint64_t, nano::amount> rbegin (nano::transaction const &) const = 0;
virtual nano::store_iterator<uint64_t, nano::amount> 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<nano::block_hash, std::nullptr_t> begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0;
virtual nano::store_iterator<nano::block_hash, std::nullptr_t> begin (nano::transaction const & transaction_a) const = 0;
virtual nano::store_iterator<nano::block_hash, std::nullptr_t> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::block_hash, std::nullptr_t>, nano::store_iterator<nano::block_hash, std::nullptr_t>)> 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<nano::confirmation_height_info> 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<nano::account, nano::confirmation_height_info> begin (nano::transaction const & transaction_a, nano::account const & account_a) const = 0;
virtual nano::store_iterator<nano::account, nano::confirmation_height_info> begin (nano::transaction const & transaction_a) const = 0;
virtual nano::store_iterator<nano::account, nano::confirmation_height_info> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::account, nano::confirmation_height_info>, nano::store_iterator<nano::account, nano::confirmation_height_info>)> 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<nano::block_hash> 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<nano::qualified_root, nano::block_hash> begin (nano::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0;
virtual nano::store_iterator<nano::qualified_root, nano::block_hash> begin (nano::transaction const & transaction_a) const = 0;
virtual nano::store_iterator<nano::qualified_root, nano::block_hash> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::qualified_root, nano::block_hash>, nano::store_iterator<nano::qualified_root, nano::block_hash>)> 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<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 store namespace store
{ {
@ -801,15 +97,3 @@ namespace store
}; };
} // namespace store } // namespace store
} // namespace nano } // namespace nano
namespace std
{
template <>
struct hash<::nano::tables>
{
size_t operator() (::nano::tables const & table_a) const
{
return static_cast<size_t> (table_a);
}
};
}

View file

@ -0,0 +1,15 @@
#include <nano/store/confirmation_height.hpp>
std::optional<nano::confirmation_height_info> 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;
}
}

View file

@ -0,0 +1,43 @@
#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 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<nano::confirmation_height_info> 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<nano::account, nano::confirmation_height_info> begin (nano::transaction const & transaction_a, nano::account const & account_a) const = 0;
virtual nano::store_iterator<nano::account, nano::confirmation_height_info> begin (nano::transaction const & transaction_a) const = 0;
virtual nano::store_iterator<nano::account, nano::confirmation_height_info> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::account, nano::confirmation_height_info>, nano::store_iterator<nano::account, nano::confirmation_height_info>)> const &) const = 0;
};
} // namespace nano::store

1
nano/store/db_val.cpp Normal file
View file

@ -0,0 +1 @@
#include <nano/store/db_val.hpp>

381
nano/store/db_val.hpp Normal file
View file

@ -0,0 +1,381 @@
#pragma once
#include <nano/lib/numbers.hpp>
#include <nano/secure/buffer.hpp>
#include <nano/secure/common.hpp>
#include <nano/store/block.hpp>
#include <nano/store/component.hpp>
#include <nano/store/versioning.hpp>
#include <cstddef>
namespace nano
{
/**
* Encapsulates database specific container
*/
template <typename Val>
class db_val
{
public:
db_val (Val const & value_a) :
value (value_a)
{
}
db_val () :
db_val (0, nullptr)
{
}
db_val (std::nullptr_t) :
db_val (0, this)
{
}
db_val (nano::uint128_union const & val_a) :
db_val (sizeof (val_a), const_cast<nano::uint128_union *> (&val_a))
{
}
db_val (nano::uint256_union const & val_a) :
db_val (sizeof (val_a), const_cast<nano::uint256_union *> (&val_a))
{
}
db_val (nano::uint512_union const & val_a) :
db_val (sizeof (val_a), const_cast<nano::uint512_union *> (&val_a))
{
}
db_val (nano::qualified_root const & val_a) :
db_val (sizeof (val_a), const_cast<nano::qualified_root *> (&val_a))
{
}
db_val (nano::account_info const & val_a) :
db_val (val_a.db_size (), const_cast<nano::account_info *> (&val_a))
{
}
db_val (nano::account_info_v14 const & val_a) :
db_val (val_a.db_size (), const_cast<nano::account_info_v14 *> (&val_a))
{
}
db_val (nano::pending_info const & val_a) :
db_val (val_a.db_size (), const_cast<nano::pending_info *> (&val_a))
{
static_assert (std::is_standard_layout<nano::pending_info>::value, "Standard layout is required");
}
db_val (nano::pending_info_v14 const & val_a) :
db_val (val_a.db_size (), const_cast<nano::pending_info_v14 *> (&val_a))
{
static_assert (std::is_standard_layout<nano::pending_info_v14>::value, "Standard layout is required");
}
db_val (nano::pending_key const & val_a) :
db_val (sizeof (val_a), const_cast<nano::pending_key *> (&val_a))
{
static_assert (std::is_standard_layout<nano::pending_key>::value, "Standard layout is required");
}
db_val (nano::confirmation_height_info const & val_a) :
buffer (std::make_shared<std::vector<uint8_t>> ())
{
{
nano::vectorstream stream (*buffer);
val_a.serialize (stream);
}
convert_buffer_to_value ();
}
db_val (nano::block_info const & val_a) :
db_val (sizeof (val_a), const_cast<nano::block_info *> (&val_a))
{
static_assert (std::is_standard_layout<nano::block_info>::value, "Standard layout is required");
}
db_val (nano::endpoint_key const & val_a) :
db_val (sizeof (val_a), const_cast<nano::endpoint_key *> (&val_a))
{
static_assert (std::is_standard_layout<nano::endpoint_key>::value, "Standard layout is required");
}
db_val (std::shared_ptr<nano::block> const & val_a) :
buffer (std::make_shared<std::vector<uint8_t>> ())
{
{
nano::vectorstream stream (*buffer);
nano::serialize_block (stream, *val_a);
}
convert_buffer_to_value ();
}
db_val (uint64_t val_a) :
buffer (std::make_shared<std::vector<uint8_t>> ())
{
{
boost::endian::native_to_big_inplace (val_a);
nano::vectorstream stream (*buffer);
nano::write (stream, val_a);
}
convert_buffer_to_value ();
}
explicit operator nano::account_info () const
{
nano::account_info result;
debug_assert (size () == result.db_size ());
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + result.db_size (), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::account_info_v14 () const
{
nano::account_info_v14 result;
debug_assert (size () == result.db_size ());
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + result.db_size (), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::block_info () const
{
nano::block_info result;
debug_assert (size () == sizeof (result));
static_assert (sizeof (nano::block_info::account) + sizeof (nano::block_info::balance) == sizeof (result), "Packed class");
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::pending_info_v14 () const
{
nano::pending_info_v14 result;
debug_assert (size () == result.db_size ());
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + result.db_size (), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::pending_info () const
{
nano::pending_info result;
debug_assert (size () == result.db_size ());
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + result.db_size (), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::pending_key () const
{
nano::pending_key result;
debug_assert (size () == sizeof (result));
static_assert (sizeof (nano::pending_key::account) + sizeof (nano::pending_key::hash) == sizeof (result), "Packed class");
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), reinterpret_cast<uint8_t *> (&result));
return result;
}
explicit operator nano::confirmation_height_info () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
nano::confirmation_height_info result;
bool error (result.deserialize (stream));
(void)error;
debug_assert (!error);
return result;
}
explicit operator nano::uint128_union () const
{
return convert<nano::uint128_union> ();
}
explicit operator nano::amount () const
{
return convert<nano::amount> ();
}
explicit operator nano::block_hash () const
{
return convert<nano::block_hash> ();
}
explicit operator nano::public_key () const
{
return convert<nano::public_key> ();
}
explicit operator nano::qualified_root () const
{
return convert<nano::qualified_root> ();
}
explicit operator nano::uint256_union () const
{
return convert<nano::uint256_union> ();
}
explicit operator nano::uint512_union () const
{
return convert<nano::uint512_union> ();
}
explicit operator std::array<char, 64> () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
std::array<char, 64> result;
auto error = nano::try_read (stream, result);
(void)error;
debug_assert (!error);
return result;
}
explicit operator nano::endpoint_key () const
{
nano::endpoint_key result;
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), reinterpret_cast<uint8_t *> (&result));
return result;
}
template <class Block>
explicit operator block_w_sideband_v18<Block> () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
auto error (false);
block_w_sideband_v18<Block> block_w_sideband;
block_w_sideband.block = std::make_shared<Block> (error, stream);
release_assert (!error);
error = block_w_sideband.sideband.deserialize (stream, block_w_sideband.block->type ());
release_assert (!error);
return block_w_sideband;
}
explicit operator block_w_sideband () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
nano::block_w_sideband block_w_sideband;
block_w_sideband.block = (nano::deserialize_block (stream));
auto error = block_w_sideband.sideband.deserialize (stream, block_w_sideband.block->type ());
release_assert (!error);
block_w_sideband.block->sideband_set (block_w_sideband.sideband);
return block_w_sideband;
}
explicit operator state_block_w_sideband_v14 () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
auto error (false);
nano::state_block_w_sideband_v14 block_w_sideband;
block_w_sideband.state_block = std::make_shared<nano::state_block> (error, stream);
debug_assert (!error);
block_w_sideband.sideband.type = nano::block_type::state;
error = block_w_sideband.sideband.deserialize (stream);
debug_assert (!error);
return block_w_sideband;
}
explicit operator std::nullptr_t () const
{
return nullptr;
}
explicit operator nano::no_value () const
{
return no_value::dummy;
}
explicit operator std::shared_ptr<nano::block> () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
std::shared_ptr<nano::block> result (nano::deserialize_block (stream));
return result;
}
template <typename Block>
std::shared_ptr<Block> convert_to_block () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
auto error (false);
auto result (std::make_shared<Block> (error, stream));
debug_assert (!error);
return result;
}
explicit operator std::shared_ptr<nano::send_block> () const
{
return convert_to_block<nano::send_block> ();
}
explicit operator std::shared_ptr<nano::receive_block> () const
{
return convert_to_block<nano::receive_block> ();
}
explicit operator std::shared_ptr<nano::open_block> () const
{
return convert_to_block<nano::open_block> ();
}
explicit operator std::shared_ptr<nano::change_block> () const
{
return convert_to_block<nano::change_block> ();
}
explicit operator std::shared_ptr<nano::state_block> () const
{
return convert_to_block<nano::state_block> ();
}
explicit operator std::shared_ptr<nano::vote> () const
{
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
auto error (false);
auto result (nano::make_shared<nano::vote> (error, stream));
debug_assert (!error);
return result;
}
explicit operator uint64_t () const
{
uint64_t result;
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (data ()), size ());
auto error (nano::try_read (stream, result));
(void)error;
debug_assert (!error);
boost::endian::big_to_native_inplace (result);
return result;
}
operator Val * () const
{
// Allow passing a temporary to a non-c++ function which doesn't have constness
return const_cast<Val *> (&value);
}
operator Val const & () const
{
return value;
}
// Must be specialized
void * data () const;
size_t size () const;
db_val (size_t size_a, void * data_a);
void convert_buffer_to_value ();
Val value;
std::shared_ptr<std::vector<uint8_t>> buffer;
private:
template <typename T>
T convert () const
{
T result;
debug_assert (size () == sizeof (result));
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), result.bytes.data ());
return result;
}
};
} // namespace nano

1
nano/store/final.cpp Normal file
View file

@ -0,0 +1 @@
#include <nano/store/final.hpp>

35
nano/store/final.hpp Normal file
View file

@ -0,0 +1,35 @@
#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 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<nano::block_hash> 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<nano::qualified_root, nano::block_hash> begin (nano::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0;
virtual nano::store_iterator<nano::qualified_root, nano::block_hash> begin (nano::transaction const & transaction_a) const = 0;
virtual nano::store_iterator<nano::qualified_root, nano::block_hash> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::qualified_root, nano::block_hash>, nano::store_iterator<nano::qualified_root, nano::block_hash>)> const & action_a) const = 0;
};
} // namespace nano::store

1
nano/store/frontier.cpp Normal file
View file

@ -0,0 +1 @@
#include <nano/store/frontier.hpp>

32
nano/store/frontier.hpp Normal file
View file

@ -0,0 +1,32 @@
#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 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<nano::block_hash, nano::account> begin (nano::transaction const &) const = 0;
virtual nano::store_iterator<nano::block_hash, nano::account> begin (nano::transaction const &, nano::block_hash const &) const = 0;
virtual nano::store_iterator<nano::block_hash, nano::account> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::block_hash, nano::account>, nano::store_iterator<nano::block_hash, nano::account>)> const & action_a) const = 0;
};
} // namespace nano::store

1
nano/store/iterator.cpp Normal file
View file

@ -0,0 +1 @@
#include <nano/store/iterator.hpp>

65
nano/store/iterator.hpp Normal file
View file

@ -0,0 +1,65 @@
#pragma once
#include <nano/store/iterator_impl.hpp>
#include <memory>
namespace nano
{
/**
* Iterates the key/value pairs of a transaction
*/
template <typename T, typename U>
class store_iterator final
{
public:
store_iterator (std::nullptr_t)
{
}
store_iterator (std::unique_ptr<nano::store_iterator_impl<T, U>> impl_a) :
impl (std::move (impl_a))
{
impl->fill (current);
}
store_iterator (nano::store_iterator<T, U> && other_a) :
current (std::move (other_a.current)),
impl (std::move (other_a.impl))
{
}
nano::store_iterator<T, U> & operator++ ()
{
++*impl;
impl->fill (current);
return *this;
}
nano::store_iterator<T, U> & operator-- ()
{
--*impl;
impl->fill (current);
return *this;
}
nano::store_iterator<T, U> & operator= (nano::store_iterator<T, U> && other_a) noexcept
{
impl = std::move (other_a.impl);
current = std::move (other_a.current);
return *this;
}
nano::store_iterator<T, U> & operator= (nano::store_iterator<T, U> const &) = delete;
std::pair<T, U> * operator-> ()
{
return &current;
}
bool operator== (nano::store_iterator<T, U> 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<T, U> const & other_a) const
{
return !(*this == other_a);
}
private:
std::pair<T, U> current;
std::unique_ptr<nano::store_iterator_impl<T, U>> impl;
};
} // namespace nano::store

View file

@ -0,0 +1 @@
#include <nano/store/iterator_impl.hpp>

View file

@ -0,0 +1,27 @@
#pragma once
#include <utility>
namespace nano
{
template <typename T, typename U>
class store_iterator_impl
{
public:
virtual ~store_iterator_impl () = default;
virtual nano::store_iterator_impl<T, U> & operator++ () = 0;
virtual nano::store_iterator_impl<T, U> & operator-- () = 0;
virtual bool operator== (nano::store_iterator_impl<T, U> const & other_a) const = 0;
virtual bool is_end_sentinal () const = 0;
virtual void fill (std::pair<T, U> &) const = 0;
nano::store_iterator_impl<T, U> & operator= (nano::store_iterator_impl<T, U> const &) = delete;
bool operator== (nano::store_iterator_impl<T, U> const * other_a) const
{
return (other_a != nullptr && *this == *other_a) || (other_a == nullptr && is_end_sentinal ());
}
bool operator!= (nano::store_iterator_impl<T, U> const & other_a) const
{
return !(*this == other_a);
}
};
} // namespace nano::store

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/account.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>

View file

@ -1,12 +1,12 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/block.hpp>
#include <nano/store/lmdb/db_val.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>
namespace nano namespace nano
{ {
using mdb_val = db_val<MDB_val>;
class block_predecessor_mdb_set; class block_predecessor_mdb_set;
namespace lmdb namespace lmdb
{ {

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/confirmation_height.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>

View file

@ -0,0 +1,28 @@
#include <nano/store/lmdb/db_val.hpp>
namespace nano
{
template <>
void * mdb_val::data () const
{
return value.mv_data;
}
template <>
std::size_t mdb_val::size () const
{
return value.mv_size;
}
template <>
mdb_val::db_val (std::size_t size_a, void * data_a) :
value ({ size_a, data_a })
{
}
template <>
void mdb_val::convert_buffer_to_value ()
{
value = { buffer->size (), const_cast<uint8_t *> (buffer->data ()) };
}
}

View file

@ -0,0 +1,10 @@
#pragma once
#include <nano/store/db_val.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h>
namespace nano
{
using mdb_val = db_val<MDB_val>;
}

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/final.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/frontier.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>

View file

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/component.hpp>
#include <nano/store/db_val.hpp>
#include <nano/store/iterator.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>

View file

@ -1,9 +1,10 @@
#include <nano/lib/utility.hpp> #include <nano/lib/utility.hpp>
#include <nano/secure/buffer.hpp> #include <nano/secure/buffer.hpp>
#include <nano/secure/ledger.hpp> #include <nano/secure/ledger.hpp>
#include <nano/store/lmdb/lmdb.hpp>
#include <nano/store/lmdb/iterator.hpp> #include <nano/store/lmdb/iterator.hpp>
#include <nano/store/lmdb/lmdb.hpp>
#include <nano/store/lmdb/wallet_value.hpp> #include <nano/store/lmdb/wallet_value.hpp>
#include <nano/store/version.hpp>
#include <nano/store/versioning.hpp> #include <nano/store/versioning.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@ -12,33 +13,6 @@
#include <queue> #include <queue>
namespace nano
{
template <>
void * mdb_val::data () const
{
return value.mv_data;
}
template <>
std::size_t mdb_val::size () const
{
return value.mv_size;
}
template <>
mdb_val::db_val (std::size_t size_a, void * data_a) :
value ({ size_a, data_a })
{
}
template <>
void mdb_val::convert_buffer_to_value ()
{
value = { buffer->size (), const_cast<uint8_t *> (buffer->data ()) };
}
}
nano::lmdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path const & path_a, nano::ledger_constants & constants, nano::txn_tracking_config const & txn_tracking_config_a, std::chrono::milliseconds block_processor_batch_max_time_a, nano::lmdb_config const & lmdb_config_a, bool backup_before_upgrade_a) : nano::lmdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path const & path_a, nano::ledger_constants & constants, nano::txn_tracking_config const & txn_tracking_config_a, std::chrono::milliseconds block_processor_batch_max_time_a, nano::lmdb_config const & lmdb_config_a, bool backup_before_upgrade_a) :
// clang-format off // clang-format off
nano::store::component{ nano::store::component{

View file

@ -8,6 +8,7 @@
#include <nano/store/lmdb/account.hpp> #include <nano/store/lmdb/account.hpp>
#include <nano/store/lmdb/block.hpp> #include <nano/store/lmdb/block.hpp>
#include <nano/store/lmdb/confirmation_height.hpp> #include <nano/store/lmdb/confirmation_height.hpp>
#include <nano/store/lmdb/db_val.hpp>
#include <nano/store/lmdb/final_vote.hpp> #include <nano/store/lmdb/final_vote.hpp>
#include <nano/store/lmdb/frontier.hpp> #include <nano/store/lmdb/frontier.hpp>
#include <nano/store/lmdb/iterator.hpp> #include <nano/store/lmdb/iterator.hpp>
@ -34,8 +35,6 @@ namespace filesystem
namespace nano namespace nano
{ {
using mdb_val = db_val<MDB_val>;
class logging_mt; class logging_mt;
class transaction; class transaction;
@ -193,13 +192,4 @@ namespace lmdb
friend void modify_confirmation_height_to_v15 (nano::lmdb::store &, nano::transaction const &, nano::account const &, uint64_t); friend void modify_confirmation_height_to_v15 (nano::lmdb::store &, nano::transaction const &, nano::account const &, uint64_t);
}; };
} }
template <>
void * mdb_val::data () const;
template <>
std::size_t mdb_val::size () const;
template <>
mdb_val::db_val (std::size_t size_a, void * data_a);
template <>
void mdb_val::convert_buffer_to_value ();
} }

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/online_weight.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/peer.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/pending.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/pruned.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/version.hpp>
namespace nano namespace nano
{ {

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <nano/lib/numbers.hpp> #include <nano/lib/numbers.hpp>
#include <nano/store/component.hpp> #include <nano/store/db_val.hpp>
#include <lmdb/libraries/liblmdb/lmdb.h> #include <lmdb/libraries/liblmdb/lmdb.h>

View file

@ -0,0 +1 @@
#include <nano/store/online_weight.hpp>

View file

@ -0,0 +1,32 @@
#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 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<uint64_t, nano::amount> begin (nano::transaction const &) const = 0;
virtual nano::store_iterator<uint64_t, nano::amount> rbegin (nano::transaction const &) const = 0;
virtual nano::store_iterator<uint64_t, nano::amount> end () const = 0;
virtual size_t count (nano::transaction const &) const = 0;
virtual void clear (nano::write_transaction const &) = 0;
};
} // namespace nano::store

1
nano/store/peer.cpp Normal file
View file

@ -0,0 +1 @@
#include <nano/store/peer.hpp>

32
nano/store/peer.hpp Normal file
View file

@ -0,0 +1,32 @@
#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 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<nano::endpoint_key, nano::no_value> begin (nano::transaction const & transaction_a) const = 0;
virtual nano::store_iterator<nano::endpoint_key, nano::no_value> end () const = 0;
};
} // namespace nano::store

1
nano/store/pending.cpp Normal file
View file

@ -0,0 +1 @@
#include <nano/store/pending.hpp>

34
nano/store/pending.hpp Normal file
View file

@ -0,0 +1,34 @@
#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 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<nano::pending_key, nano::pending_info> begin (nano::transaction const &, nano::pending_key const &) const = 0;
virtual nano::store_iterator<nano::pending_key, nano::pending_info> begin (nano::transaction const &) const = 0;
virtual nano::store_iterator<nano::pending_key, nano::pending_info> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::pending_key, nano::pending_info>, nano::store_iterator<nano::pending_key, nano::pending_info>)> const & action_a) const = 0;
};
} // namespace nano::store

1
nano/store/pruned.cpp Normal file
View file

@ -0,0 +1 @@
#include <nano/store/pruned.hpp>

35
nano/store/pruned.hpp Normal file
View file

@ -0,0 +1,35 @@
#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 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<nano::block_hash, std::nullptr_t> begin (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0;
virtual nano::store_iterator<nano::block_hash, std::nullptr_t> begin (nano::transaction const & transaction_a) const = 0;
virtual nano::store_iterator<nano::block_hash, std::nullptr_t> end () const = 0;
virtual void for_each_par (std::function<void (nano::read_transaction const &, nano::store_iterator<nano::block_hash, std::nullptr_t>, nano::store_iterator<nano::block_hash, std::nullptr_t>)> const & action_a) const = 0;
};
} // namespace nano::store

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/account.hpp>
namespace nano namespace nano
{ {

View file

@ -1,12 +1,10 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/block.hpp>
#include <nano/store/rocksdb/db_val.hpp>
#include <rocksdb/slice.h>
namespace nano namespace nano
{ {
using rocksdb_val = db_val<::rocksdb::Slice>;
class block_predecessor_rocksdb_set; class block_predecessor_rocksdb_set;
namespace rocksdb namespace rocksdb
{ {

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/confirmation_height.hpp>
namespace nano namespace nano
{ {

View file

@ -0,0 +1,28 @@
#include <nano/store/rocksdb/db_val.hpp>
namespace nano
{
template <>
void * rocksdb_val::data () const
{
return (void *)value.data ();
}
template <>
std::size_t rocksdb_val::size () const
{
return value.size ();
}
template <>
rocksdb_val::db_val (std::size_t size_a, void * data_a) :
value (static_cast<char const *> (data_a), size_a)
{
}
template <>
void rocksdb_val::convert_buffer_to_value ()
{
value = ::rocksdb::Slice (reinterpret_cast<char const *> (buffer->data ()), buffer->size ());
}
}

View file

@ -0,0 +1,10 @@
#pragma once
#include <nano/store/db_val.hpp>
#include <rocksdb/slice.h>
namespace nano
{
using rocksdb_val = db_val<::rocksdb::Slice>;
}

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/final.hpp>
namespace nano namespace nano
{ {

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/frontier.hpp>
#include <nano/store/iterator.hpp>
namespace nano namespace nano
{ {

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/component.hpp>
#include <nano/store/db_val.hpp>
#include <rocksdb/db.h> #include <rocksdb/db.h>
#include <rocksdb/filter_policy.h> #include <rocksdb/filter_policy.h>

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/online_weight.hpp>
namespace nano namespace nano
{ {

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/peer.hpp>
namespace nano namespace nano
{ {

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/pending.hpp>
namespace nano namespace nano
{ {

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/pruned.hpp>
namespace nano namespace nano
{ {

View file

@ -1,7 +1,8 @@
#include <nano/lib/rocksdbconfig.hpp> #include <nano/lib/rocksdbconfig.hpp>
#include <nano/store/rocksdb/rocksdb.hpp>
#include <nano/store/rocksdb/iterator.hpp> #include <nano/store/rocksdb/iterator.hpp>
#include <nano/store/rocksdb/rocksdb.hpp>
#include <nano/store/rocksdb/transaction_impl.hpp> #include <nano/store/rocksdb/transaction_impl.hpp>
#include <nano/store/version.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
@ -34,33 +35,6 @@ private:
}; };
} }
namespace nano
{
template <>
void * rocksdb_val::data () const
{
return (void *)value.data ();
}
template <>
std::size_t rocksdb_val::size () const
{
return value.size ();
}
template <>
rocksdb_val::db_val (std::size_t size_a, void * data_a) :
value (static_cast<char const *> (data_a), size_a)
{
}
template <>
void rocksdb_val::convert_buffer_to_value ()
{
value = ::rocksdb::Slice (reinterpret_cast<char const *> (buffer->data ()), buffer->size ());
}
}
nano::rocksdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path const & path_a, nano::ledger_constants & constants, nano::rocksdb_config const & rocksdb_config_a, bool open_read_only_a) : nano::rocksdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path const & path_a, nano::ledger_constants & constants, nano::rocksdb_config const & rocksdb_config_a, bool open_read_only_a) :
// clang-format off // clang-format off
nano::store::component{ nano::store::component{

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <nano/store/component.hpp> #include <nano/store/version.hpp>
namespace nano namespace nano
{ {

35
nano/store/tables.hpp Normal file
View file

@ -0,0 +1,35 @@
#pragma once
#include <functional>
namespace nano
{
// Keep this in alphabetical order
enum class tables
{
accounts,
blocks,
confirmation_height,
default_unused, // RocksDB only
final_votes,
frontiers,
meta,
online_weight,
peers,
pending,
pruned,
vote
};
} // namespace nano
namespace std
{
template <>
struct hash<::nano::tables>
{
size_t operator() (::nano::tables const & table_a) const
{
return static_cast<size_t> (table_a);
}
}; // struct hash
} // namespace std

View file

@ -0,0 +1,64 @@
#include <nano/lib/thread_roles.hpp>
#include <nano/lib/utility.hpp>
#include <nano/store/transaction.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);
}

View file

@ -0,0 +1,72 @@
#pragma once
#include <nano/store/tables.hpp>
#include <memory>
namespace nano
{
class transaction_impl
{
public:
virtual ~transaction_impl () = default;
virtual void * get_handle () const = 0;
};
class read_transaction_impl : public transaction_impl
{
public:
virtual void reset () = 0;
virtual void renew () = 0;
};
class write_transaction_impl : public transaction_impl
{
public:
virtual void commit () = 0;
virtual void renew () = 0;
virtual bool contains (nano::tables table_a) const = 0;
};
class transaction
{
public:
virtual ~transaction () = default;
virtual void * get_handle () const = 0;
};
/**
* RAII wrapper of a read MDB_txn where the constructor starts the transaction
* and the destructor aborts it.
*/
class read_transaction final : public transaction
{
public:
explicit read_transaction (std::unique_ptr<nano::read_transaction_impl> read_transaction_impl);
void * get_handle () const override;
void reset () const;
void renew () const;
void refresh () const;
private:
std::unique_ptr<nano::read_transaction_impl> impl;
};
/**
* RAII wrapper of a read-write MDB_txn where the constructor starts the transaction
* and the destructor commits it.
*/
class write_transaction final : public transaction
{
public:
explicit write_transaction (std::unique_ptr<nano::write_transaction_impl> write_transaction_impl);
void * get_handle () const override;
void commit ();
void renew ();
void refresh ();
bool contains (nano::tables table_a) const;
private:
std::unique_ptr<nano::write_transaction_impl> impl;
};
} // namespace nano

1
nano/store/version.cpp Normal file
View file

@ -0,0 +1 @@
#include <nano/store/version.hpp>

27
nano/store/version.hpp Normal file
View file

@ -0,0 +1,27 @@
#pragma once
#include <nano/lib/numbers.hpp>
#include <nano/store/component.hpp>
#include <functional>
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

View file

@ -71,4 +71,12 @@ public:
uint64_t timestamp{ 0 }; uint64_t timestamp{ 0 };
nano::block_details details; nano::block_details details;
}; };
// Move to versioning with a specific version if required for a future upgrade
template <typename T>
class block_w_sideband_v18
{
public:
std::shared_ptr<T> block;
nano::block_sideband_v18 sideband;
};
} }