Skip to content

Commit

Permalink
Fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Jun 26, 2024
1 parent 619ce99 commit 20a6241
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
30 changes: 20 additions & 10 deletions nano/node/online_reps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -185,22 +183,34 @@ 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<nano::uint128_t> 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
auto median_idx = items.size () / 2;
nth_element (items.begin (), items.begin () + median_idx, items.end ());
std::nth_element (items.begin (), items.begin () + median_idx, items.end ());
return items[median_idx];
}
return 0;
Expand Down
1 change: 1 addition & 0 deletions nano/node/online_reps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 20a6241

Please sign in to comment.