Skip to content

Commit

Permalink
Remove unused frontiers table (#4425)
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu authored Mar 25, 2024
1 parent 277339e commit 43dae2f
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 278 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 @@ -1397,6 +1397,42 @@ TEST (mdb_block_store, upgrade_v21_v22)
// Testing the upgrade code worked
check_correct_state ();
}

TEST (mdb_block_store, upgrade_v23_v24)
{
if (nano::rocksdb_config::using_rocksdb_in_tests ())
{
// Direct lmdb operations are used to simulate the old ledger format so this test will not work on RocksDB
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 23st version state
{
nano::store::lmdb::component store (logger, path, nano::dev::constants);
auto transaction (store.tx_begin_write ());
store.version.put (transaction, 23);
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), 23);
}

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

namespace nano::store::rocksdb
Expand Down
1 change: 0 additions & 1 deletion nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5502,7 +5502,6 @@ TEST (ledger, migrate_lmdb_to_rocksdb)
store.confirmation_height.put (transaction, nano::dev::genesis_key.pub, { 2, send->hash () });

store.online_weight.put (transaction, 100, nano::amount (2));
store.frontier.put (transaction, nano::block_hash (2), nano::account (5));
store.peer.put (transaction, endpoint_key);

store.pending.put (transaction, nano::pending_key (nano::dev::genesis_key.pub, send->hash ()), nano::pending_info (nano::dev::genesis_key.pub, 100, nano::epoch::epoch_0));
Expand Down
2 changes: 1 addition & 1 deletion nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ auto nano::block_processor::process_batch (nano::unique_lock<nano::mutex> & lock
processed_batch_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::rep_weights }));
auto transaction (node.store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights }));
nano::timer<std::chrono::milliseconds> timer_l;

lock_a.lock ();
Expand Down
4 changes: 2 additions & 2 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy

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

nano::block_status nano::node::process (std::shared_ptr<nano::block> block)
{
auto const transaction = store.tx_begin_write ({ tables::accounts, tables::blocks, tables::frontiers, tables::pending, tables::rep_weights });
auto const transaction = store.tx_begin_write ({ tables::accounts, tables::blocks, tables::pending, tables::rep_weights });
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 @@ -13,7 +13,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 @@ -59,8 +58,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).value (), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0);
ledger.update_account (transaction, pending.value ().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.value ().source);
ledger.store.block.successor_clear (transaction, block_a.hashables.previous);
ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::send);
}
Expand All @@ -79,8 +76,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.value_or (0), 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 @@ -95,7 +90,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.value_or (0), 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 @@ -113,8 +107,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 @@ -174,10 +166,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 @@ -371,10 +359,6 @@ void ledger_processor::state_block_impl (nano::state_block & block_a)

nano::account_info new_info (hash, block_a.hashables.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 @@ -441,10 +425,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.hashables.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 @@ -489,8 +469,6 @@ void ledger_processor::change_block (nano::change_block & block_a)
ledger.cache.rep_weights.representation_add_dual (transaction, block_a.hashables.representative, balance.number (), info->representative, 0 - balance.number ());
nano::account_info new_info (hash, block_a.hashables.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 @@ -539,8 +517,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 @@ -607,8 +583,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 (transaction, info->representative, pending.value ().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 @@ -669,7 +643,6 @@ void ledger_processor::open_block (nano::open_block & block_a)
nano::account_info new_info (hash, block_a.representative_field ().value (), hash, pending.value ().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 (transaction, block_a.representative_field ().value (), pending.value ().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 @@ -1498,15 +1471,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 @@ -9,13 +9,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 @@ -38,7 +36,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 @@ -61,13 +58,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 @@ -87,7 +82,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 @@ -5,12 +5,10 @@
#include <nano/store/block.hpp>
#include <nano/store/component.hpp>
#include <nano/store/confirmation_height.hpp>
#include <nano/store/frontier.hpp>
#include <nano/store/rep_weight.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::rep_weight & rep_weight_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, nano::store::rep_weight & rep_weight_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 @@ -40,5 +38,4 @@ void nano::store::component::initialize (store::write_transaction const & transa
++ledger_cache_a.account_count;
rep_weight.put (transaction_a, 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 ());
}
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 @@ -45,7 +44,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 @@ -67,12 +65,11 @@ namespace store
virtual std::string error_string (int status) const = 0;

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

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 43dae2f

Please sign in to comment.