Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 20, 2024
1 parent 46114c5 commit 8532f27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions nano/node/vote_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::vote> const & vote, std::unordered_set<nano::block_hash> const & filter)
void nano::vote_cache::vote (std::shared_ptr<nano::vote> const & vote, std::function<bool (nano::block_hash const &)> 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);
Expand All @@ -140,7 +137,7 @@ void nano::vote_cache::vote (std::shared_ptr<nano::vote> const & vote, std::unor

for (auto const & hash : vote->hashes)
{
if (!filter.contains (hash))
if (!filter (hash))
{
continue;
}
Expand Down Expand Up @@ -182,14 +179,14 @@ std::size_t nano::vote_cache::size () const
return cache.size ();
}

std::optional<nano::vote_cache::entry> nano::vote_cache::find (const nano::block_hash & hash) const
std::vector<std::shared_ptr<nano::vote>> nano::vote_cache::find (const nano::block_hash & hash) const
{
nano::lock_guard<nano::mutex> lock{ mutex };

auto & cache_by_hash = cache.get<tag_hash> ();
if (auto existing = cache_by_hash.find (hash); existing != cache_by_hash.end ())
{
return *existing;
return existing->votes ();
}
return {};
}
Expand Down
4 changes: 2 additions & 2 deletions nano/node/vote_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ class vote_cache final
/**
* Adds a new vote to cache
*/
void vote (std::shared_ptr<nano::vote> const & vote, std::unordered_set<nano::block_hash> const & filter);
void vote (std::shared_ptr<nano::vote> const & vote, std::function<bool (nano::block_hash const &)> const & filter);

/**
* Tries to find an entry associated with block hash
*/
std::optional<entry> find (nano::block_hash const & hash) const;
std::vector<std::shared_ptr<nano::vote>> find (nano::block_hash const & hash) const;

/**
* Removes an entry associated with block hash, does nothing if entry does not exist
Expand Down

0 comments on commit 8532f27

Please sign in to comment.