diff --git a/.gitlab/ci/jobs/packaging/opam_package.yml b/.gitlab/ci/jobs/packaging/opam_package.yml index 8b76c00f386ba093cd133fa4b43ed2b6853b4fc4..f50455001ddef42030c1f262708dbac17bc8c309 100644 --- a/.gitlab/ci/jobs/packaging/opam_package.yml +++ b/.gitlab/ci/jobs/packaging/opam_package.yml @@ -303,7 +303,7 @@ opam:octez-proxy-server: opam:octez-signer: extends: - .opam_template - - .rules_template__trigger_opam_batch_1 + - .rules_template__trigger_opam_batch_2 variables: package: octez-signer @@ -462,56 +462,56 @@ opam:tezos-clic: opam:tezos-client-000-Ps9mPmXa: extends: - .opam_template - - .rules_template__trigger_opam_batch_2 + - .rules_template__trigger_opam_batch_4 variables: package: tezos-client-000-Ps9mPmXa opam:tezos-client-001-PtCJ7pwo: extends: - .opam_template - - .rules_template__trigger_opam_batch_2 + - .rules_template__trigger_opam_batch_4 variables: package: tezos-client-001-PtCJ7pwo opam:tezos-client-002-PsYLVpVv: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_4 variables: package: tezos-client-002-PsYLVpVv opam:tezos-client-003-PsddFKi3: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_4 variables: package: tezos-client-003-PsddFKi3 opam:tezos-client-004-Pt24m4xi: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_4 variables: package: tezos-client-004-Pt24m4xi opam:tezos-client-005-PsBabyM1: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_4 variables: package: tezos-client-005-PsBabyM1 opam:tezos-client-006-PsCARTHA: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_4 variables: package: tezos-client-006-PsCARTHA opam:tezos-client-007-PsDELPH1: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_2 variables: package: tezos-client-007-PsDELPH1 @@ -602,14 +602,14 @@ opam:tezos-client-base-unix: opam:tezos-client-commands: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_6 variables: package: tezos-client-commands opam:tezos-client-demo-counter: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_4 variables: package: tezos-client-demo-counter @@ -777,63 +777,63 @@ opam:tezos-embedded-protocol-011-PtHangz2: opam:tezos-embedded-protocol-012-Psithaca: extends: - .opam_template - - .rules_template__trigger_opam_batch_4 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-embedded-protocol-012-Psithaca opam:tezos-embedded-protocol-013-PtJakart: extends: - .opam_template - - .rules_template__trigger_opam_batch_4 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-embedded-protocol-013-PtJakart opam:tezos-embedded-protocol-014-PtKathma: extends: - .opam_template - - .rules_template__trigger_opam_batch_4 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-embedded-protocol-014-PtKathma opam:tezos-embedded-protocol-015-PtLimaPt: extends: - .opam_template - - .rules_template__trigger_opam_batch_4 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-embedded-protocol-015-PtLimaPt opam:tezos-embedded-protocol-016-PtMumbai: extends: - .opam_template - - .rules_template__trigger_opam_batch_4 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-embedded-protocol-016-PtMumbai opam:tezos-embedded-protocol-alpha: extends: - .opam_template - - .rules_template__trigger_opam_batch_4 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-embedded-protocol-alpha opam:tezos-embedded-protocol-demo-counter: extends: - .opam_template - - .rules_template__trigger_opam_batch_4 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-embedded-protocol-demo-counter opam:tezos-embedded-protocol-demo-noops: extends: - .opam_template - - .rules_template__trigger_opam_batch_4 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-embedded-protocol-demo-noops opam:tezos-embedded-protocol-genesis: extends: - .opam_template - - .rules_template__trigger_opam_batch_4 + - .rules_template__trigger_opam_batch_3 variables: package: tezos-embedded-protocol-genesis @@ -897,7 +897,7 @@ opam:tezos-layer2-utils-016-PtMumbai: opam:tezos-lazy-containers: extends: - .opam_template - - .rules_template__trigger_opam_batch_7 + - .rules_template__trigger_opam_batch_6 variables: package: tezos-lazy-containers @@ -1112,14 +1112,14 @@ opam:tezos-protocol-alpha: opam:tezos-protocol-demo-counter: extends: - .opam_template - - .rules_template__trigger_opam_batch_6 + - .rules_template__trigger_opam_batch_5 variables: package: tezos-protocol-demo-counter opam:tezos-protocol-demo-noops: extends: - .opam_template - - .rules_template__trigger_opam_batch_6 + - .rules_template__trigger_opam_batch_5 variables: package: tezos-protocol-demo-noops @@ -1147,7 +1147,7 @@ opam:tezos-protocol-plugin-007-PsDELPH1: opam:tezos-protocol-plugin-007-PsDELPH1-registerer: extends: - .opam_template - - .rules_template__trigger_opam_batch_2 + - .rules_template__trigger_opam_batch_1 variables: package: tezos-protocol-plugin-007-PsDELPH1-registerer @@ -1335,7 +1335,7 @@ opam:tezos-rpc: opam:tezos-rpc-http: extends: - .opam_template - - .rules_template__trigger_opam_batch_6 + - .rules_template__trigger_opam_batch_7 variables: package: tezos-rpc-http @@ -1424,7 +1424,7 @@ opam:tezos-shell-services: opam:tezos-signer-backends: extends: - .opam_template - - .rules_template__trigger_opam_batch_5 + - .rules_template__trigger_opam_batch_6 variables: package: tezos-signer-backends @@ -1438,7 +1438,7 @@ opam:tezos-signer-services: opam:tezos-smart-rollup-016-PtMumbai: extends: - .opam_template - - .rules_template__trigger_opam_batch_5 + - .rules_template__trigger_opam_batch_4 variables: package: tezos-smart-rollup-016-PtMumbai @@ -1475,7 +1475,7 @@ opam:tezos-stdlib-unix: opam:tezos-store: extends: - .opam_template - - .rules_template__trigger_opam_batch_3 + - .rules_template__trigger_opam_batch_2 variables: package: tezos-store @@ -1489,7 +1489,7 @@ opam:tezos-test-helpers: opam:tezos-test-helpers-extra: extends: - .opam_template - - .rules_template__trigger_opam_batch_6 + - .rules_template__trigger_opam_batch_7 variables: package: tezos-test-helpers-extra @@ -1523,7 +1523,7 @@ opam:tezos-validation: opam:tezos-version: extends: - .opam_template - - .rules_template__trigger_opam_batch_6 + - .rules_template__trigger_opam_batch_7 variables: package: tezos-version @@ -1537,14 +1537,14 @@ opam:tezos-wasmer: opam:tezos-webassembly-interpreter: extends: - .opam_template - - .rules_template__trigger_opam_batch_7 + - .rules_template__trigger_opam_batch_6 variables: package: tezos-webassembly-interpreter opam:tezos-webassembly-interpreter-extra: extends: - .opam_template - - .rules_template__trigger_opam_batch_7 + - .rules_template__trigger_opam_batch_6 variables: package: tezos-webassembly-interpreter-extra diff --git a/manifest/main.ml b/manifest/main.ml index deae163b8638dc36d7a264f7db1ad25e84e96595..9918396a9af7a9cd91122ecff28e9b0f7eef8a56 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -1260,6 +1260,28 @@ let octez_base_test_helpers = ~linkall:true ~bisect_ppx:No +let octez_context_sigs = + public_lib + "tezos-context.sigs" + ~path:"src/lib_context/sigs" + ~opam:"tezos-context" + ~deps:[octez_base |> open_ ~m:"TzPervasives"; octez_stdlib |> open_] + ~js_compatible:true + +let tree_encoding = + public_lib + "tezos-tree-encoding" + ~path:"src/lib_tree_encoding" + ~synopsis: + "A general-purpose library to encode arbitrary data in Merkle trees" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + octez_context_sigs; + octez_lwt_result_stdlib; + data_encoding; + ] + let lazy_containers = public_lib "tezos-lazy-containers" @@ -1267,7 +1289,7 @@ let lazy_containers = ~synopsis: "A collection of lazy containers whose contents is fetched from \ arbitrary backend on-demand" - ~deps:[octez_lwt_result_stdlib; zarith] + ~deps:[zarith; tree_encoding] let _lazy_containers_tests = tezt @@ -1284,20 +1306,6 @@ let _lazy_containers_tests = alcotezt; ] -let tree_encoding = - public_lib - "tezos-tree-encoding" - ~path:"src/lib_tree_encoding" - ~synopsis: - "A general-purpose library to encode arbitrary data in Merkle trees" - ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - lazy_containers; - octez_lwt_result_stdlib; - data_encoding; - ] - let octez_webassembly_interpreter = public_lib "tezos-webassembly-interpreter" @@ -1449,14 +1457,6 @@ let _octez_workers_tests = alcotezt; ] -let octez_context_sigs = - public_lib - "tezos-context.sigs" - ~path:"src/lib_context/sigs" - ~opam:"tezos-context" - ~deps:[octez_base |> open_ ~m:"TzPervasives"; octez_stdlib |> open_] - ~js_compatible:true - let octez_merkle_proof_encoding = public_lib "tezos-context.merkle_proof_encoding" @@ -1807,38 +1807,6 @@ let octez_wasmer = c_library_flags = []; } -let octez_scoru_wasm = - public_lib - "tezos-scoru-wasm" - ~path:"src/lib_scoru_wasm" - ~synopsis: - "Protocol environment dependency providing WASM functionality for SCORU" - ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - tree_encoding; - lazy_containers; - octez_webassembly_interpreter; - octez_context_sigs; - octez_lwt_result_stdlib; - data_encoding; - ] - -let octez_scoru_wasm_fast = - public_lib - "tezos-scoru-wasm-fast" - ~path:"src/lib_scoru_wasm/fast" - ~synopsis:"WASM functionality for SCORU Fast Execution" - ~deps: - [ - octez_base |> open_ ~m:"TzPervasives"; - tree_encoding; - octez_webassembly_interpreter; - lazy_containers; - octez_scoru_wasm; - octez_wasmer; - ] - let octez_context_encoding = public_lib "tezos-context.encoding" @@ -1866,13 +1834,6 @@ let octez_context_helpers = irmin_pack; ] -let octez_context_dump = - public_lib - "tezos-context.dump" - ~path:"src/lib_context/dump" - ~deps: - [octez_base |> open_ ~m:"TzPervasives"; octez_stdlib_unix |> open_; fmt] - let octez_context_memory = public_lib "tezos-context.memory" @@ -1888,6 +1849,46 @@ let octez_context_memory = octez_context_helpers; ] +let octez_scoru_wasm = + public_lib + "tezos-scoru-wasm" + ~path:"src/lib_scoru_wasm" + ~synopsis: + "Protocol environment dependency providing WASM functionality for SCORU" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + tree_encoding; + lazy_containers; + octez_webassembly_interpreter; + octez_context_sigs; + octez_context_memory; + octez_lwt_result_stdlib; + data_encoding; + ] + +let octez_scoru_wasm_fast = + public_lib + "tezos-scoru-wasm-fast" + ~path:"src/lib_scoru_wasm/fast" + ~synopsis:"WASM functionality for SCORU Fast Execution" + ~deps: + [ + octez_base |> open_ ~m:"TzPervasives"; + tree_encoding; + octez_webassembly_interpreter; + lazy_containers; + octez_scoru_wasm; + octez_wasmer; + ] + +let octez_context_dump = + public_lib + "tezos-context.dump" + ~path:"src/lib_context/dump" + ~deps: + [octez_base |> open_ ~m:"TzPervasives"; octez_stdlib_unix |> open_; fmt] + let octez_context_disk = public_lib "tezos-context.disk" diff --git a/opam/tezos-lazy-containers.opam b/opam/tezos-lazy-containers.opam index 4f045f4a1452d818daa25e398231600e757fa644..b66074b996a4785f8506ad9ca719c4ad52a5bbbd 100644 --- a/opam/tezos-lazy-containers.opam +++ b/opam/tezos-lazy-containers.opam @@ -10,8 +10,8 @@ license: "MIT" depends: [ "dune" { >= "3.0" } "ocaml" { >= "4.14" } - "tezos-lwt-result-stdlib" "zarith" { >= "1.12" & < "1.13" } + "tezos-tree-encoding" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-tree-encoding.opam b/opam/tezos-tree-encoding.opam index 28ae9f53749452923a1da92f87749847f36958f8..1aa2abadb938bced6ed1b28830ff7e382311eb9e 100644 --- a/opam/tezos-tree-encoding.opam +++ b/opam/tezos-tree-encoding.opam @@ -11,7 +11,7 @@ depends: [ "dune" { >= "3.0" } "ocaml" { >= "4.14" } "tezos-base" - "tezos-lazy-containers" + "tezos-context" "tezos-lwt-result-stdlib" "data-encoding" { >= "0.7.1" & < "1.0.0" } ] diff --git a/src/bin_wasm_debugger/repl_helpers.ml b/src/bin_wasm_debugger/repl_helpers.ml index aa36ec762664ba260d8b433704cefa549744fe57..bd4d9220b575b651ef908393d7d5062bad6e0fbf 100644 --- a/src/bin_wasm_debugger/repl_helpers.ml +++ b/src/bin_wasm_debugger/repl_helpers.ml @@ -23,6 +23,8 @@ (* *) (*****************************************************************************) +open Tezos_scoru_wasm_helpers + (* [error loc category msg] fails with the location of an error and a message, returned by either the parser of the typechecker of the WASM reference interpreter. *) @@ -80,9 +82,9 @@ let find_key_in_durable tree key = let print_durable ?(depth = 10) ?(show_values = true) ?(path = []) tree = let open Lwt_syntax in let durable_path = "durable" :: path in - let* path_exists = Encodings_util.Context.Tree.mem_tree tree durable_path in + let* path_exists = Encodings_util.Tree.mem_tree tree durable_path in if path_exists then - Encodings_util.Context.Tree.fold + Encodings_util.Tree.fold ~depth:(`Le depth) tree ("durable" :: path) @@ -93,7 +95,7 @@ let print_durable ?(depth = 10) ?(show_values = true) ?(path = []) tree = (* If we need to show the values, we show every keys, even the root and '@'. *) if show_values then - let+ value = Encodings_util.Context.Tree.find tree [] in + let+ value = Encodings_util.Tree.find tree [] in let value = Option.value ~default:(Bytes.create 0) value in Format.printf "/%s\n %a\n%!" full_key Hex.pp (Hex.of_bytes value) else if key <> [] && key <> ["@"] then diff --git a/src/lib_lazy_containers/chunked_byte_vector.ml b/src/lib_lazy_containers/chunked_byte_vector.ml index 2d94642b2c0f339a438dc07d64ef6966a830eb52..0de931d5d4f2820bc20bdd4612f25cabf87cdf6e 100644 --- a/src/lib_lazy_containers/chunked_byte_vector.ml +++ b/src/lib_lazy_containers/chunked_byte_vector.ml @@ -91,6 +91,10 @@ module Chunk = struct argument. *) Int64.(div (pred length) size |> succ) else 0L + + let encoding = + let open Tezos_tree_encoding in + conv of_bytes to_bytes (raw []) end module Vector = Lazy_vector.Mutable.Int64Vector @@ -271,3 +275,21 @@ let to_string vector = let loaded_chunks vector = Vector.Vector.loaded_bindings (Vector.snapshot vector.chunks) + +module Enc_intf = struct + type nonrec t = t + + type chunk = Chunk.t + + let origin = origin + + let loaded_chunks = loaded_chunks + + let length = length + + let create = create +end + +module Encoding = Tezos_tree_encoding.CBV_encoding.Make (Enc_intf) + +let encoding = Encoding.cbv Chunk.encoding diff --git a/src/lib_lazy_containers/chunked_byte_vector.mli b/src/lib_lazy_containers/chunked_byte_vector.mli index 90a6fb3c92697f8ed14340d6f1bb2495b17f35e8..5a8382af9ca27b8822cf4e940d27f1046a4ddd1c 100644 --- a/src/lib_lazy_containers/chunked_byte_vector.mli +++ b/src/lib_lazy_containers/chunked_byte_vector.mli @@ -42,6 +42,9 @@ module Chunk : sig (** [num_needed len] Computes the number of chunks needed to cover [len]. *) val num_needed : int64 -> int64 + + (** [encoding] is a [Tezos_tree_encoding] for [Chunk]. *) + val encoding : t Tezos_tree_encoding.t end (** Chunked byte vector *) @@ -54,13 +57,16 @@ type t tree-encoding library. To create a brand new chunked byte vector, use {!allocate}. *) val create : - ?origin:Lazy_map.tree -> ?get_chunk:(int64 -> Chunk.t Lwt.t) -> int64 -> t + ?origin:Tezos_tree_encoding.wrapped_tree -> + ?get_chunk:(int64 -> Chunk.t Lwt.t) -> + int64 -> + t (** [origin vec] returns the tree of origin of the vector, if it exists. {b Note:} The sole consumer of this function is expected to be the tree-encoding library. *) -val origin : t -> Lazy_map.tree option +val origin : t -> Tezos_tree_encoding.wrapped_tree option (** [allocate len] creates a new zeroed chunked byte vector. @@ -115,3 +121,6 @@ val store_bytes : t -> int64 -> bytes -> unit Lwt.t been cached in-memory since [vector] has been created, either by reading its contents, or by modifying it. *) val loaded_chunks : t -> (int64 * Chunk.t option) list + +(** [encoding] is a [Tezos_tree_encoding] for [t]. *) +val encoding : t Tezos_tree_encoding.t diff --git a/src/lib_lazy_containers/dune b/src/lib_lazy_containers/dune index d1e189f447030fb59481955d4007f466251d3486..484711152ce51dba26e3f35922eec722deba19d6 100644 --- a/src/lib_lazy_containers/dune +++ b/src/lib_lazy_containers/dune @@ -6,5 +6,5 @@ (public_name tezos-lazy-containers) (instrumentation (backend bisect_ppx)) (libraries - tezos-lwt-result-stdlib - zarith)) + zarith + tezos-tree-encoding)) diff --git a/src/lib_lazy_containers/immutable_chunked_byte_vector.ml b/src/lib_lazy_containers/immutable_chunked_byte_vector.ml index c5cb0d8b3fba844c8d96b28858802fd79dc9a07d..cebbb5441c0f36fe0e4d473d8bbd6fb7759f48ba 100644 --- a/src/lib_lazy_containers/immutable_chunked_byte_vector.ml +++ b/src/lib_lazy_containers/immutable_chunked_byte_vector.ml @@ -117,6 +117,10 @@ module Chunk = struct let copied_bytes = String.to_bytes s in Bytes.set copied_bytes (Int64.to_int offset) chr ; Bytes.unsafe_to_string copied_bytes + + let encoding = + let open Tezos_tree_encoding in + conv of_bytes to_bytes (raw []) end module Vector = Lazy_vector.Int64Vector @@ -287,3 +291,21 @@ let to_string vector = Bytes.to_string buffer let loaded_chunks vector = Vector.loaded_bindings vector.chunks + +module Enc_intf = struct + type nonrec t = t + + type chunk = Chunk.t + + let origin = origin + + let loaded_chunks = loaded_chunks + + let length = length + + let create = create +end + +module Encoding = Tezos_tree_encoding.CBV_encoding.Make (Enc_intf) + +let encoding = Encoding.cbv Chunk.encoding diff --git a/src/lib_lazy_containers/immutable_chunked_byte_vector.mli b/src/lib_lazy_containers/immutable_chunked_byte_vector.mli index 510842c45132cc286451841a198e949f64e6c934..2c4d1b1e04a1ae2d26fe0ddeca9344180da6bed7 100644 --- a/src/lib_lazy_containers/immutable_chunked_byte_vector.mli +++ b/src/lib_lazy_containers/immutable_chunked_byte_vector.mli @@ -43,6 +43,9 @@ module Chunk : sig (** [num_needed len] Computes the number of chunks needed to cover [len]. *) val num_needed : int64 -> int64 + + (** [encoding] is a [Tezos_tree_encoding] for [Chunk]. *) + val encoding : t Tezos_tree_encoding.t end (** Chunked byte vector *) @@ -55,13 +58,16 @@ type t tree-encoding library. To create a brand new chunked byte vector, use {!allocate}. *) val create : - ?origin:Lazy_map.tree -> ?get_chunk:(int64 -> Chunk.t Lwt.t) -> int64 -> t + ?origin:Tezos_tree_encoding.wrapped_tree -> + ?get_chunk:(int64 -> Chunk.t Lwt.t) -> + int64 -> + t (** [origin vec] returns the tree of origin of the vector, if it exists. {b Note:} The sole consumer of this function is expected to be the tree-encoding library. *) -val origin : t -> Lazy_map.tree option +val origin : t -> Tezos_tree_encoding.wrapped_tree option (** [allocate len] creates a new zeroed chunked byte vector. @@ -118,3 +124,6 @@ val store_bytes : t -> int64 -> bytes -> t Lwt.t been cached in-memory since [vector] has been created, either by reading its contents, or by writing to those chunks. *) val loaded_chunks : t -> (int64 * Chunk.t option) list + +(** [encoding] is a [Tezos_tree_encoding] for [t]. *) +val encoding : t Tezos_tree_encoding.t diff --git a/src/lib_lazy_containers/lazy_map.ml b/src/lib_lazy_containers/lazy_map.ml index 80b79ba805da0f751a4ccc1e09c2f684324a7d57..459e46a6e75242f1ff43d9d5f405fd7ba949574a 100644 --- a/src/lib_lazy_containers/lazy_map.ml +++ b/src/lib_lazy_containers/lazy_map.ml @@ -23,8 +23,6 @@ (* *) (*****************************************************************************) -type tree = .. - module type KeyS = sig include Map.OrderedType @@ -40,7 +38,7 @@ module type S = sig type 'a t - val origin : 'a t -> tree option + val origin : 'a t -> Tezos_tree_encoding.wrapped_tree option val string_of_key : key -> string @@ -51,7 +49,7 @@ module type S = sig val create : ?values:'a Map.t -> ?produce_value:'a producer -> - ?origin:tree -> + ?origin:Tezos_tree_encoding.wrapped_tree -> unit -> 'a t @@ -76,7 +74,7 @@ module Make (Key : KeyS) : S with type key = Key.t = struct type 'a producer = key -> 'a Lwt.t type 'a t = { - origin : tree option; + origin : Tezos_tree_encoding.wrapped_tree option; produce_value : 'a producer; mutable values : 'a option Map.t; } @@ -157,7 +155,7 @@ module Mutable = struct val create : ?values:'a Map.Map.t -> ?produce_value:'a Map.producer -> - ?origin:tree -> + ?origin:Tezos_tree_encoding.wrapped_tree -> unit -> 'a t diff --git a/src/lib_lazy_containers/lazy_map.mli b/src/lib_lazy_containers/lazy_map.mli index 0f0edb1e949d2a219f16781f561763d5af40a13c..db4eb242190481ccc74ccaae7a849a6932e89177 100644 --- a/src/lib_lazy_containers/lazy_map.mli +++ b/src/lib_lazy_containers/lazy_map.mli @@ -23,13 +23,6 @@ (* *) (*****************************************************************************) -(** An extensible type to record the type of trees used as backend for - the lazy map. - - {b Note:} If you use the 'tree-encoding' library, then its functor - takes care of adding a new constructor for the expected tree. *) -type tree = .. - (** [KeyS] is the qualifier signature for key types in the lazy map. Externally visible and accessible keys of the lazy map are always non-negative. However, the lazy map implementation may internally use @@ -55,7 +48,7 @@ module type S = sig {b Note:} The sole consumer of this function is expected to be the tree-encoding library. *) - val origin : 'a t -> tree option + val origin : 'a t -> Tezos_tree_encoding.wrapped_tree option (** [string_of_key key] turns the given [key] into a string. *) val string_of_key : key -> string @@ -81,7 +74,7 @@ module type S = sig val create : ?values:'a Map.t -> ?produce_value:'a producer -> - ?origin:tree -> + ?origin:Tezos_tree_encoding.wrapped_tree -> unit -> 'a t @@ -143,7 +136,7 @@ module Mutable : sig val create : ?values:'a Map.Map.t -> ?produce_value:'a Map.producer -> - ?origin:tree -> + ?origin:Tezos_tree_encoding.wrapped_tree -> unit -> 'a t diff --git a/src/lib_lazy_containers/lazy_vector.ml b/src/lib_lazy_containers/lazy_vector.ml index 3bc31a35c00581ae245adc35bc68529e6a5a546f..afa09dff0f2a21918d723aae7e20a020b8397186 100644 --- a/src/lib_lazy_containers/lazy_vector.ml +++ b/src/lib_lazy_containers/lazy_vector.ml @@ -66,11 +66,11 @@ module type S = sig ?first_key:key -> ?values:'a Map.Map.t -> ?produce_value:'a producer -> - ?origin:Lazy_map.tree -> + ?origin:Tezos_tree_encoding.wrapped_tree -> key -> 'a t - val origin : 'a t -> Lazy_map.tree option + val origin : 'a t -> Tezos_tree_encoding.wrapped_tree option val empty : unit -> 'a t @@ -105,6 +105,11 @@ module type S = sig val loaded_bindings : 'a t -> (key * 'a option) list val first_key : 'a t -> key + + val encoding : + key Tezos_tree_encoding.t -> + 'a Tezos_tree_encoding.t -> + 'a t Tezos_tree_encoding.t end module ZZ : KeyS with type t = Z.t = struct @@ -120,7 +125,7 @@ module ZZ : KeyS with type t = Z.t = struct let unsigned_compare = Z.compare end -module Make (Key : KeyS) : S with type key = Key.t = struct +module Make_no_enc (Key : KeyS) = struct module Map = Lazy_map.Make (Key) type key = Key.t @@ -279,6 +284,14 @@ module Make (Key : KeyS) : S with type key = Key.t = struct let first_key vector = vector.first end +module Make (Key : KeyS) : S with type key = Key.t = struct + module No_enc = Make_no_enc (Key) + module Encoding = Tezos_tree_encoding.Lazy_vector_encoding.Make (No_enc) + include No_enc + + let encoding = Encoding.lazy_vector +end + module Int = struct include Int @@ -307,11 +320,11 @@ module Mutable = struct val create : ?values:'a Vector.Map.Map.t -> ?produce_value:'a Vector.producer -> - ?origin:Lazy_map.tree -> + ?origin:Tezos_tree_encoding.wrapped_tree -> key -> 'a t - val origin : 'a t -> Lazy_map.tree option + val origin : 'a t -> Tezos_tree_encoding.wrapped_tree option val get : key -> 'a t -> 'a Lwt.t diff --git a/src/lib_lazy_containers/lazy_vector.mli b/src/lib_lazy_containers/lazy_vector.mli index efcd1703261c8be0a0ab6897495a1f678c42b46c..e0a4b0bd7e062317d82cdc5da369cd2f125c9f52 100644 --- a/src/lib_lazy_containers/lazy_vector.mli +++ b/src/lib_lazy_containers/lazy_vector.mli @@ -98,7 +98,7 @@ module type S = sig ?first_key:key -> ?values:'a Map.Map.t -> ?produce_value:'a producer -> - ?origin:Lazy_map.tree -> + ?origin:Tezos_tree_encoding.wrapped_tree -> key -> 'a t @@ -106,7 +106,7 @@ module type S = sig {b Note:} The sole consumer of this function is expected to be the tree-encoding library. *) - val origin : 'a t -> Lazy_map.tree option + val origin : 'a t -> Tezos_tree_encoding.wrapped_tree option (** [empty ()] creates a vector of size zero. This is used in conjunction with {!cons} to model list-like structure. *) @@ -203,6 +203,12 @@ module type S = sig (** [first_key v] returns the first key of the given vector [v]. *) val first_key : 'a t -> key + + (** [encoding len_encoding elem_encoding] returns [Tezos_tree_encoding] for the vector *) + val encoding : + key Tezos_tree_encoding.t -> + 'a Tezos_tree_encoding.t -> + 'a t Tezos_tree_encoding.t end module Make (Key : KeyS) : S with type key = Key.t @@ -234,11 +240,11 @@ module Mutable : sig val create : ?values:'a Vector.Map.Map.t -> ?produce_value:'a Vector.producer -> - ?origin:Lazy_map.tree -> + ?origin:Tezos_tree_encoding.wrapped_tree -> key -> 'a t - val origin : 'a t -> Lazy_map.tree option + val origin : 'a t -> Tezos_tree_encoding.wrapped_tree option val get : key -> 'a t -> 'a Lwt.t diff --git a/src/lib_lazy_containers/test/chunked_byte_vector_tests.ml b/src/lib_lazy_containers/test/chunked_byte_vector_tests.ml index fe052b6e057220e048282141f02f7883d88e31ea..3ccc0f2876c357620ce087149166c1c001528f19 100644 --- a/src/lib_lazy_containers/test/chunked_byte_vector_tests.ml +++ b/src/lib_lazy_containers/test/chunked_byte_vector_tests.ml @@ -32,6 +32,7 @@ open QCheck_alcotest open QCheck2 +open Tezos_tree_encoding module type S = sig module Chunk : sig @@ -51,9 +52,9 @@ module type S = sig val name : string val create : - ?origin:Lazy_map.tree -> ?get_chunk:(int64 -> Chunk.t Lwt.t) -> int64 -> t + ?origin:wrapped_tree -> ?get_chunk:(int64 -> Chunk.t Lwt.t) -> int64 -> t - val origin : t -> Lazy_map.tree option + val origin : t -> wrapped_tree option val allocate : int64 -> t diff --git a/src/lib_protocol_environment/environment_V6.ml b/src/lib_protocol_environment/environment_V6.ml index 5458baa4644f736a39ebd939ae742688fbc485a7..f72b4572c847701a1ade8cdf0225b5ff9107ba31 100644 --- a/src/lib_protocol_environment/environment_V6.ml +++ b/src/lib_protocol_environment/environment_V6.ml @@ -1054,7 +1054,7 @@ struct module Make (Tree : Context.TREE with type key = string list and type value = bytes) = struct - type Tezos_lazy_containers.Lazy_map.tree += PVM_tree of Tree.tree + type Tezos_tree_encoding.tree_instance += PVM_tree of Tree.tree module Wasm = Tezos_scoru_wasm.Wasm_pvm.Make (struct include Tree diff --git a/src/lib_protocol_environment/environment_V7.ml b/src/lib_protocol_environment/environment_V7.ml index e7ada90a09911ec5c5c6790174cc7295f6bedd01..7225ca058f97cecb0dc0b9607082b1b334d0a3e7 100644 --- a/src/lib_protocol_environment/environment_V7.ml +++ b/src/lib_protocol_environment/environment_V7.ml @@ -1064,7 +1064,7 @@ struct module Make (Tree : Context.TREE with type key = string list and type value = bytes) = struct - type Tezos_lazy_containers.Lazy_map.tree += PVM_tree of Tree.tree + type Tezos_tree_encoding.tree_instance += PVM_tree of Tree.tree module Wasm = Tezos_scoru_wasm.Wasm_pvm.Make (struct include Tree diff --git a/src/lib_protocol_environment/environment_V8.ml b/src/lib_protocol_environment/environment_V8.ml index ad66c348098b38726e387beefb2555942066eac0..cf3aff5fa34340ed704121ee5c3ba085ae1d5589 100644 --- a/src/lib_protocol_environment/environment_V8.ml +++ b/src/lib_protocol_environment/environment_V8.ml @@ -1132,7 +1132,7 @@ struct module Make (Tree : Context.TREE with type key = string list and type value = bytes) = struct - type Tezos_lazy_containers.Lazy_map.tree += PVM_tree of Tree.tree + type Tezos_tree_encoding.tree_instance += PVM_tree of Tree.tree include Tezos_scoru_wasm.Wasm_pvm.Make (struct include Tree diff --git a/src/lib_protocol_environment/environment_V9.ml b/src/lib_protocol_environment/environment_V9.ml index fe61eb612fcbdb7887c7a871140bf4a0b98b2da1..2be89ec833c1a75edbe11d08ae977df1d75fafe3 100644 --- a/src/lib_protocol_environment/environment_V9.ml +++ b/src/lib_protocol_environment/environment_V9.ml @@ -1134,7 +1134,7 @@ struct module Make (Tree : Context.TREE with type key = string list and type value = bytes) = struct - type Tezos_lazy_containers.Lazy_map.tree += PVM_tree of Tree.tree + type Tezos_tree_encoding.tree_instance += PVM_tree of Tree.tree include Tezos_scoru_wasm.Wasm_pvm.Make (struct include Tree diff --git a/src/lib_scoru_wasm/bench/pvm_instance.mli b/src/lib_scoru_wasm/bench/pvm_instance.mli index 3a9a606d04d7737432ec298250d84921db4771e0..f1af9ce893be47c369da615ec681c1241f2f28dc 100644 --- a/src/lib_scoru_wasm/bench/pvm_instance.mli +++ b/src/lib_scoru_wasm/bench/pvm_instance.mli @@ -26,7 +26,7 @@ (** PVM instance used in benchmark*) module Wasm : Tezos_scoru_wasm.Wasm_pvm_sig.S - with type tree = Tezos_scoru_wasm_helpers.Encodings_util.Context.tree + with type tree = Tezos_scoru_wasm_helpers.Encodings_util.Tree.tree module Wasm_fast_vm : Tezos_scoru_wasm.Wasm_vm_sig.S diff --git a/src/lib_scoru_wasm/binary_parser_encodings.ml b/src/lib_scoru_wasm/binary_parser_encodings.ml index 34f977744d7fe6413dcb58e4c4d4c6f3cd1b5823..f7706f11401b53f43b0f3768b0744dbbd1b86567 100644 --- a/src/lib_scoru_wasm/binary_parser_encodings.ml +++ b/src/lib_scoru_wasm/binary_parser_encodings.ml @@ -37,7 +37,7 @@ let no_region_encoding enc = conv (fun s -> Source.(s @@ no_region)) (fun {it; _} -> it) enc let vector_encoding value_enc = - int32_lazy_vector (value [] Data_encoding.int32) value_enc + Lazy_vector.Int32Vector.encoding (value [] Data_encoding.int32) value_enc module Lazy_vec = struct let raw_encoding vector_encoding = diff --git a/src/lib_scoru_wasm/dune b/src/lib_scoru_wasm/dune index c98380dbe14c0cc8671da1c2612cd7660226fff3..e6a46acbd9bf118d571b8b74c41ff31e8d012cf9 100644 --- a/src/lib_scoru_wasm/dune +++ b/src/lib_scoru_wasm/dune @@ -11,6 +11,7 @@ tezos-lazy-containers tezos-webassembly-interpreter tezos-context.sigs + tezos-context.memory tezos-lwt-result-stdlib data-encoding) (flags diff --git a/src/lib_scoru_wasm/durable.ml b/src/lib_scoru_wasm/durable.ml index 1cffcec37951e95728df14b614d29b8d17512370..b79d83b40540f7a7d9dc9a12f908392227501046 100644 --- a/src/lib_scoru_wasm/durable.ml +++ b/src/lib_scoru_wasm/durable.ml @@ -27,6 +27,7 @@ module T = Tezos_tree_encoding.Wrapped module Runner = Tezos_tree_encoding.Runner.Make (Tezos_tree_encoding.Wrapped) module E = Tezos_tree_encoding module Storage = Tezos_webassembly_interpreter.Durable_storage +open Tezos_lazy_containers type t = T.tree @@ -52,11 +53,11 @@ exception Readonly_value let encoding = E.wrapped_tree let of_storage ~default s = - match Storage.to_tree s with Some t -> T.select t | None -> default + match Storage.to_tree s with Some t -> t | None -> default -let of_storage_exn s = T.select @@ Storage.to_tree_exn s +let of_storage_exn s = Storage.to_tree_exn s -let to_storage d = Storage.of_tree @@ T.wrap d +let to_storage d = Storage.of_tree d type key = Writeable of string list | Readonly of string list @@ -117,7 +118,7 @@ let find_value tree key = match opt with | None -> Lwt.return_none | Some subtree -> - let+ value = Runner.decode E.chunked_byte_vector subtree in + let+ value = Runner.decode Chunked_byte_vector.encoding subtree in Some value let find_value_exn tree key = @@ -181,7 +182,7 @@ let hash_exn tree key = let set_value_exn tree ?(edit_readonly = false) key str = if not edit_readonly then assert_key_writeable key ; let key = to_value_key @@ key_contents key in - let encoding = E.scope key E.chunked_byte_vector in + let encoding = E.scope key Chunked_byte_vector.encoding in Runner.encode encoding (Tezos_lazy_containers.Chunked_byte_vector.of_string str) @@ -197,7 +198,7 @@ let write_value_exn tree ?(edit_readonly = false) key offset bytes = let key = to_value_key @@ key_contents key in let* opt = T.find_tree tree key in - let encoding = E.scope key E.chunked_byte_vector in + let encoding = E.scope key Chunked_byte_vector.encoding in let* value = match opt with | None -> Lwt.return @@ Chunked_byte_vector.allocate 0L diff --git a/src/lib_scoru_wasm/helpers/encodings_util.ml b/src/lib_scoru_wasm/helpers/encodings_util.ml index 94d79eaf890bde31e56f169459d81434a92d2c39..f3e760b2f20928b6ce2aeab5dd94d604ab9351f3 100644 --- a/src/lib_scoru_wasm/helpers/encodings_util.ml +++ b/src/lib_scoru_wasm/helpers/encodings_util.ml @@ -1,8 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) -(* Copyright (c) 2023 TriliTech *) -(* Copyright (c) 2023 Nomadic Labs *) +(* Copyright (c) 2022-2023 TriliTech *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -24,34 +23,5 @@ (* *) (*****************************************************************************) -(* Use context-binary for testing. *) -module Context = Tezos_context_memory.Context_binary -include Tezos_tree_encoding - -type Tezos_lazy_containers.Lazy_map.tree += Tree of Context.tree - -module Tree = struct - type t = Context.t - - type tree = Context.tree - - type key = Context.key - - type value = Context.value - - include Context.Tree - - let select = function - | Tree t -> t - | _ -> raise Tezos_tree_encoding.Incorrect_tree_type - - let wrap t = Tree t -end - -module Tree_encoding_runner = Tezos_tree_encoding.Runner.Make (Tree) - -let empty_tree () = - let open Lwt_syntax in - let* index = Context.init "/tmp" in - let empty_store = Context.empty index in - return @@ Context.Tree.empty empty_store +include + Tezos_tree_encoding.Encodings_util.Make (Tezos_context_memory.Context_binary) diff --git a/src/lib_scoru_wasm/helpers/wasm_utils.ml b/src/lib_scoru_wasm/helpers/wasm_utils.ml index b55f526ab890512b6fcf83514648a6b8d13d8309..095a9599a8eab38c3866ebbd268998fc570cb4f5 100644 --- a/src/lib_scoru_wasm/helpers/wasm_utils.ml +++ b/src/lib_scoru_wasm/helpers/wasm_utils.ml @@ -30,12 +30,6 @@ open Tezos_lazy_containers module Wasm = Wasm_pvm.Make (Tree) module Wasm_fast = Tezos_scoru_wasm_fast.Pvm.Make (Tree) -let empty_tree () = - let open Lwt_syntax in - let* index = Context.init "/tmp" in - let empty_store = Context.empty index in - return @@ Context.Tree.empty empty_store - let parse_module code = let def = Parse.string_to_module code in match def.it with @@ -458,8 +452,7 @@ let wrap_as_durable_storage tree = Tezos_tree_encoding.(scope ["durable"] wrapped_tree) tree in - Tezos_webassembly_interpreter.Durable_storage.of_tree - @@ Tezos_tree_encoding.Wrapped.wrap tree + Tezos_webassembly_interpreter.Durable_storage.of_tree tree let has_stuck_flag tree = let open Lwt_syntax in diff --git a/src/lib_scoru_wasm/init_encodings.ml b/src/lib_scoru_wasm/init_encodings.ml index 0810462b62c1dfcc6cc621a9c908ffd2196f4a9a..26cbbecfd2d16e39d020b91fcb5475b21719954d 100644 --- a/src/lib_scoru_wasm/init_encodings.ml +++ b/src/lib_scoru_wasm/init_encodings.ml @@ -27,10 +27,12 @@ open Tezos_webassembly_interpreter.Eval module Parser = Binary_parser_encodings open Tezos_tree_encoding open Kont_encodings +open Tezos_lazy_containers let tag_encoding = value [] Data_encoding.string -let lazy_vec_encoding enc = int32_lazy_vector (value [] Data_encoding.int32) enc +let lazy_vec_encoding enc = + Lazy_vector.Int32Vector.encoding (value [] Data_encoding.int32) enc let eval_const_kont_encoding = tagged_union diff --git a/src/lib_scoru_wasm/test/durable_snapshot/durable.ml b/src/lib_scoru_wasm/test/durable_snapshot/durable.ml index 0ffa5993d9616d843ff951bc2085e18841017494..6142addc884aede05c9eead706f9aa442b8c2de7 100644 --- a/src/lib_scoru_wasm/test/durable_snapshot/durable.ml +++ b/src/lib_scoru_wasm/test/durable_snapshot/durable.ml @@ -27,6 +27,7 @@ https://gitlab.com/tezos/tezos/-/blob/668fe735aa20ce0c68b9f836208e57fa15d389c1/src/lib_scoru_wasm/durable.ml *) +open Tezos_lazy_containers module T = Tezos_tree_encoding.Wrapped module Runner = Tezos_tree_encoding.Runner.Make (Tezos_tree_encoding.Wrapped) module E = Tezos_tree_encoding @@ -56,11 +57,11 @@ exception Readonly_value let encoding = E.wrapped_tree let of_storage ~default s = - match Storage.to_tree s with Some t -> T.select t | None -> default + match Storage.to_tree s with Some t -> t | None -> default -let of_storage_exn s = T.select @@ Storage.to_tree_exn s +let of_storage_exn s = Storage.to_tree_exn s -let to_storage d = Storage.of_tree @@ T.wrap d +let to_storage d = Storage.of_tree d type key = Writeable of string list | Readonly of string list @@ -121,7 +122,7 @@ let find_value tree key = match opt with | None -> Lwt.return_none | Some subtree -> - let+ value = Runner.decode E.chunked_byte_vector subtree in + let+ value = Runner.decode Chunked_byte_vector.encoding subtree in Some value let find_value_exn tree key = @@ -185,7 +186,7 @@ let hash_exn tree key = let set_value_exn tree ?(edit_readonly = false) key str = if not edit_readonly then assert_key_writeable key ; let key = to_value_key @@ key_contents key in - let encoding = E.scope key E.chunked_byte_vector in + let encoding = E.scope key Chunked_byte_vector.encoding in Runner.encode encoding (Tezos_lazy_containers.Chunked_byte_vector.of_string str) @@ -201,7 +202,7 @@ let write_value_exn tree ?(edit_readonly = false) key offset bytes = let key = to_value_key @@ key_contents key in let* opt = T.find_tree tree key in - let encoding = E.scope key E.chunked_byte_vector in + let encoding = E.scope key Chunked_byte_vector.encoding in let* value = match opt with | None -> Lwt.return @@ Chunked_byte_vector.allocate 0L diff --git a/src/lib_scoru_wasm/test/test_durable_shapshot.ml b/src/lib_scoru_wasm/test/test_durable_shapshot.ml index c505ec4fea9c98f4fbee62c5b0937b3c86b16271..5db2194bbfee3c290a118a7991258a1589680f13 100644 --- a/src/lib_scoru_wasm/test/test_durable_shapshot.ml +++ b/src/lib_scoru_wasm/test/test_durable_shapshot.ml @@ -33,7 +33,7 @@ open Tztest open QCheck2 -open Encodings_util +open Tezos_scoru_wasm_helpers.Encodings_util open Durable_snapshot_util open Probability_utils diff --git a/src/lib_scoru_wasm/test/test_get_set.ml b/src/lib_scoru_wasm/test/test_get_set.ml index fe710913e39062412ef21fa80a346c9ef7965e15..1be5e1ac06e1c606139cc6d0d46bd613ae1a415b 100644 --- a/src/lib_scoru_wasm/test/test_get_set.ml +++ b/src/lib_scoru_wasm/test/test_get_set.ml @@ -46,7 +46,7 @@ let empty_tree () = let empty_store = Context.empty index in return @@ Context.Tree.empty empty_store -type Tezos_lazy_containers.Lazy_map.tree += Tree of Context.tree +type Tezos_tree_encoding.tree_instance += Tree of Context.tree module Tree : Tezos_tree_encoding.TREE with type tree = Context.tree = struct type tree = Context.tree diff --git a/src/lib_scoru_wasm/test/test_parser_encoding.ml b/src/lib_scoru_wasm/test/test_parser_encoding.ml index c21566ec177c18d2259fcc451ed22271fa202107..e3a0c7c38769848a77255c0ed11969cd5fe2ea1d 100644 --- a/src/lib_scoru_wasm/test/test_parser_encoding.ml +++ b/src/lib_scoru_wasm/test/test_parser_encoding.ml @@ -43,6 +43,7 @@ module Utils = struct module C = Chunked_byte_vector include Encodings_util include Test_encodings_util + include Tezos_tree_encoding end module Byte_vector = struct diff --git a/src/lib_scoru_wasm/test/test_wasm_pvm.ml b/src/lib_scoru_wasm/test/test_wasm_pvm.ml index d2eaf5f2214c2a0dc82fac679a7a57489d8cd16e..0f5eca80bdee9559c1f559056ba91a6d59e72bc2 100644 --- a/src/lib_scoru_wasm/test/test_wasm_pvm.ml +++ b/src/lib_scoru_wasm/test/test_wasm_pvm.ml @@ -33,9 +33,9 @@ *) open Tezos_scoru_wasm +open Tezos_scoru_wasm_helpers.Encodings_util open Wasm_utils open Tztest_helper -open Encodings_util let should_boot_unreachable_kernel ~version ~batch_size kernel = let open Lwt_syntax in @@ -116,7 +116,9 @@ let add_value ?(content = "a very long value") tree key_steps = let value = Chunked_byte_vector.of_string content in Tree_encoding_runner.encode Tezos_tree_encoding.( - scope ("durable" :: List.append key_steps ["@"]) chunked_byte_vector) + scope + ("durable" :: List.append key_steps ["@"]) + Chunked_byte_vector.encoding) value tree diff --git a/src/lib_scoru_wasm/wasm_encoding.ml b/src/lib_scoru_wasm/wasm_encoding.ml index a997790195731e8c9025fb6d8295f3ac88567e72..3236e67f53e1c5b9f91115448777e8b51e9ba149 100644 --- a/src/lib_scoru_wasm/wasm_encoding.ml +++ b/src/lib_scoru_wasm/wasm_encoding.ml @@ -43,10 +43,12 @@ let string_tag = value [] Data_encoding.string let lazy_vector_encoding field_name tree_encoding = scope [field_name] - (int32_lazy_vector (value [] Data_encoding.int32) tree_encoding) + (Lazy_vector.Int32Vector.encoding + (value [] Data_encoding.int32) + tree_encoding) let lazy_vector_encoding' tree_encoding = - int32_lazy_vector (value [] Data_encoding.int32) tree_encoding + Lazy_vector.Int32Vector.encoding (value [] Data_encoding.int32) tree_encoding let func'_encoding = let ftype = value ["ftype"] Interpreter_encodings.Ast.var_encoding in @@ -564,7 +566,7 @@ let memory_encoding = ~flatten:false (value ["min"] Data_encoding.int32) (value_option ["max"] Data_encoding.int32) - (scope ["chunks"] chunked_byte_vector)) + (scope ["chunks"] Chunked_byte_vector.encoding)) let table_encoding = conv @@ -657,7 +659,7 @@ let block_table_encoding = (lazy_vector_encoding "instructions" instruction_encoding) let datas_table_encoding = - lazy_vector_encoding "datas-table" chunked_byte_vector + lazy_vector_encoding "datas-table" Chunked_byte_vector.encoding let allocations_encoding = conv @@ -882,13 +884,15 @@ let input_buffer_message_encoding = ~flatten:true (value ["raw-level"] Data_encoding.int32) (value ["message-counter"] Data_encoding.z) - chunked_byte_vector) + Chunked_byte_vector.encoding) let input_buffer_encoding = conv (fun index -> Lazy_vector.Mutable.ZVector.of_immutable index) (fun buffer -> Lazy_vector.Mutable.ZVector.snapshot buffer) - (z_lazy_vector (value [] Data_encoding.z) input_buffer_message_encoding) + (Lazy_vector.ZVector.encoding + (value [] Data_encoding.z) + input_buffer_message_encoding) let label_encoding = conv @@ -1209,7 +1213,9 @@ let messages_encoding = conv (fun index -> Output_buffer.Messages.of_immutable index) (fun buffer -> Output_buffer.Messages.snapshot buffer) - (z_lazy_vector (value [] Data_encoding.z) (value [] Data_encoding.bytes)) + (Lazy_vector.ZVector.encoding + (value [] Data_encoding.z) + (value [] Data_encoding.bytes)) let outboxes_encoding = conv diff --git a/src/lib_scoru_wasm/wasm_pvm.ml b/src/lib_scoru_wasm/wasm_pvm.ml index e1b6f0bd64837681667da001da54e343f497ab3b..2108444b74a8bfe77d13e7366b2b798ebdd6b529 100644 --- a/src/lib_scoru_wasm/wasm_pvm.ml +++ b/src/lib_scoru_wasm/wasm_pvm.ml @@ -27,6 +27,7 @@ open Wasm_pvm_state.Internal_state module Wasm = Tezos_webassembly_interpreter module Parsing = Binary_parser_encodings +open Tezos_lazy_containers let durable_scope = ["durable"] @@ -54,7 +55,7 @@ let tick_state_encoding = @@ Parsing.(no_region_encoding Module.module_encoding)) (scope ["externs"] - (int32_lazy_vector + (Lazy_vector.Int32Vector.encoding (value [] Data_encoding.int32) Wasm_encoding.extern_encoding)) (value ["imports_offset"] Data_encoding.int32)) diff --git a/src/lib_tree_encoding/decoding.ml b/src/lib_tree_encoding/decoding.ml index d5f956c69206a0eba80f2acfb154556813276047..95a4db16153aa6f54f38b410a32779221a840dd0 100644 --- a/src/lib_tree_encoding/decoding.ml +++ b/src/lib_tree_encoding/decoding.ml @@ -158,7 +158,7 @@ let subtree backend tree prefix = in the tree to avoid it. *) assert false) in - Tree.wrap backend subtree + subtree let scope key {decode} = { @@ -178,7 +178,7 @@ let lazy_mapping to_key field_enc = input_prefix in let+ tree = subtree backend input_tree input_prefix in - (Some tree, produce_value)); + (Some (Tree.Wrapped_tree (tree, backend)), produce_value)); } let case_lwt tag decode extract = Case {tag; decode; extract} @@ -225,5 +225,5 @@ let wrapped_tree = (fun backend tree prefix -> let open Lwt.Syntax in let+ tree = subtree backend tree prefix in - Tree.Wrapped_tree (Tree.select backend tree, backend)); + Tree.Wrapped_tree (tree, backend)); } diff --git a/src/lib_tree_encoding/decoding.mli b/src/lib_tree_encoding/decoding.mli index b3ba52d34a160d47189d4f60b4bcfb739245b6db..812da28c200aa0c9cf11e56be3355580c9070af4 100644 --- a/src/lib_tree_encoding/decoding.mli +++ b/src/lib_tree_encoding/decoding.mli @@ -85,9 +85,7 @@ val scope : key -> 'a t -> 'a t This function is primarily useful when providing a [~produce_value] function to [Lazy_map.create]. *) val lazy_mapping : - ('i -> key) -> - 'a t -> - (Tezos_lazy_containers.Lazy_map.tree option * ('i -> 'a Lwt.t)) t + ('i -> key) -> 'a t -> (Tree.wrapped_tree option * ('i -> 'a Lwt.t)) t (** [delayed f] produces a tree decoder that delays evaluation of [f ()] until the decoder is actually needed. This is required to allow for directly diff --git a/src/lib_tree_encoding/dune b/src/lib_tree_encoding/dune index 7fbf3832f2eb6764671ed9fd70b32f0779940f27..ff7b171eb71a6a56f92fb17edb61eba671551ad4 100644 --- a/src/lib_tree_encoding/dune +++ b/src/lib_tree_encoding/dune @@ -7,7 +7,7 @@ (instrumentation (backend bisect_ppx)) (libraries tezos-base - tezos-lazy-containers + tezos-context.sigs tezos-lwt-result-stdlib data-encoding) (flags diff --git a/src/lib_tree_encoding/encoding.ml b/src/lib_tree_encoding/encoding.ml index dc5da5dd61e23d12860bb889a415b7b2e4b7fe54..081c5046acae889382fece99c9d6ca27fbbf1ed3 100644 --- a/src/lib_tree_encoding/encoding.ml +++ b/src/lib_tree_encoding/encoding.ml @@ -124,16 +124,18 @@ let scope key {encode} = let lazy_mapping to_key enc_value = { encode = - (fun backend (origin, bindings) prefix tree -> + (fun backend (origin_opt, bindings) prefix tree -> let open Lwt_syntax in let* tree = - match origin with - | Some origin -> + match origin_opt with + | Some (Tree.Wrapped_tree (origin, origin_backend)) -> Tree.add_tree backend tree (prefix []) - (Tree.select backend origin) + (Tree.select backend @@ Tree.wrap origin_backend origin) + (* Will fetch a tree of the same type as backend or throw an error. + Basically checking that origin's backend and encoding backeds are the same *) | None -> Tree.remove backend tree (prefix []) in List.fold_left_s diff --git a/src/lib_tree_encoding/encoding.mli b/src/lib_tree_encoding/encoding.mli index 61bc9b2d06fe9516d8ade83b4532922c5564f829..3a673ae0463e7eaec9756602d7c936a14ce4edae 100644 --- a/src/lib_tree_encoding/encoding.mli +++ b/src/lib_tree_encoding/encoding.mli @@ -81,9 +81,7 @@ val scope : key -> 'a t -> 'a t During the encoding process, the subtree is added to the target tree under the prefix, before the key-value list is processed. *) val lazy_mapping : - ('k -> key) -> - 'v t -> - (Tezos_lazy_containers.Lazy_map.tree option * ('k * 'v option) list) t + ('k -> key) -> 'v t -> (Tree.wrapped_tree option * ('k * 'v option) list) t (** [case tag enc f] return a partial encoder that represents a case in a sum-type. The encoder hides the (existentially bound) type of the diff --git a/src/lib_tree_encoding/test/test_encoding.ml b/src/lib_tree_encoding/test/test_encoding.ml index 3bccd40c9060be822795348b2ec12fb26adff2a3..fd6af7c490c02d8696f08c9840009e9f6ec2f958 100644 --- a/src/lib_tree_encoding/test/test_encoding.ml +++ b/src/lib_tree_encoding/test/test_encoding.ml @@ -36,20 +36,8 @@ open Tezos_lazy_containers (* Use context-binary for testing. *) module Context = Tezos_context_memory.Context_binary - -type Tezos_lazy_containers.Lazy_map.tree += Tree of Context.tree - -module Tree : Tezos_tree_encoding.TREE with type tree = Context.tree = struct - type tree = Context.tree - - include Context.Tree - - let select = function - | Tree t -> t - | _ -> raise Tezos_tree_encoding.Incorrect_tree_type - - let wrap t = Tree t -end +module E = Tezos_tree_encoding.Encodings_util.Make (Context) +module Tree = E.Tree module Map = Lazy_map.Make (struct type t = string @@ -280,7 +268,7 @@ let test_lazy_vector () = let open Tree_encoding in let open Lwt_result_syntax in let enc = - int_lazy_vector + Lazy_vector.IntVector.encoding (value [] Data_encoding.int31) (value [] Data_encoding.string) in @@ -302,7 +290,7 @@ let test_lazy_vector_pop () = let open Tree_encoding in let open Lwt_result_syntax in let int_vec_enc = - int_lazy_vector + Lazy_vector.IntVector.encoding (value [] Data_encoding.int31) (value [] Data_encoding.int31) in @@ -337,7 +325,6 @@ let test_lazy_vector_pop () = return_unit let test_chunked_byte_vector () = - let open Tree_encoding in let open Lwt_result_syntax in let vector = Chunked_byte_vector.of_string @@ -347,7 +334,7 @@ let test_chunked_byte_vector () = assert (Char.chr value = 'a') ; let*! value = Chunked_byte_vector.load_byte vector 10_005L in assert (Char.chr value = 'b') ; - let*! decoded_vector = encode_decode chunked_byte_vector vector in + let*! decoded_vector = encode_decode Chunked_byte_vector.encoding vector in let*! value = Chunked_byte_vector.load_byte decoded_vector 5L in assert (Char.chr value = 'a') ; let*! value = Chunked_byte_vector.load_byte decoded_vector 10_005L in @@ -525,7 +512,7 @@ let test_swap_vectors () = let open Tree_encoding in let open Lwt_result_syntax in let int_vec_enc = - int_lazy_vector + Lazy_vector.IntVector.encoding (value [] Data_encoding.int31) (value [] Data_encoding.int31) in diff --git a/src/lib_tree_encoding/test/test_proofs.ml b/src/lib_tree_encoding/test/test_proofs.ml index 88f1bc038213d1f334694a1bc63df0eba34a8213..880cfc9ed97cc5c215ff5592bf60b936cb4a40bc 100644 --- a/src/lib_tree_encoding/test/test_proofs.ml +++ b/src/lib_tree_encoding/test/test_proofs.ml @@ -45,9 +45,9 @@ let encoding = let open Tree_encoding in tup3 ~flatten:false - (int_lazy_vector int_encoding int_encoding) - (int_lazy_vector int_encoding int_encoding) - (int_lazy_vector int_encoding int_encoding) + (Lazy_vector.IntVector.encoding int_encoding int_encoding) + (Lazy_vector.IntVector.encoding int_encoding int_encoding) + (Lazy_vector.IntVector.encoding int_encoding int_encoding) let proof_size proof = Data_encoding.Binary.length @@ -155,10 +155,12 @@ let test_move_and_read_subtrees () = let v = make_vector (fun x -> x) 5_000 in let* context, tree = prepare_context () in let from_encoding = - Tree_encoding.(scope ["from"] (int_lazy_vector int_encoding int_encoding)) + Tree_encoding.( + scope ["from"] (Lazy_vector.IntVector.encoding int_encoding int_encoding)) in let to_encoding = - Tree_encoding.(scope ["to"] (int_lazy_vector int_encoding int_encoding)) + Tree_encoding.( + scope ["to"] (Lazy_vector.IntVector.encoding int_encoding int_encoding)) in let* tree = Tree_encoding.encode from_encoding v tree in let* proof = @@ -181,7 +183,7 @@ let test_copy_subtrees () = let v = make_vector (fun x -> x) vec_size in let* context, tree = prepare_context () in let vec_encoding = - Tree_encoding.(int_lazy_vector int_encoding int_encoding) + Lazy_vector.IntVector.encoding int_encoding int_encoding in let* tree = Tree_encoding.encode diff --git a/src/lib_tree_encoding/tezos_tree_encoding.ml b/src/lib_tree_encoding/tezos_tree_encoding.ml index e6b46e1f6760e4cffba96d308a8cfcad2f8a62af..3470494a7ba2b64109f3cb392635f5230f9d6930 100644 --- a/src/lib_tree_encoding/tezos_tree_encoding.ml +++ b/src/lib_tree_encoding/tezos_tree_encoding.ml @@ -24,7 +24,6 @@ (* *) (*****************************************************************************) -open Tezos_lazy_containers include Tree exception Uninitialized_self_ref @@ -194,13 +193,36 @@ let value ?default key de = {encode = E.value key de; decode = D.value ?default key de} module Lazy_map_encoding = struct + module type Lazy_map_sig = sig + type key + + type 'a t + + type 'a producer = key -> 'a Lwt.t + + module Map : Stdlib.Map.S with type key = key + + val origin : 'a t -> wrapped_tree option + + val string_of_key : key -> string + + val loaded_bindings : 'a t -> (key * 'a option) list + + val create : + ?values:'a Map.t -> + ?produce_value:'a producer -> + ?origin:wrapped_tree -> + unit -> + 'a t + end + module type S = sig type 'a map val lazy_map : 'a t -> 'a map t end - module Make (Map : Lazy_map.S) = struct + module Make (Map : Lazy_map_sig) = struct let lazy_map value = let to_key k = [Map.string_of_key k] in let encode = @@ -219,96 +241,117 @@ module Lazy_map_encoding = struct end end -module Make_lazy_vector_encoding (Vector : Tezos_lazy_containers.Lazy_vector.S) = -struct - let lazy_vector with_key value = - let open Vector in - let to_key k = [string_of_key k] in - let encode = - E.contramap - (fun vector -> - ( (origin vector, loaded_bindings vector), - num_elements vector, - first_key vector )) - (E.tup3 - (E.scope ["contents"] (E.lazy_mapping to_key value.encode)) - (E.scope ["length"] with_key.encode) - (E.scope ["head"] with_key.encode)) - in - let decode = - D.map - (fun ((origin, produce_value), len, head) -> - create ~produce_value ~first_key:head ?origin len) - (let open D.Syntax in - let+ x = D.scope ["contents"] (D.lazy_mapping to_key value.decode) - and+ y = D.scope ["length"] with_key.decode - and+ z = D.scope ["head"] with_key.decode in - (x, y, z)) - in - {encode; decode} +module Lazy_vector_encoding = struct + module type Lazy_vector_sig = sig + type 'a t + + type key + + type 'a producer = key -> 'a Lwt.t + + module Map : Lazy_map_encoding.Lazy_map_sig with type key = key + + val origin : 'a t -> wrapped_tree option + + val string_of_key : key -> string + + val loaded_bindings : 'a t -> (key * 'a option) list + + val create : + ?first_key:key -> + ?values:'a Map.Map.t -> + ?produce_value:'a producer -> + ?origin:wrapped_tree -> + key -> + 'a t + + val num_elements : 'a t -> key + + val first_key : 'a t -> key + end + + module type S = sig + type 'a vector + + type key + + val lazy_vector : key t -> 'a t -> 'a vector t + end + + module Make (Vector : Lazy_vector_sig) = struct + let lazy_vector with_key value = + let to_key k = [Vector.string_of_key k] in + let encode = + E.contramap + (fun vector -> + ( (Vector.origin vector, Vector.loaded_bindings vector), + Vector.num_elements vector, + Vector.first_key vector )) + (E.tup3 + (E.scope ["contents"] (E.lazy_mapping to_key value.encode)) + (E.scope ["length"] with_key.encode) + (E.scope ["head"] with_key.encode)) + in + let decode = + D.map + (fun ((origin, produce_value), len, head) -> + Vector.create ~produce_value ~first_key:head ?origin len) + (let open D.Syntax in + let+ x = D.scope ["contents"] (D.lazy_mapping to_key value.decode) + and+ y = D.scope ["length"] with_key.decode + and+ z = D.scope ["head"] with_key.decode in + (x, y, z)) + in + {encode; decode} + end end -module Int_lazy_vector = Make_lazy_vector_encoding (Lazy_vector.IntVector) -module Int32_lazy_vector = Make_lazy_vector_encoding (Lazy_vector.Int32Vector) -module Int64_lazy_vector = Make_lazy_vector_encoding (Lazy_vector.Int64Vector) -module Z_lazy_vector = Make_lazy_vector_encoding (Lazy_vector.ZVector) +module CBV_encoding = struct + module type CBV_sig = sig + type t -let int_lazy_vector = Int_lazy_vector.lazy_vector + type chunk -let int32_lazy_vector = Int32_lazy_vector.lazy_vector + val origin : t -> wrapped_tree option -let int64_lazy_vector = Int64_lazy_vector.lazy_vector + val loaded_chunks : t -> (int64 * chunk option) list -let z_lazy_vector = Z_lazy_vector.lazy_vector + val length : t -> int64 -let chunk = - let open Chunked_byte_vector.Chunk in - conv of_bytes to_bytes (raw []) + val create : + ?origin:wrapped_tree -> ?get_chunk:(int64 -> chunk Lwt.t) -> int64 -> t + end -let chunked_byte_vector = - let open Chunked_byte_vector in - let to_key k = [Int64.to_string k] in - let encode = - E.contramap - (fun vector -> ((origin vector, loaded_chunks vector), length vector)) - (E.tup2 - (E.scope ["contents"] @@ E.lazy_mapping to_key chunk.encode) - (E.value ["length"] Data_encoding.int64)) - in - let decode = - D.map - (fun ((origin, get_chunk), len) -> create ?origin ~get_chunk len) - (let open D.Syntax in - let+ x = D.scope ["contents"] @@ D.lazy_mapping to_key chunk.decode - and+ y = D.value ["length"] Data_encoding.int64 in - (x, y)) - in - {encode; decode} + module type S = sig + type cbv -let immutable_chunk = - let open Immutable_chunked_byte_vector.Chunk in - conv of_bytes to_bytes (raw []) + type chunk -let immutable_chunked_byte_vector = - let open Immutable_chunked_byte_vector in - let to_key k = [Int64.to_string k] in - let encode = - E.contramap - (fun vector -> ((origin vector, loaded_chunks vector), length vector)) - (E.tup2 - (E.scope ["contents"] @@ E.lazy_mapping to_key immutable_chunk.encode) - (E.value ["length"] Data_encoding.int64)) - in - let decode = - D.map - (fun ((origin, get_chunk), len) -> create ?origin ~get_chunk len) - (let open D.Syntax in - let+ x = - D.scope ["contents"] @@ D.lazy_mapping to_key immutable_chunk.decode - and+ y = D.value ["length"] Data_encoding.int64 in - (x, y)) - in - {encode; decode} + val cbv : chunk t -> cbv t + end + + module Make (CBV : CBV_sig) = struct + let cbv chunk = + let to_key k = [Int64.to_string k] in + let encode = + E.contramap + (fun vector -> + ((CBV.origin vector, CBV.loaded_chunks vector), CBV.length vector)) + (E.tup2 + (E.scope ["contents"] @@ E.lazy_mapping to_key chunk.encode) + (E.value ["length"] Data_encoding.int64)) + in + let decode = + D.map + (fun ((origin, get_chunk), len) -> CBV.create ?origin ~get_chunk len) + (let open D.Syntax in + let+ x = D.scope ["contents"] @@ D.lazy_mapping to_key chunk.decode + and+ y = D.value ["length"] Data_encoding.int64 in + (x, y)) + in + {encode; decode} + end +end type ('tag, 'a) case = | Case : { @@ -397,9 +440,68 @@ let wrapped_tree : wrapped_tree t = {encode = E.wrapped_tree; decode = D.wrapped_tree} module Runner = struct + module type S = sig + type tree + + val encode : 'a t -> 'a -> tree -> tree Lwt.t + + val decode : 'a t -> tree -> 'a Lwt.t + end + module Make (T : TREE) = struct + type tree = T.tree + let encode {encode; _} value tree = E.run (module T) encode value tree let decode {decode; _} tree = D.run (module T) decode tree end end + +module Encodings_util = struct + module type Bare_tezos_context_sig = sig + type t + + type tree + + type index + + module Tree : + Tezos_context_sigs.Context.TREE + with type t := t + and type key := string list + and type value := bytes + and type tree := tree + + val init : + ?patch_context:(t -> t tzresult Lwt.t) -> + ?readonly:bool -> + ?index_log_size:int -> + string -> + index Lwt.t + + val empty : index -> t + end + + (* TREE instance for Tezos context *) + module Make (Ctx : Bare_tezos_context_sig) = struct + type Tree.tree_instance += Tree of Ctx.tree + + module Tree = struct + type tree = Ctx.tree + + include Ctx.Tree + + let select = function Tree t -> t | _ -> raise Incorrect_tree_type + + let wrap t = Tree t + end + + module Tree_encoding_runner = Runner.Make (Tree) + + let empty_tree () = + let open Lwt_syntax in + let* index = Ctx.init "/tmp" in + let empty_store = Ctx.empty index in + return @@ Ctx.Tree.empty empty_store + end +end diff --git a/src/lib_tree_encoding/tezos_tree_encoding.mli b/src/lib_tree_encoding/tezos_tree_encoding.mli index 5fed816cb849ebebfacf570c9b8bd959a2f3f3d9..66d01df6f9b147fbca9b4e5a5fff7195c2e9fa26 100644 --- a/src/lib_tree_encoding/tezos_tree_encoding.mli +++ b/src/lib_tree_encoding/tezos_tree_encoding.mli @@ -33,6 +33,8 @@ type key = string trace exception Key_not_found of key +type tree_instance = Tree.tree_instance = .. + (** {2 Types}*) (** Represents a partial encoder for a specific constructor of a sum-type. *) @@ -199,41 +201,6 @@ val value : ?default:'a -> key -> 'a Data_encoding.t -> 'a t branch [key]. *) val scope : key -> 'a t -> 'a t -module Lazy_map_encoding : sig - module type S = sig - type 'a map - - val lazy_map : 'a t -> 'a map t - end - - (** [Make (YouMap)] creates a module with the [lazy_map] - combinator which can be used to decode [YouMap] specifically. *) - module Make (Map : Tezos_lazy_containers.Lazy_map.S) : - S with type 'a map := 'a Map.t -end - -val int_lazy_vector : - int t -> 'a t -> 'a Tezos_lazy_containers.Lazy_vector.IntVector.t t - -val int32_lazy_vector : - int32 t -> 'a t -> 'a Tezos_lazy_containers.Lazy_vector.Int32Vector.t t - -val int64_lazy_vector : - int64 t -> 'a t -> 'a Tezos_lazy_containers.Lazy_vector.Int64Vector.t t - -val z_lazy_vector : - Z.t t -> 'a t -> 'a Tezos_lazy_containers.Lazy_vector.ZVector.t t - -(** [chunk] is an encoder for the chunks used by [chunked_by_vector]. *) -val chunk : Tezos_lazy_containers.Chunked_byte_vector.Chunk.t t - -(** [chunked_byte_vector] is an encoder for [chunked_byte_vector]. *) -val chunked_byte_vector : Tezos_lazy_containers.Chunked_byte_vector.t t - -(** [immutable_chunked_byte_vector] is an encoder for [immutable_chunked_byte_vector]. *) -val immutable_chunked_byte_vector : - Tezos_lazy_containers.Immutable_chunked_byte_vector.t t - (** [case tag enc inj proj] returns a partial encoder that represents a case in a sum-type. The encoder hides the (existentially bound) type of the parameter to the specific case, provided converter functions [inj] and @@ -277,9 +244,9 @@ module type TREE = sig type value := bytes (** @raise Incorrect_tree_type *) - val select : Tezos_lazy_containers.Lazy_map.tree -> tree + val select : Tree.tree_instance -> tree - val wrap : tree -> Tezos_lazy_containers.Lazy_map.tree + val wrap : tree -> Tree.tree_instance val remove : tree -> key -> tree Lwt.t @@ -307,14 +274,165 @@ module Wrapped : TREE with type tree = wrapped_tree val wrapped_tree : wrapped_tree t module Runner : sig - (** Builds a new runner for encoders using a specific tree. *) - module Make (T : TREE) : sig + module type S = sig + type tree + (** [encode enc x tree] encodes a value [x] using the encoder [enc] into the provided [tree]. *) - val encode : 'a t -> 'a -> T.tree -> T.tree Lwt.t + val encode : 'a t -> 'a -> tree -> tree Lwt.t (** [decode enc x tree] decodes a value using the encoder [enc] from the provided [tree]. *) - val decode : 'a t -> T.tree -> 'a Lwt.t + val decode : 'a t -> tree -> 'a Lwt.t + end + + (** Builds a new runner for encoders using a specific tree. *) + module Make (T : TREE) : S with type tree = T.tree +end + +module Encodings_util : sig + module type Bare_tezos_context_sig = sig + type t + + type tree + + type index + + module Tree : + Tezos_context_sigs.Context.TREE + with type t := t + and type key := string list + and type value := bytes + and type tree := tree + + val init : + ?patch_context:(t -> t tzresult Lwt.t) -> + ?readonly:bool -> + ?index_log_size:int -> + string -> + index Lwt.t + + val empty : index -> t end + + module Make (Ctx : Bare_tezos_context_sig) : sig + module Tree : sig + include module type of Ctx.Tree + + type tree = Ctx.tree + + val select : Tree.tree_instance -> tree + + val wrap : tree -> Tree.tree_instance + end + + module Tree_encoding_runner : Runner.S with type tree = Ctx.tree + + (* Create an empty tree *) + val empty_tree : unit -> Ctx.tree Lwt.t + end +end + +module Lazy_map_encoding : sig + module type Lazy_map_sig = sig + type key + + type 'a t + + type 'a producer = key -> 'a Lwt.t + + module Map : Stdlib.Map.S with type key = key + + val origin : 'a t -> wrapped_tree option + + val string_of_key : key -> string + + val loaded_bindings : 'a t -> (key * 'a option) list + + val create : + ?values:'a Map.t -> + ?produce_value:'a producer -> + ?origin:wrapped_tree -> + unit -> + 'a t + end + + module type S = sig + type 'a map + + val lazy_map : 'a t -> 'a map t + end + + (** [Make (YouMap)] creates a module with the [lazy_map] + combinator which can be used to decode [YouMap] specifically. *) + module Make (Map : Lazy_map_sig) : S with type 'a map := 'a Map.t +end + +module Lazy_vector_encoding : sig + module type Lazy_vector_sig = sig + type 'a t + + type key + + type 'a producer = key -> 'a Lwt.t + + module Map : Lazy_map_encoding.Lazy_map_sig with type key = key + + val origin : 'a t -> wrapped_tree option + + val string_of_key : key -> string + + val loaded_bindings : 'a t -> (key * 'a option) list + + val create : + ?first_key:key -> + ?values:'a Map.Map.t -> + ?produce_value:'a producer -> + ?origin:wrapped_tree -> + key -> + 'a t + + val num_elements : 'a t -> key + + val first_key : 'a t -> key + end + + module type S = sig + type 'a vector + + type key + + val lazy_vector : key t -> 'a t -> 'a vector t + end + + module Make (Vector : Lazy_vector_sig) : + S with type 'a vector := 'a Vector.t and type key := Vector.key +end + +module CBV_encoding : sig + module type CBV_sig = sig + type t + + type chunk + + val origin : t -> wrapped_tree option + + val loaded_chunks : t -> (int64 * chunk option) list + + val length : t -> int64 + + val create : + ?origin:wrapped_tree -> ?get_chunk:(int64 -> chunk Lwt.t) -> int64 -> t + end + + module type S = sig + type cbv + + type chunk + + val cbv : chunk t -> cbv t + end + + module Make (CBV : CBV_sig) : + S with type cbv := CBV.t and type chunk := CBV.chunk end diff --git a/src/lib_tree_encoding/tree.ml b/src/lib_tree_encoding/tree.ml index 297c7c02b8d91d7b914c8da15bd7b41c1e44d93a..58c4c0555bdc34bf2b2bfb55a5d9fb9a9513ed33 100644 --- a/src/lib_tree_encoding/tree.ml +++ b/src/lib_tree_encoding/tree.ml @@ -24,6 +24,8 @@ (* *) (*****************************************************************************) +type tree_instance = .. + type key = string list type value = bytes @@ -33,9 +35,9 @@ exception Incorrect_tree_type module type S = sig type tree - val select : Tezos_lazy_containers.Lazy_map.tree -> tree + val select : tree_instance -> tree - val wrap : tree -> Tezos_lazy_containers.Lazy_map.tree + val wrap : tree -> tree_instance val remove : tree -> key -> tree Lwt.t @@ -57,12 +59,10 @@ end type 'tree backend = (module S with type tree = 'tree) -let select : - type tree. tree backend -> Tezos_lazy_containers.Lazy_map.tree -> tree = +let select : type tree. tree backend -> tree_instance -> tree = fun (module T) tree -> T.select tree -let wrap : - type tree. tree backend -> tree -> Tezos_lazy_containers.Lazy_map.tree = +let wrap : type tree. tree backend -> tree -> tree_instance = fun (module T) tree -> T.wrap tree let remove : type tree. tree backend -> tree -> key -> tree Lwt.t = @@ -98,7 +98,7 @@ let list : type wrapped_tree = Wrapped_tree : 'tree * 'tree backend -> wrapped_tree -type Tezos_lazy_containers.Lazy_map.tree += Wrapped of wrapped_tree +type tree_instance += Wrapped of wrapped_tree module Wrapped : S with type tree = wrapped_tree = struct type tree = wrapped_tree diff --git a/src/lib_tree_encoding/tree.mli b/src/lib_tree_encoding/tree.mli index 48873f112af472d1ba7f0a4ea589f7ef61261791..f332eac1eb8c46c44ef0981aa47b60ff4ce82429 100644 --- a/src/lib_tree_encoding/tree.mli +++ b/src/lib_tree_encoding/tree.mli @@ -24,6 +24,11 @@ (* *) (*****************************************************************************) +(** An extensible type to record the type of trees used as a way to compare + backends during decoding/encoding. +*) +type tree_instance = .. + (** Exposes a module type {!S} representing trees. *) type key = string list @@ -37,9 +42,9 @@ module type S = sig type tree (** @raise Incorrect_tree_type *) - val select : Tezos_lazy_containers.Lazy_map.tree -> tree + val select : tree_instance -> tree - val wrap : tree -> Tezos_lazy_containers.Lazy_map.tree + val wrap : tree -> tree_instance val remove : tree -> key -> tree Lwt.t @@ -61,9 +66,9 @@ end type 'tree backend = (module S with type tree = 'tree) -val select : 'tree backend -> Tezos_lazy_containers.Lazy_map.tree -> 'tree +val select : 'tree backend -> tree_instance -> 'tree -val wrap : 'tree backend -> 'tree -> Tezos_lazy_containers.Lazy_map.tree +val wrap : 'tree backend -> 'tree -> tree_instance val remove : 'tree backend -> 'tree -> key -> 'tree Lwt.t diff --git a/src/lib_webassembly/runtime/durable_storage.ml b/src/lib_webassembly/runtime/durable_storage.ml index 82dc3ccaf8a008d0a22df469d10791ba0c386308..008789c87fb27667cf363cf90b951fc11d23592d 100644 --- a/src/lib_webassembly/runtime/durable_storage.ml +++ b/src/lib_webassembly/runtime/durable_storage.ml @@ -1,4 +1,4 @@ -type t = Tezos_lazy_containers.Lazy_map.tree option +type t = Tezos_tree_encoding.wrapped_tree option exception Durable_empty diff --git a/src/lib_webassembly/runtime/durable_storage.mli b/src/lib_webassembly/runtime/durable_storage.mli index 345234e20c857c730239dbb9ebf1e19afef85197..25ecd16ec580272a527d22fca9fad1cbe80172aa 100644 --- a/src/lib_webassembly/runtime/durable_storage.mli +++ b/src/lib_webassembly/runtime/durable_storage.mli @@ -5,9 +5,9 @@ exception Durable_empty val empty : t -val of_tree : Tezos_lazy_containers.Lazy_map.tree -> t +val of_tree : Tezos_tree_encoding.wrapped_tree -> t (** @raise Durable_empty *) -val to_tree_exn : t -> Tezos_lazy_containers.Lazy_map.tree +val to_tree_exn : t -> Tezos_tree_encoding.wrapped_tree -val to_tree : t -> Tezos_lazy_containers.Lazy_map.tree option +val to_tree : t -> Tezos_tree_encoding.wrapped_tree option diff --git a/src/proto_016_PtMumbai/lib_benchmarks_proto/sc_rollup_benchmarks.ml b/src/proto_016_PtMumbai/lib_benchmarks_proto/sc_rollup_benchmarks.ml index 7f1908e6ed28c5ea0054e327ae894ebafe006a4a..3d2ddcd056ee152e6f70ffb2dfa43ddfb35a345f 100644 --- a/src/proto_016_PtMumbai/lib_benchmarks_proto/sc_rollup_benchmarks.ml +++ b/src/proto_016_PtMumbai/lib_benchmarks_proto/sc_rollup_benchmarks.ml @@ -35,7 +35,7 @@ module Pvm_state_generator = struct module Context = Tezos_context_memory.Context_binary module Wasm_context = struct - type Tezos_lazy_containers.Lazy_map.tree += Tree of Context.tree + type Tezos_tree_encoding.tree_instance += Tree of Context.tree module Tree = struct include Context.Tree diff --git a/src/proto_016_PtMumbai/lib_sc_rollup_node/wasm_2_0_0_pvm.ml b/src/proto_016_PtMumbai/lib_sc_rollup_node/wasm_2_0_0_pvm.ml index bc9abdd67d5a632626c6bfd2e91fdab75eaba7d3..6266648dd1b7f8766ffedf2d4bb052591d4d06e7 100644 --- a/src/proto_016_PtMumbai/lib_sc_rollup_node/wasm_2_0_0_pvm.ml +++ b/src/proto_016_PtMumbai/lib_sc_rollup_node/wasm_2_0_0_pvm.ml @@ -51,7 +51,7 @@ module type TreeS = module Make_wrapped_tree (Tree : TreeS) : Tezos_tree_encoding.TREE with type tree = Tree.tree = struct - type Tezos_lazy_containers.Lazy_map.tree += PVM_tree of Tree.tree + type Tezos_tree_encoding.tree_instance += PVM_tree of Tree.tree include Tree diff --git a/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml index ebcc4814e753ba8917363aaad85062eb8e6286f3..a5b91d0c80ef21ea74827e1fc365b55ad048e01d 100644 --- a/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml @@ -35,7 +35,7 @@ module Pvm_state_generator = struct module Context = Tezos_context_memory.Context_binary module Wasm_context = struct - type Tezos_lazy_containers.Lazy_map.tree += Tree of Context.tree + type Tezos_tree_encoding.tree_instance += Tree of Context.tree module Tree = struct include Context.Tree diff --git a/src/proto_alpha/lib_sc_rollup_node/wasm_2_0_0_pvm.ml b/src/proto_alpha/lib_sc_rollup_node/wasm_2_0_0_pvm.ml index 9a7170774a955c00d4f75580ba043640b56514cc..cec950da02394ba8b35d7ebc6638b654633bcc39 100644 --- a/src/proto_alpha/lib_sc_rollup_node/wasm_2_0_0_pvm.ml +++ b/src/proto_alpha/lib_sc_rollup_node/wasm_2_0_0_pvm.ml @@ -51,7 +51,7 @@ module type TreeS = module Make_wrapped_tree (Tree : TreeS) : Tezos_tree_encoding.TREE with type tree = Tree.tree = struct - type Tezos_lazy_containers.Lazy_map.tree += PVM_tree of Tree.tree + type Tezos_tree_encoding.tree_instance += PVM_tree of Tree.tree include Tree