From ee03a8e89928307925a306b3a9c78e9849da2520 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Wed, 3 Jul 2024 13:46:07 +0200 Subject: [PATCH] chore: fix regossiping for pillarvotes --- libraries/config/src/hardfork.cpp | 3 ++- .../common/ext_pillar_vote_packet_handler.hpp | 2 +- .../latest/common/ext_bls_sig_packet_handler.cpp | 13 ++++++++----- .../latest/pillar_vote_packet_handler.cpp | 5 +++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/libraries/config/src/hardfork.cpp b/libraries/config/src/hardfork.cpp index 78b6642f17..60b6119c6d 100644 --- a/libraries/config/src/hardfork.cpp +++ b/libraries/config/src/hardfork.cpp @@ -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; } diff --git a/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/common/ext_pillar_vote_packet_handler.hpp b/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/common/ext_pillar_vote_packet_handler.hpp index 66be6ea7fd..91bc38fd27 100644 --- a/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/common/ext_pillar_vote_packet_handler.hpp +++ b/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/common/ext_pillar_vote_packet_handler.hpp @@ -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& vote, const std::shared_ptr& peer); + bool processPillarVote(const std::shared_ptr& vote, const std::shared_ptr& peer); protected: std::shared_ptr pillar_chain_manager_; diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/common/ext_bls_sig_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/common/ext_bls_sig_packet_handler.cpp index dcc17e726d..20e17e1ace 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/common/ext_bls_sig_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/common/ext_bls_sig_packet_handler.cpp @@ -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 &vote, +bool ExtPillarVotePacketHandler::processPillarVote(const std::shared_ptr &vote, const std::shared_ptr &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 diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/pillar_vote_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/pillar_vote_packet_handler.cpp index f4d3da7c38..8def36ac36 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/pillar_vote_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/pillar_vote_packet_handler.cpp @@ -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 &vote, bool rebroadcast) {