From 8532f270bbe38389b725243cb71eab3551459a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 20 Mar 2024 15:01:01 +0100 Subject: [PATCH] WIP --- nano/node/vote_cache.cpp | 11 ++++------- nano/node/vote_cache.hpp | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/nano/node/vote_cache.cpp b/nano/node/vote_cache.cpp index bc48ccd1b2..5c59da6335 100644 --- a/nano/node/vote_cache.cpp +++ b/nano/node/vote_cache.cpp @@ -127,11 +127,8 @@ nano::vote_cache::vote_cache (vote_cache_config const & config_a, nano::stats & { } -void nano::vote_cache::vote (std::shared_ptr const & vote, std::unordered_set const & filter) +void nano::vote_cache::vote (std::shared_ptr const & vote, std::function const & filter) { - // Assert that supplied hash corresponds to a one of the hashes stored in vote - debug_assert (std::find (vote->hashes.begin (), vote->hashes.end (), hash) != vote->hashes.end ()); - auto const representative = vote->account; auto const timestamp = vote->timestamp (); auto const rep_weight = rep_weight_query (representative); @@ -140,7 +137,7 @@ void nano::vote_cache::vote (std::shared_ptr const & vote, std::unor for (auto const & hash : vote->hashes) { - if (!filter.contains (hash)) + if (!filter (hash)) { continue; } @@ -182,14 +179,14 @@ std::size_t nano::vote_cache::size () const return cache.size (); } -std::optional nano::vote_cache::find (const nano::block_hash & hash) const +std::vector> nano::vote_cache::find (const nano::block_hash & hash) const { nano::lock_guard lock{ mutex }; auto & cache_by_hash = cache.get (); if (auto existing = cache_by_hash.find (hash); existing != cache_by_hash.end ()) { - return *existing; + return existing->votes (); } return {}; } diff --git a/nano/node/vote_cache.hpp b/nano/node/vote_cache.hpp index 68817a20a6..d499d34442 100644 --- a/nano/node/vote_cache.hpp +++ b/nano/node/vote_cache.hpp @@ -109,12 +109,12 @@ class vote_cache final /** * Adds a new vote to cache */ - void vote (std::shared_ptr const & vote, std::unordered_set const & filter); + void vote (std::shared_ptr const & vote, std::function const & filter); /** * Tries to find an entry associated with block hash */ - std::optional find (nano::block_hash const & hash) const; + std::vector> find (nano::block_hash const & hash) const; /** * Removes an entry associated with block hash, does nothing if entry does not exist