Skip to content

Commit

Permalink
Merge pull request #2374 from Taraxa-project/issue-2372/fix_votes_syn…
Browse files Browse the repository at this point in the history
…cing

Issue 2372/fix votes syncing
  • Loading branch information
JakubFornadel authored Mar 9, 2023
2 parents 1c75893 + b561223 commit 9cff2b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ class ExtVotesPacketHandler : public PacketHandler {
const std::shared_ptr<TaraxaPeer>& peer,
bool validate_max_round_step);

/**
* @brief Common validation for all types of votes
*
* @param vote to be validated
* @return <true, ""> vote validation passed, otherwise <false, "err msg">
*/
std::pair<bool, std::string> validateVote(const std::shared_ptr<Vote>& vote) const;

/**
* @brief Validates provided vote if voted value == provided block
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,6 @@ std::pair<bool, std::string> ExtVotesPacketHandler::validateVotePeriodRoundStep(
return {true, ""};
}

std::pair<bool, std::string> ExtVotesPacketHandler::validateVote(const std::shared_ptr<Vote> &vote) const {
// Check is vote is unique per period, round & step & voter -> each address can generate just 1 vote
// (for a value that isn't NBH) per period, round & step
if (auto unique_vote_validation = vote_mgr_->isUniqueVote(vote); !unique_vote_validation.first) {
return unique_vote_validation;
}

const auto vote_valid = vote_mgr_->validateVote(vote);
if (!vote_valid.first) {
LOG(log_er_) << "Vote \"dpos\" validation failed: " << vote_valid.second;
}

return vote_valid;
}

bool ExtVotesPacketHandler::validateVoteAndBlock(const std::shared_ptr<Vote> &vote,
const std::shared_ptr<PbftBlock> &pbft_block) const {
if (pbft_block->getBlockHash() != vote->getBlockHash()) {
Expand All @@ -169,15 +154,15 @@ bool ExtVotesPacketHandler::validateVoteAndBlock(const std::shared_ptr<Vote> &vo
bool ExtVotesPacketHandler::isPbftRelevantVote(const std::shared_ptr<Vote> &vote) const {
const auto [current_pbft_round, current_pbft_period] = pbft_mgr_->getPbftRoundAndPeriod();

// Previous round next vote
if (vote->getPeriod() == current_pbft_period && (current_pbft_round - 1) == vote->getRound() &&
vote->getType() == PbftVoteTypes::next_vote) {
if (vote->getPeriod() >= current_pbft_period && vote->getRound() >= current_pbft_round) {
// Standard current or future vote
return true;
} else if (vote->getPeriod() >= current_pbft_period) {
// Standard vote
} else if (vote->getPeriod() == current_pbft_period && vote->getRound() == (current_pbft_round - 1) &&
vote->getType() == PbftVoteTypes::next_vote) {
// Previous round next vote
return true;
} else if (vote->getPeriod() == current_pbft_period - 1 && vote->getType() == PbftVoteTypes::cert_vote) {
// Previous round cert vote - potential reward vote
// Previous period cert vote - potential reward vote
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void VotesSyncPacketHandler::process(const PacketData &packet_data, const std::s
// Do not process vote that has already been validated
if (vote_mgr_->voteAlreadyValidated(vote->getHash())) {
LOG(log_dg_) << "Received vote " << vote->getHash() << " has already been validated";
return;
continue;
}

// Next votes bundle can contain votes for kNullBlockHash as well as some specific block hash
Expand Down

0 comments on commit 9cff2b1

Please sign in to comment.