From 35ffa41fa44c0e6ee4ce601bedbb1514a698808b Mon Sep 17 00:00:00 2001 From: JakubFornadel Date: Thu, 16 Mar 2023 12:50:21 +0100 Subject: [PATCH] fix: do not broadcast votes that were not processed + request pbft syncing only vote sender is also vote author --- .../packets_handlers/common/ext_votes_packet_handler.cpp | 3 ++- .../src/tarcap/packets_handlers/vote_packet_handler.cpp | 4 +++- .../tarcap/packets_handlers/votes_sync_packet_handler.cpp | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/common/ext_votes_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/common/ext_votes_packet_handler.cpp index d90bcb4326..a1bededff5 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/common/ext_votes_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/common/ext_votes_packet_handler.cpp @@ -85,7 +85,8 @@ std::pair ExtVotesPacketHandler::validateVotePeriodRoundStep( // skip this check if kConf.network.ddos_protection.vote_accepting_periods == 0 // vote->getPeriod() - 1 is here because votes are validated against vote_period - 1 in dpos contract // Do not request round sync too often here - if (std::chrono::system_clock::now() - last_pbft_block_sync_request_time_ > kSyncRequestInterval) { + if (vote->getVoter() == peer->getId() && + std::chrono::system_clock::now() - last_pbft_block_sync_request_time_ > kSyncRequestInterval) { // request PBFT chain sync from this node sealAndSend(peer->getId(), SubprotocolPacketType::GetPbftSyncPacket, std::move(dev::RLPStream(1) << std::max(vote->getPeriod() - 1, peer->pbft_chain_size_.load()))); diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/vote_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/vote_packet_handler.cpp index 7bd333abc9..dd213a4e63 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/vote_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/vote_packet_handler.cpp @@ -63,7 +63,9 @@ void VotePacketHandler::process(const PacketData &packet_data, const std::shared peer->markPbftBlockAsKnown(pbft_block->getBlockHash()); } - processVote(vote, pbft_block, peer, true); + if (processVote(vote, pbft_block, peer, true)) { + return; + } // Do not mark it before, as peers have small caches of known votes. Only mark gossiping votes peer->markVoteAsKnown(vote_hash); diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/votes_sync_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/votes_sync_packet_handler.cpp index 88faf800ce..02124ebbb2 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/votes_sync_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/votes_sync_packet_handler.cpp @@ -114,7 +114,10 @@ void VotesSyncPacketHandler::process(const PacketData &packet_data, const std::s // Process processStandardVote is called with false in case of next votes bundle -> does not check max boundaries // for round and step to actually being able to sync the current round in case network is stalled bool check_max_round_step = votes_bundle_votes_type == PbftVoteTypes::next_vote ? false : true; - processVote(vote, nullptr, peer, check_max_round_step); + if (processVote(vote, nullptr, peer, check_max_round_step)) { + continue; + } + votes.push_back(std::move(vote)); }