#include <block_tree_impl.hpp>
|
static outcome::result< std::shared_ptr< BlockTreeImpl > > | create (std::shared_ptr< BlockHeaderRepository > header_repo, std::shared_ptr< BlockStorage > storage, std::shared_ptr< network::ExtrinsicObserver > extrinsic_observer, std::shared_ptr< crypto::Hasher > hasher, primitives::events::ChainSubscriptionEnginePtr chain_events_engine, primitives::events::ExtrinsicSubscriptionEnginePtr extrinsic_events_engine, std::shared_ptr< subscription::ExtrinsicEventKeyRepository > extrinsic_event_key_repo, std::shared_ptr< storage::changes_trie::ChangesTracker > changes_tracker, std::shared_ptr< const class JustificationStoragePolicy > justification_storage_policy) |
| Create an instance of block tree. More...
|
|
static outcome::result< void > | recover (primitives::BlockId target_block, std::shared_ptr< BlockStorage > storage, std::shared_ptr< BlockHeaderRepository > header_repo, std::shared_ptr< const storage::trie::TrieStorage > trie_storage, std::shared_ptr< blockchain::BlockTree > block_tree) |
| Recover block tree state at provided block. More...
|
|
|
| BlockTreeImpl (std::shared_ptr< BlockHeaderRepository > header_repo, std::shared_ptr< BlockStorage > storage, std::unique_ptr< CachedTree > cached_tree, std::shared_ptr< network::ExtrinsicObserver > extrinsic_observer, std::shared_ptr< crypto::Hasher > hasher, primitives::events::ChainSubscriptionEnginePtr chain_events_engine, primitives::events::ExtrinsicSubscriptionEnginePtr extrinsic_events_engine, std::shared_ptr< subscription::ExtrinsicEventKeyRepository > extrinsic_event_key_repo, std::shared_ptr< storage::changes_trie::ChangesTracker > changes_tracker, std::shared_ptr< const class JustificationStoragePolicy > justification_storage_policy) |
|
outcome::result< primitives::BlockHash > | walkBackUntilLess (const primitives::BlockHash &start, const primitives::BlockNumber &limit) const |
|
std::vector< primitives::BlockHash > | getLeavesSorted () const |
|
outcome::result< void > | prune (const std::shared_ptr< TreeNode > &lastFinalizedNode) |
|
outcome::result< void > | reorganize () |
|
Definition at line 44 of file block_tree_impl.hpp.
kagome::blockchain::BlockTreeImpl::~BlockTreeImpl |
( |
| ) |
|
|
overridedefault |
Private constructor, so that instances are created only through the factory method
Definition at line 327 of file block_tree_impl.cpp.
outcome::result< void > kagome::blockchain::BlockTreeImpl::addBlock |
( |
const primitives::Block & |
block | ) |
|
|
overridevirtual |
Add a new block to the tree
- Parameters
-
block | to be stored and added to tree |
- Returns
- nothing or error; if error happens, no changes in the tree are made
- Note
- if block, which is specified in PARENT_HASH field of (
- Parameters
-
block) | is not in our local storage, corresponding error is returned. It is suggested that after getting that error, the caller would ask another peer for the parent block and try to insert it; this operation is to be repeated until a successful insertion happens |
Implements kagome::blockchain::BlockTree.
Definition at line 438 of file block_tree_impl.cpp.
Adds block body to the storage
- Parameters
-
block_number | that corresponds to the block which body we are adding |
block_hash | that corresponds to the block which body we are adding |
block_body | that we are adding |
- Returns
- result with success if block body was inserted. Error otherwise
Implements kagome::blockchain::BlockTree.
Definition at line 627 of file block_tree_impl.cpp.
outcome::result< void > kagome::blockchain::BlockTreeImpl::addBlockHeader |
( |
const primitives::BlockHeader & |
header | ) |
|
|
overridevirtual |
Add an existent block to the tree
- Parameters
-
block_hash | is hash of the added block in the tree |
block_header | is header of that block |
- Returns
- nothing or error; if error happens, no changes in the tree are made
Implements kagome::blockchain::BlockTree.
Definition at line 526 of file block_tree_impl.cpp.
Get a deepest leaf of the tree
- Returns
- deepest leaf
- Note
- deepest leaf is also a result of "SelectBestChain": if we are the leader, we connect a block, which we constructed, to that deepest leaf
Implements kagome::blockchain::BlockTree.
Definition at line 963 of file block_tree_impl.cpp.
Get a chain of blocks from provided block to best block direction
- Parameters
-
block,from | which the chain is started |
maximum | number of blocks to be retrieved |
- Returns
- chain or blocks or error
Implements kagome::blockchain::BlockTree.
Definition at line 756 of file block_tree_impl.cpp.
Get the most recent block of the best (longest) chain among those that contain a block with.
- Parameters
-
target_hash | |
target_hash | is a hash of a block that the chosen chain must contain |
max_number | is the max block number that the resulting block (and the target one) may possess |
Implements kagome::blockchain::BlockTree.
Definition at line 969 of file block_tree_impl.cpp.
Get a body (extrinsics) of the block (if present)
- Parameters
-
block | - id of the block to get body for |
- Returns
- body, if the block exists in our storage, error in case it does not exist in our storage, or actual error happens
Implements kagome::blockchain::BlockTree.
Definition at line 742 of file block_tree_impl.cpp.
Get block header by provided block id
- Parameters
-
block | id of the block header we are looking for |
- Returns
- result containing block header if it exists, error otherwise
Implements kagome::blockchain::BlockTree.
Definition at line 735 of file block_tree_impl.cpp.
Get a justification of the block (if present)
- Parameters
-
block | - id of the block to get justification for |
- Returns
- body, if the block exists in our storage, error in case it does not exist in our storage, or actual error happens
Implements kagome::blockchain::BlockTree.
Definition at line 750 of file block_tree_impl.cpp.
Get a chain of blocks. Implies hasDirectChain(ancestor, descendant)
.
- Parameters
-
ancestor | - block, which is closest to the genesis |
descendant | - block, which is farthest from the genesis |
- Returns
- chain of blocks in ascending order or error
Implements kagome::blockchain::BlockTree.
Definition at line 847 of file block_tree_impl.cpp.
Get a chain of blocks before provided block including its
- Parameters
-
block,to | which the chain is ended |
maximum | number of blocks to be retrieved |
- Returns
- chain or blocks or error
Implements kagome::blockchain::BlockTree.
Definition at line 803 of file block_tree_impl.cpp.
outcome::result< bool > kagome::blockchain::BlockTreeImpl::hasBlockHeader |
( |
const primitives::BlockId & |
block | ) |
const |
|
overridevirtual |
Checks containing of block header by provided block id
- Parameters
-
block | id of the block header we are checking |
- Returns
- containing block header or does not, or error
Implements kagome::blockchain::BlockTree.
Definition at line 730 of file block_tree_impl.cpp.
Check if one block is ancestor of second one (direct chain exists)
- Parameters
-
ancestor | - block, which is closest to the genesis |
descendant | - block, which is farthest from the genesis |
- Returns
- true if
- Parameters
-
ancestor | is ancestor of |
descendant | |
Implements kagome::blockchain::BlockTree.
Definition at line 865 of file block_tree_impl.cpp.
outcome::result< void > kagome::blockchain::BlockTreeImpl::prune |
( |
const std::shared_ptr< TreeNode > & |
lastFinalizedNode | ) |
|
|
private |
outcome::result< void > kagome::blockchain::BlockTreeImpl::removeLeaf |
( |
const primitives::BlockHash & |
block_hash | ) |
|
|
overridevirtual |
outcome::result< void > kagome::blockchain::BlockTreeImpl::reorganize |
( |
| ) |
|
|
private |
Walks the chain backwards starting from
- Parameters
-
start | until the current block number is less or equal than |
limit | |
Definition at line 1081 of file block_tree_impl.cpp.
std::shared_ptr<crypto::Hasher> kagome::blockchain::BlockTreeImpl::hasher_ |
|
private |
metrics::Gauge* kagome::blockchain::BlockTreeImpl::metric_best_block_height_ |
|
private |
metrics::Gauge* kagome::blockchain::BlockTreeImpl::metric_finalized_block_height_ |
|
private |
metrics::Gauge* kagome::blockchain::BlockTreeImpl::metric_known_chain_leaves_ |
|
private |
std::shared_ptr<BlockStorage> kagome::blockchain::BlockTreeImpl::storage_ |
|
private |
std::unique_ptr<CachedTree> kagome::blockchain::BlockTreeImpl::tree_ |
|
private |
The documentation for this class was generated from the following files: