TARAXA
Loading...
Searching...
No Matches
ext_votes_packet_handler.hpp
Go to the documentation of this file.
1#pragma once
2
6#include "packet_handler.hpp"
8#include "vote/pbft_vote.hpp"
11
13
19 public:
20 ExtVotesPacketHandler(const FullNodeConfig& conf, std::shared_ptr<PeersState> peers_state,
21 std::shared_ptr<TimePeriodPacketsStats> packets_stats, std::shared_ptr<PbftManager> pbft_mgr,
22 std::shared_ptr<PbftChain> pbft_chain, std::shared_ptr<VoteManager> vote_mgr,
23 std::shared_ptr<SlashingManager> slashing_manager, const addr_t& node_addr,
24 const std::string& log_channel_name);
25
26 virtual ~ExtVotesPacketHandler() = default;
31
41 bool processVote(const std::shared_ptr<PbftVote>& vote, const std::shared_ptr<PbftBlock>& pbft_block,
42 const std::shared_ptr<TaraxaPeer>& peer, bool validate_max_round_step);
43
49 bool isPbftRelevantVote(const std::shared_ptr<PbftVote>& vote) const;
50
51 void requestPbftNextVotesAtPeriodRound(const dev::p2p::NodeID& peerID, PbftPeriod pbft_period, PbftRound pbft_round);
52
53 private:
62 std::pair<bool, std::string> validateVotePeriodRoundStep(const std::shared_ptr<PbftVote>& vote,
63 const std::shared_ptr<TaraxaPeer>& peer,
64 bool validate_max_round_step);
65
73 bool validateVoteAndBlock(const std::shared_ptr<PbftVote>& vote, const std::shared_ptr<PbftBlock>& pbft_block) const;
74
75 protected:
76 constexpr static size_t kMaxVotesInBundleRlp{1000};
77 constexpr static std::chrono::seconds kSyncRequestInterval = std::chrono::seconds(10);
78
79 mutable std::chrono::system_clock::time_point last_votes_sync_request_time_;
80 mutable std::chrono::system_clock::time_point last_pbft_block_sync_request_time_;
81
82 std::shared_ptr<PbftManager> pbft_mgr_;
83 std::shared_ptr<PbftChain> pbft_chain_;
84 std::shared_ptr<VoteManager> vote_mgr_;
85 std::shared_ptr<SlashingManager> slashing_manager_;
86};
87
88} // namespace taraxa::network::tarcap
Definition FixedHash.h:35
ExtVotesPacketHandler is extended abstract PacketHandler with added functions that are used in packet...
Definition ext_votes_packet_handler.hpp:18
std::chrono::system_clock::time_point last_pbft_block_sync_request_time_
Definition ext_votes_packet_handler.hpp:80
std::pair< bool, std::string > validateVotePeriodRoundStep(const std::shared_ptr< PbftVote > &vote, const std::shared_ptr< TaraxaPeer > &peer, bool validate_max_round_step)
Validates vote period, round and step against max values from config.
Definition ext_votes_packet_handler.cpp:72
bool validateVoteAndBlock(const std::shared_ptr< PbftVote > &vote, const std::shared_ptr< PbftBlock > &pbft_block) const
Validates provided vote if voted value == provided block.
Definition ext_votes_packet_handler.cpp:154
ExtVotesPacketHandler & operator=(const ExtVotesPacketHandler &)=delete
ExtVotesPacketHandler(const ExtVotesPacketHandler &)=delete
static constexpr std::chrono::seconds kSyncRequestInterval
Definition ext_votes_packet_handler.hpp:77
static constexpr size_t kMaxVotesInBundleRlp
Definition ext_votes_packet_handler.hpp:76
void requestPbftNextVotesAtPeriodRound(const dev::p2p::NodeID &peerID, PbftPeriod pbft_period, PbftRound pbft_round)
Definition ext_votes_packet_handler.cpp:189
ExtVotesPacketHandler(ExtVotesPacketHandler &&)=delete
std::chrono::system_clock::time_point last_votes_sync_request_time_
Definition ext_votes_packet_handler.hpp:79
bool isPbftRelevantVote(const std::shared_ptr< PbftVote > &vote) const
Checks is vote is relevant for current pbft state in terms of period, round and type.
Definition ext_votes_packet_handler.cpp:171
std::shared_ptr< PbftChain > pbft_chain_
Definition ext_votes_packet_handler.hpp:83
ExtVotesPacketHandler & operator=(ExtVotesPacketHandler &&)=delete
std::shared_ptr< PbftManager > pbft_mgr_
Definition ext_votes_packet_handler.hpp:82
bool processVote(const std::shared_ptr< PbftVote > &vote, const std::shared_ptr< PbftBlock > &pbft_block, const std::shared_ptr< TaraxaPeer > &peer, bool validate_max_round_step)
Process vote.
Definition ext_votes_packet_handler.cpp:27
std::shared_ptr< VoteManager > vote_mgr_
Definition ext_votes_packet_handler.hpp:84
std::shared_ptr< SlashingManager > slashing_manager_
Definition ext_votes_packet_handler.hpp:85
Packet handler base class that consists of shared state and some commonly used functions.
Definition packet_handler.hpp:33
Definition vote_manager.hpp:23
uint32_t PbftRound
Definition types.hpp:25
EthBlockNumber PbftPeriod
Definition types.hpp:24
Definition config.hpp:40