diff --git a/CHANGES.rst b/CHANGES.rst index 8bd9ff50346a07195c90912e71d2794569f6faf4..5f3f146ead28c2a74bd1f801b4879487cf715326 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -25,6 +25,9 @@ be documented here either. General ------- +- Add and **experimental** switch to enable the use of the Brassaia context + backend using ``TEZOS_CONTEXT_BACKEND=Brassaia`` environment variable. (MR :gl:`!13054`) + Node ---- diff --git a/devtools/yes_wallet/dune b/devtools/yes_wallet/dune index f2b9ab9bbc840f348aecadf78952daece6664303..a7f2078f5e49c309957bc22e06c82f1e6d84de49 100644 --- a/devtools/yes_wallet/dune +++ b/devtools/yes_wallet/dune @@ -10,7 +10,6 @@ ezjsonm octez-node-config octez-shell-libs.store - octez-shell-libs.shell-context tezos-protocol-018-Proxford.protocol tezos-protocol-019-PtParisB.protocol tezos-protocol-alpha.protocol) diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index f3462fbfaf679cbac3f0feff224e035e0cf31787..e7dbea42e0eda98281f9f371e9c0f49619043ec0 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -2776,6 +2776,7 @@ let octez_context_brassaia_helpers = ] ~conflicts:[Conflicts.checkseum] +(* Should not be used directly in most cases, use context_ops abstraction instead *) let octez_context_memory = octez_lib "tezos-context.memory" @@ -2794,6 +2795,7 @@ let octez_context_memory = ] ~conflicts:[Conflicts.checkseum] +(* Should not be used directly in most cases, use context_ops abstraction instead *) let octez_context_brassaia_memory = octez_lib "tezos-context-brassaia.memory" @@ -2856,6 +2858,7 @@ let octez_context_brassaia_dump = ~path:"src/lib_context_brassaia/dump" ~deps: [octez_base |> open_ ~m:"TzPervasives"; octez_stdlib_unix |> open_; fmt] +(* Should not be used directly in most cases, use context_ops abstraction instead *) let octez_context_disk = octez_lib @@ -2880,6 +2883,7 @@ let octez_context_disk = ] ~conflicts:[Conflicts.checkseum] +(* Should not be used directly in most cases, use context_ops abstraction instead *) let octez_context_brassaia_disk = octez_lib "tezos-context-brassaia.disk" @@ -3447,10 +3451,13 @@ let octez_protocol_environment = octez_protocol_environment_structs; octez_micheline |> open_; octez_context_memory; + octez_context_brassaia_memory; octez_scoru_wasm; octez_event_logging; ] +(* in general this library should not be used directly, context_ops should be + used instead *) let octez_shell_context = octez_shell_lib "shell-context" @@ -3461,6 +3468,17 @@ let octez_shell_context = octez_base |> open_ ~m:"TzPervasives"; octez_protocol_environment; octez_context; + ] + +let octez_brassaia_context = + octez_shell_lib + "brassaia-context" + ~internal_name:"tezos_brassaia_context" + ~path:"src/lib_protocol_environment/brassaia_context" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + octez_protocol_environment; octez_context_brassaia; ] @@ -3500,6 +3518,7 @@ let octez_context_ops = octez_context |> open_; octez_context_brassaia |> open_; octez_shell_context |> open_; + octez_brassaia_context |> open_; ] let _octez_protocol_shell_context_tests = @@ -3676,7 +3695,6 @@ let octez_protocol_updater = octez_micheline |> open_; octez_shell_services |> open_; octez_protocol_environment; - octez_shell_context; octez_protocol_compiler_registerer; octez_protocol_compiler_native; octez_context |> open_; @@ -3697,7 +3715,6 @@ let octez_validation = octez_crypto |> open_; octez_rpc; octez_context_ops |> open_; - octez_shell_context |> open_; octez_shell_services |> open_; octez_protocol_updater |> open_; octez_stdlib_unix |> open_; @@ -3743,7 +3760,6 @@ let octez_store_unix = octez_store_shared |> open_; octez_protocol_environment |> open_; octez_context_ops |> open_; - octez_shell_context; octez_validation |> open_; octez_protocol_updater |> open_; octez_stdlib_unix |> open_; @@ -3845,7 +3861,6 @@ let _octez_store_mocked = octez_base |> open_ ~m:"TzPervasives"; octez_crypto |> open_; octez_shell_services |> open_; - octez_context_memory |> open_; octez_context_ops |> open_; octez_validation |> open_; octez_protocol_environment; @@ -3907,7 +3922,6 @@ let octez_shell = octez_store_shared |> open_; octez_protocol_environment |> open_; octez_context_ops |> open_; - octez_shell_context |> open_; octez_p2p |> open_; octez_stdlib_unix |> open_; octez_shell_services |> open_; @@ -4535,7 +4549,6 @@ let octez_shell_benchmarks = octez_error_monad |> open_; octez_benchmark |> open_; octez_crypto; - octez_shell_context; octez_store; octez_micheline; ] @@ -4978,7 +4991,6 @@ let octez_scoru_wasm_benchmark = octez_base |> open_ ~m:"TzPervasives"; tezt_lib; octez_webassembly_interpreter; - octez_context_memory; octez_scoru_wasm; octez_scoru_wasm_helpers; lwt_unix; @@ -6558,9 +6570,9 @@ let hash = Protocol.hash octez_client_commands |> open_; octez_stdlib |> open_; octez_stdlib_unix |> open_; - octez_shell_context |> open_; + octez_shell_context |> if_ N.(number <= 019) |> open_; octez_context |> open_; - octez_context_memory |> if_ N.(number >= 012); + octez_context_memory |> if_ (N.(number >= 012) && N.(number <= 019)); octez_rpc_http_client_unix |> if_ N.(number >= 011); octez_context_ops |> if_ N.(number >= 011) |> open_; octez_rpc; @@ -7521,7 +7533,6 @@ let yes_wallet_lib = ezjsonm; octez_node_config; octez_store; - octez_shell_context; ] @ protocols) ~all_modules_except:["yes_wallet"] @@ -7838,7 +7849,6 @@ let _octez_node = octez_store_unix_reconstruction |> open_; octez_store_unix_snapshots |> open_; octez_validation |> open_; - octez_shell_context |> open_; octez_workers |> open_; octez_protocol_updater |> open_; cmdliner; @@ -7992,6 +8002,7 @@ let _octez_proxy_server = octez_rpc_http_client_unix; octez_rpc_http_server; octez_shell_services; + (* TODO: use context_ops ~kind:`Disk instead of shell_context *) octez_shell_context; octez_version_value; uri; diff --git a/src/bin_node/dune b/src/bin_node/dune index 2792ff4112543e220f722f68a85f1769fa40562a..2dbf90955d106a276ace756267d81b4ffa2236ab 100644 --- a/src/bin_node/dune +++ b/src/bin_node/dune @@ -23,7 +23,6 @@ octez-shell-libs.store.unix-reconstruction octez-shell-libs.store.unix-snapshots octez-shell-libs.validation - octez-shell-libs.shell-context octez-libs.tezos-workers octez-shell-libs.protocol-updater cmdliner @@ -166,7 +165,6 @@ -open Tezos_store_unix_reconstruction -open Tezos_store_unix_snapshots -open Tezos_validation - -open Tezos_shell_context -open Tezos_workers -open Tezos_protocol_updater -open Tezos_base_p2p_identity_file)) diff --git a/src/lib_protocol_environment/brassaia_context/brassaia_context.ml b/src/lib_protocol_environment/brassaia_context/brassaia_context.ml new file mode 100644 index 0000000000000000000000000000000000000000..d94e7554c3958abf5e254b1213a218c753d48d6b --- /dev/null +++ b/src/lib_protocol_environment/brassaia_context/brassaia_context.ml @@ -0,0 +1,42 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +open Tezos_protocol_environment +open Tezos_context_brassaia +open Context + +module C = struct + include Tezos_context.Context + + let set_protocol = add_protocol +end + +include Register (C) + +let impl_name = "brassaia" + +let checkout index context_hash = + let open Lwt_syntax in + let+ oc = Tezos_context.Context.checkout index context_hash in + Option.map + (fun ctxt -> + Context.make ~ops ~ctxt ~kind:Context ~equality_witness ~impl_name) + oc + +let checkout_exn index context_hash = + let open Lwt_syntax in + let+ ctxt = Tezos_context.Context.checkout_exn index context_hash in + Context.make ~ops ~ctxt ~kind:Context ~equality_witness ~impl_name + +let wrap_disk_context ctxt = + Context.make ~ops ~ctxt ~kind:Context ~equality_witness ~impl_name + +let unwrap_disk_context : t -> Tezos_context.Context.t = function + | Context.Context {ctxt; kind = Context; _} -> ctxt + | Context.Context t -> + err_implementation_mismatch ~expected:impl_name ~got:t.impl_name diff --git a/src/lib_protocol_environment/brassaia_context/brassaia_context.mli b/src/lib_protocol_environment/brassaia_context/brassaia_context.mli new file mode 100644 index 0000000000000000000000000000000000000000..a4e79da1bc145d5006f6f751e1e7dcb3bdcbf3c5 --- /dev/null +++ b/src/lib_protocol_environment/brassaia_context/brassaia_context.mli @@ -0,0 +1,60 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +(** [Brassaia_context] is a persisting recursive map backed by an on-disk Brassaia tree, + i.e. {!Tezos_context.Context} (in [src/lib_context]), used + by nodes. It is the "main" kind of context. It abstracts away + {!Tezos_context.Context}, by hiding the internals, and making it + an instance of the generic {!Protocol_environment.Context.t}. + Other [*_context] modules of {!Tezos_protocol_environment}, i.e. + siblings of this file, are backed by different type of values coming + from {!Tezos_context}. + + [Brassaia_context] is one of the instances of {!Environment_context} along + {!Memory_context} and {!Proxy_context}. All these 3 instances + can implement the same API (i.e. {!Environment_context}), because + this API is highly polymorphic, thanks to {!Environment_context.Context.ops}. + + As such, a {!Brassaia_context} value is an instance of {!Environment_context} + whose [kind] is the one declared in this file. + + Instances of {!Brassaia_context} are harder to obtain than {!Memory_context} ones, because + they require a dedicated folder on disk (the subdirectory [context] + of the node's [--data-dir] when it runs). As such, instances of + {!Brassaia_context} are harder to initialize and use than {!Memory_context}; + making them less amenable to testing for example. *) + +open Tezos_protocol_environment +open Tezos_context_brassaia + +(** The additional kind identifying {!Brassaia_context} values. Used to + detect at runtime when a brassaia context is expected, to disambiguate + from other kinds. *) +type _ Context.kind += Context : Tezos_context.Context.t Context.kind + +(** [checkout index ctxt_hash] checks whether the underlying data on disk + contain an entry for [ctxt_hash]. If so, it is returned; otherwise + [Nothing] is returned. *) +val checkout : + Tezos_context.Context.index -> Context_hash.t -> Context.t option Lwt.t + +(** [checkout_exn index ctxt_hash] checks whether the underlying data on disk + contain an entry for [ctxt_hash]. If so, the data are loaded and returned; + otherwise the exception thrown by {!Tezos_context_brassaia.Context.checkout_exn} + is forwarded. Prefer using {!checkout}. *) +val checkout_exn : + Tezos_context.Context.index -> Context_hash.t -> Context.t Lwt.t + +(** [wrap_disk_context t] creates a brassaia context from an Brassaia on-disk folder + (i.e. {!Tezos_context.Context.t}). This function hereby abstracts away + a value, from the low-level [lib_context] to the higher-level [lib_protocol_environment]. *) +val wrap_disk_context : Tezos_context.Context.t -> Context.t + +(** [unwrap_disk_context t] gives access to the lower-level {!Tezos_context.Context.t} + value underlying a {!Brassaia_context}. *) +val unwrap_disk_context : Context.t -> Tezos_context.Context.t diff --git a/src/lib_protocol_environment/brassaia_context/dune b/src/lib_protocol_environment/brassaia_context/dune new file mode 100644 index 0000000000000000000000000000000000000000..3043f453811b16dc4feb53d55f64a628e109bc49 --- /dev/null +++ b/src/lib_protocol_environment/brassaia_context/dune @@ -0,0 +1,14 @@ +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + +(library + (name tezos_brassaia_context) + (public_name octez-shell-libs.brassaia-context) + (instrumentation (backend bisect_ppx)) + (libraries + octez-libs.base + octez-proto-libs.protocol-environment + octez-libs.tezos-context-brassaia) + (flags + (:standard) + -open Tezos_base.TzPervasives)) diff --git a/src/lib_protocol_environment/brassaia_memory_context.ml b/src/lib_protocol_environment/brassaia_memory_context.ml new file mode 100644 index 0000000000000000000000000000000000000000..9e76f15d9165c5e1611715eda7718b6f8d43053c --- /dev/null +++ b/src/lib_protocol_environment/brassaia_memory_context.ml @@ -0,0 +1,46 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2021-2024 Nomadic Labs *) +(* *) +(*****************************************************************************) +open Tezos_context_brassaia_memory + +module M = struct + include Tezos_context_memory.Context + + let set_protocol = add_protocol + + let fork_test_chain c ~protocol:_ ~expiration:_ = Lwt.return c +end + +open Environment_context + +type t = M.t + +include Environment_context.Register (M) + +let impl_name = "brassaia_memory" + +let project : Context.t -> t = + fun (Context.Context t) -> + match t.kind with + | Context -> t.ctxt + | _ -> + Environment_context.err_implementation_mismatch + ~expected:impl_name + ~got:t.impl_name + +let inject : t -> Context.t = + fun ctxt -> Context.make ~ops ~ctxt ~kind:Context ~equality_witness ~impl_name + +let empty = inject (Tezos_context_memory.Context.make_empty_context ()) + +let encoding : Context.t Data_encoding.t = + let open Data_encoding in + conv project inject M.encoding + +let wrap_memory_context = inject + +let unwrap_memory_context = project diff --git a/src/lib_protocol_environment/brassaia_memory_context.mli b/src/lib_protocol_environment/brassaia_memory_context.mli new file mode 100644 index 0000000000000000000000000000000000000000..cd6da8e35aa530c2c2f265e65afa645c1fc321ce --- /dev/null +++ b/src/lib_protocol_environment/brassaia_memory_context.mli @@ -0,0 +1,66 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +(** [Memory_context] is a recursive map backed by an in-memory Brassaia tree, + i.e. {!Tezos_context_memory.Context} (in [src/lib_context]), used + by the mockup mode and by proof verifiers (i.e. clients + of {!Tezos_context_helpers.Context.Make_tree.Proof}). + It abstracts away {!Tezos_context_memory.Context.t}. + + It is one of the instances of {!Environment_context} along + {!Shell_context} and {!Proxy_context}. All these 3 instances + can implement the same API (i.e. {!Environment_context}), because + this API is highly polymorphic, thanks to {!Environment_context.Context.ops}. + + As such, a {!Memory_context} value is an instance of {!Environment_context} + whose {!Environment_context.Context.kind} is the one declared below in this + file, i.e. {!extension-Context}. + + Instances of {!t} are easier to obtain than {!Shell_context} (which + are used by nodes), because they don't require access to a disk: they + live completely in memory. That is why they are ideal for testing. *) +open Tezos_context_brassaia_memory + +open Environment_context + +(** The type of the context backing {!Memory_context}. Main use is + the parameterization of {!Environment_context.Context.kind} below, + as well as the instantiation of the {!S} signature below (the module type + of {!M}). *) +type t = Tezos_context_memory.Context.t + +(** The additional kind identifying {!Memory_context} values. Used to + detect at runtime when a memory context is expected, to disambiguate + from other kinds. *) +type _ Context.kind += Context : t Context.kind + +(** [empty] creates a pristine memory context: a {!Protocol_environment.Context.t} + value whose kind indicates that it is a memory context. See {!wrap_memory_context} + for an alternative constructor. *) +val empty : Context.t + +(** [encoding] is an appropriate encoding for {!Environment_context.Context.t} values + whose kind is [Memory_context]. This is used by the mockup for storing + its state on disk. This is unique to [Memory_context]: + + - [Shell_context] is backed by an Irmin on-disk storage and so doesn't need + its own serialization mechanism. + - [Proxy_context] doesn't need to be serializable. *) +val encoding : Context.t Data_encoding.t + +(** [M] is the [Memory_context] specific instance of {!Environment_context_intf.S} *) +module M : S with type t = t + +(** [wrap_memory_context t] creates a memory context from an Irmin in-memory tree: + in this signature, [t] comes from {!Tezos_context_memory.Context} + (in [src/lib_context]. See {!empty} for an alternative constructor. *) +val wrap_memory_context : t -> Context.t + +(** [unwrap_memory_context ctxt] returns the {!Tezos_context_memory.Context.t} + underlying [ctxt]. *) +val unwrap_memory_context : Context.t -> t diff --git a/src/lib_protocol_environment/context_ops/context_ops.ml b/src/lib_protocol_environment/context_ops/context_ops.ml index 6a0cc31ce5621fe93a996d6f81f7e498c5f628c5..9f03289b6294f0a1cd5a66880193450a02fab1d9 100644 --- a/src/lib_protocol_environment/context_ops/context_ops.ml +++ b/src/lib_protocol_environment/context_ops/context_ops.ml @@ -1,25 +1,7 @@ (*****************************************************************************) (* *) -(* 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. *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2021-2024 Nomadic Labs *) (* *) (*****************************************************************************) @@ -27,6 +9,13 @@ module Environment_context = Tezos_protocol_environment.Context module Memory_context = Tezos_protocol_environment.Memory_context +module Brassaia = Tezos_context_brassaia.Tezos_context.Context + +module Brassaia_memory = + Tezos_context_brassaia_memory.Tezos_context_memory.Context + +module Brassaia_memory_context = + Tezos_protocol_environment.Brassaia_memory_context let err_implementation_mismatch = Tezos_protocol_environment.err_implementation_mismatch @@ -35,9 +24,18 @@ let err_implementation_mismatch = type index = | Disk_index of Context.index | Memory_index of Tezos_context_memory.Context.index + | Brassaia_index of Brassaia.index + | Brassaia_memory_index of Brassaia_memory.index open Environment_context +type t = Environment_context.t + +let err_impl_mismatch ~got = + err_implementation_mismatch + ~expected:"shell, memory, brassaia or brassaia_memory" + ~got + let init ~kind ?patch_context ?readonly ?index_log_size s = let open Lwt_syntax in match kind with @@ -57,6 +55,32 @@ let init ~kind ?patch_context ?readonly ?index_log_size s = Tezos_context_memory.Context.init ?readonly ?index_log_size s in Memory_index index + | `Brassaia -> + let patch_context = + Option.map + (fun f context -> + let open Lwt_result_syntax in + let* context = f (Brassaia_context.wrap_disk_context context) in + return @@ Brassaia_context.unwrap_disk_context context) + patch_context + in + let+ index = Brassaia.init ?patch_context ?readonly ?index_log_size s in + Brassaia_index index + | `Brassaia_memory -> + let+ index = Brassaia_memory.init ?readonly ?index_log_size s in + Brassaia_memory_index index + +(* Wrapper over init that uses an environment variable ('TEZOS_CONTEXT_BACKEND') + to select the backend between Memory|Brassaia_memory and Disk|Brassaia *) +let init ~kind = + let backend_variable = "TEZOS_CONTEXT_BACKEND" in + match Sys.getenv_opt backend_variable with + | Some "Brassaia" -> ( + match kind with + | `Disk -> init ~kind:`Brassaia + | `Memory -> init ~kind:`Brassaia_memory + | _ -> init ~kind) + | _ -> init ~kind let index (context : Environment_context.t) = match context with @@ -64,32 +88,40 @@ let index (context : Environment_context.t) = Disk_index (Context.index ctxt) | Context {kind = Memory_context.Context; ctxt; _} -> Memory_index (Tezos_context_memory.Context.index ctxt) - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + Brassaia_index (Brassaia.index ctxt) + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory_index (Brassaia_memory.index ctxt) + | Context t -> err_impl_mismatch ~got:t.impl_name let mem (context : Environment_context.t) key = match context with | Context {kind = Shell_context.Context; ctxt; _} -> Context.mem ctxt key | Context {kind = Memory_context.Context; ctxt; _} -> Tezos_context_memory.Context.mem ctxt key - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> Brassaia.mem ctxt key + | Context t -> err_impl_mismatch ~got:t.impl_name let mem_tree (context : Environment_context.t) key = match context with | Context {kind = Shell_context.Context; ctxt; _} -> Context.mem_tree ctxt key | Context {kind = Memory_context.Context; ctxt; _} -> Tezos_context_memory.Context.mem_tree ctxt key - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + Brassaia.mem_tree ctxt key + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory.mem_tree ctxt key + | Context t -> err_impl_mismatch ~got:t.impl_name let find (context : Environment_context.t) key = match context with | Context {kind = Shell_context.Context; ctxt; _} -> Context.find ctxt key | Context {kind = Memory_context.Context; ctxt; _} -> Tezos_context_memory.Context.find ctxt key - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> Brassaia.find ctxt key + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory.find ctxt key + | Context t -> err_impl_mismatch ~got:t.impl_name let add (context : Environment_context.t) key data = let open Lwt_syntax in @@ -100,8 +132,13 @@ let add (context : Environment_context.t) key data = | Context {kind = Memory_context.Context; ctxt; _} -> let+ ctxt = Tezos_context_memory.Context.add ctxt key data in Memory_context.wrap_memory_context ctxt - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + let+ ctxt = Brassaia.add ctxt key data in + Brassaia_context.wrap_disk_context ctxt + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + let+ ctxt = Brassaia_memory.add ctxt key data in + Brassaia_memory_context.wrap_memory_context ctxt + | Context t -> err_impl_mismatch ~got:t.impl_name let fold_value ?depth (context : Environment_context.t) key ~order ~init ~f = match context with @@ -114,8 +151,15 @@ let fold_value ?depth (context : Environment_context.t) key ~order ~init ~f = Context.fold ?depth ctxt key ~order ~init ~f:(fun k tree acc -> let v () = Context.Tree.to_value tree in f k v acc) - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + Brassaia.fold ?depth ctxt key ~order ~init ~f:(fun k tree acc -> + let v () = Brassaia.Tree.to_value tree in + f k v acc) + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory.fold ?depth ctxt key ~order ~init ~f:(fun k tree acc -> + let v () = Brassaia_memory.Tree.to_value tree in + f k v acc) + | Context t -> err_impl_mismatch ~got:t.impl_name let add_protocol (context : Environment_context.t) proto_hash = let open Lwt_syntax in @@ -126,16 +170,24 @@ let add_protocol (context : Environment_context.t) proto_hash = | Context {kind = Memory_context.Context; ctxt; _} -> let+ ctxt = Tezos_context_memory.Context.add_protocol ctxt proto_hash in Memory_context.wrap_memory_context ctxt - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + let+ ctxt = Brassaia.add_protocol ctxt proto_hash in + Brassaia_context.wrap_disk_context ctxt + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + let+ ctxt = Brassaia_memory.add_protocol ctxt proto_hash in + Brassaia_memory_context.wrap_memory_context ctxt + | Context t -> err_impl_mismatch ~got:t.impl_name let get_protocol (context : Environment_context.t) = match context with | Context {kind = Shell_context.Context; ctxt; _} -> Context.get_protocol ctxt | Context {kind = Memory_context.Context; ctxt; _} -> Tezos_context_memory.Context.get_protocol ctxt - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + Brassaia.get_protocol ctxt + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory.get_protocol ctxt + | Context t -> err_impl_mismatch ~got:t.impl_name let add_predecessor_block_metadata_hash (context : Environment_context.t) hash = let open Lwt_syntax in @@ -150,8 +202,15 @@ let add_predecessor_block_metadata_hash (context : Environment_context.t) hash = hash in Memory_context.wrap_memory_context ctxt - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + let+ ctxt = Brassaia.add_predecessor_block_metadata_hash ctxt hash in + Brassaia_context.wrap_disk_context ctxt + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + let+ ctxt = + Brassaia_memory.add_predecessor_block_metadata_hash ctxt hash + in + Brassaia_memory_context.wrap_memory_context ctxt + | Context t -> err_impl_mismatch ~got:t.impl_name let add_predecessor_ops_metadata_hash (context : Environment_context.t) hash = let open Lwt_syntax in @@ -164,8 +223,13 @@ let add_predecessor_ops_metadata_hash (context : Environment_context.t) hash = Tezos_context_memory.Context.add_predecessor_ops_metadata_hash ctxt hash in Memory_context.wrap_memory_context ctxt - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + let+ ctxt = Brassaia.add_predecessor_ops_metadata_hash ctxt hash in + Brassaia_context.wrap_disk_context ctxt + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + let+ ctxt = Brassaia_memory.add_predecessor_ops_metadata_hash ctxt hash in + Brassaia_memory_context.wrap_memory_context ctxt + | Context t -> err_impl_mismatch ~got:t.impl_name let hash ~time ?message (context : Environment_context.t) = match context with @@ -173,8 +237,11 @@ let hash ~time ?message (context : Environment_context.t) = Context.hash ~time ?message ctxt | Context {kind = Memory_context.Context; ctxt; _} -> Tezos_context_memory.Context.hash ~time ?message ctxt - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + Brassaia.hash ~time ?message ctxt + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory.hash ~time ?message ctxt + | Context t -> err_impl_mismatch ~got:t.impl_name let get_test_chain (context : Environment_context.t) = match context with @@ -182,8 +249,11 @@ let get_test_chain (context : Environment_context.t) = Context.get_test_chain ctxt | Context {kind = Memory_context.Context; _} -> Lwt.return Test_chain_status.Not_running - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + Brassaia.get_test_chain ctxt + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory.get_test_chain ctxt + | Context t -> err_impl_mismatch ~got:t.impl_name let add_test_chain (context : Environment_context.t) status = let open Lwt_syntax in @@ -194,8 +264,13 @@ let add_test_chain (context : Environment_context.t) status = | Context {kind = Memory_context.Context; ctxt; _} -> let+ ctxt = Tezos_context_memory.Context.add_test_chain ctxt status in Memory_context.wrap_memory_context ctxt - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + let+ ctxt = Brassaia.add_test_chain ctxt status in + Brassaia_context.wrap_disk_context ctxt + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + let+ ctxt = Brassaia_memory.add_test_chain ctxt status in + Brassaia_memory_context.wrap_memory_context ctxt + | Context t -> err_impl_mismatch ~got:t.impl_name let fork_test_chain (context : Environment_context.t) ~protocol ~expiration = let open Lwt_syntax in @@ -208,8 +283,13 @@ let fork_test_chain (context : Environment_context.t) ~protocol ~expiration = Tezos_context_memory.Context.fork_test_chain ctxt ~protocol ~expiration in Memory_context.wrap_memory_context ctxt - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + let+ ctxt = Brassaia.fork_test_chain ctxt ~protocol ~expiration in + Brassaia_context.wrap_disk_context ctxt + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + let+ ctxt = Brassaia_memory.fork_test_chain ctxt ~protocol ~expiration in + Brassaia_memory_context.wrap_memory_context ctxt + | Context t -> err_impl_mismatch ~got:t.impl_name let commit ~time ?message (context : Environment_context.t) = match context with @@ -217,32 +297,45 @@ let commit ~time ?message (context : Environment_context.t) = Context.commit ~time ?message ctxt | Context {kind = Memory_context.Context; ctxt; _} -> Tezos_context_memory.Context.commit ~time ?message ctxt - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + Brassaia.commit ~time ?message ctxt + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory.commit ~time ?message ctxt + | Context t -> err_impl_mismatch ~got:t.impl_name let gc context_index context_hash = match context_index with | Disk_index index -> Context.gc index context_hash | Memory_index index -> Tezos_context_memory.Context.gc index context_hash + | Brassaia_index index -> Brassaia.gc index context_hash + | Brassaia_memory_index index -> Brassaia_memory.gc index context_hash let wait_gc_completion context_index = match context_index with | Disk_index index -> Context.wait_gc_completion index | Memory_index index -> Tezos_context_memory.Context.wait_gc_completion index + | Brassaia_index index -> Brassaia.wait_gc_completion index + | Brassaia_memory_index index -> Brassaia_memory.wait_gc_completion index let is_gc_allowed context_index = match context_index with | Disk_index index -> Context.is_gc_allowed index | Memory_index index -> Tezos_context_memory.Context.is_gc_allowed index + | Brassaia_index index -> Brassaia.is_gc_allowed index + | Brassaia_memory_index index -> Brassaia_memory.is_gc_allowed index let split context_index = match context_index with | Disk_index index -> Context.split index | Memory_index index -> Tezos_context_memory.Context.split index + | Brassaia_index index -> Brassaia.split index + | Brassaia_memory_index index -> Brassaia_memory.split index let sync = function | Disk_index index -> Context.sync index | Memory_index index -> Tezos_context_memory.Context.sync index + | Brassaia_index index -> Brassaia.sync index + | Brassaia_memory_index index -> Brassaia_memory.sync index let commit_test_chain_genesis (context : Environment_context.t) block_header = match context with @@ -250,8 +343,11 @@ let commit_test_chain_genesis (context : Environment_context.t) block_header = Context.commit_test_chain_genesis ctxt block_header | Context {kind = Memory_context.Context; ctxt; _} -> Tezos_context_memory.Context.commit_test_chain_genesis ctxt block_header - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + Brassaia.commit_test_chain_genesis ctxt block_header + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory.commit_test_chain_genesis ctxt block_header + | Context t -> err_impl_mismatch ~got:t.impl_name let compute_testchain_genesis (context : Environment_context.t) block_hash = match context with @@ -259,8 +355,11 @@ let compute_testchain_genesis (context : Environment_context.t) block_hash = Context.compute_testchain_genesis block_hash | Context {kind = Memory_context.Context; _} -> Tezos_context_memory.Context.compute_testchain_genesis block_hash - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; _} -> + Brassaia.compute_testchain_genesis block_hash + | Context {kind = Brassaia_memory_context.Context; _} -> + Brassaia_memory.compute_testchain_genesis block_hash + | Context t -> err_impl_mismatch ~got:t.impl_name let merkle_tree (context : Environment_context.t) leaf_kind path = match context with @@ -268,8 +367,11 @@ let merkle_tree (context : Environment_context.t) leaf_kind path = Context.merkle_tree ctxt leaf_kind path | Context {kind = Memory_context.Context; ctxt; _} -> Tezos_context_memory.Context.merkle_tree ctxt leaf_kind path - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + Brassaia.merkle_tree ctxt leaf_kind path + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory.merkle_tree ctxt leaf_kind path + | Context t -> err_impl_mismatch ~got:t.impl_name let merkle_tree_v2 (context : Environment_context.t) leaf_kind path = match context with @@ -277,8 +379,11 @@ let merkle_tree_v2 (context : Environment_context.t) leaf_kind path = Context.merkle_tree_v2 ctxt leaf_kind path | Context {kind = Memory_context.Context; ctxt; _} -> Tezos_context_memory.Context.merkle_tree_v2 ctxt leaf_kind path - | Context t -> - err_implementation_mismatch ~expected:"shell or memory" ~got:t.impl_name + | Context {kind = Brassaia_context.Context; ctxt; _} -> + Brassaia.merkle_tree_v2 ctxt leaf_kind path + | Context {kind = Brassaia_memory_context.Context; ctxt; _} -> + Brassaia_memory.merkle_tree_v2 ctxt leaf_kind path + | Context t -> err_impl_mismatch ~got:t.impl_name let commit_genesis context_index ~chain_id ~time ~protocol = match context_index with @@ -289,6 +394,10 @@ let commit_genesis context_index ~chain_id ~time ~protocol = ~chain_id ~time ~protocol + | Brassaia_index index -> + Brassaia.commit_genesis index ~chain_id ~time ~protocol + | Brassaia_memory_index index -> + Brassaia_memory.commit_genesis index ~chain_id ~time ~protocol let checkout context_index context_hash = let open Lwt_syntax in @@ -299,6 +408,12 @@ let checkout context_index context_hash = | Memory_index index -> let+ ctxt = Tezos_context_memory.Context.checkout index context_hash in Option.map Memory_context.wrap_memory_context ctxt + | Brassaia_index index -> + let+ ctxt = Brassaia.checkout index context_hash in + Option.map Brassaia_context.wrap_disk_context ctxt + | Brassaia_memory_index index -> + let+ ctxt = Brassaia_memory.checkout index context_hash in + Option.map Brassaia_memory_context.wrap_memory_context ctxt let checkout_exn context_index context_hash = let open Lwt_syntax in @@ -311,16 +426,26 @@ let checkout_exn context_index context_hash = Tezos_context_memory.Context.checkout_exn index context_hash in Memory_context.wrap_memory_context ctxt + | Brassaia_index index -> + let+ ctxt = Brassaia.checkout_exn index context_hash in + Brassaia_context.wrap_disk_context ctxt + | Brassaia_memory_index index -> + let+ ctxt = Brassaia_memory.checkout_exn index context_hash in + Brassaia_memory_context.wrap_memory_context ctxt let exists context_index context_hash = match context_index with | Disk_index index -> Context.exists index context_hash | Memory_index index -> Tezos_context_memory.Context.exists index context_hash + | Brassaia_index index -> Brassaia.exists index context_hash + | Brassaia_memory_index index -> Brassaia_memory.exists index context_hash let close context_index = match context_index with | Disk_index index -> Context.close index | Memory_index index -> Tezos_context_memory.Context.close index + | Brassaia_index index -> Brassaia.close index + | Brassaia_memory_index index -> Brassaia_memory.close index let compute_testchain_chain_id (context : Environment_context.t) block_hash = match context with @@ -328,7 +453,8 @@ let compute_testchain_chain_id (context : Environment_context.t) block_hash = Context.compute_testchain_chain_id block_hash | Context {kind = Memory_context.Context; _} -> Tezos_context_memory.Context.compute_testchain_chain_id block_hash - | Context t -> - err_implementation_mismatch - ~expected:"shell, brassaia or memory" - ~got:t.impl_name + | Context {kind = Brassaia_context.Context; _} -> + Brassaia.compute_testchain_chain_id block_hash + | Context {kind = Brassaia_memory_context.Context; _} -> + Brassaia_memory.compute_testchain_chain_id block_hash + | Context t -> err_impl_mismatch ~got:t.impl_name diff --git a/src/lib_protocol_environment/context_ops/context_ops.mli b/src/lib_protocol_environment/context_ops/context_ops.mli new file mode 100644 index 0000000000000000000000000000000000000000..d316594b640309e8d29000dfcbea6b049c2319c9 --- /dev/null +++ b/src/lib_protocol_environment/context_ops/context_ops.mli @@ -0,0 +1,192 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2024 Nomadic Labs *) +(* *) +(*****************************************************************************) + +module Environment_context = Tezos_protocol_environment.Context + +val err_implementation_mismatch : expected:string -> got:string -> 'a + +type t = Environment_context.t + +(** Values of type [index] are used to [checkout] contexts specified by their hash. *) +type index + +(** [init] uses an environment variable ('TEZOS_CONTEXT_BACKEND') + to select the `Disk backend between `Shell and `Brassaia *) +val init : + kind:[< `Brassaia | `Brassaia_memory | `Disk | `Memory > `Disk `Memory] -> + ?patch_context: + (Tezos_protocol_environment.Context.t -> + (Tezos_protocol_environment.Context.t, tztrace) result Lwt.t) -> + ?readonly:bool -> + ?index_log_size:int -> + string -> + index Lwt.t + +val index : t -> index + +(** [mem t k] is an Lwt promise that resolves to [true] iff [k] is bound + to a value in [t]. *) +val mem : t -> Context.key -> bool Lwt.t + +(** [mem_tree t k] is like {!mem} but for trees. *) +val mem_tree : t -> Context.key -> bool Lwt.t + +(** [find t k] is an Lwt promise that resolves to [Some v] if [k] is + bound to the value [v] in [t] and [None] otherwise. *) +val find : t -> Context.key -> Context.value option Lwt.t + +(** [add t k v] is an Lwt promise that resolves to [c] such that: + + - [k] is bound to [v] in [c]; + - and [c] is similar to [t] otherwise. + + If [k] was already bound in [t] to a value that is physically equal + to [v], the result of the function is a promise that resolves to + [t]. Otherwise, the previous binding of [k] in [t] disappears. *) +val add : + t -> + Context.key -> + Context.value -> + Tezos_protocol_environment.Context.t Lwt.t + +(** [fold ?depth t root ~order ~init ~f] recursively folds over the trees + and values of [t]. The [f] callbacks are called with a key relative + to [root]. [f] is never called with an empty key for values; i.e., + folding over a value is a no-op. + + The depth is 0-indexed. If [depth] is set (by default it is not), then [f] + is only called when the conditions described by the parameter is true: + + - [Eq d] folds over nodes and values of depth exactly [d]. + - [Lt d] folds over nodes and values of depth strictly less than [d]. + - [Le d] folds over nodes and values of depth less than or equal to [d]. + - [Gt d] folds over nodes and values of depth strictly more than [d]. + - [Ge d] folds over nodes and values of depth more than or equal to [d]. + + If [order] is [`Sorted] (the default), the elements are traversed in + lexicographic order of their keys. For large nodes, it is memory-consuming, + use [`Undefined] for a more memory efficient [fold]. *) +val fold_value : + ?depth:Tezos_context_sigs__Context.depth -> + t -> + Context.key -> + order:[`Sorted | `Undefined] -> + init:'a -> + f:(Context.key -> (unit -> Context.value option Lwt.t) -> 'a -> 'a Lwt.t) -> + 'a Lwt.t + +val add_protocol : + t -> Protocol_hash.t -> Tezos_protocol_environment.Context.t Lwt.t + +val get_protocol : t -> Protocol_hash.t Lwt.t + +val add_predecessor_block_metadata_hash : + t -> Block_metadata_hash.t -> Tezos_protocol_environment.Context.t Lwt.t + +val add_predecessor_ops_metadata_hash : + t -> + Operation_metadata_list_list_hash.t -> + Tezos_protocol_environment.Context.t Lwt.t + +val hash : time:Time.Protocol.t -> ?message:string -> t -> Context_hash.t + +val get_test_chain : t -> Test_chain_status.t Lwt.t + +val add_test_chain : + t -> Test_chain_status.t -> Tezos_protocol_environment.Context.t Lwt.t + +val fork_test_chain : + t -> + protocol:Protocol_hash.t -> + expiration:Time.Protocol.t -> + Tezos_protocol_environment.Context.t Lwt.t + +val commit : + time:Time.Protocol.t -> ?message:string -> t -> Context_hash.t Lwt.t + +(** [gc index commit_hash] removes from disk all the data older than + the [commit_hash]. Operations needing to checkout commits + greater or equal to [commit_hash] will continue to work. Calling + [checkout h'] on GC-ed commits will return [None]. + + From the irmin point of view, a successful gc call on a + [commit_hash] will result in a new prefix file containing that + [commit_hash] as a root commit. This prefix file is considered + as standalone as all the data referenced by that commit is + contained in that file. *) +val gc : index -> Context_hash.t -> unit Lwt.t + +(** [wait_gc_completion index] will return a blocking thread if an + Irmin GC is currently ongoing. + + {b Warning}: this currently only applies to GC started in the + Irmin instance referenced as [index]; other opened instances + will always return instantly. *) +val wait_gc_completion : index -> unit Lwt.t + +(** [is_gc_allowed index] returns whether or not it is possible to + run a GC on the given context tree. If false is returned, it + means that the context was run, at least once, with the indexing + strategy mode "always", which is not suitable for GC.*) +val is_gc_allowed : index -> bool + +(** [split index] creates a new suffix file, also called "chunk", + into the irmin's file hierarchy. + + To be optimal, the split function is expected to be called + directly after committing, to the context, a commit (of hash + [context_hash]) that will be a future candidate of a GC + target. Thus, the commit [commit_hash] is the last commit stored + on a given chunk. The GC called on that [commit_hash] will be + able to extract that [commit_hash] into a new prefix file, and + then, drop the whole chunk. + + If the last commit of a chunk appears not to be the candidate of + a future GC, it may result in keeping chunks containing + partially needed data. This is not an issue, but it should be + avoided to prevent storing unnecessary data and thus, to + minimize the disk footprint. *) +val split : index -> unit Lwt.t + +(** Sync the context with disk. Only useful for read-only instances. + Does not fail when the context is not in read-only mode. *) +val sync : index -> unit Lwt.t + +val commit_test_chain_genesis : t -> Block_header.t -> Block_header.t Lwt.t + +val compute_testchain_genesis : t -> Block_hash.t -> Block_hash.t + +val merkle_tree : + t -> + Tezos_context_sigs__Context.Proof_types.merkle_leaf_kind -> + Context.key -> + Tezos_context_sigs__Context.Proof_types.merkle_tree Lwt.t + +val merkle_tree_v2 : + t -> + Tezos_context_sigs__Context.Proof_types.merkle_leaf_kind -> + Context.key -> + Context.Proof.tree Context.Proof.t Lwt.t + +val commit_genesis : + index -> + chain_id:Chain_id.t -> + time:Time.Protocol.t -> + protocol:Protocol_hash.t -> + Context_hash.t tzresult Lwt.t + +val checkout : + index -> Context_hash.t -> Tezos_protocol_environment.Context.t option Lwt.t + +val checkout_exn : + index -> Context_hash.t -> Tezos_protocol_environment.Context.t Lwt.t + +val exists : index -> Context_hash.t -> bool Lwt.t + +val close : index -> unit Lwt.t + +val compute_testchain_chain_id : t -> Block_hash.t -> Chain_id.t diff --git a/src/lib_protocol_environment/context_ops/dune b/src/lib_protocol_environment/context_ops/dune index 558cc950482ace6fef4a6f21a7de2d57361fd0f0..3be71adfc1b9273a65332e6d26cd2b12bdc0784e 100644 --- a/src/lib_protocol_environment/context_ops/dune +++ b/src/lib_protocol_environment/context_ops/dune @@ -11,11 +11,13 @@ octez-proto-libs.protocol-environment octez-libs.tezos-context octez-libs.tezos-context-brassaia - octez-shell-libs.shell-context) + octez-shell-libs.shell-context + octez-shell-libs.brassaia-context) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_error_monad -open Tezos_context -open Tezos_context_brassaia - -open Tezos_shell_context)) + -open Tezos_shell_context + -open Tezos_brassaia_context)) diff --git a/src/lib_protocol_environment/dune b/src/lib_protocol_environment/dune index 9faa82f4a53f571c5c24b2d381f8e5f466040a54..10089f49197ea02511d14fd14befaaedc96c145e 100644 --- a/src/lib_protocol_environment/dune +++ b/src/lib_protocol_environment/dune @@ -20,6 +20,7 @@ octez-proto-libs.protocol-environment.structs octez-libs.micheline octez-libs.tezos-context.memory + octez-libs.tezos-context-brassaia.memory octez-l2-libs.scoru-wasm octez-libs.event-logging) (flags diff --git a/src/lib_protocol_environment/shell_context/dune b/src/lib_protocol_environment/shell_context/dune index 4ad21abecaf4abd24366829cb6d8bda2c05a9e33..8dd2ce73b84bc464aa7354832352ec8acc017a4e 100644 --- a/src/lib_protocol_environment/shell_context/dune +++ b/src/lib_protocol_environment/shell_context/dune @@ -8,8 +8,7 @@ (libraries octez-libs.base octez-proto-libs.protocol-environment - octez-libs.tezos-context - octez-libs.tezos-context-brassaia) + octez-libs.tezos-context) (flags (:standard) -open Tezos_base.TzPervasives)) diff --git a/src/lib_protocol_environment/tezos_protocol_environment.ml b/src/lib_protocol_environment/tezos_protocol_environment.ml index 05ff7a5dbd9d2e4ae873040896d58317083f10c5..1610e8087909877a04ffc57c94a1a9ab2987961f 100644 --- a/src/lib_protocol_environment/tezos_protocol_environment.ml +++ b/src/lib_protocol_environment/tezos_protocol_environment.ml @@ -64,6 +64,7 @@ module V11 = Environment_V11 module V12 = Environment_V12 module V13 = Environment_V13 module Memory_context = Memory_context +module Brassaia_memory_context = Brassaia_memory_context module Proxy_context = Proxy_context module Proxy_delegate = Proxy_delegate diff --git a/src/lib_protocol_updater/dune b/src/lib_protocol_updater/dune index 9abeb5553645c096ebca3d97e022aa4489420f6a..ce9ec02cadfee5f7533cdaf970cfd76694da0822 100644 --- a/src/lib_protocol_updater/dune +++ b/src/lib_protocol_updater/dune @@ -11,7 +11,6 @@ octez-libs.micheline octez-shell-libs.shell-services octez-proto-libs.protocol-environment - octez-shell-libs.shell-context octez-protocol-compiler.registerer octez-protocol-compiler.native octez-libs.tezos-context diff --git a/src/lib_scoru_wasm/bench/dune b/src/lib_scoru_wasm/bench/dune index 312676802b30fb207dc2b592a33166bdb9da51e8..77cd511ccbb7e6f11b96eccde196c5afc825ace7 100644 --- a/src/lib_scoru_wasm/bench/dune +++ b/src/lib_scoru_wasm/bench/dune @@ -9,7 +9,6 @@ octez-libs.base tezt octez-l2-libs.webassembly-interpreter - octez-libs.tezos-context.memory octez-l2-libs.scoru-wasm octez-l2-libs.scoru-wasm-helpers lwt.unix) diff --git a/src/lib_shell/dune b/src/lib_shell/dune index ea0dad8abaefe4d9bd734f84fba2a279ce3588e9..2af271ee3877b354b92c5e8f84c02f467fe3f0ee 100644 --- a/src/lib_shell/dune +++ b/src/lib_shell/dune @@ -16,7 +16,6 @@ octez-shell-libs.store.shared octez-proto-libs.protocol-environment octez-shell-libs.context-ops - octez-shell-libs.shell-context octez-shell-libs.p2p octez-libs.stdlib-unix octez-shell-libs.shell-services @@ -39,7 +38,6 @@ -open Tezos_store_shared -open Tezos_protocol_environment -open Tezos_context_ops - -open Tezos_shell_context -open Tezos_p2p -open Tezos_stdlib_unix -open Tezos_shell_services diff --git a/src/lib_shell/index.mld b/src/lib_shell/index.mld index d0902273e972c7427ca4642954ff48a8a292d4a0..8b3411194b8f914bb5fc2b3b2ffbeeb848d70aa8 100644 --- a/src/lib_shell/index.mld +++ b/src/lib_shell/index.mld @@ -5,6 +5,7 @@ This is a package containing some libraries used by the shell of Octez. It contains the following libraries: - {{!module-Mocked}Mocked} +- {{!module-Tezos_brassaia_context}Tezos_brassaia_context} - {{!module-Tezos_client_base}Tezos_client_base}: Tezos: common helpers for `octez-client` - {{!module-Tezos_client_base_unix}Tezos_client_base_unix}: Tezos: common helpers for `octez-client` (unix-specific fragment) - {{!module-Tezos_client_commands}Tezos_client_commands}: Tezos: protocol agnostic commands for `octez-client` diff --git a/src/lib_shell_benchmarks/dune b/src/lib_shell_benchmarks/dune index 6cca87eaf91bc9d0b9a1ad0ebabb4b47f8ed65bd..15d2edcc2eb9a325cbb8dfac287190450af1bafb 100644 --- a/src/lib_shell_benchmarks/dune +++ b/src/lib_shell_benchmarks/dune @@ -11,7 +11,6 @@ octez-libs.error-monad tezos-benchmark octez-libs.crypto - octez-shell-libs.shell-context octez-shell-libs.store octez-libs.micheline) (library_flags (:standard -linkall)) diff --git a/src/lib_store/mocked/dune b/src/lib_store/mocked/dune index 6fb87b39a0eb20060401710e69f83e27ba4ac770..6fadae98a4fddfb61bbad42ddf18217004e5ab8d 100644 --- a/src/lib_store/mocked/dune +++ b/src/lib_store/mocked/dune @@ -10,7 +10,6 @@ octez-libs.base octez-libs.crypto octez-shell-libs.shell-services - octez-libs.tezos-context.memory octez-shell-libs.context-ops octez-shell-libs.validation octez-proto-libs.protocol-environment @@ -20,7 +19,6 @@ -open Tezos_base.TzPervasives -open Tezos_crypto -open Tezos_shell_services - -open Tezos_context_memory -open Tezos_context_ops -open Tezos_validation -open Tezos_store_shared) diff --git a/src/lib_store/mocked/store.ml b/src/lib_store/mocked/store.ml index 16e58846a42ce58f3e7bdaaa915f3ba01746b2f0..1772ae3438a063981d9ad84ff2f4757e3f00a24b 100644 --- a/src/lib_store/mocked/store.ml +++ b/src/lib_store/mocked/store.ml @@ -1832,32 +1832,26 @@ let init ?patch_context ?commit_genesis ?history_mode ?(readonly = false) "init: already initialized context in %s" context_dir ; context_dirs := context_dir :: !context_dirs ; - let patch_context = - Option.map - (fun f ctxt -> - let ctxt = - Tezos_protocol_environment.Memory_context.wrap_memory_context ctxt - in - let+ ctxt = f ctxt in - Tezos_protocol_environment.Memory_context.unwrap_memory_context ctxt) - patch_context - in + let store_dir = Naming.store_dir ~dir_path:store_dir in let chain_id = Chain_id.of_block_hash genesis.Genesis.block in let*! context_index, commit_genesis = - let open Tezos_context_memory in match commit_genesis with | Some commit_genesis -> let*! context_index = - Context.init ~readonly:true ?patch_context context_dir + Context_ops.init + ~kind:`Memory + ~readonly:true + ?patch_context + context_dir in Lwt.return (context_index, commit_genesis) | None -> let*! context_index = - Context.init ~readonly ?patch_context context_dir + Context_ops.init ~kind:`Memory ~readonly ?patch_context context_dir in let commit_genesis ~chain_id = - Context.commit_genesis + Context_ops.commit_genesis context_index ~chain_id ~time:genesis.time @@ -1879,7 +1873,7 @@ let init ?patch_context ?commit_genesis ?history_mode ?(readonly = false) create_store ?block_cache_limit store_dir - ~context_index:(Context_ops.Memory_index context_index) + ~context_index ~chain_id ~genesis ~genesis_context diff --git a/src/lib_store/unix/dune b/src/lib_store/unix/dune index 54d1d733a0f78f08d49e2523e4feccc011644101..467289b25a7fdc637c7950d140cd0a73861fa2d9 100644 --- a/src/lib_store/unix/dune +++ b/src/lib_store/unix/dune @@ -13,7 +13,6 @@ octez-shell-libs.store.shared octez-proto-libs.protocol-environment octez-shell-libs.context-ops - octez-shell-libs.shell-context octez-shell-libs.validation octez-shell-libs.protocol-updater octez-libs.stdlib-unix diff --git a/src/lib_store/unix/test/test_protocol_store.ml b/src/lib_store/unix/test/test_protocol_store.ml index 65f131d0dd0131de63657824a8c267d95c596995..7dd3af699cfc6d214d077250592463c02b206eaf 100644 --- a/src/lib_store/unix/test/test_protocol_store.ml +++ b/src/lib_store/unix/test/test_protocol_store.ml @@ -1,25 +1,7 @@ (*****************************************************************************) (* *) -(* Open Source License *) -(* Copyright (c) 2020 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. *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2020-2024 Nomadic Labs *) (* *) (*****************************************************************************) diff --git a/src/lib_validation/dune b/src/lib_validation/dune index b7e6fb6363e157f2dd7fdc919c0e6deb7ce8cbae..af4aa84baa3d131e1e595e127f0748084ea6055a 100644 --- a/src/lib_validation/dune +++ b/src/lib_validation/dune @@ -11,7 +11,6 @@ octez-libs.crypto octez-libs.rpc octez-shell-libs.context-ops - octez-shell-libs.shell-context octez-shell-libs.shell-services octez-shell-libs.protocol-updater octez-libs.stdlib-unix @@ -21,7 +20,6 @@ -open Tezos_base.TzPervasives -open Tezos_crypto -open Tezos_context_ops - -open Tezos_shell_context -open Tezos_shell_services -open Tezos_protocol_updater -open Tezos_stdlib_unix)) diff --git a/src/proto_alpha/lib_delegate/abstract_context_index.ml b/src/proto_alpha/lib_delegate/abstract_context_index.ml index 2e54f32fdc1398787ea5bb20ca04aefeee2427b3..5545bee1c2831f94c08cd1a747eebd0b35a3272f 100644 --- a/src/proto_alpha/lib_delegate/abstract_context_index.ml +++ b/src/proto_alpha/lib_delegate/abstract_context_index.ml @@ -1,25 +1,8 @@ (*****************************************************************************) (* *) -(* Open Source License *) -(* Copyright (c) 2021 Dynamic Ledger Solutions, Inc. *) -(* *) -(* 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. *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2021-2024 Nomadic Labs *) (* *) (*****************************************************************************) @@ -32,7 +15,7 @@ type t = { let abstract index = { - sync_fun = (fun () -> Context.sync index); - checkout_fun = Shell_context.checkout index; - finalize_fun = (fun () -> Context.close index); + sync_fun = (fun () -> Context_ops.sync index); + checkout_fun = Context_ops.checkout index; + finalize_fun = (fun () -> Context_ops.close index); } diff --git a/src/proto_alpha/lib_delegate/abstract_context_index.mli b/src/proto_alpha/lib_delegate/abstract_context_index.mli index 5a280d04ac579a0d7f27272693335772133ed201..99ac3dd7ba44225a8976806883466970471c7b4e 100644 --- a/src/proto_alpha/lib_delegate/abstract_context_index.mli +++ b/src/proto_alpha/lib_delegate/abstract_context_index.mli @@ -1,25 +1,8 @@ (*****************************************************************************) (* *) -(* Open Source License *) -(* Copyright (c) 2021 Dynamic Ledger Solutions, Inc. *) -(* *) -(* 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. *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2021-2024 Nomadic Labs *) (* *) (*****************************************************************************) @@ -30,4 +13,4 @@ type t = { finalize_fun : unit -> unit Lwt.t; } -val abstract : Context.index -> t +val abstract : Context_ops.index -> t diff --git a/src/proto_alpha/lib_delegate/baking_simulator.ml b/src/proto_alpha/lib_delegate/baking_simulator.ml index 4184b4033f0d023832c7c85e2e2c131d333e8aa5..a2e47c559bd2bf344a0e19a58086285f28feec6a 100644 --- a/src/proto_alpha/lib_delegate/baking_simulator.ml +++ b/src/proto_alpha/lib_delegate/baking_simulator.ml @@ -1,25 +1,8 @@ (*****************************************************************************) (* *) -(* Open Source License *) +(* SPDX-License-Identifier: MIT *) (* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) -(* *) -(* 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. *) +(* Copyright (c) 2024 Nomadic Labs *) (* *) (*****************************************************************************) @@ -38,7 +21,7 @@ type incremental = { let load_context ~context_path = let open Lwt_result_syntax in protect (fun () -> - let*! index = Context.init ~readonly:true context_path in + let*! index = Context_ops.init ~kind:`Disk ~readonly:true context_path in return (Abstract_context_index.abstract index)) let check_context_consistency (abstract_index : Abstract_context_index.t) diff --git a/src/proto_alpha/lib_delegate/dune b/src/proto_alpha/lib_delegate/dune index 6187d634434b3256e43462f82fe33505d0151546..eee391da2a432cc8205e690c58f6e1de4a9985b5 100644 --- a/src/proto_alpha/lib_delegate/dune +++ b/src/proto_alpha/lib_delegate/dune @@ -19,9 +19,7 @@ octez-shell-libs.client-commands octez-libs.stdlib octez-libs.stdlib-unix - octez-shell-libs.shell-context octez-libs.tezos-context - octez-libs.tezos-context.memory octez-libs.rpc-http-client-unix octez-shell-libs.context-ops octez-libs.rpc @@ -44,7 +42,6 @@ -open Tezos_client_commands -open Tezos_stdlib -open Tezos_stdlib_unix - -open Tezos_shell_context -open Tezos_context -open Tezos_context_ops -open Tezos_rpc_http