From a770ea15fbe3d4f9a7bd0027a1918e3b896bd88e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:47:19 +0100 Subject: [PATCH] Fix `vote_processor.codes` test --- nano/core_test/vote_processor.cpp | 5 ++++- nano/node/vote_cache.cpp | 6 ++++++ nano/node/vote_cache.hpp | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index 48bdc4ec..14fea2b4 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -25,9 +25,12 @@ TEST (vote_processor, codes) // Hint of pre-validation ASSERT_NE (nano::vote_code::invalid, node.vote_processor.vote_blocking (vote_invalid, channel, true)); - // No ongoing election + // No ongoing election (vote goes to vote cache) ASSERT_EQ (nano::vote_code::indeterminate, node.vote_processor.vote_blocking (vote, channel)); + // Clear vote cache before starting election + node.vote_cache.clear (); + // First vote from an account for an ongoing election node.start_election (blocks[0]); std::shared_ptr election; diff --git a/nano/node/vote_cache.cpp b/nano/node/vote_cache.cpp index b6e2bb80..527ea0a0 100644 --- a/nano/node/vote_cache.cpp +++ b/nano/node/vote_cache.cpp @@ -193,6 +193,12 @@ bool nano::vote_cache::erase (const nano::block_hash & hash) return result; } +void nano::vote_cache::clear () +{ + nano::lock_guard lock{ mutex }; + cache.clear (); +} + std::vector nano::vote_cache::top (const nano::uint128_t & min_tally) { stats.inc (nano::stat::type::vote_cache, nano::stat::detail::top); diff --git a/nano/node/vote_cache.hpp b/nano/node/vote_cache.hpp index 4a353446..5b88ff1b 100644 --- a/nano/node/vote_cache.hpp +++ b/nano/node/vote_cache.hpp @@ -97,15 +97,18 @@ public: * Adds a new vote to cache */ void vote (nano::block_hash const & hash, std::shared_ptr vote); + /** * Tries to find an entry associated with block hash */ std::optional find (nano::block_hash const & hash) const; + /** * Removes an entry associated with block hash, does nothing if entry does not exist * @return true if hash existed and was erased, false otherwise */ bool erase (nano::block_hash const & hash); + void clear (); std::size_t size () const; bool empty () const;