TARAXA
Loading...
Searching...
No Matches
pbft_vote.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <json/value.h>
4
7#include "vote.hpp"
8#include "vrf_sortition.hpp"
9
10namespace taraxa {
11
20class PbftVote : public Vote {
21 public:
23 PbftVote() = default;
24 PbftVote(secret_t const& node_sk, VrfPbftSortition vrf_sortition, blk_hash_t const& block_hash);
25
26 // Ctor for optimized rlp vote objects - only signature and vrf proof are in the rlp
27 explicit PbftVote(const blk_hash_t& block_hash, PbftPeriod period, PbftRound round, PbftStep step,
28 dev::RLP const& rlp);
29
30 // Ctors for full rlp vote objects - all data are encoded in the rlp
31 explicit PbftVote(dev::RLP const& rlp);
32 explicit PbftVote(bytes const& rlp);
33
34 bool operator==(const PbftVote& other) const;
35
40 bool verifyVrfSortition(const vrf_pk_t& pk, bool strict) const;
41
46 const VrfPbftSortition& getVrfSortition() const;
47
53
59
64 PbftVoteTypes getType() const;
65
70 PbftPeriod getPeriod() const;
71
76 PbftRound getRound() const;
77
82 PbftStep getStep() const;
83
90 bytes rlp(bool inc_sig = true, bool inc_weight = false) const;
91
98 bytes optimizedRlp() const;
99
107 uint64_t calculateWeight(uint64_t stake, double dpos_total_votes_count, double threshold) const;
108
113 std::optional<uint64_t> getWeight() const;
114
115 friend std::ostream& operator<<(std::ostream& strm, PbftVote const& vote) {
116 strm << "[Vote] " << std::endl;
117 strm << " vote_hash: " << vote.vote_hash_ << std::endl;
118 strm << " voter: " << vote.getVoter() << std::endl;
119 strm << " vote_signature: " << vote.vote_signature_ << std::endl;
120 strm << " blockhash: " << vote.block_hash_ << std::endl;
121 if (vote.weight_) strm << " weight: " << vote.weight_.value() << std::endl;
122 strm << " vrf_sortition: " << vote.vrf_sortition_ << std::endl;
123 return strm;
124 }
125
130 Json::Value toJSON() const;
131
133
134 private:
140 vote_hash_t sha3(bool inc_sig) const override;
141
143 mutable std::optional<uint64_t> weight_;
144};
145
148} // namespace taraxa
Definition RLP.h:56
#define HAS_RLP_FIELDS
Definition encoding_rlp.hpp:208
VrfPbftSortition vrf_sortition_
Definition pbft_vote.hpp:142
bool verifyVrfSortition(const vrf_pk_t &pk, bool strict) const
Verify VRF sortition.
Definition pbft_vote.cpp:102
bytes rlp(bool inc_sig=true, bool inc_weight=false) const
Recursive Length Prefix.
Definition pbft_vote.cpp:57
bytes optimizedRlp() const
Optimized Recursive Length Prefix.
Definition pbft_vote.cpp:81
vote_hash_t sha3(bool inc_sig) const override
Secure Hash Algorithm 3.
Definition pbft_vote.cpp:126
Json::Value toJSON() const
Get vote in JSON representation.
Definition pbft_vote.cpp:89
std::optional< uint64_t > weight_
Definition pbft_vote.hpp:143
PbftStep getStep() const
Get vote PBFT step.
Definition pbft_vote.cpp:124
friend std::ostream & operator<<(std::ostream &strm, PbftVote const &vote)
Definition pbft_vote.hpp:115
const VrfPbftSortition & getVrfSortition() const
Get VRF sortition.
Definition pbft_vote.cpp:104
const public_t & getVoter() const
Get voter public key.
Definition vote.cpp:20
std::optional< uint64_t > getWeight() const
Get vote weight.
Definition pbft_vote.cpp:114
uint64_t calculateWeight(uint64_t stake, double dpos_total_votes_count, double threshold) const
Calculate vote weight.
Definition pbft_vote.cpp:108
PbftVote()=default
PbftVoteTypes getType() const
Get vote type.
Definition pbft_vote.cpp:118
PbftPeriod getPeriod() const
Get vote PBFT period.
Definition pbft_vote.cpp:120
PbftRound getRound() const
Get vote PBFT round.
Definition pbft_vote.cpp:122
bool operator==(const PbftVote &other) const
Definition pbft_vote.cpp:54
const vrf_wrapper::vrf_proof_t & getSortitionProof() const
Get VRF sortition proof.
Definition pbft_vote.cpp:106
vote_hash_t vote_hash_
Definition vote.hpp:75
blk_hash_t block_hash_
Definition vote.hpp:72
sig_t vote_signature_
Definition vote.hpp:73
const vrf_wrapper::vrf_output_t & getCredential() const
Get VRF sortition output.
Definition pbft_vote.cpp:116
PbftVote class is a vote class that includes vote hash, vote on PBFT block hash, vote signature,...
Definition pbft_vote.hpp:20
Vote class is a vote class that includes vote hash, vote on PBFT block hash, vote signature,...
Definition vote.hpp:15
VrfPbftSortition class used for doing VRF sortition to place a vote or to propose a new PBFT block.
Definition vrf_sortition.hpp:76
PbftVoteTypes
Definition vrf_sortition.hpp:21
dev::FixedHash< crypto_vrf_PUBLICKEYBYTES > vrf_pk_t
Definition vrf_wrapper.hpp:11
Definition app.hpp:16
uint32_t PbftStep
Definition types.hpp:26
std::vector< byte > bytes
Definition types.hpp:53
uint32_t PbftRound
Definition types.hpp:25
EthBlockNumber PbftPeriod
Definition types.hpp:24