Skip to content

Commit

Permalink
Remove unused frontiers table
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Mar 5, 2024
1 parent 519eca6 commit 9f2d728
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 277 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
36 changes: 0 additions & 36 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#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>
Expand Down Expand Up @@ -53,8 +52,6 @@ class rollback_visitor : public nano::block_visitor
nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.balance (transaction, block_a.hashables.previous), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0);
ledger.update_account (transaction, pending.source, *info, new_info);
ledger.store.block.del (transaction, hash);
ledger.store.frontier.del (transaction, hash);
ledger.store.frontier.put (transaction, block_a.hashables.previous, pending.source);
ledger.store.block.successor_clear (transaction, block_a.hashables.previous);
ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::send);
}
Expand All @@ -74,8 +71,6 @@ class rollback_visitor : public nano::block_visitor
ledger.update_account (transaction, destination_account, *info, new_info);
ledger.store.block.del (transaction, hash);
ledger.store.pending.put (transaction, nano::pending_key (destination_account, block_a.hashables.source), { source_account, amount, nano::epoch::epoch_0 });
ledger.store.frontier.del (transaction, hash);
ledger.store.frontier.put (transaction, block_a.hashables.previous, destination_account);
ledger.store.block.successor_clear (transaction, block_a.hashables.previous);
ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::receive);
}
Expand All @@ -92,7 +87,6 @@ class rollback_visitor : public nano::block_visitor
ledger.update_account (transaction, destination_account, new_info, new_info);
ledger.store.block.del (transaction, hash);
ledger.store.pending.put (transaction, nano::pending_key (destination_account, block_a.hashables.source), { source_account, amount, nano::epoch::epoch_0 });
ledger.store.frontier.del (transaction, hash);
ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::open);
}
void change_block (nano::change_block const & block_a) override
Expand All @@ -110,8 +104,6 @@ class rollback_visitor : public nano::block_visitor
ledger.store.block.del (transaction, hash);
nano::account_info new_info (block_a.hashables.previous, representative, info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0);
ledger.update_account (transaction, account, *info, new_info);
ledger.store.frontier.del (transaction, hash);
ledger.store.frontier.put (transaction, block_a.hashables.previous, account);
ledger.store.block.successor_clear (transaction, block_a.hashables.previous);
ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::change);
}
Expand Down Expand Up @@ -172,10 +164,6 @@ class rollback_visitor : public nano::block_visitor
if (previous != nullptr)
{
ledger.store.block.successor_clear (transaction, block_a.hashables.previous);
if (previous->type () < nano::block_type::state)
{
ledger.store.frontier.put (transaction, block_a.hashables.previous, block_a.hashables.account);
}
}
else
{
Expand Down Expand Up @@ -369,10 +357,6 @@ void ledger_processor::state_block_impl (nano::state_block & block_a)

nano::account_info new_info (hash, block_a.representative (), info.open_block.is_zero () ? hash : info.open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch);
ledger.update_account (transaction, block_a.hashables.account, info, new_info);
if (!ledger.store.frontier.get (transaction, info.head).is_zero ())
{
ledger.store.frontier.del (transaction, info.head);
}
}
}
}
Expand Down Expand Up @@ -439,10 +423,6 @@ void ledger_processor::epoch_block_impl (nano::state_block & block_a)
ledger.store.block.put (transaction, hash, block_a);
nano::account_info new_info (hash, block_a.representative (), info.open_block.is_zero () ? hash : info.open_block, info.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch);
ledger.update_account (transaction, block_a.hashables.account, info, new_info);
if (!ledger.store.frontier.get (transaction, info.head).is_zero ())
{
ledger.store.frontier.del (transaction, info.head);
}
}
}
}
Expand Down Expand Up @@ -487,8 +467,6 @@ void ledger_processor::change_block (nano::change_block & block_a)
ledger.cache.rep_weights.representation_add_dual (block_a.representative (), balance, info->representative, 0 - balance);
nano::account_info new_info (hash, block_a.representative (), info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0);
ledger.update_account (transaction, account, *info, new_info);
ledger.store.frontier.del (transaction, block_a.hashables.previous);
ledger.store.frontier.put (transaction, hash, account);
ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::change);
}
}
Expand Down Expand Up @@ -537,8 +515,6 @@ void ledger_processor::send_block (nano::send_block & block_a)
nano::account_info new_info (hash, info->representative, info->open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0);
ledger.update_account (transaction, account, *info, new_info);
ledger.store.pending.put (transaction, nano::pending_key (block_a.hashables.destination, hash), { account, amount, nano::epoch::epoch_0 });
ledger.store.frontier.del (transaction, block_a.hashables.previous);
ledger.store.frontier.put (transaction, hash, account);
ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::send);
}
}
Expand Down Expand Up @@ -605,8 +581,6 @@ void ledger_processor::receive_block (nano::receive_block & block_a)
nano::account_info new_info (hash, info->representative, info->open_block, new_balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0);
ledger.update_account (transaction, account, *info, new_info);
ledger.cache.rep_weights.representation_add (info->representative, pending.amount.number ());
ledger.store.frontier.del (transaction, block_a.hashables.previous);
ledger.store.frontier.put (transaction, hash, account);
ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::receive);
}
}
Expand Down Expand Up @@ -667,7 +641,6 @@ void ledger_processor::open_block (nano::open_block & block_a)
nano::account_info new_info (hash, block_a.representative (), hash, pending.amount.number (), nano::seconds_since_epoch (), 1, nano::epoch::epoch_0);
ledger.update_account (transaction, block_a.hashables.account, info, new_info);
ledger.cache.rep_weights.representation_add (block_a.representative (), pending.amount.number ());
ledger.store.frontier.put (transaction, hash, block_a.hashables.account);
ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::open);
}
}
Expand Down Expand Up @@ -1608,15 +1581,6 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p
}
});

store.frontier.for_each_par (
[&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) {
for (; i != n; ++i)
{
auto rocksdb_transaction (rocksdb_store->tx_begin_write ({}, { nano::tables::frontiers }));
rocksdb_store->frontier.put (rocksdb_transaction, i->first, i->second);
}
});

store.pruned.for_each_par (
[&rocksdb_store] (store::read_transaction const & /*unused*/, auto i, auto n) {
for (; i != n; ++i)
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.

Loading

0 comments on commit 9f2d728

Please sign in to comment.