From 6968371b93abf0e0fac290f28ff2d52d1e3d9da5 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Tue, 2 May 2023 11:03:15 +0200 Subject: [PATCH 1/4] SCORU/Node: don't start injector in observer mode --- src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml | 1 + src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml | 1 + src/proto_alpha/lib_sc_rollup_node/daemon.ml | 1 + 3 files changed, 3 insertions(+) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml index 25ad3512d606..d16e6a2a0166 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/daemon.ml @@ -539,6 +539,7 @@ module Make (PVM : Pvm.S) = struct let* () = Components.Commitment.Publisher.init node_ctxt in let* () = Components.Refutation_coordinator.init node_ctxt in let* () = + unless (signers = []) @@ fun () -> Injector.init node_ctxt.cctxt (Node_context.readonly node_ctxt) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml index 623525ef0450..f97b10536f80 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/daemon.ml @@ -533,6 +533,7 @@ module Make (PVM : Pvm.S) = struct let* () = Components.Commitment.Publisher.init node_ctxt in let* () = Components.Refutation_coordinator.init node_ctxt in let* () = + unless (signers = []) @@ fun () -> Injector.init node_ctxt.cctxt (Node_context.readonly node_ctxt) diff --git a/src/proto_alpha/lib_sc_rollup_node/daemon.ml b/src/proto_alpha/lib_sc_rollup_node/daemon.ml index a53ac6cb324c..5eb7c83900b8 100644 --- a/src/proto_alpha/lib_sc_rollup_node/daemon.ml +++ b/src/proto_alpha/lib_sc_rollup_node/daemon.ml @@ -533,6 +533,7 @@ module Make (PVM : Pvm.S) = struct let* () = Components.Commitment.Publisher.init node_ctxt in let* () = Components.Refutation_coordinator.init node_ctxt in let* () = + unless (signers = []) @@ fun () -> Injector.init node_ctxt.cctxt (Node_context.readonly node_ctxt) -- GitLab From b52a9999168dcdf5f0d0a58ef55c001e83d935aa Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Tue, 2 May 2023 11:05:06 +0200 Subject: [PATCH 2/4] SCORU/Node: faster computation of large reorganization Especially useful when starting, e.g., a rollup node which is very late. --- src/lib_crawler/layer_1.ml | 25 ++++++++++++++++--------- src/lib_crawler/layer_1.mli | 18 +++++++++++++----- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/lib_crawler/layer_1.ml b/src/lib_crawler/layer_1.ml index 2431fc7d5eb0..fd424a189c2d 100644 --- a/src/lib_crawler/layer_1.ml +++ b/src/lib_crawler/layer_1.ml @@ -184,13 +184,19 @@ let predecessors_of_blocks hashes = number of RPCs, this information is requested for a batch of hashes and cached locally. *) let get_predecessor = - let max_cached = 1023 and max_read = 8 in + let max_cached = 65536 in + let hard_max_read = max_cached in + (* 2MB *) let module HM = Aches.Vache.Map (Aches.Vache.FIFO_Precise) (Aches.Vache.Strong) (Block_hash) in let cache = HM.create max_cached in - fun cctxt (chain : Tezos_shell_services.Chain_services.chain) ancestor -> + fun ~max_read + cctxt + (chain : Tezos_shell_services.Chain_services.chain) + ancestor -> let open Lwt_result_syntax in + let max_read = min max_read hard_max_read in match HM.find_opt cache ancestor with | Some pred -> return_some pred | None -> ( @@ -214,17 +220,17 @@ let get_predecessor = | Some predecessor -> return_some predecessor) | _ -> return_none) -let get_predecessor_opt state (hash, level) = +let get_predecessor_opt ?(max_read = 8) state (hash, level) = let open Lwt_result_syntax in if level = 0l then return_none else let level = Int32.pred level in - let+ hash = get_predecessor state.cctxt state.cctxt#chain hash in + let+ hash = get_predecessor ~max_read state.cctxt state.cctxt#chain hash in Option.map (fun hash -> (hash, level)) hash -let get_predecessor state ((hash, _) as head) = +let get_predecessor ?max_read state ((hash, _) as head) = let open Lwt_result_syntax in - let* pred = get_predecessor_opt state head in + let* pred = get_predecessor_opt ?max_read state head in match pred with | None -> tzfail (Cannot_find_predecessor hash) | Some pred -> return pred @@ -271,7 +277,7 @@ let get_tezos_reorg_for_new_head l1_state else if old_head_level < new_head_level then let+ new_head, new_chain = nth_predecessor - ~get_predecessor:(get_predecessor l1_state) + ~get_predecessor:(get_predecessor ~max_read:distance l1_state) distance new_head in @@ -295,10 +301,11 @@ let get_tezos_reorg_for_new_head l1_state ?get_old_predecessor old_head new_head (* No known tezos head, we want all blocks from l. *) if new_head_level < l then return Reorg.no_reorg else + let distance = Int32.sub new_head_level l |> Int32.to_int in let* _block_at_l, new_chain = nth_predecessor - ~get_predecessor:(get_predecessor l1_state) - (Int32.sub new_head_level l |> Int32.to_int) + ~get_predecessor:(get_predecessor ~max_read:distance l1_state) + distance new_head in return Reorg.{old_chain = []; new_chain} diff --git a/src/lib_crawler/layer_1.mli b/src/lib_crawler/layer_1.mli index 847767538340..bb50c95d567c 100644 --- a/src/lib_crawler/layer_1.mli +++ b/src/lib_crawler/layer_1.mli @@ -59,14 +59,22 @@ val iter_heads : (** {2 Helper functions for the Layer 1 chain} *) -(** [get_predecessor_opt state head] returns the predecessor of block [head], - when [head] is not the genesis block. *) +(** [get_predecessor_opt ?max_read state head] returns the predecessor of block + [head], when [head] is not the genesis block. [max_read] (by default [8]) is + used to cache a number of predecessors to avoid some RPC calls when one need + to access multiple predecessors. *) val get_predecessor_opt : - t -> Block_hash.t * int32 -> (Block_hash.t * int32) option tzresult Lwt.t + ?max_read:int -> + t -> + Block_hash.t * int32 -> + (Block_hash.t * int32) option tzresult Lwt.t -(** [get_predecessor state head] returns the predecessor block of [head]. *) +(** [get_predecessor ?max_read state head] returns the predecessor block of [head]. *) val get_predecessor : - t -> Block_hash.t * int32 -> (Block_hash.t * int32) tzresult Lwt.t + ?max_read:int -> + t -> + Block_hash.t * int32 -> + (Block_hash.t * int32) tzresult Lwt.t (** [nth_predecessor ~get_predecessor n head] returns [block, history] where [block] is the nth predecessor of [head] and [history] is the list of blocks -- GitLab From d4bb65217dbcc121a4750166d62218498f915176 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Mon, 15 May 2023 13:55:13 +0200 Subject: [PATCH 3/4] SCORU/Node: tail-recursive map operation on reorganizations --- src/lib_crawler/reorg.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib_crawler/reorg.ml b/src/lib_crawler/reorg.ml index 99ff139e2a00..93910f126c5f 100644 --- a/src/lib_crawler/reorg.ml +++ b/src/lib_crawler/reorg.ml @@ -38,7 +38,10 @@ let encoding block_encoding = (req "new_chain" (list block_encoding)) let map f {old_chain; new_chain} = - {old_chain = List.map f old_chain; new_chain = List.map f new_chain} + { + old_chain = List.rev_map f old_chain |> List.rev; + new_chain = List.rev_map f new_chain |> List.rev; + } let map_es f {old_chain; new_chain} = let open Lwt_result_syntax in -- GitLab From c76d26fb1d7f9f4b0b08186cf6f04668a85251c2 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Mon, 15 May 2023 13:58:49 +0200 Subject: [PATCH 4/4] Doc: changelog --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index e80f6fa24ac2..0264192f317d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -101,6 +101,8 @@ Docker Images Smart Rollup node ----------------- +- Faster bootstrapping process. (MR :gl:`!8618`) + Smart Rollup client ------------------- -- GitLab