Clear peers and online weight after 1 week of inactivity (#2506)
* Drop peers and online weight after 1 week of inactivity * Making method private and simplifying condition check (Wesley review)
This commit is contained in:
parent
1edb8c6c93
commit
2d503c3651
2 changed files with 29 additions and 0 deletions
|
@ -630,6 +630,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)
|
||||
|
@ -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 ());
|
||||
|
|
|
@ -196,6 +196,9 @@ public:
|
|||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue