From 09f5ab867f76ebe39d51f8f9d74ae0654353a7c9 Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Tue, 17 May 2022 16:55:02 +0200 Subject: [PATCH 1/7] Scoru/Node: add lib_injector dependency --- .gitlab/ci/opam-ci.yml | 8 ++++---- manifest/main.ml | 1 + opam/tezos-sc-rollup-node-013-PtJakart.opam | 1 + opam/tezos-sc-rollup-node-alpha.opam | 1 + src/proto_013_PtJakart/bin_sc_rollup_node/dune | 6 ++++-- src/proto_alpha/bin_sc_rollup_node/dune | 6 ++++-- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.gitlab/ci/opam-ci.yml b/.gitlab/ci/opam-ci.yml index c29c02943e57..0ac354757d9a 100644 --- a/.gitlab/ci/opam-ci.yml +++ b/.gitlab/ci/opam-ci.yml @@ -217,7 +217,7 @@ opam:tezos-012-Psithaca-test-helpers: opam:tezos-013-PtJakart-test-helpers: extends: - .opam_template - - .rules_template__trigger_opam_batch_1 + - .rules_template__trigger_opam_batch_2 variables: package: tezos-013-PtJakart-test-helpers @@ -245,7 +245,7 @@ opam:tezos-accuser-alpha: opam:tezos-alpha-test-helpers: extends: - .opam_template - - .rules_template__trigger_opam_batch_1 + - .rules_template__trigger_opam_batch_2 variables: package: tezos-alpha-test-helpers @@ -1232,14 +1232,14 @@ opam:tezos-sc-rollup-client-alpha: opam:tezos-sc-rollup-node-013-PtJakart: extends: - .opam_template - - .rules_template__trigger_opam_batch_2 + - .rules_template__trigger_opam_batch_1 variables: package: tezos-sc-rollup-node-013-PtJakart opam:tezos-sc-rollup-node-alpha: extends: - .opam_template - - .rules_template__trigger_opam_batch_2 + - .rules_template__trigger_opam_batch_1 variables: package: tezos-sc-rollup-node-alpha diff --git a/manifest/main.ml b/manifest/main.ml index f6c7b50f12df..884e6b3cce0a 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -4220,6 +4220,7 @@ module Protocol = Protocol irmin; ringo; ringo_lwt; + injector |> if_some |> open_; ] in let tx_rollup = diff --git a/opam/tezos-sc-rollup-node-013-PtJakart.opam b/opam/tezos-sc-rollup-node-013-PtJakart.opam index c42e1494b462..94a02df3d8c2 100644 --- a/opam/tezos-sc-rollup-node-013-PtJakart.opam +++ b/opam/tezos-sc-rollup-node-013-PtJakart.opam @@ -28,6 +28,7 @@ depends: [ "irmin" { >= "3.2.2" & < "3.3.0" } "ringo" { >= "0.9" } "ringo-lwt" { >= "0.9" } + "tezos-injector-013-PtJakart" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-sc-rollup-node-alpha.opam b/opam/tezos-sc-rollup-node-alpha.opam index 3334adcfde1a..c180872d39b8 100644 --- a/opam/tezos-sc-rollup-node-alpha.opam +++ b/opam/tezos-sc-rollup-node-alpha.opam @@ -28,6 +28,7 @@ depends: [ "irmin" { >= "3.2.2" & < "3.3.0" } "ringo" { >= "0.9" } "ringo-lwt" { >= "0.9" } + "tezos-injector-alpha" ] build: [ ["rm" "-r" "vendors"] diff --git a/src/proto_013_PtJakart/bin_sc_rollup_node/dune b/src/proto_013_PtJakart/bin_sc_rollup_node/dune index a1db0066b916..5604e9d4a02c 100644 --- a/src/proto_013_PtJakart/bin_sc_rollup_node/dune +++ b/src/proto_013_PtJakart/bin_sc_rollup_node/dune @@ -28,7 +28,8 @@ irmin-pack.unix irmin ringo - ringo-lwt) + ringo-lwt + tezos-injector-013-PtJakart) (link_flags (:standard) (:include %{workspace_root}/static-link-flags.sexp)) @@ -46,4 +47,5 @@ -open Tezos_protocol_013_PtJakart_parameters -open Tezos_rpc -open Tezos_shell_services - -open Tezos_sc_rollup_013_PtJakart)) + -open Tezos_sc_rollup_013_PtJakart + -open Tezos_injector_013_PtJakart)) diff --git a/src/proto_alpha/bin_sc_rollup_node/dune b/src/proto_alpha/bin_sc_rollup_node/dune index f16b4510fd82..f0d7fbdc4f4b 100644 --- a/src/proto_alpha/bin_sc_rollup_node/dune +++ b/src/proto_alpha/bin_sc_rollup_node/dune @@ -28,7 +28,8 @@ irmin-pack.unix irmin ringo - ringo-lwt) + ringo-lwt + tezos-injector-alpha) (link_flags (:standard) (:include %{workspace_root}/static-link-flags.sexp)) @@ -46,4 +47,5 @@ -open Tezos_protocol_alpha_parameters -open Tezos_rpc -open Tezos_shell_services - -open Tezos_sc_rollup_alpha)) + -open Tezos_sc_rollup_alpha + -open Tezos_injector_alpha)) -- GitLab From 9a5d59eda18fb0109755f6ace0254e8e2cba2a75 Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Tue, 3 May 2022 13:13:41 +0200 Subject: [PATCH 2/7] SCORU/Node: add cache for recent blocks to compute reorgs --- src/proto_alpha/bin_sc_rollup_node/daemon.ml | 19 ++--- src/proto_alpha/bin_sc_rollup_node/layer1.ml | 75 ++++++++++++++++++- src/proto_alpha/bin_sc_rollup_node/layer1.mli | 45 +++++++++-- 3 files changed, 118 insertions(+), 21 deletions(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/daemon.ml b/src/proto_alpha/bin_sc_rollup_node/daemon.ml index 48bfee07de34..2ad277d0bc6f 100644 --- a/src/proto_alpha/bin_sc_rollup_node/daemon.ml +++ b/src/proto_alpha/bin_sc_rollup_node/daemon.ml @@ -193,16 +193,15 @@ module Make (PVM : Pvm.S) = struct in go [] - let daemonize node_ctxt store layer_1_chain_events = - Lwt.no_cancel - @@ iter_stream layer_1_chain_events + let daemonize node_ctxt store (l1_ctxt : Layer1.t) = + Lwt.no_cancel @@ iter_stream l1_ctxt.events @@ on_layer_1_chain_event node_ctxt store - let install_finalizer store rpc_server heads stopper = + let install_finalizer store rpc_server (l1_ctxt : Layer1.t) = let open Lwt_syntax in Lwt_exit.register_clean_up_callback ~loc:__LOC__ @@ fun exit_status -> - stopper () ; - let* () = Lwt_stream.closed heads in + l1_ctxt.stopper () ; + let* () = Lwt_stream.closed l1_ctxt.events in let* () = Layer1.shutdown store in let* () = Components.RPC_server.shutdown rpc_server in let* () = Store.close store in @@ -215,19 +214,17 @@ module Make (PVM : Pvm.S) = struct let* rpc_server = Components.RPC_server.start node_ctxt store configuration in - let* tezos_heads, stopper = - Layer1.start configuration node_ctxt.Node_context.cctxt store - in + let* l1_ctxt = Layer1.start configuration node_ctxt.cctxt store in let*! () = Inbox.start () in let*! () = Components.Commitment.start () in - let _ = install_finalizer store rpc_server tezos_heads stopper in + let _ = install_finalizer store rpc_server l1_ctxt in let*! () = Event.node_is_ready ~rpc_addr:configuration.rpc_addr ~rpc_port:configuration.rpc_port in - daemonize node_ctxt store tezos_heads + daemonize node_ctxt store l1_ctxt in start () end diff --git a/src/proto_alpha/bin_sc_rollup_node/layer1.ml b/src/proto_alpha/bin_sc_rollup_node/layer1.ml index ee02f32af289..e3f21daab666 100644 --- a/src/proto_alpha/bin_sc_rollup_node/layer1.ml +++ b/src/proto_alpha/bin_sc_rollup_node/layer1.ml @@ -26,6 +26,7 @@ open Configuration open Protocol.Alpha_context open Plugin +open Tezos_injector_alpha.Common (** @@ -40,6 +41,24 @@ let synchronization_failure e = e ; Lwt_exit.exit_and_raise 1 +type error += Cannot_find_block of Block_hash.t + +let () = + register_error_kind + ~id:"sc_rollup.node.cannot_find_block" + ~title:"Cannot find block from L1" + ~description:"A block couldn't be found from the L1 node" + ~pp:(fun ppf hash -> + Format.fprintf + ppf + "Block with hash %a was not found on the L1 node." + Block_hash.pp + hash) + `Temporary + Data_encoding.(obj1 (req "hash" Block_hash.encoding)) + (function Cannot_find_block hash -> Some hash | _ -> None) + (fun hash -> Cannot_find_block hash) + (** State @@ -126,6 +145,12 @@ module State = struct let block_of_hash = Store.Blocks.get + module Blocks_cache = + Ringo_lwt.Functors.Make_opt + ((val Ringo.( + map_maker ~replacement:LRU ~overflow:Strong ~accounting:Precise)) + (Block_hash)) + let mark_processed_head store (Head {hash; _} as head) = let open Lwt_syntax in let* () = Store.ProcessedHashes.add store hash () in @@ -136,6 +161,9 @@ module State = struct let last_processed_head = Store.LastProcessedHead.find end +type blocks_cache = + Protocol_client_context.Alpha_block_services.block_info State.Blocks_cache.t + (** Chain events @@ -152,6 +180,13 @@ let same_branch new_head intermediate_heads = let rollback new_head = Rollback {new_head} +type t = { + blocks_cache : blocks_cache; + events : chain_event Lwt_stream.t; + cctxt : Protocol_client_context.full; + stopper : RPC_context.stopper; +} + (** Helpers @@ -163,6 +198,11 @@ let genesis_hash = Block_hash.of_b58check_exn "BLockGenesisGenesisGenesisGenesisGenesisf79b5d1CoW2" +let chain_event_head_hash = function + | SameBranch {new_head = Head {hash; _}; _} + | Rollback {new_head = Head {hash; _}} -> + hash + (** [blocks_of_heads base heads] given a list of successive heads connected to [base], returns an associative list mapping block hash to block. This list is only used for traversal, not lookup. The @@ -356,8 +396,9 @@ let start configuration (cctxt : Protocol_client_context.full) store = check_sc_rollup_address_exists configuration.sc_rollup_address cctxt in let* event_stream, stopper = chain_events cctxt store `Main in - let* info = gather_info cctxt configuration.sc_rollup_address in - return (discard_pre_origination_blocks info event_stream, stopper) + let+ info = gather_info cctxt configuration.sc_rollup_address in + let events = discard_pre_origination_blocks info event_stream in + {cctxt; events; blocks_cache = State.Blocks_cache.create 32; stopper} let current_head_hash store = let open Lwt_syntax in @@ -401,3 +442,33 @@ let shutdown store = match last_processed_head with | None -> return_unit | Some head -> State.set_new_head store head + +(** [fetch_tezos_block l1_ctxt 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. *) +let fetch_tezos_block l1_ctxt hash = + let open Lwt_result_syntax in + let find_in_cache hash fetch = + let fetch hash = + let*! block = fetch hash in + Lwt.return @@ Result.to_option block + in + let*! block = + State.Blocks_cache.find_or_replace l1_ctxt.blocks_cache hash fetch + in + match block with Some b -> return b | _ -> tzfail (Cannot_find_block hash) + in + fetch_tezos_block ~find_in_cache l1_ctxt.cctxt hash + +(** Returns the reorganization of L1 blocks (if any) for [new_head]. *) +let get_tezos_reorg_for_new_head l1_state store new_head_hash = + let open Lwt_result_syntax in + let*! old_head_hash = current_head_hash store in + match old_head_hash with + | None -> + (* No known tezos head, consider the new head as being on top of a previous + tezos block. *) + let+ new_head = fetch_tezos_block l1_state new_head_hash in + {old_chain = []; new_chain = [new_head]} + | Some old_head_hash -> + tezos_reorg (fetch_tezos_block l1_state) ~old_head_hash ~new_head_hash diff --git a/src/proto_alpha/bin_sc_rollup_node/layer1.mli b/src/proto_alpha/bin_sc_rollup_node/layer1.mli index 8ea49d73bcde..f12f6a0a8a4b 100644 --- a/src/proto_alpha/bin_sc_rollup_node/layer1.mli +++ b/src/proto_alpha/bin_sc_rollup_node/layer1.mli @@ -46,15 +46,27 @@ type chain_event = (** A chain reorganization occurred since the previous synchronization. The rollback set [new_head] to an old block. *) -(** [start configuration cctxt store] returns a stream of [chain_event] - obtained from the monitoring of the Tezos node set up by the client - [cctxt]. The layer 1 state is stored in the data directory declared - in [configuration]. *) +(** Type of cache holding the last 32 blocks, with their operations. *) +type blocks_cache + +type t = private { + blocks_cache : blocks_cache; + events : chain_event Lwt_stream.t; + cctxt : Protocol_client_context.full; + stopper : RPC_context.stopper; +} + +val chain_event_head_hash : chain_event -> Block_hash.t + +(* TODO: https://gitlab.com/tezos/tezos/-/issues/3311 + Allow to retrieve L1 blocks through Tezos node storage locally. *) + +(** [start configuration cctxt store] returns a stream of [chain_event] obtained + from the monitoring of the Tezos node set up by the client [cctxt]. The + layer 1 state is stored in the data directory declared in + [configuration]. *) val start : - Configuration.t -> - Protocol_client_context.full -> - Store.t -> - (chain_event Lwt_stream.t * RPC_context.stopper) tzresult Lwt.t + Configuration.t -> Protocol_client_context.full -> Store.t -> t tzresult Lwt.t (** [current_head_hash store] is the current hash of the head of the Tezos chain as far as the smart-contract rollup node knows from the @@ -85,3 +97,20 @@ val mark_processed_head : Store.t -> head -> unit Lwt.t (** [shutdown store] properly shut the layer 1 down. *) val shutdown : Store.t -> unit Lwt.t + +(** [fetch_tezos_block l1_ctxt 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 fetch_tezos_block : + t -> + Block_hash.t -> + Protocol_client_context.Alpha_block_services.block_info tzresult Lwt.t + +(** [get_tezos_reorg_for_new_head l1_ctxt store hash] returns the reorganization + of L1 blocks (if any) for [new_head]. *) +val get_tezos_reorg_for_new_head : + t -> + Store.t -> + Block_hash.t -> + Protocol_client_context.Alpha_block_services.block_info Common.reorg tzresult + Lwt.t -- GitLab From 94889ef8bd41e41b4e9f0b22c22f36a6be74a371 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Wed, 22 Jun 2022 17:20:38 +0200 Subject: [PATCH 3/7] ORU/Injector: propagate errors of block fetching through cache --- src/proto_alpha/bin_sc_rollup_node/layer1.ml | 17 +++------- src/proto_alpha/lib_injector/common.ml | 33 +++++++++++++++----- src/proto_alpha/lib_injector/common.mli | 12 ++++--- src/proto_alpha/lib_tx_rollup/state.ml | 25 ++++----------- 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/layer1.ml b/src/proto_alpha/bin_sc_rollup_node/layer1.ml index e3f21daab666..08f77748a409 100644 --- a/src/proto_alpha/bin_sc_rollup_node/layer1.ml +++ b/src/proto_alpha/bin_sc_rollup_node/layer1.ml @@ -447,18 +447,11 @@ let shutdown store = hash. Looks for the block in the blocks cache first, and fetches it from the L1 node otherwise. *) let fetch_tezos_block l1_ctxt hash = - let open Lwt_result_syntax in - let find_in_cache hash fetch = - let fetch hash = - let*! block = fetch hash in - Lwt.return @@ Result.to_option block - in - let*! block = - State.Blocks_cache.find_or_replace l1_ctxt.blocks_cache hash fetch - in - match block with Some b -> return b | _ -> tzfail (Cannot_find_block hash) - in - fetch_tezos_block ~find_in_cache l1_ctxt.cctxt hash + trace (Cannot_find_block hash) + @@ fetch_tezos_block + l1_ctxt.cctxt + hash + ~find_in_cache:(State.Blocks_cache.find_or_replace l1_ctxt.blocks_cache) (** Returns the reorganization of L1 blocks (if any) for [new_head]. *) let get_tezos_reorg_for_new_head l1_state store new_head_hash = diff --git a/src/proto_alpha/lib_injector/common.ml b/src/proto_alpha/lib_injector/common.ml index 1fd54ccb49e3..924c679032c9 100644 --- a/src/proto_alpha/lib_injector/common.ml +++ b/src/proto_alpha/lib_injector/common.ml @@ -52,15 +52,34 @@ let reorg_encoding block_encoding = let fetch_tezos_block ~find_in_cache (cctxt : #full) hash : (Alpha_block_services.block_info, error trace) result Lwt.t = + let open Lwt_syntax in + let errors = ref None in let fetch hash = - Alpha_block_services.info - cctxt - ~chain:cctxt#chain - ~block:(`Hash (hash, 0)) - ~metadata:`Always - () + let* block = + Alpha_block_services.info + cctxt + ~chain:cctxt#chain + ~block:(`Hash (hash, 0)) + ~metadata:`Always + () + in + match block with + | Error errs -> + errors := Some errs ; + return_none + | Ok block -> return_some block in - find_in_cache hash fetch + let+ block = find_in_cache hash fetch in + match (block, !errors) with + | None, None -> + (* This should not happen if {!find_in_cache} behaves correctly, + i.e. calls {!fetch} for cache misses. *) + error_with + "Fetching Tezos block %a failed unexpectedly" + Block_hash.pp + hash + | None, Some errs -> Error errs + | Some block, _ -> Ok block (* Compute the reorganization of L1 blocks from the chain whose head is [old_head_hash] and the chain whose head [new_head_hash]. *) diff --git a/src/proto_alpha/lib_injector/common.mli b/src/proto_alpha/lib_injector/common.mli index a1f4a55e2c7d..4a1651ede2f7 100644 --- a/src/proto_alpha/lib_injector/common.mli +++ b/src/proto_alpha/lib_injector/common.mli @@ -52,14 +52,16 @@ val reorg_encoding : 'a Data_encoding.t -> 'a reorg Data_encoding.t type block_info := Alpha_block_services.block_info -(** [fetch_tezos_block ~find_in_cache cctxt hash] returns a block info given a - block hash. Looks for the block using [find_in_cache] first, and fetches - it from the L1 node otherwise. *) +(** [fetch_tezos_block ~find_in_cache cctxt hash] returns [Some block_info] + given a block hash. Looks for the block using [find_in_cache] first, and + fetches it from the L1 node otherwise. Returns [None] if no such block hash + exists. [find_in_cache] should be from an instance of + {!Ringo_lwt.Sigs.CACHE_MAP_RESULT}. *) val fetch_tezos_block : find_in_cache: (Block_hash.t -> - (Block_hash.t -> block_info tzresult Lwt.t) -> - block_info tzresult Lwt.t) -> + (Block_hash.t -> block_info option Lwt.t) -> + block_info option Lwt.t) -> #full -> Block_hash.t -> block_info tzresult Lwt.t diff --git a/src/proto_alpha/lib_tx_rollup/state.ml b/src/proto_alpha/lib_tx_rollup/state.ml index 9ac2681899e9..c68bb8058bb2 100644 --- a/src/proto_alpha/lib_tx_rollup/state.ml +++ b/src/proto_alpha/lib_tx_rollup/state.ml @@ -69,25 +69,12 @@ let rollup_operation_index = 3 let get_head state = state.head let fetch_tezos_block state hash = - let open Lwt_syntax in - let errors = ref [] in - let find_in_cache hash fetch = - let fetch hash = - let* block = fetch hash in - match block with - | Error errs -> - errors := errs ; - return_none - | Ok block -> return_some block - in - let+ block = - Tezos_blocks_cache.find_or_replace state.tezos_blocks_cache hash fetch - in - Result.of_option ~error:!errors block - |> record_trace (Error.Tx_rollup_cannot_fetch_tezos_block hash) - in - - fetch_tezos_block ~find_in_cache state.cctxt hash + trace (Error.Tx_rollup_cannot_fetch_tezos_block hash) + @@ fetch_tezos_block + state.cctxt + hash + ~find_in_cache: + (Tezos_blocks_cache.find_or_replace state.tezos_blocks_cache) let set_tezos_head state new_head_hash = let open Lwt_result_syntax in -- GitLab From 0966c416725f6d9bb77a61b59f31a14217279b9a Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Thu, 23 Jun 2022 14:56:36 +0200 Subject: [PATCH 4/7] SCORU/Node: get operation by block hash instead of level --- src/proto_alpha/bin_sc_rollup_node/inbox.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/inbox.ml b/src/proto_alpha/bin_sc_rollup_node/inbox.ml index 970fdc1ffe59..97d9d185a69f 100644 --- a/src/proto_alpha/bin_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/bin_sc_rollup_node/inbox.ml @@ -75,7 +75,7 @@ let get_messages cctxt head rollup = let open Lwt_result_syntax in let open Block_services in let+ operations = - Operations.operations cctxt ~chain:`Main ~block:(`Level (snd head)) () + Operations.operations cctxt ~chain:`Main ~block:(`Hash (fst head, 0)) () in let is_add_message = function | Contents -- GitLab From 3fad86e1b99518a11731e74b49c9530e3abe9891 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Thu, 23 Jun 2022 15:11:12 +0200 Subject: [PATCH 5/7] SCORU/Node: L1 context inside node context --- src/proto_alpha/bin_sc_rollup_node/daemon.ml | 7 ++++--- src/proto_alpha/bin_sc_rollup_node/inbox.ml | 4 ++-- src/proto_alpha/bin_sc_rollup_node/node_context.ml | 4 +++- src/proto_alpha/bin_sc_rollup_node/node_context.mli | 9 ++++++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/daemon.ml b/src/proto_alpha/bin_sc_rollup_node/daemon.ml index 2ad277d0bc6f..a6ce1d8d4388 100644 --- a/src/proto_alpha/bin_sc_rollup_node/daemon.ml +++ b/src/proto_alpha/bin_sc_rollup_node/daemon.ml @@ -214,17 +214,16 @@ module Make (PVM : Pvm.S) = struct let* rpc_server = Components.RPC_server.start node_ctxt store configuration in - let* l1_ctxt = Layer1.start configuration node_ctxt.cctxt store in let*! () = Inbox.start () in let*! () = Components.Commitment.start () in - let _ = install_finalizer store rpc_server l1_ctxt in + let _ = install_finalizer store rpc_server node_ctxt.l1_ctxt in let*! () = Event.node_is_ready ~rpc_addr:configuration.rpc_addr ~rpc_port:configuration.rpc_port in - daemonize node_ctxt store l1_ctxt + daemonize node_ctxt store node_ctxt.l1_ctxt in start () end @@ -238,9 +237,11 @@ let run ~data_dir (cctxt : Protocol_client_context.full) = configuration in let*! store = Store.load configuration in + let* l1_ctxt = Layer1.start configuration cctxt store in let* node_ctxt = Node_context.init cctxt + l1_ctxt sc_rollup_address sc_rollup_node_operator fee_parameter diff --git a/src/proto_alpha/bin_sc_rollup_node/inbox.ml b/src/proto_alpha/bin_sc_rollup_node/inbox.ml index 97d9d185a69f..15e44d694672 100644 --- a/src/proto_alpha/bin_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/bin_sc_rollup_node/inbox.ml @@ -75,7 +75,7 @@ let get_messages cctxt head rollup = let open Lwt_result_syntax in let open Block_services in let+ operations = - Operations.operations cctxt ~chain:`Main ~block:(`Hash (fst head, 0)) () + Operations.operations cctxt ~chain:`Main ~block:(`Hash (head, 0)) () in let is_add_message = function | Contents @@ -97,7 +97,7 @@ let get_messages cctxt head rollup = let process_head Node_context.({cctxt; rollup_address; _} as node_ctxt) store Layer1.(Head {level; hash = head_hash} as head) = let open Lwt_result_syntax in - let*! res = get_messages cctxt (head_hash, level) rollup_address in + let*! res = get_messages cctxt head_hash rollup_address in match res with | Error e -> head_processing_failure e | Ok messages -> diff --git a/src/proto_alpha/bin_sc_rollup_node/node_context.ml b/src/proto_alpha/bin_sc_rollup_node/node_context.ml index d769f4f3082c..9653ed574a73 100644 --- a/src/proto_alpha/bin_sc_rollup_node/node_context.ml +++ b/src/proto_alpha/bin_sc_rollup_node/node_context.ml @@ -28,6 +28,7 @@ open Alpha_context type t = { cctxt : Protocol_client_context.full; + l1_ctxt : Layer1.t; rollup_address : Sc_rollup.t; operator : Signature.Public_key_hash.t; initial_level : Raw_level.t; @@ -41,7 +42,7 @@ let get_operator_keys node_ctxt = let+ _, pk, sk = Client_keys.get_key node_ctxt.cctxt node_ctxt.operator in (node_ctxt.operator, pk, sk) -let init (cctxt : Protocol_client_context.full) rollup_address operator +let init (cctxt : Protocol_client_context.full) l1_ctxt rollup_address operator fee_parameter = let open Lwt_result_syntax in let* initial_level = @@ -55,6 +56,7 @@ let init (cctxt : Protocol_client_context.full) rollup_address operator in { cctxt; + l1_ctxt; rollup_address; operator; initial_level; diff --git a/src/proto_alpha/bin_sc_rollup_node/node_context.mli b/src/proto_alpha/bin_sc_rollup_node/node_context.mli index e51c11150b6c..17a1975ad66b 100644 --- a/src/proto_alpha/bin_sc_rollup_node/node_context.mli +++ b/src/proto_alpha/bin_sc_rollup_node/node_context.mli @@ -31,6 +31,8 @@ open Alpha_context type t = { cctxt : Protocol_client_context.full; (** Client context used by the rollup node. *) + l1_ctxt : Layer1.t; + (** Layer 1 context to fetch blocks and monitor heads, etc.*) rollup_address : Sc_rollup.t; (** Smart contract rollup tracked by the rollup node. *) operator : Signature.Public_key_hash.t; @@ -53,12 +55,13 @@ val get_operator_keys : tzresult Lwt.t -(** [init cctxt sc_rollup operator_pkh] initialises the rollup representation. - The rollup origination level and kind are fetched via an RPC call to the - layer1 node that [cctxt] uses for RPC requests. +(** [init cctxt l1_ctxt sc_rollup operator_pkh] initialises the rollup + representation. The rollup origination level and kind are fetched via an + RPC call to the layer1 node that [cctxt] uses for RPC requests. *) val init : Protocol_client_context.full -> + Layer1.t -> Sc_rollup.t -> Signature.Public_key_hash.t -> Injection.fee_parameter -> -- GitLab From 0cb3ca3b4b4ae229f56be89a053b2d4b803d2dc5 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Thu, 23 Jun 2022 15:14:13 +0200 Subject: [PATCH 6/7] SCORU/Node: use L1 block cache to retrieve inbox --- src/proto_alpha/bin_sc_rollup_node/inbox.ml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/inbox.ml b/src/proto_alpha/bin_sc_rollup_node/inbox.ml index 15e44d694672..41502115bdb5 100644 --- a/src/proto_alpha/bin_sc_rollup_node/inbox.ml +++ b/src/proto_alpha/bin_sc_rollup_node/inbox.ml @@ -28,7 +28,6 @@ *) open Protocol open Alpha_context -module Block_services = Block_services.Make (Protocol) (Protocol) let lift = Lwt.map Environment.wrap_tzresult @@ -71,12 +70,9 @@ end (* FIXME: https://gitlab.com/tezos/tezos/-/issues/3199 For the moment, the rollup node ignores L1 to L2 messages. *) -let get_messages cctxt head rollup = +let get_messages l1_ctxt head rollup = let open Lwt_result_syntax in - let open Block_services in - let+ operations = - Operations.operations cctxt ~chain:`Main ~block:(`Hash (head, 0)) () - in + let+ block = Layer1.fetch_tezos_block l1_ctxt head in let is_add_message = function | Contents (Manager_operation @@ -85,19 +81,21 @@ let get_messages cctxt head rollup = messages | _ -> [] in - let process_contents {protocol_data = Operation_data {contents; _}; _} = + let process_contents + Protocol_client_context.Alpha_block_services. + {protocol_data = Operation_data {contents; _}; _} = let operations = Operation.to_list (Contents_list contents) in List.concat_map is_add_message operations in let process_operations operations = List.concat_map process_contents operations in - List.concat_map process_operations operations + List.concat_map process_operations block.operations -let process_head Node_context.({cctxt; rollup_address; _} as node_ctxt) store +let process_head Node_context.({l1_ctxt; rollup_address; _} as node_ctxt) store Layer1.(Head {level; hash = head_hash} as head) = let open Lwt_result_syntax in - let*! res = get_messages cctxt head_hash rollup_address in + let*! res = get_messages l1_ctxt head_hash rollup_address in match res with | Error e -> head_processing_failure e | Ok messages -> -- GitLab From 4fd2768222e65ce9f2906ea963e393c1b3e31c08 Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Tue, 28 Jun 2022 10:21:09 +0200 Subject: [PATCH 7/7] Injector: Rename Common module to Injector_common --- src/proto_alpha/bin_sc_rollup_node/layer1.ml | 2 +- src/proto_alpha/bin_sc_rollup_node/layer1.mli | 3 ++- .../lib_injector/{common.ml => injector_common.ml} | 0 .../lib_injector/{common.mli => injector_common.mli} | 0 src/proto_alpha/lib_injector/injector_functor.ml | 2 +- src/proto_alpha/lib_injector/injector_sigs.ml | 3 ++- src/proto_alpha/lib_injector/injector_worker_types.ml | 2 +- src/proto_alpha/lib_injector/injector_worker_types.mli | 2 +- src/proto_alpha/lib_tx_rollup/daemon.ml | 4 ++-- src/proto_alpha/lib_tx_rollup/state.ml | 2 +- src/proto_alpha/lib_tx_rollup/state.mli | 2 +- 11 files changed, 12 insertions(+), 10 deletions(-) rename src/proto_alpha/lib_injector/{common.ml => injector_common.ml} (100%) rename src/proto_alpha/lib_injector/{common.mli => injector_common.mli} (100%) diff --git a/src/proto_alpha/bin_sc_rollup_node/layer1.ml b/src/proto_alpha/bin_sc_rollup_node/layer1.ml index 08f77748a409..8faeaaed8e77 100644 --- a/src/proto_alpha/bin_sc_rollup_node/layer1.ml +++ b/src/proto_alpha/bin_sc_rollup_node/layer1.ml @@ -26,7 +26,7 @@ open Configuration open Protocol.Alpha_context open Plugin -open Tezos_injector_alpha.Common +open Injector_common (** diff --git a/src/proto_alpha/bin_sc_rollup_node/layer1.mli b/src/proto_alpha/bin_sc_rollup_node/layer1.mli index f12f6a0a8a4b..bca23c318292 100644 --- a/src/proto_alpha/bin_sc_rollup_node/layer1.mli +++ b/src/proto_alpha/bin_sc_rollup_node/layer1.mli @@ -112,5 +112,6 @@ val get_tezos_reorg_for_new_head : t -> Store.t -> Block_hash.t -> - Protocol_client_context.Alpha_block_services.block_info Common.reorg tzresult + Protocol_client_context.Alpha_block_services.block_info Injector_common.reorg + tzresult Lwt.t diff --git a/src/proto_alpha/lib_injector/common.ml b/src/proto_alpha/lib_injector/injector_common.ml similarity index 100% rename from src/proto_alpha/lib_injector/common.ml rename to src/proto_alpha/lib_injector/injector_common.ml diff --git a/src/proto_alpha/lib_injector/common.mli b/src/proto_alpha/lib_injector/injector_common.mli similarity index 100% rename from src/proto_alpha/lib_injector/common.mli rename to src/proto_alpha/lib_injector/injector_common.mli diff --git a/src/proto_alpha/lib_injector/injector_functor.ml b/src/proto_alpha/lib_injector/injector_functor.ml index 3e844aa3e73d..bcdd2b2b5523 100644 --- a/src/proto_alpha/lib_injector/injector_functor.ml +++ b/src/proto_alpha/lib_injector/injector_functor.ml @@ -26,7 +26,7 @@ open Protocol_client_context open Protocol open Alpha_context -open Common +open Injector_common open Injector_worker_types open Injector_sigs open Injector_errors diff --git a/src/proto_alpha/lib_injector/injector_sigs.ml b/src/proto_alpha/lib_injector/injector_sigs.ml index 1bee0bd72170..60763ecea85d 100644 --- a/src/proto_alpha/lib_injector/injector_sigs.ml +++ b/src/proto_alpha/lib_injector/injector_sigs.ml @@ -133,7 +133,8 @@ module type S = sig considered as {e confirmed}, it disappears from the injector. *) val new_tezos_head : Protocol_client_context.Alpha_block_services.block_info -> - Protocol_client_context.Alpha_block_services.block_info Common.reorg -> + Protocol_client_context.Alpha_block_services.block_info + Injector_common.reorg -> unit Lwt.t (** Trigger an injection of the pending operations for all workers. If [tags] diff --git a/src/proto_alpha/lib_injector/injector_worker_types.ml b/src/proto_alpha/lib_injector/injector_worker_types.ml index 563a74756dee..e084db461a15 100644 --- a/src/proto_alpha/lib_injector/injector_worker_types.ml +++ b/src/proto_alpha/lib_injector/injector_worker_types.ml @@ -26,7 +26,7 @@ open Protocol_client_context open Protocol open Alpha_context -open Common +open Injector_common module Request = struct type ('a, 'b) t = diff --git a/src/proto_alpha/lib_injector/injector_worker_types.mli b/src/proto_alpha/lib_injector/injector_worker_types.mli index 48600ef46e13..2ed157ad8e6e 100644 --- a/src/proto_alpha/lib_injector/injector_worker_types.mli +++ b/src/proto_alpha/lib_injector/injector_worker_types.mli @@ -26,7 +26,7 @@ open Protocol_client_context open Protocol open Alpha_context -open Common +open Injector_common module Request : sig type ('a, 'b) t = diff --git a/src/proto_alpha/lib_tx_rollup/daemon.ml b/src/proto_alpha/lib_tx_rollup/daemon.ml index c06ed081dc00..3d16b62244e1 100644 --- a/src/proto_alpha/lib_tx_rollup/daemon.ml +++ b/src/proto_alpha/lib_tx_rollup/daemon.ml @@ -770,13 +770,13 @@ let handle_l1_reorg state acc reorg = List.fold_left_es (handle_l1_block `Rollback state) acc - (List.rev reorg.Common.old_chain) + (List.rev reorg.Injector_common.old_chain) in let* acc = List.fold_left_es (handle_l1_block `Process state) acc - reorg.Common.new_chain + reorg.Injector_common.new_chain in return acc diff --git a/src/proto_alpha/lib_tx_rollup/state.ml b/src/proto_alpha/lib_tx_rollup/state.ml index c68bb8058bb2..5f4a314b8179 100644 --- a/src/proto_alpha/lib_tx_rollup/state.ml +++ b/src/proto_alpha/lib_tx_rollup/state.ml @@ -27,7 +27,7 @@ open Protocol.Alpha_context open Protocol_client_context -open Common +open Injector_common module Tezos_blocks_cache = Ringo_lwt.Functors.Make_opt diff --git a/src/proto_alpha/lib_tx_rollup/state.mli b/src/proto_alpha/lib_tx_rollup/state.mli index 165df959d42c..a5713398f081 100644 --- a/src/proto_alpha/lib_tx_rollup/state.mli +++ b/src/proto_alpha/lib_tx_rollup/state.mli @@ -26,7 +26,7 @@ (*****************************************************************************) open Protocol.Alpha_context open Protocol_client_context -open Common +open Injector_common (** The RPC server and the Daemon main loop are sharing a variable of the type stored in the Irmin store. The [State] module allows access to this stored -- GitLab