Skip to content

Commit

Permalink
Fix vote_processor.codes test
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Dec 12, 2023
1 parent 632b73e commit a770ea1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nano/core_test/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::election> election;
Expand Down
6 changes: 6 additions & 0 deletions nano/node/vote_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ bool nano::vote_cache::erase (const nano::block_hash & hash)
return result;
}

void nano::vote_cache::clear ()
{
nano::lock_guard<nano::mutex> lock{ mutex };
cache.clear ();
}

std::vector<nano::vote_cache::top_entry> nano::vote_cache::top (const nano::uint128_t & min_tally)
{
stats.inc (nano::stat::type::vote_cache, nano::stat::detail::top);
Expand Down
3 changes: 3 additions & 0 deletions nano/node/vote_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,18 @@ class vote_cache final
* Adds a new vote to cache
*/
void vote (nano::block_hash const & hash, std::shared_ptr<nano::vote> vote);

/**
* Tries to find an entry associated with block hash
*/
std::optional<entry> 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;
Expand Down

0 comments on commit a770ea1

Please sign in to comment.