Octez_smart_rollup_node.Layer1SourceThis 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 Tezos_base.TzPervasives.error += | Cannot_find_block of Tezos_base.TzPervasives.Block_hash.ttype header = {hash : Tezos_base.TzPervasives.Block_hash.t;level : int32;header : Tezos_base.Block_header.shell_header;}An extensible type for the protocol specific full blocks. This allows to have a single cache for blocks from all protocols.
type fetch_block_rpc =
Tezos_client_base.Client_context.full ->
?metadata:[ `Always | `Never ] ->
?chain:Tezos_shell_services.Block_services.chain ->
?block:Tezos_shell_services.Block_services.block ->
unit ->
block Tezos_base.TzPervasives.tzresult Lwt.tType 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.tstart ~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 iter_heads :
t ->
(header -> unit Tezos_base.TzPervasives.tzresult Lwt.t) ->
unit Tezos_base.TzPervasives.tzresult Lwt.titer_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.
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.tval get_predecessor :
?max_read:int ->
t ->
(Tezos_base.TzPervasives.Block_hash.t * int32) ->
(Tezos_base.TzPervasives.Block_hash.t * int32)
Tezos_base.TzPervasives.tzresult
Lwt.tval get_tezos_reorg_for_new_head :
t ->
?get_old_predecessor:
((Tezos_base.TzPervasives.Block_hash.t * int32) ->
(Tezos_base.TzPervasives.Block_hash.t * int32)
Tezos_base.TzPervasives.tzresult
Lwt.t) ->
[ `Head of Tezos_base.TzPervasives.Block_hash.t * int32 | `Level of int32 ] ->
(Tezos_base.TzPervasives.Block_hash.t * int32) ->
(Tezos_base.TzPervasives.Block_hash.t * int32) Octez_crawler.Reorg.t
Tezos_base.TzPervasives.tzresult
Lwt.tval cache_shell_header :
t ->
Tezos_base.TzPervasives.Block_hash.t ->
Tezos_base.Block_header.shell_header ->
unitRegister a block header in the cache.
Returns the client context used by the L1 monitor.
val fetch_tezos_shell_header :
t ->
Tezos_base.TzPervasives.Block_hash.t ->
Tezos_base.Block_header.shell_header Tezos_base.TzPervasives.tzresult Lwt.tfetch_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.
val fetch_tezos_block :
fetch_block_rpc ->
(block -> Tezos_base.Block_header.shell_header) ->
t ->
Tezos_base.TzPervasives.Block_hash.t ->
block Tezos_base.TzPervasives.tzresult Lwt.tfetch_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) listmake_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 ->
unitprefetch_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.