Skip to content

Commit

Permalink
Merge pull request #4286 from clemahieu/nano_store_lib
Browse files Browse the repository at this point in the history
This creates a the nano::store library/namespace/directory
  • Loading branch information
clemahieu authored Sep 20, 2023
2 parents 3e0ff04 + 1e57b5b commit ea7713a
Show file tree
Hide file tree
Showing 203 changed files with 5,269 additions and 4,908 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ target_compile_definitions(blake2 PRIVATE -D__SSE2__)

add_subdirectory(nano/crypto_lib)
add_subdirectory(nano/secure)
add_subdirectory(nano/store)
target_include_directories(nano_store PUBLIC ${BOOST_LIBRARY_INCLUDES})
target_include_directories(nano_store PUBLIC submodules)
add_subdirectory(nano/lib)
add_subdirectory(nano/node)
add_subdirectory(nano/nano_node)
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/backlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST (backlog, population)
nano::test::system system{};
auto & node = *system.add_node ();

node.backlog.activate_callback.add ([&] (nano::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) {
node.backlog.activate_callback.add ([&] (nano::store::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) {
nano::lock_guard<nano::mutex> lock{ mutex };

activated.insert (account);
Expand Down
1,850 changes: 920 additions & 930 deletions nano/core_test/block_store.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion nano/core_test/confirmation_height.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ TEST (confirmation_height, gap_bootstrap)
// Receive 2 comes in on the live network, however the chain has not been finished so it gets added to unchecked
node1.process_active (receive2);
// Waits for the unchecked_map to process the 4 blocks added to the block_processor, saving them in the unchecked table
auto check_block_is_listed = [&] (nano::transaction const & transaction_a, nano::block_hash const & block_hash_a) {
auto check_block_is_listed = [&] (nano::store::transaction const & transaction_a, nano::block_hash const & block_hash_a) {
return !node1.unchecked.get (block_hash_a).empty ();
};
ASSERT_TIMELY (5s, check_block_is_listed (node1.store.tx_begin_read (), receive2->previous ()));
Expand Down
1 change: 1 addition & 0 deletions nano/core_test/gap_cache.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <nano/store/block.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>

Expand Down
10 changes: 5 additions & 5 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include <nano/lib/threading.hpp>
#include <nano/node/election.hpp>
#include <nano/node/make_store.hpp>
#include <nano/node/rocksdb/rocksdb.hpp>
#include <nano/node/scheduler/component.hpp>
#include <nano/node/scheduler/priority.hpp>
#include <nano/node/transport/inproc.hpp>
#include <nano/store/rocksdb/rocksdb.hpp>
#include <nano/test_common/ledger.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>
Expand Down Expand Up @@ -4495,7 +4495,7 @@ TEST (ledger, unchecked_receive)
node1.work_generate_blocking (*receive1);
node1.block_processor.add (send1);
node1.block_processor.add (receive1);
auto check_block_is_listed = [&] (nano::transaction const & transaction_a, nano::block_hash const & block_hash_a) {
auto check_block_is_listed = [&] (nano::store::transaction const & transaction_a, nano::block_hash const & block_hash_a) {
return !node1.unchecked.get (block_hash_a).empty ();
};
// Previous block for receive1 is unknown, signature cannot be validated
Expand Down Expand Up @@ -5543,7 +5543,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb)
nano::logger_mt logger{};
boost::asio::ip::address_v6 address (boost::asio::ip::make_address_v6 ("::ffff:127.0.0.1"));
uint16_t port = 100;
nano::lmdb::store store{ logger, path / "data.ldb", nano::dev::constants };
nano::store::lmdb::component store{ logger, path / "data.ldb", nano::dev::constants };
nano::ledger ledger{ store, system.stats, nano::dev::constants };
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };

Expand All @@ -5558,7 +5558,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb)
.build_shared ();

nano::endpoint_key endpoint_key (address.to_bytes (), port);
auto version = nano::store::version_current;
auto version = nano::store::component::version_current;

{
auto transaction = store.tx_begin_write ();
Expand All @@ -5583,7 +5583,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb)
auto error = ledger.migrate_lmdb_to_rocksdb (path);
ASSERT_FALSE (error);

nano::rocksdb::store rocksdb_store{ logger, path / "rocksdb", nano::dev::constants };
nano::store::rocksdb::component rocksdb_store{ logger, path / "rocksdb", nano::dev::constants };
auto rocksdb_transaction (rocksdb_store.tx_begin_read ());

nano::pending_info pending_info{};
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/processor_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <nano/lib/work.hpp>
#include <nano/node/make_store.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/store.hpp>
#include <nano/secure/utility.hpp>
#include <nano/store/component.hpp>
#include <nano/test_common/testutil.hpp>

#include <gtest/gtest.h>
Expand Down
40 changes: 20 additions & 20 deletions nano/core_test/wallet.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <nano/crypto_lib/random_pool.hpp>
#include <nano/lib/thread_runner.hpp>
#include <nano/lib/threading.hpp>
#include <nano/node/lmdb/wallet_value.hpp>
#include <nano/store/lmdb/wallet_value.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>

Expand All @@ -15,7 +15,7 @@ unsigned constexpr nano::wallet_store::version_current;
TEST (wallet, no_special_keys_accounts)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -36,7 +36,7 @@ TEST (wallet, no_special_keys_accounts)
TEST (wallet, no_key)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -51,7 +51,7 @@ TEST (wallet, no_key)
TEST (wallet, fetch_locked)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -73,7 +73,7 @@ TEST (wallet, fetch_locked)
TEST (wallet, retrieval)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -95,7 +95,7 @@ TEST (wallet, retrieval)
TEST (wallet, empty_iteration)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -109,7 +109,7 @@ TEST (wallet, empty_iteration)
TEST (wallet, one_item_iteration)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -131,7 +131,7 @@ TEST (wallet, one_item_iteration)
TEST (wallet, two_item_iteration)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
nano::keypair key1;
nano::keypair key2;
Expand Down Expand Up @@ -270,7 +270,7 @@ TEST (wallet, spend_no_previous)
TEST (wallet, find_none)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -283,7 +283,7 @@ TEST (wallet, find_none)
TEST (wallet, find_existing)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -302,7 +302,7 @@ TEST (wallet, find_existing)
TEST (wallet, rekey)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -374,7 +374,7 @@ TEST (account, encode_fail)
TEST (wallet, hash_password)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -423,7 +423,7 @@ TEST (fan, change)
TEST (wallet, reopen_default_password)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
auto transaction (env.tx_begin_write ());
ASSERT_FALSE (init);
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -459,7 +459,7 @@ TEST (wallet, reopen_default_password)
TEST (wallet, representative)
{
auto error (false);
nano::mdb_env env (error, nano::unique_path ());
nano::store::lmdb::env env (error, nano::unique_path ());
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -480,7 +480,7 @@ TEST (wallet, representative)
TEST (wallet, serialize_json_empty)
{
auto error (false);
nano::mdb_env env (error, nano::unique_path ());
nano::store::lmdb::env env (error, nano::unique_path ());
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand All @@ -505,7 +505,7 @@ TEST (wallet, serialize_json_empty)
TEST (wallet, serialize_json_one)
{
auto error (false);
nano::mdb_env env (error, nano::unique_path ());
nano::store::lmdb::env env (error, nano::unique_path ());
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -534,7 +534,7 @@ TEST (wallet, serialize_json_one)
TEST (wallet, serialize_json_password)
{
auto error (false);
nano::mdb_env env (error, nano::unique_path ());
nano::store::lmdb::env env (error, nano::unique_path ());
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -567,7 +567,7 @@ TEST (wallet, serialize_json_password)
TEST (wallet_store, move)
{
auto error (false);
nano::mdb_env env (error, nano::unique_path ());
nano::store::lmdb::env env (error, nano::unique_path ());
ASSERT_FALSE (error);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -725,7 +725,7 @@ TEST (wallet, insert_locked)
TEST (wallet, deterministic_keys)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down Expand Up @@ -768,7 +768,7 @@ TEST (wallet, deterministic_keys)
TEST (wallet, reseed)
{
bool init;
nano::mdb_env env (init, nano::unique_path ());
nano::store::lmdb::env env (init, nano::unique_path ());
ASSERT_FALSE (init);
auto transaction (env.tx_begin_write ());
nano::kdf kdf{ nano::dev::network_params.kdf_work };
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/wallets.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <nano/secure/versioning.hpp>
#include <nano/store/versioning.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>

Expand Down
2 changes: 1 addition & 1 deletion nano/lib/rep_weights.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <nano/lib/rep_weights.hpp>
#include <nano/secure/store.hpp>
#include <nano/store/component.hpp>

void nano::rep_weights::representation_add (nano::account const & source_rep_a, nano::uint128_t const & amount_a)
{
Expand Down
5 changes: 4 additions & 1 deletion nano/lib/rep_weights.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

namespace nano
{
class store;
namespace store
{
class component;
}
class transaction;

class rep_weights
Expand Down
11 changes: 6 additions & 5 deletions nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <nano/node/json_handler.hpp>
#include <nano/node/node.hpp>
#include <nano/node/transport/inproc.hpp>
#include <nano/store/pending.hpp>

#include <boost/dll/runtime_symbol_info.hpp>
#include <boost/filesystem/operations.hpp>
Expand Down Expand Up @@ -307,7 +308,7 @@ int main (int argc, char * const * argv)
for (; i != end; ++i)
{
nano::block_hash hash = i->first;
nano::block_w_sideband sideband = i->second;
nano::store::block_w_sideband sideband = i->second;
std::shared_ptr<nano::block> b = sideband.block;
std::cout << hash.to_string () << std::endl
<< b->to_json ();
Expand Down Expand Up @@ -1407,7 +1408,7 @@ int main (int argc, char * const * argv)
}
};

auto check_account = [&print_error_message, &silent, &count, &block_count] (std::shared_ptr<nano::node> const & node, nano::read_transaction const & transaction, nano::account const & account, nano::account_info const & info) {
auto check_account = [&print_error_message, &silent, &count, &block_count] (std::shared_ptr<nano::node> const & node, nano::store::read_transaction const & transaction, nano::account const & account, nano::account_info const & info) {
++count;
if (!silent && (count % 20000) == 0)
{
Expand Down Expand Up @@ -1681,7 +1682,7 @@ int main (int argc, char * const * argv)
finished = false;
std::deque<std::pair<nano::pending_key, nano::pending_info>> pending;

auto check_pending = [&print_error_message, &silent, &count] (std::shared_ptr<nano::node> const & node, nano::read_transaction const & transaction, nano::pending_key const & key, nano::pending_info const & info) {
auto check_pending = [&print_error_message, &silent, &count] (std::shared_ptr<nano::node> const & node, nano::store::read_transaction const & transaction, nano::pending_key const & key, nano::pending_info const & info) {
++count;
if (!silent && (count % 500000) == 0)
{
Expand Down Expand Up @@ -1915,7 +1916,7 @@ int main (int argc, char * const * argv)
nano::locked<std::vector<boost::unordered_set<nano::account>>> opened_account_versions_shared (epoch_count);
using opened_account_versions_t = decltype (opened_account_versions_shared)::value_type;
node->store.account.for_each_par (
[&opened_account_versions_shared, epoch_count] (nano::read_transaction const & /*unused*/, nano::store_iterator<nano::account, nano::account_info> i, nano::store_iterator<nano::account, nano::account_info> n) {
[&opened_account_versions_shared, epoch_count] (nano::store::read_transaction const & /*unused*/, nano::store::iterator<nano::account, nano::account_info> i, nano::store::iterator<nano::account, nano::account_info> n) {
// First cache locally
opened_account_versions_t opened_account_versions_l (epoch_count);
for (; i != n; ++i)
Expand Down Expand Up @@ -1952,7 +1953,7 @@ int main (int argc, char * const * argv)
nano::locked<boost::unordered_map<nano::account, std::underlying_type_t<nano::epoch>>> unopened_highest_pending_shared;
using unopened_highest_pending_t = decltype (unopened_highest_pending_shared)::value_type;
node->store.pending.for_each_par (
[&unopened_highest_pending_shared, &opened_accounts] (nano::read_transaction const & /*unused*/, nano::store_iterator<nano::pending_key, nano::pending_info> i, nano::store_iterator<nano::pending_key, nano::pending_info> n) {
[&unopened_highest_pending_shared, &opened_accounts] (nano::store::read_transaction const & /*unused*/, nano::store::iterator<nano::pending_key, nano::pending_info> i, nano::store::iterator<nano::pending_key, nano::pending_info> n) {
// First cache locally
unopened_highest_pending_t unopened_highest_pending_l;
for (; i != n; ++i)
Expand Down
Loading

0 comments on commit ea7713a

Please sign in to comment.