TARAXA
Vote

Classes

class  taraxa::VoteManager
 VoteManager class manage votes for PBFT consensus. More...
 
class  taraxa::PbftVote
 PbftVote class is a vote class that includes vote hash, vote on PBFT block hash, vote signature, VRF sortition, voter public key, voter address, and vote weight. More...
 
class  taraxa::PillarVote
 PillarVote class. More...
 
class  taraxa::Vote
 Vote class is a vote class that includes vote hash, vote on PBFT block hash, vote signature, VRF sortition, voter public key, voter address, and vote weight. More...
 
class  taraxa::VrfPbftMsg
 VrfPbftMsg class uses PBFT period, round and step to generate a message for doing VRF sortition. More...
 
class  taraxa::VrfPbftSortition
 VrfPbftSortition class used for doing VRF sortition to place a vote or to propose a new PBFT block. More...
 

Enumerations

enum class  taraxa::PbftVoteTypes : uint8_t {
  taraxa::invalid_vote = 0 , taraxa::propose_vote , taraxa::soft_vote , taraxa::cert_vote ,
  taraxa::next_vote
}
 

Functions

dev::bytes taraxa::encodePbftVotesBundleRlp (const std::vector< std::shared_ptr< PbftVote >> &votes)
 Encodes pbft votes into optimized votes bundle rlp. More...
 
std::vector< std::shared_ptr< PbftVote > > taraxa::decodePbftVotesBundleRlp (const dev::RLP &votes_bundle_rlp)
 Decodes pbft votes from optimized votes bundle rlp. More...
 
dev::bytes taraxa::encodePillarVotesBundleRlp (const std::vector< std::shared_ptr< PillarVote >> &votes)
 Encodes pillar votes into optimized votes bundle rlp. More...
 
std::vector< std::shared_ptr< PillarVote > > taraxa::decodePillarVotesBundleRlp (const dev::RLP &votes_bundle_rlp)
 Decodes pillar votes from optimized votes bundle rlp. More...
 
dev::h256 taraxa::getVoterIndexHash (const vrf_wrapper::vrf_output_t &vrf, const public_t &address, uint64_t index=0)
 Get a hash number of combining VRF output, voter address, and vote weight index. More...
 

Variables

constexpr static size_t taraxa::kPbftVotesBundleRlpSize {5}
 
constexpr static size_t taraxa::kPillarVotesBundleRlpSize {3}
 

Detailed Description


Class Documentation

◆ taraxa::VoteManager

class taraxa::VoteManager

VoteManager class manage votes for PBFT consensus.

Collaboration diagram for taraxa::VoteManager:

Public Member Functions

 VoteManager (const FullNodeConfig &config, std::shared_ptr< DbStorage > db, std::shared_ptr< PbftChain > pbft_chain, std::shared_ptr< final_chain::FinalChain > final_chain, std::shared_ptr< KeyManager > key_manager, std::shared_ptr< SlashingManager > slashing_manager)
 
 ~VoteManager ()=default
 
 VoteManager (const VoteManager &)=delete
 
 VoteManager (VoteManager &&)=delete
 
VoteManageroperator= (const VoteManager &)=delete
 
VoteManageroperator= (VoteManager &&)=delete
 
void setNetwork (std::weak_ptr< Network > network)
 Set network as a weak pointer. More...
 
bool addVerifiedVote (const std::shared_ptr< PbftVote > &vote)
 Add a vote to the verified votes map. More...
 
bool voteInVerifiedMap (std::shared_ptr< PbftVote > const &vote) const
 Check if the vote has been in the verified votes map. More...
 
std::pair< bool, std::shared_ptr< PbftVote > > isUniqueVote (const std::shared_ptr< PbftVote > &vote) const
 
std::vector< std::shared_ptr< PbftVote > > getVerifiedVotes () const
 Get all verified votes. More...
 
uint64_t getVerifiedVotesSize () const
 Get the total size of all verified votes. More...
 
void cleanupVotesByPeriod (PbftPeriod pbft_period)
 Cleanup votes for previous PBFT periods. More...
 
std::vector< std::shared_ptr< PbftVote > > getProposalVotes (PbftPeriod period, PbftRound round) const
 Get all verified votes in proposal vote type for the current PBFT round. More...
 
std::optional< PbftRounddetermineNewRound (PbftPeriod current_pbft_period, PbftRound current_pbft_round)
 Check if there are enough next voting type votes to set PBFT to a forward round within period. More...
 
void resetRewardVotes (PbftPeriod period, PbftRound round, PbftStep step, const blk_hash_t &block_hash, Batch &batch)
 Replace current reward votes with new period, round & block hash based on vote. More...
 
std::pair< bool, std::vector< std::shared_ptr< PbftVote > > > checkRewardVotes (const std::shared_ptr< PbftBlock > &pbft_block, bool copy_votes)
 Check reward votes for specified pbft block. More...
 
std::vector< std::shared_ptr< PbftVote > > getRewardVotes ()
 Get reward votes with the round during which was the previous block pushed. More...
 
PbftPeriod getRewardVotesPbftBlockPeriod ()
 Get current reward votes pbft block period. More...
 
void saveOwnVerifiedVote (const std::shared_ptr< PbftVote > &vote)
 Saves own verified vote into memory and db. More...
 
std::vector< std::shared_ptr< PbftVote > > getOwnVerifiedVotes ()
 
void clearOwnVerifiedVotes (Batch &write_batch)
 Clear own verified votes. More...
 
std::shared_ptr< PbftVotegenerateVoteWithWeight (const blk_hash_t &blockhash, PbftVoteTypes vote_type, PbftPeriod period, PbftRound round, PbftStep step)
 Place a vote, save it in the verified votes queue, and gossip to peers. More...
 
std::shared_ptr< PbftVotegenerateVote (const blk_hash_t &blockhash, PbftVoteTypes type, PbftPeriod period, PbftRound round, PbftStep step)
 Generate a vote. More...
 
std::pair< bool, std::string > validateVote (const std::shared_ptr< PbftVote > &vote, bool strict=true) const
 Validates vote. More...
 
std::optional< uint64_t > getPbftTwoTPlusOne (PbftPeriod pbft_period, PbftVoteTypes vote_type) const
 Get 2t+1. 2t+1 is 2/3 of PBFT sortition threshold and plus 1 for a specific period. More...
 
bool voteAlreadyValidated (const vote_hash_t &vote_hash) const
 
bool genAndValidateVrfSortition (PbftPeriod pbft_period, PbftRound pbft_round) const
 Generates vrf sortition and calculates its weight. More...
 
std::optional< blk_hash_tgetTwoTPlusOneVotedBlock (PbftPeriod period, PbftRound round, TwoTPlusOneVotedBlockType type) const
 Get 2t+1 voted block for specific period, round and type, e.g. soft/cert/next voted block. More...
 
std::vector< std::shared_ptr< PbftVote > > getTwoTPlusOneVotedBlockVotes (PbftPeriod period, PbftRound round, TwoTPlusOneVotedBlockType type) const
 
void setCurrentPbftPeriodAndRound (PbftPeriod pbft_period, PbftRound pbft_round)
 Sets current pbft period & round. It also checks if we dont already have 2t+1 vote bundles(pf any type) for the provided period & round and if so, it saves these bundles into db. More...
 
PbftStep getNetworkTplusOneNextVotingStep (PbftPeriod period, PbftRound round) const
 Returns greatest step (in specified period & round), for which there is at least t+1 voting power from all nodes. More...
 

Private Member Functions

bool isValidRewardVote (const std::shared_ptr< PbftVote > &vote) const
 
std::pair< bool, std::shared_ptr< PbftVote > > insertUniqueVote (const std::shared_ptr< PbftVote > &vote)
 Inserts unique vote. More...
 
uint64_t getPbftSortitionThreshold (uint64_t total_dpos_votes_count, PbftVoteTypes vote_type) const
 Get PBFT sortition threshold for specific period. More...
 

Private Attributes

const addr_t kNodeAddr
 
const PbftConfigkPbftConfig
 
const vrf_wrapper::vrf_sk_t kVrfSk
 
const secret_t kNodeSk
 
const dev::Public kNodePub
 
std::shared_ptr< DbStoragedb_
 
std::shared_ptr< PbftChainpbft_chain_
 
std::shared_ptr< final_chain::FinalChainfinal_chain_
 
std::shared_ptr< KeyManagerkey_manager_
 
std::weak_ptr< Networknetwork_
 
std::shared_ptr< SlashingManagerslashing_manager_
 
std::atomic< PbftPeriodcurrent_pbft_period_ {0}
 
std::atomic< PbftRoundcurrent_pbft_round_ {0}
 
std::map< PbftPeriod, std::map< PbftRound, VerifiedVotes > > verified_votes_
 
std::shared_mutex verified_votes_access_
 
blk_hash_t reward_votes_block_hash_
 
PbftRound reward_votes_period_
 
PbftRound reward_votes_round_
 
std::vector< vote_hash_textra_reward_votes_
 
std::shared_mutex reward_votes_info_mutex_
 
std::vector< std::shared_ptr< PbftVote > > own_verified_votes_
 
std::unordered_map< PbftVoteTypes, std::pair< PbftPeriod, uint64_t > > current_two_t_plus_one_
 
std::shared_mutex current_two_t_plus_one_mutex_
 
ExpirationCache< vote_hash_talready_validated_votes_
 

Constructor & Destructor Documentation

◆ VoteManager() [1/3]

taraxa::VoteManager::VoteManager ( const FullNodeConfig config,
std::shared_ptr< DbStorage db,
std::shared_ptr< PbftChain pbft_chain,
std::shared_ptr< final_chain::FinalChain final_chain,
std::shared_ptr< KeyManager key_manager,
std::shared_ptr< SlashingManager slashing_manager 
)

◆ ~VoteManager()

taraxa::VoteManager::~VoteManager ( )
default

◆ VoteManager() [2/3]

taraxa::VoteManager::VoteManager ( const VoteManager )
delete

◆ VoteManager() [3/3]

taraxa::VoteManager::VoteManager ( VoteManager &&  )
delete

Member Function Documentation

◆ addVerifiedVote()

bool taraxa::VoteManager::addVerifiedVote ( const std::shared_ptr< PbftVote > &  vote)

Add a vote to the verified votes map.

Parameters
votevote
Returns
true if vote was successfully added, otherwise false

◆ checkRewardVotes()

std::pair< bool, std::vector< std::shared_ptr< PbftVote > > > taraxa::VoteManager::checkRewardVotes ( const std::shared_ptr< PbftBlock > &  pbft_block,
bool  copy_votes 
)

Check reward votes for specified pbft block.

Parameters
pbft_block
copy_votes- if set to true, votes are copied and returned, otherwise votes are just checked if present
Returns
<true, votes> - votes are empty in case copy_votes is set to false

◆ cleanupVotesByPeriod()

void taraxa::VoteManager::cleanupVotesByPeriod ( PbftPeriod  pbft_period)

Cleanup votes for previous PBFT periods.

Parameters
pbft_periodcurrent PBFT period

◆ clearOwnVerifiedVotes()

void taraxa::VoteManager::clearOwnVerifiedVotes ( Batch write_batch)

Clear own verified votes.

Parameters
write_batch

◆ determineNewRound()

std::optional< PbftRound > taraxa::VoteManager::determineNewRound ( PbftPeriod  current_pbft_period,
PbftRound  current_pbft_round 
)

Check if there are enough next voting type votes to set PBFT to a forward round within period.

Parameters
current_pbft_periodcurrent pbft period
current_pbft_roundcurrent pbft round
Returns
optional<new round> if there is enough next votes from prior round, otherwise returns empty optional

◆ genAndValidateVrfSortition()

bool taraxa::VoteManager::genAndValidateVrfSortition ( PbftPeriod  pbft_period,
PbftRound  pbft_round 
) const

Generates vrf sortition and calculates its weight.

Returns
true if sortition weight > 0, otherwise false

◆ generateVote()

std::shared_ptr< PbftVote > taraxa::VoteManager::generateVote ( const blk_hash_t blockhash,
PbftVoteTypes  type,
PbftPeriod  period,
PbftRound  round,
PbftStep  step 
)

Generate a vote.

Parameters
blockhashvote on PBFT block hash
typevote type
periodPBFT period
roundPBFT round
stepPBFT step
Returns
vote

◆ generateVoteWithWeight()

std::shared_ptr< PbftVote > taraxa::VoteManager::generateVoteWithWeight ( const blk_hash_t blockhash,
PbftVoteTypes  vote_type,
PbftPeriod  period,
PbftRound  round,
PbftStep  step 
)

Place a vote, save it in the verified votes queue, and gossip to peers.

Parameters
blockhashvote on PBFT block hash
vote_typevote type
periodPBFT period
roundPBFT round
stepPBFT step
stepPBFT step

◆ getNetworkTplusOneNextVotingStep()

PbftStep taraxa::VoteManager::getNetworkTplusOneNextVotingStep ( PbftPeriod  period,
PbftRound  round 
) const

Returns greatest step (in specified period & round), for which there is at least t+1 voting power from all nodes.

Note
It is used for triggering lambda exponential backoff
Parameters
period
round
Returns
greatest network 2t+1 next voting step

◆ getOwnVerifiedVotes()

std::vector< std::shared_ptr< PbftVote > > taraxa::VoteManager::getOwnVerifiedVotes ( )
Returns
all own verified votes

◆ getPbftSortitionThreshold()

uint64_t taraxa::VoteManager::getPbftSortitionThreshold ( uint64_t  total_dpos_votes_count,
PbftVoteTypes  vote_type 
) const
private

Get PBFT sortition threshold for specific period.

Parameters
total_dpos_votes_counttotal votes count
vote_typevote type
Returns
PBFT sortition threshold

◆ getPbftTwoTPlusOne()

std::optional< uint64_t > taraxa::VoteManager::getPbftTwoTPlusOne ( PbftPeriod  pbft_period,
PbftVoteTypes  vote_type 
) const

Get 2t+1. 2t+1 is 2/3 of PBFT sortition threshold and plus 1 for a specific period.

Parameters
pbft_periodpbft period
vote_typevote type, for which we get 2t+1
Returns
PBFT 2T + 1 if successful, otherwise (due to non-existent data for pbft_period) empty optional

◆ getProposalVotes()

std::vector< std::shared_ptr< PbftVote > > taraxa::VoteManager::getProposalVotes ( PbftPeriod  period,
PbftRound  round 
) const

Get all verified votes in proposal vote type for the current PBFT round.

Parameters
periodnew PBFT period (period == chain_size + 1)
roundcurrent PBFT round
Returns
all verified votes in proposal vote type for the current PBFT round

◆ getRewardVotes()

std::vector< std::shared_ptr< PbftVote > > taraxa::VoteManager::getRewardVotes ( )

Get reward votes with the round during which was the previous block pushed.

Returns
vector of reward votes

◆ getRewardVotesPbftBlockPeriod()

PbftPeriod taraxa::VoteManager::getRewardVotesPbftBlockPeriod ( )

Get current reward votes pbft block period.

Returns
period

◆ getTwoTPlusOneVotedBlock()

std::optional< blk_hash_t > taraxa::VoteManager::getTwoTPlusOneVotedBlock ( PbftPeriod  period,
PbftRound  round,
TwoTPlusOneVotedBlockType  type 
) const

Get 2t+1 voted block for specific period, round and type, e.g. soft/cert/next voted block.

Parameters
period
round
votes_type
Returns
empty optional if no 2t+1 voted block was found, otherwise initialized optional with block hash

◆ getTwoTPlusOneVotedBlockVotes()

std::vector< std::shared_ptr< PbftVote > > taraxa::VoteManager::getTwoTPlusOneVotedBlockVotes ( PbftPeriod  period,
PbftRound  round,
TwoTPlusOneVotedBlockType  type 
) const

Get 2t+1 voted block votes for specific period, round and type, e.g. soft/cert/next voted block

Parameters
period
round
type
Returns
vector of votes if 2t+1 voted block votes found, otherwise empty vector

◆ getVerifiedVotes()

std::vector< std::shared_ptr< PbftVote > > taraxa::VoteManager::getVerifiedVotes ( ) const

Get all verified votes.

Returns
all verified votes

◆ getVerifiedVotesSize()

uint64_t taraxa::VoteManager::getVerifiedVotesSize ( ) const

Get the total size of all verified votes.

Returns
the total size of all verified votes

◆ insertUniqueVote()

std::pair< bool, std::shared_ptr< PbftVote > > taraxa::VoteManager::insertUniqueVote ( const std::shared_ptr< PbftVote > &  vote)
private

Inserts unique vote.

Parameters
vote
Returns
<true, nullptr> if vote is unique per round & step & voter, otherwise <false, existing vote>

◆ isUniqueVote()

std::pair< bool, std::shared_ptr< PbftVote > > taraxa::VoteManager::isUniqueVote ( const std::shared_ptr< PbftVote > &  vote) const
Parameters
vote
Returns
<true, nullptr> if vote is unique per round & step & voter, otherwise <false, existing vote>

◆ isValidRewardVote()

bool taraxa::VoteManager::isValidRewardVote ( const std::shared_ptr< PbftVote > &  vote) const
private
Parameters
vote
Returns
true if vote is valid potential reward vote

◆ operator=() [1/2]

VoteManager& taraxa::VoteManager::operator= ( const VoteManager )
delete

◆ operator=() [2/2]

VoteManager& taraxa::VoteManager::operator= ( VoteManager &&  )
delete

◆ resetRewardVotes()

void taraxa::VoteManager::resetRewardVotes ( PbftPeriod  period,
PbftRound  round,
PbftStep  step,
const blk_hash_t block_hash,
Batch batch 
)

Replace current reward votes with new period, round & block hash based on vote.

Parameters
period
round
step
block_hash
batch

◆ saveOwnVerifiedVote()

void taraxa::VoteManager::saveOwnVerifiedVote ( const std::shared_ptr< PbftVote > &  vote)

Saves own verified vote into memory and db.

Parameters
vote

◆ setCurrentPbftPeriodAndRound()

void taraxa::VoteManager::setCurrentPbftPeriodAndRound ( PbftPeriod  pbft_period,
PbftRound  pbft_round 
)

Sets current pbft period & round. It also checks if we dont already have 2t+1 vote bundles(pf any type) for the provided period & round and if so, it saves these bundles into db.

Parameters
pbft_period
pbft_round

◆ setNetwork()

void taraxa::VoteManager::setNetwork ( std::weak_ptr< Network network)

Set network as a weak pointer.

Parameters
networka weak pointer

◆ validateVote()

std::pair< bool, std::string > taraxa::VoteManager::validateVote ( const std::shared_ptr< PbftVote > &  vote,
bool  strict = true 
) const

Validates vote.

Parameters
voteto be validated
strictstrict validation
Returns
<true, ""> vote validation passed, otherwise <false, "err msg">

◆ voteAlreadyValidated()

bool taraxa::VoteManager::voteAlreadyValidated ( const vote_hash_t vote_hash) const
Parameters
vote_hash
Returns
true if vote_hash was already validated, otherwise false

◆ voteInVerifiedMap()

bool taraxa::VoteManager::voteInVerifiedMap ( std::shared_ptr< PbftVote > const &  vote) const

Check if the vote has been in the verified votes map.

Parameters
votevote
Returns
true if exist

Member Data Documentation

◆ already_validated_votes_

ExpirationCache<vote_hash_t> taraxa::VoteManager::already_validated_votes_
mutableprivate

◆ current_pbft_period_

std::atomic<PbftPeriod> taraxa::VoteManager::current_pbft_period_ {0}
private

◆ current_pbft_round_

std::atomic<PbftRound> taraxa::VoteManager::current_pbft_round_ {0}
private

◆ current_two_t_plus_one_

std::unordered_map<PbftVoteTypes, std::pair<PbftPeriod, uint64_t> > taraxa::VoteManager::current_two_t_plus_one_
mutableprivate

◆ current_two_t_plus_one_mutex_

std::shared_mutex taraxa::VoteManager::current_two_t_plus_one_mutex_
mutableprivate

◆ db_

std::shared_ptr<DbStorage> taraxa::VoteManager::db_
private

◆ extra_reward_votes_

std::vector<vote_hash_t> taraxa::VoteManager::extra_reward_votes_
private

◆ final_chain_

std::shared_ptr<final_chain::FinalChain> taraxa::VoteManager::final_chain_
private

◆ key_manager_

std::shared_ptr<KeyManager> taraxa::VoteManager::key_manager_
private

◆ kNodeAddr

const addr_t taraxa::VoteManager::kNodeAddr
private

◆ kNodePub

const dev::Public taraxa::VoteManager::kNodePub
private

◆ kNodeSk

const secret_t taraxa::VoteManager::kNodeSk
private

◆ kPbftConfig

const PbftConfig& taraxa::VoteManager::kPbftConfig
private

◆ kVrfSk

const vrf_wrapper::vrf_sk_t taraxa::VoteManager::kVrfSk
private

◆ network_

std::weak_ptr<Network> taraxa::VoteManager::network_
private

◆ own_verified_votes_

std::vector<std::shared_ptr<PbftVote> > taraxa::VoteManager::own_verified_votes_
private

◆ pbft_chain_

std::shared_ptr<PbftChain> taraxa::VoteManager::pbft_chain_
private

◆ reward_votes_block_hash_

blk_hash_t taraxa::VoteManager::reward_votes_block_hash_
private

◆ reward_votes_info_mutex_

std::shared_mutex taraxa::VoteManager::reward_votes_info_mutex_
mutableprivate

◆ reward_votes_period_

PbftRound taraxa::VoteManager::reward_votes_period_
private

◆ reward_votes_round_

PbftRound taraxa::VoteManager::reward_votes_round_
private

◆ slashing_manager_

std::shared_ptr<SlashingManager> taraxa::VoteManager::slashing_manager_
private

◆ verified_votes_

std::map<PbftPeriod, std::map<PbftRound, VerifiedVotes> > taraxa::VoteManager::verified_votes_
private

◆ verified_votes_access_

std::shared_mutex taraxa::VoteManager::verified_votes_access_
mutableprivate

◆ taraxa::PbftVote

class taraxa::PbftVote

PbftVote class is a vote class that includes vote hash, vote on PBFT block hash, vote signature, VRF sortition, voter public key, voter address, and vote weight.

Collaboration diagram for taraxa::PbftVote:

Public Types

using vrf_pk_t = vrf_wrapper::vrf_pk_t
 

Public Member Functions

 PbftVote ()=default
 
 PbftVote (secret_t const &node_sk, VrfPbftSortition vrf_sortition, blk_hash_t const &block_hash)
 
 PbftVote (const blk_hash_t &block_hash, PbftPeriod period, PbftRound round, PbftStep step, dev::RLP const &rlp)
 
 PbftVote (dev::RLP const &rlp)
 
 PbftVote (bytes const &rlp)
 
bool operator== (const PbftVote &other) const
 
bool verifyVrfSortition (const vrf_pk_t &pk, bool strict) const
 Verify VRF sortition. More...
 
const VrfPbftSortitiongetVrfSortition () const
 Get VRF sortition. More...
 
const vrf_wrapper::vrf_proof_tgetSortitionProof () const
 Get VRF sortition proof. More...
 
const vrf_wrapper::vrf_output_tgetCredential () const
 Get VRF sortition output. More...
 
PbftVoteTypes getType () const
 Get vote type. More...
 
PbftPeriod getPeriod () const
 Get vote PBFT period. More...
 
PbftRound getRound () const
 Get vote PBFT round. More...
 
PbftStep getStep () const
 Get vote PBFT step. More...
 
bytes rlp (bool inc_sig=true, bool inc_weight=false) const
 Recursive Length Prefix. More...
 
bytes optimizedRlp () const
 Optimized Recursive Length Prefix. More...
 
uint64_t calculateWeight (uint64_t stake, double dpos_total_votes_count, double threshold) const
 Calculate vote weight. More...
 
std::optional< uint64_t > getWeight () const
 Get vote weight. More...
 
Json::Value toJSON () const
 Get vote in JSON representation. More...
 
- Public Member Functions inherited from taraxa::Vote
 Vote ()=default
 
 Vote (const blk_hash_t &block_hash)
 
void signVote (const secret_t &node_sk)
 Sign the vote. More...
 
const vote_hash_tgetHash () const
 Get vote hash. More...
 
const public_tgetVoter () const
 Get voter public key. More...
 
const addr_tgetVoterAddr () const
 Get voter address. More...
 
const sig_tgetVoteSignature () const
 Get vote signature. More...
 
const blk_hash_tgetBlockHash () const
 Get PBFT block hash that votes on. More...
 
bool verifyVote () const
 Verify vote. More...
 

Private Member Functions

vote_hash_t sha3 (bool inc_sig) const override
 Secure Hash Algorithm 3. More...
 

Private Attributes

VrfPbftSortition vrf_sortition_
 
std::optional< uint64_t > weight_
 

Friends

std::ostream & operator<< (std::ostream &strm, PbftVote const &vote)
 

Additional Inherited Members

- Protected Attributes inherited from taraxa::Vote
blk_hash_t block_hash_
 
sig_t vote_signature_
 
vote_hash_t vote_hash_
 
public_t cached_voter_
 
addr_t cached_voter_addr_
 

Member Typedef Documentation

◆ vrf_pk_t

Constructor & Destructor Documentation

◆ PbftVote() [1/5]

taraxa::PbftVote::PbftVote ( )
default

◆ PbftVote() [2/5]

taraxa::PbftVote::PbftVote ( secret_t const &  node_sk,
VrfPbftSortition  vrf_sortition,
blk_hash_t const &  block_hash 
)

◆ PbftVote() [3/5]

taraxa::PbftVote::PbftVote ( const blk_hash_t block_hash,
PbftPeriod  period,
PbftRound  round,
PbftStep  step,
dev::RLP const &  rlp 
)
explicit

◆ PbftVote() [4/5]

taraxa::PbftVote::PbftVote ( dev::RLP const &  rlp)
explicit

◆ PbftVote() [5/5]

taraxa::PbftVote::PbftVote ( bytes const &  rlp)
explicit

Member Function Documentation

◆ calculateWeight()

uint64_t taraxa::PbftVote::calculateWeight ( uint64_t  stake,
double  dpos_total_votes_count,
double  threshold 
) const

Calculate vote weight.

Parameters
stakevoter DPOS eligible votes count
dpos_total_votes_counttotal DPOS votes count
thresholdPBFT sortition threshold that is minimum of between PBFT committee size and total DPOS votes count
Returns
vote weight

◆ getCredential()

const vrf_wrapper::vrf_output_t & taraxa::PbftVote::getCredential ( ) const

Get VRF sortition output.

Returns
VRF sortition output

◆ getPeriod()

PbftPeriod taraxa::PbftVote::getPeriod ( ) const

Get vote PBFT period.

Returns
vote PBFT period

◆ getRound()

PbftRound taraxa::PbftVote::getRound ( ) const

Get vote PBFT round.

Returns
vote PBFT round

◆ getSortitionProof()

const vrf_wrapper::vrf_proof_t & taraxa::PbftVote::getSortitionProof ( ) const

Get VRF sortition proof.

Returns
VRF sortition proof

◆ getStep()

PbftStep taraxa::PbftVote::getStep ( ) const

Get vote PBFT step.

Returns
vote PBFT step

◆ getType()

PbftVoteTypes taraxa::PbftVote::getType ( ) const

Get vote type.

Returns
vote type

◆ getVrfSortition()

const VrfPbftSortition & taraxa::PbftVote::getVrfSortition ( ) const

Get VRF sortition.

Returns
VRF sortition

◆ getWeight()

std::optional< uint64_t > taraxa::PbftVote::getWeight ( ) const

Get vote weight.

Returns
vote weight

◆ operator==()

bool taraxa::PbftVote::operator== ( const PbftVote other) const

◆ optimizedRlp()

bytes taraxa::PbftVote::optimizedRlp ( ) const

Optimized Recursive Length Prefix.

Note
Encode only vote's signature and vrf proof into the rlp
Returns
bytes of RLP stream

◆ rlp()

bytes taraxa::PbftVote::rlp ( bool  inc_sig = true,
bool  inc_weight = false 
) const

Recursive Length Prefix.

Parameters
inc_sigif include vote signature
inc_weightif include vote weight
Returns
bytes of RLP stream

◆ sha3()

vote_hash_t taraxa::PbftVote::sha3 ( bool  inc_sig) const
overrideprivatevirtual

Secure Hash Algorithm 3.

Parameters
inc_sigif include vote signature
Returns
secure hash as vote hash

Implements taraxa::Vote.

◆ toJSON()

Json::Value taraxa::PbftVote::toJSON ( ) const

Get vote in JSON representation.

Returns
vote JSON

◆ verifyVrfSortition()

bool taraxa::PbftVote::verifyVrfSortition ( const vrf_pk_t pk,
bool  strict 
) const

Verify VRF sortition.

Returns
true if passed

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  strm,
PbftVote const &  vote 
)
friend

Member Data Documentation

◆ vrf_sortition_

VrfPbftSortition taraxa::PbftVote::vrf_sortition_
private

◆ weight_

std::optional<uint64_t> taraxa::PbftVote::weight_
mutableprivate

◆ taraxa::PillarVote

class taraxa::PillarVote

PillarVote class.

Collaboration diagram for taraxa::PillarVote:

Public Member Functions

 PillarVote ()=default
 
 PillarVote (const secret_t &node_sk, PbftPeriod period, const blk_hash_t &block_hash)
 
 PillarVote (PbftPeriod period, const blk_hash_t &block_hash, sig_t &&signature)
 
 PillarVote (const dev::RLP &rlp)
 
 PillarVote (const bytes &rlp)
 
PbftPeriod getPeriod () const
 
bytes rlp () const
 Recursive Length Prefix. More...
 
bytes encodeSolidity (bool inc_sig=true) const
 
- Public Member Functions inherited from taraxa::Vote
 Vote ()=default
 
 Vote (const blk_hash_t &block_hash)
 
void signVote (const secret_t &node_sk)
 Sign the vote. More...
 
const vote_hash_tgetHash () const
 Get vote hash. More...
 
const public_tgetVoter () const
 Get voter public key. More...
 
const addr_tgetVoterAddr () const
 Get voter address. More...
 
const sig_tgetVoteSignature () const
 Get vote signature. More...
 
const blk_hash_tgetBlockHash () const
 Get PBFT block hash that votes on. More...
 
bool verifyVote () const
 Verify vote. More...
 

Static Public Member Functions

static PillarVote decodeSolidity (const bytes &enc)
 Decodes solidity encoded representation of pillar vote. More...
 

Static Public Attributes

constexpr static size_t kNoSigRlpSize {2}
 
constexpr static size_t kStandardRlpSize {3}
 

Private Member Functions

vote_hash_t sha3 (bool inc_sig) const override
 Secure Hash Algorithm 3. More...
 

Private Attributes

PbftPeriod period_
 

Additional Inherited Members

- Protected Attributes inherited from taraxa::Vote
blk_hash_t block_hash_
 
sig_t vote_signature_
 
vote_hash_t vote_hash_
 
public_t cached_voter_
 
addr_t cached_voter_addr_
 

Constructor & Destructor Documentation

◆ PillarVote() [1/5]

taraxa::PillarVote::PillarVote ( )
default

◆ PillarVote() [2/5]

taraxa::PillarVote::PillarVote ( const secret_t node_sk,
PbftPeriod  period,
const blk_hash_t block_hash 
)

◆ PillarVote() [3/5]

taraxa::PillarVote::PillarVote ( PbftPeriod  period,
const blk_hash_t block_hash,
sig_t &&  signature 
)

◆ PillarVote() [4/5]

taraxa::PillarVote::PillarVote ( const dev::RLP rlp)
explicit

◆ PillarVote() [5/5]

taraxa::PillarVote::PillarVote ( const bytes rlp)
explicit

Member Function Documentation

◆ decodeSolidity()

PillarVote taraxa::PillarVote::decodeSolidity ( const bytes enc)
static

Decodes solidity encoded representation of pillar vote.

Parameters
enc
Returns
PillarVote

◆ encodeSolidity()

bytes taraxa::PillarVote::encodeSolidity ( bool  inc_sig = true) const
Note
Solidity encoding is used for data that are sent to smart contracts
Returns
solidity encoded representation of pillar vote

◆ getPeriod()

PbftPeriod taraxa::PillarVote::getPeriod ( ) const
Returns
vote pbft period

◆ rlp()

bytes taraxa::PillarVote::rlp ( ) const

Recursive Length Prefix.

Returns
bytes of RLP stream

◆ sha3()

vote_hash_t taraxa::PillarVote::sha3 ( bool  inc_sig) const
overrideprivatevirtual

Secure Hash Algorithm 3.

Parameters
inc_sigif include vote signature
Returns
secure hash as vote hash

Implements taraxa::Vote.

Member Data Documentation

◆ kNoSigRlpSize

constexpr static size_t taraxa::PillarVote::kNoSigRlpSize {2}
staticconstexpr

◆ kStandardRlpSize

constexpr static size_t taraxa::PillarVote::kStandardRlpSize {3}
staticconstexpr

◆ period_

PbftPeriod taraxa::PillarVote::period_
private

◆ taraxa::Vote

class taraxa::Vote

Vote class is a vote class that includes vote hash, vote on PBFT block hash, vote signature, VRF sortition, voter public key, voter address, and vote weight.

Collaboration diagram for taraxa::Vote:

Public Member Functions

 Vote ()=default
 
 Vote (const blk_hash_t &block_hash)
 
void signVote (const secret_t &node_sk)
 Sign the vote. More...
 
const vote_hash_tgetHash () const
 Get vote hash. More...
 
const public_tgetVoter () const
 Get voter public key. More...
 
const addr_tgetVoterAddr () const
 Get voter address. More...
 
const sig_tgetVoteSignature () const
 Get vote signature. More...
 
const blk_hash_tgetBlockHash () const
 Get PBFT block hash that votes on. More...
 
bool verifyVote () const
 Verify vote. More...
 
virtual vote_hash_t sha3 (bool inc_sig) const =0
 Secure Hash Algorithm 3. More...
 

Protected Attributes

blk_hash_t block_hash_
 
sig_t vote_signature_
 
vote_hash_t vote_hash_
 
public_t cached_voter_
 
addr_t cached_voter_addr_
 

Constructor & Destructor Documentation

◆ Vote() [1/2]

taraxa::Vote::Vote ( )
default

◆ Vote() [2/2]

taraxa::Vote::Vote ( const blk_hash_t block_hash)

Member Function Documentation

◆ getBlockHash()

const blk_hash_t & taraxa::Vote::getBlockHash ( ) const

Get PBFT block hash that votes on.

Returns
PBFT block hash

◆ getHash()

const vote_hash_t & taraxa::Vote::getHash ( ) const

Get vote hash.

Returns
vote hash

◆ getVoter()

const public_t & taraxa::Vote::getVoter ( ) const

Get voter public key.

Returns
voter public key

◆ getVoterAddr()

const addr_t & taraxa::Vote::getVoterAddr ( ) const

Get voter address.

Returns
voter address

◆ getVoteSignature()

const sig_t & taraxa::Vote::getVoteSignature ( ) const

Get vote signature.

Returns
vote signature

◆ sha3()

virtual vote_hash_t taraxa::Vote::sha3 ( bool  inc_sig) const
pure virtual

Secure Hash Algorithm 3.

Parameters
inc_sigif include vote signature
Returns
secure hash as vote hash

Implemented in taraxa::PillarVote, and taraxa::PbftVote.

◆ signVote()

void taraxa::Vote::signVote ( const secret_t node_sk)

Sign the vote.

Parameters
node_sk

◆ verifyVote()

bool taraxa::Vote::verifyVote ( ) const

Verify vote.

Returns
true if passed

Member Data Documentation

◆ block_hash_

blk_hash_t taraxa::Vote::block_hash_
protected

◆ cached_voter_

public_t taraxa::Vote::cached_voter_
mutableprotected

◆ cached_voter_addr_

addr_t taraxa::Vote::cached_voter_addr_
mutableprotected

◆ vote_hash_

vote_hash_t taraxa::Vote::vote_hash_
mutableprotected

◆ vote_signature_

sig_t taraxa::Vote::vote_signature_
protected

◆ taraxa::VrfPbftMsg

class taraxa::VrfPbftMsg

VrfPbftMsg class uses PBFT period, round and step to generate a message for doing VRF sortition.

Public Member Functions

 VrfPbftMsg ()=default
 
 VrfPbftMsg (PbftVoteTypes type, PbftPeriod period, PbftRound round, PbftStep step)
 
PbftVoteTypes getType () const
 Get v type based on vote step. More...
 
std::string toString () const
 Combine vote type, PBFT period, round and step to a string. More...
 
bytes getRlpBytes () const
 Get bytes of RLP stream. More...
 
bool operator== (VrfPbftMsg const &other) const
 

Public Attributes

PbftPeriod period_
 
PbftRound round_
 
PbftStep step_
 

Friends

std::ostream & operator<< (std::ostream &strm, VrfPbftMsg const &pbft_msg)
 

Constructor & Destructor Documentation

◆ VrfPbftMsg() [1/2]

taraxa::VrfPbftMsg::VrfPbftMsg ( )
default

◆ VrfPbftMsg() [2/2]

taraxa::VrfPbftMsg::VrfPbftMsg ( PbftVoteTypes  type,
PbftPeriod  period,
PbftRound  round,
PbftStep  step 
)

Member Function Documentation

◆ getRlpBytes()

bytes taraxa::VrfPbftMsg::getRlpBytes ( ) const

Get bytes of RLP stream.

Returns
bytes of RLP stream

◆ getType()

PbftVoteTypes taraxa::VrfPbftMsg::getType ( ) const

Get v type based on vote step.

Returns
PbftVoteTypes based on vote step

◆ operator==()

bool taraxa::VrfPbftMsg::operator== ( VrfPbftMsg const &  other) const

◆ toString()

std::string taraxa::VrfPbftMsg::toString ( ) const

Combine vote type, PBFT period, round and step to a string.

Returns
a string of vote type, PBFT period, round and step

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  strm,
VrfPbftMsg const &  pbft_msg 
)
friend

Member Data Documentation

◆ period_

PbftPeriod taraxa::VrfPbftMsg::period_

◆ round_

PbftRound taraxa::VrfPbftMsg::round_

◆ step_

PbftStep taraxa::VrfPbftMsg::step_

◆ taraxa::VrfPbftSortition

class taraxa::VrfPbftSortition

VrfPbftSortition class used for doing VRF sortition to place a vote or to propose a new PBFT block.

Collaboration diagram for taraxa::VrfPbftSortition:

Public Member Functions

 VrfPbftSortition ()=default
 
 VrfPbftSortition (vrf_sk_t const &sk, const VrfPbftMsg &pbft_msg)
 
 VrfPbftSortition (dev::bytes const &rlp)
 
dev::bytes getRlpBytes () const
 Get bytes of RLP stream. More...
 
bool verify (const vrf_pk_t &pk, bool strict=true) const
 Verify VRF sortition. More...
 
bool operator== (VrfPbftSortition const &other) const
 
uint64_t calculateWeight (uint64_t stake, uint64_t dpos_total_votes_count, uint64_t threshold, const public_t &address) const
 Calculate vote weight. More...
 
- Public Member Functions inherited from taraxa::vrf_wrapper::VrfSortitionBase
 VrfSortitionBase ()=default
 
 VrfSortitionBase (vrf_sk_t const &sk, bytes const &msg, uint16_t vote_count=1)
 
bool verify (const vrf_pk_t &pk, const bytes &msg, uint16_t vote_count=1, bool strict=true) const
 
bool operator== (VrfSortitionBase const &other) const
 
virtual std::ostream & print (std::ostream &strm) const
 

Static Public Member Functions

static uint64_t getBinominalDistribution (uint64_t stake, double dpos_total_votes_count, double threshold, const uint256_t &hash)
 Calculate a vote weight in binominal distribution. More...
 
- Static Public Member Functions inherited from taraxa::vrf_wrapper::VrfSortitionBase
static dev::bytes makeVrfInput (taraxa::level_t level, const dev::h256 &period_hash)
 

Public Attributes

VrfPbftMsg pbft_msg_
 
- Public Attributes inherited from taraxa::vrf_wrapper::VrfSortitionBase
vrf_proof_t proof_
 
vrf_output_t output_
 
uint16_t threshold_
 

Static Public Attributes

static uint256_t max256bits = std::numeric_limits<uint256_t>::max()
 
static auto kMax256bFP = max256bits.convert_to<boost::multiprecision::mpfr_float>()
 

Private Types

using vrf_sk_t = vrf_wrapper::vrf_sk_t
 
using vrf_pk_t = vrf_wrapper::vrf_pk_t
 
using vrf_proof_t = vrf_wrapper::vrf_proof_t
 
using vrf_output_t = vrf_wrapper::vrf_output_t
 

Friends

std::ostream & operator<< (std::ostream &strm, const VrfPbftSortition &vrf_sortition)
 

Member Typedef Documentation

◆ vrf_output_t

◆ vrf_pk_t

◆ vrf_proof_t

◆ vrf_sk_t

Constructor & Destructor Documentation

◆ VrfPbftSortition() [1/3]

taraxa::VrfPbftSortition::VrfPbftSortition ( )
default

◆ VrfPbftSortition() [2/3]

taraxa::VrfPbftSortition::VrfPbftSortition ( vrf_sk_t const &  sk,
const VrfPbftMsg pbft_msg 
)
inline

◆ VrfPbftSortition() [3/3]

taraxa::VrfPbftSortition::VrfPbftSortition ( dev::bytes const &  rlp)
explicit

Member Function Documentation

◆ calculateWeight()

uint64_t taraxa::VrfPbftSortition::calculateWeight ( uint64_t  stake,
uint64_t  dpos_total_votes_count,
uint64_t  threshold,
const public_t address 
) const

Calculate vote weight.

Parameters
stakevoter DPOS eligible votes count
dpos_total_votes_counttotal DPOS votes count
thresholdPBFT sortition threshold that is minimum of between PBFT committee size and total DPOS votes count
addressvoter public key
Returns
vote weight

◆ getBinominalDistribution()

uint64_t taraxa::VrfPbftSortition::getBinominalDistribution ( uint64_t  stake,
double  dpos_total_votes_count,
double  threshold,
const uint256_t hash 
)
static

Calculate a vote weight in binominal distribution.

Parameters
stakevoter DPOS eligible votes count
dpos_total_votes_counttotal DPOS votes count
thresholdPBFT sortition threshold that is minimum of between PBFT committee size and total DPOS votes count
hasha hash number of combining VRF output, voter address, and vote weight index
Returns
vote weight

◆ getRlpBytes()

bytes taraxa::VrfPbftSortition::getRlpBytes ( ) const

Get bytes of RLP stream.

Returns
bytes of RLP stream

◆ operator==()

bool taraxa::VrfPbftSortition::operator== ( VrfPbftSortition const &  other) const
inline

◆ verify()

bool taraxa::VrfPbftSortition::verify ( const vrf_pk_t pk,
bool  strict = true 
) const
inline

Verify VRF sortition.

Parameters
strictstrict validation
Returns
true if passed

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  strm,
const VrfPbftSortition vrf_sortition 
)
friend

Member Data Documentation

◆ kMax256bFP

auto taraxa::VrfPbftSortition::kMax256bFP = max256bits.convert_to<boost::multiprecision::mpfr_float>()
inlinestatic

◆ max256bits

uint256_t taraxa::VrfPbftSortition::max256bits = std::numeric_limits<uint256_t>::max()
inlinestatic

◆ pbft_msg_

VrfPbftMsg taraxa::VrfPbftSortition::pbft_msg_

Enumeration Type Documentation

◆ PbftVoteTypes

enum taraxa::PbftVoteTypes : uint8_t
strong
Enumerator
invalid_vote 
propose_vote 
soft_vote 
cert_vote 
next_vote 

Function Documentation

◆ decodePbftVotesBundleRlp()

std::vector< std::shared_ptr< PbftVote > > taraxa::decodePbftVotesBundleRlp ( const dev::RLP votes_bundle_rlp)

Decodes pbft votes from optimized votes bundle rlp.

Parameters
votes_bundle_rlp
Returns
votes

◆ decodePillarVotesBundleRlp()

std::vector< std::shared_ptr< PillarVote > > taraxa::decodePillarVotesBundleRlp ( const dev::RLP votes_bundle_rlp)

Decodes pillar votes from optimized votes bundle rlp.

Parameters
votes_bundle_rlp
Returns
votes

◆ encodePbftVotesBundleRlp()

dev::bytes taraxa::encodePbftVotesBundleRlp ( const std::vector< std::shared_ptr< PbftVote >> &  votes)

Encodes pbft votes into optimized votes bundle rlp.

Parameters
votes
Returns
votes bundle rlp bytes

◆ encodePillarVotesBundleRlp()

dev::bytes taraxa::encodePillarVotesBundleRlp ( const std::vector< std::shared_ptr< PillarVote >> &  votes)

Encodes pillar votes into optimized votes bundle rlp.

Parameters
votes
Returns
votes bundle rlp bytes

◆ getVoterIndexHash()

dev::h256 taraxa::getVoterIndexHash ( const vrf_wrapper::vrf_output_t vrf,
const public_t address,
uint64_t  index = 0 
)

Get a hash number of combining VRF output, voter address, and vote weight index.

Parameters
vrfVRF output
addressvoter address
indexvote weight index
Returns
a hash number in Secure Hash Algorithm 3

Variable Documentation

◆ kPbftVotesBundleRlpSize

constexpr static size_t taraxa::kPbftVotesBundleRlpSize {5}
staticconstexpr

◆ kPillarVotesBundleRlpSize

constexpr static size_t taraxa::kPillarVotesBundleRlpSize {3}
staticconstexpr