Skip to content

Commit

Permalink
Address review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Aug 27, 2022
1 parent 521934c commit c245b2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 8 additions & 8 deletions nano/node/vote_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bool nano::vote_cache::entry::vote (const nano::account & representative, const
{
// We already have a vote from this rep
// Update timestamp if newer but tally remains unchanged as we already counted this rep weight
// It is not essential to keep tally up to date if rep voting weight changes, elections do tally calculations independently, so in the worst case scenario only our queue ordering will be a bit off
if (timestamp > existing->second)
{
existing->second = timestamp;
Expand Down Expand Up @@ -74,15 +75,14 @@ void nano::vote_cache::vote_impl (const nano::block_hash & hash, const nano::acc
bool success = cache_by_hash.modify (existing, [&representative, &timestamp, &rep_weight] (entry & ent) {
ent.vote (representative, timestamp, rep_weight);
});
if (success) // Should never fail, but a check ensures the iterator `existing` is valid
release_assert (success); // Ensure iterator `existing` is valid

auto & queue_by_hash = queue.get<tag_hash> ();
if (auto queue_existing = queue_by_hash.find (hash); queue_existing != queue_by_hash.end ())
{
auto & queue_by_hash = queue.get<tag_hash> ();
if (auto queue_existing = queue_by_hash.find (hash); queue_existing != queue_by_hash.end ())
{
queue_by_hash.modify (queue_existing, [&existing] (queue_entry & ent) {
ent.tally = existing->tally;
});
}
queue_by_hash.modify (queue_existing, [&existing] (queue_entry & ent) {
ent.tally = existing->tally;
});
}
}
else
Expand Down
6 changes: 4 additions & 2 deletions nano/node/vote_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,18 @@ class vote_cache final
bool erase (nano::block_hash const & hash);
/**
* Returns an entry with the highest tally.
* @param min_tally minimum tally threshold, entries below with their voting weight below this will be ignored
*/
std::optional<entry> peek (nano::uint128_t const & min_tally = 0) const;
/**
* Returns an entry with the highest tally and removes it from container.
* @param min_tally minimum tally threshold, entries below with their voting weight below this will be ignored
*/
std::optional<entry> pop (nano::uint128_t const & min_tally = 0);
/**
* Reinserts a block into the queue.
* It is possible that we dequeue a hash that doesn't have a received block yet (for eg. if publish message was lost).
* We need a way to reinsert that hash into the queue when we finally receive the block
*/
void trigger (const nano::block_hash & hash);

Expand Down Expand Up @@ -160,7 +164,5 @@ class vote_cache final
ordered_queue queue;

mutable nano::mutex mutex;

friend std::unique_ptr<nano::container_info_component> collect_container_info (active_transactions &, std::string const &);
};
}

0 comments on commit c245b2a

Please sign in to comment.