Skip to content

Commit

Permalink
fix: setting reward votes period
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankovi committed Apr 25, 2023
1 parent f08494b commit d557974
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions libraries/core_libs/consensus/src/vote_manager/vote_manager.cpp
Original file line number Diff line number Diff line change
@@ -31,19 +31,25 @@ VoteManager::VoteManager(const addr_t& node_addr, const PbftConfig& pbft_config,

auto db_votes = db_->getAllTwoTPlusOneVotes();

auto addVerifiedVotes = [this](const std::vector<std::shared_ptr<Vote>>& votes) {
bool reward_votes_info_set = false;
auto addVerifiedVotes = [this](const std::vector<std::shared_ptr<Vote>>& votes, bool set_reward_votes_info = false) {
bool rewards_info_already_set = false;
for (const auto& vote : votes) {
// Check if votes are unique per round, step & voter
if (!isUniqueVote(vote).first) {
continue;
}

if (!reward_votes_info_set && vote->getType() == PbftVoteTypes::cert_vote) {
reward_votes_info_set = true;
reward_votes_block_hash_ = vote->getBlockHash();
reward_votes_period_ = vote->getPeriod();
reward_votes_round_ = vote->getRound();
if (set_reward_votes_info && vote->getType() == PbftVoteTypes::cert_vote) {
if (!rewards_info_already_set) {
rewards_info_already_set = true;
reward_votes_block_hash_ = vote->getBlockHash();
reward_votes_period_ = vote->getPeriod();
reward_votes_round_ = vote->getRound();
} else {
assert(reward_votes_block_hash_ == vote->getBlockHash());
assert(reward_votes_period_ == vote->getPeriod());
assert(reward_votes_round_ == vote->getRound());
}
}

addVerifiedVote(vote);
@@ -52,7 +58,7 @@ VoteManager::VoteManager(const addr_t& node_addr, const PbftConfig& pbft_config,
};

// Load 2t+1 vote blocks votes
addVerifiedVotes(db_->getAllTwoTPlusOneVotes());
addVerifiedVotes(db_->getAllTwoTPlusOneVotes(), true);

// Load own votes
const auto own_votes = db_->getOwnVerifiedVotes();

0 comments on commit d557974

Please sign in to comment.