diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 8419811f..7d7ec1f3 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -630,6 +630,7 @@ nano::process_return nano::node::process_local (std::shared_ptr blo void nano::node::start () { + long_inactivity_cleanup (); network.start (); add_initial_peers (); if (!flags.disable_legacy_bootstrap) @@ -774,6 +775,31 @@ nano::uint128_t nano::node::minimum_principal_weight (nano::uint128_t const & on return online_stake / network_params.network.principal_weight_factor; } +void nano::node::long_inactivity_cleanup () +{ + bool perform_cleanup = false; + auto transaction (store.tx_begin_write ()); + if (store.online_weight_count (transaction) > 0) + { + auto i (store.online_weight_begin (transaction)); + auto sample (store.online_weight_begin (transaction)); + auto n (store.online_weight_end ()); + while (++i != n) + { + ++sample; + } + assert (sample != n); + auto const one_week_ago = (std::chrono::system_clock::now () - std::chrono::hours (7 * 24)).time_since_epoch ().count (); + perform_cleanup = sample->first < one_week_ago; + } + if (perform_cleanup) + { + store.online_weight_clear (transaction); + store.peer_clear (transaction); + logger.always_log ("Removed records of peers and online weight after a long period of inactivity"); + } +} + void nano::node::ongoing_rep_calculation () { auto now (std::chrono::steady_clock::now ()); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index c107dd5e..6cf68be7 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -196,6 +196,9 @@ public: std::atomic stopped{ false }; static double constexpr price_max = 16.0; static double constexpr free_cutoff = 1024.0; + +private: + void long_inactivity_cleanup (); }; std::unique_ptr collect_container_info (node & node, const std::string & name);