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

Namespaces

 prefix
 

Classes

class  BlockHeaderRepository
 
class  BlockHeaderRepositoryImpl
 
class  BlockStorage
 
class  BlockStorageImpl
 
class  BlockTree
 
class  BlockTreeImpl
 
class  CachedTree
 
class  DigestTracker
 
class  DigestTrackerImpl
 
class  JustificationStoragePolicy
 
class  JustificationStoragePolicyImpl
 
struct  TreeMeta
 
class  TreeNode
 

Typedefs

using Buffer = common::Buffer
 
using Prefix = prefix::Prefix
 
using DatabaseError = kagome::storage::DatabaseError
 
using ReadableBufferStorage = storage::face::ReadableStorage< common::BufferView, common::Buffer >
 

Enumerations

enum  BlockStatus { BlockStatus::InChain, BlockStatus::Unknown }
 
enum  BlockStorageError {
  BlockStorageError::BLOCK_EXISTS = 1, BlockStorageError::HEADER_NOT_FOUND, BlockStorageError::GENESIS_BLOCK_ALREADY_EXISTS, BlockStorageError::GENESIS_BLOCK_NOT_FOUND,
  BlockStorageError::FINALIZED_BLOCK_NOT_FOUND, BlockStorageError::BLOCK_TREE_LEAVES_NOT_FOUND
}
 
enum  BlockTreeError {
  BlockTreeError::NO_PARENT = 1, BlockTreeError::BLOCK_EXISTS, BlockTreeError::TARGET_IS_PAST_MAX, BlockTreeError::BLOCK_ON_DEAD_END,
  BlockTreeError::EXISTING_BLOCK_NOT_FOUND, BlockTreeError::NON_FINALIZED_BLOCK_NOT_FOUND, BlockTreeError::JUSTIFICATION_NOT_FOUND, BlockTreeError::BODY_NOT_FOUND,
  BlockTreeError::HEADER_NOT_FOUND, BlockTreeError::SOME_BLOCK_IN_CHAIN_NOT_FOUND, BlockTreeError::BLOCK_IS_NOT_LEAF
}
 
enum  KeyValueRepositoryError { KeyValueRepositoryError::INVALID_KEY = 1 }
 

Functions

outcome::result< std::optional< common::Buffer > > idToLookupKey (const ReadableBufferStorage &map, const primitives::BlockId &id)
 
storage::trie::RootHash trieRoot (const std::vector< std::pair< common::Buffer, common::Buffer >> &key_vals)
 
outcome::result< void > putNumberToIndexKey (storage::BufferStorage &map, const primitives::BlockInfo &block)
 
outcome::result< void > putWithPrefix (storage::BufferStorage &map, prefix::Prefix prefix, BlockNumber num, Hash256 block_hash, const common::Buffer &value)
 
outcome::result< bool > hasWithPrefix (const storage::BufferStorage &map, prefix::Prefix prefix, const primitives::BlockId &block_id)
 
outcome::result< std::optional< common::Buffer > > getWithPrefix (const storage::BufferStorage &map, prefix::Prefix prefix, const primitives::BlockId &block_id)
 
common::Buffer numberToIndexKey (primitives::BlockNumber n)
 
common::Buffer numberAndHashToLookupKey (primitives::BlockNumber number, const common::Hash256 &hash)
 
outcome::result< primitives::BlockNumberlookupKeyToNumber (const common::BufferView &key)
 
common::Buffer prependPrefix (common::BufferView key, prefix::Prefix key_column)
 
outcome::result< void > putWithPrefix (storage::BufferStorage &map, prefix::Prefix prefix, primitives::BlockNumber num, common::Hash256 block_hash, const common::Buffer &value)
 

Detailed Description

Copyright Soramitsu Co., Ltd. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Copyright Soramitsu Co., Ltd. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 Auxiliary functions to simplify usage of persistant map based storage as a Blockchain storage

Typedef Documentation

Enumeration Type Documentation

Status of a block

Enumerator
InChain 
Unknown 

Definition at line 22 of file block_header_repository.hpp.

Enumerator
BLOCK_EXISTS 
HEADER_NOT_FOUND 
GENESIS_BLOCK_ALREADY_EXISTS 
GENESIS_BLOCK_NOT_FOUND 
FINALIZED_BLOCK_NOT_FOUND 
BLOCK_TREE_LEAVES_NOT_FOUND 

Definition at line 13 of file block_storage_error.hpp.

Errors of the block tree are here, so that other modules can use them, for example, to compare a received error with those

Enumerator
NO_PARENT 
BLOCK_EXISTS 
TARGET_IS_PAST_MAX 
BLOCK_ON_DEAD_END 
EXISTING_BLOCK_NOT_FOUND 
NON_FINALIZED_BLOCK_NOT_FOUND 
JUSTIFICATION_NOT_FOUND 
BODY_NOT_FOUND 
HEADER_NOT_FOUND 
SOME_BLOCK_IN_CHAIN_NOT_FOUND 
BLOCK_IS_NOT_LEAF 

Definition at line 16 of file block_tree_error.hpp.

Errors that might occur during work with storage

Enumerator
INVALID_KEY 

Definition at line 43 of file storage_util.hpp.

Function Documentation

outcome::result< std::optional< common::Buffer > > kagome::blockchain::getWithPrefix ( const storage::BufferStorage storage,
prefix::Prefix  prefix,
const primitives::BlockId block_id 
)

Get an entry from the database

Parameters
storage- to get the entry from
prefix- key space in the storage to which the entry belongs
block_id- id of the block to get entry for
Returns
error, or an encoded entry, if any, or std::nullopt, if none

Definition at line 59 of file storage_util.cpp.

outcome::result< bool > kagome::blockchain::hasWithPrefix ( const storage::BufferStorage storage,
prefix::Prefix  prefix,
const primitives::BlockId block_id 
)

Chech if an entry from the database

Parameters
storage- to get the entry from
prefix- key space in the storage to which the entry belongs
block_id- id of the block to get entry for
Returns
true if entry exists, false if does not, and error at fail

Definition at line 51 of file storage_util.cpp.

outcome::result< std::optional< common::Buffer > > kagome::blockchain::idToLookupKey ( const ReadableBufferStorage map,
const primitives::BlockId id 
)

Convert a block ID into a key, which is a first part of a key, by which the columns are stored in the database

Definition at line 15 of file common.cpp.

outcome::result< primitives::BlockNumber > kagome::blockchain::lookupKeyToNumber ( const common::BufferView key)

Convert lookup key to a block number

Definition at line 85 of file storage_util.cpp.

common::Buffer kagome::blockchain::numberAndHashToLookupKey ( primitives::BlockNumber  number,
const common::Hash256 hash 
)

Convert number and hash into long lookup key for blocks that are not in the canonical chain.

Definition at line 78 of file storage_util.cpp.

common::Buffer kagome::blockchain::numberToIndexKey ( primitives::BlockNumber  n)

Convert block number into short lookup key (LE representation) for blocks that are in the canonical chain.

In the current database schema, this kind of key is only used for lookups into an index, NOT for storing header data or others.

Definition at line 68 of file storage_util.cpp.

common::Buffer kagome::blockchain::prependPrefix ( common::BufferView  key,
prefix::Prefix  key_column 
)

Concatenate

Parameters
key_columnwith
key
Returns
key_column|key

Definition at line 94 of file storage_util.cpp.

outcome::result< void > kagome::blockchain::putNumberToIndexKey ( storage::BufferStorage map,
const primitives::BlockInfo block 
)

Definition at line 28 of file storage_util.cpp.

outcome::result<void> kagome::blockchain::putWithPrefix ( storage::BufferStorage map,
prefix::Prefix  prefix,
BlockNumber  num,
Hash256  block_hash,
const common::Buffer value 
)

Definition at line 36 of file storage_util.cpp.

outcome::result<void> kagome::blockchain::putWithPrefix ( storage::BufferStorage map,
prefix::Prefix  prefix,
primitives::BlockNumber  num,
common::Hash256  block_hash,
const common::Buffer value 
)

Put an entry to key space

Parameters
prefixand corresponding lookup keys to ID_TO_LOOKUP_KEY space
mapto put the entry to
prefixkeyspace for the entry value
numblock number that could be used to retrieve the value
block_hashblock hash that could be used to retrieve the value
valuedata to be put to the storage
Returns
storage error if any
storage::trie::RootHash kagome::blockchain::trieRoot ( const std::vector< std::pair< common::Buffer, common::Buffer >> &  key_vals)

Instantiate empty merkle trie, insert

Parameters
key_valspairs and
Returns
Buffer containing merkle root of resulting trie

Definition at line 32 of file common.cpp.