TARAXA
ext_votes_packet_handler.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "packet_handler.hpp"
4 
5 namespace taraxa {
6 class PbftVote;
7 class PbftManager;
8 class PbftChain;
9 class PbftBlock;
10 class VoteManager;
11 class SlashingManager;
12 } // namespace taraxa
13 
14 namespace taraxa::network::tarcap {
15 
21  public:
22  ExtVotesPacketHandler(const FullNodeConfig& conf, std::shared_ptr<PeersState> peers_state,
23  std::shared_ptr<TimePeriodPacketsStats> packets_stats, std::shared_ptr<PbftManager> pbft_mgr,
24  std::shared_ptr<PbftChain> pbft_chain, std::shared_ptr<VoteManager> vote_mgr,
25  std::shared_ptr<SlashingManager> slashing_manager, const addr_t& node_addr,
26  const std::string& log_channel_name);
27 
28  virtual ~ExtVotesPacketHandler() = default;
33 
43  bool processVote(const std::shared_ptr<PbftVote>& vote, const std::shared_ptr<PbftBlock>& pbft_block,
44  const std::shared_ptr<TaraxaPeer>& peer, bool validate_max_round_step);
45 
51  bool isPbftRelevantVote(const std::shared_ptr<PbftVote>& vote) const;
52 
53  virtual void sendPbftVotesBundle(const std::shared_ptr<TaraxaPeer>& peer,
54  std::vector<std::shared_ptr<PbftVote>>&& votes);
55 
56  private:
65  std::pair<bool, std::string> validateVotePeriodRoundStep(const std::shared_ptr<PbftVote>& vote,
66  const std::shared_ptr<TaraxaPeer>& peer,
67  bool validate_max_round_step);
68 
76  bool validateVoteAndBlock(const std::shared_ptr<PbftVote>& vote, const std::shared_ptr<PbftBlock>& pbft_block) const;
77 
78  protected:
79  constexpr static size_t kMaxVotesInBundleRlp{1000};
80  constexpr static std::chrono::seconds kSyncRequestInterval = std::chrono::seconds(10);
81 
84 
85  std::shared_ptr<PbftManager> pbft_mgr_;
86  std::shared_ptr<PbftChain> pbft_chain_;
87  std::shared_ptr<VoteManager> vote_mgr_;
88  std::shared_ptr<SlashingManager> slashing_manager_;
89 };
90 
91 } // 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:20
std::chrono::system_clock::time_point last_pbft_block_sync_request_time_
Definition: ext_votes_packet_handler.hpp:83
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:70
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:151
ExtVotesPacketHandler(const ExtVotesPacketHandler &)=delete
constexpr static size_t kMaxVotesInBundleRlp
Definition: ext_votes_packet_handler.hpp:79
ExtVotesPacketHandler & operator=(const ExtVotesPacketHandler &)=delete
ExtVotesPacketHandler(ExtVotesPacketHandler &&)=delete
std::chrono::system_clock::time_point last_votes_sync_request_time_
Definition: ext_votes_packet_handler.hpp:82
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:161
ExtVotesPacketHandler(const FullNodeConfig &conf, std::shared_ptr< PeersState > peers_state, std::shared_ptr< TimePeriodPacketsStats > packets_stats, std::shared_ptr< PbftManager > pbft_mgr, std::shared_ptr< PbftChain > pbft_chain, std::shared_ptr< VoteManager > vote_mgr, std::shared_ptr< SlashingManager > slashing_manager, const addr_t &node_addr, const std::string &log_channel_name)
Definition: ext_votes_packet_handler.cpp:11
std::shared_ptr< PbftChain > pbft_chain_
Definition: ext_votes_packet_handler.hpp:86
std::shared_ptr< PbftManager > pbft_mgr_
Definition: ext_votes_packet_handler.hpp:85
ExtVotesPacketHandler & operator=(ExtVotesPacketHandler &&)=delete
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:26
constexpr static std::chrono::seconds kSyncRequestInterval
Definition: ext_votes_packet_handler.hpp:80
std::shared_ptr< VoteManager > vote_mgr_
Definition: ext_votes_packet_handler.hpp:87
virtual void sendPbftVotesBundle(const std::shared_ptr< TaraxaPeer > &peer, std::vector< std::shared_ptr< PbftVote >> &&votes)
Definition: ext_votes_packet_handler.cpp:179
std::shared_ptr< SlashingManager > slashing_manager_
Definition: ext_votes_packet_handler.hpp:88
Packet handler base class that consists of shared state and some commonly used functions.
Definition: packet_handler.hpp:25
std::chrono::system_clock::time_point time_point
Definition: watches.hpp:12
Definition: vote_manager.hpp:23
Definition: config.hpp:8
Definition: config.hpp:24