Skip to content

Commit

Permalink
chore: check state root on syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankovi committed Apr 20, 2023
1 parent 1feb182 commit f74d6c4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libraries/core_libs/consensus/src/pbft/pbft_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,24 @@ std::optional<std::pair<PeriodData, std::vector<std::shared_ptr<Vote>>>> PbftMan
return std::nullopt;
}

{
auto period = period_data.pbft_blk->getPeriod();
h256 prev_state_root_hash;
if (period > final_chain_->delegation_delay()) {
if (const auto header = final_chain_->block_header(period - final_chain_->delegation_delay())) {
prev_state_root_hash = header->state_root;
} else {
LOG(log_er_) << "Block " << pbft_block_hash << " could not be validated as we are behind";
return std::nullopt;
}
}
if (period_data.pbft_blk->getPrevStateRoot() != prev_state_root_hash) {
LOG(log_er_) << "Block " << pbft_block_hash << " state root " << period_data.pbft_blk->getPrevStateRoot()
<< " isn't matching actual " << prev_state_root_hash;
return std::nullopt;
}
}

// Check reward votes
auto reward_votes = vote_mgr_->checkRewardVotes(period_data.pbft_blk, true);
if (!reward_votes.first) {
Expand Down

0 comments on commit f74d6c4

Please sign in to comment.