package tezos-protocol-012-Psithaca

  1. Overview
  2. Docs
Module type
Class type

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.

type key

A key uniquely identifies a cached value in some subcache.

type value

Cached values.

val pp : Stdlib.Format.formatter -> Raw_context.t -> unit

pp fmt ctxt is a pretty printter for the cache of ctxt.

val set_cache_layout : Raw_context.t -> size list -> Raw_context.t 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 keys are invalidated in that case, i.e. find t k will return None.

val sync : Raw_context.t -> cache_nonce:bytes -> Raw_context.t 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.

clear ctxt removes all cache entries.

Cache helpers for RPCs

val future_cache_expectation : Raw_context.t -> time_in_blocks:int -> Raw_context.t

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`.

val cache_size : Raw_context.t -> cache_index:int -> size option

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.

val cache_size_limit : Raw_context.t -> cache_index:int -> size option

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 : Raw_context.t -> Environment_context.Context.cache_key -> (Environment_context.Context.cache_value, Tezos_protocol_environment_012_Psithaca__Environment.Error_monad.error Tezos_protocol_environment_012_Psithaca__Environment.Error_monad.trace) Stdlib.result Lwt.t

value_of_key ctxt k interprets the functions introduced by register to construct a cacheable value for a key k.


Innovation. Community. Security.