Kagome
Polkadot Runtime Engine in C++17
kagome::blockchain::BlockStorageImpl Class Reference

#include <block_storage_impl.hpp>

Inheritance diagram for kagome::blockchain::BlockStorageImpl:
Collaboration diagram for kagome::blockchain::BlockStorageImpl:

Public Member Functions

 ~BlockStorageImpl () override=default
 
outcome::result< std::vector< primitives::BlockHash > > getBlockTreeLeaves () const override
 
outcome::result< void > setBlockTreeLeaves (std::vector< primitives::BlockHash > leaves) override
 
outcome::result< bool > hasBlockHeader (const primitives::BlockId &id) const override
 Check if header existing by provided block {. More...
 
outcome::result< std::optional< primitives::BlockHeader > > getBlockHeader (const primitives::BlockId &id) const override
 
outcome::result< std::optional< primitives::BlockBody > > getBlockBody (const primitives::BlockId &id) const override
 
outcome::result< std::optional< primitives::BlockData > > getBlockData (const primitives::BlockId &id) const override
 
outcome::result< std::optional< primitives::Justification > > getJustification (const primitives::BlockId &block) const override
 
outcome::result< void > putNumberToIndexKey (const primitives::BlockInfo &block) override
 
outcome::result< primitives::BlockHashputBlockHeader (const primitives::BlockHeader &header) override
 
outcome::result< void > putBlockData (primitives::BlockNumber block_number, const primitives::BlockData &block_data) override
 
outcome::result< void > removeBlockData (primitives::BlockNumber block_number, const primitives::BlockDataFlags &remove_flags) override
 
outcome::result< primitives::BlockHashputBlock (const primitives::Block &block) override
 
outcome::result< void > putJustification (const primitives::Justification &j, const primitives::BlockHash &hash, primitives::BlockNumber number) override
 
outcome::result< void > removeJustification (const primitives::BlockHash &hash, primitives::BlockNumber number) override
 
outcome::result< void > removeBlock (const primitives::BlockInfo &block) override
 
outcome::result< primitives::BlockInfogetLastFinalized () const override
 
- Public Member Functions inherited from kagome::blockchain::BlockStorage
virtual ~BlockStorage ()=default
 

Static Public Member Functions

static outcome::result< std::shared_ptr< BlockStorageImpl > > create (storage::trie::RootHash state_root, const std::shared_ptr< storage::BufferStorage > &storage, const std::shared_ptr< crypto::Hasher > &hasher)
 

Private Member Functions

 BlockStorageImpl (std::shared_ptr< storage::BufferStorage > storage, std::shared_ptr< crypto::Hasher > hasher)
 

Private Attributes

std::shared_ptr< storage::BufferStoragestorage_
 
std::shared_ptr< crypto::Hasherhasher_
 
log::Logger logger_
 
std::optional< std::vector< primitives::BlockHash > > block_tree_leaves_
 

Detailed Description

Definition at line 18 of file block_storage_impl.hpp.

Constructor & Destructor Documentation

kagome::blockchain::BlockStorageImpl::~BlockStorageImpl ( )
overridedefault
kagome::blockchain::BlockStorageImpl::BlockStorageImpl ( std::shared_ptr< storage::BufferStorage storage,
std::shared_ptr< crypto::Hasher hasher 
)
private

Definition at line 20 of file block_storage_impl.cpp.

Member Function Documentation

outcome::result< std::shared_ptr< BlockStorageImpl > > kagome::blockchain::BlockStorageImpl::create ( storage::trie::RootHash  state_root,
const std::shared_ptr< storage::BufferStorage > &  storage,
const std::shared_ptr< crypto::Hasher > &  hasher 
)
static

Creates block storage. Iff block storage is empty, then initializes with a genesis block which is created automatically from merkle trie root

Parameters
state_rootmerkle root of genesis state
storageunderlying storage (must be empty)
hashera hasher instance

Definition at line 30 of file block_storage_impl.cpp.

outcome::result< std::optional< primitives::BlockBody > > kagome::blockchain::BlockStorageImpl::getBlockBody ( const primitives::BlockId id) const
overridevirtual

Tries to get block body by {

Parameters
id}
Returns
block body or error

Implements kagome::blockchain::BlockStorage.

Definition at line 80 of file block_storage_impl.cpp.

outcome::result< std::optional< primitives::BlockData > > kagome::blockchain::BlockStorageImpl::getBlockData ( const primitives::BlockId id) const
overridevirtual

Tries to get block data by {

Parameters
id}
Returns
block data or error

Implements kagome::blockchain::BlockStorage.

Definition at line 89 of file block_storage_impl.cpp.

outcome::result< std::optional< primitives::BlockHeader > > kagome::blockchain::BlockStorageImpl::getBlockHeader ( const primitives::BlockId id) const
overridevirtual

Tries to get block header by {

Parameters
id}
Returns
block header or error

Implements kagome::blockchain::BlockStorage.

Definition at line 67 of file block_storage_impl.cpp.

outcome::result< std::vector< primitives::BlockHash > > kagome::blockchain::BlockStorageImpl::getBlockTreeLeaves ( ) const
overridevirtual

Obtains leaves of block tree

Returns
hashes of block tree leaves

Implements kagome::blockchain::BlockStorage.

Definition at line 298 of file block_storage_impl.cpp.

outcome::result< std::optional< primitives::Justification > > kagome::blockchain::BlockStorageImpl::getJustification ( const primitives::BlockId block) const
overridevirtual

Tries to get justification of block finality by {

Parameters
id}
Returns
justification or error

Implements kagome::blockchain::BlockStorage.

Definition at line 102 of file block_storage_impl.cpp.

outcome::result< primitives::BlockInfo > kagome::blockchain::BlockStorageImpl::getLastFinalized ( ) const
overridevirtual

Get the last finalized block

Returns
BlockInfo of the block

Implements kagome::blockchain::BlockStorage.

Definition at line 334 of file block_storage_impl.cpp.

outcome::result< bool > kagome::blockchain::BlockStorageImpl::hasBlockHeader ( const primitives::BlockId id) const
overridevirtual

Check if header existing by provided block {.

Parameters
id}

Implements kagome::blockchain::BlockStorage.

Definition at line 61 of file block_storage_impl.cpp.

outcome::result< primitives::BlockHash > kagome::blockchain::BlockStorageImpl::putBlock ( const primitives::Block block)
overridevirtual

Saves {

Parameters
block}to block storage
Returns
hash of saved header or error

Implements kagome::blockchain::BlockStorage.

Definition at line 206 of file block_storage_impl.cpp.

outcome::result< void > kagome::blockchain::BlockStorageImpl::putBlockData ( primitives::BlockNumber  ,
const primitives::BlockData block_data 
)
overridevirtual

Saves {

Parameters
data}of block with {
number}to block storage
Returns
result of saving

Implements kagome::blockchain::BlockStorage.

Definition at line 129 of file block_storage_impl.cpp.

outcome::result< primitives::BlockHash > kagome::blockchain::BlockStorageImpl::putBlockHeader ( const primitives::BlockHeader header)
overridevirtual

Saves block header {

Parameters
header}to block storage
Returns
hash of saved header or error

Implements kagome::blockchain::BlockStorage.

Definition at line 117 of file block_storage_impl.cpp.

outcome::result< void > kagome::blockchain::BlockStorageImpl::putJustification ( const primitives::Justification justification,
const primitives::BlockHash hash,
primitives::BlockNumber  number 
)
overridevirtual

Saves {

Parameters
justification}of block with {
number}and {
hash}to block storage
Returns
result of saving

Implements kagome::blockchain::BlockStorage.

Definition at line 224 of file block_storage_impl.cpp.

outcome::result< void > kagome::blockchain::BlockStorageImpl::putNumberToIndexKey ( const primitives::BlockInfo block)
overridevirtual

Saves number-to-block_lookup_key for {

Parameters
block}to block storage
Returns
hash of saved header or error

Implements kagome::blockchain::BlockStorage.

Definition at line 111 of file block_storage_impl.cpp.

outcome::result< void > kagome::blockchain::BlockStorageImpl::removeBlock ( const primitives::BlockInfo block)
overridevirtual

Removes all data of block {

Parameters
block}from block storage
Returns
result of removing

Implements kagome::blockchain::BlockStorage.

Definition at line 243 of file block_storage_impl.cpp.

outcome::result< void > kagome::blockchain::BlockStorageImpl::removeBlockData ( primitives::BlockNumber  block_number,
const primitives::BlockDataFlags remove_flags 
)
overridevirtual

Removes data parts from storage

  • remove_flags - parts to remove
  • number - block number
    Returns
    result of removal

Implements kagome::blockchain::BlockStorage.

Definition at line 166 of file block_storage_impl.cpp.

outcome::result< void > kagome::blockchain::BlockStorageImpl::removeJustification ( const primitives::BlockHash hash,
primitives::BlockNumber  number 
)
overridevirtual

Removes {

Parameters
justification}of block with {
number}and {
hash}from block storage
Returns
result of saving

Implements kagome::blockchain::BlockStorage.

Definition at line 234 of file block_storage_impl.cpp.

outcome::result< void > kagome::blockchain::BlockStorageImpl::setBlockTreeLeaves ( std::vector< primitives::BlockHash leaves)
overridevirtual

Saves provided block tree {

Parameters
leaves}
Returns
result of saving

Implements kagome::blockchain::BlockStorage.

Definition at line 318 of file block_storage_impl.cpp.

Member Data Documentation

std::optional<std::vector<primitives::BlockHash> > kagome::blockchain::BlockStorageImpl::block_tree_leaves_
mutableprivate

Definition at line 87 of file block_storage_impl.hpp.

std::shared_ptr<crypto::Hasher> kagome::blockchain::BlockStorageImpl::hasher_
private

Definition at line 83 of file block_storage_impl.hpp.

log::Logger kagome::blockchain::BlockStorageImpl::logger_
private

Definition at line 84 of file block_storage_impl.hpp.

std::shared_ptr<storage::BufferStorage> kagome::blockchain::BlockStorageImpl::storage_
private

Definition at line 82 of file block_storage_impl.hpp.


The documentation for this class was generated from the following files: