Skip to content

Commit

Permalink
Merge pull request #2854 from Taraxa-project/fix-pillar-vote-boundle
Browse files Browse the repository at this point in the history
bugfix: split pillar vote packet to serverl ones
  • Loading branch information
kstdl authored Sep 25, 2024
2 parents 05f94e6 + a88feea commit aa31fb7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaraxaPeer>& peer) override;

protected:
public:
constexpr static size_t kMaxPillarVotesInBundleRlp{250};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit aa31fb7

Please sign in to comment.