diff --git a/CMakeLists.txt b/CMakeLists.txt index 08bdd2e088..c033e469b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.20) # Set current version of the project set(TARAXA_MAJOR_VERSION 1) set(TARAXA_MINOR_VERSION 11) -set(TARAXA_PATCH_VERSION 3) +set(TARAXA_PATCH_VERSION 4) set(TARAXA_VERSION ${TARAXA_MAJOR_VERSION}.${TARAXA_MINOR_VERSION}.${TARAXA_PATCH_VERSION}) # Any time a change in the network protocol is introduced this version should be increased diff --git a/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/pillar_votes_bundle_packet_handler.hpp b/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/pillar_votes_bundle_packet_handler.hpp index 550ca3e6a8..15a9ccfff7 100644 --- a/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/pillar_votes_bundle_packet_handler.hpp +++ b/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/pillar_votes_bundle_packet_handler.hpp @@ -18,7 +18,7 @@ class PillarVotesBundlePacketHandler : public ExtPillarVotePacketHandler { virtual void validatePacketRlpFormat(const threadpool::PacketData& packet_data) const override; virtual void process(const threadpool::PacketData& packet_data, const std::shared_ptr& peer) override; - protected: + public: constexpr static size_t kMaxPillarVotesInBundleRlp{250}; }; diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp index 2c01eff1ae..cc71e189e9 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp @@ -1,5 +1,7 @@ #include "network/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.hpp" +#include "network/tarcap/packets_handlers/latest/pillar_votes_bundle_packet_handler.hpp" + namespace taraxa::network::tarcap { GetPillarVotesBundlePacketHandler::GetPillarVotesBundlePacketHandler( @@ -42,19 +44,39 @@ void GetPillarVotesBundlePacketHandler::process(const threadpool::PacketData &pa LOG(log_dg_) << "No pillar votes for period " << period << "and pillar block hash " << pillar_block_hash; return; } + // Check if the votes size exceeds the maximum limit and split into multiple packets if needed + const size_t total_votes = votes.size(); + size_t votes_sent = 0; - dev::RLPStream s(votes.size()); - for (const auto &sig : votes) { - s.appendRaw(sig->rlp()); - } + while (votes_sent < total_votes) { + // Determine the size of the current chunk + const size_t chunk_size = + std::min(PillarVotesBundlePacketHandler::kMaxPillarVotesInBundleRlp, total_votes - votes_sent); + + // Create a new RLPStream for the chunk + dev::RLPStream s(chunk_size); + for (size_t i = 0; i < chunk_size; ++i) { + const auto &sig = votes[votes_sent + i]; + s.appendRaw(sig->rlp()); + } + + // Seal and send the chunk to the peer + if (sealAndSend(peer->getId(), SubprotocolPacketType::PillarVotesBundlePacket, std::move(s))) { + // Mark the votes in this chunk as known + for (size_t i = 0; i < chunk_size; ++i) { + peer->markPillarVoteAsKnown(votes[votes_sent + i]->getHash()); + } - if (sealAndSend(peer->getId(), SubprotocolPacketType::PillarVotesBundlePacket, std::move(s))) { - for (const auto &vote : votes) { - peer->markPillarVoteAsKnown(vote->getHash()); + LOG(log_nf_) << "Pillar votes bundle for period " << period << ", hash " << pillar_block_hash << " sent to " + << peer->getId() << " (Chunk " + << (votes_sent / PillarVotesBundlePacketHandler::kMaxPillarVotesInBundleRlp) + 1 << "/" + << (total_votes + PillarVotesBundlePacketHandler::kMaxPillarVotesInBundleRlp - 1) / + PillarVotesBundlePacketHandler::kMaxPillarVotesInBundleRlp + << ")"; } - LOG(log_nf_) << "Pillar votes bundle for period " << period << ", hash " << pillar_block_hash << " sent to " - << peer->getId(); + // Update the votes_sent counter + votes_sent += chunk_size; } }