package tezos-context

  1. Overview
  2. Docs

Tezos - Versioned, block indexed (key x value) store

type Tezos_base__TzPervasives.error +=
  1. | Cannot_create_file of string
  2. | Cannot_open_file of string
  3. | Cannot_find_protocol
  4. | Suspicious_file of int

Generic interface

module type S = sig ... end
include S
include Tezos_context_sigs.Context.VIEW with type key = string list and type value = bytes
type t

The type for context views.

type key = string list

The type for context keys.

type value = bytes

The type for context values.

type tree

The type for context trees.

Getters

val mem : t -> key -> bool Lwt.t

mem t k is an Lwt promise that resolves to true iff k is bound to a value in t.

val mem_tree : t -> key -> bool Lwt.t

mem_tree t k is like mem but for trees.

val find : t -> key -> value option Lwt.t

find t k is an Lwt promise that resolves to Some v if k is bound to the value v in t and None otherwise.

val find_tree : t -> key -> tree option Lwt.t

find_tree t k is like find but for trees.

val list : t -> ?offset:int -> ?length:int -> key -> (string * tree) list Lwt.t

list t key is the list of files and sub-nodes stored under k in t. The result order is not specified but is stable.

offset and length are used for pagination.

Setters

val add : t -> key -> value -> t Lwt.t

add t k v is an Lwt promise that resolves to c such that:

  • k is bound to v in c;
  • and c is similar to t otherwise.

If k was already bound in t to a value that is physically equal to v, the result of the function is a promise that resolves to t. Otherwise, the previous binding of k in t disappears.

val add_tree : t -> key -> tree -> t Lwt.t

add_tree is like add but for trees.

val remove : t -> key -> t Lwt.t

remove t k v is an Lwt promise that resolves to c such that:

  • k is unbound in c;
  • and c is similar to t otherwise.

Folding

val fold : ?depth:[ `Eq of int | `Le of int | `Lt of int | `Ge of int | `Gt of int ] -> t -> key -> init:'a -> f:(key -> tree -> 'a -> 'a Lwt.t) -> 'a Lwt.t

fold ?depth t root ~init ~f recursively folds over the trees and values of t. The f callbacks are called with a key relative to root. f is never called with an empty key for values; i.e., folding over a value is a no-op.

Elements are traversed in lexical order of keys.

The depth is 0-indexed. If depth is set (by default it is not), then f is only called when the conditions described by the parameter is true:

  • Eq d folds over nodes and contents of depth exactly d.
  • Lt d folds over nodes and contents of depth strictly less than d.
  • Le d folds over nodes and contents of depth less than or equal to d.
  • Gt d folds over nodes and contents of depth strictly more than d.
  • Ge d folds over nodes and contents of depth more than or equal to d.
module Tree : sig ... end
type context = t
type index

A block-indexed (key x value) store directory.

val init : ?patch_context: (context -> (context, Tezos_error_monad.TzCore.error list) Stdlib.result Lwt.t) -> ?readonly:bool -> string -> index Lwt.t

Open or initialize a versioned store at a given path.

val close : index -> unit Lwt.t

Close the index. Does not fail when the context is already closed.

val sync : index -> unit Lwt.t

Sync the context with disk. Only useful for read-only instances. Does not fail when the context is not in read-only mode.

val compute_testchain_chain_id : Tezos_crypto.Block_hash.t -> Tezos_crypto.Chain_id.t
val compute_testchain_genesis : Tezos_crypto.Block_hash.t -> Tezos_crypto.Block_hash.t

merkle_tree t leaf_kind key returns a Merkle proof for key (i.e. whose hashes reach key). If leaf_kind is Block_services.Hole, the value at key is a hash. If leaf_kind is Block_services.Raw_context, the value at key is a Block_services.raw_context. Values higher in the returned tree are hashes of the siblings on the path to reach key.

Accessing and Updating Versions

val restore_integrity : ?ppf:Stdlib.Format.formatter -> index -> (int option, Tezos_error_monad.TzCore.error list) Stdlib.result

restore_integrity ppf index attempts to restore the context integrity of index. Returns None when nothing needs to be fixed and Some n with n the number of entries fixed. If needs be, the progress might be printed via ppf If the context integrity cannot be restored, Failure msg is thrown.

val exists : index -> Tezos_crypto.Context_hash.t -> bool Lwt.t
val checkout : index -> Tezos_crypto.Context_hash.t -> context option Lwt.t
val hash : time:Tezos_base.Time.Protocol.t -> ?message:string -> t -> Tezos_crypto.Context_hash.t
val commit : time:Tezos_base.Time.Protocol.t -> ?message:string -> context -> Tezos_crypto.Context_hash.t Lwt.t
val set_master : index -> Tezos_crypto.Context_hash.t -> unit Lwt.t

Predefined Fields

val remove_test_chain : context -> context Lwt.t
val fork_test_chain : context -> protocol:Tezos_crypto.Protocol_hash.t -> expiration:Tezos_base.Time.Protocol.t -> context Lwt.t
val clear_test_chain : index -> Tezos_crypto.Chain_id.t -> unit Lwt.t
val find_predecessor_block_metadata_hash : context -> Tezos_crypto.Block_metadata_hash.t option Lwt.t
val add_predecessor_block_metadata_hash : context -> Tezos_crypto.Block_metadata_hash.t -> context Lwt.t
val find_predecessor_ops_metadata_hash : context -> Tezos_crypto.Operation_metadata_list_list_hash.t option Lwt.t
val add_predecessor_ops_metadata_hash : context -> Tezos_crypto.Operation_metadata_list_list_hash.t -> context Lwt.t

Context dumping

module Protocol_data_legacy : sig ... end
module Block_data_legacy : sig ... end
module Pruned_block_legacy : sig ... end
val dump_context : index -> Tezos_crypto.Context_hash.t -> fd:Lwt_unix.file_descr -> (int, Tezos_error_monad.TzCore.error list) Stdlib.result Lwt.t
val restore_context : index -> expected_context_hash:Tezos_crypto.Context_hash.t -> nb_context_elements:int -> fd:Lwt_unix.file_descr -> (unit, Tezos_error_monad.TzCore.error list) Stdlib.result Lwt.t
val legacy_restore_context : ?expected_block:string -> index -> snapshot_file:string -> handle_block: (Tezos_shell_services.History_mode.Legacy.t -> (Tezos_crypto.Block_hash.t * Pruned_block_legacy.t) -> (unit, Tezos_error_monad.TzCore.error list) Stdlib.result Lwt.t) -> handle_protocol_data: (Protocol_data_legacy.t -> (unit, Tezos_error_monad.TzCore.error list) Stdlib.result Lwt.t) -> block_validation: (Tezos_base.Block_header.t option -> Tezos_crypto.Block_hash.t -> Pruned_block_legacy.t -> (unit, Tezos_error_monad.TzCore.error list) Stdlib.result Lwt.t) -> (Tezos_base.Block_header.t * Block_data_legacy.t * Tezos_crypto.Block_metadata_hash.t option * Tezos_crypto.Operation_metadata_hash.t list list option * Tezos_base.Block_header.t option * Tezos_shell_services.History_mode.Legacy.t, Tezos_error_monad.TzCore.error list) Stdlib.result Lwt.t
val legacy_read_metadata : snapshot_file:string -> (string * Tezos_shell_services.History_mode.Legacy.t, Tezos_error_monad.TzCore.error list) Stdlib.result Lwt.t
val check_protocol_commit_consistency : index -> expected_context_hash:Tezos_crypto.Context_hash.t -> given_protocol_hash:Tezos_crypto.Protocol_hash.t -> author:string -> message:string -> timestamp:Tezos_base.Time.Protocol.t -> test_chain_status:Tezos_base.Test_chain_status.t -> predecessor_block_metadata_hash:Tezos_crypto.Block_metadata_hash.t option -> predecessor_ops_metadata_hash: Tezos_crypto.Operation_metadata_list_list_hash.t option -> data_merkle_root:Tezos_crypto.Context_hash.t -> parents_contexts:Tezos_crypto.Context_hash.t list -> bool Lwt.t
OCaml

Innovation. Community. Security.