Skip to content

Commit

Permalink
Remove cleanup functions related to unchecked blocks.
Browse files Browse the repository at this point in the history
These functions are no longer relevant since the blocks are now stored in memory and are bounded.
  • Loading branch information
clemahieu committed Jan 24, 2024
1 parent b225de0 commit f9c9915
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 113 deletions.
39 changes: 0 additions & 39 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3254,45 +3254,6 @@ TEST (node, peer_cache_restart)
}
}

TEST (node, unchecked_cleanup)
{
nano::test::system system{};
nano::node_flags node_flags{};
node_flags.disable_unchecked_cleanup = true;
nano::keypair key{};
auto & node = *system.add_node (node_flags);
auto open = nano::state_block_builder ()
.account (key.pub)
.previous (0)
.representative (key.pub)
.balance (1)
.link (key.pub)
.sign (key.prv, key.pub)
.work (*system.work.generate (key.pub))
.build_shared ();
std::vector<uint8_t> bytes;
{
nano::vectorstream stream (bytes);
open->serialize (stream);
}
// Add to the blocks filter
// Should be cleared after unchecked cleanup
ASSERT_FALSE (node.network.publish_filter.apply (bytes.data (), bytes.size ()));
node.process_active (open);
// Waits for the open block to get saved in the database
ASSERT_TIMELY_EQ (15s, 1, node.unchecked.count ());
node.config.unchecked_cutoff_time = std::chrono::seconds (2);
ASSERT_EQ (1, node.unchecked.count ());
std::this_thread::sleep_for (std::chrono::seconds (1));
node.unchecked_cleanup ();
ASSERT_TRUE (node.network.publish_filter.apply (bytes.data (), bytes.size ()));
ASSERT_EQ (1, node.unchecked.count ());
std::this_thread::sleep_for (std::chrono::seconds (2));
node.unchecked_cleanup ();
ASSERT_FALSE (node.network.publish_filter.apply (bytes.data (), bytes.size ()));
ASSERT_EQ (0, node.unchecked.count ());
}

/** This checks that a node can be opened (without being blocked) when a write lock is held elsewhere */
TEST (node, dont_write_lock_node)
{
Expand Down
4 changes: 0 additions & 4 deletions nano/node/bootstrap/bootstrap_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,6 @@ void nano::bootstrap_attempt_legacy::run ()
{
request_push (lock);
}
if (!stopped)
{
node->unchecked_cleanup ();
}
}
lock.unlock ();
stop ();
Expand Down
2 changes: 0 additions & 2 deletions nano/node/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ std::error_code nano::update_flags (nano::node_flags & flags_a, boost::program_o
flags_a.disable_bootstrap_listener = (vm.count ("disable_bootstrap_listener") > 0);
}
flags_a.disable_providing_telemetry_metrics = (vm.count ("disable_providing_telemetry_metrics") > 0);
flags_a.disable_unchecked_cleanup = (vm.count ("disable_unchecked_cleanup") > 0);
flags_a.disable_unchecked_drop = (vm.count ("disable_unchecked_drop") > 0);
flags_a.disable_block_processor_unchecked_deletion = (vm.count ("disable_block_processor_unchecked_deletion") > 0);
flags_a.enable_pruning = (vm.count ("enable_pruning") > 0);
flags_a.allow_bootstrap_peers_duplicates = (vm.count ("allow_bootstrap_peers_duplicates") > 0);
Expand Down
64 changes: 0 additions & 64 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,6 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons

logger.info (nano::log::type::node, "************************************ ================= ************************************");
}

// Drop unchecked blocks if initial bootstrap is completed
if (!flags.disable_unchecked_drop && !use_bootstrap_weight && !flags.read_only)
{
logger.info (nano::log::type::node, "Dropping unchecked blocks...");
unchecked.clear ();
}
}

ledger.pruning = flags.enable_pruning || store.pruned.count (store.tx_begin_read ()) > 0;
Expand Down Expand Up @@ -610,13 +603,6 @@ void nano::node::start ()
{
ongoing_bootstrap ();
}
if (!flags.disable_unchecked_cleanup)
{
auto this_l (shared ());
workers.push_task ([this_l] () {
this_l->ongoing_unchecked_cleanup ();
});
}
if (flags.enable_pruning)
{
auto this_l (shared ());
Expand Down Expand Up @@ -947,56 +933,6 @@ void nano::node::bootstrap_wallet ()
}
}

void nano::node::unchecked_cleanup ()
{
std::vector<nano::uint128_t> digests;
std::deque<nano::unchecked_key> cleaning_list;
auto const attempt (bootstrap_initiator.current_attempt ());
const bool long_attempt (attempt != nullptr && std::chrono::duration_cast<std::chrono::seconds> (std::chrono::steady_clock::now () - attempt->attempt_start).count () > config.unchecked_cutoff_time.count ());
// Collect old unchecked keys
if (ledger.cache.block_count >= ledger.bootstrap_weight_max_blocks && !long_attempt)
{
auto const now (nano::seconds_since_epoch ());
auto const transaction (store.tx_begin_read ());
// Max 1M records to clean, max 2 minutes reading to prevent slow i/o systems issues
unchecked.for_each (
[this, &digests, &cleaning_list, &now] (nano::unchecked_key const & key, nano::unchecked_info const & info) {
if ((now - info.modified ()) > static_cast<uint64_t> (config.unchecked_cutoff_time.count ()))
{
digests.push_back (network.publish_filter.hash (info.block));
cleaning_list.push_back (key);
} }, [iterations = 0, count = 1024 * 1024] () mutable { return iterations++ < count; });
}
if (!cleaning_list.empty ())
{
logger.info (nano::log::type::node, "Deleting {} old unchecked blocks", cleaning_list.size ());
}
// Delete old unchecked keys in batches
while (!cleaning_list.empty ())
{
std::size_t deleted_count (0);
while (deleted_count++ < 2 * 1024 && !cleaning_list.empty ())
{
auto key (cleaning_list.front ());
cleaning_list.pop_front ();
if (unchecked.exists (key))
{
unchecked.del (key);
}
}
}
// Delete from the duplicate filter
network.publish_filter.clear (digests);
}

void nano::node::ongoing_unchecked_cleanup ()
{
unchecked_cleanup ();
workers.add_timed_task (std::chrono::steady_clock::now () + network_params.node.unchecked_cleaning_interval, [this_l = shared ()] () {
this_l->ongoing_unchecked_cleanup ();
});
}

bool nano::node::collect_ledger_pruning_targets (std::deque<nano::block_hash> & pruning_targets_a, nano::account & last_account_a, uint64_t const batch_read_size_a, uint64_t const max_depth_a, uint64_t const cutoff_time_a)
{
uint64_t read_operations (0);
Expand Down
2 changes: 0 additions & 2 deletions nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ class node final : public std::enable_shared_from_this<nano::node>
void ongoing_rep_calculation ();
void ongoing_bootstrap ();
void ongoing_peer_store ();
void ongoing_unchecked_cleanup ();
void backup_wallet ();
void search_receivable_all ();
void bootstrap_wallet ();
void unchecked_cleanup ();
bool collect_ledger_pruning_targets (std::deque<nano::block_hash> &, nano::account &, uint64_t const, uint64_t const, uint64_t const);
void ledger_pruning (uint64_t const, bool);
void ongoing_ledger_pruning ();
Expand Down
2 changes: 0 additions & 2 deletions nano/node/nodeconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ class node_flags final
bool disable_rep_crawler{ false };
bool disable_request_loop{ false }; // For testing only
bool disable_tcp_realtime{ false };
bool disable_unchecked_cleanup{ false };
bool disable_unchecked_drop{ true };
bool disable_providing_telemetry_metrics{ false };
bool disable_ongoing_telemetry_requests{ false };
bool disable_block_processor_unchecked_deletion{ false };
Expand Down

0 comments on commit f9c9915

Please sign in to comment.