From 8c32228ef73d278f6b738cd1ec77b626a1a50cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sun, 24 Mar 2024 13:48:42 +0100 Subject: [PATCH] Make target interval more explicit --- nano/lib/interval.hpp | 8 +------- nano/lib/uniquer.hpp | 4 ++-- nano/node/vote_cache.cpp | 5 ++--- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/nano/lib/interval.hpp b/nano/lib/interval.hpp index 263f15ce7..a4b500fa6 100644 --- a/nano/lib/interval.hpp +++ b/nano/lib/interval.hpp @@ -7,12 +7,7 @@ namespace nano class interval { public: - explicit interval (std::chrono::milliseconds target) : - target{ target } - { - } - - bool elapsed () + bool elapsed (auto target) { auto const now = std::chrono::steady_clock::now (); if (now - last >= target) @@ -24,7 +19,6 @@ public: } private: - std::chrono::milliseconds const target; std::chrono::steady_clock::time_point last{ std::chrono::steady_clock::now () }; }; } \ No newline at end of file diff --git a/nano/lib/uniquer.hpp b/nano/lib/uniquer.hpp index 351df334d..022616fa3 100644 --- a/nano/lib/uniquer.hpp +++ b/nano/lib/uniquer.hpp @@ -27,7 +27,7 @@ public: nano::lock_guard guard{ mutex }; - if (cleanup_interval.elapsed ()) + if (cleanup_interval.elapsed (cleanup_cutoff)) { cleanup (); } @@ -75,6 +75,6 @@ private: private: mutable nano::mutex mutex; std::unordered_map> values; - nano::interval cleanup_interval{ cleanup_cutoff }; + nano::interval cleanup_interval; }; } \ No newline at end of file diff --git a/nano/node/vote_cache.cpp b/nano/node/vote_cache.cpp index f3eaec23c..92a78ff03 100644 --- a/nano/node/vote_cache.cpp +++ b/nano/node/vote_cache.cpp @@ -123,8 +123,7 @@ std::chrono::steady_clock::time_point nano::vote_cache_entry::last_vote () const nano::vote_cache::vote_cache (vote_cache_config const & config_a, nano::stats & stats_a) : config{ config_a }, - stats{ stats_a }, - cleanup_interval{ config_a.age_cutoff / 2 } + stats{ stats_a } { } @@ -239,7 +238,7 @@ std::vector nano::vote_cache::top (const nano::uint { nano::lock_guard lock{ mutex }; - if (cleanup_interval.elapsed ()) + if (cleanup_interval.elapsed (config.age_cutoff / 2)) { cleanup (); }