diff --git a/contrib/octez_injector_server/injector_daemon_http.ml b/contrib/octez_injector_server/injector_daemon_http.ml index f2cf3c259597a9482b5f143125ce0eb989d4f7d1..30ed563b41c944a561e07ccca76fa6f5258b5241 100644 --- a/contrib/octez_injector_server/injector_daemon_http.ml +++ b/contrib/octez_injector_server/injector_daemon_http.ml @@ -133,8 +133,13 @@ let run ~data_dir (cctxt : Client_context.full) = Configuration.load ~data_dir in let*? signers = make_signers_for_transactions signer block_delay in + let chain = cctxt#chain in let*! l1_ctxt = - Octez_crawler.Layer_1.start ~name:"injector" ~reconnection_delay:2.0 cctxt + Octez_crawler.Layer_1.start + ~name:"injector" + ~chain + ~reconnection_delay:2.0 + (cctxt :> Tezos_rpc.Context.generic) in let* () = Injector_server.init cctxt l1_ctxt ~data_dir state ~signers in let*! () = Event.(emit accepting_requests) ("HTTP", config.rpc_port) in diff --git a/src/lib_crawler/layer_1.ml b/src/lib_crawler/layer_1.ml index 4f68bdd5c65e0bf10263b10a450b3d4cc854ef2d..1ef3b97a5374f06a9e2fb55a69394d4d8b94b848 100644 --- a/src/lib_crawler/layer_1.ml +++ b/src/lib_crawler/layer_1.ml @@ -110,9 +110,10 @@ type connection_status = type t = { name : string; + chain : Tezos_shell_services.Chain_services.chain; protocols : Protocol_hash.t list option; reconnection_delay : float; - cctxt : Client_context.full; + cctxt : Tezos_rpc.Context.generic; mutable last_seen : (Block_hash.t * Block_header.t) option; mutable status : connection_status; } @@ -123,7 +124,8 @@ let is_running c = | Connected _ | Connecting _ -> true let rec do_connect ~count ~previous_status - ({name; protocols; reconnection_delay = delay; cctxt; _} as l1_ctxt) = + ({name; protocols; reconnection_delay = delay; cctxt; chain; _} as l1_ctxt) + = assert (match l1_ctxt.status with Connecting _ -> true | _ -> false) ; let open Lwt_syntax in let* () = @@ -143,7 +145,7 @@ let rec do_connect ~count ~previous_status Lwt_unix.sleep delay in let* res = - Tezos_shell_services.Monitor_services.heads ?protocols cctxt cctxt#chain + Tezos_shell_services.Monitor_services.heads ?protocols cctxt chain in match res with | Ok (heads, stopper) -> @@ -190,20 +192,21 @@ let connect l1_ctxt = Lwt_condition.wait c | Disconnected -> do_connect l1_ctxt -let create ~name ~reconnection_delay ?protocols (cctxt : #Client_context.full) = +let create ~name ~chain ~reconnection_delay ?protocols cctxt = { name; - cctxt = (cctxt :> Client_context.full); + chain; + cctxt; reconnection_delay; protocols; last_seen = None; status = Disconnected; } -let start ~name ~reconnection_delay ?protocols (cctxt : #Client_context.full) = +let start ~name ~chain ~reconnection_delay ?protocols cctxt = let open Lwt_syntax in let* () = Layer1_event.starting ~name in - let l1_ctxt = create ~name ~reconnection_delay ?protocols cctxt in + let l1_ctxt = create ~name ~chain ~reconnection_delay ?protocols cctxt in let* (_ : connection_info) = connect l1_ctxt in return l1_ctxt @@ -415,7 +418,7 @@ let get_predecessor_opt ?(max_read = 8) state (hash, level) = if level = 0l then return_none else let level = Int32.pred level in - let+ hash = get_predecessor ~max_read state.cctxt state.cctxt#chain hash in + let+ hash = get_predecessor ~max_read state.cctxt state.chain hash in Option.map (fun hash -> (hash, level)) hash let get_predecessor ?max_read state ((hash, _) as head) = @@ -512,8 +515,9 @@ module Internal_for_tests = struct let dummy cctxt = { name = "dummy_layer_1_for_tests"; + chain = `Main; reconnection_delay = 5.0; - cctxt = (cctxt :> Client_context.full); + cctxt; protocols = None; last_seen = None; status = Disconnected; diff --git a/src/lib_crawler/layer_1.mli b/src/lib_crawler/layer_1.mli index a3d619b2086913294bdbbecfbf7f1a6ecb3ec97d..2194759e8f591116218fb6225414f6432837798f 100644 --- a/src/lib_crawler/layer_1.mli +++ b/src/lib_crawler/layer_1.mli @@ -44,9 +44,10 @@ type t protocols will be monitored. *) val start : name:string -> + chain:Tezos_shell_services.Chain_services.chain -> reconnection_delay:float -> ?protocols:Protocol_hash.t list -> - #Client_context.full -> + Tezos_rpc.Context.generic -> t Lwt.t (** [create ~name ~reconnection_delay ?protocols cctxt] creates a Layer 1 @@ -55,9 +56,10 @@ val start : protocols will be monitored. *) val create : name:string -> + chain:Tezos_shell_services.Chain_services.chain -> reconnection_delay:float -> ?protocols:Protocol_hash.t list -> - #Client_context.full -> + Tezos_rpc.Context.generic -> t (** [shutdown t] properly shuts the layer 1 down. This function is to be used on @@ -145,5 +147,5 @@ module Internal_for_tests : sig (** Create a dummy Layer 1 object that does not follow any L1 chain. This function is only to be used as a placeholder for unit tests (that do not exercise the Layer 1 connection). *) - val dummy : #Client_context.full -> t + val dummy : Tezos_rpc.Context.generic -> t end diff --git a/src/lib_smart_rollup_node/layer1.ml b/src/lib_smart_rollup_node/layer1.ml index ecf07c07f5f9d664a345453900a0e2dc8f00d77c..dc485f7a64670e0d6d0c945e6d0f818036340ec2 100644 --- a/src/lib_smart_rollup_node/layer1.ml +++ b/src/lib_smart_rollup_node/layer1.ml @@ -124,10 +124,18 @@ let start ~name ~reconnection_delay ~l1_blocks_cache_size ?protocols l1_blocks_cache_size else Ok () in - let*! l1 = start ~name ~reconnection_delay ?protocols cctxt in + let chain = cctxt#chain in + let*! l1 = + start + ~name + ~chain + ~reconnection_delay + ?protocols + (cctxt :> Tezos_rpc.Context.generic) + in + let cctxt = (cctxt :> Client_context.full) in let blocks_cache = Blocks_cache.create l1_blocks_cache_size in let headers_cache = Blocks_cache.create l1_blocks_cache_size in - let cctxt = (cctxt :> Client_context.full) in return {l1; cctxt; blocks_cache; headers_cache; prefetch_blocks} let create ~name ~reconnection_delay ~l1_blocks_cache_size ?protocols @@ -140,10 +148,18 @@ let create ~name ~reconnection_delay ~l1_blocks_cache_size ?protocols l1_blocks_cache_size else Ok () in - let l1 = create ~name ~reconnection_delay ?protocols cctxt in + let chain = cctxt#chain in + let l1 = + create + ~name + ~chain + ~reconnection_delay + ?protocols + (cctxt :> Tezos_rpc.Context.generic) + in + let cctxt = (cctxt :> Client_context.full) in let blocks_cache = Blocks_cache.create l1_blocks_cache_size in let headers_cache = Blocks_cache.create l1_blocks_cache_size in - let cctxt = (cctxt :> Client_context.full) in return {l1; cctxt; blocks_cache; headers_cache; prefetch_blocks} let shutdown {l1; _} = shutdown l1 @@ -183,7 +199,7 @@ let get_tezos_reorg_for_new_head {l1; _} ?get_old_predecessor old_head new_head module Internal_for_tests = struct let dummy cctxt = { - l1 = Internal_for_tests.dummy cctxt; + l1 = Internal_for_tests.dummy (cctxt :> Tezos_rpc.Context.generic); cctxt = (cctxt :> Client_context.full); blocks_cache = Blocks_cache.create 1; headers_cache = Blocks_cache.create 1;