Octez_smart_rollup_node.Layer1This 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 = {hash : Tezos_base.TzPervasives.Block_hash.t;level : int32;header : Tezos_base.Block_header.shell_header;}val header_encoding : header Tezos_base.TzPervasives.Data_encoding.tval head_encoding : head Tezos_base.TzPervasives.Data_encoding.tAn 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 raw_l1_connection : t -> Octez_crawler.Layer_1.tReturns the raw L1 connection to allow for monitoring by others.
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 create :
name:string ->
reconnection_delay:float ->
l1_blocks_cache_size:int ->
?protocols:
Tezos_base.TzPervasives.Protocol_hash.t Tezos_base.TzPervasives.trace ->
?prefetch_blocks:int ->
Tezos_client_base.Client_context.full ->
t Tezos_base.TzPervasives.tzresultSame as start but does not start monitoring L1 blocks.
val shutdown : t -> unit Lwt.tshutdown t properly shuts the layer 1 down.
val get_chain_id :
t ->
Tezos_base.TzPervasives.Chain_id.t Tezos_base.TzPervasives.tzresult Lwt.tget_chain_id t retreives the chain id of the layer 1 chain.
val iter_heads :
?name:string ->
t ->
(header -> unit Tezos_base.TzPervasives.tzresult Lwt.t) ->
unit Tezos_base.TzPervasives.tzresult Lwt.titer_heads ?name 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. A name can be provided to differentiate iterations on the same connection.
val iter_finalized_heads :
?name:string ->
prefetch:(t -> head -> unit) ->
t ->
(header -> unit Tezos_base.TzPervasives.tzresult Lwt.t) ->
unit Tezos_base.TzPervasives.tzresult Lwt.titer_finalized_heads ?name ~prefetch t f is the same as iter_heads but only iterates on blocks that are considered finalized. prefetch is a function that is called as soon as a block is seen on L1, even if it's unfinalized, to prefetch it for the next processing call.
wait_first t waits for the first head to appear in the stream and returns it.
get_latest_head t returns the latest L1 head if at least one was seen by t. The head is the one sent by the heads monitoring RPC of the L1 node, independently of how they were processed by the current process.
val get_status : t -> [ `Connected | `Disconnected | `Reconnecting ]get_status t returns the connection status to the L1 node.
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.
val client_context : t -> Tezos_client_base.Client_context.fullReturns 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.