Skip to content

sgns::blockchain

More...

Namespaces

Name
sgns::blockchain::prefix

Classes

Name
class sgns::blockchain::BlockHeaderRepository
class sgns::blockchain::BlockStorage
struct sgns::blockchain::BlockTree
class sgns::blockchain::BlockTreeImpl
class sgns::blockchain::KeyValueBlockHeaderRepository
class sgns::blockchain::KeyValueBlockStorage
class sgns::blockchain::ValidatorRegistry

Types

Name
enum class BlockStatus
enum class BlockTreeError
enum class Error
enum class KeyValueRepositoryError
using base::Buffer Buffer
using prefix::Prefix Prefix
using sgns::storage::DatabaseError DatabaseError
using storage::face::Readable< base::Buffer, base::Buffer > ReadableBufferMap
using boost::variant< BlockHash, BlockNumber > BlockId
Block id is the variant over BlockHash and BlockNumber.

Functions

Name
outcome::result< base::Buffer > idToBufferKey(crdt::GlobalDB & db, const primitives::BlockId & id)
outcome::result< std::string > idToStringKey(crdt::GlobalDB & db, const primitives::BlockId & id)
base::Buffer trieRoot(const std::vector< std::pair< base::Buffer, base::Buffer > > & key_vals)
outcome::result< void > putWithPrefix(crdt::GlobalDB & db, prefix::Prefix prefix, primitives::BlockNumber num, base::Hash256 block_hash, const base::Buffer & value)
outcome::result< base::Buffer > getWithPrefix(crdt::GlobalDB & db, prefix::Prefix prefix, const primitives::BlockId & block_id)
base::Buffer NumberToBuffer(primitives::BlockNumber n)
base::Buffer numberAndHashToLookupKey(primitives::BlockNumber number, const base::Hash256 & hash)
outcome::result< primitives::BlockNumber > BufferToNumber(const base::Buffer & key)
base::Buffer prependPrefix(const base::Buffer & key, prefix::Prefix key_column)
bool isNotFoundError(outcome::result< void > result)

Detailed Description

Auxiliary functions to simplify usage of persistant map based storage as a Blockchain storage

Types Documentation

enum BlockStatus

Enumerator Value Description
InChain
Unknown

Status of a block

enum BlockTreeError

Enumerator Value Description
INVALID_DB 1
NO_PARENT
BLOCK_EXISTS
HASH_FAILED
NO_SUCH_BLOCK
INCORRECT_ARGS
INTERNAL_ERROR

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

enum Error

Enumerator Value Description
BLOCK_NOT_FOUND 1

enum KeyValueRepositoryError

Enumerator Value Description
INVALID_KEY 1

Errors that might occur during work with storage

using Buffer

using sgns::blockchain::Buffer = base::Buffer;

using Prefix

using sgns::blockchain::Prefix = prefix::Prefix;

using DatabaseError

using sgns::blockchain::DatabaseError = sgns::storage::DatabaseError;

using ReadableBufferMap

using sgns::blockchain::ReadableBufferMap = 
storage::face::Readable<base::Buffer, base::Buffer>;

using BlockId

using sgns::primitives::BlockId = boost::variant<BlockHash, BlockNumber>;

Block id is the variant over BlockHash and BlockNumber.

Functions Documentation

function idToBufferKey

outcome::result< base::Buffer > idToBufferKey(
    crdt::GlobalDB & db,
    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

function idToStringKey

outcome::result< std::string > idToStringKey(
    crdt::GlobalDB & db,
    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

function trieRoot

base::Buffer trieRoot(
    const std::vector< std::pair< base::Buffer, base::Buffer > > & key_vals
)

Parameters:

  • key_vals pairs and

Return: Buffer containing merkle root of resulting trie

Instantiate empty merkle trie, insert

function putWithPrefix

outcome::result< void > putWithPrefix(
    crdt::GlobalDB & db,
    prefix::Prefix prefix,
    primitives::BlockNumber num,
    base::Hash256 block_hash,
    const base::Buffer & value
)

Parameters:

  • db database to put the entry to
  • prefix keyspace for the entry value
  • num block number that could be used to retrieve the value
  • block_hash block hash that could be used to retrieve the value
  • value data to be put to the storage

Return: storage error if any

Put an entry to key space prefix and corresponding lookup keys to ID_TO_LOOKUP_KEY space.

function getWithPrefix

outcome::result< base::Buffer > getWithPrefix(
    crdt::GlobalDB & db,
    prefix::Prefix prefix,
    const primitives::BlockId & block_id
)

Parameters:

  • db database to get the entry from
  • prefix prefix with which the entry was put into
  • block_id id of the block to get entry for

Return: encoded entry or error

Get an entry from the database.

function NumberToBuffer

base::Buffer NumberToBuffer(
    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.

base::Buffer retval;

Little endian for ( std::size_t i = 0; i < sizeof(primitives::BlockNumber); ++i ) { retval.putUint8(static_cast((n >> (i * 8)) & 0xffu)) ; } return retval;

function numberAndHashToLookupKey

base::Buffer numberAndHashToLookupKey(
    primitives::BlockNumber number,
    const base::Hash256 & hash
)

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

function BufferToNumber

outcome::result< primitives::BlockNumber > BufferToNumber(
    const base::Buffer & key
)

Converts buffer data to a block number

function prependPrefix

base::Buffer prependPrefix(
    const base::Buffer & key,
    prefix::Prefix key_column
)

Parameters:

  • key key buffer
  • key_column prefix keyspace

Return: key_column|key

Concatenate prefix with key.

function isNotFoundError

bool isNotFoundError(
    outcome::result< void > result
)

For a persistant map based storage checks whether result should be considered as NOT FOUND error


Updated on 2026-03-04 at 13:10:43 -0800