package tezos-store

  1. Overview
  2. Docs

The module for handling block-related operations such as storing and reading data associated to a single block.

type t

The abstract type for a block.

type block = t

The type alias for a block.

type metadata = Block_repr.metadata = {
  1. message : string option;
  2. max_operations_ttl : int;
  3. last_allowed_fork_level : Int32.t;
  4. block_metadata : Bytes.t;
  5. operations_metadata : Tezos_validation.Block_validation.operation_metadata list list;
}

The type for block's metadata.

val equal : block -> block -> bool

equal b1 b2 tests the equality between b1 and b2. Warning only block hashes are compared.

val is_known_valid : chain_store -> Tezos_crypto.Block_hash.t -> bool Lwt.t

is_known_valid chain_store bh tests that the block bh is known and valid in chain_store (i.e. the block is present in the block store).

val is_known_invalid : chain_store -> Tezos_crypto.Block_hash.t -> bool Lwt.t

is_known_invalid chain_store bh tests that the block bh is invalid in chain_store (i.e. the block is present in the invalid blocks file).

val is_known_prechecked : chain_store -> Tezos_crypto.Block_hash.t -> bool Lwt.t

is_known_prechecked chain_store bh tests that the block bh is prechecked in chain_store (i.e. the block is present in the prechecked block cache).

val is_known : chain_store -> Tezos_crypto.Block_hash.t -> bool Lwt.t

is_known chain_store bh tests that the block bh is either known valid or known invalid in chain_store.

val is_genesis : chain_store -> Tezos_crypto.Block_hash.t -> bool

is_genesis chain_store bh tests that the block bh is the genesis initialized in chain_store.

validity chain_store bh computes the Block_locator.validity (Unknown, Known_valid or Known_invalid) for the block bh in chain_store.

read_block chain_store ?distance bh tries to read in the chain_store the block bh or the predecessing block at the offset distance of bh. By default, distance is 0.

val read_block_opt : chain_store -> ?distance:int -> Tezos_crypto.Block_hash.t -> block option Lwt.t

read_block_opt chain_store ?distance bh optional version of read_block.

val read_block_by_level : chain_store -> int32 -> (block, Tezos_error_monad.TzCore.error list) result Lwt.t

read_block_by_level chain_store level reads in the chain_store the block at level. The block retrieved will be the (level(current_head) - level)-th predecessor of the chain_store's current head.

val read_block_by_level_opt : chain_store -> int32 -> block option Lwt.t

read_block_by_level_opt chain_store level optional version of read_block_by_level.

val read_block_metadata : ?distance:int -> chain_store -> Tezos_crypto.Block_hash.t -> (metadata option, Tezos_error_monad.TzCore.error list) result Lwt.t

read_block_metadata ?distance chain_store bh reads in the chain_store the metadata associated to the block bh or its distance-th predecessor if given. Returns None otherwise. By default, distance is 0.

Warning If the block is already read, prefer the usage of get_block_metadata which will memoize the result.

val read_block_metadata_opt : ?distance:int -> chain_store -> Tezos_crypto.Block_hash.t -> metadata option Lwt.t

read_block_metadata_opt ?distance chain_store bh same as read_block_metadata but returns None in case of errors.

val get_block_metadata : chain_store -> block -> (metadata, Tezos_error_monad.TzCore.error list) result Lwt.t

get_block_metadata chain_store block reads in the chain_store the metadata associated to the block. Returns None if the metadata cannot be retrieved. This function also memoize the result in the block structure so subsequent calls will be disk I/O free.

val get_block_metadata_opt : chain_store -> block -> metadata option Lwt.t

get_block_metadata_opt chain_store block optional version of get_block_metadata

val read_predecessor : chain_store -> block -> (block, Tezos_error_monad.TzCore.error list) result Lwt.t

read_predecessor chain_store block reads in the chain_store the direct predecessor of block. Returns None if it cannot be found.

val read_predecessor_opt : chain_store -> block -> block option Lwt.t

read_predecessor_opt chain_store block optional version of read_predecessor.

read_predecessor_of_hash chain_store bh reads in chain_store the predecessor's block of bh.

read_ancestor_hash chain_store ~distance bh retrieves in the chain_store the hash of the ancestor of the block bh at distance if it exists. Returns None otherwise.

val read_ancestor_hash_opt : chain_store -> distance:int -> Tezos_crypto.Block_hash.t -> Tezos_crypto.Block_hash.t option Lwt.t

read_ancestor_hash_opt chain_store ~distance bh same as read_ancestor_hash but returns None on errors.

val read_predecessor_of_hash_opt : chain_store -> Tezos_crypto.Block_hash.t -> block option Lwt.t

read_ancestor_opt chain_store block optional version of read_ancestor.

read_prechecked_block chain_store bh tries to read in the chain_store's prechecked block cache the block bh.

val read_prechecked_block_opt : chain_store -> Tezos_crypto.Block_hash.t -> block option Lwt.t

read_prechecked_block_opt chain_store bh optional version of read_prechecked_block.

store_block chain_store ~block_header ~operations validation_result stores in chain_store the block with its block_header, operations and validation result. Inconsistent blocks and validation will result in failures. Returns None if the block was already stored. If the block is correctly stored, the newly created block is returned.

If the block was successfully stored, then the block is removed from the prechecked block cache.

Warning The store will refuse to store blocks with no associated context's commit.

val store_prechecked_block : chain_store -> hash:Tezos_crypto.Block_hash.t -> block_header:Tezos_base.Block_header.t -> operations:Tezos_base.Operation.t list list -> (unit, Tezos_error_monad.TzCore.error list) result Lwt.t

store_prechecked_block chain_store ~hash ~block_header ~operations stores in chain_store's prechecked block cache the block with its block_header and operations.

context_exn chain_store block checkouts the context of the block.

val context_opt : chain_store -> block -> Tezos_context.Context.t option Lwt.t

context_opt chain_store block optional version of context_exn.

context chain_store block error monad version of context_exn.

val context_exists : chain_store -> block -> bool Lwt.t

context_exists chain_store block tests the existence of the block's commit in the context.

testchain_status chain_store block returns the test chain status stored in context of block along with testchain's genesis if the testchain is found Forking or Running.

val protocol_hash_exn : chain_store -> block -> Tezos_crypto.Protocol_hash.t Lwt.t

protocol_hash_exn chain_store block reads the protocol associated to block in its associated context. Fails when the context is unknown.

protocol_hash chain_store block error monad version of protocol_hash_exn.

val read_invalid_block_opt : chain_store -> Tezos_crypto.Block_hash.t -> Store_types.invalid_block option Lwt.t

read_invalid_block_opt chain_store bh reads in the chain_store the invalid block bh if it exists.

read_invalid_blocks chain_store returns the map of all invalid blocks of chain_store.

mark_invalid chain_store bh ~level errors stores the block bh at level with the given errors. Fails when trying to mark the genesis block as invalid.

unmark_invalid chain_store bh unmarks invalid the block bh in the chain_store.

descriptor block returns the pair (hash x level) of block.

Block field accessors

val operations : block -> Tezos_base.Operation.t list list
val level : block -> int32
val proto_level : block -> int
val predecessor : block -> Tezos_crypto.Block_hash.t
val validation_passes : block -> int
val fitness : block -> Tezos_base.Fitness.t
val context_hash : block -> Tezos_crypto.Context_hash.t
val protocol_data : block -> bytes
val block_metadata_hash : block -> Tezos_crypto.Block_metadata_hash.t option
val operations_metadata_hashes : block -> Tezos_crypto.Operation_metadata_hash.t list list option
val operations_metadata_hashes_path : block -> int -> Tezos_crypto.Operation_metadata_hash.t list option
val all_operations_metadata_hash : block -> Tezos_crypto.Operation_metadata_list_list_hash.t option

Block metadata field accessors

val message : metadata -> string option
val max_operations_ttl : metadata -> int
val last_allowed_fork_level : metadata -> int32
val block_metadata : metadata -> Bytes.t
val operations_metadata : metadata -> Tezos_validation.Block_validation.operation_metadata list list

operations_path block nth computes the nth operations list of block along with the hash of all operations.

operations_hashes_path block nth computes the nth operations hash list of block along with the hash of all operations.

val all_operation_hashes : block -> Tezos_crypto.Operation_hash.t list list

all_operation_hashes block computes the hash of all operations in block.

OCaml

Innovation. Community. Security.