Skip to content

Commit

Permalink
adjust pillar votes bundle packet
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubFornadel committed Nov 2, 2024
1 parent ed22eb6 commit 61ccc0d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
namespace taraxa::network::tarcap {

struct PillarVotesBundlePacket {
std::vector<std::shared_ptr<PillarVote>> pillar_votes;
OptimizedPillarVotesBundle pillar_votes_bundle;

void rlp(::taraxa::util::RLPDecoderRef encoding) { pillar_votes = decodePillarVotesBundleRlp(encoding.value); }
void rlp(::taraxa::util::RLPEncoderRef encoding) const {
encoding.appendRaw(encodePillarVotesBundleRlp(pillar_votes));
}
RLP_FIELDS_DEFINE_INPLACE(pillar_votes_bundle)
};

} // namespace taraxa::network::tarcap
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void GetPillarVotesBundlePacketHandler::process(GetPillarVotesBundlePacket &&pac
for (size_t i = 0; i < chunk_size; ++i) {
pillar_votes.emplace_back(votes[votes_sent + i]);
}
PillarVotesBundlePacket pillar_votes_bundle_packet(std::move(pillar_votes));
PillarVotesBundlePacket pillar_votes_bundle_packet(OptimizedPillarVotesBundle{std::move(pillar_votes)});

// Seal and send the chunk to the peer
if (sealAndSend(peer->getId(), SubprotocolPacketType::kPillarVotesBundlePacket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ PillarVotesBundlePacketHandler::PillarVotesBundlePacketHandler(

void PillarVotesBundlePacketHandler::process(PillarVotesBundlePacket &&packet,
const std::shared_ptr<TaraxaPeer> &peer) {
if (packet.pillar_votes.size() == 0 || packet.pillar_votes.size() > kMaxPillarVotesInBundleRlp) {
throw InvalidRlpItemsCountException("PillarVotesBundlePacket", packet.pillar_votes.size(),
if (packet.pillar_votes_bundle.pillar_votes.size() == 0 ||
packet.pillar_votes_bundle.pillar_votes.size() > kMaxPillarVotesInBundleRlp) {
throw InvalidRlpItemsCountException("PillarVotesBundlePacket", packet.pillar_votes_bundle.pillar_votes.size(),
kMaxPillarVotesInBundleRlp);
}

// TODO[2744]: there could be the same protection as in pbft syncing that only requested bundle packet is accepted
LOG(log_dg_) << "PillarVotesBundlePacket received from peer " << peer->getId();

for (const auto &pillar_vote : packet.pillar_votes) {
for (const auto &pillar_vote : packet.pillar_votes_bundle.pillar_votes) {
if (!kConf.genesis.state.hardforks.ficus_hf.isFicusHardfork(pillar_vote->getPeriod())) {
std::ostringstream err_msg;
err_msg << "Synced pillar vote " << pillar_vote->getHash() << ", period " << pillar_vote->getPeriod()
Expand Down
1 change: 1 addition & 0 deletions libraries/types/vote/include/vote/votes_bundle_rlp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PillarVote;
* @{
*/

// TOOD[2865]: move to cpp file
constexpr static size_t kPbftVotesBundleRlpSize{5};

/**
Expand Down

0 comments on commit 61ccc0d

Please sign in to comment.