TARAXA
PILLAR_CHAIN

Classes

class  taraxa::pillar_chain::PillarBlock
 PillarBlock contains merkle root of all finalized blocks created in the last epoch. More...
 
struct  taraxa::pillar_chain::PillarBlockData
 
struct  taraxa::pillar_chain::CurrentPillarBlockDataDb
 
class  taraxa::pillar_chain::PillarChainManager
 PillarChainMgr class contains functionality related to pillar chain. More...
 

Detailed Description


Class Documentation

◆ taraxa::pillar_chain::PillarBlock

class taraxa::pillar_chain::PillarBlock

PillarBlock contains merkle root of all finalized blocks created in the last epoch.

Collaboration diagram for taraxa::pillar_chain::PillarBlock:

Public Member Functions

 PillarBlock ()=default
 
 PillarBlock (const dev::RLP &rlp)
 
 PillarBlock (PbftPeriod period, h256 state_root, blk_hash_t previous_pillar_block_hash, h256 bridge_root, u256 epoch, std::vector< ValidatorVoteCountChange > &&validator_votes_count_changes)
 
 PillarBlock (const PillarBlock &pillar_block)
 
blk_hash_t getHash () const
 
PbftPeriod getPeriod () const
 
blk_hash_t getPreviousBlockHash () const
 
const std::vector< ValidatorVoteCountChange > & getValidatorsVoteCountsChanges () const
 
const h256getStateRoot () const
 
const h256getBridgeRoot () const
 
const uint64_t & getEpoch () const
 
dev::bytes getRlp () const
 
Json::Value getJson () const
 
dev::bytes encodeSolidity () const
 

Static Public Member Functions

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

Static Public Attributes

static constexpr uint8_t kFieldsSize = 5
 
static constexpr uint8_t kArrayPosAndSize = 2
 
static constexpr uint8_t kFieldsInVoteCount = 2
 

Private Attributes

PbftPeriod pbft_period_ {0}
 
h256 state_root_ {}
 
blk_hash_t previous_pillar_block_hash_ {0}
 
h256 bridge_root_ {}
 
uint64_t epoch_ {}
 
std::vector< ValidatorVoteCountChangevalidators_votes_count_changes_ {}
 
std::optional< blk_hash_thash_
 
std::shared_mutex hash_mutex_
 

Constructor & Destructor Documentation

◆ PillarBlock() [1/4]

taraxa::pillar_chain::PillarBlock::PillarBlock ( )
default

◆ PillarBlock() [2/4]

taraxa::pillar_chain::PillarBlock::PillarBlock ( const dev::RLP rlp)

◆ PillarBlock() [3/4]

taraxa::pillar_chain::PillarBlock::PillarBlock ( PbftPeriod  period,
h256  state_root,
blk_hash_t  previous_pillar_block_hash,
h256  bridge_root,
u256  epoch,
std::vector< ValidatorVoteCountChange > &&  validator_votes_count_changes 
)

◆ PillarBlock() [4/4]

taraxa::pillar_chain::PillarBlock::PillarBlock ( const PillarBlock pillar_block)

Member Function Documentation

◆ decodeSolidity()

PillarBlock taraxa::pillar_chain::PillarBlock::decodeSolidity ( const bytes enc)
static

Decodes solidity encoded representation of pillar block.

Parameters
enc
Returns

◆ encodeSolidity()

dev::bytes taraxa::pillar_chain::PillarBlock::encodeSolidity ( ) const
Note
Solidity encoding is used for data that are sent to smart contracts
Returns
solidity encoded representation of pillar block

◆ getBridgeRoot()

const h256 & taraxa::pillar_chain::PillarBlock::getBridgeRoot ( ) const
Returns
bridge root

◆ getEpoch()

const uint64_t & taraxa::pillar_chain::PillarBlock::getEpoch ( ) const
Returns
epoch

◆ getHash()

blk_hash_t taraxa::pillar_chain::PillarBlock::getHash ( ) const
Returns
pillar block hash

◆ getJson()

Json::Value taraxa::pillar_chain::PillarBlock::getJson ( ) const
Returns
json representation of Pillar block

◆ getPeriod()

PbftPeriod taraxa::pillar_chain::PillarBlock::getPeriod ( ) const
Returns
pillar block pbft period

◆ getPreviousBlockHash()

blk_hash_t taraxa::pillar_chain::PillarBlock::getPreviousBlockHash ( ) const
Returns
pillar block previous block hash

◆ getRlp()

dev::bytes taraxa::pillar_chain::PillarBlock::getRlp ( ) const
Returns
pillar block rlp

◆ getStateRoot()

const h256 & taraxa::pillar_chain::PillarBlock::getStateRoot ( ) const
Returns
state root

◆ getValidatorsVoteCountsChanges()

const std::vector< PillarBlock::ValidatorVoteCountChange > & taraxa::pillar_chain::PillarBlock::getValidatorsVoteCountsChanges ( ) const
Returns
validator vote counts changes

Member Data Documentation

◆ bridge_root_

h256 taraxa::pillar_chain::PillarBlock::bridge_root_ {}
private

◆ epoch_

uint64_t taraxa::pillar_chain::PillarBlock::epoch_ {}
private

◆ hash_

std::optional<blk_hash_t> taraxa::pillar_chain::PillarBlock::hash_
mutableprivate

◆ hash_mutex_

std::shared_mutex taraxa::pillar_chain::PillarBlock::hash_mutex_
mutableprivate

◆ kArrayPosAndSize

constexpr uint8_t taraxa::pillar_chain::PillarBlock::kArrayPosAndSize = 2
staticconstexpr

◆ kFieldsInVoteCount

constexpr uint8_t taraxa::pillar_chain::PillarBlock::kFieldsInVoteCount = 2
staticconstexpr

◆ kFieldsSize

constexpr uint8_t taraxa::pillar_chain::PillarBlock::kFieldsSize = 5
staticconstexpr

◆ pbft_period_

PbftPeriod taraxa::pillar_chain::PillarBlock::pbft_period_ {0}
private

◆ previous_pillar_block_hash_

blk_hash_t taraxa::pillar_chain::PillarBlock::previous_pillar_block_hash_ {0}
private

◆ state_root_

h256 taraxa::pillar_chain::PillarBlock::state_root_ {}
private

◆ validators_votes_count_changes_

std::vector<ValidatorVoteCountChange> taraxa::pillar_chain::PillarBlock::validators_votes_count_changes_ {}
private

◆ taraxa::pillar_chain::PillarBlockData

struct taraxa::pillar_chain::PillarBlockData
Collaboration diagram for taraxa::pillar_chain::PillarBlockData:

Public Member Functions

 PillarBlockData (std::shared_ptr< PillarBlock > block, const std::vector< std::shared_ptr< PillarVote >> &pillar_votes)
 
 PillarBlockData (const dev::RLP &rlp)
 
dev::bytes getRlp () const
 
Json::Value getJson (bool include_signatures) const
 

Public Attributes

std::shared_ptr< PillarBlockblock_
 
std::vector< std::shared_ptr< PillarVote > > pillar_votes_
 

Static Public Attributes

static const size_t kRlpItemCount = 2
 

Constructor & Destructor Documentation

◆ PillarBlockData() [1/2]

taraxa::pillar_chain::PillarBlockData::PillarBlockData ( std::shared_ptr< PillarBlock block,
const std::vector< std::shared_ptr< PillarVote >> &  pillar_votes 
)

◆ PillarBlockData() [2/2]

taraxa::pillar_chain::PillarBlockData::PillarBlockData ( const dev::RLP rlp)

Member Function Documentation

◆ getJson()

Json::Value taraxa::pillar_chain::PillarBlockData::getJson ( bool  include_signatures) const

◆ getRlp()

dev::bytes taraxa::pillar_chain::PillarBlockData::getRlp ( ) const

Member Data Documentation

◆ block_

std::shared_ptr<PillarBlock> taraxa::pillar_chain::PillarBlockData::block_

◆ kRlpItemCount

const size_t taraxa::pillar_chain::PillarBlockData::kRlpItemCount = 2
static

◆ pillar_votes_

std::vector<std::shared_ptr<PillarVote> > taraxa::pillar_chain::PillarBlockData::pillar_votes_

◆ taraxa::pillar_chain::CurrentPillarBlockDataDb

struct taraxa::pillar_chain::CurrentPillarBlockDataDb
Class Members
shared_ptr< PillarBlock > pillar_block
vector< ValidatorVoteCount > vote_counts

◆ taraxa::pillar_chain::PillarChainManager

class taraxa::pillar_chain::PillarChainManager

PillarChainMgr class contains functionality related to pillar chain.

Collaboration diagram for taraxa::pillar_chain::PillarChainManager:

Public Member Functions

 PillarChainManager (const FicusHardforkConfig &ficus_hf_config, std::shared_ptr< DbStorage > db, std::shared_ptr< final_chain::FinalChain > final_chain, std::shared_ptr< KeyManager > key_manager, addr_t node_addr)
 
std::shared_ptr< PillarBlockcreatePillarBlock (PbftPeriod period, const std::shared_ptr< const final_chain::BlockHeader > &block_header, const h256 &bridge_root, const h256 &bridge_epoch)
 
std::shared_ptr< PillarVotegenAndPlacePillarVote (PbftPeriod period, const blk_hash_t &pillar_block_hash, const secret_t &node_sk, bool broadcast_vote)
 Generate and place pillar vote for provided pillar_block_hash in case the whole pillar block is present and valid. More...
 
void setNetwork (std::weak_ptr< Network > network)
 Set network as a weak pointer. More...
 
bool isRelevantPillarVote (const std::shared_ptr< PillarVote > vote) const
 Checks if vote is related to saved latest_pillar_block_ and it is not already saved. More...
 
bool validatePillarVote (const std::shared_ptr< PillarVote > vote) const
 Validates pillar vote. More...
 
bool isPillarBlockLatestFinalized (const blk_hash_t &block_hash) const
 
std::shared_ptr< PillarBlockgetLastFinalizedPillarBlock () const
 
uint64_t addVerifiedPillarVote (const std::shared_ptr< PillarVote > &vote)
 Add a vote to the pillar votes map. More...
 
std::vector< std::shared_ptr< PillarVote > > finalizePillarBlock (const blk_hash_t &pillar_block_hash)
 Finalize pillar block. More...
 
std::shared_ptr< PillarBlockgetCurrentPillarBlock () const
 
std::vector< std::shared_ptr< PillarVote > > getVerifiedPillarVotes (PbftPeriod period, const blk_hash_t pillar_block_hash, bool above_threshold=false) const
 Get all pillar votes for specified pillar block. More...
 
bool isValidPillarBlock (const std::shared_ptr< PillarBlock > &pillar_block) const
 
std::optional< uint64_t > getPillarConsensusThreshold (PbftPeriod period) const
 

Public Attributes

decltype(pillar_block_finalized_emitter_) const ::Subscriber & pillar_block_finalized_
 

Private Member Functions

std::vector< PillarBlock::ValidatorVoteCountChangegetOrderedValidatorsVoteCountsChanges (const std::vector< state_api::ValidatorVoteCount > &current_vote_counts, const std::vector< state_api::ValidatorVoteCount > &previous_pillar_block_vote_counts)
 Return a vector of validators vote counts changes between the current and previous pillar block Changes are ordered based on validators addresses. More...
 
void saveNewPillarBlock (std::shared_ptr< PillarBlock > pillar_block, std::vector< state_api::ValidatorVoteCount > &&new_vote_counts)
 Save new pillar block into db & class data members. More...
 

Private Attributes

const util::EventEmitter< const PillarBlockData & > pillar_block_finalized_emitter_ {}
 
const FicusHardforkConfigkFicusHfConfig
 
std::shared_ptr< DbStoragedb_
 
std::weak_ptr< Networknetwork_
 
std::shared_ptr< final_chain::FinalChainfinal_chain_
 
std::shared_ptr< KeyManagerkey_manager_
 
const addr_t node_addr_
 
std::shared_ptr< PillarBlocklast_finalized_pillar_block_
 
std::shared_ptr< PillarBlockcurrent_pillar_block_
 
std::vector< state_api::ValidatorVoteCountcurrent_pillar_block_vote_counts_
 
PillarVotes pillar_votes_
 
std::shared_mutex mutex_
 

Constructor & Destructor Documentation

◆ PillarChainManager()

taraxa::pillar_chain::PillarChainManager::PillarChainManager ( const FicusHardforkConfig ficus_hf_config,
std::shared_ptr< DbStorage db,
std::shared_ptr< final_chain::FinalChain final_chain,
std::shared_ptr< KeyManager key_manager,
addr_t  node_addr 
)

Member Function Documentation

◆ addVerifiedPillarVote()

uint64_t taraxa::pillar_chain::PillarChainManager::addVerifiedPillarVote ( const std::shared_ptr< PillarVote > &  vote)

Add a vote to the pillar votes map.

Parameters
votevote
Returns
vote's weight if vote was successfully added, otherwise 0

◆ createPillarBlock()

std::shared_ptr< PillarBlock > taraxa::pillar_chain::PillarChainManager::createPillarBlock ( PbftPeriod  period,
const std::shared_ptr< const final_chain::BlockHeader > &  block_header,
const h256 bridge_root,
const h256 bridge_epoch 
)

@Process Creates new pillar block

Parameters
period
block_header
bridge_root
bridge_epoch
Returns
pillar block in case block was created, otherwise nullptr

◆ finalizePillarBlock()

std::vector< std::shared_ptr< PillarVote > > taraxa::pillar_chain::PillarChainManager::finalizePillarBlock ( const blk_hash_t pillar_block_hash)

Finalize pillar block.

Parameters
pillar_block_hash
Returns
above threshold pillar votes if successfully finalized, otherwise empty vector

◆ genAndPlacePillarVote()

std::shared_ptr< PillarVote > taraxa::pillar_chain::PillarChainManager::genAndPlacePillarVote ( PbftPeriod  period,
const blk_hash_t pillar_block_hash,
const secret_t node_sk,
bool  broadcast_vote 
)

Generate and place pillar vote for provided pillar_block_hash in case the whole pillar block is present and valid.

Parameters
period
pillar_block_hash
node_sk
broadcast_vote
Returns
vote if it was created, otherwise nullptr

◆ getCurrentPillarBlock()

std::shared_ptr< PillarBlock > taraxa::pillar_chain::PillarChainManager::getCurrentPillarBlock ( ) const
Returns
current pillar block

◆ getLastFinalizedPillarBlock()

std::shared_ptr< PillarBlock > taraxa::pillar_chain::PillarChainManager::getLastFinalizedPillarBlock ( ) const
Returns
last finalized pillar block

◆ getOrderedValidatorsVoteCountsChanges()

std::vector< PillarBlock::ValidatorVoteCountChange > taraxa::pillar_chain::PillarChainManager::getOrderedValidatorsVoteCountsChanges ( const std::vector< state_api::ValidatorVoteCount > &  current_vote_counts,
const std::vector< state_api::ValidatorVoteCount > &  previous_pillar_block_vote_counts 
)
private

Return a vector of validators vote counts changes between the current and previous pillar block Changes are ordered based on validators addresses.

Parameters
current_vote_counts
previous_pillar_block_vote_counts
Returns
ordered vector of validators vote counts changes

◆ getPillarConsensusThreshold()

std::optional< uint64_t > taraxa::pillar_chain::PillarChainManager::getPillarConsensusThreshold ( PbftPeriod  period) const
Parameters
period
Returns
pillar consensus threshold (total votes count / 2 + 1) for provided period

◆ getVerifiedPillarVotes()

std::vector< std::shared_ptr< PillarVote > > taraxa::pillar_chain::PillarChainManager::getVerifiedPillarVotes ( PbftPeriod  period,
const blk_hash_t  pillar_block_hash,
bool  above_threshold = false 
) const

Get all pillar votes for specified pillar block.

Parameters
period
pillar_block_hash
above_threshold
Returns
all pillar votes for specified period and pillar block hash. In case above_threshold == true, votes are sorted based on vote weight and the minimum number of votes above threshold are returned

◆ isPillarBlockLatestFinalized()

bool taraxa::pillar_chain::PillarChainManager::isPillarBlockLatestFinalized ( const blk_hash_t block_hash) const
Returns
true if block_hash is the latest finalized pillar block

◆ isRelevantPillarVote()

bool taraxa::pillar_chain::PillarChainManager::isRelevantPillarVote ( const std::shared_ptr< PillarVote vote) const

Checks if vote is related to saved latest_pillar_block_ and it is not already saved.

Parameters
vote
Returns
true if relevant, otherwise false

◆ isValidPillarBlock()

bool taraxa::pillar_chain::PillarChainManager::isValidPillarBlock ( const std::shared_ptr< PillarBlock > &  pillar_block) const
Returns
true if pillar block is valid - previous pillar block hash == last finalized pillar block hash

◆ saveNewPillarBlock()

void taraxa::pillar_chain::PillarChainManager::saveNewPillarBlock ( std::shared_ptr< PillarBlock pillar_block,
std::vector< state_api::ValidatorVoteCount > &&  new_vote_counts 
)
private

Save new pillar block into db & class data members.

Parameters
pillar_block
new_vote_counts

◆ setNetwork()

void taraxa::pillar_chain::PillarChainManager::setNetwork ( std::weak_ptr< Network network)

Set network as a weak pointer.

Parameters
networka weak pointer

◆ validatePillarVote()

bool taraxa::pillar_chain::PillarChainManager::validatePillarVote ( const std::shared_ptr< PillarVote vote) const

Validates pillar vote.

Parameters
vote
Returns
true if valid, otherwise false

Member Data Documentation

◆ current_pillar_block_

std::shared_ptr<PillarBlock> taraxa::pillar_chain::PillarChainManager::current_pillar_block_
private

◆ current_pillar_block_vote_counts_

std::vector<state_api::ValidatorVoteCount> taraxa::pillar_chain::PillarChainManager::current_pillar_block_vote_counts_
private

◆ db_

std::shared_ptr<DbStorage> taraxa::pillar_chain::PillarChainManager::db_
private

◆ final_chain_

std::shared_ptr<final_chain::FinalChain> taraxa::pillar_chain::PillarChainManager::final_chain_
private

◆ key_manager_

std::shared_ptr<KeyManager> taraxa::pillar_chain::PillarChainManager::key_manager_
private

◆ kFicusHfConfig

const FicusHardforkConfig& taraxa::pillar_chain::PillarChainManager::kFicusHfConfig
private

◆ last_finalized_pillar_block_

std::shared_ptr<PillarBlock> taraxa::pillar_chain::PillarChainManager::last_finalized_pillar_block_
private

◆ mutex_

std::shared_mutex taraxa::pillar_chain::PillarChainManager::mutex_
mutableprivate

◆ network_

std::weak_ptr<Network> taraxa::pillar_chain::PillarChainManager::network_
private

◆ node_addr_

const addr_t taraxa::pillar_chain::PillarChainManager::node_addr_
private

◆ pillar_block_finalized_

decltype(pillar_block_finalized_emitter_) const ::Subscriber& taraxa::pillar_chain::PillarChainManager::pillar_block_finalized_
Initial value:
=
const util::EventEmitter< const PillarBlockData & > pillar_block_finalized_emitter_
Definition: pillar_chain_manager.hpp:33

◆ pillar_block_finalized_emitter_

const util::EventEmitter<const PillarBlockData&> taraxa::pillar_chain::PillarChainManager::pillar_block_finalized_emitter_ {}
private

◆ pillar_votes_

PillarVotes taraxa::pillar_chain::PillarChainManager::pillar_votes_
private