diff --git a/docs/odoc_protocols.patch b/docs/odoc_protocols.patch index 0eaa8c6aa1622c768853ce7154bc68a4e917e3c3..90c1bd01ce10cd3057968aa95dc7758357b3cc04 100644 --- a/docs/odoc_protocols.patch +++ b/docs/odoc_protocols.patch @@ -274,41 +274,6 @@ index 7e01854acc..caf342d8c6 100644 amount is zero. } {li [Zk_rollup.Errors.Invalid_deposit_amount] if the amount of the ticket -diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/context.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/context.mli -index 636bb700d1..1a54302fd8 100644 ---- a/src/proto_016_PtMumbai/lib_sc_rollup_node/context.mli -+++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/context.mli -@@ -29,10 +29,10 @@ open Store_sigs - index can be written or only read. *) - type 'a index constraint 'a = [< `Read | `Write > `Read] - --(** Read/write {!index}. *) -+(** Read/write {!type:index}. *) - type rw_index = [`Read | `Write] index - --(** Read only {!index}. *) -+(** Read only {!type:index}. *) - type ro_index = [`Read] index - - (** The type of trees stored in the context, i.e. the actual data. *) -@@ -48,7 +48,7 @@ type rw = [`Read | `Write] t - type ro = [`Read] t - - (** A context hash is the hash produced when the data of the context is -- committed to disk, i.e. the {!commit} hash. *) -+ committed to disk, i.e. the {!type:commit} hash. *) - type hash = Sc_rollup_context_hash.t - - (** The type of commits for the context. *) -@@ -156,7 +156,7 @@ module PVMState : sig - - (** [set context state] saves the PVM state [state] in the context and returns - the updated context. Note: [set] does not perform any write on disk, this -- information must be committed using {!commit}. *) -+ information must be committed using {!val:commit}. *) - val set : 'a t -> value -> 'a t Lwt.t - end - diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/dal_pages_request.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/dal_pages_request.mli index 2a9a69a71b..f7247a51e3 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/dal_pages_request.mli @@ -357,41 +322,6 @@ index ca8e5769b9..90a3c81f2f 100644 val set : 'a Context.t -> state -> 'a Context.t Lwt.t end end -diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/context.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/context.mli -index 636bb700d1..1a54302fd8 100644 ---- a/src/proto_017_PtNairob/lib_sc_rollup_node/context.mli -+++ b/src/proto_017_PtNairob/lib_sc_rollup_node/context.mli -@@ -29,10 +29,10 @@ open Store_sigs - index can be written or only read. *) - type 'a index constraint 'a = [< `Read | `Write > `Read] - --(** Read/write {!index}. *) -+(** Read/write {!type:index}. *) - type rw_index = [`Read | `Write] index - --(** Read only {!index}. *) -+(** Read only {!type:index}. *) - type ro_index = [`Read] index - - (** The type of trees stored in the context, i.e. the actual data. *) -@@ -48,7 +48,7 @@ type rw = [`Read | `Write] t - type ro = [`Read] t - - (** A context hash is the hash produced when the data of the context is -- committed to disk, i.e. the {!commit} hash. *) -+ committed to disk, i.e. the {!type:commit} hash. *) - type hash = Sc_rollup_context_hash.t - - (** The type of commits for the context. *) -@@ -156,7 +156,7 @@ module PVMState : sig - - (** [set context state] saves the PVM state [state] in the context and returns - the updated context. Note: [set] does not perform any write on disk, this -- information must be committed using {!commit}. *) -+ information must be committed using {!val:commit}. *) - val set : 'a t -> value -> 'a t Lwt.t - end - diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_pages_request.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/dal_pages_request.mli index 3be2cdb1f5..f27d737fbc 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/dal_pages_request.mli diff --git a/manifest/main.ml b/manifest/main.ml index ad011b80dc2c5000296b2f3dc8b1f54f7a0445d8..9076f3f13bc39ce4ad72c622023836b0332643ca 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -4103,6 +4103,7 @@ let octez_smart_rollup_node_lib = octez_injector |> open_; octez_version_value |> open_; octez_smart_rollup_lib |> open_; + octez_layer2_store |> open_; ] let octez_scoru_wasm_helpers = diff --git a/opam/octez-smart-rollup-node.opam b/opam/octez-smart-rollup-node.opam index c5215fbb62c011a7f1efcdc7316d4636971b84ae..fbf24bc6872bdba1328349389bc880411c3b8991 100644 --- a/opam/octez-smart-rollup-node.opam +++ b/opam/octez-smart-rollup-node.opam @@ -21,6 +21,7 @@ depends: [ "octez-injector" "tezos-version" "octez-smart-rollup" + "tezos-layer2-store" ] build: [ ["rm" "-r" "vendors" "contrib"] diff --git a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_context_hash.ml b/src/lib_smart_rollup/smart_rollup_context_hash.ml similarity index 93% rename from src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_context_hash.ml rename to src/lib_smart_rollup/smart_rollup_context_hash.ml index 000536a07aa55fea3f79d2ce6506e8b777dab8bb..ca539749516bbca813c89890e7e7c4066aed66df 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_context_hash.ml +++ b/src/lib_smart_rollup/smart_rollup_context_hash.ml @@ -1,7 +1,8 @@ (*****************************************************************************) (* *) (* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) +(* Copyright (c) 2023 Nomadic Labs, *) +(* Copyright (c) 2023 Functori, *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) diff --git a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_context_hash.mli b/src/lib_smart_rollup/smart_rollup_context_hash.mli similarity index 92% rename from src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_context_hash.mli rename to src/lib_smart_rollup/smart_rollup_context_hash.mli index d7acec7ff0ea7c661607780ead88138dc5f2de91..fcb83978ebfe7de13488e08f5c72dfd02437255c 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_context_hash.mli +++ b/src/lib_smart_rollup/smart_rollup_context_hash.mli @@ -1,7 +1,8 @@ (*****************************************************************************) (* *) (* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) +(* Copyright (c) 2023 Nomadic Labs, *) +(* Copyright (c) 2023 Functori, *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/context.ml b/src/lib_smart_rollup_node/context.ml similarity index 83% rename from src/proto_017_PtNairob/lib_sc_rollup_node/context.ml rename to src/lib_smart_rollup_node/context.ml index afbce3ba94818b3f4dc36bbec434bf1691937479..c2bd6aaa1dccd91e18e0f6bc3448f244fbf8aca5 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/context.ml +++ b/src/lib_smart_rollup_node/context.ml @@ -23,8 +23,6 @@ (* *) (*****************************************************************************) -open Protocol -open Alpha_context open Store_sigs module Context_encoding = Tezos_context_encoding.Context_binary @@ -34,6 +32,38 @@ module Context_encoding = Tezos_context_encoding.Context_binary refactoring.*) module Tezos_context_encoding = struct end +type error += + | Unexpected_rollup of { + rollup_address : Octez_smart_rollup.Address.t; + saved_address : Octez_smart_rollup.Address.t; + } + +let () = + register_error_kind + ~id:"sc_rollup.node.unexpected_rollup" + ~title:"Unexpected rollup for rollup node" + ~description:"This rollup node is already set up for another rollup." + ~pp:(fun ppf (rollup_address, saved_address) -> + Format.fprintf + ppf + "This rollup node was already set up for rollup %a, it cannot be run \ + for a different rollup %a." + Octez_smart_rollup.Address.pp + saved_address + Octez_smart_rollup.Address.pp + rollup_address) + `Permanent + Data_encoding.( + obj2 + (req "rollup_address" Octez_smart_rollup.Address.encoding) + (req "saved_address" Octez_smart_rollup.Address.encoding)) + (function + | Unexpected_rollup {rollup_address; saved_address} -> + Some (rollup_address, saved_address) + | _ -> None) + (fun (rollup_address, saved_address) -> + Unexpected_rollup {rollup_address; saved_address}) + module Maker = Irmin_pack_unix.Maker (Context_encoding.Conf) module IStore = struct @@ -62,17 +92,17 @@ type ro = [`Read] t type commit = IStore.commit -type hash = Sc_rollup_context_hash.t +type hash = Smart_rollup_context_hash.t type path = string list -let () = assert (Sc_rollup_context_hash.size = IStore.Hash.hash_size) +let () = assert (Smart_rollup_context_hash.size = IStore.Hash.hash_size) let hash_to_istore_hash h = - Sc_rollup_context_hash.to_string h |> IStore.Hash.unsafe_of_raw_string + Smart_rollup_context_hash.to_string h |> IStore.Hash.unsafe_of_raw_string let istore_hash_to_hash h = - IStore.Hash.to_raw_string h |> Sc_rollup_context_hash.of_string_exn + IStore.Hash.to_raw_string h |> Smart_rollup_context_hash.of_string_exn let load : type a. a mode -> string -> a raw_index Lwt.t = fun mode path -> @@ -121,7 +151,9 @@ module Proof (Hash : sig val of_context_hash : Context_hash.t -> t end) (Proof_encoding : sig val proof_encoding : - Environment.Context.Proof.tree Environment.Context.Proof.t Data_encoding.t + Tezos_context_sigs.Context.Proof_types.tree + Tezos_context_sigs.Context.Proof_types.t + Data_encoding.t end) = struct module IStoreProof = @@ -178,11 +210,6 @@ struct return None end -module Inbox = struct - include Sc_rollup.Inbox - module Message = Sc_rollup.Inbox_message -end - (** State of the PVM that this rollup node deals with. *) module PVMState = struct type value = tree @@ -214,7 +241,7 @@ module Rollup = struct IStore.Info.v date in let value = - Data_encoding.Binary.to_bytes_exn Sc_rollup.Address.encoding addr + Data_encoding.Binary.to_bytes_exn Octez_smart_rollup.Address.encoding addr in let*! store = IStore.main index.repo in let*! () = IStore.set_exn ~info store path value in @@ -227,7 +254,7 @@ module Rollup = struct let*! value = IStore.find store path in return @@ Option.map - (Data_encoding.Binary.of_bytes_exn Sc_rollup.Address.encoding) + (Data_encoding.Binary.of_bytes_exn Octez_smart_rollup.Address.encoding) value let check_or_set_address (type a) (mode : a mode) (index : a raw_index) @@ -236,9 +263,8 @@ module Rollup = struct let* saved_address = get_address index in match saved_address with | Some saved_address -> - fail_unless Sc_rollup.Address.(rollup_address = saved_address) - @@ Sc_rollup_node_errors.Unexpected_rollup - {rollup_address; saved_address} + fail_unless Octez_smart_rollup.Address.(rollup_address = saved_address) + @@ Unexpected_rollup {rollup_address; saved_address} | None -> ( (* Address was never saved, we set it permanently if not in read-only mode. *) diff --git a/src/proto_alpha/lib_sc_rollup_node/context.mli b/src/lib_smart_rollup_node/context.mli similarity index 95% rename from src/proto_alpha/lib_sc_rollup_node/context.mli rename to src/lib_smart_rollup_node/context.mli index 6a2f40660c1200aa296c9635c218032388586d34..4b49e6246075eb8905cce37efc1a4bba92def1cb 100644 --- a/src/proto_alpha/lib_sc_rollup_node/context.mli +++ b/src/lib_smart_rollup_node/context.mli @@ -49,7 +49,7 @@ type ro = [`Read] t (** A context hash is the hash produced when the data of the context is committed to disk, i.e. the {!type:commit} hash. *) -type hash = Sc_rollup_context_hash.t +type hash = Smart_rollup_context_hash.t (** The type of commits for the context. *) type commit @@ -94,7 +94,9 @@ module Proof (Hash : sig val of_context_hash : Context_hash.t -> t end) (Proof_encoding : sig val proof_encoding : - Environment.Context.Proof.tree Environment.Context.Proof.t Data_encoding.t + Tezos_context_sigs.Context.Proof_types.tree + Tezos_context_sigs.Context.Proof_types.t + Data_encoding.t end) : sig (** Tree representation for proof generation. @@ -163,11 +165,8 @@ end (** Static information about the rollup. *) module Rollup : sig val get_address : - _ index -> Protocol.Alpha_context.Sc_rollup.Address.t option tzresult Lwt.t + _ index -> Octez_smart_rollup.Address.t option tzresult Lwt.t val check_or_set_address : - 'a mode -> - 'a index -> - Protocol.Alpha_context.Sc_rollup.Address.t -> - unit tzresult Lwt.t + 'a mode -> 'a index -> Octez_smart_rollup.Address.t -> unit tzresult Lwt.t end diff --git a/src/lib_smart_rollup_node/dune b/src/lib_smart_rollup_node/dune index bb1a49fc2d077abc58b74e1a3147bc88f07f4ebb..d5c967b2ecdf3e40e62cf975f92447735f8c861b 100644 --- a/src/lib_smart_rollup_node/dune +++ b/src/lib_smart_rollup_node/dune @@ -17,7 +17,8 @@ prometheus-app octez-injector tezos-version.value - octez-smart-rollup) + octez-smart-rollup + tezos_layer2_store) (flags (:standard) -open Tezos_base.TzPervasives @@ -27,4 +28,5 @@ -open Tezos_client_base_unix -open Octez_injector -open Tezos_version_value - -open Octez_smart_rollup)) + -open Octez_smart_rollup + -open Tezos_layer2_store)) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.ml b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.ml index 4f832b00e6fb3e9518fbf1f47ddc02e27455daa8..a5c25b817f13899df8a2c5aa8b30c30c78e21aac 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.ml @@ -32,7 +32,7 @@ type header = { predecessor : Block_hash.t; commitment_hash : Sc_rollup.Commitment.Hash.t option; previous_commitment_hash : Sc_rollup.Commitment.Hash.t; - context : Sc_rollup_context_hash.t; + context : Smart_rollup_context_hash.t; inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; inbox_hash : Sc_rollup.Inbox.Hash.t; } @@ -129,7 +129,7 @@ let header_encoding = previously computed.") (req "context" - Sc_rollup_context_hash.encoding + Smart_rollup_context_hash.encoding ~description:"Hash of the layer 2 context for this block.") (req "inbox_witness" diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.mli b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.mli index 1f0f8c7b4bbd75dcc5c3f500c51b5f5c3adbf6d6..b575a5da9f52aaad5e2151bdbce9d4e5e9a4110b 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.mli +++ b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_block.mli @@ -42,7 +42,7 @@ type header = { (** Previous commitment hash in the chain. If there is a commitment for this block, this field contains the commitment that was previously computed. *) - context : Sc_rollup_context_hash.t; + context : Smart_rollup_context_hash.t; (** Hash of the layer 2 context for this block. *) inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; (** Witness for the inbox for this block, i.e. the Merkle hash of payloads diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_context_hash.ml b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_context_hash.ml deleted file mode 100644 index 4538fec721c6effdca82c16e79d28a1f449f9beb..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_context_hash.ml +++ /dev/null @@ -1,39 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -include - Tezos_crypto.Blake2B.Make - (Tezos_crypto.Base58) - (struct - let name = "Smart_rollup_context_hash" - - let title = "A base58-check encoded hash of a Smart rollup node context" - - let b58check_prefix = "\008\209\216\166" - - let size = None - end) - -let () = Tezos_crypto.Base58.check_encoded_prefix b58check_encoding "SRCo" 54 diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_context_hash.mli b/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_context_hash.mli deleted file mode 100644 index d7acec7ff0ea7c661607780ead88138dc5f2de91..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_layer2/sc_rollup_context_hash.mli +++ /dev/null @@ -1,26 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -include Tezos_crypto.Intfs.HASH diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/context.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/context.ml deleted file mode 100644 index afbce3ba94818b3f4dc36bbec434bf1691937479..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/context.ml +++ /dev/null @@ -1,308 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context -open Store_sigs -module Context_encoding = Tezos_context_encoding.Context_binary - -(* We shadow [Tezos_context_encoding] to prevent accidentally using - [Tezos_context_encoding.Context] instead of - [Tezos_context_encoding.Context_binary] during a future - refactoring.*) -module Tezos_context_encoding = struct end - -module Maker = Irmin_pack_unix.Maker (Context_encoding.Conf) - -module IStore = struct - include Maker.Make (Context_encoding.Schema) - module Schema = Context_encoding.Schema -end - -module IStoreTree = - Tezos_context_helpers.Context.Make_tree (Context_encoding.Conf) (IStore) - -type tree = IStore.tree - -type 'a raw_index = {path : string; repo : IStore.Repo.t} - -type 'a index = 'a raw_index constraint 'a = [< `Read | `Write > `Read] - -type rw_index = [`Read | `Write] index - -type ro_index = [`Read] index - -type 'a t = {index : 'a index; tree : tree} - -type rw = [`Read | `Write] t - -type ro = [`Read] t - -type commit = IStore.commit - -type hash = Sc_rollup_context_hash.t - -type path = string list - -let () = assert (Sc_rollup_context_hash.size = IStore.Hash.hash_size) - -let hash_to_istore_hash h = - Sc_rollup_context_hash.to_string h |> IStore.Hash.unsafe_of_raw_string - -let istore_hash_to_hash h = - IStore.Hash.to_raw_string h |> Sc_rollup_context_hash.of_string_exn - -let load : type a. a mode -> string -> a raw_index Lwt.t = - fun mode path -> - let open Lwt_syntax in - let readonly = match mode with Read_only -> true | Read_write -> false in - let+ repo = - IStore.Repo.v - (Irmin_pack.config - ~readonly - ~indexing_strategy:Irmin_pack.Indexing_strategy.minimal - path) - in - {path; repo} - -let close ctxt = IStore.Repo.close ctxt.repo - -let readonly (index : [> `Read] index) = (index :> [`Read] index) - -let raw_commit ?(message = "") index tree = - let info = IStore.Info.v ~author:"Tezos" 0L ~message in - IStore.Commit.v index.repo ~info ~parents:[] tree - -let commit ?message ctxt = - let open Lwt_syntax in - let+ commit = raw_commit ?message ctxt.index ctxt.tree in - IStore.Commit.hash commit |> istore_hash_to_hash - -let checkout index key = - let open Lwt_syntax in - let* o = IStore.Commit.of_hash index.repo (hash_to_istore_hash key) in - match o with - | None -> return_none - | Some commit -> - let tree = IStore.Commit.tree commit in - return_some {index; tree} - -let empty index = {index; tree = IStore.Tree.empty ()} - -let is_empty ctxt = IStore.Tree.is_empty ctxt.tree - -let index context = context.index - -module Proof (Hash : sig - type t - - val of_context_hash : Context_hash.t -> t -end) (Proof_encoding : sig - val proof_encoding : - Environment.Context.Proof.tree Environment.Context.Proof.t Data_encoding.t -end) = -struct - module IStoreProof = - Tezos_context_helpers.Context.Make_proof (IStore) (Context_encoding.Conf) - - module Tree = struct - include IStoreTree - - type t = rw_index - - type tree = IStore.tree - - type key = path - - type value = bytes - end - - type tree = Tree.tree - - type proof = IStoreProof.Proof.tree IStoreProof.Proof.t - - let hash_tree tree = Hash.of_context_hash (Tree.hash tree) - - let proof_encoding = Proof_encoding.proof_encoding - - let proof_before proof = - let (`Value hash | `Node hash) = proof.IStoreProof.Proof.before in - Hash.of_context_hash hash - - let proof_after proof = - let (`Value hash | `Node hash) = proof.IStoreProof.Proof.after in - Hash.of_context_hash hash - - let produce_proof index tree step = - let open Lwt_syntax in - (* Committing the context is required by Irmin to produce valid proofs. *) - let* _commit_key = raw_commit index tree in - match Tree.kinded_key tree with - | Some k -> - let* p = IStoreProof.produce_tree_proof index.repo k step in - return (Some p) - | None -> return None - - let verify_proof proof step = - (* The rollup node is not supposed to verify proof. We keep - this part in case this changes in the future. *) - let open Lwt_syntax in - let* result = IStoreProof.verify_tree_proof proof step in - match result with - | Ok v -> return (Some v) - | Error _ -> - (* We skip the error analysis here since proof verification is not a - job for the rollup node. *) - return None -end - -module Inbox = struct - include Sc_rollup.Inbox - module Message = Sc_rollup.Inbox_message -end - -(** State of the PVM that this rollup node deals with. *) -module PVMState = struct - type value = tree - - let key = ["pvm_state"] - - let empty () = IStore.Tree.empty () - - let find ctxt = IStore.Tree.find_tree ctxt.tree key - - let lookup tree path = IStore.Tree.find tree path - - let set ctxt state = - let open Lwt_syntax in - let+ tree = IStore.Tree.add_tree ctxt.tree key state in - {ctxt with tree} -end - -module Rollup = struct - let path = ["rollup_address"] - - let set_address (index : rw_index) addr = - let open Lwt_result_syntax in - protect @@ fun () -> - let info () = - let date = - Time.(System.now () |> System.to_protocol |> Protocol.to_seconds) - in - IStore.Info.v date - in - let value = - Data_encoding.Binary.to_bytes_exn Sc_rollup.Address.encoding addr - in - let*! store = IStore.main index.repo in - let*! () = IStore.set_exn ~info store path value in - return_unit - - let get_address (index : _ raw_index) = - let open Lwt_result_syntax in - protect @@ fun () -> - let*! store = IStore.main index.repo in - let*! value = IStore.find store path in - return - @@ Option.map - (Data_encoding.Binary.of_bytes_exn Sc_rollup.Address.encoding) - value - - let check_or_set_address (type a) (mode : a mode) (index : a raw_index) - rollup_address = - let open Lwt_result_syntax in - let* saved_address = get_address index in - match saved_address with - | Some saved_address -> - fail_unless Sc_rollup.Address.(rollup_address = saved_address) - @@ Sc_rollup_node_errors.Unexpected_rollup - {rollup_address; saved_address} - | None -> ( - (* Address was never saved, we set it permanently if not in read-only - mode. *) - match mode with - | Store_sigs.Read_only -> return_unit - | Read_write -> set_address index rollup_address) -end - -module Version = struct - type t = V0 - - let version = V0 - - let encoding = - let open Data_encoding in - conv - (fun V0 -> 0) - (function - | 0 -> V0 - | v -> - Format.ksprintf Stdlib.failwith "Unsupported context version %d" v) - int31 - - let path = ["context_version"] - - let set (index : rw_index) = - let open Lwt_result_syntax in - protect @@ fun () -> - let info () = - let date = - Time.(System.now () |> System.to_protocol |> Protocol.to_seconds) - in - IStore.Info.v date - in - let value = Data_encoding.Binary.to_bytes_exn encoding version in - let*! store = IStore.main index.repo in - let*! () = IStore.set_exn ~info store path value in - return_unit - - let get (index : _ index) = - let open Lwt_result_syntax in - protect @@ fun () -> - let*! store = IStore.main index.repo in - let*! value = IStore.find store path in - return @@ Option.map (Data_encoding.Binary.of_bytes_exn encoding) value - - let check (index : _ index) = - let open Lwt_result_syntax in - let* context_version = get index in - match context_version with None | Some V0 -> return_unit - - let check_and_set (index : _ index) = - let open Lwt_result_syntax in - let* context_version = get index in - match context_version with None -> set index | Some V0 -> return_unit -end - -let load : type a. a mode -> string -> a raw_index tzresult Lwt.t = - fun mode path -> - let open Lwt_result_syntax in - let*! index = load mode path in - let+ () = - match mode with - | Read_only -> Version.check index - | Read_write -> Version.check_and_set index - in - index diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/context.mli b/src/proto_016_PtMumbai/lib_sc_rollup_node/context.mli deleted file mode 100644 index d4c1acbc98e5efdf05363c768ca88dbe06deac54..0000000000000000000000000000000000000000 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/context.mli +++ /dev/null @@ -1,173 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -open Store_sigs - -(** The type of indexed repository for contexts. The parameter indicates if the - index can be written or only read. *) -type 'a index constraint 'a = [< `Read | `Write > `Read] - -(** Read/write {!index}. *) -type rw_index = [`Read | `Write] index - -(** Read only {!index}. *) -type ro_index = [`Read] index - -(** The type of trees stored in the context, i.e. the actual data. *) -type tree - -(** The type of context with its content. *) -type 'a t constraint 'a = [< `Read | `Write > `Read] - -(** Read/write context {!t}. *) -type rw = [`Read | `Write] t - -(** Read-only context {!t}. *) -type ro = [`Read] t - -(** A context hash is the hash produced when the data of the context is - committed to disk, i.e. the {!commit} hash. *) -type hash = Sc_rollup_context_hash.t - -(** The type of commits for the context. *) -type commit - -(** [load path] initializes from disk a context from [path]. *) -val load : 'a mode -> string -> 'a index tzresult Lwt.t - -(** [index context] is the repository of the context [context]. *) -val index : 'a t -> 'a index - -(** [close ctxt] closes the context index [ctxt]. *) -val close : _ index -> unit Lwt.t - -(** [readonly index] returns a read-only version of the index. *) -val readonly : [> `Read] index -> [`Read] index - -(** [raw_commit ?message ctxt tree] commits the [tree] in the context repository - [ctxt] on disk, and return the commit. *) -val raw_commit : ?message:string -> [> `Write] index -> tree -> commit Lwt.t - -(** [commit ?message context] commits content of the context [context] on disk, - and return the commit hash. *) -val commit : ?message:string -> [> `Write] t -> hash Lwt.t - -(** [checkout ctxt hash] checkouts the content that corresponds to the commit - hash [hash] in the repository [ctxt] and returns the corresponding - context. If there is no commit that corresponds to [hash], it returns - [None]. *) -val checkout : 'a index -> hash -> 'a t option Lwt.t - -(** [empty ctxt] is the context with an empty content for the repository [ctxt]. *) -val empty : 'a index -> 'a t - -(** [is_empty context] returns [true] iff the context content of [context] is - empty. *) -val is_empty : _ t -> bool - -(** Module for generating and verifying proofs for a context *) -module Proof (Hash : sig - type t - - val of_context_hash : Context_hash.t -> t -end) (Proof_encoding : sig - val proof_encoding : - Environment.Context.Proof.tree Environment.Context.Proof.t Data_encoding.t -end) : sig - (** Tree representation for proof generation. - - NOTE: The index needs to be accessed with write permissions because we - need to commit on disk to generate the proofs (e.g. in - {!Inbox.produce_proof}, {!PVM.produce_proof}. or - {!PVM.produce_output_proof}). *) - module Tree : - Tezos_context_sigs.Context.TREE - with type key = string list - and type value = bytes - and type t = rw_index - and type tree = tree - - type tree = Tree.tree - - (** See {!Sc_rollup_PVM_sem.proof} *) - type proof - - val hash_tree : tree -> Hash.t - - (** See {!Sc_rollup_PVM_sem.proof_encoding} *) - val proof_encoding : proof Data_encoding.t - - (** [proof_before proof] is the hash of the state before the step that - generated [rpoof]. *) - val proof_before : proof -> Hash.t - - (** [proof_after proof] is the hash of the state after the step that generated - [rpoof]. *) - val proof_after : proof -> Hash.t - - (** [produce_proof ctxt tree f] produces and returns a proof for the execution - of [f] on the state [tree]. *) - val produce_proof : - rw_index -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t - - (** [verify_proof proof f] verifies that [f] produces the proof [proof] and - returns the resulting [tree], or [None] if the proof cannot be - verified. *) - val verify_proof : - proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t -end - -(** State of the PVM that this rollup node deals with *) -module PVMState : sig - (** The value of a PVM state *) - type value = tree - - (** [empty ()] is the empty PVM state. *) - val empty : unit -> value - - (** [find context] returns the PVM state stored in the [context], if any. *) - val find : _ t -> value option Lwt.t - - (** [lookup state path] returns the data stored for the path [path] in the PVM - state [state]. *) - val lookup : value -> string list -> bytes option Lwt.t - - (** [set context state] saves the PVM state [state] in the context and returns - the updated context. Note: [set] does not perform any write on disk, this - information must be committed using {!commit}. *) - val set : 'a t -> value -> 'a t Lwt.t -end - -(** Static information about the rollup. *) -module Rollup : sig - val get_address : - _ index -> Protocol.Alpha_context.Sc_rollup.Address.t option tzresult Lwt.t - - val check_or_set_address : - 'a mode -> - 'a index -> - Protocol.Alpha_context.Sc_rollup.Address.t -> - unit tzresult Lwt.t -end diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml index 4af400c134b80dc24bb28c3bbd5892b389a6cc5b..5e12722b9d436db27224cdc11d8bb67662b86333 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/node_context.ml @@ -292,10 +292,6 @@ let init (cctxt : Protocol_client_context.full) ~data_dir ?log_kernel_debug_file } as configuration) = let open Lwt_result_syntax in let*? () = check_config configuration in - let rollup_address = - (* Convert to protocol rollup address *) - Sc_rollup_proto_types.Address.of_octez rollup_address - in let* lockfile = lock ~data_dir in let* () = Store_migration.maybe_run_migration @@ -315,6 +311,10 @@ let init (cctxt : Protocol_client_context.full) ~data_dir ?log_kernel_debug_file in let* () = Context.Rollup.check_or_set_address mode context rollup_address in let publisher = Configuration.Operator_purpose_map.find Publish operators in + let rollup_address = + (* Convert to protocol rollup address *) + Sc_rollup_proto_types.Address.of_octez rollup_address + in let* protocol_constants = retrieve_constants cctxt and* lcc = get_last_cemented_commitment cctxt rollup_address and* lpc = diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/sc_rollup_node_errors.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/sc_rollup_node_errors.ml index 75f4fd02e92bcce2c9c4b6ffb75a0d5ccc25fca1..f20e60b4cdc5ca34c89595cbed7ee3e2cf5db0b9 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/sc_rollup_node_errors.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/sc_rollup_node_errors.ml @@ -46,12 +46,8 @@ type error += layer1_inbox : Sc_rollup.Inbox.t; inbox : Sc_rollup.Inbox.t; } - | Unexpected_rollup of { - rollup_address : Sc_rollup.Address.t; - saved_address : Sc_rollup.Address.t; - } | Missing_PVM_state of Block_hash.t * Int32.t - | Cannot_checkout_context of Block_hash.t * Sc_rollup_context_hash.t option + | Cannot_checkout_context of Block_hash.t * Smart_rollup_context_hash.t option | No_batcher | No_publisher | Refutation_player_failed_to_start @@ -191,31 +187,6 @@ let () = | _ -> None) (fun (layer1_inbox, inbox) -> Inconsistent_inbox {layer1_inbox; inbox}) ; - register_error_kind - ~id:"sc_rollup.node.unexpected_rollup" - ~title:"Unexpected rollup for rollup node" - ~description:"This rollup node is already set up for another rollup." - ~pp:(fun ppf (rollup_address, saved_address) -> - Format.fprintf - ppf - "This rollup node was already set up for rollup %a, it cannot be run \ - for a different rollup %a." - Sc_rollup.Address.pp - saved_address - Sc_rollup.Address.pp - rollup_address) - `Permanent - Data_encoding.( - obj2 - (req "rollup_address" Sc_rollup.Address.encoding) - (req "saved_address" Sc_rollup.Address.encoding)) - (function - | Unexpected_rollup {rollup_address; saved_address} -> - Some (rollup_address, saved_address) - | _ -> None) - (fun (rollup_address, saved_address) -> - Unexpected_rollup {rollup_address; saved_address}) ; - register_error_kind `Permanent ~id:"internal.missing_pvm_state" @@ -245,14 +216,14 @@ let () = "The context %sfor block %a cannot be checkouted" (Option.fold ~none:"" - ~some:Sc_rollup_context_hash.to_b58check + ~some:Smart_rollup_context_hash.to_b58check context_hash) Block_hash.pp block) Data_encoding.( obj2 (req "block" Block_hash.encoding) - (opt "context" Sc_rollup_context_hash.encoding)) + (opt "context" Smart_rollup_context_hash.encoding)) (function | Cannot_checkout_context (block, context) -> Some (block, context) | _ -> None) diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.ml index b408c4b3c9f227f9576d33e6320d1baa410e0622..1af610d1f524e8b2e6443ce5c901244fc456b54c 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/test/helpers/helpers.ml @@ -69,7 +69,7 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = in let* inbox_hash = Node_context.save_inbox node_ctxt inbox in let inbox_witness = Sc_rollup.Inbox.current_witness inbox in - let ctxt = Context.empty node_ctxt.context in + let ctxt = Octez_smart_rollup_node.Context.empty node_ctxt.context in let num_ticks = 0L in let module PVM = (val node_ctxt.pvm) in let initial_tick = Sc_rollup.Tick.initial in @@ -77,7 +77,7 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = let*! state = PVM.install_boot_sector initial_state boot_sector in let*! genesis_state_hash = PVM.state_hash state in let*! ctxt = PVM.State.set ctxt state in - let*! context_hash = Context.commit ctxt in + let*! context_hash = Octez_smart_rollup_node.Context.commit ctxt in let commitment = Sc_rollup.Commitment.genesis_commitment ~origination_level:node_ctxt.genesis_info.level diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.ml b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.ml index 4f832b00e6fb3e9518fbf1f47ddc02e27455daa8..a5c25b817f13899df8a2c5aa8b30c30c78e21aac 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.ml @@ -32,7 +32,7 @@ type header = { predecessor : Block_hash.t; commitment_hash : Sc_rollup.Commitment.Hash.t option; previous_commitment_hash : Sc_rollup.Commitment.Hash.t; - context : Sc_rollup_context_hash.t; + context : Smart_rollup_context_hash.t; inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; inbox_hash : Sc_rollup.Inbox.Hash.t; } @@ -129,7 +129,7 @@ let header_encoding = previously computed.") (req "context" - Sc_rollup_context_hash.encoding + Smart_rollup_context_hash.encoding ~description:"Hash of the layer 2 context for this block.") (req "inbox_witness" diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.mli b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.mli index 1f0f8c7b4bbd75dcc5c3f500c51b5f5c3adbf6d6..b575a5da9f52aaad5e2151bdbce9d4e5e9a4110b 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.mli +++ b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_block.mli @@ -42,7 +42,7 @@ type header = { (** Previous commitment hash in the chain. If there is a commitment for this block, this field contains the commitment that was previously computed. *) - context : Sc_rollup_context_hash.t; + context : Smart_rollup_context_hash.t; (** Hash of the layer 2 context for this block. *) inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; (** Witness for the inbox for this block, i.e. the Merkle hash of payloads diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_context_hash.ml b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_context_hash.ml deleted file mode 100644 index 000536a07aa55fea3f79d2ce6506e8b777dab8bb..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_context_hash.ml +++ /dev/null @@ -1,41 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -open Tezos_crypto - -include - Blake2B.Make - (Base58) - (struct - let name = "Smart_rollup_context_hash" - - let title = "A base58-check encoded hash of a Smart rollup node context" - - let b58check_prefix = "\008\209\216\166" - - let size = None - end) - -let () = Base58.check_encoded_prefix b58check_encoding "SRCo" 54 diff --git a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_context_hash.mli b/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_context_hash.mli deleted file mode 100644 index d7acec7ff0ea7c661607780ead88138dc5f2de91..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_layer2/sc_rollup_context_hash.mli +++ /dev/null @@ -1,26 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2022 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -include Tezos_crypto.Intfs.HASH diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/context.mli b/src/proto_017_PtNairob/lib_sc_rollup_node/context.mli deleted file mode 100644 index d4c1acbc98e5efdf05363c768ca88dbe06deac54..0000000000000000000000000000000000000000 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/context.mli +++ /dev/null @@ -1,173 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -open Store_sigs - -(** The type of indexed repository for contexts. The parameter indicates if the - index can be written or only read. *) -type 'a index constraint 'a = [< `Read | `Write > `Read] - -(** Read/write {!index}. *) -type rw_index = [`Read | `Write] index - -(** Read only {!index}. *) -type ro_index = [`Read] index - -(** The type of trees stored in the context, i.e. the actual data. *) -type tree - -(** The type of context with its content. *) -type 'a t constraint 'a = [< `Read | `Write > `Read] - -(** Read/write context {!t}. *) -type rw = [`Read | `Write] t - -(** Read-only context {!t}. *) -type ro = [`Read] t - -(** A context hash is the hash produced when the data of the context is - committed to disk, i.e. the {!commit} hash. *) -type hash = Sc_rollup_context_hash.t - -(** The type of commits for the context. *) -type commit - -(** [load path] initializes from disk a context from [path]. *) -val load : 'a mode -> string -> 'a index tzresult Lwt.t - -(** [index context] is the repository of the context [context]. *) -val index : 'a t -> 'a index - -(** [close ctxt] closes the context index [ctxt]. *) -val close : _ index -> unit Lwt.t - -(** [readonly index] returns a read-only version of the index. *) -val readonly : [> `Read] index -> [`Read] index - -(** [raw_commit ?message ctxt tree] commits the [tree] in the context repository - [ctxt] on disk, and return the commit. *) -val raw_commit : ?message:string -> [> `Write] index -> tree -> commit Lwt.t - -(** [commit ?message context] commits content of the context [context] on disk, - and return the commit hash. *) -val commit : ?message:string -> [> `Write] t -> hash Lwt.t - -(** [checkout ctxt hash] checkouts the content that corresponds to the commit - hash [hash] in the repository [ctxt] and returns the corresponding - context. If there is no commit that corresponds to [hash], it returns - [None]. *) -val checkout : 'a index -> hash -> 'a t option Lwt.t - -(** [empty ctxt] is the context with an empty content for the repository [ctxt]. *) -val empty : 'a index -> 'a t - -(** [is_empty context] returns [true] iff the context content of [context] is - empty. *) -val is_empty : _ t -> bool - -(** Module for generating and verifying proofs for a context *) -module Proof (Hash : sig - type t - - val of_context_hash : Context_hash.t -> t -end) (Proof_encoding : sig - val proof_encoding : - Environment.Context.Proof.tree Environment.Context.Proof.t Data_encoding.t -end) : sig - (** Tree representation for proof generation. - - NOTE: The index needs to be accessed with write permissions because we - need to commit on disk to generate the proofs (e.g. in - {!Inbox.produce_proof}, {!PVM.produce_proof}. or - {!PVM.produce_output_proof}). *) - module Tree : - Tezos_context_sigs.Context.TREE - with type key = string list - and type value = bytes - and type t = rw_index - and type tree = tree - - type tree = Tree.tree - - (** See {!Sc_rollup_PVM_sem.proof} *) - type proof - - val hash_tree : tree -> Hash.t - - (** See {!Sc_rollup_PVM_sem.proof_encoding} *) - val proof_encoding : proof Data_encoding.t - - (** [proof_before proof] is the hash of the state before the step that - generated [rpoof]. *) - val proof_before : proof -> Hash.t - - (** [proof_after proof] is the hash of the state after the step that generated - [rpoof]. *) - val proof_after : proof -> Hash.t - - (** [produce_proof ctxt tree f] produces and returns a proof for the execution - of [f] on the state [tree]. *) - val produce_proof : - rw_index -> tree -> (tree -> (tree * 'a) Lwt.t) -> (proof * 'a) option Lwt.t - - (** [verify_proof proof f] verifies that [f] produces the proof [proof] and - returns the resulting [tree], or [None] if the proof cannot be - verified. *) - val verify_proof : - proof -> (tree -> (tree * 'a) Lwt.t) -> (tree * 'a) option Lwt.t -end - -(** State of the PVM that this rollup node deals with *) -module PVMState : sig - (** The value of a PVM state *) - type value = tree - - (** [empty ()] is the empty PVM state. *) - val empty : unit -> value - - (** [find context] returns the PVM state stored in the [context], if any. *) - val find : _ t -> value option Lwt.t - - (** [lookup state path] returns the data stored for the path [path] in the PVM - state [state]. *) - val lookup : value -> string list -> bytes option Lwt.t - - (** [set context state] saves the PVM state [state] in the context and returns - the updated context. Note: [set] does not perform any write on disk, this - information must be committed using {!commit}. *) - val set : 'a t -> value -> 'a t Lwt.t -end - -(** Static information about the rollup. *) -module Rollup : sig - val get_address : - _ index -> Protocol.Alpha_context.Sc_rollup.Address.t option tzresult Lwt.t - - val check_or_set_address : - 'a mode -> - 'a index -> - Protocol.Alpha_context.Sc_rollup.Address.t -> - unit tzresult Lwt.t -end diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml index 8b7acd4d6cd574d71159923dcbe962085efa3030..cec116c42af0ac46c7e1f6c8362d8133006b261e 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/node_context.ml @@ -292,10 +292,6 @@ let init (cctxt : Protocol_client_context.full) ~data_dir ?log_kernel_debug_file } as configuration) = let open Lwt_result_syntax in let*? () = check_config configuration in - let rollup_address = - (* Convert to protocol rollup address *) - Sc_rollup_proto_types.Address.of_octez rollup_address - in let* lockfile = lock ~data_dir in let* () = Store_migration.maybe_run_migration @@ -315,6 +311,10 @@ let init (cctxt : Protocol_client_context.full) ~data_dir ?log_kernel_debug_file in let* () = Context.Rollup.check_or_set_address mode context rollup_address in let publisher = Configuration.Operator_purpose_map.find Publish operators in + let rollup_address = + (* Convert to protocol rollup address *) + Sc_rollup_proto_types.Address.of_octez rollup_address + in let* protocol_constants = retrieve_constants cctxt and* lcc = get_last_cemented_commitment cctxt rollup_address and* lpc = diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_node_errors.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_node_errors.ml index 75f4fd02e92bcce2c9c4b6ffb75a0d5ccc25fca1..f20e60b4cdc5ca34c89595cbed7ee3e2cf5db0b9 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_node_errors.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/sc_rollup_node_errors.ml @@ -46,12 +46,8 @@ type error += layer1_inbox : Sc_rollup.Inbox.t; inbox : Sc_rollup.Inbox.t; } - | Unexpected_rollup of { - rollup_address : Sc_rollup.Address.t; - saved_address : Sc_rollup.Address.t; - } | Missing_PVM_state of Block_hash.t * Int32.t - | Cannot_checkout_context of Block_hash.t * Sc_rollup_context_hash.t option + | Cannot_checkout_context of Block_hash.t * Smart_rollup_context_hash.t option | No_batcher | No_publisher | Refutation_player_failed_to_start @@ -191,31 +187,6 @@ let () = | _ -> None) (fun (layer1_inbox, inbox) -> Inconsistent_inbox {layer1_inbox; inbox}) ; - register_error_kind - ~id:"sc_rollup.node.unexpected_rollup" - ~title:"Unexpected rollup for rollup node" - ~description:"This rollup node is already set up for another rollup." - ~pp:(fun ppf (rollup_address, saved_address) -> - Format.fprintf - ppf - "This rollup node was already set up for rollup %a, it cannot be run \ - for a different rollup %a." - Sc_rollup.Address.pp - saved_address - Sc_rollup.Address.pp - rollup_address) - `Permanent - Data_encoding.( - obj2 - (req "rollup_address" Sc_rollup.Address.encoding) - (req "saved_address" Sc_rollup.Address.encoding)) - (function - | Unexpected_rollup {rollup_address; saved_address} -> - Some (rollup_address, saved_address) - | _ -> None) - (fun (rollup_address, saved_address) -> - Unexpected_rollup {rollup_address; saved_address}) ; - register_error_kind `Permanent ~id:"internal.missing_pvm_state" @@ -245,14 +216,14 @@ let () = "The context %sfor block %a cannot be checkouted" (Option.fold ~none:"" - ~some:Sc_rollup_context_hash.to_b58check + ~some:Smart_rollup_context_hash.to_b58check context_hash) Block_hash.pp block) Data_encoding.( obj2 (req "block" Block_hash.encoding) - (opt "context" Sc_rollup_context_hash.encoding)) + (opt "context" Smart_rollup_context_hash.encoding)) (function | Cannot_checkout_context (block, context) -> Some (block, context) | _ -> None) diff --git a/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.ml b/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.ml index e4e10ac2334469df8a139f5463d9fd4092d50764..9299b441332c34bb7bc89836491e9d3b7bd60696 100644 --- a/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.ml +++ b/src/proto_017_PtNairob/lib_sc_rollup_node/test/helpers/helpers.ml @@ -68,7 +68,7 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = in let* inbox_hash = Node_context.save_inbox node_ctxt inbox in let inbox_witness = Sc_rollup.Inbox.current_witness inbox in - let ctxt = Context.empty node_ctxt.context in + let ctxt = Octez_smart_rollup_node.Context.empty node_ctxt.context in let num_ticks = 0L in let module PVM = (val node_ctxt.pvm) in let initial_tick = Sc_rollup.Tick.initial in @@ -76,7 +76,7 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = let*! state = PVM.install_boot_sector initial_state boot_sector in let*! genesis_state_hash = PVM.state_hash state in let*! ctxt = PVM.State.set ctxt state in - let*! context_hash = Context.commit ctxt in + let*! context_hash = Octez_smart_rollup_node.Context.commit ctxt in let commitment = Sc_rollup.Commitment.genesis_commitment ~origination_level:node_ctxt.genesis_info.level diff --git a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.ml b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.ml index 4f832b00e6fb3e9518fbf1f47ddc02e27455daa8..a5c25b817f13899df8a2c5aa8b30c30c78e21aac 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.ml +++ b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.ml @@ -32,7 +32,7 @@ type header = { predecessor : Block_hash.t; commitment_hash : Sc_rollup.Commitment.Hash.t option; previous_commitment_hash : Sc_rollup.Commitment.Hash.t; - context : Sc_rollup_context_hash.t; + context : Smart_rollup_context_hash.t; inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; inbox_hash : Sc_rollup.Inbox.Hash.t; } @@ -129,7 +129,7 @@ let header_encoding = previously computed.") (req "context" - Sc_rollup_context_hash.encoding + Smart_rollup_context_hash.encoding ~description:"Hash of the layer 2 context for this block.") (req "inbox_witness" diff --git a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.mli b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.mli index 1f0f8c7b4bbd75dcc5c3f500c51b5f5c3adbf6d6..b575a5da9f52aaad5e2151bdbce9d4e5e9a4110b 100644 --- a/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.mli +++ b/src/proto_alpha/lib_sc_rollup_layer2/sc_rollup_block.mli @@ -42,7 +42,7 @@ type header = { (** Previous commitment hash in the chain. If there is a commitment for this block, this field contains the commitment that was previously computed. *) - context : Sc_rollup_context_hash.t; + context : Smart_rollup_context_hash.t; (** Hash of the layer 2 context for this block. *) inbox_witness : Sc_rollup.Inbox_merkelized_payload_hashes.Hash.t; (** Witness for the inbox for this block, i.e. the Merkle hash of payloads diff --git a/src/proto_alpha/lib_sc_rollup_node/context.ml b/src/proto_alpha/lib_sc_rollup_node/context.ml deleted file mode 100644 index afbce3ba94818b3f4dc36bbec434bf1691937479..0000000000000000000000000000000000000000 --- a/src/proto_alpha/lib_sc_rollup_node/context.ml +++ /dev/null @@ -1,308 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2021 Nomadic Labs, *) -(* *) -(* Permission is hereby granted, free of charge, to any person obtaining a *) -(* copy of this software and associated documentation files (the "Software"),*) -(* to deal in the Software without restriction, including without limitation *) -(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) -(* and/or sell copies of the Software, and to permit persons to whom the *) -(* Software is furnished to do so, subject to the following conditions: *) -(* *) -(* The above copyright notice and this permission notice shall be included *) -(* in all copies or substantial portions of the Software. *) -(* *) -(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) -(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) -(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) -(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) -(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) -(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) -(* DEALINGS IN THE SOFTWARE. *) -(* *) -(*****************************************************************************) - -open Protocol -open Alpha_context -open Store_sigs -module Context_encoding = Tezos_context_encoding.Context_binary - -(* We shadow [Tezos_context_encoding] to prevent accidentally using - [Tezos_context_encoding.Context] instead of - [Tezos_context_encoding.Context_binary] during a future - refactoring.*) -module Tezos_context_encoding = struct end - -module Maker = Irmin_pack_unix.Maker (Context_encoding.Conf) - -module IStore = struct - include Maker.Make (Context_encoding.Schema) - module Schema = Context_encoding.Schema -end - -module IStoreTree = - Tezos_context_helpers.Context.Make_tree (Context_encoding.Conf) (IStore) - -type tree = IStore.tree - -type 'a raw_index = {path : string; repo : IStore.Repo.t} - -type 'a index = 'a raw_index constraint 'a = [< `Read | `Write > `Read] - -type rw_index = [`Read | `Write] index - -type ro_index = [`Read] index - -type 'a t = {index : 'a index; tree : tree} - -type rw = [`Read | `Write] t - -type ro = [`Read] t - -type commit = IStore.commit - -type hash = Sc_rollup_context_hash.t - -type path = string list - -let () = assert (Sc_rollup_context_hash.size = IStore.Hash.hash_size) - -let hash_to_istore_hash h = - Sc_rollup_context_hash.to_string h |> IStore.Hash.unsafe_of_raw_string - -let istore_hash_to_hash h = - IStore.Hash.to_raw_string h |> Sc_rollup_context_hash.of_string_exn - -let load : type a. a mode -> string -> a raw_index Lwt.t = - fun mode path -> - let open Lwt_syntax in - let readonly = match mode with Read_only -> true | Read_write -> false in - let+ repo = - IStore.Repo.v - (Irmin_pack.config - ~readonly - ~indexing_strategy:Irmin_pack.Indexing_strategy.minimal - path) - in - {path; repo} - -let close ctxt = IStore.Repo.close ctxt.repo - -let readonly (index : [> `Read] index) = (index :> [`Read] index) - -let raw_commit ?(message = "") index tree = - let info = IStore.Info.v ~author:"Tezos" 0L ~message in - IStore.Commit.v index.repo ~info ~parents:[] tree - -let commit ?message ctxt = - let open Lwt_syntax in - let+ commit = raw_commit ?message ctxt.index ctxt.tree in - IStore.Commit.hash commit |> istore_hash_to_hash - -let checkout index key = - let open Lwt_syntax in - let* o = IStore.Commit.of_hash index.repo (hash_to_istore_hash key) in - match o with - | None -> return_none - | Some commit -> - let tree = IStore.Commit.tree commit in - return_some {index; tree} - -let empty index = {index; tree = IStore.Tree.empty ()} - -let is_empty ctxt = IStore.Tree.is_empty ctxt.tree - -let index context = context.index - -module Proof (Hash : sig - type t - - val of_context_hash : Context_hash.t -> t -end) (Proof_encoding : sig - val proof_encoding : - Environment.Context.Proof.tree Environment.Context.Proof.t Data_encoding.t -end) = -struct - module IStoreProof = - Tezos_context_helpers.Context.Make_proof (IStore) (Context_encoding.Conf) - - module Tree = struct - include IStoreTree - - type t = rw_index - - type tree = IStore.tree - - type key = path - - type value = bytes - end - - type tree = Tree.tree - - type proof = IStoreProof.Proof.tree IStoreProof.Proof.t - - let hash_tree tree = Hash.of_context_hash (Tree.hash tree) - - let proof_encoding = Proof_encoding.proof_encoding - - let proof_before proof = - let (`Value hash | `Node hash) = proof.IStoreProof.Proof.before in - Hash.of_context_hash hash - - let proof_after proof = - let (`Value hash | `Node hash) = proof.IStoreProof.Proof.after in - Hash.of_context_hash hash - - let produce_proof index tree step = - let open Lwt_syntax in - (* Committing the context is required by Irmin to produce valid proofs. *) - let* _commit_key = raw_commit index tree in - match Tree.kinded_key tree with - | Some k -> - let* p = IStoreProof.produce_tree_proof index.repo k step in - return (Some p) - | None -> return None - - let verify_proof proof step = - (* The rollup node is not supposed to verify proof. We keep - this part in case this changes in the future. *) - let open Lwt_syntax in - let* result = IStoreProof.verify_tree_proof proof step in - match result with - | Ok v -> return (Some v) - | Error _ -> - (* We skip the error analysis here since proof verification is not a - job for the rollup node. *) - return None -end - -module Inbox = struct - include Sc_rollup.Inbox - module Message = Sc_rollup.Inbox_message -end - -(** State of the PVM that this rollup node deals with. *) -module PVMState = struct - type value = tree - - let key = ["pvm_state"] - - let empty () = IStore.Tree.empty () - - let find ctxt = IStore.Tree.find_tree ctxt.tree key - - let lookup tree path = IStore.Tree.find tree path - - let set ctxt state = - let open Lwt_syntax in - let+ tree = IStore.Tree.add_tree ctxt.tree key state in - {ctxt with tree} -end - -module Rollup = struct - let path = ["rollup_address"] - - let set_address (index : rw_index) addr = - let open Lwt_result_syntax in - protect @@ fun () -> - let info () = - let date = - Time.(System.now () |> System.to_protocol |> Protocol.to_seconds) - in - IStore.Info.v date - in - let value = - Data_encoding.Binary.to_bytes_exn Sc_rollup.Address.encoding addr - in - let*! store = IStore.main index.repo in - let*! () = IStore.set_exn ~info store path value in - return_unit - - let get_address (index : _ raw_index) = - let open Lwt_result_syntax in - protect @@ fun () -> - let*! store = IStore.main index.repo in - let*! value = IStore.find store path in - return - @@ Option.map - (Data_encoding.Binary.of_bytes_exn Sc_rollup.Address.encoding) - value - - let check_or_set_address (type a) (mode : a mode) (index : a raw_index) - rollup_address = - let open Lwt_result_syntax in - let* saved_address = get_address index in - match saved_address with - | Some saved_address -> - fail_unless Sc_rollup.Address.(rollup_address = saved_address) - @@ Sc_rollup_node_errors.Unexpected_rollup - {rollup_address; saved_address} - | None -> ( - (* Address was never saved, we set it permanently if not in read-only - mode. *) - match mode with - | Store_sigs.Read_only -> return_unit - | Read_write -> set_address index rollup_address) -end - -module Version = struct - type t = V0 - - let version = V0 - - let encoding = - let open Data_encoding in - conv - (fun V0 -> 0) - (function - | 0 -> V0 - | v -> - Format.ksprintf Stdlib.failwith "Unsupported context version %d" v) - int31 - - let path = ["context_version"] - - let set (index : rw_index) = - let open Lwt_result_syntax in - protect @@ fun () -> - let info () = - let date = - Time.(System.now () |> System.to_protocol |> Protocol.to_seconds) - in - IStore.Info.v date - in - let value = Data_encoding.Binary.to_bytes_exn encoding version in - let*! store = IStore.main index.repo in - let*! () = IStore.set_exn ~info store path value in - return_unit - - let get (index : _ index) = - let open Lwt_result_syntax in - protect @@ fun () -> - let*! store = IStore.main index.repo in - let*! value = IStore.find store path in - return @@ Option.map (Data_encoding.Binary.of_bytes_exn encoding) value - - let check (index : _ index) = - let open Lwt_result_syntax in - let* context_version = get index in - match context_version with None | Some V0 -> return_unit - - let check_and_set (index : _ index) = - let open Lwt_result_syntax in - let* context_version = get index in - match context_version with None -> set index | Some V0 -> return_unit -end - -let load : type a. a mode -> string -> a raw_index tzresult Lwt.t = - fun mode path -> - let open Lwt_result_syntax in - let*! index = load mode path in - let+ () = - match mode with - | Read_only -> Version.check index - | Read_write -> Version.check_and_set index - in - index diff --git a/src/proto_alpha/lib_sc_rollup_node/node_context.ml b/src/proto_alpha/lib_sc_rollup_node/node_context.ml index 2f5d3b6b141062b90f4ad12baf6d033683b08ebf..cf29439317bdbe3fedfc764ca0de3c15394d6f0a 100644 --- a/src/proto_alpha/lib_sc_rollup_node/node_context.ml +++ b/src/proto_alpha/lib_sc_rollup_node/node_context.ml @@ -303,6 +303,10 @@ let init (cctxt : Protocol_client_context.full) ~data_dir ?log_kernel_debug_file in let* () = Context.Rollup.check_or_set_address mode context rollup_address in let publisher = Configuration.Operator_purpose_map.find Publish operators in + let rollup_address = + (* Convert to protocol rollup address *) + Sc_rollup_proto_types.Address.of_octez rollup_address + in let* protocol_constants = retrieve_constants cctxt and* lcc = get_last_cemented_commitment cctxt rollup_address and* lpc = diff --git a/src/proto_alpha/lib_sc_rollup_node/sc_rollup_node_errors.ml b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_node_errors.ml index 6f88c4fb3f80c919a8955b1cef30b1d131a106a4..2949749abd34e12b06f4322e5f4299a3a402720c 100644 --- a/src/proto_alpha/lib_sc_rollup_node/sc_rollup_node_errors.ml +++ b/src/proto_alpha/lib_sc_rollup_node/sc_rollup_node_errors.ml @@ -46,12 +46,8 @@ type error += layer1_inbox : Sc_rollup.Inbox.t; inbox : Sc_rollup.Inbox.t; } - | Unexpected_rollup of { - rollup_address : Sc_rollup.Address.t; - saved_address : Sc_rollup.Address.t; - } | Missing_PVM_state of Block_hash.t * Int32.t - | Cannot_checkout_context of Block_hash.t * Sc_rollup_context_hash.t option + | Cannot_checkout_context of Block_hash.t * Smart_rollup_context_hash.t option | No_batcher | No_publisher | Refutation_player_failed_to_start @@ -192,31 +188,6 @@ let () = | _ -> None) (fun (layer1_inbox, inbox) -> Inconsistent_inbox {layer1_inbox; inbox}) ; - register_error_kind - ~id:"sc_rollup.node.unexpected_rollup" - ~title:"Unexpected rollup for rollup node" - ~description:"This rollup node is already set up for another rollup." - ~pp:(fun ppf (rollup_address, saved_address) -> - Format.fprintf - ppf - "This rollup node was already set up for rollup %a, it cannot be run \ - for a different rollup %a." - Sc_rollup.Address.pp - saved_address - Sc_rollup.Address.pp - rollup_address) - `Permanent - Data_encoding.( - obj2 - (req "rollup_address" Sc_rollup.Address.encoding) - (req "saved_address" Sc_rollup.Address.encoding)) - (function - | Unexpected_rollup {rollup_address; saved_address} -> - Some (rollup_address, saved_address) - | _ -> None) - (fun (rollup_address, saved_address) -> - Unexpected_rollup {rollup_address; saved_address}) ; - register_error_kind `Permanent ~id:"internal.missing_pvm_state" @@ -246,14 +217,14 @@ let () = "The context %sfor block %a cannot be checkouted" (Option.fold ~none:"" - ~some:Sc_rollup_context_hash.to_b58check + ~some:Smart_rollup_context_hash.to_b58check context_hash) Block_hash.pp block) Data_encoding.( obj2 (req "block" Block_hash.encoding) - (opt "context" Sc_rollup_context_hash.encoding)) + (opt "context" Smart_rollup_context_hash.encoding)) (function | Cannot_checkout_context (block, context) -> Some (block, context) | _ -> None) diff --git a/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.ml b/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.ml index e4e10ac2334469df8a139f5463d9fd4092d50764..9299b441332c34bb7bc89836491e9d3b7bd60696 100644 --- a/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.ml +++ b/src/proto_alpha/lib_sc_rollup_node/test/helpers/helpers.ml @@ -68,7 +68,7 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = in let* inbox_hash = Node_context.save_inbox node_ctxt inbox in let inbox_witness = Sc_rollup.Inbox.current_witness inbox in - let ctxt = Context.empty node_ctxt.context in + let ctxt = Octez_smart_rollup_node.Context.empty node_ctxt.context in let num_ticks = 0L in let module PVM = (val node_ctxt.pvm) in let initial_tick = Sc_rollup.Tick.initial in @@ -76,7 +76,7 @@ let add_l2_genesis_block (node_ctxt : _ Node_context.t) ~boot_sector = let*! state = PVM.install_boot_sector initial_state boot_sector in let*! genesis_state_hash = PVM.state_hash state in let*! ctxt = PVM.State.set ctxt state in - let*! context_hash = Context.commit ctxt in + let*! context_hash = Octez_smart_rollup_node.Context.commit ctxt in let commitment = Sc_rollup.Commitment.genesis_commitment ~origination_level:node_ctxt.genesis_info.level