diff --git a/src/lib_protocol_environment/dummy_context.ml b/src/lib_protocol_environment/dummy_context.ml index 57148b40d96b1cc04eaeb58c5dc490b41aba08ae..50d175e2ad86139585a1c376daf2a0d7e0154c50 100644 --- a/src/lib_protocol_environment/dummy_context.ml +++ b/src/lib_protocol_environment/dummy_context.ml @@ -28,7 +28,7 @@ module M = struct type key = string list - type value = Bytes.t + type value = string type tree = | diff --git a/src/lib_protocol_environment/environment_V0.ml b/src/lib_protocol_environment/environment_V0.ml index 7e0e0314682363b43a21dcee4b52cab640e10194..49d683c03468cf855fa4e231da7c7067697c6133 100644 --- a/src/lib_protocol_environment/environment_V0.ml +++ b/src/lib_protocol_environment/environment_V0.ml @@ -866,9 +866,11 @@ struct module Context = struct include Context - let set = add + type value = bytes - let get = find + let set t k v = add t k (Bytes.unsafe_to_string v) + + let get t k = find t k >|= Option.map ~f:Bytes.unsafe_of_string let dir_mem = mem_tree diff --git a/src/lib_protocol_environment/environment_V1.ml b/src/lib_protocol_environment/environment_V1.ml index 10eada363cd7f29317b7be95ab20188f5643bf76..aa40fea03f8b2de38dbc7d8fe7d6e21e653f1517 100644 --- a/src/lib_protocol_environment/environment_V1.ml +++ b/src/lib_protocol_environment/environment_V1.ml @@ -1053,9 +1053,11 @@ struct module Context = struct include Context - let set = add + type value = bytes - let get = find + let set t k v = add t k (Bytes.unsafe_to_string v) + + let get t k = find t k >|= Option.map Bytes.unsafe_of_string let dir_mem = mem_tree diff --git a/src/lib_protocol_environment/environment_context.ml b/src/lib_protocol_environment/environment_context.ml index 21323951a5673d74faa9a02a654b73818e551e7d..304bc13ba7d6f30c0d7f9a3a78b4ee097ecd3a00 100644 --- a/src/lib_protocol_environment/environment_context.ml +++ b/src/lib_protocol_environment/environment_context.ml @@ -74,7 +74,7 @@ end module Context = struct type key = string list - type value = Bytes.t + type value = string type ('ctxt, 'tree) ops = (module CONTEXT with type t = 'ctxt and type tree = 'tree) diff --git a/src/lib_protocol_environment/environment_context_intf.ml b/src/lib_protocol_environment/environment_context_intf.ml index 2a1a7e89386f8fc517ec2dd6da95d6ebdf155b09..bf31de16ba09023d0041545d00e9b7b23c0e6435 100644 --- a/src/lib_protocol_environment/environment_context_intf.ml +++ b/src/lib_protocol_environment/environment_context_intf.ml @@ -35,7 +35,7 @@ module type TREE = sig end module type S = sig - include VIEW with type key = string list and type value = bytes + include VIEW with type key = string list and type value = string module Tree : TREE diff --git a/src/lib_protocol_environment/proxy_context.ml b/src/lib_protocol_environment/proxy_context.ml index b0c509514c93c835ed8a21c11c04a6b0769eeba9..691f24ca8e7083551dc39e2cd90d1408cd8177a2 100644 --- a/src/lib_protocol_environment/proxy_context.ml +++ b/src/lib_protocol_environment/proxy_context.ml @@ -30,7 +30,7 @@ module M = struct type value = Local.value - type tree = [`Value of bytes | `Tree of tree TzString.Map.t] + type tree = [`Value of value | `Tree of tree TzString.Map.t] module type ProxyDelegate = sig val proxy_dir_mem : key -> bool tzresult Lwt.t diff --git a/src/lib_protocol_environment/proxy_context.mli b/src/lib_protocol_environment/proxy_context.mli index 7ad4f8c7622a74a9159c034884d3d77f6775f3ee..4a815c497a2b635a38f412c67d81c796ae22a318 100644 --- a/src/lib_protocol_environment/proxy_context.mli +++ b/src/lib_protocol_environment/proxy_context.mli @@ -40,9 +40,9 @@ open Tezos_protocol_environment module M : sig type key = string list (* as in environment_context.mli *) - type value = Bytes.t (* as in environment_context.mli *) + type value = string (* as in environment_context.mli *) - type tree = [`Value of bytes | `Tree of tree TzString.Map.t] + type tree = [`Value of value | `Tree of tree TzString.Map.t] module type ProxyDelegate = sig (** Whether [mem] would return Some Dir _ *) diff --git a/src/lib_protocol_environment/sigs/v2/context.mli b/src/lib_protocol_environment/sigs/v2/context.mli index 7e521fdef38cf50dc8b5ffd3a1d9fa80a0d9f49d..65324ae30d67ae071a75f7612c692776d2991a3d 100644 --- a/src/lib_protocol_environment/sigs/v2/context.mli +++ b/src/lib_protocol_environment/sigs/v2/context.mli @@ -127,6 +127,8 @@ module type TREE = sig (** The type for context trees. *) type tree + include VIEW with type t := tree and type tree := tree + (** [empty _] is the empty tree. *) val empty : t -> tree @@ -135,7 +137,7 @@ module type TREE = sig (** [kind t] is [t]'s kind. It's either a tree node or a leaf value. *) - val kind : tree -> [`Value of bytes | `Tree] + val kind : tree -> [`Value of value | `Tree] (** [hash t] is [t]'s Merkle hash. *) val hash : tree -> Context_hash.t @@ -143,8 +145,6 @@ module type TREE = sig (** [equal x y] is true iff [x] and [y] have the same Merkle hash. *) val equal : tree -> tree -> bool - include VIEW with type t := tree and type tree := tree - (** {2 Caches} *) (** [clear ?depth t] clears all caches in the tree [t] for subtrees with a @@ -153,7 +153,7 @@ module type TREE = sig val clear : ?depth:int -> tree -> unit end -include VIEW with type key = string list and type value = bytes +include VIEW with type key = string list and type value = string module Tree : TREE diff --git a/src/lib_protocol_environment/test/test_mem_context.ml b/src/lib_protocol_environment/test/test_mem_context.ml index eb6064d333000853b537b57451a8c54b5e7a4d28..0d7549358d338adc1cc5fbbdea93eb80d0684c04 100644 --- a/src/lib_protocol_environment/test/test_mem_context.ml +++ b/src/lib_protocol_environment/test/test_mem_context.ml @@ -40,24 +40,18 @@ *) let create_block2 ctxt = - Context.add ctxt ["a"; "b"] (Bytes.of_string "Novembre") + Context.add ctxt ["a"; "b"] "Novembre" >>= fun ctxt -> - Context.add ctxt ["a"; "c"] (Bytes.of_string "Juin") - >>= fun ctxt -> - Context.add ctxt ["version"] (Bytes.of_string "0.0") - >>= fun ctxt -> Lwt.return ctxt + Context.add ctxt ["a"; "c"] "Juin" + >>= fun ctxt -> Context.add ctxt ["version"] "0.0" let create_block3a ctxt = Context.remove ctxt ["a"; "b"] - >>= fun ctxt -> - Context.add ctxt ["a"; "d"] (Bytes.of_string "Mars") - >>= fun ctxt -> Lwt.return ctxt + >>= fun ctxt -> Context.add ctxt ["a"; "d"] "Mars" let create_block3b ctxt = Context.remove ctxt ["a"; "c"] - >>= fun ctxt -> - Context.add ctxt ["a"; "d"] (Bytes.of_string "Février") - >>= fun ctxt -> Lwt.return ctxt + >>= fun ctxt -> Context.add ctxt ["a"; "d"] "Février" type t = { genesis : Context.t; @@ -78,8 +72,6 @@ let wrap_context_init f _ () = (** Simple test *) -let c = function None -> None | Some s -> Some (Bytes.to_string s) - (** Restore the context applied until [block2]. It is asserted that the following key-values are present: - (["version"], ["0.0"]) @@ -89,13 +81,13 @@ let c = function None -> None | Some s -> Some (Bytes.to_string s) let test_simple {block2 = ctxt; _} = Context.find ctxt ["version"] >>= fun version -> - Assert.equal_string_option ~msg:__LOC__ (c version) (Some "0.0") ; + Assert.equal_string_option ~msg:__LOC__ version (Some "0.0") ; Context.find ctxt ["a"; "b"] >>= fun novembre -> - Assert.equal_string_option (Some "Novembre") (c novembre) ; + Assert.equal_string_option (Some "Novembre") novembre ; Context.find ctxt ["a"; "c"] >>= fun juin -> - Assert.equal_string_option ~msg:__LOC__ (Some "Juin") (c juin) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Juin") juin ; Lwt.return_unit (** Restore the context applied until [block3a]. It is asserted that @@ -109,16 +101,16 @@ let test_simple {block2 = ctxt; _} = let test_continuation {block3a = ctxt; _} = Context.find ctxt ["version"] >>= fun version -> - Assert.equal_string_option ~msg:__LOC__ (Some "0.0") (c version) ; + Assert.equal_string_option ~msg:__LOC__ (Some "0.0") version ; Context.find ctxt ["a"; "b"] >>= fun novembre -> - Assert.is_none ~msg:__LOC__ (c novembre) ; + Assert.is_none ~msg:__LOC__ novembre ; Context.find ctxt ["a"; "c"] >>= fun juin -> - Assert.equal_string_option ~msg:__LOC__ (Some "Juin") (c juin) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Juin") juin ; Context.find ctxt ["a"; "d"] >>= fun mars -> - Assert.equal_string_option ~msg:__LOC__ (Some "Mars") (c mars) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Mars") mars ; Lwt.return_unit (** Restore the context applied until [block3b]. It is asserted that @@ -132,49 +124,49 @@ let test_continuation {block3a = ctxt; _} = let test_fork {block3b = ctxt; _} = Context.find ctxt ["version"] >>= fun version -> - Assert.equal_string_option ~msg:__LOC__ (Some "0.0") (c version) ; + Assert.equal_string_option ~msg:__LOC__ (Some "0.0") version ; Context.find ctxt ["a"; "b"] >>= fun novembre -> - Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") (c novembre) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") novembre ; Context.find ctxt ["a"; "c"] >>= fun juin -> - Assert.is_none ~msg:__LOC__ (c juin) ; + Assert.is_none ~msg:__LOC__ juin ; Context.find ctxt ["a"; "d"] >>= fun mars -> - Assert.equal_string_option ~msg:__LOC__ (Some "Février") (c mars) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Février") mars ; Lwt.return_unit (** Restore the context at [genesis] and explicitly replay setting/getting key-values. *) let test_replay {genesis = ctxt0; _} = - Context.add ctxt0 ["version"] (Bytes.of_string "0.0") + Context.add ctxt0 ["version"] "0.0" >>= fun ctxt1 -> - Context.add ctxt1 ["a"; "b"] (Bytes.of_string "Novembre") + Context.add ctxt1 ["a"; "b"] "Novembre" >>= fun ctxt2 -> - Context.add ctxt2 ["a"; "c"] (Bytes.of_string "Juin") + Context.add ctxt2 ["a"; "c"] "Juin" >>= fun ctxt3 -> - Context.add ctxt3 ["a"; "d"] (Bytes.of_string "July") + Context.add ctxt3 ["a"; "d"] "July" >>= fun ctxt4a -> - Context.add ctxt3 ["a"; "d"] (Bytes.of_string "Juillet") + Context.add ctxt3 ["a"; "d"] "Juillet" >>= fun ctxt4b -> - Context.add ctxt4a ["a"; "b"] (Bytes.of_string "November") + Context.add ctxt4a ["a"; "b"] "November" >>= fun ctxt5a -> Context.find ctxt4a ["a"; "b"] >>= fun novembre -> - Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") (c novembre) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") novembre ; Context.find ctxt5a ["a"; "b"] >>= fun november -> - Assert.equal_string_option ~msg:__LOC__ (Some "November") (c november) ; + Assert.equal_string_option ~msg:__LOC__ (Some "November") november ; Context.find ctxt5a ["a"; "d"] >>= fun july -> - Assert.equal_string_option ~msg:__LOC__ (Some "July") (c july) ; + Assert.equal_string_option ~msg:__LOC__ (Some "July") july ; Context.find ctxt4b ["a"; "b"] >>= fun novembre -> - Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") (c novembre) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") novembre ; Context.find ctxt4b ["a"; "d"] >>= fun juillet -> - Assert.equal_string_option ~msg:__LOC__ (Some "Juillet") (c juillet) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Juillet") juillet ; Lwt.return_unit let fold_keys s root ~init ~f = @@ -191,15 +183,15 @@ let keys t = fold_keys t ~init:[] ~f:(fun k acc -> Lwt.return (k :: acc)) of key prefixes using {!Context.fold}. *) let test_fold_keys {genesis = ctxt; _} = - Context.add ctxt ["a"; "b"] (Bytes.of_string "Novembre") + Context.add ctxt ["a"; "b"] "Novembre" >>= fun ctxt -> - Context.add ctxt ["a"; "c"] (Bytes.of_string "Juin") + Context.add ctxt ["a"; "c"] "Juin" >>= fun ctxt -> - Context.add ctxt ["a"; "d"; "e"] (Bytes.of_string "Septembre") + Context.add ctxt ["a"; "d"; "e"] "Septembre" >>= fun ctxt -> - Context.add ctxt ["f"] (Bytes.of_string "Avril") + Context.add ctxt ["f"] "Avril" >>= fun ctxt -> - Context.add ctxt ["g"; "h"] (Bytes.of_string "Avril") + Context.add ctxt ["g"; "h"] "Avril" >>= fun ctxt -> keys ctxt [] >>= fun l -> @@ -225,8 +217,8 @@ let test_fold_keys {genesis = ctxt; _} = Lwt.return_unit let test_fold {genesis = ctxt; _} = - let foo1 = Bytes.of_string "foo1" in - let foo2 = Bytes.of_string "foo2" in + let foo1 = "foo1" in + let foo2 = "foo2" in Context.add ctxt ["foo"; "toto"] foo1 >>= fun ctxt -> Context.add ctxt ["foo"; "bar"; "toto"] foo2 @@ -288,7 +280,7 @@ let steps = [@@ocamlformat "disable"] let bindings = - let zero = Bytes.make 10 '0' in + let zero = Bytes.make 10 '0' |> Bytes.unsafe_to_string in List.map (fun x -> (["root"; x], zero)) steps let test_fold_order {genesis = ctxt; _} = @@ -313,8 +305,8 @@ let test_trees {genesis = ctxt; _} = assert (List.length k = 1) ; Assert.fail_msg "empty") >>= fun () -> - let foo1 = Bytes.of_string "foo1" in - let foo2 = Bytes.of_string "foo2" in + let foo1 = "foo1" in + let foo2 = "foo2" in Context.Tree.empty ctxt |> fun v1 -> Context.Tree.add v1 ["foo"; "toto"] foo1 @@ -361,10 +353,10 @@ let test_trees {genesis = ctxt; _} = >>= fun v1 -> Context.Tree.find v1 ["foo"; "bar"; "toto"] >>= fun v -> - Assert.equal_bytes_option ~msg:__LOC__ None v ; + Assert.equal_string_option ~msg:__LOC__ None v ; Context.Tree.find v1 ["foo"; "toto"] >>= fun v -> - Assert.equal_bytes_option ~msg:__LOC__ (Some foo1) v ; + Assert.equal_string_option ~msg:__LOC__ (Some foo1) v ; Context.Tree.empty ctxt |> fun v1 -> Context.Tree.add v1 ["foo"; "1"] foo1 @@ -377,7 +369,7 @@ let test_trees {genesis = ctxt; _} = >>= fun v1 -> Context.Tree.find v1 ["foo"; "1"] >>= fun v -> - Assert.equal_bytes_option ~msg:__LOC__ None v ; + Assert.equal_string_option ~msg:__LOC__ None v ; Context.Tree.remove v1 [] >>= fun v1 -> Assert.equal_bool ~msg:__LOC__ true (Context.Tree.is_empty v1) ; @@ -431,7 +423,7 @@ let check_eq_domains d1 d2 = Assert.equal ~eq ~prn:PP.domain_to_string d1 d2 let test_domain0 () = - let b0 = Bytes.of_string "0" in + let b0 = "0" in let k1 = ["a"] in let k2 = ["b"] in let k3 = ["c"] in @@ -450,7 +442,7 @@ let test_domain0 () = Lwt.return_unit let test_domain1 () = - let b0 = Bytes.of_string "0" in + let b0 = "0" in let k1 = ["a"; "b"] in let k2 = ["a"; "c"; "d"] in let ctxt = Memory_context.empty in @@ -466,7 +458,7 @@ let test_domain1 () = Lwt.return_unit let test_domain2 () = - let b0 = Bytes.of_string "0" in + let b0 = "0" in let k1 = ["a"; "b"] in let k2 = ["a"; "c"; "d"] in let k3 = ["a"; "c"; "e"] in diff --git a/src/lib_protocol_environment/test/test_mem_context_array_theory.ml b/src/lib_protocol_environment/test/test_mem_context_array_theory.ml index 9db7b8e2cc5b610ccf3db96f36e198330f08538e..60895c4c4c89712f4ed6b671898537e3ed2c099f 100644 --- a/src/lib_protocol_environment/test/test_mem_context_array_theory.ml +++ b/src/lib_protocol_environment/test/test_mem_context_array_theory.ml @@ -74,7 +74,7 @@ let key_gen mode = let value_gen = let open Crowbar in - map [bytes] Bytes.of_string + bytes let key_value_gen kmode = let open Crowbar in @@ -163,7 +163,7 @@ let test_get_set (ctxt, (k, v)) = Crowbar.check_eq at_k v let value_opt ppf value_opt = - let ppv ppf v = Format.fprintf ppf "%s" @@ Bytes.to_string v in + let ppv ppf v = Format.fprintf ppf "%s" v in Format.pp_print_option ppv ppf value_opt (* Tests that: forall k2 <> k1, (get (set m k1 v) k2) equals get m k2; diff --git a/src/lib_proxy/proxy_getter.ml b/src/lib_proxy/proxy_getter.ml index 52a1d69d76b056888360ed7105ba655b733fc73b..dfb9434152593939fa367987f60e91e93d6adae3 100644 --- a/src/lib_proxy/proxy_getter.ml +++ b/src/lib_proxy/proxy_getter.ml @@ -65,8 +65,8 @@ let rec raw_context_to_tree (raw : Tezos_shell_services.Block_services.raw_context) : Proxy_context.M.tree option = match raw with - | Key (bytes : Bytes.t) -> - Some (`Value bytes) + | Key (v : string) -> + Some (`Value v) | Cut -> None | Dir pairs -> diff --git a/src/lib_proxy/test/test_proxy.ml b/src/lib_proxy/test/test_proxy.ml index 34b76cd0a3ec6ca65523d0838403ac94fc818450..016b991008b6f4c7b33586651b7a73b2a9460d4a 100644 --- a/src/lib_proxy/test/test_proxy.ml +++ b/src/lib_proxy/test/test_proxy.ml @@ -74,7 +74,7 @@ let mock_proto_rpc () = in let rec mock_tree = function | [] -> - `Value Bytes.empty + `Value "" | hd :: tail -> `Tree (StringMap.add hd (mock_tree tail) StringMap.empty) in diff --git a/src/lib_shell/patch_context.ml b/src/lib_shell/patch_context.ml index d4e9e5f580caa66e35147a00e74bbc1e9a4eb737..5ea17b35b08a09f990d3cd0bd376bfcf12e50a4e 100644 --- a/src/lib_shell/patch_context.ml +++ b/src/lib_shell/patch_context.ml @@ -29,10 +29,9 @@ let patch_context (genesis : Genesis.t) key_json ctxt = | None -> Lwt.return ctxt | Some (key, json) -> - Tezos_storage.Context.add - ctxt - [key] - (Data_encoding.Binary.to_bytes_exn Data_encoding.json json) ) + let v = Data_encoding.Binary.to_bytes_exn Data_encoding.json json in + let v = Bytes.unsafe_to_string v in + Tezos_storage.Context.add ctxt [key] v ) >>= fun ctxt -> Registered_protocol.get_result genesis.protocol >>=? fun proto -> diff --git a/src/lib_shell_benchmarks/io_benchmarks.ml b/src/lib_shell_benchmarks/io_benchmarks.ml index b9f07685842e8e82cfe7bb5fabded4ed5374d49c..7c4202b88e0ccdfd27fbc213d553181f6cfb62ec 100644 --- a/src/lib_shell_benchmarks/io_benchmarks.ml +++ b/src/lib_shell_benchmarks/io_benchmarks.ml @@ -359,8 +359,8 @@ module Context_size_dependent_write_bench : Benchmark.S = struct cfg.commit_batch_size keys in - let bytes = Base_samplers.uniform_bytes rng_state ~nbytes:value_size in - let context = write_storage context random_key bytes in + let str = Base_samplers.uniform_string rng_state ~nbytes:value_size in + let context = write_storage context random_key str in let finalizer () = Gc.compact () ; Lwt_main.run @@ -772,10 +772,10 @@ module Irmin_pack_write_bench : Benchmark.S = struct let context = List.fold_left (fun context key -> - let bytes = - Base_samplers.uniform_bytes rng_state ~nbytes:value_size + let str = + Base_samplers.uniform_string rng_state ~nbytes:value_size in - write_storage context key bytes) + write_storage context key str) context keys_written_to in @@ -1044,10 +1044,10 @@ module Write_random_keys_bench : Benchmark.S = struct let context = List.fold_left (fun context (key, _) -> - let bytes = - Base_samplers.uniform_bytes rng_state ~nbytes:value_size + let str = + Base_samplers.uniform_string rng_state ~nbytes:value_size in - write_storage context key bytes) + write_storage context key str) context keys_written_to in diff --git a/src/lib_shell_benchmarks/io_helpers.ml b/src/lib_shell_benchmarks/io_helpers.ml index 30e0556398c600a76f972d273714c87877264865..6d910aa4b8ef2875c920e8173e0d12b1f5278b51 100644 --- a/src/lib_shell_benchmarks/io_helpers.ml +++ b/src/lib_shell_benchmarks/io_helpers.ml @@ -106,8 +106,8 @@ let prepare_base_dir base_dir = (* This function updates the context with random bytes at a given depth. *) let initialize_key rng_state context path storage_size = - let bytes = Base_samplers.uniform_bytes rng_state ~nbytes:storage_size in - Tezos_protocol_environment.Context.add context path bytes + let str = Base_samplers.uniform_string rng_state ~nbytes:storage_size in + Tezos_protocol_environment.Context.add context path str let commit_and_reload base_dir index context = commit context diff --git a/src/lib_shell_benchmarks/io_stats.ml b/src/lib_shell_benchmarks/io_stats.ml index 27f53e80a86e95e34da3673cff2ebba814aee1c3..23f465f0c3a1edae9d4e41bde2a948bdf3d63b88 100644 --- a/src/lib_shell_benchmarks/io_stats.ml +++ b/src/lib_shell_benchmarks/io_stats.ml @@ -93,8 +93,8 @@ let load_tree context key = ~init:Io_helpers.Key_map.empty ~f:(fun path t tree -> match Context.Tree.kind t with - | `Value bytes -> - let len = Bytes.length bytes in + | `Value str -> + let len = String.length str in Lwt.return (Io_helpers.Key_map.insert path len tree) | `Tree -> Lwt.return tree) diff --git a/src/lib_shell_services/block_services.ml b/src/lib_shell_services/block_services.ml index cce1e7a8cca137d01a38a6f0ee6f0ebfe5c3bc24..1e29992960584bc28f8f28bd5c91a22037a2ebe0 100644 --- a/src/lib_shell_services/block_services.ml +++ b/src/lib_shell_services/block_services.ml @@ -196,13 +196,13 @@ let operation_list_quota_encoding = (fun (max_size, max_op) -> {max_size; max_op}) (obj2 (req "max_size" int31) (opt "max_op" int31)) -type raw_context = Key of Bytes.t | Dir of (string * raw_context) list | Cut +type raw_context = Key of string | Dir of (string * raw_context) list | Cut let rec pp_raw_context ppf = function | Cut -> Format.fprintf ppf "..." | Key v -> - Hex.pp ppf (Hex.of_bytes v) + Hex.pp ppf (Hex.of_string v) | Dir l -> Format.fprintf ppf @@ -216,7 +216,7 @@ let raw_context_encoding = union [ case (Tag 0) - bytes + string ~title:"Key" (function Key k -> Some k | _ -> None) (fun k -> Key k); diff --git a/src/lib_shell_services/block_services.mli b/src/lib_shell_services/block_services.mli index 4842d5fd247adff3c625c40915147452a8f9d676..aaa7dc4e13456bb02cce2f8ad64b1fe9227d09b4 100644 --- a/src/lib_shell_services/block_services.mli +++ b/src/lib_shell_services/block_services.mli @@ -58,7 +58,7 @@ val live_blocks_path : ('a, 'b) RPC_path.t -> ('a, 'b) RPC_path.t type operation_list_quota = {max_size : int; max_op : int option} -type raw_context = Key of Bytes.t | Dir of (string * raw_context) list | Cut +type raw_context = Key of string | Dir of (string * raw_context) list | Cut val pp_raw_context : Format.formatter -> raw_context -> unit diff --git a/src/lib_storage/context.ml b/src/lib_storage/context.ml index 6d1fd6ec1d8260a8ce1de481c9ddda772e35c95b..f7978b8f902f5d06b0d8b80c5e4bb2808d0980e5 100644 --- a/src/lib_storage/context.ml +++ b/src/lib_storage/context.ml @@ -214,7 +214,7 @@ let data_key key = current_data_key @ key type key = string list -type value = bytes +type value = string type tree = Store.tree @@ -257,10 +257,10 @@ let get_protocol v = | None -> assert false | Some data -> - Lwt.return (Protocol_hash.of_bytes_exn data) + Lwt.return (Protocol_hash.of_string_exn data) let add_protocol v key = - let key = Protocol_hash.to_bytes key in + let key = Protocol_hash.to_string key in raw_add v current_protocol_key key let get_test_chain v = @@ -269,7 +269,11 @@ let get_test_chain v = | None -> Lwt.fail (Failure "Unexpected error (Context.get_test_chain)") | Some data -> ( - match Data_encoding.Binary.of_bytes Test_chain_status.encoding data with + match + Data_encoding.Binary.of_bytes + Test_chain_status.encoding + (Bytes.unsafe_of_string data) + with | Error re -> Format.kasprintf (fun s -> Lwt.fail (Failure s)) @@ -281,7 +285,7 @@ let get_test_chain v = let add_test_chain v id = let id = Data_encoding.Binary.to_bytes_exn Test_chain_status.encoding id in - raw_add v current_test_chain_key id + raw_add v current_test_chain_key (Bytes.unsafe_to_string id) let remove_test_chain v = raw_remove v current_test_chain_key @@ -295,7 +299,9 @@ let find_predecessor_block_metadata_hash v = Lwt.return_none | Some data -> ( match - Data_encoding.Binary.of_bytes_opt Block_metadata_hash.encoding data + Data_encoding.Binary.of_bytes_opt + Block_metadata_hash.encoding + (Bytes.unsafe_of_string data) with | None -> Lwt.fail @@ -308,7 +314,10 @@ let add_predecessor_block_metadata_hash v hash = let data = Data_encoding.Binary.to_bytes_exn Block_metadata_hash.encoding hash in - raw_add v current_predecessor_block_metadata_hash_key data + raw_add + v + current_predecessor_block_metadata_hash_key + (Bytes.unsafe_to_string data) let find_predecessor_ops_metadata_hash v = raw_find v current_predecessor_ops_metadata_hash_key @@ -319,7 +328,7 @@ let find_predecessor_ops_metadata_hash v = match Data_encoding.Binary.of_bytes_opt Operation_metadata_list_list_hash.encoding - data + (Bytes.unsafe_of_string data) with | None -> Lwt.fail @@ -334,7 +343,10 @@ let add_predecessor_ops_metadata_hash v hash = Operation_metadata_list_list_hash.encoding hash in - raw_add v current_predecessor_ops_metadata_hash_key data + raw_add + v + current_predecessor_ops_metadata_hash_key + (Bytes.unsafe_to_string data) (*-- Initialisation ----------------------------------------------------------*) @@ -625,15 +637,15 @@ module Dumpable_context = struct conv (function | `Blob h -> - (`Blob, Context_hash.to_bytes (Hash.to_context_hash h)) + (`Blob, Context_hash.to_string (Hash.to_context_hash h)) | `Node h -> - (`Node, Context_hash.to_bytes (Hash.to_context_hash h))) + (`Node, Context_hash.to_string (Hash.to_context_hash h))) (function | (`Blob, h) -> - `Blob (Hash.of_context_hash (Context_hash.of_bytes_exn h)) + `Blob (Hash.of_context_hash (Context_hash.of_string_exn h)) | (`Node, h) -> - `Node (Hash.of_context_hash (Context_hash.of_bytes_exn h))) - (obj2 (req "kind" kind_encoding) (req "value" bytes)) + `Node (Hash.of_context_hash (Context_hash.of_string_exn h))) + (obj2 (req "kind" kind_encoding) (req "value" string)) let hash_equal (h1 : hash) (h2 : hash) = h1 = h2 @@ -760,7 +772,7 @@ module Dumpable_context = struct | Some t -> Store.Tree.add_tree tree key (t :> tree) >>= Lwt.return_some - let add_bytes (Batch (_, t, _)) b = + let add_string (Batch (_, t, _)) b = (* Save the contents in the store *) Store.save_contents t b >|= fun _ -> Store.Tree.of_contents b @@ -843,9 +855,10 @@ let validate_context_hash_consistency_and_commit ~data_hash ~predecessor_ops_metadata_hash ~index = let data_hash = Hash.of_context_hash data_hash in let parents = List.map Hash.of_context_hash parents in - let protocol_value = Protocol_hash.to_bytes protocol_hash in + let protocol_value = Protocol_hash.to_string protocol_hash in let test_chain_value = Data_encoding.Binary.to_bytes_exn Test_chain_status.encoding test_chain + |> Bytes.unsafe_to_string in let tree = Store.Tree.empty in Store.Tree.add tree current_protocol_key protocol_value @@ -855,7 +868,7 @@ let validate_context_hash_consistency_and_commit ~data_hash ( match predecessor_block_metadata_hash with | Some predecessor_block_metadata_hash -> let predecessor_block_metadata_hash_value = - Block_metadata_hash.to_bytes predecessor_block_metadata_hash + Block_metadata_hash.to_string predecessor_block_metadata_hash in Store.Tree.add tree @@ -867,7 +880,7 @@ let validate_context_hash_consistency_and_commit ~data_hash ( match predecessor_ops_metadata_hash with | Some predecessor_ops_metadata_hash -> let predecessor_ops_metadata_hash_value = - Operation_metadata_list_list_hash.to_bytes + Operation_metadata_list_list_hash.to_string predecessor_ops_metadata_hash in Store.Tree.add diff --git a/src/lib_storage/context_dump.ml b/src/lib_storage/context_dump.ml index 9aa1dd145299d5017bce2dfdd344077fec0e2de0..7f669b2bad3a9a45800b9aac0a6346e474e857ac 100644 --- a/src/lib_storage/context_dump.ml +++ b/src/lib_storage/context_dump.ml @@ -169,7 +169,7 @@ module Make (I : Dump_interface) = struct pred_ops_metadata_hashes : Operation_metadata_hash.t list list option; } | Node of (string * I.hash) list - | Blob of bytes + | Blob of string | Proot of I.Pruned_block.t | Loot of I.Protocol_data.t | End @@ -181,7 +181,7 @@ module Make (I : Dump_interface) = struct case ~title:"blob" (Tag (Char.code 'b')) - bytes + string (function Blob b -> Some b | _ -> None) (function b -> Blob b) @@ -566,7 +566,7 @@ module Make (I : Dump_interface) = struct let read = ref 0 in let rbuf = ref (fd, Bytes.empty, 0, read) in (* Editing the repository *) - let add_blob t blob = I.add_bytes t blob >>= fun tree -> return tree in + let add_blob t blob = I.add_string t blob >>= fun tree -> return tree in let add_dir t keys = I.add_dir t keys >>= function diff --git a/src/lib_storage/context_dump_intf.ml b/src/lib_storage/context_dump_intf.ml index b001923fae6c0a6cb0ca3ce2ec1018a515ea6538..8a301aab21282fa8af59d4c15aeb7fb207d207e1 100644 --- a/src/lib_storage/context_dump_intf.ml +++ b/src/lib_storage/context_dump_intf.ml @@ -35,7 +35,7 @@ module type Dump_interface = sig type hash - type contents := bytes + type contents := string type step := string @@ -141,7 +141,7 @@ module type Dump_interface = sig val update_context : context -> tree -> context - val add_bytes : batch -> bytes -> tree Lwt.t + val add_string : batch -> string -> tree Lwt.t val add_dir : batch -> (step * hash) list -> tree option Lwt.t end diff --git a/src/lib_storage/encoding/context.ml b/src/lib_storage/encoding/context.ml index 48cb996501d9e29c025b67c14235e6d0110390b0..24a3cb5d1994233ad2a13227bb7e5a1a58debda9 100644 --- a/src/lib_storage/encoding/context.ml +++ b/src/lib_storage/encoding/context.ml @@ -152,15 +152,15 @@ module Commit = struct end module Contents = struct - type t = bytes + type t = string - let ty = Irmin.Type.(pair (bytes_of `Int64) unit) + let ty = Irmin.Type.(pair (string_of `Int64) unit) let pre_hash_ty = Irmin.Type.(unstage (pre_hash ty)) let pre_hash_v1 x = pre_hash_ty (x, ()) - let t = Irmin.Type.(like bytes ~pre_hash:(stage @@ fun x -> pre_hash_v1 x)) + let t = Irmin.Type.(like string ~pre_hash:(stage @@ fun x -> pre_hash_v1 x)) let merge = Irmin.Merge.(idempotent (Irmin.Type.option t)) end diff --git a/src/lib_storage/encoding/context.mli b/src/lib_storage/encoding/context.mli index f4d642474501275b370837cd0f03389e010f6f89..2c244821751e7f797889ec05b7556ec882ee4c77 100644 --- a/src/lib_storage/encoding/context.mli +++ b/src/lib_storage/encoding/context.mli @@ -33,7 +33,7 @@ module Hash : sig val of_context_hash : Context_hash.t -> t end -module Contents : Irmin.Contents.S with type t = bytes +module Contents : Irmin.Contents.S with type t = string module Metadata : Irmin.Metadata.S with type t = unit diff --git a/src/lib_storage/helpers/context.ml b/src/lib_storage/helpers/context.ml index c0fea728b768354ed41143f3326f9db0b312c530..4d507b26b5af02477235cbae1bc6de29c6c50b52 100644 --- a/src/lib_storage/helpers/context.ml +++ b/src/lib_storage/helpers/context.ml @@ -72,7 +72,7 @@ module Make_tree (Store : DB) = struct t init - type raw = [`Value of bytes | `Tree of raw TzString.Map.t] + type raw = [`Value of string | `Tree of raw TzString.Map.t] type concrete = Store.Tree.concrete @@ -135,7 +135,7 @@ module Make_tree (Store : DB) = struct case ~title:"value" (Tag 1) - bytes + string (function `Value v -> Some v | `Tree _ -> None) (fun v -> `Value v) ]) end diff --git a/src/lib_storage/helpers/context.mli b/src/lib_storage/helpers/context.mli index 095cb4153e35ac38b0afd3abc8ea8df76d4a3300..d5a3d84b6425c6b30b7cba2bf1fe8969d19de3d4 100644 --- a/src/lib_storage/helpers/context.mli +++ b/src/lib_storage/helpers/context.mli @@ -40,12 +40,12 @@ module Make_tree (DB : DB) : sig Tezos_storage_sigs.Context.TREE with type t := DB.t and type key := string list - and type value := bytes + and type value := DB.contents and type tree := DB.tree val empty : _ -> DB.tree - type raw = [`Value of bytes | `Tree of raw TzString.Map.t] + type raw = [`Value of DB.contents | `Tree of raw TzString.Map.t] val raw_encoding : raw Data_encoding.t diff --git a/src/lib_storage/memory/context.ml b/src/lib_storage/memory/context.ml index 00442991dcf4a9255102531d8e1cd558e6e47d32..34bf3d3b80119fb20ce7c95b0276f345e9dcefaf 100644 --- a/src/lib_storage/memory/context.ml +++ b/src/lib_storage/memory/context.ml @@ -34,9 +34,9 @@ type t = Store.tree type tree = t -type key = string list +type key = Path.t -type value = bytes +type value = Contents.t module Tree = Tezos_storage_helpers.Context.Make_tree (Store) include Tree @@ -69,10 +69,10 @@ let get_protocol t = | None -> assert false | Some data -> - Lwt.return (Protocol_hash.of_bytes_exn data) + Lwt.return (Protocol_hash.of_string_exn data) let add_protocol t key = - let key = Protocol_hash.to_bytes key in + let key = Protocol_hash.to_string key in Tree.add t current_protocol_key key let empty = Store.Tree.empty @@ -91,7 +91,7 @@ let concrete_encoding : Store.Tree.concrete Data_encoding.t = case ~title:"value" (Tag 1) - bytes + string (function `Contents (v, _) -> Some v | `Tree _ -> None) (fun v -> `Contents (v, ())) ]) diff --git a/src/lib_storage/sigs/context.ml b/src/lib_storage/sigs/context.ml index 192e345457d148b727fe9184fae4c8b78ef6cbaf..dce3dfa1d29f6899f89b93e17d3ed3ed0c857fda 100644 --- a/src/lib_storage/sigs/context.ml +++ b/src/lib_storage/sigs/context.ml @@ -124,6 +124,8 @@ module type TREE = sig (** The type for context trees. *) type tree + include VIEW with type t := tree and type tree := tree + (** [empty _] is the empty tree. *) val empty : t -> tree @@ -132,7 +134,7 @@ module type TREE = sig (** [kind t] is [t]'s kind. It's either a tree node or a leaf value. *) - val kind : tree -> [`Value of bytes | `Tree] + val kind : tree -> [`Value of value | `Tree] (** [hash t] is [t]'s Merkle hash. *) val hash : tree -> Context_hash.t @@ -140,8 +142,6 @@ module type TREE = sig (** [equal x y] is true iff [x] and [y] have the same Merkle hash. *) val equal : tree -> tree -> bool - include VIEW with type t := tree and type tree := tree - (** {2 Caches} *) (** [clear ?depth t] clears all caches in the tree [t] for subtrees with a @@ -151,7 +151,7 @@ module type TREE = sig end module type S = sig - include VIEW with type key = string list and type value = bytes + include VIEW with type key = string list and type value = string module Tree : sig include @@ -164,7 +164,7 @@ module type S = sig (** {2 Data Encoding} *) (** The type for in-memory, raw contexts. *) - type raw = [`Value of bytes | `Tree of raw TzString.Map.t] + type raw = [`Value of value | `Tree of raw TzString.Map.t] (** [raw_encoding] is the data encoding for raw trees. *) val raw_encoding : raw Data_encoding.t diff --git a/src/lib_storage/test/assert.ml b/src/lib_storage/test/assert.ml index 0d05047a48c2eee4e9a5ddbf9c9ed291746f82e1..1b70bbe4424af15fe2c4f5576aafe98c12b7e768 100644 --- a/src/lib_storage/test/assert.ml +++ b/src/lib_storage/test/assert.ml @@ -111,15 +111,14 @@ let equal_raw_tree ?(msg = "") r1 r2 = let rec aux r1 r2 = match (r1, r2) with | (`Value v1, `Value v2) -> - equal_string ~msg (Bytes.to_string v1) (Bytes.to_string v2) ; - true + equal_string ~msg v1 v2 ; true | (`Tree t1, `Tree t2) -> if not (TzString.Map.equal aux t1 t2) then fail "" "" msg ; true | (`Tree _, `Value v) -> - fail "" (Bytes.to_string v) msg + fail "" v msg | (`Value v, `Tree _) -> - fail "" (Bytes.to_string v) msg + fail "" v msg in let (_ : bool) = aux r1 r2 in () diff --git a/src/lib_storage/test/test_context.ml b/src/lib_storage/test/test_context.ml index 36a4a5b65e7b9ec556ebe3b7ed1591d54e2cbd46..5c3a435e1ca9c069b075f66b25a742598ab48814 100644 --- a/src/lib_storage/test/test_context.ml +++ b/src/lib_storage/test/test_context.ml @@ -71,11 +71,10 @@ let create_block2 idx genesis_commit = | None -> Assert.fail_msg "checkout genesis_block" | Some ctxt -> - add ctxt ["a"; "b"] (Bytes.of_string "Novembre") + add ctxt ["a"; "b"] "Novembre" >>= fun ctxt -> - add ctxt ["a"; "c"] (Bytes.of_string "Juin") - >>= fun ctxt -> - add ctxt ["version"] (Bytes.of_string "0.0") >>= fun ctxt -> commit ctxt + add ctxt ["a"; "c"] "Juin" + >>= fun ctxt -> add ctxt ["version"] "0.0" >>= commit let create_block3a idx block2_commit = checkout idx block2_commit @@ -84,8 +83,7 @@ let create_block3a idx block2_commit = Assert.fail_msg "checkout block2" | Some ctxt -> remove ctxt ["a"; "b"] - >>= fun ctxt -> - add ctxt ["a"; "d"] (Bytes.of_string "Mars") >>= fun ctxt -> commit ctxt + >>= fun ctxt -> add ctxt ["a"; "d"] "Mars" >>= commit let create_block3b idx block2_commit = checkout idx block2_commit @@ -94,9 +92,7 @@ let create_block3b idx block2_commit = Assert.fail_msg "checkout block3b" | Some ctxt -> remove ctxt ["a"; "c"] - >>= fun ctxt -> - add ctxt ["a"; "d"] (Bytes.of_string "Février") - >>= fun ctxt -> commit ctxt + >>= fun ctxt -> add ctxt ["a"; "d"] "Février" >>= commit type t = { idx : Context.index; @@ -126,8 +122,6 @@ let wrap_context_init f _ () = (** Simple test *) -let c = function None -> None | Some s -> Some (Bytes.to_string s) - (** Checkout the context applied until [block2]. It is asserted that the following key-values are present: - (["version"], ["0.0"]) @@ -141,13 +135,13 @@ let test_simple {idx; block2; _} = | Some ctxt -> find ctxt ["version"] >>= fun version -> - Assert.equal_string_option ~msg:__LOC__ (c version) (Some "0.0") ; + Assert.equal_string_option ~msg:__LOC__ version (Some "0.0") ; find ctxt ["a"; "b"] >>= fun novembre -> - Assert.equal_string_option (Some "Novembre") (c novembre) ; + Assert.equal_string_option (Some "Novembre") novembre ; find ctxt ["a"; "c"] >>= fun juin -> - Assert.equal_string_option ~msg:__LOC__ (Some "Juin") (c juin) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Juin") juin ; Lwt.return_unit let test_list {idx; block2; _} = @@ -177,16 +171,16 @@ let test_continuation {idx; block3a; _} = | Some ctxt -> find ctxt ["version"] >>= fun version -> - Assert.equal_string_option ~msg:__LOC__ (Some "0.0") (c version) ; + Assert.equal_string_option ~msg:__LOC__ (Some "0.0") version ; find ctxt ["a"; "b"] >>= fun novembre -> - Assert.is_none ~msg:__LOC__ (c novembre) ; + Assert.is_none ~msg:__LOC__ novembre ; find ctxt ["a"; "c"] >>= fun juin -> - Assert.equal_string_option ~msg:__LOC__ (Some "Juin") (c juin) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Juin") juin ; find ctxt ["a"; "d"] >>= fun mars -> - Assert.equal_string_option ~msg:__LOC__ (Some "Mars") (c mars) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Mars") mars ; Lwt.return_unit (** Checkout the context applied until [block3b]. It is asserted that @@ -204,16 +198,16 @@ let test_fork {idx; block3b; _} = | Some ctxt -> find ctxt ["version"] >>= fun version -> - Assert.equal_string_option ~msg:__LOC__ (Some "0.0") (c version) ; + Assert.equal_string_option ~msg:__LOC__ (Some "0.0") version ; find ctxt ["a"; "b"] >>= fun novembre -> - Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") (c novembre) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") novembre ; find ctxt ["a"; "c"] >>= fun juin -> - Assert.is_none ~msg:__LOC__ (c juin) ; + Assert.is_none ~msg:__LOC__ juin ; find ctxt ["a"; "d"] >>= fun mars -> - Assert.equal_string_option ~msg:__LOC__ (Some "Février") (c mars) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Février") mars ; Lwt.return_unit (** Checkout the context at [genesis] and explicitly replay @@ -224,33 +218,33 @@ let test_replay {idx; genesis; _} = | None -> Assert.fail_msg "checkout genesis_block" | Some ctxt0 -> - add ctxt0 ["version"] (Bytes.of_string "0.0") + add ctxt0 ["version"] "0.0" >>= fun ctxt1 -> - add ctxt1 ["a"; "b"] (Bytes.of_string "Novembre") + add ctxt1 ["a"; "b"] "Novembre" >>= fun ctxt2 -> - add ctxt2 ["a"; "c"] (Bytes.of_string "Juin") + add ctxt2 ["a"; "c"] "Juin" >>= fun ctxt3 -> - add ctxt3 ["a"; "d"] (Bytes.of_string "July") + add ctxt3 ["a"; "d"] "July" >>= fun ctxt4a -> - add ctxt3 ["a"; "d"] (Bytes.of_string "Juillet") + add ctxt3 ["a"; "d"] "Juillet" >>= fun ctxt4b -> - add ctxt4a ["a"; "b"] (Bytes.of_string "November") + add ctxt4a ["a"; "b"] "November" >>= fun ctxt5a -> find ctxt4a ["a"; "b"] >>= fun novembre -> - Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") (c novembre) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") novembre ; find ctxt5a ["a"; "b"] >>= fun november -> - Assert.equal_string_option ~msg:__LOC__ (Some "November") (c november) ; + Assert.equal_string_option ~msg:__LOC__ (Some "November") november ; find ctxt5a ["a"; "d"] >>= fun july -> - Assert.equal_string_option ~msg:__LOC__ (Some "July") (c july) ; + Assert.equal_string_option ~msg:__LOC__ (Some "July") july ; find ctxt4b ["a"; "b"] >>= fun novembre -> - Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") (c novembre) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Novembre") novembre ; find ctxt4b ["a"; "d"] >>= fun juillet -> - Assert.equal_string_option ~msg:__LOC__ (Some "Juillet") (c juillet) ; + Assert.equal_string_option ~msg:__LOC__ (Some "Juillet") juillet ; Lwt.return_unit let fold_keys s root ~init ~f = @@ -285,7 +279,7 @@ let steps = [@@ocamlformat "disable"] let bindings = - let zero = Bytes.make 10 '0' in + let zero = Bytes.make 10 '0' |> Bytes.unsafe_to_string in List.map (fun x -> (["root"; x], zero)) steps let test_fold_keys {idx; genesis; _} = @@ -294,15 +288,15 @@ let test_fold_keys {idx; genesis; _} = | None -> Assert.fail_msg "checkout genesis_block" | Some ctxt -> - add ctxt ["a"; "b"] (Bytes.of_string "Novembre") + add ctxt ["a"; "b"] "Novembre" >>= fun ctxt -> - add ctxt ["a"; "c"] (Bytes.of_string "Juin") + add ctxt ["a"; "c"] "Juin" >>= fun ctxt -> - add ctxt ["a"; "d"; "e"] (Bytes.of_string "Septembre") + add ctxt ["a"; "d"; "e"] "Septembre" >>= fun ctxt -> - add ctxt ["f"] (Bytes.of_string "Avril") + add ctxt ["f"] "Avril" >>= fun ctxt -> - add ctxt ["g"; "h"] (Bytes.of_string "Avril") + add ctxt ["g"; "h"] "Avril" >>= fun ctxt -> keys ctxt [] >>= fun l -> @@ -345,8 +339,8 @@ let test_fold {idx; genesis; _} = | None -> Assert.fail_msg "checkout genesis_block" | Some ctxt -> - let foo1 = Bytes.of_string "foo1" in - let foo2 = Bytes.of_string "foo2" in + let foo1 = "foo1" in + let foo2 = "foo2" in add ctxt ["foo"; "toto"] foo1 >>= fun ctxt -> add ctxt ["foo"; "bar"; "toto"] foo2 @@ -394,8 +388,8 @@ let test_trees {idx; genesis; _} = assert (List.length k = 1) ; Assert.fail_msg "empty") >>= fun () -> - let foo1 = Bytes.of_string "foo1" in - let foo2 = Bytes.of_string "foo2" in + let foo1 = "foo1" in + let foo2 = "foo2" in Tree.empty ctxt |> fun v1 -> Tree.add v1 ["foo"; "toto"] foo1 @@ -440,10 +434,10 @@ let test_trees {idx; genesis; _} = >>= fun v1 -> Tree.find v1 ["foo"; "bar"; "toto"] >>= fun v -> - Assert.equal_bytes_option ~msg:__LOC__ None v ; + Assert.equal_string_option ~msg:__LOC__ None v ; Tree.find v1 ["foo"; "toto"] >>= fun v -> - Assert.equal_bytes_option ~msg:__LOC__ (Some foo1) v ; + Assert.equal_string_option ~msg:__LOC__ (Some foo1) v ; Tree.empty ctxt |> fun v1 -> Tree.add v1 ["foo"; "1"] foo1 @@ -456,7 +450,7 @@ let test_trees {idx; genesis; _} = >>= fun v1 -> Tree.find v1 ["foo"; "1"] >>= fun v -> - Assert.equal_bytes_option ~msg:__LOC__ None v ; + Assert.equal_string_option ~msg:__LOC__ None v ; Tree.remove v1 [] >>= fun v1 -> Assert.equal_bool ~msg:__LOC__ true (Tree.is_empty v1) ; @@ -468,8 +462,8 @@ let test_raw {idx; genesis; _} = | None -> Assert.fail_msg "checkout genesis_block" | Some ctxt -> - let foo1 = Bytes.of_string "foo1" in - let foo2 = Bytes.of_string "foo2" in + let foo1 = "foo1" in + let foo2 = "foo2" in add ctxt ["foo"; "toto"] foo1 >>= fun ctxt -> add ctxt ["foo"; "bar"; "toto"] foo2 @@ -495,8 +489,8 @@ let test_encoding {idx; genesis; _} = | None -> Assert.fail_msg "checkout genesis_block" | Some ctxt -> - let foo1 = Bytes.of_string "foo1" in - let foo2 = Bytes.of_string "foo2" in + let foo1 = "foo1" in + let foo2 = "foo2" in add ctxt ["a"; string 7] foo1 >>= fun ctxt -> add ctxt ["a"; string 8] foo2 diff --git a/src/proto_006_PsCARTHA/lib_client/proxy.ml b/src/proto_006_PsCARTHA/lib_client/proxy.ml index b88a2ce405c3222a7b05b96c820c01118fcb70b6..e86b77b7b3813774d9e35c956fcb2910c2039d1a 100644 --- a/src/proto_006_PsCARTHA/lib_client/proxy.ml +++ b/src/proto_006_PsCARTHA/lib_client/proxy.ml @@ -110,10 +110,7 @@ let initial_context (rpc_context : RPC_context.json) end in let empty = Proxy_context.empty @@ Some (module N) in let version_value = "carthage_006" in - Tezos_protocol_environment.Context.add - empty - ["version"] - (Bytes.of_string version_value) + Tezos_protocol_environment.Context.add empty ["version"] version_value let init_env_rpc_context (_printer : Tezos_client_base.Client_context.printer) (rpc_context : RPC_context.json) diff --git a/src/proto_007_PsDELPH1/lib_client/mockup.ml b/src/proto_007_PsDELPH1/lib_client/mockup.ml index 5d955b9021ac96f9267808243be8bafef59d9806..b3268a0c8633d4295eb8aab3f0e1fda1d7251379 100644 --- a/src/proto_007_PsDELPH1/lib_client/mockup.ml +++ b/src/proto_007_PsDELPH1/lib_client/mockup.ml @@ -384,10 +384,11 @@ let initial_context (header : Block_header.shell_header) let json = Default_parameters.json_of_parameters parameters in let proto_params = Data_encoding.Binary.to_bytes_exn Data_encoding.json json + |> Bytes.unsafe_to_string in Tezos_protocol_environment.Context.( let empty = Memory_context.empty in - add empty ["version"] (Bytes.of_string "genesis") + add empty ["version"] "genesis" >>= fun ctxt -> add ctxt ["protocol_parameters"] proto_params) >>= fun ctxt -> Protocol.Main.init ctxt header diff --git a/src/proto_007_PsDELPH1/lib_client/proxy.ml b/src/proto_007_PsDELPH1/lib_client/proxy.ml index ec3c16a2d2759ad2dddbdb8b0ebb15e61288ae35..29c0dca1217cda770bdffe7df566fd7f22304983 100644 --- a/src/proto_007_PsDELPH1/lib_client/proxy.ml +++ b/src/proto_007_PsDELPH1/lib_client/proxy.ml @@ -110,10 +110,7 @@ let initial_context (rpc_context : RPC_context.json) end in let empty = Proxy_context.empty @@ Some (module N) in let version_value = "delphi_007" in - Tezos_protocol_environment.Context.add - empty - ["version"] - (Bytes.of_string version_value) + Tezos_protocol_environment.Context.add empty ["version"] version_value let init_env_rpc_context (_printer : Tezos_client_base.Client_context.printer) (rpc_context : RPC_context.json) diff --git a/src/proto_007_PsDELPH1/lib_protocol/test/helpers/block.ml b/src/proto_007_PsDELPH1/lib_protocol/test/helpers/block.ml index 2406ffbdd150c23444affaf445644353a1afb789..860a4fe3e510c42e0c47b6858a9a013d90ecbec1 100644 --- a/src/proto_007_PsDELPH1/lib_protocol/test/helpers/block.ml +++ b/src/proto_007_PsDELPH1/lib_protocol/test/helpers/block.ml @@ -262,10 +262,11 @@ let initial_context ?(with_commitments = false) constants header let json = Default_parameters.json_of_parameters parameters in let proto_params = Data_encoding.Binary.to_bytes_exn Data_encoding.json json + |> Bytes.unsafe_to_string in Tezos_protocol_environment.Context.( let empty = Memory_context.empty in - add empty ["version"] (Bytes.of_string "genesis") + add empty ["version"] "genesis" >>= fun ctxt -> add ctxt protocol_param_key proto_params) >>= fun ctxt -> Main.init ctxt header >|= Environment.wrap_error @@ -289,10 +290,11 @@ let genesis_with_parameters parameters = let json = Default_parameters.json_of_parameters parameters in let proto_params = Data_encoding.Binary.to_bytes_exn Data_encoding.json json + |> Bytes.unsafe_to_string in Tezos_protocol_environment.Context.( let empty = Memory_context.empty in - add empty ["version"] (Bytes.of_string "genesis") + add empty ["version"] "genesis" >>= fun ctxt -> add ctxt protocol_param_key proto_params) >>= fun ctxt -> Main.init ctxt shell >|= Environment.wrap_error diff --git a/src/proto_008_PtEdoTez/lib_client/mockup.ml b/src/proto_008_PtEdoTez/lib_client/mockup.ml index 68ca698f2fbe7766d43c96a5a69d4069cfdb4e14..014f51e7a78aa7ceaca4b07a1d8f9da521be4532 100644 --- a/src/proto_008_PtEdoTez/lib_client/mockup.ml +++ b/src/proto_008_PtEdoTez/lib_client/mockup.ml @@ -384,10 +384,11 @@ let initial_context (header : Block_header.shell_header) let json = Default_parameters.json_of_parameters parameters in let proto_params = Data_encoding.Binary.to_bytes_exn Data_encoding.json json + |> Bytes.unsafe_to_string in Tezos_protocol_environment.Context.( let empty = Memory_context.empty in - add empty ["version"] (Bytes.of_string "genesis") + add empty ["version"] "genesis" >>= fun ctxt -> add ctxt ["protocol_parameters"] proto_params) >>= fun ctxt -> Protocol.Main.init ctxt header diff --git a/src/proto_008_PtEdoTez/lib_client/proxy.ml b/src/proto_008_PtEdoTez/lib_client/proxy.ml index 1eee7831d3bdee4dfa5daeb96566944ac904bfd1..c407f3ce949f361a92f0ad9768e2d49e2e9339e4 100644 --- a/src/proto_008_PtEdoTez/lib_client/proxy.ml +++ b/src/proto_008_PtEdoTez/lib_client/proxy.ml @@ -110,10 +110,7 @@ let initial_context (rpc_context : RPC_context.json) end in let empty = Proxy_context.empty @@ Some (module N) in let version_value = "edo_008" in - Tezos_protocol_environment.Context.add - empty - ["version"] - (Bytes.of_string version_value) + Tezos_protocol_environment.Context.add empty ["version"] version_value let init_env_rpc_context (_printer : Tezos_client_base.Client_context.printer) (rpc_context : RPC_context.json) diff --git a/src/proto_008_PtEdoTez/lib_protocol/test/helpers/block.ml b/src/proto_008_PtEdoTez/lib_protocol/test/helpers/block.ml index 50f981aae4ed9ca04590699ea234b8e0cd17da2a..d0c2e53c5113b9fbd1cb202470fa1589d200451c 100644 --- a/src/proto_008_PtEdoTez/lib_protocol/test/helpers/block.ml +++ b/src/proto_008_PtEdoTez/lib_protocol/test/helpers/block.ml @@ -263,10 +263,11 @@ let initial_context ?(with_commitments = false) constants header let json = Default_parameters.json_of_parameters parameters in let proto_params = Data_encoding.Binary.to_bytes_exn Data_encoding.json json + |> Bytes.unsafe_to_string in Tezos_protocol_environment.Context.( let empty = Memory_context.empty in - add empty ["version"] (Bytes.of_string "genesis") + add empty ["version"] "genesis" >>= fun ctxt -> add ctxt protocol_param_key proto_params) >>= fun ctxt -> Main.init ctxt header >|= Environment.wrap_error @@ -290,10 +291,11 @@ let genesis_with_parameters parameters = let json = Default_parameters.json_of_parameters parameters in let proto_params = Data_encoding.Binary.to_bytes_exn Data_encoding.json json + |> Bytes.unsafe_to_string in Tezos_protocol_environment.Context.( let empty = Memory_context.empty in - add empty ["version"] (Bytes.of_string "genesis") + add empty ["version"] "genesis" >>= fun ctxt -> add ctxt protocol_param_key proto_params) >>= fun ctxt -> Main.init ctxt shell >|= Environment.wrap_error diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index d13fb76a4ca1a189184ddb74fa1f121fcd7564f7..4dae1bf5c86f1612f1a5a1e93bb922f727290b87 100644 --- a/src/proto_alpha/lib_client/mockup.ml +++ b/src/proto_alpha/lib_client/mockup.ml @@ -359,10 +359,11 @@ let initial_context (header : Block_header.shell_header) let json = Default_parameters.json_of_parameters parameters in let proto_params = Data_encoding.Binary.to_bytes_exn Data_encoding.json json + |> Bytes.to_string in Tezos_protocol_environment.Context.( let empty = Memory_context.empty in - add empty ["version"] (Bytes.of_string "genesis") + add empty ["version"] "genesis" >>= fun ctxt -> add ctxt ["protocol_parameters"] proto_params) >>= fun ctxt -> Protocol.Main.init ctxt header diff --git a/src/proto_alpha/lib_client/proxy.ml b/src/proto_alpha/lib_client/proxy.ml index 3ced2424ce0a93801374a10e1d96f8f3eecb8ae2..af104c322a9cbeeaa5e24d54d649b8af562d4a1d 100644 --- a/src/proto_alpha/lib_client/proxy.ml +++ b/src/proto_alpha/lib_client/proxy.ml @@ -110,10 +110,7 @@ let initial_context (rpc_context : RPC_context.json) end in let empty = Proxy_context.empty @@ Some (module N) in let version_value = "alpha_current" in - Tezos_protocol_environment.Context.add - empty - ["version"] - (Bytes.of_string version_value) + Tezos_protocol_environment.Context.add empty ["version"] version_value let init_env_rpc_context (_printer : Tezos_client_base.Client_context.printer) (rpc_context : RPC_context.json) diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 859a5ede8e65fdb326664482d4e9d5216f1ff3df..c4026437983f6c3d8b1430ccc650d1aca9f99e87 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -598,8 +598,12 @@ let get_first_level ctxt = >|= function | None -> storage_error (Missing_key (first_level_key, Get)) - | Some bytes -> ( - match Data_encoding.Binary.of_bytes Raw_level_repr.encoding bytes with + | Some str -> ( + match + Data_encoding.Binary.of_bytes + Raw_level_repr.encoding + (Bytes.of_string str) + with | None -> storage_error (Corrupted_data first_level_key) | Some level -> @@ -609,9 +613,9 @@ let set_first_level ctxt level = let bytes = Data_encoding.Binary.to_bytes_exn Raw_level_repr.encoding level in - Context.add ctxt first_level_key bytes >|= ok + Context.add ctxt first_level_key (Bytes.to_string bytes) >|= ok -type error += Failed_to_parse_parameter of bytes +type error += Failed_to_parse_parameter of string type error += Failed_to_decode_parameter of Data_encoding.json * string @@ -621,12 +625,12 @@ let () = ~id:"context.failed_to_parse_parameter" ~title:"Failed to parse parameter" ~description:"The protocol parameters are not valid JSON." - ~pp:(fun ppf bytes -> + ~pp:(fun ppf string -> Format.fprintf ppf "@[Cannot parse the protocol parameter:@ %s@]" - (Bytes.to_string bytes)) - Data_encoding.(obj1 (req "contents" bytes)) + string) + Data_encoding.(obj1 (req "contents" string)) (function Failed_to_parse_parameter data -> Some data | _ -> None) (fun data -> Failed_to_parse_parameter data) ; register_error_kind @@ -651,10 +655,12 @@ let get_proto_param ctxt = >>= function | None -> failwith "Missing protocol parameters." - | Some bytes -> ( - match Data_encoding.Binary.of_bytes Data_encoding.json bytes with + | Some str -> ( + match + Data_encoding.Binary.of_bytes Data_encoding.json (Bytes.of_string str) + with | None -> - fail (Failed_to_parse_parameter bytes) + fail (Failed_to_parse_parameter str) | Some json -> ( Context.remove ctxt protocol_param_key >|= fun ctxt -> @@ -676,16 +682,18 @@ let add_constants ctxt constants = Constants_repr.parametric_encoding constants in - Context.add ctxt constants_key bytes + Context.add ctxt constants_key (Bytes.to_string bytes) let get_constants ctxt = Context.find ctxt constants_key >|= function | None -> failwith "Internal error: cannot read constants in context." - | Some bytes -> ( + | Some str -> ( match - Data_encoding.Binary.of_bytes Constants_repr.parametric_encoding bytes + Data_encoding.Binary.of_bytes + Constants_repr.parametric_encoding + (Bytes.of_string str) with | None -> failwith "Internal error: cannot parse constants in context." @@ -704,8 +712,7 @@ let check_inited ctxt = >|= function | None -> failwith "Internal error: un-initialized context." - | Some bytes -> - let s = Bytes.to_string bytes in + | Some s -> if Compare.String.(s = version_value) then ok_unit else storage_error (Incompatible_protocol_version s) @@ -762,8 +769,7 @@ let check_and_update_protocol_version ctxt = | None -> failwith "Internal error: un-initialized context in check_first_block." - | Some bytes -> - let s = Bytes.to_string bytes in + | Some s -> if Compare.String.(s = version_value) then failwith "Internal error: previously initialized context." else if Compare.String.(s = "genesis") then @@ -772,7 +778,7 @@ let check_and_update_protocol_version ctxt = else if Compare.String.(s = "edo_008") then return (Edo_008, ctxt) else Lwt.return @@ storage_error (Incompatible_protocol_version s)) >>=? fun (previous_proto, ctxt) -> - Context.add ctxt version_key (Bytes.of_string version_value) + Context.add ctxt version_key version_value >|= fun ctxt -> ok (previous_proto, ctxt) let prepare_first_block ~level ~timestamp ~fitness ctxt = @@ -796,7 +802,7 @@ let activate ctxt h = Updater.activate (context ctxt) h >|= update_context ctxt type key = string list -type value = bytes +type value = string type tree = Context.tree diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index f06b2fec7ccafcbeb62e018344a38f22c53df3cf..74563e7e64244ee1e7848a2bb496efcb7193b705 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -38,7 +38,7 @@ type storage_error = type error += Storage_error of storage_error -type error += Failed_to_parse_parameter of bytes +type error += Failed_to_parse_parameter of string type error += Failed_to_decode_parameter of Data_encoding.json * string @@ -151,7 +151,7 @@ val unset_origination_nonce : t -> t type key = string list -type value = bytes +type value = string type tree diff --git a/src/proto_alpha/lib_protocol/raw_context_intf.ml b/src/proto_alpha/lib_protocol/raw_context_intf.ml index b82f376e9b55fd88bc83f2fa675a282a726ecdc5..8177a4d852ab2cbf503094360ce76796e70c3355 100644 --- a/src/proto_alpha/lib_protocol/raw_context_intf.ml +++ b/src/proto_alpha/lib_protocol/raw_context_intf.ml @@ -42,7 +42,7 @@ module type VIEW = sig type key = string list (** The type for context values. *) - type value = bytes + type value = string (** {2 Getters} *) @@ -190,6 +190,8 @@ module type TREE = sig (** The type for context trees. *) type tree + include VIEW with type t := tree and type tree := tree + (** [empty _] is the empty tree. *) val empty : t -> tree @@ -198,7 +200,7 @@ module type TREE = sig (** [kind t] is [t]'s kind. It's either a tree node or a leaf value. *) - val kind : tree -> [`Value of bytes | `Tree] + val kind : tree -> [`Value of value | `Tree] (** [hash t] is [t]'s Merkle hash. *) val hash : tree -> Context_hash.t @@ -206,8 +208,6 @@ module type TREE = sig (** [equal x y] is true iff [x] and [y] have the same Merkle hash. *) val equal : tree -> tree -> bool - include VIEW with type t := tree and type tree := tree - (** {2 Caches} *) (** [clear ?depth t] clears all caches in the tree [t] for subtrees with a diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 2971e5ea2200ed1c8a5a0c70da0c056ef4e9be53..8d337af7b59485f88a25e64def6db3a27acdd9e2 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -35,31 +35,31 @@ module Ghost = struct end module Make_encoder (V : VALUE) = struct - let of_bytes ~key b = - match Data_encoding.Binary.of_bytes V.encoding b with + let of_string ~key b = + match Data_encoding.Binary.of_bytes V.encoding (Bytes.of_string b) with | None -> error (Raw_context.Storage_error (Corrupted_data (key ()))) | Some v -> Ok v - let to_bytes v = + let to_string v = match Data_encoding.Binary.to_bytes V.encoding v with | Some b -> - b + Bytes.to_string b | None -> - Bytes.empty + "" end let len_name = "len" let data_name = "data" -let encode_len_value bytes = - let length = Bytes.length bytes in - Data_encoding.(Binary.to_bytes_exn int31) length +let encode_len_value str = + let length = String.length str in + Data_encoding.(Binary.to_bytes_exn int31) length |> Bytes.to_string let decode_len_value key len = - match Data_encoding.(Binary.of_bytes int31) len with + match Data_encoding.(Binary.of_bytes int31) (Bytes.of_string len) with | None -> error (Raw_context.Storage_error (Corrupted_data key)) | Some len -> @@ -150,7 +150,7 @@ struct C.get t N.name >>=? fun b -> let key () = C.absolute_key t N.name in - Lwt.return (of_bytes ~key b) + Lwt.return (of_string ~key b) let find t = C.find t N.name @@ -159,16 +159,16 @@ struct ok_none | Some b -> let key () = C.absolute_key t N.name in - of_bytes ~key b >|? fun v -> Some v + of_string ~key b >|? fun v -> Some v - let init t v = C.init t N.name (to_bytes v) >|=? fun t -> C.project t + let init t v = C.init t N.name (to_string v) >|=? fun t -> C.project t - let update t v = C.update t N.name (to_bytes v) >|=? fun t -> C.project t + let update t v = C.update t N.name (to_string v) >|=? fun t -> C.project t - let add t v = C.add t N.name (to_bytes v) >|= fun t -> C.project t + let add t v = C.add t N.name (to_string v) >|= fun t -> C.project t let add_or_remove t v = - C.add_or_remove t N.name (Option.map to_bytes v) >|= fun t -> C.project t + C.add_or_remove t N.name (Option.map to_string v) >|= fun t -> C.project t let remove t = C.remove t N.name >|= fun t -> C.project t @@ -231,7 +231,7 @@ module Make_data_set_storage (C : Raw_context.T) (I : INDEX) : type elt = I.t - let inited = Bytes.of_string "inited" + let inited = "inited" let mem s i = C.mem s (I.to_path i []) @@ -286,7 +286,7 @@ module Make_indexed_data_storage (C : Raw_context.T) (I : INDEX) (V : VALUE) : C.get s (I.to_path i []) >>=? fun b -> let key () = C.absolute_key s (I.to_path i []) in - Lwt.return (of_bytes ~key b) + Lwt.return (of_string ~key b) let find s i = C.find s (I.to_path i []) @@ -295,19 +295,19 @@ module Make_indexed_data_storage (C : Raw_context.T) (I : INDEX) (V : VALUE) : ok_none | Some b -> let key () = C.absolute_key s (I.to_path i []) in - of_bytes ~key b >|? fun v -> Some v + of_string ~key b >|? fun v -> Some v let update s i v = - C.update s (I.to_path i []) (to_bytes v) >|=? fun t -> C.project t + C.update s (I.to_path i []) (to_string v) >|=? fun t -> C.project t let init s i v = - C.init s (I.to_path i []) (to_bytes v) >|=? fun t -> C.project t + C.init s (I.to_path i []) (to_string v) >|=? fun t -> C.project t let add s i v = - C.add s (I.to_path i []) (to_bytes v) >|= fun t -> C.project t + C.add s (I.to_path i []) (to_string v) >|= fun t -> C.project t let add_or_remove s i v = - C.add_or_remove s (I.to_path i []) (Option.map to_bytes v) + C.add_or_remove s (I.to_path i []) (Option.map to_string v) >|= fun t -> C.project t let remove s i = C.remove s (I.to_path i []) >|= fun t -> C.project t @@ -326,7 +326,7 @@ module Make_indexed_data_storage (C : Raw_context.T) (I : INDEX) (V : VALUE) : assert false | Some path -> ( let key () = C.absolute_key s file in - match of_bytes ~key v with + match of_string ~key v with | Ok v -> f path v acc | Error _ -> @@ -407,14 +407,14 @@ struct to bytes. It would be cleaner for users of this functor to provide gas costs for the encoding. *) let consume_serialize_write_gas set c i v = - let bytes = to_bytes v in - let len = Bytes.length bytes in + let str = to_string v in + let len = String.length str in C.consume_gas c (Gas_limit_repr.alloc_mbytes_cost len) >>?= fun c -> let cost = Storage_costs.write_access ~written_bytes:len in C.consume_gas c cost >>?= fun c -> - set c (len_key i) (encode_len_value bytes) >|=? fun c -> (c, bytes) + set c (len_key i) (encode_len_value str) >|=? fun c -> (c, str) let consume_remove_gas del c i = C.consume_gas c (Storage_costs.write_access ~written_bytes:0) @@ -431,7 +431,7 @@ struct C.get s (data_key i) >>=? fun b -> let key () = C.absolute_key s (data_key i) in - Lwt.return (of_bytes ~key b >|? fun v -> (C.project s, v)) + Lwt.return (of_string ~key b >|? fun v -> (C.project s, v)) let find s i = let key = data_key i in @@ -446,18 +446,18 @@ struct existing_size s i >>=? fun (prev_size, _) -> consume_serialize_write_gas C.update s i v - >>=? fun (s, bytes) -> - C.update s (data_key i) bytes + >>=? fun (s, str) -> + C.update s (data_key i) str >|=? fun t -> - let size_diff = Bytes.length bytes - prev_size in + let size_diff = String.length str - prev_size in (C.project t, size_diff) let init s i v = consume_serialize_write_gas C.init s i v - >>=? fun (s, bytes) -> - C.init s (data_key i) bytes + >>=? fun (s, str) -> + C.init s (data_key i) str >|=? fun t -> - let size = Bytes.length bytes in + let size = String.length str in (C.project t, size) let add s i v = @@ -465,10 +465,10 @@ struct existing_size s i >>=? fun (prev_size, existed) -> consume_serialize_write_gas add s i v - >>=? fun (s, bytes) -> - add s (data_key i) bytes + >>=? fun (s, str) -> + add s (data_key i) str >|=? fun t -> - let size_diff = Bytes.length bytes - prev_size in + let size_diff = String.length str - prev_size in (C.project t, size_diff, existed) let remove s i = @@ -837,7 +837,7 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : type elt = I.t - let inited = Bytes.of_string "inited" + let inited = "inited" let mem s i = Raw_context.mem (pack s i) N.name @@ -900,7 +900,7 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : Raw_context.get (pack s i) N.name >>=? fun b -> let key () = Raw_context.absolute_key (pack s i) N.name in - Lwt.return (of_bytes ~key b) + Lwt.return (of_string ~key b) let find s i = Raw_context.find (pack s i) N.name @@ -909,28 +909,28 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : ok_none | Some b -> let key () = Raw_context.absolute_key (pack s i) N.name in - of_bytes ~key b >|? fun v -> Some v + of_string ~key b >|? fun v -> Some v let update s i v = - Raw_context.update (pack s i) N.name (to_bytes v) + Raw_context.update (pack s i) N.name (to_string v) >|=? fun c -> let (s, _) = unpack c in C.project s let init s i v = - Raw_context.init (pack s i) N.name (to_bytes v) + Raw_context.init (pack s i) N.name (to_string v) >|=? fun c -> let (s, _) = unpack c in C.project s let add s i v = - Raw_context.add (pack s i) N.name (to_bytes v) + Raw_context.add (pack s i) N.name (to_string v) >|= fun c -> let (s, _) = unpack c in C.project s let add_or_remove s i v = - Raw_context.add_or_remove (pack s i) N.name (Option.map to_bytes v) + Raw_context.add_or_remove (pack s i) N.name (Option.map to_string v) >|= fun c -> let (s, _) = unpack c in C.project s @@ -1020,11 +1020,10 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : (Storage_costs.read_access ~path_length ~read_bytes) ) let consume_write_gas set c v = - let bytes = to_bytes v in - let len = Bytes.length bytes in + let str = to_string v in + let len = String.length str in Raw_context.consume_gas c (Storage_costs.write_access ~written_bytes:len) - >>?= fun c -> - set c len_name (encode_len_value bytes) >|=? fun c -> (c, bytes) + >>?= fun c -> set c len_name (encode_len_value str) >|=? fun c -> (c, str) let consume_remove_gas del c = Raw_context.consume_gas c (Storage_costs.write_access ~written_bytes:0) @@ -1041,7 +1040,7 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : Raw_context.get c data_name >>=? fun b -> let key () = Raw_context.absolute_key c data_name in - Lwt.return (of_bytes ~key b >|? fun v -> (Raw_context.project c, v)) + Lwt.return (of_string ~key b >|? fun v -> (Raw_context.project c, v)) let find s i = consume_mem_gas (pack s i) @@ -1056,18 +1055,18 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : existing_size (pack s i) >>=? fun (prev_size, _) -> consume_write_gas Raw_context.update (pack s i) v - >>=? fun (c, bytes) -> - Raw_context.update c data_name bytes + >>=? fun (c, str) -> + Raw_context.update c data_name str >|=? fun c -> - let size_diff = Bytes.length bytes - prev_size in + let size_diff = String.length str - prev_size in (Raw_context.project c, size_diff) let init s i v = consume_write_gas Raw_context.init (pack s i) v - >>=? fun (c, bytes) -> - Raw_context.init c data_name bytes + >>=? fun (c, str) -> + Raw_context.init c data_name str >|=? fun c -> - let size = Bytes.length bytes in + let size = String.length str in (Raw_context.project c, size) let add s i v = @@ -1075,10 +1074,10 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : existing_size (pack s i) >>=? fun (prev_size, existed) -> consume_write_gas add (pack s i) v - >>=? fun (c, bytes) -> - add c data_name bytes + >>=? fun (c, str) -> + add c data_name str >|=? fun c -> - let size_diff = Bytes.length bytes - prev_size in + let size_diff = String.length str - prev_size in (Raw_context.project c, size_diff, existed) let remove s i = diff --git a/src/proto_alpha/lib_protocol/test/helpers/block.ml b/src/proto_alpha/lib_protocol/test/helpers/block.ml index f52ac378eab104443213c147662c38d9106088c1..73ac6852f42d91bb9c3516f7003759da93670ad6 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/block.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/block.ml @@ -263,10 +263,11 @@ let initial_context ?(with_commitments = false) constants header let json = Default_parameters.json_of_parameters parameters in let proto_params = Data_encoding.Binary.to_bytes_exn Data_encoding.json json + |> Bytes.to_string in Tezos_protocol_environment.Context.( let empty = Memory_context.empty in - add empty ["version"] (Bytes.of_string "genesis") + add empty ["version"] "genesis" >>= fun ctxt -> add ctxt protocol_param_key proto_params) >>= fun ctxt -> Main.init ctxt header >|= Environment.wrap_error @@ -290,10 +291,11 @@ let genesis_with_parameters parameters = let json = Default_parameters.json_of_parameters parameters in let proto_params = Data_encoding.Binary.to_bytes_exn Data_encoding.json json + |> Bytes.to_string in Tezos_protocol_environment.Context.( let empty = Memory_context.empty in - add empty ["version"] (Bytes.of_string "genesis") + add empty ["version"] "genesis" >>= fun ctxt -> add ctxt protocol_param_key proto_params) >>= fun ctxt -> Main.init ctxt shell >|= Environment.wrap_error diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index bad68594ada6c0d1546be65819e754769950fa31..01b42aef6a7a89cd736e833e3ae70f2ebccff448 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -198,12 +198,17 @@ module Vote = struct let get_participation_ema (b : Block.t) = Environment.Context.find b.context ["votes"; "participation_ema"] >|= function - | None -> assert false | Some bytes -> ok (TzEndian.get_int32 bytes 0) + | None -> + assert false + | Some str -> + let bytes = Bytes.unsafe_of_string str in + ok (TzEndian.get_int32 bytes 0) let set_participation_ema (b : Block.t) ema = let bytes = Bytes.make 4 '\000' in TzEndian.set_int32 bytes 0 ema ; - Environment.Context.add b.context ["votes"; "participation_ema"] bytes + let str = Bytes.unsafe_to_string bytes in + Environment.Context.add b.context ["votes"; "participation_ema"] str >|= fun context -> {b with context} end