TARAXA
PBFT

Classes

class  taraxa::PbftChain
 PbftChain class is a single linked list that contains finalized PBFT blocks. More...
 
class  taraxa::PbftManager
 PbftManager class is a daemon that is used to finalize a bench of directed acyclic graph (DAG) blocks by using Practical Byzantine Fault Tolerance (PBFT) protocol. More...
 
class  taraxa::PeriodDataQueue
 PeriodDataQueue class is a syncing queue, the queue stores blocks synced from peers. More...
 
class  taraxa::PbftBlock
 The PbftBlock class is a PBFT block class that includes PBFT block hash, previous PBFT block hash, DAG anchor hash, DAG blocks ordering hash, period number, timestamp, proposer address, and proposer signature. More...
 
class  taraxa::PbftBlockExtraData
 
class  taraxa::PeriodData
 PeriodData class is for block execution, that includes PBFT block, certify votes, DAG blocks, and transactions. More...
 

Enumerations

enum  taraxa::PbftStates {
  taraxa::value_proposal_state = 1 , taraxa::filter_state , taraxa::certify_state , taraxa::finish_state ,
  taraxa::finish_polling_state
}
 
enum class  taraxa::PbftStateRootValidation { taraxa::Valid = 0 , taraxa::Missing , taraxa::Invalid }
 

Functions

std::ostream & taraxa::operator<< (std::ostream &strm, PbftChain const &pbft_chain)
 
std::ostream & taraxa::operator<< (std::ostream &strm, const PbftBlock &pbft_blk)
 
std::ostream & taraxa::operator<< (std::ostream &strm, PeriodData const &b)
 

Detailed Description


Class Documentation

◆ taraxa::PbftChain

class taraxa::PbftChain

PbftChain class is a single linked list that contains finalized PBFT blocks.

Collaboration diagram for taraxa::PbftChain:

Public Member Functions

 PbftChain (addr_t node_addr, std::shared_ptr< DbStorage > db)
 
blk_hash_t getHeadHash () const
 Get PBFT chain head hash. More...
 
PbftPeriod getPbftChainSize () const
 Get PBFT chain size. More...
 
PbftPeriod getPbftChainSizeExcludingEmptyPbftBlocks () const
 Get PBFT chain size excluding empty PBFT blocks. More...
 
blk_hash_t getLastPbftBlockHash () const
 Get last PBFT block hash. More...
 
blk_hash_t getLastNonNullPbftBlockAnchor () const
 Get last non null PBFT block anchor. More...
 
PbftBlock getPbftBlockInChain (blk_hash_t const &pbft_block_hash)
 Get a PBFT block in chain. More...
 
std::string getJsonStr () const
 Get PBFT chain head block in JSON string. More...
 
std::string getJsonStrForBlock (blk_hash_t const &block_hash, bool null_anchor) const
 Get PBFT chain head block in JSON string. More...
 
bool findPbftBlockInChain (blk_hash_t const &pbft_block_hash)
 Find a PBFT block in chain. More...
 
void updatePbftChain (blk_hash_t const &pbft_block_hash, blk_hash_t const &anchor_hash)
 Update PBFT chain size, non empty chain size, and last PBFT block hash. More...
 
bool checkPbftBlockValidation (const std::shared_ptr< PbftBlock > &pbft_block) const
 Verify a PBFT block. More...
 

Private Attributes

std::shared_mutex chain_head_access_
 
blk_hash_t head_hash_
 
PbftPeriod size_
 
PbftPeriod non_empty_size_
 
blk_hash_t last_pbft_block_hash_
 
blk_hash_t last_non_null_pbft_dag_anchor_hash_
 
std::shared_ptr< DbStoragedb_ = nullptr
 

Constructor & Destructor Documentation

◆ PbftChain()

taraxa::PbftChain::PbftChain ( addr_t  node_addr,
std::shared_ptr< DbStorage db 
)
explicit

Member Function Documentation

◆ checkPbftBlockValidation()

bool taraxa::PbftChain::checkPbftBlockValidation ( const std::shared_ptr< PbftBlock > &  pbft_block) const

Verify a PBFT block.

Parameters
pbft_blockPBFT block
Returns
true if passed verification

◆ findPbftBlockInChain()

bool taraxa::PbftChain::findPbftBlockInChain ( taraxa::blk_hash_t const &  pbft_block_hash)

Find a PBFT block in chain.

Parameters
pbft_block_hashPBFT block hash
Returns
true if found

◆ getHeadHash()

blk_hash_t taraxa::PbftChain::getHeadHash ( ) const

Get PBFT chain head hash.

Returns
PBFT chain head hash

◆ getJsonStr()

std::string taraxa::PbftChain::getJsonStr ( ) const

Get PBFT chain head block in JSON string.

Returns
PBFT chain head block in string

◆ getJsonStrForBlock()

std::string taraxa::PbftChain::getJsonStrForBlock ( blk_hash_t const &  block_hash,
bool  null_anchor 
) const

Get PBFT chain head block in JSON string.

Parameters
block_hashlast PBFT block hash
null_anchorif the PBFT block include an empty DAG anchor
Returns
PBFT chain head block in string

◆ getLastNonNullPbftBlockAnchor()

blk_hash_t taraxa::PbftChain::getLastNonNullPbftBlockAnchor ( ) const

Get last non null PBFT block anchor.

Returns
anchor hash

◆ getLastPbftBlockHash()

blk_hash_t taraxa::PbftChain::getLastPbftBlockHash ( ) const

Get last PBFT block hash.

Returns
last PBFT block hash

◆ getPbftBlockInChain()

PbftBlock taraxa::PbftChain::getPbftBlockInChain ( blk_hash_t const &  pbft_block_hash)

Get a PBFT block in chain.

Parameters
pbft_block_hashPBFT block hash
Returns
PBFT block

◆ getPbftChainSize()

PbftPeriod taraxa::PbftChain::getPbftChainSize ( ) const

Get PBFT chain size.

Returns
PBFT chain size

◆ getPbftChainSizeExcludingEmptyPbftBlocks()

PbftPeriod taraxa::PbftChain::getPbftChainSizeExcludingEmptyPbftBlocks ( ) const

Get PBFT chain size excluding empty PBFT blocks.

Returns
PBFT chain size excluding empty PBFT blocks

◆ updatePbftChain()

void taraxa::PbftChain::updatePbftChain ( blk_hash_t const &  pbft_block_hash,
blk_hash_t const &  anchor_hash 
)

Update PBFT chain size, non empty chain size, and last PBFT block hash.

Parameters
pbft_block_hashlast PBFT block hash
anchorDAG anchor hash

Member Data Documentation

◆ chain_head_access_

std::shared_mutex taraxa::PbftChain::chain_head_access_
mutableprivate

◆ db_

std::shared_ptr<DbStorage> taraxa::PbftChain::db_ = nullptr
private

◆ head_hash_

blk_hash_t taraxa::PbftChain::head_hash_
private

◆ last_non_null_pbft_dag_anchor_hash_

blk_hash_t taraxa::PbftChain::last_non_null_pbft_dag_anchor_hash_
private

◆ last_pbft_block_hash_

blk_hash_t taraxa::PbftChain::last_pbft_block_hash_
private

◆ non_empty_size_

PbftPeriod taraxa::PbftChain::non_empty_size_
private

◆ size_

PbftPeriod taraxa::PbftChain::size_
private

◆ taraxa::PbftManager

class taraxa::PbftManager

PbftManager class is a daemon that is used to finalize a bench of directed acyclic graph (DAG) blocks by using Practical Byzantine Fault Tolerance (PBFT) protocol.

According to paper "ALGORAND AGREEMENT Super Fast and Partition Resilient Byzantine Agreement (https://eprint.iacr.org/2018/377.pdf)", implement PBFT manager for finalizing DAG blocks.

There are 5 states in one PBFT round: proposal state, filter state, certify state, finish state, and finish polling state.

  • Proposal state: PBFT step 1. Generate a PBFT block and propose a vote on the block hash
  • Filter state: PBFT step 2. Identify a leader block from all received proposed blocks for the current period by using minimum Verifiable Random Function (VRF) output. Soft vote at the leader block hash. In filter state, don’t need check vote value correction.
  • Certify state: PBFT step 3. If receive enough soft votes, cert vote at the value. If receive enough cert votes, finalize the PBFT block and push it to PBFT chain.
  • Finish state: Happens at even number steps from step 4. Next vote at finishing value for the current PBFT round. If node receives enough next voting votes, PBFT goes to next round.
  • Finish polling state: Happens at odd number steps from step 5. Next vote at finishing value for the current PBFT round. If node receives enough next voting votes, PBFT goes to next round.

PBFT timing: All players keep a timer clock. The timer clock will reset to 0 at every new PBFT round. That doesn’t require all players clocks to be synchronized; it only requires that they have the same clock speed.

  • Proposal state: Reset clock to 0
  • Filter state: Start at clock 2 lambda time
  • Certify state: Start after filter state, clock is between 2 lambda and 4 lambda duration
  • Finish state: Start at 4 lambda time, until receive enough next voting votes to go to next round
  • Finish polling state: Start after first finish state. If node receives enough next voting votes within 2 lambda duration, PBFT will go to next round. Otherwise that will go back to Finish state.
Collaboration diagram for taraxa::PbftManager:

Public Types

using time_point = std::chrono::system_clock::time_point
 

Public Member Functions

 PbftManager (const FullNodeConfig &conf, std::shared_ptr< DbStorage > db, std::shared_ptr< PbftChain > pbft_chain, std::shared_ptr< VoteManager > vote_mgr, std::shared_ptr< DagManager > dag_mgr, std::shared_ptr< TransactionManager > trx_mgr, std::shared_ptr< final_chain::FinalChain > final_chain, std::shared_ptr< pillar_chain::PillarChainManager > pillar_chain_mgr)
 
 ~PbftManager ()
 
 PbftManager (const PbftManager &)=delete
 
 PbftManager (PbftManager &&)=delete
 
PbftManageroperator= (const PbftManager &)=delete
 
PbftManageroperator= (PbftManager &&)=delete
 
void setNetwork (std::weak_ptr< Network > network)
 Set network as a weak pointer. More...
 
void start ()
 Start PBFT daemon. More...
 
void stop ()
 Stop PBFT daemon. More...
 
void run ()
 Run PBFT daemon. More...
 
void initialState ()
 Initial PBFT states when node start PBFT. More...
 
std::pair< bool, PbftPeriodgetDagBlockPeriod (const blk_hash_t &hash)
 Get a DAG block period number. More...
 
PbftPeriod getPbftPeriod () const
 Get current PBFT period number. More...
 
PbftRound getPbftRound () const
 Get current PBFT round number. More...
 
std::pair< PbftRound, PbftPeriodgetPbftRoundAndPeriod () const
 Get PBFT round & period number. More...
 
PbftStep getPbftStep () const
 Get PBFT step number. More...
 
void setPbftRound (PbftRound round)
 Set PBFT round number. More...
 
void setPbftStep (PbftStep pbft_step)
 Set PBFT step. More...
 
std::optional< std::pair< std::shared_ptr< PbftBlock >, std::vector< std::shared_ptr< PbftVote > > > > generatePbftBlock (PbftPeriod propose_period, const blk_hash_t &prev_blk_hash, const blk_hash_t &anchor_hash, const blk_hash_t &order_hash, const std::optional< PbftBlockExtraData > &extra_data)
 Generate PBFT block, push into unverified queue, and broadcast to peers. More...
 
std::optional< uint64_t > getCurrentDposTotalVotesCount () const
 Get current total DPOS votes count. More...
 
std::optional< uint64_t > getCurrentNodeVotesCount () const
 Get current node DPOS votes count. More...
 
PbftPeriod pbftSyncingPeriod () const
 Get PBFT blocks synced period. More...
 
size_t periodDataQueueSize () const
 Get PBFT blocks syncing queue size. More...
 
bool periodDataQueueEmpty () const
 Returns true if queue is empty. More...
 
void periodDataQueuePush (PeriodData &&period_data, dev::p2p::NodeID const &node_id, std::vector< std::shared_ptr< PbftVote >> &&current_block_cert_votes)
 Push synced period data in syncing queue. More...
 
blk_hash_t lastPbftBlockHashFromQueueOrChain ()
 Get last pbft block hash from queue or if queue empty, from chain. More...
 
std::chrono::milliseconds getPbftInitialLambda () const
 Get PBFT lambda. PBFT lambda is a timer clock. More...
 
bool checkBlockWeight (const std::vector< DagBlock > &dag_blocks) const
 Check a block weight of gas estimation. More...
 
blk_hash_t getLastPbftBlockHash ()
 
void processProposedBlock (const std::shared_ptr< PbftBlock > &proposed_block, const std::shared_ptr< PbftVote > &propose_vote)
 Push proposed block into the proposed_blocks_ in case it is not there yet. More...
 
std::shared_ptr< PbftBlockgetPbftProposedBlock (PbftPeriod period, const blk_hash_t &block_hash) const
 Get a proposed PBFT block based on specified period and block hash. More...
 
size_t getPbftCommitteeSize () const
 Get PBFT committee size. More...
 
void testBroadcastVotesFunctionality ()
 Test/enforce broadcastVotes() to actually send votes. More...
 
void pushSyncedPbftBlocksIntoChain ()
 Check PBFT blocks syncing queue. If there are synced PBFT blocks in queue, push it to PBFT chain. More...
 
void waitForPeriodFinalization ()
 wait for DPOS period finalization More...
 
bool validatePillarDataInPeriodData (const PeriodData &period_data) const
 Validates pbft block extra data presence + pillar votes presence based on pbft block number and ficus hf block number. More...
 
void gossipVote (const std::shared_ptr< PbftVote > &vote, const std::shared_ptr< PbftBlock > &voted_block)
 Gossips vote to the other peers. More...
 

Static Public Member Functions

static blk_hash_t calculateOrderHash (const std::vector< blk_hash_t > &dag_block_hashes)
 Calculate DAG blocks ordering hash. More...
 
static blk_hash_t calculateOrderHash (const std::vector< DagBlock > &dag_blocks)
 Calculate DAG blocks ordering hash. More...
 
static void reorderTransactions (SharedTransactions &transactions)
 Reorder transactions data if DAG reordering caused transactions with same sender to have nonce in incorrect order. Reordering is deterministic so that same order is produced on any node on any platform. More...
 

Private Member Functions

void broadcastVotes ()
 Broadcast or rebroadcast 2t+1 soft/reward/previous round next votes + all own votes if needed. More...
 
void resetStep ()
 Reset PBFT step to 1. More...
 
bool advanceRound ()
 If node receives 2t+1 next votes for some block(including kNullBlockHash), advance round to + 1. More...
 
bool advancePeriod ()
 If node receives 2t+1 cert votes for some valid block and pushes it to the chain, advance period to + 1. More...
 
bool tryPushCertVotesBlock ()
 Check if there is 2t+1 cert votes for some valid block, if yes - push it into the chain. More...
 
void resetPbftConsensus (PbftRound round)
 Resets pbft consensus: current pbft round is set to round, step is set to the beginning value. More...
 
std::chrono::milliseconds elapsedTimeInMs (const time_point &start_time)
 
void sleep_ ()
 Time to sleep for PBFT protocol. More...
 
void setFilterState_ ()
 Set PBFT filter state. More...
 
void setCertifyState_ ()
 Set PBFT certify state. More...
 
void setFinishState_ ()
 Set PBFT finish state. More...
 
void setFinishPollingState_ ()
 Set PBFT finish polling state. More...
 
void loopBackFinishState_ ()
 Set back to PBFT finish state from PBFT finish polling state. More...
 
bool stateOperations_ ()
 If there are any synced PBFT blocks from peers, push the synced blocks in PBFT chain. Verify all received incoming votes. If there are enough certify votes, push voting PBFT block in PBFT chain. More...
 
void proposeBlock_ ()
 PBFT proposal state. PBFT step 1. Propose a PBFT block and place a proposal vote on the block hash. More...
 
void identifyBlock_ ()
 PBFT filter state. PBFT step 2. Identify a leader block from all received proposed blocks for the current period, and place a soft vote at the leader block hash. More...
 
void certifyBlock_ ()
 PBFT certify state. PBFT step 3. If receive enough soft votes and pass verification, place a cert vote at the value. More...
 
void firstFinish_ ()
 PBFT finish state. Happens at even number steps from step 4. Place a next vote at finishing value for the current PBFT round. More...
 
void secondFinish_ ()
 PBFT finish polling state: Happens at odd number steps from step 5. Place a next vote at finishing value for the current PBFT round. More...
 
bool placeVote (const std::shared_ptr< PbftVote > &vote, std::string_view log_vote_id, const std::shared_ptr< PbftBlock > &voted_block)
 Place (gossip) vote. More...
 
bool genAndPlaceProposeVote (const std::shared_ptr< PbftBlock > &proposed_block, std::vector< std::shared_ptr< PbftVote >> &&reward_votes)
 Generate propose vote for provided block place (gossip) it. More...
 
void gossipNewVote (const std::shared_ptr< PbftVote > &vote, const std::shared_ptr< PbftBlock > &voted_block)
 Gossips newly generated vote to the other peers. More...
 
std::optional< std::pair< std::shared_ptr< PbftBlock >, std::vector< std::shared_ptr< PbftVote > > > > proposePbftBlock ()
 Propose a new PBFT block. More...
 
std::optional< PbftBlockExtraDatacreatePbftBlockExtraData (PbftPeriod pbft_period) const
 Creates pbft block extra data. More...
 
std::shared_ptr< PbftBlockidentifyLeaderBlock_ (PbftRound round, PbftPeriod period)
 Identify a leader block from all received proposed PBFT blocks for the current round by using minimum Verifiable Random Function (VRF) output. In filter state, don’t need check vote value correction. More...
 
h256 getProposal (const std::shared_ptr< PbftVote > &vote) const
 Calculate the lowest hash of a vote by vote weight. More...
 
bool validatePbftBlock (const std::shared_ptr< PbftBlock > &pbft_block) const
 Validates pbft block. It checks if: More...
 
PbftStateRootValidation validateFinalChainHash (const std::shared_ptr< PbftBlock > &pbft_block) const
 Validates pbft block final chain hash. More...
 
bool validatePbftBlockExtraData (const std::shared_ptr< PbftBlock > &pbft_block) const
 Validates pbft block extra data presence: More...
 
bool pushCertVotedPbftBlockIntoChain_ (const std::shared_ptr< PbftBlock > &pbft_block, std::vector< std::shared_ptr< PbftVote >> &&current_round_cert_votes)
 If there are enough certify votes, push the vote PBFT block in PBFT chain. More...
 
void finalize_ (PeriodData &&period_data, std::vector< h256 > &&finalized_dag_blk_hashes, bool synchronous_processing=false)
 Final chain executes a finalized PBFT block. More...
 
bool pushPbftBlock_ (PeriodData &&period_data, std::vector< std::shared_ptr< PbftVote >> &&cert_votes)
 Push a new PBFT block into the PBFT chain. More...
 
std::shared_ptr< PbftBlockgetValidPbftProposedBlock (PbftPeriod period, const blk_hash_t &block_hash)
 Get valid proposed pbft block. It will retrieve block from proposed_blocks and then validate it if not already validated. More...
 
std::optional< std::pair< PeriodData, std::vector< std::shared_ptr< PbftVote > > > > processPeriodData ()
 Process synced PBFT blocks if PBFT syncing queue is not empty. More...
 
bool validatePbftBlockCertVotes (const std::shared_ptr< PbftBlock > pbft_block, const std::vector< std::shared_ptr< PbftVote >> &cert_votes) const
 Validates PBFT block cert votes. More...
 
bool validatePbftBlockPillarVotes (const PeriodData &period_data) const
 Validates PBFT block pillar votes. More...
 
bool canParticipateInConsensus (PbftPeriod period) const
 
void printVotingSummary () const
 Prints all votes generated by node in current round. More...
 
void processPillarBlock (PbftPeriod period)
 Creates pillar block (and pillar vote in case node is eligible to vote & is not syncing) More...
 

Private Attributes

std::atomic< bool > stopped_ = true
 
std::unordered_map< blk_hash_t, std::vector< DagBlock > > anchor_dag_block_order_cache_
 
std::unique_ptr< std::thread > daemon_
 
std::shared_ptr< DbStoragedb_
 
std::shared_ptr< PbftChainpbft_chain_
 
std::shared_ptr< VoteManagervote_mgr_
 
std::shared_ptr< DagManagerdag_mgr_
 
std::weak_ptr< Networknetwork_
 
std::shared_ptr< TransactionManagertrx_mgr_
 
std::shared_ptr< final_chain::FinalChainfinal_chain_
 
std::shared_ptr< pillar_chain::PillarChainManagerpillar_chain_mgr_
 
const addr_t node_addr_
 
const secret_t node_sk_
 
const std::chrono::milliseconds kMinLambda
 
std::chrono::milliseconds lambda_ {0}
 
const std::chrono::milliseconds kMaxLambda {60000}
 
const uint32_t kBroadcastVotesLambdaTime = 20
 
const uint32_t kRebroadcastVotesLambdaTime = 60
 
uint32_t broadcast_votes_counter_ = 1
 
uint32_t rebroadcast_votes_counter_ = 1
 
uint32_t broadcast_reward_votes_counter_ = 1
 
uint32_t rebroadcast_reward_votes_counter_ = 1
 
PbftStates state_ = value_proposal_state
 
std::atomic< PbftRoundround_ = 1
 
PbftStep step_ = 1
 
std::optional< std::shared_ptr< PbftBlock > > cert_voted_block_for_round_ {}
 
std::map< blk_hash_t, std::vector< PbftStep > > current_round_broadcasted_votes_
 
time_point current_round_start_datetime_
 
time_point current_period_start_datetime_
 
time_point second_finish_step_start_datetime_
 
std::chrono::milliseconds next_step_time_ms_ {0}
 
bool executed_pbft_block_ = false
 
bool already_next_voted_value_ = false
 
bool already_next_voted_null_block_hash_ = false
 
bool go_finish_state_ = false
 
bool loop_back_finish_state_ = false
 
PbftPeriod last_placed_pillar_vote_period_ = 0
 
bool printSecondFinishStepInfo_ = true
 
bool printCertStepInfo_ = true
 
const blk_hash_t dag_genesis_block_hash_
 
const GenesisConfigkGenesisConfig
 
std::condition_variable stop_cv_
 
std::mutex stop_mtx_
 
PeriodDataQueue sync_queue_
 
ProposedBlocks proposed_blocks_
 

Member Typedef Documentation

◆ time_point

using taraxa::PbftManager::time_point = std::chrono::system_clock::time_point

Constructor & Destructor Documentation

◆ PbftManager() [1/3]

taraxa::PbftManager::PbftManager ( const FullNodeConfig conf,
std::shared_ptr< DbStorage db,
std::shared_ptr< PbftChain pbft_chain,
std::shared_ptr< VoteManager vote_mgr,
std::shared_ptr< DagManager dag_mgr,
std::shared_ptr< TransactionManager trx_mgr,
std::shared_ptr< final_chain::FinalChain final_chain,
std::shared_ptr< pillar_chain::PillarChainManager pillar_chain_mgr 
)

◆ ~PbftManager()

taraxa::PbftManager::~PbftManager ( )

◆ PbftManager() [2/3]

taraxa::PbftManager::PbftManager ( const PbftManager )
delete

◆ PbftManager() [3/3]

taraxa::PbftManager::PbftManager ( PbftManager &&  )
delete

Member Function Documentation

◆ advancePeriod()

bool taraxa::PbftManager::advancePeriod ( )
private

If node receives 2t+1 cert votes for some valid block and pushes it to the chain, advance period to + 1.

Returns
true if PBFT period advanced, otherwise false

◆ advanceRound()

bool taraxa::PbftManager::advanceRound ( )
private

If node receives 2t+1 next votes for some block(including kNullBlockHash), advance round to + 1.

Returns
true if PBFT round advanced, otherwise false

◆ broadcastVotes()

void taraxa::PbftManager::broadcastVotes ( )
private

Broadcast or rebroadcast 2t+1 soft/reward/previous round next votes + all own votes if needed.

◆ calculateOrderHash() [1/2]

blk_hash_t taraxa::PbftManager::calculateOrderHash ( const std::vector< blk_hash_t > &  dag_block_hashes)
static

Calculate DAG blocks ordering hash.

Parameters
dag_block_hashesDAG blocks hashes
Returns
DAG blocks ordering hash

◆ calculateOrderHash() [2/2]

blk_hash_t taraxa::PbftManager::calculateOrderHash ( const std::vector< DagBlock > &  dag_blocks)
static

Calculate DAG blocks ordering hash.

Parameters
dag_blocksDAG blocks
Returns
DAG blocks ordering hash

◆ canParticipateInConsensus()

bool taraxa::PbftManager::canParticipateInConsensus ( PbftPeriod  period) const
private
Parameters
period
Returns
true if node can participate in consensus - is dpos eligible to vote and create blocks for specified period

◆ certifyBlock_()

void taraxa::PbftManager::certifyBlock_ ( )
private

PBFT certify state. PBFT step 3. If receive enough soft votes and pass verification, place a cert vote at the value.

◆ checkBlockWeight()

bool taraxa::PbftManager::checkBlockWeight ( const std::vector< DagBlock > &  dag_blocks) const

Check a block weight of gas estimation.

Parameters
dag_blocksdag blocks
Returns
true if total weight of gas estimation is less or equal to gas limit. Otherwise return false

◆ createPbftBlockExtraData()

std::optional< PbftBlockExtraData > taraxa::PbftManager::createPbftBlockExtraData ( PbftPeriod  pbft_period) const
private

Creates pbft block extra data.

Parameters
pbft_period
Returns
std::optional<PbftBlockExtraData>

◆ elapsedTimeInMs()

std::chrono::milliseconds taraxa::PbftManager::elapsedTimeInMs ( const time_point start_time)
private
Parameters
start_time
Returns
elapsed time in ms from provided start_time

◆ finalize_()

void taraxa::PbftManager::finalize_ ( PeriodData &&  period_data,
std::vector< h256 > &&  finalized_dag_blk_hashes,
bool  synchronous_processing = false 
)
private

Final chain executes a finalized PBFT block.

Parameters
period_dataPBFT block, cert votes, DAG blocks, and transactions
finalized_dag_blk_hashesDAG blocks hashes
synchronous_processingwait for block finalization to finish

◆ firstFinish_()

void taraxa::PbftManager::firstFinish_ ( )
private

PBFT finish state. Happens at even number steps from step 4. Place a next vote at finishing value for the current PBFT round.

◆ genAndPlaceProposeVote()

bool taraxa::PbftManager::genAndPlaceProposeVote ( const std::shared_ptr< PbftBlock > &  proposed_block,
std::vector< std::shared_ptr< PbftVote >> &&  reward_votes 
)
private

Generate propose vote for provided block place (gossip) it.

Parameters
proposed_block
reward_votesfor proposed_block
Returns
true if successful, otherwise false

◆ generatePbftBlock()

std::optional< std::pair< std::shared_ptr< PbftBlock >, std::vector< std::shared_ptr< PbftVote > > > > taraxa::PbftManager::generatePbftBlock ( PbftPeriod  propose_period,
const blk_hash_t prev_blk_hash,
const blk_hash_t anchor_hash,
const blk_hash_t order_hash,
const std::optional< PbftBlockExtraData > &  extra_data 
)

Generate PBFT block, push into unverified queue, and broadcast to peers.

Parameters
propose_period
prev_blk_hashprevious PBFT block hash
anchor_hashproposed DAG pivot block hash for finalization
order_hashthe hash of all DAG blocks include in the PBFT block
extra_dataoptional extra_data
Returns
optional<pair<PBFT block, PBFT block reward votes>>

◆ getCurrentDposTotalVotesCount()

std::optional< uint64_t > taraxa::PbftManager::getCurrentDposTotalVotesCount ( ) const

Get current total DPOS votes count.

Returns
current total DPOS votes count if successful, otherwise (due to non-existent data for pbft_period) empty optional

◆ getCurrentNodeVotesCount()

std::optional< uint64_t > taraxa::PbftManager::getCurrentNodeVotesCount ( ) const

Get current node DPOS votes count.

Returns
node current DPOS votes count if successful, otherwise (due to non-existent data for pbft_period) empty optional

◆ getDagBlockPeriod()

std::pair< bool, PbftPeriod > taraxa::PbftManager::getDagBlockPeriod ( const blk_hash_t hash)

Get a DAG block period number.

Parameters
hashDAG block hash
Returns
true with DAG block period number if the DAG block has been finalized. Otherwise return false

◆ getLastPbftBlockHash()

blk_hash_t taraxa::PbftManager::getLastPbftBlockHash ( )

◆ getPbftCommitteeSize()

size_t taraxa::PbftManager::getPbftCommitteeSize ( ) const
inline

Get PBFT committee size.

Returns
PBFT committee size

◆ getPbftInitialLambda()

std::chrono::milliseconds taraxa::PbftManager::getPbftInitialLambda ( ) const
inline

Get PBFT lambda. PBFT lambda is a timer clock.

Returns
PBFT lambda

◆ getPbftPeriod()

PbftPeriod taraxa::PbftManager::getPbftPeriod ( ) const

Get current PBFT period number.

Returns
current PBFT period

◆ getPbftProposedBlock()

std::shared_ptr< PbftBlock > taraxa::PbftManager::getPbftProposedBlock ( PbftPeriod  period,
const blk_hash_t block_hash 
) const

Get a proposed PBFT block based on specified period and block hash.

Parameters
period
block_hash
Returns
std::shared_ptr<PbftBlock>

◆ getPbftRound()

PbftRound taraxa::PbftManager::getPbftRound ( ) const

Get current PBFT round number.

Returns
current PBFT round

◆ getPbftRoundAndPeriod()

std::pair< PbftRound, PbftPeriod > taraxa::PbftManager::getPbftRoundAndPeriod ( ) const

Get PBFT round & period number.

Returns
<PBFT round, PBFT period>

◆ getPbftStep()

PbftStep taraxa::PbftManager::getPbftStep ( ) const

Get PBFT step number.

Returns
PBFT step

◆ getProposal()

h256 taraxa::PbftManager::getProposal ( const std::shared_ptr< PbftVote > &  vote) const
private

Calculate the lowest hash of a vote by vote weight.

Parameters
votevote
Returns
lowest hash of a vote

◆ getValidPbftProposedBlock()

std::shared_ptr< PbftBlock > taraxa::PbftManager::getValidPbftProposedBlock ( PbftPeriod  period,
const blk_hash_t block_hash 
)
private

Get valid proposed pbft block. It will retrieve block from proposed_blocks and then validate it if not already validated.

Parameters
period
block_hash
Returns
valid proposed pbft block or nullptr

◆ gossipNewVote()

void taraxa::PbftManager::gossipNewVote ( const std::shared_ptr< PbftVote > &  vote,
const std::shared_ptr< PbftBlock > &  voted_block 
)
private

Gossips newly generated vote to the other peers.

Parameters
vote
voted_block

◆ gossipVote()

void taraxa::PbftManager::gossipVote ( const std::shared_ptr< PbftVote > &  vote,
const std::shared_ptr< PbftBlock > &  voted_block 
)

Gossips vote to the other peers.

Parameters
vote
voted_block

◆ identifyBlock_()

void taraxa::PbftManager::identifyBlock_ ( )
private

PBFT filter state. PBFT step 2. Identify a leader block from all received proposed blocks for the current period, and place a soft vote at the leader block hash.

◆ identifyLeaderBlock_()

std::shared_ptr< PbftBlock > taraxa::PbftManager::identifyLeaderBlock_ ( PbftRound  round,
PbftPeriod  period 
)
private

Identify a leader block from all received proposed PBFT blocks for the current round by using minimum Verifiable Random Function (VRF) output. In filter state, don’t need check vote value correction.

Parameters
roundcurrent pbft round
periodnew pbft period (period == chain_size + 1)
Returns
shared_ptr to leader identified leader block

◆ initialState()

void taraxa::PbftManager::initialState ( )

Initial PBFT states when node start PBFT.

◆ lastPbftBlockHashFromQueueOrChain()

blk_hash_t taraxa::PbftManager::lastPbftBlockHashFromQueueOrChain ( )

Get last pbft block hash from queue or if queue empty, from chain.

Returns
last block hash

◆ loopBackFinishState_()

void taraxa::PbftManager::loopBackFinishState_ ( )
private

Set back to PBFT finish state from PBFT finish polling state.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ pbftSyncingPeriod()

PbftPeriod taraxa::PbftManager::pbftSyncingPeriod ( ) const

Get PBFT blocks synced period.

Returns
PBFT blocks synced period

◆ periodDataQueueEmpty()

bool taraxa::PbftManager::periodDataQueueEmpty ( ) const

Returns true if queue is empty.

Returns

◆ periodDataQueuePush()

void taraxa::PbftManager::periodDataQueuePush ( PeriodData &&  period_data,
dev::p2p::NodeID const &  node_id,
std::vector< std::shared_ptr< PbftVote >> &&  current_block_cert_votes 
)

Push synced period data in syncing queue.

Parameters
blocksynced period data from peer
current_block_cert_votescert votes for PeriodData pbft block period
node_idpeer node ID

◆ periodDataQueueSize()

size_t taraxa::PbftManager::periodDataQueueSize ( ) const

Get PBFT blocks syncing queue size.

Returns
PBFT syncing queue size

◆ placeVote()

bool taraxa::PbftManager::placeVote ( const std::shared_ptr< PbftVote > &  vote,
std::string_view  log_vote_id,
const std::shared_ptr< PbftBlock > &  voted_block 
)
private

Place (gossip) vote.

Parameters
vote
log_vote_idvote identifier for log msg
voted_blockvoted block object - should be == vote->voted_block. In case we dont have block object, nullptr is provided

◆ printVotingSummary()

void taraxa::PbftManager::printVotingSummary ( ) const
private

Prints all votes generated by node in current round.

◆ processPeriodData()

std::optional< std::pair< PeriodData, std::vector< std::shared_ptr< PbftVote > > > > taraxa::PbftManager::processPeriodData ( )
private

Process synced PBFT blocks if PBFT syncing queue is not empty.

Returns
period data with cert votes for the current period

◆ processPillarBlock()

void taraxa::PbftManager::processPillarBlock ( PbftPeriod  period)
private

Creates pillar block (and pillar vote in case node is eligible to vote & is not syncing)

Parameters
period

◆ processProposedBlock()

void taraxa::PbftManager::processProposedBlock ( const std::shared_ptr< PbftBlock > &  proposed_block,
const std::shared_ptr< PbftVote > &  propose_vote 
)

Push proposed block into the proposed_blocks_ in case it is not there yet.

Parameters
proposed_block
propose_vote

◆ proposeBlock_()

void taraxa::PbftManager::proposeBlock_ ( )
private

PBFT proposal state. PBFT step 1. Propose a PBFT block and place a proposal vote on the block hash.

◆ proposePbftBlock()

std::optional< std::pair< std::shared_ptr< PbftBlock >, std::vector< std::shared_ptr< PbftVote > > > > taraxa::PbftManager::proposePbftBlock ( )
private

Propose a new PBFT block.

Returns
optional<pair<PBFT block, PBFT block reward votes>> in case new block was proposed, otherwise empty optional

◆ pushCertVotedPbftBlockIntoChain_()

bool taraxa::PbftManager::pushCertVotedPbftBlockIntoChain_ ( const std::shared_ptr< PbftBlock > &  pbft_block,
std::vector< std::shared_ptr< PbftVote >> &&  current_round_cert_votes 
)
private

If there are enough certify votes, push the vote PBFT block in PBFT chain.

Parameters
pbft_blockPBFT block
current_round_cert_votescertify votes
Returns
true if push a new PBFT block in chain

◆ pushPbftBlock_()

bool taraxa::PbftManager::pushPbftBlock_ ( PeriodData &&  period_data,
std::vector< std::shared_ptr< PbftVote >> &&  cert_votes 
)
private

Push a new PBFT block into the PBFT chain.

Parameters
period_dataPBFT block, cert votes for previous period, DAG blocks, and transactions
cert_votescert votes for pbft block period
Returns
true if push a new PBFT block into the PBFT chain

◆ pushSyncedPbftBlocksIntoChain()

void taraxa::PbftManager::pushSyncedPbftBlocksIntoChain ( )

Check PBFT blocks syncing queue. If there are synced PBFT blocks in queue, push it to PBFT chain.

◆ reorderTransactions()

void taraxa::PbftManager::reorderTransactions ( SharedTransactions transactions)
static

Reorder transactions data if DAG reordering caused transactions with same sender to have nonce in incorrect order. Reordering is deterministic so that same order is produced on any node on any platform.

Parameters
transactionstransactions to reorder

◆ resetPbftConsensus()

void taraxa::PbftManager::resetPbftConsensus ( PbftRound  round)
private

Resets pbft consensus: current pbft round is set to round, step is set to the beginning value.

Parameters
round

◆ resetStep()

void taraxa::PbftManager::resetStep ( )
private

Reset PBFT step to 1.

◆ run()

void taraxa::PbftManager::run ( )

Run PBFT daemon.

◆ secondFinish_()

void taraxa::PbftManager::secondFinish_ ( )
private

PBFT finish polling state: Happens at odd number steps from step 5. Place a next vote at finishing value for the current PBFT round.

◆ setCertifyState_()

void taraxa::PbftManager::setCertifyState_ ( )
private

Set PBFT certify state.

◆ setFilterState_()

void taraxa::PbftManager::setFilterState_ ( )
private

Set PBFT filter state.

◆ setFinishPollingState_()

void taraxa::PbftManager::setFinishPollingState_ ( )
private

Set PBFT finish polling state.

◆ setFinishState_()

void taraxa::PbftManager::setFinishState_ ( )
private

Set PBFT finish state.

◆ setNetwork()

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

Set network as a weak pointer.

Parameters
networka weak pinter

◆ setPbftRound()

void taraxa::PbftManager::setPbftRound ( PbftRound  round)

Set PBFT round number.

Parameters
roundPBFT round

◆ setPbftStep()

void taraxa::PbftManager::setPbftStep ( PbftStep  pbft_step)

Set PBFT step.

Parameters
pbft_stepPBFT step

◆ sleep_()

void taraxa::PbftManager::sleep_ ( )
private

Time to sleep for PBFT protocol.

◆ start()

void taraxa::PbftManager::start ( )

Start PBFT daemon.

◆ stateOperations_()

bool taraxa::PbftManager::stateOperations_ ( )
private

If there are any synced PBFT blocks from peers, push the synced blocks in PBFT chain. Verify all received incoming votes. If there are enough certify votes, push voting PBFT block in PBFT chain.

Returns
true if there are enough certify votes voting on a new PBFT block, or PBFT goes to a forward round

◆ stop()

void taraxa::PbftManager::stop ( )

Stop PBFT daemon.

◆ testBroadcastVotesFunctionality()

void taraxa::PbftManager::testBroadcastVotesFunctionality ( )

Test/enforce broadcastVotes() to actually send votes.

◆ tryPushCertVotesBlock()

bool taraxa::PbftManager::tryPushCertVotesBlock ( )
private

Check if there is 2t+1 cert votes for some valid block, if yes - push it into the chain.

Returns
true if new cert voted block was pushed into the chain, otherwise false

◆ validateFinalChainHash()

PbftStateRootValidation taraxa::PbftManager::validateFinalChainHash ( const std::shared_ptr< PbftBlock > &  pbft_block) const
private

Validates pbft block final chain hash.

Parameters
pbft_blockPBFT block
Returns
validation result

◆ validatePbftBlock()

bool taraxa::PbftManager::validatePbftBlock ( const std::shared_ptr< PbftBlock > &  pbft_block) const
private

Validates pbft block. It checks if:

  • pbft_block's previous pbft block hash == node's latest finalized pbft block
  • node has all DAG blocks with correct ordering,
  • node has all reward votes
  • total gas estimation is not greater than gas limit
    Parameters
    pbft_blockPBFT block
    Returns
    true if pbft block is valid, otherwise false

◆ validatePbftBlockCertVotes()

bool taraxa::PbftManager::validatePbftBlockCertVotes ( const std::shared_ptr< PbftBlock pbft_block,
const std::vector< std::shared_ptr< PbftVote >> &  cert_votes 
) const
private

Validates PBFT block cert votes.

Parameters
pbft_block
cert_votes
Returns
true if there is enough(2t+1) votes and all of them are valid, otherwise false

◆ validatePbftBlockExtraData()

bool taraxa::PbftManager::validatePbftBlockExtraData ( const std::shared_ptr< PbftBlock > &  pbft_block) const
private

Validates pbft block extra data presence:

  • checks if extra data is present or not based on pbft block number and ficus hf block number
  • checks if pillar block hash is present on not during specific pbft periods
Parameters
pbft_block
Returns
true if valid, otherwise false

◆ validatePbftBlockPillarVotes()

bool taraxa::PbftManager::validatePbftBlockPillarVotes ( const PeriodData period_data) const
private

Validates PBFT block pillar votes.

Parameters
period_data
Returns

◆ validatePillarDataInPeriodData()

bool taraxa::PbftManager::validatePillarDataInPeriodData ( const PeriodData period_data) const

Validates pbft block extra data presence + pillar votes presence based on pbft block number and ficus hf block number.

Note
See validatePbftBlockExtraData description, it is called inside
Parameters
period_data
Returns
true if valid, otherwise false

◆ waitForPeriodFinalization()

void taraxa::PbftManager::waitForPeriodFinalization ( )

wait for DPOS period finalization

Member Data Documentation

◆ already_next_voted_null_block_hash_

bool taraxa::PbftManager::already_next_voted_null_block_hash_ = false
private

◆ already_next_voted_value_

bool taraxa::PbftManager::already_next_voted_value_ = false
private

◆ anchor_dag_block_order_cache_

std::unordered_map<blk_hash_t, std::vector<DagBlock> > taraxa::PbftManager::anchor_dag_block_order_cache_
mutableprivate

◆ broadcast_reward_votes_counter_

uint32_t taraxa::PbftManager::broadcast_reward_votes_counter_ = 1
private

◆ broadcast_votes_counter_

uint32_t taraxa::PbftManager::broadcast_votes_counter_ = 1
private

◆ cert_voted_block_for_round_

std::optional<std::shared_ptr<PbftBlock> > taraxa::PbftManager::cert_voted_block_for_round_ {}
private

◆ current_period_start_datetime_

time_point taraxa::PbftManager::current_period_start_datetime_
private

◆ current_round_broadcasted_votes_

std::map<blk_hash_t, std::vector<PbftStep> > taraxa::PbftManager::current_round_broadcasted_votes_
private

◆ current_round_start_datetime_

time_point taraxa::PbftManager::current_round_start_datetime_
private

◆ daemon_

std::unique_ptr<std::thread> taraxa::PbftManager::daemon_
private

◆ dag_genesis_block_hash_

const blk_hash_t taraxa::PbftManager::dag_genesis_block_hash_
private

◆ dag_mgr_

std::shared_ptr<DagManager> taraxa::PbftManager::dag_mgr_
private

◆ db_

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

◆ executed_pbft_block_

bool taraxa::PbftManager::executed_pbft_block_ = false
private

◆ final_chain_

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

◆ go_finish_state_

bool taraxa::PbftManager::go_finish_state_ = false
private

◆ kBroadcastVotesLambdaTime

const uint32_t taraxa::PbftManager::kBroadcastVotesLambdaTime = 20
private

◆ kGenesisConfig

const GenesisConfig& taraxa::PbftManager::kGenesisConfig
private

◆ kMaxLambda

const std::chrono::milliseconds taraxa::PbftManager::kMaxLambda {60000}
private

◆ kMinLambda

const std::chrono::milliseconds taraxa::PbftManager::kMinLambda
private

◆ kRebroadcastVotesLambdaTime

const uint32_t taraxa::PbftManager::kRebroadcastVotesLambdaTime = 60
private

◆ lambda_

std::chrono::milliseconds taraxa::PbftManager::lambda_ {0}
private

◆ last_placed_pillar_vote_period_

PbftPeriod taraxa::PbftManager::last_placed_pillar_vote_period_ = 0
private

◆ loop_back_finish_state_

bool taraxa::PbftManager::loop_back_finish_state_ = false
private

◆ network_

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

◆ next_step_time_ms_

std::chrono::milliseconds taraxa::PbftManager::next_step_time_ms_ {0}
private

◆ node_addr_

const addr_t taraxa::PbftManager::node_addr_
private

◆ node_sk_

const secret_t taraxa::PbftManager::node_sk_
private

◆ pbft_chain_

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

◆ pillar_chain_mgr_

std::shared_ptr<pillar_chain::PillarChainManager> taraxa::PbftManager::pillar_chain_mgr_
private

◆ printCertStepInfo_

bool taraxa::PbftManager::printCertStepInfo_ = true
private

◆ printSecondFinishStepInfo_

bool taraxa::PbftManager::printSecondFinishStepInfo_ = true
private

◆ proposed_blocks_

ProposedBlocks taraxa::PbftManager::proposed_blocks_
private

◆ rebroadcast_reward_votes_counter_

uint32_t taraxa::PbftManager::rebroadcast_reward_votes_counter_ = 1
private

◆ rebroadcast_votes_counter_

uint32_t taraxa::PbftManager::rebroadcast_votes_counter_ = 1
private

◆ round_

std::atomic<PbftRound> taraxa::PbftManager::round_ = 1
private

◆ second_finish_step_start_datetime_

time_point taraxa::PbftManager::second_finish_step_start_datetime_
private

◆ state_

PbftStates taraxa::PbftManager::state_ = value_proposal_state
private

◆ step_

PbftStep taraxa::PbftManager::step_ = 1
private

◆ stop_cv_

std::condition_variable taraxa::PbftManager::stop_cv_
private

◆ stop_mtx_

std::mutex taraxa::PbftManager::stop_mtx_
private

◆ stopped_

std::atomic<bool> taraxa::PbftManager::stopped_ = true
private

◆ sync_queue_

PeriodDataQueue taraxa::PbftManager::sync_queue_
private

◆ trx_mgr_

std::shared_ptr<TransactionManager> taraxa::PbftManager::trx_mgr_
private

◆ vote_mgr_

std::shared_ptr<VoteManager> taraxa::PbftManager::vote_mgr_
private

◆ taraxa::PeriodDataQueue

class taraxa::PeriodDataQueue

PeriodDataQueue class is a syncing queue, the queue stores blocks synced from peers.

Public Member Functions

 PeriodDataQueue ()=default
 
bool push (PeriodData &&period_data, const dev::p2p::NodeID &node_id, uint64_t max_pbft_size, std::vector< std::shared_ptr< PbftVote >> &&cert_votes)
 Push a synced block in queue. More...
 
std::tuple< PeriodData, std::vector< std::shared_ptr< PbftVote > >, dev::p2p::NodeIDpop ()
 Pop the first block from syncing queue. More...
 
void clear ()
 Clear the syncing queue and reset period to 0. More...
 
size_t size () const
 Get the syncing queue size. More...
 
bool empty () const
 Return true if the queue is empty. More...
 
uint64_t getPeriod () const
 Get period number of the last synced block in queue. More...
 
std::shared_ptr< PbftBlocklastPbftBlock () const
 Get last pbft block from queue. More...
 
void cleanOldData (uint64_t period)
 Clean any old blocks below current period. More...
 

Private Attributes

std::deque< std::pair< PeriodData, dev::p2p::NodeID > > queue_
 
uint64_t period_ {0}
 
std::shared_mutex queue_access_
 
std::vector< std::shared_ptr< PbftVote > > last_block_cert_votes_
 

Constructor & Destructor Documentation

◆ PeriodDataQueue()

taraxa::PeriodDataQueue::PeriodDataQueue ( )
default

Member Function Documentation

◆ cleanOldData()

void taraxa::PeriodDataQueue::cleanOldData ( uint64_t  period)

Clean any old blocks below current period.

Parameters
periodcurrent period

◆ clear()

void taraxa::PeriodDataQueue::clear ( )

Clear the syncing queue and reset period to 0.

◆ empty()

bool taraxa::PeriodDataQueue::empty ( ) const

Return true if the queue is empty.

Returns

◆ getPeriod()

uint64_t taraxa::PeriodDataQueue::getPeriod ( ) const

Get period number of the last synced block in queue.

Returns
period number of the last synced block in queue. If syncing queue is empty, return 0

◆ lastPbftBlock()

std::shared_ptr< PbftBlock > taraxa::PeriodDataQueue::lastPbftBlock ( ) const

Get last pbft block from queue.

Returns
last block or nullptr if queue empty

◆ pop()

std::tuple< PeriodData, std::vector< std::shared_ptr< PbftVote > >, dev::p2p::NodeID > taraxa::PeriodDataQueue::pop ( )

Pop the first block from syncing queue.

Returns
the first block, votes for the block if they are available and peer node ID

◆ push()

bool taraxa::PeriodDataQueue::push ( PeriodData &&  period_data,
const dev::p2p::NodeID node_id,
uint64_t  max_pbft_size,
std::vector< std::shared_ptr< PbftVote >> &&  cert_votes 
)

Push a synced block in queue.

Parameters
period_dataperiod_data synced from peer
node_idpeer node ID
max_pbft_sizemaximum PBFT chain size
cert_votescert votes
Returns
true if pushed

◆ size()

size_t taraxa::PeriodDataQueue::size ( ) const

Get the syncing queue size.

Returns
syncing queue size

Member Data Documentation

◆ last_block_cert_votes_

std::vector<std::shared_ptr<PbftVote> > taraxa::PeriodDataQueue::last_block_cert_votes_
private

◆ period_

uint64_t taraxa::PeriodDataQueue::period_ {0}
private

◆ queue_

std::deque<std::pair<PeriodData, dev::p2p::NodeID> > taraxa::PeriodDataQueue::queue_
private

◆ queue_access_

std::shared_mutex taraxa::PeriodDataQueue::queue_access_
mutableprivate

◆ taraxa::PbftBlock

class taraxa::PbftBlock

The PbftBlock class is a PBFT block class that includes PBFT block hash, previous PBFT block hash, DAG anchor hash, DAG blocks ordering hash, period number, timestamp, proposer address, and proposer signature.

Collaboration diagram for taraxa::PbftBlock:

Public Member Functions

 PbftBlock (const blk_hash_t &prev_blk_hash, const blk_hash_t &dag_blk_hash_as_pivot, const blk_hash_t &order_hash, const blk_hash_t &final_chain_hash, PbftPeriod period, const addr_t &beneficiary, const secret_t &sk, std::vector< vote_hash_t > &&reward_votes, const std::optional< PbftBlockExtraData > &extra_data={})
 
 PbftBlock (const dev::RLP &rlp)
 
 PbftBlock (const bytes &RLP)
 
blk_hash_t sha3 (bool include_sig) const
 Secure Hash Algorithm 3. More...
 
std::string getJsonStr () const
 Get PBFT block in string. More...
 
Json::Value getJson () const
 Get PBFT block in JSON. More...
 
void streamRLP (dev::RLPStream &strm, bool include_sig) const
 Stream RLP uses to setup PBFT block hash. More...
 
bytes rlp (bool include_sig) const
 Recursive Length Prefix. More...
 
const auto & getBlockHash () const
 Get PBFT block hash. More...
 
const auto & getPrevBlockHash () const
 Get previous PBFT block hash. More...
 
const auto & getPivotDagBlockHash () const
 Get DAG anchor hash for the finalized PBFT block. More...
 
const auto & getOrderHash () const
 Get DAG blocks ordering hash. More...
 
const auto & getFinalChainHash () const
 Get final chain hash to tie final chain to the PBFT chain. More...
 
PbftPeriod getPeriod () const
 Get period number. More...
 
auto getTimestamp () const
 Get timestamp. More...
 
auto getExtraData () const
 Get extra data. More...
 
auto getExtraDataRlp () const
 Get extra data rlp. More...
 
const auto & getBeneficiary () const
 Get PBFT block proposer address. More...
 
const auto & getRewardVotes () const
 

Static Public Member Functions

static Json::Value toJson (const PbftBlock &b, const std::vector< blk_hash_t > &dag_blks)
 Get PBFT block with DAG blocks in JSON. More...
 

Private Member Functions

void calculateHash_ ()
 Set PBFT block hash and block proposer address. More...
 
void checkUniqueRewardVotes ()
 Check if all rewards votes are unique. More...
 

Private Attributes

blk_hash_t block_hash_
 
blk_hash_t prev_block_hash_
 
blk_hash_t dag_block_hash_as_pivot_
 
blk_hash_t order_hash_
 
blk_hash_t final_chain_hash_
 
PbftPeriod period_
 
uint64_t timestamp_
 
addr_t beneficiary_
 
sig_t signature_
 
std::vector< vote_hash_treward_votes_
 
std::optional< PbftBlockExtraDataextra_data_
 

Constructor & Destructor Documentation

◆ PbftBlock() [1/3]

taraxa::PbftBlock::PbftBlock ( const blk_hash_t prev_blk_hash,
const blk_hash_t dag_blk_hash_as_pivot,
const blk_hash_t order_hash,
const blk_hash_t final_chain_hash,
PbftPeriod  period,
const addr_t beneficiary,
const secret_t sk,
std::vector< vote_hash_t > &&  reward_votes,
const std::optional< PbftBlockExtraData > &  extra_data = {} 
)

◆ PbftBlock() [2/3]

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

◆ PbftBlock() [3/3]

taraxa::PbftBlock::PbftBlock ( const bytes RLP)
explicit

Member Function Documentation

◆ calculateHash_()

void taraxa::PbftBlock::calculateHash_ ( )
private

Set PBFT block hash and block proposer address.

◆ checkUniqueRewardVotes()

void taraxa::PbftBlock::checkUniqueRewardVotes ( )
private

Check if all rewards votes are unique.

◆ getBeneficiary()

const auto& taraxa::PbftBlock::getBeneficiary ( ) const
inline

Get PBFT block proposer address.

Returns
PBFT block proposer address

◆ getBlockHash()

const auto& taraxa::PbftBlock::getBlockHash ( ) const
inline

Get PBFT block hash.

Returns
PBFT block hash

◆ getExtraData()

auto taraxa::PbftBlock::getExtraData ( ) const
inline

Get extra data.

Returns
extra data

◆ getExtraDataRlp()

auto taraxa::PbftBlock::getExtraDataRlp ( ) const
inline

Get extra data rlp.

Returns
extra data rlp

◆ getFinalChainHash()

const auto& taraxa::PbftBlock::getFinalChainHash ( ) const
inline

Get final chain hash to tie final chain to the PBFT chain.

Returns
final chain hash

◆ getJson()

Json::Value taraxa::PbftBlock::getJson ( ) const

Get PBFT block in JSON.

Returns
PBFT block in JSON

◆ getJsonStr()

std::string taraxa::PbftBlock::getJsonStr ( ) const

Get PBFT block in string.

Returns
PBFT block in string

◆ getOrderHash()

const auto& taraxa::PbftBlock::getOrderHash ( ) const
inline

Get DAG blocks ordering hash.

Returns
DAG blocks ordering hash

◆ getPeriod()

PbftPeriod taraxa::PbftBlock::getPeriod ( ) const
inline

Get period number.

Returns
period number

◆ getPivotDagBlockHash()

const auto& taraxa::PbftBlock::getPivotDagBlockHash ( ) const
inline

Get DAG anchor hash for the finalized PBFT block.

Returns
DAG anchor hash

◆ getPrevBlockHash()

const auto& taraxa::PbftBlock::getPrevBlockHash ( ) const
inline

Get previous PBFT block hash.

Returns
previous PBFT block hash

◆ getRewardVotes()

const auto& taraxa::PbftBlock::getRewardVotes ( ) const
inline

◆ getTimestamp()

auto taraxa::PbftBlock::getTimestamp ( ) const
inline

Get timestamp.

Returns
timestamp

◆ rlp()

bytes taraxa::PbftBlock::rlp ( bool  include_sig) const

Recursive Length Prefix.

Parameters
include_sigif include signature
Returns
bytes of RLP stream

◆ sha3()

blk_hash_t taraxa::PbftBlock::sha3 ( bool  include_sig) const

Secure Hash Algorithm 3.

Parameters
include_sigif include signature
Returns
secure hash as PBFT block hash

◆ streamRLP()

void taraxa::PbftBlock::streamRLP ( dev::RLPStream strm,
bool  include_sig 
) const

Stream RLP uses to setup PBFT block hash.

Parameters
strmRLP stream
include_sigif include signature

◆ toJson()

Json::Value taraxa::PbftBlock::toJson ( const PbftBlock b,
const std::vector< blk_hash_t > &  dag_blks 
)
static

Get PBFT block with DAG blocks in JSON.

Parameters
bPBFT block
dag_blksDAG blocks hashes
Returns
PBFT block with DAG blocks in JSON

Member Data Documentation

◆ beneficiary_

addr_t taraxa::PbftBlock::beneficiary_
private

◆ block_hash_

blk_hash_t taraxa::PbftBlock::block_hash_
private

◆ dag_block_hash_as_pivot_

blk_hash_t taraxa::PbftBlock::dag_block_hash_as_pivot_
private

◆ extra_data_

std::optional<PbftBlockExtraData> taraxa::PbftBlock::extra_data_
private

◆ final_chain_hash_

blk_hash_t taraxa::PbftBlock::final_chain_hash_
private

◆ order_hash_

blk_hash_t taraxa::PbftBlock::order_hash_
private

◆ period_

PbftPeriod taraxa::PbftBlock::period_
private

◆ prev_block_hash_

blk_hash_t taraxa::PbftBlock::prev_block_hash_
private

◆ reward_votes_

std::vector<vote_hash_t> taraxa::PbftBlock::reward_votes_
private

◆ signature_

sig_t taraxa::PbftBlock::signature_
private

◆ timestamp_

uint64_t taraxa::PbftBlock::timestamp_
private

◆ taraxa::PbftBlockExtraData

class taraxa::PbftBlockExtraData
Collaboration diagram for taraxa::PbftBlockExtraData:

Public Member Functions

 PbftBlockExtraData ()
 
 PbftBlockExtraData (const uint16_t major_version, const uint16_t minor_version, const uint16_t patch_version, const uint16_t net_version, const std::string node_implementation, const std::optional< blk_hash_t > &pillar_block_hash)
 
bytes rlp () const
 Get rlp. More...
 
Json::Value getJson () const
 Get JSON. More...
 
std::optional< blk_hash_tgetPillarBlockHash () const
 

Static Public Member Functions

static std::optional< PbftBlockExtraDatafromBytes (const bytes &data)
 

Private Attributes

uint16_t major_version_
 
uint16_t minor_version_
 
uint16_t patch_version_
 
uint16_t net_version_
 
std::string node_implementation_
 
std::optional< blk_hash_tpillar_block_hash_
 

Static Private Attributes

static constexpr uint32_t kExtraDataMaxSize = 1024
 

Constructor & Destructor Documentation

◆ PbftBlockExtraData() [1/2]

taraxa::PbftBlockExtraData::PbftBlockExtraData ( )
inline

◆ PbftBlockExtraData() [2/2]

taraxa::PbftBlockExtraData::PbftBlockExtraData ( const uint16_t  major_version,
const uint16_t  minor_version,
const uint16_t  patch_version,
const uint16_t  net_version,
const std::string  node_implementation,
const std::optional< blk_hash_t > &  pillar_block_hash 
)

Member Function Documentation

◆ fromBytes()

std::optional< PbftBlockExtraData > taraxa::PbftBlockExtraData::fromBytes ( const bytes data)
static

◆ getJson()

Json::Value taraxa::PbftBlockExtraData::getJson ( ) const

Get JSON.

Returns
Json

◆ getPillarBlockHash()

std::optional< blk_hash_t > taraxa::PbftBlockExtraData::getPillarBlockHash ( ) const
Returns
pillar bock hash

◆ rlp()

bytes taraxa::PbftBlockExtraData::rlp ( ) const

Get rlp.

Returns
rlp

Member Data Documentation

◆ kExtraDataMaxSize

constexpr uint32_t taraxa::PbftBlockExtraData::kExtraDataMaxSize = 1024
staticconstexprprivate

◆ major_version_

uint16_t taraxa::PbftBlockExtraData::major_version_
private

◆ minor_version_

uint16_t taraxa::PbftBlockExtraData::minor_version_
private

◆ net_version_

uint16_t taraxa::PbftBlockExtraData::net_version_
private

◆ node_implementation_

std::string taraxa::PbftBlockExtraData::node_implementation_
private

◆ patch_version_

uint16_t taraxa::PbftBlockExtraData::patch_version_
private

◆ pillar_block_hash_

std::optional<blk_hash_t> taraxa::PbftBlockExtraData::pillar_block_hash_
private

◆ taraxa::PeriodData

class taraxa::PeriodData

PeriodData class is for block execution, that includes PBFT block, certify votes, DAG blocks, and transactions.

Collaboration diagram for taraxa::PeriodData:

Public Member Functions

 PeriodData ()=default
 
 PeriodData (std::shared_ptr< PbftBlock > pbft_blk, const std::vector< std::shared_ptr< PbftVote >> &previous_block_cert_votes, std::optional< std::vector< std::shared_ptr< PillarVote >>> &&pillar_votes={})
 
 PeriodData (const dev::RLP &all_rlp)
 
 PeriodData (const bytes &all_rlp)
 
bytes rlp () const
 Recursive Length Prefix. More...
 
void clear ()
 Clear PBFT block, certify votes, DAG blocks, and transactions. More...
 

Static Public Member Functions

static PeriodData FromOldPeriodData (const dev::RLP &rlp)
 
static bytes ToOldPeriodData (const bytes &rlp)
 

Public Attributes

std::shared_ptr< PbftBlockpbft_blk
 
std::vector< std::shared_ptr< PbftVote > > previous_block_cert_votes
 
std::vector< DagBlockdag_blocks
 
SharedTransactions transactions
 
std::optional< std::vector< std::shared_ptr< PillarVote > > > pillar_votes_
 

Static Public Attributes

constexpr static size_t kBaseRlpItemCount = 4
 
constexpr static size_t kExtendedRlpItemCount = 5
 

Constructor & Destructor Documentation

◆ PeriodData() [1/4]

taraxa::PeriodData::PeriodData ( )
default

◆ PeriodData() [2/4]

taraxa::PeriodData::PeriodData ( std::shared_ptr< PbftBlock pbft_blk,
const std::vector< std::shared_ptr< PbftVote >> &  previous_block_cert_votes,
std::optional< std::vector< std::shared_ptr< PillarVote >>> &&  pillar_votes = {} 
)

◆ PeriodData() [3/4]

taraxa::PeriodData::PeriodData ( const dev::RLP all_rlp)
explicit

◆ PeriodData() [4/4]

taraxa::PeriodData::PeriodData ( const bytes all_rlp)
explicit

Member Function Documentation

◆ clear()

void taraxa::PeriodData::clear ( )

Clear PBFT block, certify votes, DAG blocks, and transactions.

◆ FromOldPeriodData()

PeriodData taraxa::PeriodData::FromOldPeriodData ( const dev::RLP rlp)
static

◆ rlp()

bytes taraxa::PeriodData::rlp ( ) const

Recursive Length Prefix.

Returns
bytes of RLP stream

◆ ToOldPeriodData()

bytes taraxa::PeriodData::ToOldPeriodData ( const bytes rlp)
static

Member Data Documentation

◆ dag_blocks

std::vector<DagBlock> taraxa::PeriodData::dag_blocks

◆ kBaseRlpItemCount

constexpr static size_t taraxa::PeriodData::kBaseRlpItemCount = 4
staticconstexpr

◆ kExtendedRlpItemCount

constexpr static size_t taraxa::PeriodData::kExtendedRlpItemCount = 5
staticconstexpr

◆ pbft_blk

std::shared_ptr<PbftBlock> taraxa::PeriodData::pbft_blk

◆ pillar_votes_

std::optional<std::vector<std::shared_ptr<PillarVote> > > taraxa::PeriodData::pillar_votes_

◆ previous_block_cert_votes

std::vector<std::shared_ptr<PbftVote> > taraxa::PeriodData::previous_block_cert_votes

◆ transactions

SharedTransactions taraxa::PeriodData::transactions

Enumeration Type Documentation

◆ PbftStateRootValidation

Enumerator
Valid 
Missing 
Invalid 

◆ PbftStates

Enumerator
value_proposal_state 
filter_state 
certify_state 
finish_state 
finish_polling_state 

Function Documentation

◆ operator<<() [1/3]

std::ostream & taraxa::operator<< ( std::ostream &  strm,
const PbftBlock pbft_blk 
)

◆ operator<<() [2/3]

std::ostream & taraxa::operator<< ( std::ostream &  strm,
PbftChain const &  pbft_chain 
)

◆ operator<<() [3/3]

std::ostream & taraxa::operator<< ( std::ostream &  strm,
PeriodData const &  b 
)