Skip to content

Commit

Permalink
Merge pull request #2801 from Taraxa-project/fix-regossiping
Browse files Browse the repository at this point in the history
chore: fix regossiping for pillarvotes
  • Loading branch information
MatusKysel authored Jul 3, 2024
2 parents 3fa9c21 + ee03a8e commit d9a242f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion libraries/config/src/hardfork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ RLP_FIELDS_DEFINE(AspenHardfork, block_num_part_one, block_num_part_two, max_sup
bool FicusHardforkConfig::isFicusHardfork(taraxa::PbftPeriod period) const { return period >= block_num; }

bool FicusHardforkConfig::isPillarBlockPeriod(taraxa::PbftPeriod period, bool skip_first_pillar_block) const {
return period >= block_num && period >= firstPillarBlockPeriod() + (skip_first_pillar_block ? 1 : 0) * pillar_blocks_interval &&
return period >= block_num &&
period >= firstPillarBlockPeriod() + (skip_first_pillar_block ? 1 : 0) * pillar_blocks_interval &&
period % pillar_blocks_interval == 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ExtPillarVotePacketHandler : public PacketHandler {
const addr_t& node_addr, const std::string& log_channel);

protected:
void processPillarVote(const std::shared_ptr<PillarVote>& vote, const std::shared_ptr<TaraxaPeer>& peer);
bool processPillarVote(const std::shared_ptr<PillarVote>& vote, const std::shared_ptr<TaraxaPeer>& peer);

protected:
std::shared_ptr<pillar_chain::PillarChainManager> pillar_chain_manager_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@ ExtPillarVotePacketHandler::ExtPillarVotePacketHandler(
: PacketHandler(conf, std::move(peers_state), std::move(packets_stats), node_addr, log_channel),
pillar_chain_manager_{std::move(pillar_chain_manager)} {}

void ExtPillarVotePacketHandler::processPillarVote(const std::shared_ptr<PillarVote> &vote,
bool ExtPillarVotePacketHandler::processPillarVote(const std::shared_ptr<PillarVote> &vote,
const std::shared_ptr<TaraxaPeer> &peer) {
if (!pillar_chain_manager_->isRelevantPillarVote(vote)) {
LOG(log_dg_) << "Drop irrelevant pillar vote " << vote->getHash() << " from peer " << peer->getId();
return;
return false;
}

if (!pillar_chain_manager_->validatePillarVote(vote)) {
std::ostringstream err_msg;
err_msg << "Invalid pillar vote " << vote->getHash() << " from peer " << peer->getId();
throw MaliciousPeerException(err_msg.str());
// TODO: enable for mainnet
// std::ostringstream err_msg;
// err_msg << "Invalid pillar vote " << vote->getHash() << " from peer " << peer->getId();
// throw MaliciousPeerException(err_msg.str());
return false;
}

pillar_chain_manager_->addVerifiedPillarVote(vote);

// Mark pillar vote as known for peer
peer->markPillarVoteAsKnown(vote->getHash());
return true;
}

} // namespace taraxa::network::tarcap
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ void PillarVotePacketHandler::process(const threadpool::PacketData &packet_data,
throw MaliciousPeerException(err_msg.str());
}

processPillarVote(pillar_vote, peer);
onNewPillarVote(pillar_vote);
if (processPillarVote(pillar_vote, peer)) {
onNewPillarVote(pillar_vote);
}
}

void PillarVotePacketHandler::onNewPillarVote(const std::shared_ptr<PillarVote> &vote, bool rebroadcast) {
Expand Down

0 comments on commit d9a242f

Please sign in to comment.