Mavkit_smart_rollup_node.Layer1
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 Mavryk node.
type header = {
hash : Mavryk_base.TzPervasives.Block_hash.t;
level : int32;
header : Mavryk_base.Block_header.shell_header;
}
val header_encoding : header Mavryk_base.TzPervasives.Data_encoding.t
val head_encoding : head Mavryk_base.TzPervasives.Data_encoding.t
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 =
Mavryk_client_base.Client_context.full ->
?metadata:[ `Always | `Never ] ->
?chain:Mavryk_shell_services.Block_services.chain ->
?block:Mavryk_shell_services.Block_services.block ->
unit ->
block Mavryk_base.TzPervasives.tzresult Lwt.t
Type of protocol specific functions for fetching protocol specific blocks.
val raw_l1_connection : t -> Mavkit_crawler.Layer_1.t
Returns the raw L1 connection to allow for monitoring by others.
val start :
name:string ->
reconnection_delay:float ->
l1_blocks_cache_size:int ->
?protocols:Mavryk_base.TzPervasives.Protocol_hash.t list ->
?prefetch_blocks:int ->
Mavryk_client_base.Client_context.full ->
t Mavryk_base.TzPervasives.tzresult Lwt.t
start ~name ~reconnection_delay ~l1_blocks_cache_size ?protocols cctxt
connects to a Mavryk 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:
Mavryk_base.TzPervasives.Protocol_hash.t Mavryk_base.TzPervasives.trace ->
?prefetch_blocks:int ->
Mavryk_client_base.Client_context.full ->
t Mavryk_base.TzPervasives.tzresult
Same as start
but does not start monitoring L1 blocks.
val shutdown : t -> unit Lwt.t
shutdown t
properly shuts the layer 1 down.
val iter_heads :
?name:string ->
t ->
(header -> unit Mavryk_base.TzPervasives.tzresult Lwt.t) ->
unit Mavryk_base.TzPervasives.tzresult Lwt.t
iter_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.
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_predecessor_opt :
?max_read:int ->
t ->
(Mavryk_base.TzPervasives.Block_hash.t * int32) ->
(Mavryk_base.TzPervasives.Block_hash.t * int32) option
Mavryk_base.TzPervasives.tzresult
Lwt.t
val get_predecessor :
?max_read:int ->
t ->
(Mavryk_base.TzPervasives.Block_hash.t * int32) ->
(Mavryk_base.TzPervasives.Block_hash.t * int32)
Mavryk_base.TzPervasives.tzresult
Lwt.t
val get_mavryk_reorg_for_new_head :
t ->
?get_old_predecessor:
((Mavryk_base.TzPervasives.Block_hash.t * int32) ->
(Mavryk_base.TzPervasives.Block_hash.t * int32)
Mavryk_base.TzPervasives.tzresult
Lwt.t) ->
[ `Head of Mavryk_base.TzPervasives.Block_hash.t * int32 | `Level of int32 ] ->
(Mavryk_base.TzPervasives.Block_hash.t * int32) ->
(Mavryk_base.TzPervasives.Block_hash.t * int32) Mavkit_crawler.Reorg.t
Mavryk_base.TzPervasives.tzresult
Lwt.t
val cache_shell_header :
t ->
Mavryk_base.TzPervasives.Block_hash.t ->
Mavryk_base.Block_header.shell_header ->
unit
Register a block header in the cache.
val client_context : t -> Mavryk_client_base.Client_context.full
Returns the client context used by the L1 monitor.
val fetch_mavryk_shell_header :
t ->
Mavryk_base.TzPervasives.Block_hash.t ->
Mavryk_base.Block_header.shell_header Mavryk_base.TzPervasives.tzresult Lwt.t
fetch_mavryk_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_mavryk_block :
fetch_block_rpc ->
(block -> Mavryk_base.Block_header.shell_header) ->
t ->
Mavryk_base.TzPervasives.Block_hash.t ->
block Mavryk_base.TzPervasives.tzresult Lwt.t
fetch_mavryk_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 Mavryk_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_mavryk_blocks :
fetch_block_rpc ->
(block -> Mavryk_base.Block_header.shell_header) ->
t ->
head list ->
unit
prefetch_mavryk_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.