package tezos-protocol-011-PtHangz2
The following module acts on the whole cache, not on a specific sub-cache, unlike Interface
. It is used to administrate the protocol cache, e.g., to maintain the cache in a consistent state with respect to the chain. This module is typically used by low-level layers of the protocol and by the shell.
val pp :
Tezos_protocol_environment_011_PtHangz2.Format.formatter ->
context ->
unit
pp fmt ctxt
is a pretty printter for the cache
of ctxt
.
val set_cache_layout :
context ->
size list ->
context Tezos_protocol_environment_011_PtHangz2.Lwt.t
set_cache_layout ctxt layout
sets the caches of ctxt
to comply with given layout
. If there was already a cache in ctxt
, it is erased by the new layout.
In that case, a fresh collection of empty caches is reconstructed from the new layout
. Notice that cache key
s are invalidated in that case, i.e., find t k
will return None
.
val sync :
context ->
cache_nonce:Tezos_protocol_environment_011_PtHangz2.Bytes.t ->
context Tezos_protocol_environment_011_PtHangz2.Lwt.t
sync ctxt ~cache_nonce
updates the context with the domain of the cache computed so far. Such function is expected to be called at the end of the validation of a block, when there is no more accesses to the cache.
cache_nonce
identifies the block that introduced new cache entries. The nonce should identify uniquely the block which modifies this value. It cannot be the block hash for circularity reasons: The value of the nonce is stored onto the context and consequently influences the context hash of the very same block. Such nonce cannot be determined by the shell and its computation is delegated to the economic protocol.
Cache helpers for RPCs
future_cache_expectation ctxt ~time_in_blocks
returns ctxt
except that the entries of the caches that are presumably too old to still be in the caches in n_blocks
are removed.
This function is based on a heuristic. The context maintains the median of the number of removed entries: this number is multipled by `n_blocks` to determine the entries that are likely to be removed in `n_blocks`.
cache_size ctxt ~cache_index
returns an overapproximation of the size of the cache. Returns None
if cache_index
is greater than the number of subcaches declared by the cache layout.
cache_size_limit ctxt ~cache_index
returns the maximal size of the cache indexed by cache_index
. Returns None
if cache_index
is greater than the number of subcaches declared by the cache layout.
val value_of_key :
context ->
Tezos_protocol_environment_011_PtHangz2.Context.Cache.key ->
Tezos_protocol_environment_011_PtHangz2.Context.Cache.value
Tezos_protocol_environment_011_PtHangz2.Error_monad.tzresult
Tezos_protocol_environment_011_PtHangz2.Lwt.t
value_of_key ctxt k
interprets the functions introduced by register
to construct a cacheable value for a key k
.