Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear peers and online weight after 1 week of inactivity #2506

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ nano::process_return nano::node::process_local (std::shared_ptr<nano::block> blo

void nano::node::start ()
{
long_inactivity_cleanup ();
network.start ();
add_initial_peers ();
if (!flags.disable_legacy_bootstrap)
Expand Down Expand Up @@ -768,6 +769,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 ());
Expand Down
3 changes: 3 additions & 0 deletions nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ class node final : public std::enable_shared_from_this<nano::node>
std::atomic<bool> stopped{ false };
static double constexpr price_max = 16.0;
static double constexpr free_cutoff = 1024.0;

private:
void long_inactivity_cleanup ();
};

std::unique_ptr<container_info_component> collect_container_info (node & node, const std::string & name);
Expand Down