TARAXA
|
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) |
class taraxa::PbftChain |
PbftChain class is a single linked list that contains finalized PBFT blocks.
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< DbStorage > | db_ = nullptr |
bool taraxa::PbftChain::checkPbftBlockValidation | ( | const std::shared_ptr< PbftBlock > & | pbft_block | ) | const |
Verify a PBFT block.
pbft_block | PBFT block |
bool taraxa::PbftChain::findPbftBlockInChain | ( | taraxa::blk_hash_t const & | pbft_block_hash | ) |
Find a PBFT block in chain.
pbft_block_hash | PBFT block hash |
blk_hash_t taraxa::PbftChain::getHeadHash | ( | ) | const |
Get PBFT chain head hash.
std::string taraxa::PbftChain::getJsonStr | ( | ) | const |
Get PBFT chain head block in JSON string.
std::string taraxa::PbftChain::getJsonStrForBlock | ( | blk_hash_t const & | block_hash, |
bool | null_anchor | ||
) | const |
Get PBFT chain head block in JSON string.
block_hash | last PBFT block hash |
null_anchor | if the PBFT block include an empty DAG anchor |
blk_hash_t taraxa::PbftChain::getLastNonNullPbftBlockAnchor | ( | ) | const |
Get last non null PBFT block anchor.
blk_hash_t taraxa::PbftChain::getLastPbftBlockHash | ( | ) | const |
Get last PBFT block hash.
PbftBlock taraxa::PbftChain::getPbftBlockInChain | ( | blk_hash_t const & | pbft_block_hash | ) |
Get a PBFT block in chain.
pbft_block_hash | PBFT block hash |
PbftPeriod taraxa::PbftChain::getPbftChainSize | ( | ) | const |
Get PBFT chain size.
PbftPeriod taraxa::PbftChain::getPbftChainSizeExcludingEmptyPbftBlocks | ( | ) | const |
Get PBFT chain size excluding empty PBFT blocks.
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.
pbft_block_hash | last PBFT block hash |
anchor | DAG anchor hash |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
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.
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.
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 | |
PbftManager & | operator= (const PbftManager &)=delete |
PbftManager & | operator= (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, PbftPeriod > | getDagBlockPeriod (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, PbftPeriod > | getPbftRoundAndPeriod () 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 >> &¤t_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< PbftBlock > | getPbftProposedBlock (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< PbftBlockExtraData > | createPbftBlockExtraData (PbftPeriod pbft_period) const |
Creates pbft block extra data. More... | |
std::shared_ptr< PbftBlock > | identifyLeaderBlock_ (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 >> &¤t_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< PbftBlock > | getValidPbftProposedBlock (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< DbStorage > | db_ |
std::shared_ptr< PbftChain > | pbft_chain_ |
std::shared_ptr< VoteManager > | vote_mgr_ |
std::shared_ptr< DagManager > | dag_mgr_ |
std::weak_ptr< Network > | network_ |
std::shared_ptr< TransactionManager > | trx_mgr_ |
std::shared_ptr< final_chain::FinalChain > | final_chain_ |
std::shared_ptr< pillar_chain::PillarChainManager > | pillar_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< PbftRound > | round_ = 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 GenesisConfig & | kGenesisConfig |
std::condition_variable | stop_cv_ |
std::mutex | stop_mtx_ |
PeriodDataQueue | sync_queue_ |
ProposedBlocks | proposed_blocks_ |
using taraxa::PbftManager::time_point = std::chrono::system_clock::time_point |
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 | ||
) |
taraxa::PbftManager::~PbftManager | ( | ) |
|
delete |
|
delete |
|
private |
If node receives 2t+1 cert votes for some valid block and pushes it to the chain, advance period to + 1.
|
private |
If node receives 2t+1 next votes for some block(including kNullBlockHash), advance round to + 1.
|
private |
Broadcast or rebroadcast 2t+1 soft/reward/previous round next votes + all own votes if needed.
|
static |
Calculate DAG blocks ordering hash.
dag_block_hashes | DAG blocks hashes |
|
static |
Calculate DAG blocks ordering hash.
dag_blocks | DAG blocks |
|
private |
period |
|
private |
PBFT certify state. PBFT step 3. If receive enough soft votes and pass verification, place a cert vote at the value.
bool taraxa::PbftManager::checkBlockWeight | ( | const std::vector< DagBlock > & | dag_blocks | ) | const |
Check a block weight of gas estimation.
dag_blocks | dag blocks |
|
private |
Creates pbft block extra data.
pbft_period |
|
private |
start_time |
|
private |
Final chain executes a finalized PBFT block.
period_data | PBFT block, cert votes, DAG blocks, and transactions |
finalized_dag_blk_hashes | DAG blocks hashes |
synchronous_processing | wait for block finalization to finish |
|
private |
PBFT finish state. Happens at even number steps from step 4. Place a next vote at finishing value for the current PBFT round.
|
private |
Generate propose vote for provided block place (gossip) it.
proposed_block | |
reward_votes | for proposed_block |
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.
propose_period | |
prev_blk_hash | previous PBFT block hash |
anchor_hash | proposed DAG pivot block hash for finalization |
order_hash | the hash of all DAG blocks include in the PBFT block |
extra_data | optional extra_data |
std::optional< uint64_t > taraxa::PbftManager::getCurrentDposTotalVotesCount | ( | ) | const |
Get current total DPOS votes count.
std::optional< uint64_t > taraxa::PbftManager::getCurrentNodeVotesCount | ( | ) | const |
Get current node DPOS votes count.
std::pair< bool, PbftPeriod > taraxa::PbftManager::getDagBlockPeriod | ( | const blk_hash_t & | hash | ) |
Get a DAG block period number.
hash | DAG block hash |
blk_hash_t taraxa::PbftManager::getLastPbftBlockHash | ( | ) |
|
inline |
Get PBFT committee size.
|
inline |
Get PBFT lambda. PBFT lambda is a timer clock.
PbftPeriod taraxa::PbftManager::getPbftPeriod | ( | ) | const |
Get current PBFT period number.
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.
period | |
block_hash |
PbftRound taraxa::PbftManager::getPbftRound | ( | ) | const |
Get current PBFT round number.
std::pair< PbftRound, PbftPeriod > taraxa::PbftManager::getPbftRoundAndPeriod | ( | ) | const |
Get PBFT round & period number.
PbftStep taraxa::PbftManager::getPbftStep | ( | ) | const |
Get PBFT step number.
Calculate the lowest hash of a vote by vote weight.
vote | vote |
|
private |
Get valid proposed pbft block. It will retrieve block from proposed_blocks and then validate it if not already validated.
period | |
block_hash |
|
private |
Gossips newly generated vote to the other peers.
vote | |
voted_block |
void taraxa::PbftManager::gossipVote | ( | const std::shared_ptr< PbftVote > & | vote, |
const std::shared_ptr< PbftBlock > & | voted_block | ||
) |
Gossips vote to the other peers.
vote | |
voted_block |
|
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.
|
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.
round | current pbft round |
period | new pbft period (period == chain_size + 1) |
void taraxa::PbftManager::initialState | ( | ) |
Initial PBFT states when node start PBFT.
blk_hash_t taraxa::PbftManager::lastPbftBlockHashFromQueueOrChain | ( | ) |
Get last pbft block hash from queue or if queue empty, from chain.
|
private |
Set back to PBFT finish state from PBFT finish polling state.
|
delete |
|
delete |
PbftPeriod taraxa::PbftManager::pbftSyncingPeriod | ( | ) | const |
Get PBFT blocks synced period.
bool taraxa::PbftManager::periodDataQueueEmpty | ( | ) | const |
Returns true if queue is empty.
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.
block | synced period data from peer |
current_block_cert_votes | cert votes for PeriodData pbft block period |
node_id | peer node ID |
size_t taraxa::PbftManager::periodDataQueueSize | ( | ) | const |
Get PBFT blocks syncing queue size.
|
private |
Place (gossip) vote.
vote | |
log_vote_id | vote identifier for log msg |
voted_block | voted block object - should be == vote->voted_block. In case we dont have block object, nullptr is provided |
|
private |
Prints all votes generated by node in current round.
|
private |
Process synced PBFT blocks if PBFT syncing queue is not empty.
|
private |
Creates pillar block (and pillar vote in case node is eligible to vote & is not syncing)
period |
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.
proposed_block | |
propose_vote |
|
private |
PBFT proposal state. PBFT step 1. Propose a PBFT block and place a proposal vote on the block hash.
|
private |
Propose a new PBFT block.
|
private |
If there are enough certify votes, push the vote PBFT block in PBFT chain.
pbft_block | PBFT block |
current_round_cert_votes | certify votes |
|
private |
Push a new PBFT block into the PBFT chain.
period_data | PBFT block, cert votes for previous period, DAG blocks, and transactions |
cert_votes | cert votes for pbft block period |
void taraxa::PbftManager::pushSyncedPbftBlocksIntoChain | ( | ) |
Check PBFT blocks syncing queue. If there are synced PBFT blocks in queue, push it to PBFT chain.
|
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.
transactions | transactions to reorder |
|
private |
Resets pbft consensus: current pbft round is set to round, step is set to the beginning value.
round |
|
private |
Reset PBFT step to 1.
void taraxa::PbftManager::run | ( | ) |
Run PBFT daemon.
|
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.
|
private |
Set PBFT certify state.
|
private |
Set PBFT filter state.
|
private |
Set PBFT finish polling state.
|
private |
Set PBFT finish state.
void taraxa::PbftManager::setNetwork | ( | std::weak_ptr< Network > | network | ) |
Set network as a weak pointer.
network | a weak pinter |
void taraxa::PbftManager::setPbftRound | ( | PbftRound | round | ) |
Set PBFT round number.
round | PBFT round |
void taraxa::PbftManager::setPbftStep | ( | PbftStep | pbft_step | ) |
Set PBFT step.
pbft_step | PBFT step |
|
private |
Time to sleep for PBFT protocol.
void taraxa::PbftManager::start | ( | ) |
Start PBFT daemon.
|
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.
void taraxa::PbftManager::stop | ( | ) |
Stop PBFT daemon.
void taraxa::PbftManager::testBroadcastVotesFunctionality | ( | ) |
Test/enforce broadcastVotes() to actually send votes.
|
private |
Check if there is 2t+1 cert votes for some valid block, if yes - push it into the chain.
|
private |
Validates pbft block final chain hash.
pbft_block | PBFT block |
|
private |
Validates pbft block. It checks if:
pbft_block | PBFT block |
|
private |
Validates PBFT block cert votes.
pbft_block | |
cert_votes |
|
private |
Validates pbft block extra data presence:
pbft_block |
|
private |
Validates PBFT block pillar votes.
period_data |
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.
period_data |
void taraxa::PbftManager::waitForPeriodFinalization | ( | ) |
wait for DPOS period finalization
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
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::NodeID > | pop () |
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< PbftBlock > | lastPbftBlock () 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_ |
|
default |
void taraxa::PeriodDataQueue::cleanOldData | ( | uint64_t | period | ) |
Clean any old blocks below current period.
period | current period |
void taraxa::PeriodDataQueue::clear | ( | ) |
Clear the syncing queue and reset period to 0.
bool taraxa::PeriodDataQueue::empty | ( | ) | const |
Return true if the queue is empty.
uint64_t taraxa::PeriodDataQueue::getPeriod | ( | ) | const |
Get period number of the last synced block in queue.
std::shared_ptr< PbftBlock > taraxa::PeriodDataQueue::lastPbftBlock | ( | ) | const |
Get last pbft block from queue.
std::tuple< PeriodData, std::vector< std::shared_ptr< PbftVote > >, dev::p2p::NodeID > taraxa::PeriodDataQueue::pop | ( | ) |
Pop the first block from syncing queue.
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.
period_data | period_data synced from peer |
node_id | peer node ID |
max_pbft_size | maximum PBFT chain size |
cert_votes | cert votes |
size_t taraxa::PeriodDataQueue::size | ( | ) | const |
Get the syncing queue size.
|
private |
|
private |
|
private |
|
mutableprivate |
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.
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_t > | reward_votes_ |
std::optional< PbftBlockExtraData > | extra_data_ |
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 = {} |
||
) |
|
explicit |
|
explicit |
|
private |
Set PBFT block hash and block proposer address.
|
private |
Check if all rewards votes are unique.
|
inline |
Get PBFT block proposer address.
|
inline |
Get PBFT block hash.
|
inline |
Get extra data.
|
inline |
Get extra data rlp.
|
inline |
Get final chain hash to tie final chain to the PBFT chain.
Json::Value taraxa::PbftBlock::getJson | ( | ) | const |
Get PBFT block in JSON.
std::string taraxa::PbftBlock::getJsonStr | ( | ) | const |
Get PBFT block in string.
|
inline |
Get DAG blocks ordering hash.
|
inline |
Get period number.
|
inline |
Get DAG anchor hash for the finalized PBFT block.
|
inline |
Get previous PBFT block hash.
|
inline |
|
inline |
Get timestamp.
bytes taraxa::PbftBlock::rlp | ( | bool | include_sig | ) | const |
Recursive Length Prefix.
include_sig | if include signature |
blk_hash_t taraxa::PbftBlock::sha3 | ( | bool | include_sig | ) | const |
Secure Hash Algorithm 3.
include_sig | if include signature |
void taraxa::PbftBlock::streamRLP | ( | dev::RLPStream & | strm, |
bool | include_sig | ||
) | const |
Stream RLP uses to setup PBFT block hash.
strm | RLP stream |
include_sig | if include signature |
|
static |
Get PBFT block with DAG blocks in JSON.
b | PBFT block |
dag_blks | DAG blocks hashes |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
class 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_t > | getPillarBlockHash () const |
Static Public Member Functions | |
static std::optional< PbftBlockExtraData > | fromBytes (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_t > | pillar_block_hash_ |
Static Private Attributes | |
static constexpr uint32_t | kExtraDataMaxSize = 1024 |
|
inline |
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 | ||
) |
|
static |
Json::Value taraxa::PbftBlockExtraData::getJson | ( | ) | const |
Get JSON.
std::optional< blk_hash_t > taraxa::PbftBlockExtraData::getPillarBlockHash | ( | ) | const |
bytes taraxa::PbftBlockExtraData::rlp | ( | ) | const |
Get rlp.
|
staticconstexprprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
class taraxa::PeriodData |
PeriodData class is for block execution, that includes PBFT block, certify votes, DAG blocks, and transactions.
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< PbftBlock > | pbft_blk |
std::vector< std::shared_ptr< PbftVote > > | previous_block_cert_votes |
std::vector< DagBlock > | dag_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 |
|
default |
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 = {} |
||
) |
|
explicit |
|
explicit |
void taraxa::PeriodData::clear | ( | ) |
Clear PBFT block, certify votes, DAG blocks, and transactions.
|
static |
bytes taraxa::PeriodData::rlp | ( | ) | const |
Recursive Length Prefix.
std::vector<DagBlock> taraxa::PeriodData::dag_blocks |
|
staticconstexpr |
|
staticconstexpr |
std::shared_ptr<PbftBlock> taraxa::PeriodData::pbft_blk |
std::optional<std::vector<std::shared_ptr<PillarVote> > > taraxa::PeriodData::pillar_votes_ |
std::vector<std::shared_ptr<PbftVote> > taraxa::PeriodData::previous_block_cert_votes |
SharedTransactions taraxa::PeriodData::transactions |
|
strong |
enum taraxa::PbftStates |
std::ostream & taraxa::operator<< | ( | std::ostream & | strm, |
const PbftBlock & | pbft_blk | ||
) |
std::ostream & taraxa::operator<< | ( | std::ostream & | strm, |
PbftChain const & | pbft_chain | ||
) |
std::ostream & taraxa::operator<< | ( | std::ostream & | strm, |
PeriodData const & | b | ||
) |