Store.Block
The module for handling block-related operations such as storing and reading data associated to a single block.
type block = t
The type alias for a block.
type metadata = Mavryk_store_shared.Block_repr.metadata = {
message : string option;
max_operations_ttl : int;
last_preserved_block_level : Stdlib.Int32.t;
block_metadata : Mavryk_base.TzPervasives.Bytes.t;
operations_metadata : Mavryk_validation.Block_validation.operation_metadata
list
list;
}
The type for block's metadata.
equal b1 b2
tests the equality between b1
and b2
. Warning only block hashes are compared.
val is_known_valid :
chain_store ->
Mavryk_base.TzPervasives.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 ->
Mavryk_base.TzPervasives.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_validated :
chain_store ->
Mavryk_base.TzPervasives.Block_hash.t ->
bool Lwt.t
is_known_validated chain_store bh
tests that the block bh
is validated in chain_store
(i.e. the block is present in the validated block cache).
val is_known :
chain_store ->
Mavryk_base.TzPervasives.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 -> Mavryk_base.TzPervasives.Block_hash.t -> bool
is_genesis chain_store bh
tests that the block bh
is the genesis initialized in chain_store
.
val validity :
chain_store ->
Mavryk_base.TzPervasives.Block_hash.t ->
Mavryk_base.TzPervasives.Block_locator.validity Lwt.t
validity chain_store bh
computes the Block_locator
.validity (Unknown
, Known_valid
or Known_invalid
) for the block bh
in chain_store
.
val read_block :
chain_store ->
?distance:int ->
Mavryk_base.TzPervasives.Block_hash.t ->
block Mavryk_base.TzPervasives.tzresult Lwt.t
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 ->
Mavryk_base.TzPervasives.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 Mavryk_base.TzPervasives.tzresult 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 ->
Mavryk_base.TzPervasives.Block_hash.t ->
metadata option Mavryk_base.TzPervasives.tzresult 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 ->
Mavryk_base.TzPervasives.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 Mavryk_base.TzPervasives.tzresult 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 Mavryk_base.TzPervasives.tzresult 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
.
val read_predecessor_of_hash :
chain_store ->
Mavryk_base.TzPervasives.Block_hash.t ->
block Mavryk_base.TzPervasives.tzresult Lwt.t
read_predecessor_of_hash chain_store bh
reads in chain_store
the predecessor's block of bh
.
val read_ancestor_hash :
chain_store ->
distance:int ->
Mavryk_base.TzPervasives.Block_hash.t ->
Mavryk_base.TzPervasives.Block_hash.t option
Mavryk_base.TzPervasives.tzresult
Lwt.t
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 ->
Mavryk_base.TzPervasives.Block_hash.t ->
Mavryk_base.TzPervasives.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 ->
Mavryk_base.TzPervasives.Block_hash.t ->
block option Lwt.t
read_ancestor_opt chain_store block
optional version of read_ancestor
.
val read_validated_block :
chain_store ->
Mavryk_base.TzPervasives.Block_hash.t ->
block Mavryk_base.TzPervasives.tzresult Lwt.t
read_validated_block chain_store bh
tries to read in the chain_store
's validated block cache the block bh
.
val read_validated_block_opt :
chain_store ->
Mavryk_base.TzPervasives.Block_hash.t ->
block option Lwt.t
read_validated_block_opt chain_store bh
optional version of read_validated_block
.
val store_block :
chain_store ->
block_header:Mavryk_base.TzPervasives.Block_header.t ->
operations:Mavryk_base.TzPervasives.Operation.t list list ->
Mavryk_validation.Block_validation.result ->
block option Mavryk_base.TzPervasives.tzresult Lwt.t
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 validated block cache.
Warning The store will refuse to store blocks with no associated context's commit.
val store_validated_block :
chain_store ->
hash:Mavryk_base.TzPervasives.Block_hash.t ->
block_header:Mavryk_base.TzPervasives.Block_header.t ->
operations:
Mavryk_base.TzPervasives.Operation.t Mavryk_base.TzPervasives.trace
Mavryk_base.TzPervasives.trace ->
unit Mavryk_base.TzPervasives.tzresult Lwt.t
store_validated_block chain_store ~hash ~block_header ~operations
stores in chain_store
's validated block cache the block with its block_header
and operations
.
val resulting_context_hash :
chain_store ->
block ->
Mavryk_base.TzPervasives.Context_hash.t Mavryk_base.TzPervasives.tzresult
Lwt.t
resulting_context_hash chain_store block
returns the resulting context hash of the block
. This context depends on the block
's protocol associated semantics, i.e., it can either be the one contained in its block header or the stored result of its application.
val context_exn :
chain_store ->
block ->
Mavryk_protocol_environment.Context.t Lwt.t
context_exn chain_store block
checkouts the resulting context of the block
which may differ from its block header's one depending on the block's associated protocol semantics.
val context_opt :
chain_store ->
block ->
Mavryk_protocol_environment.Context.t option Lwt.t
context_opt chain_store block
optional version of context_exn
.
val context :
chain_store ->
block ->
Mavryk_protocol_environment.Context.t Mavryk_base.TzPervasives.tzresult Lwt.t
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.
val testchain_status :
chain_store ->
block ->
(Mavryk_base.TzPervasives.Test_chain_status.t
* Mavryk_base.TzPervasives.Block_hash.t option)
Mavryk_base.TzPervasives.tzresult
Lwt.t
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 ->
Mavryk_base.TzPervasives.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.
val protocol_hash :
chain_store ->
block ->
Mavryk_base.TzPervasives.Protocol_hash.t Mavryk_base.TzPervasives.tzresult
Lwt.t
protocol_hash chain_store block
error monad version of protocol_hash_exn
.
val read_invalid_block_opt :
chain_store ->
Mavryk_base.TzPervasives.Block_hash.t ->
Mavryk_store_shared.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.
val read_invalid_blocks :
chain_store ->
Mavryk_store_shared.Store_types.invalid_block
Mavryk_base.TzPervasives.Block_hash.Map.t
Lwt.t
read_invalid_blocks chain_store
returns the map of all invalid blocks of chain_store
.
val mark_invalid :
chain_store ->
Mavryk_base.TzPervasives.Block_hash.t ->
level:int32 ->
Mavryk_base.TzPervasives.error list ->
unit Mavryk_base.TzPervasives.tzresult Lwt.t
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.
val unmark_invalid :
chain_store ->
Mavryk_base.TzPervasives.Block_hash.t ->
unit Mavryk_base.TzPervasives.tzresult Lwt.t
unmark_invalid chain_store bh
unmarks invalid the block bh
in the chain_store
.
val descriptor : block -> Mavryk_store_shared.Store_types.block_descriptor
descriptor block
returns the pair (hash x level) of block
.
val hash : block -> Mavryk_base.TzPervasives.Block_hash.t
val header : block -> Mavryk_base.TzPervasives.Block_header.t
val operations : block -> Mavryk_base.TzPervasives.Operation.t list list
val shell_header : block -> Mavryk_base.TzPervasives.Block_header.shell_header
val level : block -> int32
val proto_level : block -> int
val predecessor : block -> Mavryk_base.TzPervasives.Block_hash.t
val timestamp : block -> Mavryk_base.TzPervasives.Time.Protocol.t
val validation_passes : block -> int
val operations_hash :
block ->
Mavryk_base.TzPervasives.Operation_list_list_hash.t
val fitness : block -> Mavryk_base.TzPervasives.Fitness.t
val context_hash : block -> Mavryk_base.TzPervasives.Context_hash.t
val protocol_data : block -> bytes
val block_metadata_hash :
block ->
Mavryk_base.TzPervasives.Block_metadata_hash.t option
val operations_metadata_hashes :
block ->
Mavryk_base.TzPervasives.Operation_metadata_hash.t list list option
val operations_metadata_hashes_path :
block ->
int ->
Mavryk_base.TzPervasives.Operation_metadata_hash.t list option
val all_operations_metadata_hash :
block ->
Mavryk_base.TzPervasives.Operation_metadata_list_list_hash.t option
val message : metadata -> string option
val max_operations_ttl : metadata -> int
val last_preserved_block_level : metadata -> int32
val block_metadata : metadata -> Mavryk_base.TzPervasives.Bytes.t
val operations_metadata :
metadata ->
Mavryk_validation.Block_validation.operation_metadata list list
val operations_path :
block ->
int ->
Mavryk_base.TzPervasives.Operation.t list
* Mavryk_base.TzPervasives.Operation_list_list_hash.path
operations_path block nth
computes the nth
operations list of block
along with the hash of all operations.
val operations_hashes_path :
block ->
int ->
Mavryk_base.TzPervasives.Operation_hash.t list
* Mavryk_base.TzPervasives.Operation_list_list_hash.path
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 ->
Mavryk_base.TzPervasives.Operation_hash.t list list
all_operation_hashes block
computes the hash of all operations in block
.