Skip to content

Commit

Permalink
Remove unused frontiers table.
Browse files Browse the repository at this point in the history
This change upgrades the database version.
  • Loading branch information
clemahieu committed Feb 10, 2024
1 parent 5c6f746 commit 9f10d06
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 241 deletions.
36 changes: 36 additions & 0 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,42 @@ TEST (mdb_block_store, upgrade_v21_v22)
// Testing the upgrade code worked
check_correct_state ();
}

TEST (mdb_block_store, upgrade_v22_v23)
{
if (nano::rocksdb_config::using_rocksdb_in_tests ())
{
// Don't test this in rocksdb mode
GTEST_SKIP ();
}

auto path (nano::unique_path () / "data.ldb");
nano::logger logger;
nano::stats stats;
auto const check_correct_state = [&] () {
nano::store::lmdb::component store (logger, path, nano::dev::constants);
auto transaction (store.tx_begin_write ());
ASSERT_EQ (store.version.get (transaction), store.version_current);
MDB_dbi frontiers_handle{ 0 };
ASSERT_EQ (MDB_NOTFOUND, mdb_dbi_open (store.env.tx (transaction), "frontiers", 0, &frontiers_handle));
};

// Testing current version doesn't contain the frontiers table
check_correct_state ();

// Setting the database to its 22st version state
{
nano::store::lmdb::component store (logger, path, nano::dev::constants);
auto transaction (store.tx_begin_write ());
store.version.put (transaction, 22);
MDB_dbi frontiers_handle{ 0 };
ASSERT_FALSE (mdb_dbi_open (store.env.tx (transaction), "frontiers", MDB_CREATE, &frontiers_handle));
ASSERT_EQ (store.version.get (transaction), 22);
}

// Testing the upgrade code worked
check_correct_state ();
}
}

namespace nano::store::rocksdb
Expand Down
2 changes: 1 addition & 1 deletion nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,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 }));
auto transaction (node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending }));
nano::timer<std::chrono::milliseconds> timer_l;
lock_a.lock ();
timer_l.start ();
Expand Down
4 changes: 2 additions & 2 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons

if (!is_initialized && !flags.read_only)
{
auto const transaction (store.tx_begin_write ({ tables::accounts, tables::blocks, tables::confirmation_height, tables::frontiers }));
auto const transaction (store.tx_begin_write ({ tables::accounts, tables::blocks, tables::confirmation_height }));
// Store was empty meaning we just created it, add the genesis block
store.initialize (transaction, ledger.cache, ledger.constants);
}
Expand Down Expand Up @@ -568,7 +568,7 @@ void nano::node::process_active (std::shared_ptr<nano::block> const & incoming)

nano::process_return nano::node::process (nano::block & block)
{
auto const transaction = store.tx_begin_write ({ tables::accounts, tables::blocks, tables::frontiers, tables::pending });
auto const transaction = store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending });
return process (transaction, block);
}

Expand Down
6 changes: 0 additions & 6 deletions nano/store/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ add_library(
iterator.hpp
iterator_impl.hpp
final.hpp
frontier.hpp
lmdb/account.hpp
lmdb/block.hpp
lmdb/confirmation_height.hpp
lmdb/db_val.hpp
lmdb/final_vote.hpp
lmdb/frontier.hpp
lmdb/iterator.hpp
lmdb/lmdb.hpp
lmdb/lmdb_env.hpp
Expand All @@ -36,7 +34,6 @@ add_library(
rocksdb/confirmation_height.hpp
rocksdb/db_val.hpp
rocksdb/final_vote.hpp
rocksdb/frontier.hpp
rocksdb/iterator.hpp
rocksdb/online_weight.hpp
rocksdb/peer.hpp
Expand All @@ -58,13 +55,11 @@ add_library(
iterator.cpp
iterator_impl.cpp
final.cpp
frontier.cpp
lmdb/account.cpp
lmdb/block.cpp
lmdb/confirmation_height.cpp
lmdb/db_val.cpp
lmdb/final_vote.cpp
lmdb/frontier.cpp
lmdb/lmdb.cpp
lmdb/lmdb_env.cpp
lmdb/transaction.cpp
Expand All @@ -83,7 +78,6 @@ add_library(
rocksdb/confirmation_height.cpp
rocksdb/db_val.cpp
rocksdb/final_vote.cpp
rocksdb/frontier.cpp
rocksdb/online_weight.cpp
rocksdb/peer.cpp
rocksdb/pending.cpp
Expand Down
5 changes: 1 addition & 4 deletions nano/store/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
#include <nano/store/block.hpp>
#include <nano/store/component.hpp>
#include <nano/store/confirmation_height.hpp>
#include <nano/store/frontier.hpp>

nano::store::component::component (nano::store::block & block_store_a, nano::store::frontier & frontier_store_a, nano::store::account & account_store_a, nano::store::pending & pending_store_a, nano::store::online_weight & online_weight_store_a, nano::store::pruned & pruned_store_a, nano::store::peer & peer_store_a, nano::store::confirmation_height & confirmation_height_store_a, nano::store::final_vote & final_vote_store_a, nano::store::version & version_store_a) :
nano::store::component::component (nano::store::block & block_store_a, nano::store::account & account_store_a, nano::store::pending & pending_store_a, nano::store::online_weight & online_weight_store_a, nano::store::pruned & pruned_store_a, nano::store::peer & peer_store_a, nano::store::confirmation_height & confirmation_height_store_a, nano::store::final_vote & final_vote_store_a, nano::store::version & version_store_a) :
block (block_store_a),
frontier (frontier_store_a),
account (account_store_a),
pending (pending_store_a),
online_weight (online_weight_store_a),
Expand Down Expand Up @@ -36,5 +34,4 @@ void nano::store::component::initialize (store::write_transaction const & transa
account.put (transaction_a, constants.genesis->account (), { hash_l, constants.genesis->account (), constants.genesis->hash (), std::numeric_limits<nano::uint128_t>::max (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0 });
++ledger_cache_a.account_count;
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 ());
}
5 changes: 1 addition & 4 deletions nano/store/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace store
class block;
class confirmation_height;
class final_vote;
class frontier;
class online_weight;
class peer;
class pending;
Expand All @@ -44,7 +43,6 @@ namespace store
// clang-format off
explicit component (
nano::store::block &,
nano::store::frontier &,
nano::store::account &,
nano::store::pending &,
nano::store::online_weight&,
Expand All @@ -65,11 +63,10 @@ namespace store
virtual std::string error_string (int status) const = 0;

store::block & block;
store::frontier & frontier;
store::account & account;
store::pending & pending;
static int constexpr version_minimum{ 21 };
static int constexpr version_current{ 22 };
static int constexpr version_current{ 23 };

public:
store::online_weight & online_weight;
Expand Down
1 change: 0 additions & 1 deletion nano/store/frontier.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions nano/store/frontier.hpp

This file was deleted.

57 changes: 0 additions & 57 deletions nano/store/lmdb/frontier.cpp

This file was deleted.

34 changes: 0 additions & 34 deletions nano/store/lmdb/frontier.hpp

This file was deleted.

20 changes: 15 additions & 5 deletions nano/store/lmdb/lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ nano::store::lmdb::component::component (nano::logger & logger_a, std::filesyste
// clang-format off
nano::store::component{
block_store,
frontier_store,
account_store,
pending_store,
online_weight_store,
Expand All @@ -28,7 +27,6 @@ nano::store::lmdb::component::component (nano::logger & logger_a, std::filesyste
},
// clang-format on
block_store{ *this },
frontier_store{ *this },
account_store{ *this },
pending_store{ *this },
online_weight_store{ *this },
Expand Down Expand Up @@ -192,7 +190,6 @@ nano::store::lmdb::txn_callbacks nano::store::lmdb::component::create_txn_callba

void nano::store::lmdb::component::open_databases (bool & error_a, store::transaction const & transaction_a, unsigned flags)
{
error_a |= mdb_dbi_open (env.tx (transaction_a), "frontiers", flags, &frontier_store.frontiers_handle) != 0;
error_a |= mdb_dbi_open (env.tx (transaction_a), "online_weight", flags, &online_weight_store.online_weight_handle) != 0;
error_a |= mdb_dbi_open (env.tx (transaction_a), "meta", flags, &version_store.meta_handle) != 0;
error_a |= mdb_dbi_open (env.tx (transaction_a), "peers", flags, &peer_store.peers_handle) != 0;
Expand Down Expand Up @@ -221,6 +218,9 @@ bool nano::store::lmdb::component::do_upgrades (store::write_transaction & trans
upgrade_v21_to_v22 (transaction_a);
[[fallthrough]];
case 22:
upgrade_v22_to_v23 (transaction_a);
[[fallthrough]];
case 23:
break;
default:
logger.critical (nano::log::type::lmdb, "The version of the ledger ({}) is too high for this node", version_l);
Expand All @@ -242,6 +242,18 @@ void nano::store::lmdb::component::upgrade_v21_to_v22 (store::write_transaction
logger.info (nano::log::type::lmdb, "Upgrading database from v21 to v22 completed");
}

void nano::store::lmdb::component::upgrade_v22_to_v23 (store::write_transaction const & transaction_a)
{
logger.info (nano::log::type::lmdb, "Upgrading database from v22 to v23...");

MDB_dbi frontiers_handle{ 0 };
release_assert (!mdb_dbi_open (env.tx (transaction_a), "frontiers", MDB_CREATE, &frontiers_handle));
release_assert (!mdb_drop (env.tx (transaction_a), frontiers_handle, 1)); // del = 1, to delete it from the environment and close the DB handle.
version.put (transaction_a, 23);

logger.info (nano::log::type::lmdb, "Upgrading database from v22 to v23 completed");
}

/** Takes a filepath, appends '_backup_<timestamp>' to the end (but before any extension) and saves that file in the same directory */
void nano::store::lmdb::component::create_backup_file (nano::store::lmdb::env & env_a, std::filesystem::path const & filepath_a, nano::logger & logger)
{
Expand Down Expand Up @@ -319,8 +331,6 @@ MDB_dbi nano::store::lmdb::component::table_to_dbi (tables table_a) const
{
switch (table_a)
{
case tables::frontiers:
return frontier_store.frontiers_handle;
case tables::accounts:
return account_store.accounts_handle;
case tables::blocks:
Expand Down
4 changes: 1 addition & 3 deletions nano/store/lmdb/lmdb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#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/frontier.hpp>
#include <nano/store/lmdb/iterator.hpp>
#include <nano/store/lmdb/lmdb_env.hpp>
#include <nano/store/lmdb/online_weight.hpp>
Expand Down Expand Up @@ -44,7 +43,6 @@ class component : public nano::store::component
nano::store::lmdb::block block_store;
nano::store::lmdb::confirmation_height confirmation_height_store;
nano::store::lmdb::final_vote final_vote_store;
nano::store::lmdb::frontier frontier_store;
nano::store::lmdb::online_weight online_weight_store;
nano::store::lmdb::peer peer_store;
nano::store::lmdb::pending pending_store;
Expand All @@ -55,7 +53,6 @@ class component : public nano::store::component
friend class nano::store::lmdb::block;
friend class nano::store::lmdb::confirmation_height;
friend class nano::store::lmdb::final_vote;
friend class nano::store::lmdb::frontier;
friend class nano::store::lmdb::online_weight;
friend class nano::store::lmdb::peer;
friend class nano::store::lmdb::pending;
Expand Down Expand Up @@ -113,6 +110,7 @@ class component : public nano::store::component
private:
bool do_upgrades (store::write_transaction &, nano::ledger_constants & constants, bool &);
void upgrade_v21_to_v22 (store::write_transaction const &);
void upgrade_v22_to_v23 (store::write_transaction const &);

void open_databases (bool &, store::transaction const &, unsigned);

Expand Down
Loading

0 comments on commit 9f10d06

Please sign in to comment.