From 81d699052f0afa905fa527371220b21f14266e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:39:17 +0200 Subject: [PATCH] Fix compilation --- nano/node/online_reps.cpp | 28 +++++++++++++++++++--------- nano/node/online_reps.hpp | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/nano/node/online_reps.cpp b/nano/node/online_reps.cpp index 45d6ffb1c7..fa61a65c5f 100644 --- a/nano/node/online_reps.cpp +++ b/nano/node/online_reps.cpp @@ -147,9 +147,7 @@ void nano::online_reps::trim_trend (nano::store::write_transaction const & trans } // Ensure that all remaining entries are within the expected range - debug_assert (std::none_of (ledger.store.online_weight.begin (transaction), ledger.store.online_weight.end (), [cutoff, now] (auto const & item) { - return nano::from_seconds_since_epoch (item.first) < cutoff || nano::from_seconds_since_epoch (item.first) > now; - })); + debug_assert (verify_consistency (transaction, now, cutoff)); } void nano::online_reps::sanitize_trend (nano::store::write_transaction const & transaction) @@ -185,17 +183,29 @@ void nano::online_reps::sanitize_trend (nano::store::write_transaction const & t removed_future); // Ensure that all remaining entries are within the expected range - debug_assert (std::none_of (ledger.store.online_weight.begin (transaction), ledger.store.online_weight.end (), [cutoff, now] (auto const & item) { - return nano::from_seconds_since_epoch (item.first) < cutoff || nano::from_seconds_since_epoch (item.first) > now; - })); + debug_assert (verify_consistency (transaction, now, cutoff)); +} + +bool nano::online_reps::verify_consistency (nano::store::write_transaction const & transaction, std::chrono::system_clock::time_point now, std::chrono::system_clock::time_point cutoff) const +{ + for (auto it = ledger.store.online_weight.begin (transaction); it != ledger.store.online_weight.end (); ++it) + { + auto tstamp = nano::from_seconds_since_epoch (it->first); + if (tstamp < cutoff || tstamp > now) + { + return false; + } + } + return true; } nano::uint128_t nano::online_reps::calculate_trend (store::transaction const & transaction) const { std::vector items; - std::transform (ledger.store.online_weight.begin (transaction), ledger.store.online_weight.end (), std::back_inserter (items), [] (const auto & entry) { - return entry.second.number (); - }); + for (auto it = ledger.store.online_weight.begin (transaction); it != ledger.store.online_weight.end (); ++it) + { + items.push_back (it->second.number ()); + } if (!items.empty ()) { // Pick median value for our target vote weight diff --git a/nano/node/online_reps.hpp b/nano/node/online_reps.hpp index 4cbfd3ee13..6bcec904a4 100644 --- a/nano/node/online_reps.hpp +++ b/nano/node/online_reps.hpp @@ -61,6 +61,7 @@ class online_reps final void trim_trend (nano::store::write_transaction const &); /** Iterate over all database samples and remove invalid records. This is meant to clean potential leftovers from previous versions. */ void sanitize_trend (nano::store::write_transaction const &); + bool verify_consistency (nano::store::write_transaction const &, std::chrono::system_clock::time_point now, std::chrono::system_clock::time_point cutoff) const; nano::uint128_t calculate_trend (nano::store::transaction const &) const; nano::uint128_t calculate_online () const;