Skip to content

Commit

Permalink
simplify new packets handlers code
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubFornadel committed Oct 18, 2024
1 parent d10f0e3 commit 7e596c5
Show file tree
Hide file tree
Showing 78 changed files with 1,658 additions and 1,801 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@
namespace taraxa::network::tarcap {

struct DagBlockPacket {
DagBlockPacket() = default;
DagBlockPacket(const DagBlockPacket&) = default;
DagBlockPacket(DagBlockPacket&&) = default;
DagBlockPacket& operator=(const DagBlockPacket&) = default;
DagBlockPacket& operator=(DagBlockPacket&&) = default;
// TODO[2868]: optimize args
DagBlockPacket(const std::vector<std::shared_ptr<Transaction>>& transactions, const DagBlock& dag_block)
: transactions(transactions), dag_block(dag_block) {}

DagBlockPacket(const dev::RLP& packet_rlp) { *this = util::rlp_dec<DagBlockPacket>(packet_rlp); }
dev::bytes encodeRlp() { return util::rlp_enc(*this); }

std::vector<std::shared_ptr<Transaction>> transactions;
DagBlock dag_block;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@
namespace taraxa::network::tarcap {

struct DagSyncPacket {
DagSyncPacket() = default;
DagSyncPacket(const DagSyncPacket&) = default;
DagSyncPacket(DagSyncPacket&&) = default;
DagSyncPacket& operator=(const DagSyncPacket&) = default;
DagSyncPacket& operator=(DagSyncPacket&&) = default;
DagSyncPacket(PbftPeriod request_period, PbftPeriod response_period,
std::vector<std::shared_ptr<Transaction>>&& transactions,
std::vector<std::shared_ptr<DagBlock>>&& dag_blocks)
: request_period(request_period),
response_period(response_period),
transactions(std::move(transactions)),
dag_blocks(std::move(dag_blocks)) {}
DagSyncPacket(const dev::RLP& packet_rlp) { *this = util::rlp_dec<DagSyncPacket>(packet_rlp); }

dev::bytes encodeRlp() { return util::rlp_enc(*this); }

PbftPeriod request_period;
PbftPeriod response_period;
std::vector<std::shared_ptr<Transaction>> transactions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
namespace taraxa::network::tarcap {

struct GetDagSyncPacket {
GetDagSyncPacket() = default;
GetDagSyncPacket(const GetDagSyncPacket&) = default;
GetDagSyncPacket(GetDagSyncPacket&&) = default;
GetDagSyncPacket& operator=(const GetDagSyncPacket&) = default;
GetDagSyncPacket& operator=(GetDagSyncPacket&&) = default;
GetDagSyncPacket(PbftPeriod peer_period, std::vector<blk_hash_t>&& blocks_hashes)
: peer_period(peer_period), blocks_hashes(std::move(blocks_hashes)) {}
GetDagSyncPacket(const dev::RLP& packet_rlp) { *this = util::rlp_dec<GetDagSyncPacket>(packet_rlp); }
dev::bytes encodeRlp() { return util::rlp_enc(*this); }

PbftPeriod peer_period;
std::vector<blk_hash_t> blocks_hashes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
namespace taraxa::network::tarcap {

struct GetNextVotesBundlePacket {
GetNextVotesBundlePacket() = default;
GetNextVotesBundlePacket(const GetNextVotesBundlePacket&) = default;
GetNextVotesBundlePacket(GetNextVotesBundlePacket&&) = default;
GetNextVotesBundlePacket& operator=(const GetNextVotesBundlePacket&) = default;
GetNextVotesBundlePacket& operator=(GetNextVotesBundlePacket&&) = default;

GetNextVotesBundlePacket(const dev::RLP& packet_rlp) { *this = util::rlp_dec<GetNextVotesBundlePacket>(packet_rlp); };
dev::bytes encodeRlp() { return util::rlp_enc(*this); }

PbftPeriod peer_pbft_period;
PbftRound peer_pbft_round;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@
namespace taraxa::network::tarcap {

struct GetPbftSyncPacket {
GetPbftSyncPacket() = default;
GetPbftSyncPacket(const GetPbftSyncPacket&) = default;
GetPbftSyncPacket(GetPbftSyncPacket&&) = default;
GetPbftSyncPacket& operator=(const GetPbftSyncPacket&) = default;
GetPbftSyncPacket& operator=(GetPbftSyncPacket&&) = default;
GetPbftSyncPacket(size_t height_to_sync) : height_to_sync(height_to_sync) {}
GetPbftSyncPacket(const dev::RLP& packet_rlp) { *this = util::rlp_dec<GetPbftSyncPacket>(packet_rlp); }
dev::bytes encodeRlp() { return util::rlp_enc(*this); }

size_t height_to_sync;

RLP_FIELDS_DEFINE_INPLACE(height_to_sync)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@
namespace taraxa::network::tarcap {

struct GetPillarVotesBundlePacket {
GetPillarVotesBundlePacket() = default;
GetPillarVotesBundlePacket(const GetPillarVotesBundlePacket&) = default;
GetPillarVotesBundlePacket(GetPillarVotesBundlePacket&&) = default;
GetPillarVotesBundlePacket& operator=(const GetPillarVotesBundlePacket&) = default;
GetPillarVotesBundlePacket& operator=(GetPillarVotesBundlePacket&&) = default;
GetPillarVotesBundlePacket(PbftPeriod period, blk_hash_t pillar_block_hash)
: period(period), pillar_block_hash(pillar_block_hash) {}
GetPillarVotesBundlePacket(const dev::RLP& packet_rlp) {
*this = util::rlp_dec<GetPillarVotesBundlePacket>(packet_rlp);
}

dev::bytes encodeRlp() { return util::rlp_enc(*this); }

PbftPeriod period;
blk_hash_t pillar_block_hash;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@
namespace taraxa::network::tarcap {

struct PbftSyncPacket {
PbftSyncPacket() = default;
PbftSyncPacket(const PbftSyncPacket&) = default;
PbftSyncPacket(PbftSyncPacket&&) = default;
PbftSyncPacket& operator=(const PbftSyncPacket&) = default;
PbftSyncPacket& operator=(PbftSyncPacket&&) = default;
PbftSyncPacket(bool last_block, PeriodData&& period_data,
std::vector<std::shared_ptr<PbftVote>>&& current_block_cert_votes = {})
: last_block(last_block),
period_data(std::move(period_data)),
current_block_cert_votes(std::move(current_block_cert_votes)) {}
PbftSyncPacket(const dev::RLP& packet_rlp) { *this = util::rlp_dec<PbftSyncPacket>(packet_rlp); };

dev::bytes encodeRlp() { return util::rlp_enc(*this); }

bool last_block;
PeriodData period_data;
// TODO: should it be optional ???
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
namespace taraxa::network::tarcap {

struct PillarVotePacket {
PillarVotePacket() = default;
PillarVotePacket(const PillarVotePacket&) = default;
PillarVotePacket(PillarVotePacket&&) = default;
PillarVotePacket& operator=(const PillarVotePacket&) = default;
PillarVotePacket& operator=(PillarVotePacket&&) = default;
PillarVotePacket(std::shared_ptr<PillarVote> pillar_vote) : pillar_vote(std::move(pillar_vote)) {}
PillarVotePacket(const dev::RLP& packet_rlp) { *this = util::rlp_dec<PillarVotePacket>(packet_rlp); }
dev::bytes encodeRlp() { return util::rlp_enc(*this); }

std::shared_ptr<PillarVote> pillar_vote;

RLP_FIELDS_DEFINE_INPLACE(pillar_vote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,9 @@
namespace taraxa::network::tarcap {

struct PillarVotesBundlePacket {
PillarVotesBundlePacket() = default;
PillarVotesBundlePacket(const PillarVotesBundlePacket&) = default;
PillarVotesBundlePacket(PillarVotesBundlePacket&&) = default;
PillarVotesBundlePacket& operator=(const PillarVotesBundlePacket&) = default;
PillarVotesBundlePacket& operator=(PillarVotesBundlePacket&&) = default;
PillarVotesBundlePacket(std::vector<std::shared_ptr<PillarVote>>&& pillar_votes)
: pillar_votes(std::move(pillar_votes)) {}
PillarVotesBundlePacket(const dev::RLP& packet_rlp) {
*this = util::rlp_dec<PillarVotesBundlePacket>(packet_rlp);
if (pillar_votes.size() == 0 || pillar_votes.size() > kMaxPillarVotesInBundleRlp) {
throw InvalidRlpItemsCountException("PillarVotesBundlePacket", pillar_votes.size(), kMaxPillarVotesInBundleRlp);
}
}
dev::bytes encodeRlp() { return util::rlp_enc(*this); }

// TODO[2870]: optimize rlp size (use custom class), see encodePillarVotesBundleRlp
std::vector<std::shared_ptr<PillarVote>> pillar_votes;

constexpr static size_t kMaxPillarVotesInBundleRlp{250};

RLP_FIELDS_DEFINE_INPLACE(pillar_votes)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace taraxa::network::tarcap {

// TODO: create new version of this packet without manual parsing
struct StatusPacket {
struct InitialData {
uint64_t peer_chain_id;
Expand All @@ -17,21 +16,6 @@ struct StatusPacket {
is_light_node, node_history)
};

StatusPacket() = default;
StatusPacket(const StatusPacket&) = default;
StatusPacket(StatusPacket&&) = default;
StatusPacket& operator=(const StatusPacket&) = default;
StatusPacket& operator=(StatusPacket&&) = default;
StatusPacket(PbftPeriod peer_pbft_chain_size, PbftRound peer_pbft_round, uint64_t peer_dag_level, bool peer_syncing,
std::optional<InitialData> initial_data = {})
: peer_pbft_chain_size(peer_pbft_chain_size),
peer_pbft_round(peer_pbft_round),
peer_dag_level(peer_dag_level),
peer_syncing(peer_syncing),
initial_data(std::move(initial_data)) {}
StatusPacket(const dev::RLP& packet_rlp) { *this = util::rlp_dec<StatusPacket>(packet_rlp); }
dev::bytes encodeRlp() { return util::rlp_enc(*this); }

PbftPeriod peer_pbft_chain_size;
PbftRound peer_pbft_round;
uint64_t peer_dag_level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,11 @@
namespace taraxa::network::tarcap {

struct TransactionPacket {
TransactionPacket() = default;
TransactionPacket(const TransactionPacket&) = default;
TransactionPacket(TransactionPacket&&) = default;
TransactionPacket& operator=(const TransactionPacket&) = default;
TransactionPacket& operator=(TransactionPacket&&) = default;
// TODO[2868]: optimize ctor
TransactionPacket(const std::vector<std::shared_ptr<Transaction>>& transactions) : transactions(transactions) {}
TransactionPacket(const dev::RLP& packet_rlp) {
*this = util::rlp_dec<TransactionPacket>(packet_rlp);
if (transactions.size() > kMaxTransactionsInPacket) {
throw InvalidRlpItemsCountException("TransactionPacket", transactions.size(), kMaxTransactionsInPacket);
}
}
dev::bytes encodeRlp() { return util::rlp_enc(*this); }

std::vector<std::shared_ptr<Transaction>> transactions;

constexpr static uint32_t kMaxTransactionsInPacket{500};

RLP_FIELDS_DEFINE_INPLACE(transactions)

constexpr static uint32_t kMaxTransactionsInPacket{500};
};

} // namespace taraxa::network::tarcap
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ struct VotePacket {
RLP_FIELDS_DEFINE_INPLACE(pbft_block, peer_chain_size)
};

VotePacket() = default;
VotePacket(const VotePacket&) = default;
VotePacket(VotePacket&&) = default;
VotePacket& operator=(const VotePacket&) = default;
VotePacket& operator=(VotePacket&&) = default;
VotePacket(std::shared_ptr<PbftVote> vote, std::optional<OptionalData> optional_data = {})
: vote(std::move(vote)), optional_data(std::move(optional_data)) {}
VotePacket(const dev::RLP& packet_rlp) { *this = util::rlp_dec<VotePacket>(packet_rlp); };
dev::bytes encodeRlp() { return util::rlp_enc(*this); }

std::shared_ptr<PbftVote> vote;
std::optional<OptionalData> optional_data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@
namespace taraxa::network::tarcap {

struct VotesBundlePacket {
VotesBundlePacket() = default;
VotesBundlePacket(const VotesBundlePacket&) = default;
VotesBundlePacket(VotesBundlePacket&&) = default;
VotesBundlePacket& operator=(const VotesBundlePacket&) = default;
VotesBundlePacket& operator=(VotesBundlePacket&&) = default;
VotesBundlePacket(std::vector<std::shared_ptr<PbftVote>>&& votes) : votes(std::move(votes)) {}
VotesBundlePacket(const dev::RLP& packet_rlp) {
*this = util::rlp_dec<VotesBundlePacket>(packet_rlp);
if (votes.size() == 0 || votes.size() > kMaxVotesInBundleRlp) {
throw InvalidRlpItemsCountException("VotesBundlePacket", votes.size(), kMaxVotesInBundleRlp);
}
};
dev::bytes encodeRlp() { return util::rlp_enc(*this); }

// TODO[2870]: Create votes bundles class
// blk_hash_t votes_bundle_block_hash;
// PbftPeriod votes_bundle_pbft_period;
Expand All @@ -28,8 +14,6 @@ struct VotesBundlePacket {

std::vector<std::shared_ptr<PbftVote>> votes;

constexpr static size_t kMaxVotesInBundleRlp{1000};

// RLP_FIELDS_DEFINE_INPLACE(votes_bundle_block_hash, votes_bundle_pbft_period, votes_bundle_pbft_round,
// votes_bundle_votes_step, votes)
RLP_FIELDS_DEFINE_INPLACE(votes)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7e596c5

Please sign in to comment.