Skip to content

Commit

Permalink
Merge pull request #2390 from Taraxa-project/fix-for-double-votes
Browse files Browse the repository at this point in the history
chore: introduce check on double votes
  • Loading branch information
MatusKysel authored Mar 17, 2023
2 parents 1500374 + 9a2b67f commit 25c65e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ std::optional<addr_t> RewardsStats::getTransactionValidator(const trx_hash_t& tx
bool RewardsStats::addVote(const std::shared_ptr<Vote>& vote) {
// Set valid cert vote to validator
auto& validator_stats = validators_stats_[vote->getVoterAddr()];
assert(validator_stats.vote_weight_ == 0);
// assert(validator_stats.vote_weight_ == 0);
assert(vote->getWeight());

if (validator_stats.vote_weight_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ bool ExtVotesPacketHandler::validateVoteAndBlock(const std::shared_ptr<Vote> &vo
<< pbft_block->getBlockHash();
return false;
}
std::unordered_set<vote_hash_t> set;
const auto reward_votes = pbft_block->getRewardVotes();
set.reserve(reward_votes.size());
for (const auto &hash : reward_votes) {
if (!set.insert(hash).second) {
LOG(log_er_) << "PBFT block " << pbft_block->getBlockHash() << " has duplicated vote " << hash;
}
}

return true;
}
Expand Down

0 comments on commit 25c65e2

Please sign in to comment.