package octez-smart-rollup-node-lib

  1. Overview
  2. Docs
On This Page
  1. Helpers
Legend:
Library
Module
Module type
Parameter
Class
Class type

This module maintains information about the layer 1 chain.

This module follows the evolution of the layer 1 chain by subscribing to the head monitoring RPC offered by the Tezos node.

type header = {
  1. hash : Tezos_base.TzPervasives.Block_hash.t;
  2. level : int32;
  3. header : Tezos_base.Block_header.shell_header;
}
type head = {
  1. hash : Tezos_base.TzPervasives.Block_hash.t;
  2. level : int32;
}
val head_of_header : header -> head
type t
type block = ..

An extensible type for the protocol specific full blocks. This allows to have a single cache for blocks from all protocols.

Type of protocol specific functions for fetching protocol specific blocks.

val start : name:string -> reconnection_delay:float -> l1_blocks_cache_size:int -> ?protocols:Tezos_base.TzPervasives.Protocol_hash.t list -> ?prefetch_blocks:int -> Tezos_client_base.Client_context.full -> t Tezos_base.TzPervasives.tzresult Lwt.t

start ~name ~reconnection_delay ~l1_blocks_cache_size ?protocols cctxt connects to a Tezos node and starts monitoring new heads. One can iterate on the heads by calling iter_heads on its result. reconnection_delay gives an initial delay for the reconnection which is used in an exponential backoff. The name is used to differentiate events. l1_blocks_cache_size is the size of the caches for the blocks and headers. If protocols is provided, only heads of these protocols will be monitored.

val shutdown : t -> unit Lwt.t

shutdown t properly shuts the layer 1 down.

iter_heads t f calls f on all new heads appearing in the layer 1 chain. In case of a disconnection with the layer 1 node, it reconnects automatically. If f returns an error (other than a disconnection) it, iter_heads terminates and returns the error.

val wait_first : t -> header Lwt.t

wait_first t waits for the first head to appear in the stream and returns it.

val get_predecessor_opt : ?max_read:int -> t -> (Tezos_base.TzPervasives.Block_hash.t * int32) -> (Tezos_base.TzPervasives.Block_hash.t * int32) option Tezos_base.TzPervasives.tzresult Lwt.t

Helpers

Register a block header in the cache.

Returns the client context used by the L1 monitor.

fetch_tezos_shell_header cctxt hash returns the block shell header of hash. Looks for the block in the blocks cache first, and fetches it from the L1 node otherwise.

fetch_tezos_block fetch extract_header cctxt hash returns a block info given a block hash. Looks for the block in the blocks cache first, and fetches it from the L1 node otherwise.

val make_prefetching_schedule : t -> 'block Tezos_base.TzPervasives.trace -> ('block * 'block list) list

make_prefetching_schedule l1_ctxt blocks returns the list blocks with each element associated to a list of blocks to prefetch of at most l1_ctxt.prefetch_blocks. If blocks = [b1; ...; bn] and prefetch_blocks = 3 then the result will be (b1, [b1;b2;b3]); (b2, []); (b3, []); (b4, [b4;b5;b6]); ....

val prefetch_tezos_blocks : fetch_block_rpc -> (block -> Tezos_base.Block_header.shell_header) -> t -> head list -> unit

prefetch_tezos_blocks fetch extract_header l1_ctxt blocks prefetches the blocks asynchronously. NOTE: the number of blocks to prefetch must not be greater than the size of the blocks cache otherwise they will be lost.

OCaml

Innovation. Community. Security.