Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the unchecked table code from the store classes #4216

Merged
merged 5 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 9 additions & 60 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,7 @@ TEST (block_store, empty_bootstrap)
{
nano::test::system system{};
nano::logger_mt logger;
auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants);
nano::unchecked_map unchecked{ *store, system.stats, false };
ASSERT_TRUE (!store->init_error ());
nano::unchecked_map unchecked{ system.stats, false };
size_t count = 0;
unchecked.for_each ([&count] (nano::unchecked_key const & key, nano::unchecked_info const & info) {
++count;
Expand Down Expand Up @@ -961,54 +959,6 @@ TEST (block_store, pruned_random)
ASSERT_EQ (hash1, random_hash);
}

namespace nano
{
namespace lmdb
{
// Databases need to be dropped in order to convert to dupsort compatible
TEST (block_store, DISABLED_change_dupsort) // Unchecked is no longer dupsort table
{
nano::test::system system{};
auto path (nano::unique_path ());
nano::logger_mt logger{};
nano::lmdb::store store{ logger, path, nano::dev::constants };
nano::unchecked_map unchecked{ store, system.stats, false };
auto transaction (store.tx_begin_write ());
ASSERT_EQ (0, mdb_drop (store.env.tx (transaction), store.unchecked_store.unchecked_handle, 1));
ASSERT_EQ (0, mdb_dbi_open (store.env.tx (transaction), "unchecked", MDB_CREATE, &store.unchecked_store.unchecked_handle));
nano::block_builder builder;
auto send1 = builder
.send ()
.previous (0)
.destination (0)
.balance (0)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (0)
.build_shared ();
auto send2 = builder
.send ()
.previous (1)
.destination (0)
.balance (0)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (0)
.build_shared ();
ASSERT_NE (send1->hash (), send2->hash ());
unchecked.put (send1->hash (), nano::unchecked_info (send1));
unchecked.put (send1->hash (), nano::unchecked_info (send2));
ASSERT_EQ (0, mdb_drop (store.env.tx (transaction), store.unchecked_store.unchecked_handle, 0));
mdb_dbi_close (store.env, store.unchecked_store.unchecked_handle);
ASSERT_EQ (0, mdb_dbi_open (store.env.tx (transaction), "unchecked", MDB_CREATE | MDB_DUPSORT, &store.unchecked_store.unchecked_handle));
unchecked.put (send1->hash (), nano::unchecked_info (send1));
unchecked.put (send1->hash (), nano::unchecked_info (send2));
ASSERT_EQ (0, mdb_drop (store.env.tx (transaction), store.unchecked_store.unchecked_handle, 1));
ASSERT_EQ (0, mdb_dbi_open (store.env.tx (transaction), "unchecked", MDB_CREATE | MDB_DUPSORT, &store.unchecked_store.unchecked_handle));
unchecked.put (send1->hash (), nano::unchecked_info (send1));
unchecked.put (send1->hash (), nano::unchecked_info (send2));
}
}
}

TEST (block_store, state_block)
{
nano::logger_mt logger;
Expand Down Expand Up @@ -2442,7 +2392,7 @@ TEST (rocksdb_block_store, tombstone_count)
{
GTEST_SKIP ();
}
nano::test::system system{};
nano::test::system system;
nano::logger_mt logger;
auto store = std::make_unique<nano::rocksdb::store> (logger, nano::unique_path (), nano::dev::constants);
ASSERT_TRUE (!store->init_error ());
Expand All @@ -2456,18 +2406,17 @@ TEST (rocksdb_block_store, tombstone_count)
.work (5)
.build_shared ();
// Enqueues a block to be saved in the database
auto previous = block->previous ();
store->unchecked.put (store->tx_begin_write (), previous, nano::unchecked_info (block));
nano::unchecked_key key{ previous, block->hash () };
nano::account account{ 1 };
store->account.put (store->tx_begin_write (), account, nano::account_info{});
auto check_block_is_listed = [&] (nano::transaction const & transaction_a) {
return store->unchecked.exists (transaction_a, key);
return store->account.exists (transaction_a, account);
};
// Waits for the block to get saved
ASSERT_TIMELY (5s, check_block_is_listed (store->tx_begin_read ()));
ASSERT_EQ (store->tombstone_map.at (nano::tables::unchecked).num_since_last_flush.load (), 0);
// Perorms a delete and checks for the tombstone counter
store->unchecked.del (store->tx_begin_write (), nano::unchecked_key (previous, block->hash ()));
ASSERT_TIMELY (5s, store->tombstone_map.at (nano::tables::unchecked).num_since_last_flush.load () == 1);
ASSERT_EQ (store->tombstone_map.at (nano::tables::accounts).num_since_last_flush.load (), 0);
// Performs a delete operation and checks for the tombstone counter
store->account.del (store->tx_begin_write (), account);
ASSERT_TIMELY (5s, store->tombstone_map.at (nano::tables::accounts).num_since_last_flush.load () == 1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5541,7 +5541,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb)
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::unchecked_map unchecked{ store, system.stats, false };
nano::unchecked_map unchecked{ system.stats, false };
nano::ledger ledger{ store, system.stats, nano::dev::constants };
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };

Expand Down Expand Up @@ -5582,7 +5582,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb)
ASSERT_FALSE (error);

nano::rocksdb::store rocksdb_store{ logger, path / "rocksdb", nano::dev::constants };
nano::unchecked_map rocksdb_unchecked{ rocksdb_store, system.stats, false };
nano::unchecked_map rocksdb_unchecked{ system.stats, false };
auto rocksdb_transaction (rocksdb_store.tx_begin_read ());

nano::pending_info pending_info{};
Expand Down
39 changes: 10 additions & 29 deletions nano/core_test/unchecked_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <nano/lib/logger_mt.hpp>
#include <nano/lib/stats.hpp>
#include <nano/node/unchecked_map.hpp>
#include <nano/secure/store.hpp>
#include <nano/secure/common.hpp>
#include <nano/secure/utility.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>
Expand All @@ -19,13 +19,10 @@ class context
{
public:
context () :
store{ nano::make_store (logger, nano::unique_path (), nano::dev::constants) },
unchecked{ *store, stats, false }
unchecked{ stats, false }
{
}
nano::logger_mt logger;
nano::stats stats;
std::unique_ptr<nano::store> store;
nano::unchecked_map unchecked;
};
std::shared_ptr<nano::block> block ()
Expand Down Expand Up @@ -58,10 +55,7 @@ TEST (unchecked_map, put_one)
TEST (block_store, one_bootstrap)
{
nano::test::system system{};
nano::logger_mt logger{};
auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants);
nano::unchecked_map unchecked{ *store, system.stats, false };
ASSERT_TRUE (!store->init_error ());
nano::unchecked_map unchecked{ system.stats, false };
nano::block_builder builder;
auto block1 = builder
.send ()
Expand All @@ -72,12 +66,11 @@ TEST (block_store, one_bootstrap)
.work (5)
.build_shared ();
unchecked.put (block1->hash (), nano::unchecked_info{ block1 });
auto check_block_is_listed = [&] (nano::transaction const & transaction_a, nano::block_hash const & block_hash_a) {
auto check_block_is_listed = [&] (nano::block_hash const & block_hash_a) {
return unchecked.get (block_hash_a).size () > 0;
};
// Waits for the block1 to get saved in the database
ASSERT_TIMELY (10s, check_block_is_listed (store->tx_begin_read (), block1->hash ()));
auto transaction = store->tx_begin_read ();
ASSERT_TIMELY (10s, check_block_is_listed (block1->hash ()));
std::vector<nano::block_hash> dependencies;
unchecked.for_each ([&dependencies] (nano::unchecked_key const & key, nano::unchecked_info const & info) {
dependencies.push_back (key.key ());
Expand All @@ -95,10 +88,7 @@ TEST (block_store, one_bootstrap)
TEST (unchecked, simple)
{
nano::test::system system{};
nano::logger_mt logger{};
auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants);
nano::unchecked_map unchecked{ *store, system.stats, false };
ASSERT_TRUE (!store->init_error ());
nano::unchecked_map unchecked{ system.stats, false };
nano::block_builder builder;
auto block = builder
.send ()
Expand Down Expand Up @@ -139,10 +129,7 @@ TEST (unchecked, multiple)
// Don't test this in rocksdb mode
GTEST_SKIP ();
}
nano::logger_mt logger{};
auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants);
nano::unchecked_map unchecked{ *store, system.stats, false };
ASSERT_TRUE (!store->init_error ());
nano::unchecked_map unchecked{ system.stats, false };
nano::block_builder builder;
auto block = builder
.send ()
Expand Down Expand Up @@ -172,10 +159,7 @@ TEST (unchecked, multiple)
TEST (unchecked, double_put)
{
nano::test::system system{};
nano::logger_mt logger{};
auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants);
nano::unchecked_map unchecked{ *store, system.stats, false };
ASSERT_TRUE (!store->init_error ());
nano::unchecked_map unchecked{ system.stats, false };
nano::block_builder builder;
auto block = builder
.send ()
Expand Down Expand Up @@ -206,10 +190,7 @@ TEST (unchecked, double_put)
TEST (unchecked, multiple_get)
{
nano::test::system system{};
nano::logger_mt logger{};
auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants);
nano::unchecked_map unchecked{ *store, system.stats, false };
ASSERT_TRUE (!store->init_error ());
nano::unchecked_map unchecked{ system.stats, false };
// Instantiates three blocks
nano::block_builder builder;
auto block1 = builder
Expand Down Expand Up @@ -248,7 +229,7 @@ TEST (unchecked, multiple_get)

// count the number of blocks in the unchecked table by counting them one by one
// we cannot trust the count() method if the backend is rocksdb
auto count_unchecked_blocks_one_by_one = [&store, &unchecked] () {
auto count_unchecked_blocks_one_by_one = [&unchecked] () {
size_t count = 0;
unchecked.for_each ([&count] (nano::unchecked_key const & key, nano::unchecked_info const & info) {
++count;
Expand Down
3 changes: 0 additions & 3 deletions nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ add_library(
lmdb/version_store.hpp
lmdb/version_store.cpp
lmdb/unchecked_store.hpp
lmdb/unchecked_store.cpp
lmdb/lmdb.hpp
lmdb/lmdb.cpp
lmdb/lmdb_env.hpp
Expand Down Expand Up @@ -197,8 +196,6 @@ add_library(
rocksdb/pending_store.cpp
rocksdb/pruned_store.hpp
rocksdb/pruned_store.cpp
rocksdb/unchecked_store.hpp
rocksdb/unchecked_store.cpp
rocksdb/version_store.hpp
rocksdb/version_store.cpp
rocksdb/rocksdb.hpp
Expand Down
2 changes: 1 addition & 1 deletion nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ auto nano::block_processor::process_batch (nano::unique_lock<nano::mutex> & lock
{
std::deque<processed_t> processed;
auto scoped_write_guard = write_database_queue.wait (nano::writer::process_batch);
auto transaction (node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::frontiers, tables::pending, tables::unchecked }));
auto transaction (node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::frontiers, tables::pending }));
nano::timer<std::chrono::milliseconds> timer_l;
lock_a.lock ();
timer_l.start ();
Expand Down
3 changes: 0 additions & 3 deletions nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4114,7 +4114,6 @@ void nano::json_handler::unchecked ()
if (!ec)
{
boost::property_tree::ptree unchecked;
auto transaction (node.store.tx_begin_read ());
node.unchecked.for_each (
[&unchecked, &json_block_l] (nano::unchecked_key const & key, nano::unchecked_info const & info) {
if (json_block_l)
Expand All @@ -4137,7 +4136,6 @@ void nano::json_handler::unchecked ()
void nano::json_handler::unchecked_clear ()
{
node.workers.push_task (create_worker_task ([] (std::shared_ptr<nano::json_handler> const & rpc_l) {
auto transaction (rpc_l->node.store.tx_begin_write ({ tables::unchecked }));
rpc_l->node.unchecked.clear ();
rpc_l->response_l.put ("success", "");
rpc_l->response_errors ();
Expand Down Expand Up @@ -4195,7 +4193,6 @@ void nano::json_handler::unchecked_keys ()
if (!ec)
{
boost::property_tree::ptree unchecked;
auto transaction (node.store.tx_begin_read ());
node.unchecked.for_each (
key,
[&unchecked, json_block_l] (nano::unchecked_key const & key, nano::unchecked_info const & info) {
Expand Down
3 changes: 1 addition & 2 deletions nano/node/lmdb/lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ nano::lmdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path co
frontier_store,
account_store,
pending_store,
unchecked_store,
online_weight_store,
pruned_store,
peer_store,
Expand All @@ -63,7 +62,7 @@ nano::lmdb::store::store (nano::logger_mt & logger_a, boost::filesystem::path co
peer_store{ *this },
confirmation_height_store{ *this },
final_vote_store{ *this },
unchecked_store{ *this },
unchecked_store{},
version_store{ *this },
logger (logger_a),
env (error, path_a, nano::mdb_env::options::make ().set_config (lmdb_config_a).set_use_no_mem_init (true)),
Expand Down
52 changes: 0 additions & 52 deletions nano/node/lmdb/unchecked_store.cpp

This file was deleted.

38 changes: 9 additions & 29 deletions nano/node/lmdb/unchecked_store.hpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
#pragma once

#include <nano/secure/store.hpp>

#include <lmdb/libraries/liblmdb/lmdb.h>

namespace nano
namespace nano::lmdb
{
namespace lmdb
class unchecked_store
{
class store;
class unchecked_store : public nano::unchecked_store
{
private:
nano::lmdb::store & store;

public:
unchecked_store (nano::lmdb::store & store_a);

void clear (nano::write_transaction const & transaction_a) override;
void put (nano::write_transaction const & transaction_a, nano::hash_or_account const & dependency, nano::unchecked_info const & info_a) override;
bool exists (nano::transaction const & transaction_a, nano::unchecked_key const & unchecked_key_a) override;
void del (nano::write_transaction const & transaction_a, nano::unchecked_key const & key_a) override;
nano::store_iterator<nano::unchecked_key, nano::unchecked_info> end () const override;
nano::store_iterator<nano::unchecked_key, nano::unchecked_info> begin (nano::transaction const & transaction_a) const override;
nano::store_iterator<nano::unchecked_key, nano::unchecked_info> lower_bound (nano::transaction const & transaction_a, nano::unchecked_key const & key_a) const override;
size_t count (nano::transaction const & transaction_a) override;

/**
* Unchecked bootstrap blocks info.
* nano::block_hash -> nano::unchecked_info
*/
MDB_dbi unchecked_handle{ 0 };
};
}
public:
/**
* Unchecked bootstrap blocks info.
* nano::block_hash -> nano::unchecked_info
*/
MDB_dbi unchecked_handle{ 0 };
};
}
Loading