From 7d79d5041f14e86d963322edf64c2c765f07237f Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Wed, 20 Jul 2022 10:07:35 +0900 Subject: [PATCH 01/20] Protocol Storage : Improve the speed of contract deletion --- .../lib_protocol/contract_storage.ml | 15 ++- src/proto_alpha/lib_protocol/raw_context.ml | 112 ++++++++++++++++++ src/proto_alpha/lib_protocol/raw_context.mli | 3 + .../lib_protocol/raw_context_intf.ml | 26 ++++ src/proto_alpha/lib_protocol/storage.ml | 3 + src/proto_alpha/lib_protocol/storage.mli | 18 ++- .../lib_protocol/storage_functors.ml | 32 ++++- src/proto_alpha/lib_protocol/storage_sigs.ml | 25 +++- 8 files changed, 222 insertions(+), 12 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 4e17ed75ccb6..64e4c0e21f1b 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -441,10 +441,17 @@ let delete c contract = do not exist). An implicit contract deletion should not cost extra gas. *) Contract_delegate_storage.unlink c contract >>=? fun c -> - Storage.Contract.Spendable_balance.remove_existing c contract - >>=? fun c -> - Contract_manager_storage.remove_existing c contract >>=? fun c -> - Storage.Contract.Counter.remove_existing c contract + Storage.Contract.with_local_context + ~for_write:true + c + contract + (fun local -> + Storage.Contract.Spendable_balance.Local.remove_existing local + >>=? fun local -> + Storage.Contract.Manager.Local.remove_existing local >>=? fun local -> + Storage.Contract.Counter.Local.remove_existing local >|=? fun local -> + (local, ())) + >|=? fun (c, ()) -> c let allocated c contract = Storage.Contract.Spendable_balance.mem c contract diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index a34b0145576c..b00460d5b37a 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1021,12 +1021,23 @@ type value = bytes type tree = Context.tree +(* The type for relative context accesses instead from the root. In order for + the carbonated storage functions to consume the gas, this has gas infomation +*) +type local_context = { + tree : tree; + path : key; + remaining_operation_gas : Gas_limit_repr.Arith.fp; + unlimited_operation_gas : bool; +} + module type T = Raw_context_intf.T with type root := root and type key := key and type value := value and type tree := tree + and type local_context := local_context let mem ctxt k = Context.mem (context ctxt) k @@ -1553,3 +1564,104 @@ module Dal = struct let shards ctxt ~endorser = compute_shards ~index:0 ctxt ~endorser end + +let with_local_context ~for_write ctxt key f = + (find_tree ctxt key >|= function None -> Tree.empty ctxt | Some tree -> tree) + >>= fun tree -> + let local_ctxt = + { + tree; + path = key; + remaining_operation_gas = remaining_operation_gas ctxt; + unlimited_operation_gas = unlimited_operation_gas ctxt; + } + in + f local_ctxt >>=? fun (local_ctxt, res) -> + (if for_write then add_tree ctxt key local_ctxt.tree else Lwt.return ctxt) + >|= fun ctxt -> + update_remaining_operation_gas ctxt local_ctxt.remaining_operation_gas + |> fun ctxt -> + update_unlimited_operation_gas ctxt local_ctxt.unlimited_operation_gas + |> fun ctxt -> ok (ctxt, res) + +module Local_context : sig + include + Raw_context_intf.VIEW + with type t = local_context + and type key := key + and type value := value + and type tree := tree + + val consume_gas : + local_context -> Gas_limit_repr.cost -> local_context tzresult + + val absolute_key : local_context -> key -> key +end = struct + type t = local_context + + let consume_gas local cost = + match Gas_limit_repr.raw_consume local.remaining_operation_gas cost with + | Some gas_counter -> Ok {local with remaining_operation_gas = gas_counter} + | None -> + if local.unlimited_operation_gas then ok local + else error Operation_quota_exceeded + + let tree local = local.tree + + let update_root_tree local tree = {local with tree} + + let absolute_key local key = local.path @ key + + let find local = Tree.find (tree local) + + let find_tree local = Tree.find_tree (tree local) + + let mem local = Tree.mem (tree local) + + let mem_tree local = Tree.mem_tree (tree local) + + let get local = Tree.get (tree local) + + let get_tree local = Tree.get_tree (tree local) + + let update local key b = + Tree.update (tree local) key b >|=? update_root_tree local + + let update_tree local key b = + Tree.update_tree (tree local) key b >|=? update_root_tree local + + let init local key b = + Tree.init (tree local) key b >|=? update_root_tree local + + let init_tree local key t = + Tree.init_tree (tree local) key t >|=? update_root_tree local + + let add local i b = Tree.add (tree local) i b >|= update_root_tree local + + let add_tree local i t = + Tree.add_tree (tree local) i t >|= update_root_tree local + + let remove local i = Tree.remove (tree local) i >|= update_root_tree local + + let remove_existing local key = + Tree.remove_existing (tree local) key >|=? update_root_tree local + + let remove_existing_tree local key = + Tree.remove_existing_tree (tree local) key >|=? update_root_tree local + + let add_or_remove local key vopt = + Tree.add_or_remove (tree local) key vopt >|= update_root_tree local + + let add_or_remove_tree local key topt = + Tree.add_or_remove_tree (tree local) key topt >|= update_root_tree local + + let fold ?depth local key ~order ~init ~f = + Tree.fold ?depth (tree local) key ~order ~init ~f + + let list local ?offset ?length key = + Tree.list (tree local) ?offset ?length key + + let config local = Tree.config (tree local) + + let length local i = Tree.length (tree local) i +end diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index eef60d8c3117..8c44aaf2752e 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -181,12 +181,15 @@ type value = bytes type tree +type local_context + module type T = Raw_context_intf.T with type root := root and type key := key and type value := value and type tree := tree + and type local_context := local_context include T with type t := t diff --git a/src/proto_alpha/lib_protocol/raw_context_intf.ml b/src/proto_alpha/lib_protocol/raw_context_intf.ml index 39c8b058d78a..a721b371e556 100644 --- a/src/proto_alpha/lib_protocol/raw_context_intf.ml +++ b/src/proto_alpha/lib_protocol/raw_context_intf.ml @@ -457,6 +457,11 @@ module type T = sig include VIEW + (** The type for relative context accesses instead from the root. In order for + the carbonated storage functions to consume the gas, this has gas infomation + *) + type local_context + module Tree : TREE with type t := t @@ -559,4 +564,25 @@ module type T = sig val check_enough_gas : t -> Gas_limit_repr.cost -> unit tzresult val description : t Storage_description.t + + val with_local_context : + for_write:bool -> + t -> + key -> + (local_context -> (local_context * 'a) tzresult Lwt.t) -> + (t * 'a) tzresult Lwt.t + + module Local_context : sig + include + VIEW + with type t = local_context + and type tree := tree + and type key := key + and type value := value + + val consume_gas : + local_context -> Gas_limit_repr.cost -> local_context tzresult + + val absolute_key : local_context -> key -> key + end end diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 637404e7263f..2c77dc861a75 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -188,6 +188,9 @@ module Contract = struct let list = Indexed_context.keys + let with_local_context ~for_write = + Indexed_context.with_local_context ~for_write + module Spendable_balance = Indexed_context.Make_map (struct diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index c4c00f28d58f..178f271e4ef2 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -69,12 +69,20 @@ module Contract : sig val list : Raw_context.t -> Contract_repr.t list Lwt.t + val with_local_context : + for_write:bool -> + Raw_context.t -> + Contract_repr.t -> + (Raw_context.local_context -> + (Raw_context.local_context * 'a) tzresult Lwt.t) -> + (Raw_context.t * 'a) tzresult Lwt.t + (** The tez possessed by a contract and that can be used. A contract may also possess tez in frozen deposits. Empty balances (of zero tez) are only allowed for originated contracts, not for implicit ones. *) module Spendable_balance : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = Tez_repr.t and type t := Raw_context.t @@ -99,7 +107,7 @@ module Contract : sig (** The manager of a contract *) module Manager : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = Manager_repr.t and type t := Raw_context.t @@ -148,7 +156,7 @@ module Contract : sig and type t := Raw_context.t module Counter : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = Z.t and type t := Raw_context.t @@ -168,14 +176,14 @@ module Contract : sig (** Current storage space in bytes. Includes code, global storage and big map elements. *) module Used_storage_space : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = Z.t and type t := Raw_context.t (** Maximal space available without needing to burn new fees. *) module Paid_storage_space : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = Z.t and type t := Raw_context.t diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index b07dcbe31d9e..34122b7f2de2 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -142,6 +142,11 @@ module Make_subcontext (R : REGISTER) (C : Raw_context.T) (N : NAME) : Storage_description.register_named_subcontext description N.name let length = C.length + + let with_local_context ~for_write ctxt k f = + C.with_local_context ~for_write ctxt (to_key k) f + + module Local_context = C.Local_context end module Make_single_data_storage @@ -824,8 +829,20 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : let length c = let t, _i = unpack c in C.length t + + let with_local_context ~for_write c k f = + let t, i = unpack c in + C.with_local_context ~for_write t (to_key i k) f >|=? fun (t, res) -> + (pack t i, res) + + module Local_context = C.Local_context end + let with_local_context ~for_write s i f = + Raw_context.with_local_context ~for_write (pack s i) [] f >|=? fun (c, x) -> + let s, _ = unpack c in + (s, x) + module Make_set (R : REGISTER) (N : NAME) : Data_set_storage with type t = t and type elt = key = struct type t = C.t @@ -878,8 +895,10 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : end module Make_map (N : NAME) (V : VALUE) : - Indexed_data_storage with type t = t and type key = key and type value = V.t = - struct + Indexed_data_storage_with_local_context + with type t = t + and type key = key + and type value = V.t = struct type t = C.t type context = t @@ -967,6 +986,15 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : find c k) (register_named_subcontext Raw_context.description N.name) V.encoding + + module Local = struct + type context = Raw_context.Local_context.t + + let remove_existing local = + Raw_context.Local_context.remove_existing local N.name + + let remove local = Raw_context.Local_context.remove local N.name + end end module Make_carbonated_map (N : NAME) (V : VALUE) : diff --git a/src/proto_alpha/lib_protocol/storage_sigs.ml b/src/proto_alpha/lib_protocol/storage_sigs.ml index d6c0a2886083..e504346b1ed8 100644 --- a/src/proto_alpha/lib_protocol/storage_sigs.ml +++ b/src/proto_alpha/lib_protocol/storage_sigs.ml @@ -269,6 +269,18 @@ module type Indexed_data_storage = sig 'a Lwt.t end +module type Indexed_data_storage_with_local_context = sig + include Indexed_data_storage + + module Local : sig + type context = Raw_context.local_context + + val remove_existing : context -> context tzresult Lwt.t + + val remove : context -> context Lwt.t + end +end + module type Indexed_data_snapshotable_storage = sig type snapshot @@ -408,11 +420,22 @@ module type Indexed_raw_context = sig val copy : context -> from:key -> to_:key -> context tzresult Lwt.t + val with_local_context : + for_write:bool -> + context -> + key -> + (Raw_context.local_context -> + (Raw_context.local_context * 'a) tzresult Lwt.t) -> + (context * 'a) tzresult Lwt.t + module Make_set (_ : REGISTER) (_ : NAME) : Data_set_storage with type t = t and type elt = key module Make_map (_ : NAME) (V : VALUE) : - Indexed_data_storage with type t = t and type key = key and type value = V.t + Indexed_data_storage_with_local_context + with type t = t + and type key = key + and type value = V.t module Make_carbonated_map (_ : NAME) (V : VALUE) : Non_iterable_indexed_carbonated_data_storage -- GitLab From f2b823cc5b0fe9b063e7babd6f22f22e4abed74d Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Wed, 27 Jul 2022 12:23:44 +0900 Subject: [PATCH 02/20] Protocol Storage: small changes for reviews * https://gitlab.com/tezos/tezos/-/merge_requests/5922#note_1039716605 * https://gitlab.com/tezos/tezos/-/merge_requests/5922#note_1039719299 * https://gitlab.com/tezos/tezos/-/merge_requests/5922#note_1039719695 --- src/proto_alpha/lib_protocol/contract_storage.ml | 2 +- src/proto_alpha/lib_protocol/raw_context.ml | 4 ++-- src/proto_alpha/lib_protocol/raw_context_intf.ml | 12 ++++++------ src/proto_alpha/lib_protocol/storage.ml | 3 +-- src/proto_alpha/lib_protocol/storage.mli | 2 +- src/proto_alpha/lib_protocol/storage_functors.ml | 12 ++++++------ src/proto_alpha/lib_protocol/storage_sigs.ml | 2 +- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 64e4c0e21f1b..05b6cdba17d1 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -442,7 +442,7 @@ let delete c contract = extra gas. *) Contract_delegate_storage.unlink c contract >>=? fun c -> Storage.Contract.with_local_context - ~for_write:true + ~add_back:true c contract (fun local -> diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index b00460d5b37a..79caf278d4d3 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1565,7 +1565,7 @@ module Dal = struct let shards ctxt ~endorser = compute_shards ~index:0 ctxt ~endorser end -let with_local_context ~for_write ctxt key f = +let with_local_context ~add_back ctxt key f = (find_tree ctxt key >|= function None -> Tree.empty ctxt | Some tree -> tree) >>= fun tree -> let local_ctxt = @@ -1577,7 +1577,7 @@ let with_local_context ~for_write ctxt key f = } in f local_ctxt >>=? fun (local_ctxt, res) -> - (if for_write then add_tree ctxt key local_ctxt.tree else Lwt.return ctxt) + (if add_back then add_tree ctxt key local_ctxt.tree else Lwt.return ctxt) >|= fun ctxt -> update_remaining_operation_gas ctxt local_ctxt.remaining_operation_gas |> fun ctxt -> diff --git a/src/proto_alpha/lib_protocol/raw_context_intf.ml b/src/proto_alpha/lib_protocol/raw_context_intf.ml index a721b371e556..f6534819ea33 100644 --- a/src/proto_alpha/lib_protocol/raw_context_intf.ml +++ b/src/proto_alpha/lib_protocol/raw_context_intf.ml @@ -457,11 +457,6 @@ module type T = sig include VIEW - (** The type for relative context accesses instead from the root. In order for - the carbonated storage functions to consume the gas, this has gas infomation - *) - type local_context - module Tree : TREE with type t := t @@ -565,8 +560,13 @@ module type T = sig val description : t Storage_description.t + (** The type for relative context accesses instead from the root. In order for + the carbonated storage functions to consume the gas, this has gas infomation + *) + type local_context + val with_local_context : - for_write:bool -> + add_back:bool -> t -> key -> (local_context -> (local_context * 'a) tzresult Lwt.t) -> diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 2c77dc861a75..ce38e6f01a0b 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -188,8 +188,7 @@ module Contract = struct let list = Indexed_context.keys - let with_local_context ~for_write = - Indexed_context.with_local_context ~for_write + let with_local_context = Indexed_context.with_local_context module Spendable_balance = Indexed_context.Make_map diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 178f271e4ef2..929f77d7ed92 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -70,7 +70,7 @@ module Contract : sig val list : Raw_context.t -> Contract_repr.t list Lwt.t val with_local_context : - for_write:bool -> + add_back:bool -> Raw_context.t -> Contract_repr.t -> (Raw_context.local_context -> diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 34122b7f2de2..4ef03e9ca993 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -143,8 +143,8 @@ module Make_subcontext (R : REGISTER) (C : Raw_context.T) (N : NAME) : let length = C.length - let with_local_context ~for_write ctxt k f = - C.with_local_context ~for_write ctxt (to_key k) f + let with_local_context ~add_back ctxt k f = + C.with_local_context ~add_back ctxt (to_key k) f module Local_context = C.Local_context end @@ -830,16 +830,16 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : let t, _i = unpack c in C.length t - let with_local_context ~for_write c k f = + let with_local_context ~add_back c k f = let t, i = unpack c in - C.with_local_context ~for_write t (to_key i k) f >|=? fun (t, res) -> + C.with_local_context ~add_back t (to_key i k) f >|=? fun (t, res) -> (pack t i, res) module Local_context = C.Local_context end - let with_local_context ~for_write s i f = - Raw_context.with_local_context ~for_write (pack s i) [] f >|=? fun (c, x) -> + let with_local_context ~add_back s i f = + Raw_context.with_local_context ~add_back (pack s i) [] f >|=? fun (c, x) -> let s, _ = unpack c in (s, x) diff --git a/src/proto_alpha/lib_protocol/storage_sigs.ml b/src/proto_alpha/lib_protocol/storage_sigs.ml index e504346b1ed8..d5065899e3bd 100644 --- a/src/proto_alpha/lib_protocol/storage_sigs.ml +++ b/src/proto_alpha/lib_protocol/storage_sigs.ml @@ -421,7 +421,7 @@ module type Indexed_raw_context = sig val copy : context -> from:key -> to_:key -> context tzresult Lwt.t val with_local_context : - for_write:bool -> + add_back:bool -> context -> key -> (Raw_context.local_context -> -- GitLab From aaa7432aab1a5cc10a2ac15abc180577d1a666c3 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Wed, 27 Jul 2022 14:22:43 +0900 Subject: [PATCH 03/20] Protocol Storage : Make local_type a specia type * https://gitlab.com/tezos/tezos/-/merge_requests/5922#note_1039734752 --- src/proto_alpha/lib_protocol/storage.ml | 2 ++ src/proto_alpha/lib_protocol/storage.mli | 8 ++++++-- src/proto_alpha/lib_protocol/storage_functors.ml | 7 ++++++- src/proto_alpha/lib_protocol/storage_sigs.ml | 10 +++++++--- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index ce38e6f01a0b..0902183524b8 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -188,6 +188,8 @@ module Contract = struct let list = Indexed_context.keys + type local_context = Indexed_context.local_context + let with_local_context = Indexed_context.with_local_context module Spendable_balance = diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 929f77d7ed92..bc1845e62d1c 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -69,12 +69,13 @@ module Contract : sig val list : Raw_context.t -> Contract_repr.t list Lwt.t + type local_context + val with_local_context : add_back:bool -> Raw_context.t -> Contract_repr.t -> - (Raw_context.local_context -> - (Raw_context.local_context * 'a) tzresult Lwt.t) -> + (local_context -> (local_context * 'a) tzresult Lwt.t) -> (Raw_context.t * 'a) tzresult Lwt.t (** The tez possessed by a contract and that can be used. A contract @@ -86,6 +87,7 @@ module Contract : sig with type key = Contract_repr.t and type value = Tez_repr.t and type t := Raw_context.t + and type local_context := local_context (** If the value is not set, the delegate didn't miss any endorsing opportunity. If it is set, this value is a record of type @@ -111,6 +113,7 @@ module Contract : sig with type key = Contract_repr.t and type value = Manager_repr.t and type t := Raw_context.t + and type local_context := local_context (** The delegate of a contract, if any. *) module Delegate : @@ -160,6 +163,7 @@ module Contract : sig with type key = Contract_repr.t and type value = Z.t and type t := Raw_context.t + and type local_context := local_context module Code : Non_iterable_indexed_carbonated_data_storage diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 4ef03e9ca993..56b095df73b6 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -668,6 +668,8 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : type 'a ipath = 'a I.ipath + type local_context = Raw_context.local_context + let clear t = C.remove t [] >|= fun t -> C.project t let fold_keys t ~order ~init ~f = @@ -898,7 +900,8 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : Indexed_data_storage_with_local_context with type t = t and type key = key - and type value = V.t = struct + and type value = V.t + and type local_context = local_context = struct type t = C.t type context = t @@ -907,6 +910,8 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : type value = V.t + type nonrec local_context = local_context + include Make_encoder (V) let mem s i = Raw_context.mem (pack s i) N.name diff --git a/src/proto_alpha/lib_protocol/storage_sigs.ml b/src/proto_alpha/lib_protocol/storage_sigs.ml index d5065899e3bd..0fd43629c3a3 100644 --- a/src/proto_alpha/lib_protocol/storage_sigs.ml +++ b/src/proto_alpha/lib_protocol/storage_sigs.ml @@ -272,8 +272,10 @@ end module type Indexed_data_storage_with_local_context = sig include Indexed_data_storage + type local_context + module Local : sig - type context = Raw_context.local_context + type context = local_context val remove_existing : context -> context tzresult Lwt.t @@ -405,6 +407,8 @@ module type Indexed_raw_context = sig type 'a ipath + type local_context + val clear : context -> Raw_context.t Lwt.t val fold_keys : @@ -424,8 +428,7 @@ module type Indexed_raw_context = sig add_back:bool -> context -> key -> - (Raw_context.local_context -> - (Raw_context.local_context * 'a) tzresult Lwt.t) -> + (local_context -> (local_context * 'a) tzresult Lwt.t) -> (context * 'a) tzresult Lwt.t module Make_set (_ : REGISTER) (_ : NAME) : @@ -436,6 +439,7 @@ module type Indexed_raw_context = sig with type t = t and type key = key and type value = V.t + and type local_context = local_context module Make_carbonated_map (_ : NAME) (V : VALUE) : Non_iterable_indexed_carbonated_data_storage -- GitLab From 438d3514be88bfc0254d45ab775fdf44c6dc7d29 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Wed, 27 Jul 2022 19:11:56 +0900 Subject: [PATCH 04/20] Protocol Storage : Add other functions to Local module --- .../lib_protocol/storage_functors.ml | 28 +++++++++++++++ src/proto_alpha/lib_protocol/storage_sigs.ml | 35 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 56b095df73b6..717816e4d286 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -995,6 +995,34 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : module Local = struct type context = Raw_context.Local_context.t + let mem local = Raw_context.Local_context.mem local N.name + + let get local = + Raw_context.Local_context.get local N.name >|= fun r -> + let key () = Raw_context.Local_context.absolute_key local N.name in + r >>? of_bytes ~key + + let find local = + Raw_context.Local_context.find local N.name >|= function + | None -> Result.return_none + | Some b -> + let key () = Raw_context.Local_context.absolute_key local N.name in + of_bytes ~key b >|? fun v -> Some v + + let init local v = + Raw_context.Local_context.init local N.name (to_bytes v) + + let update local v = + Raw_context.Local_context.update local N.name (to_bytes v) + + let add local v = Raw_context.Local_context.add local N.name (to_bytes v) + + let add_or_remove local vo = + Raw_context.Local_context.add_or_remove + local + N.name + (Option.map to_bytes vo) + let remove_existing local = Raw_context.Local_context.remove_existing local N.name diff --git a/src/proto_alpha/lib_protocol/storage_sigs.ml b/src/proto_alpha/lib_protocol/storage_sigs.ml index 0fd43629c3a3..3921221ad5c3 100644 --- a/src/proto_alpha/lib_protocol/storage_sigs.ml +++ b/src/proto_alpha/lib_protocol/storage_sigs.ml @@ -277,8 +277,43 @@ module type Indexed_data_storage_with_local_context = sig module Local : sig type context = local_context + (** Tells if the data is already defined *) + val mem : context -> bool Lwt.t + + (** Retrieve the value from the storage bucket ; returns a + {!Storage_error} if the key is not set or if the deserialisation + fails *) + val get : context -> value tzresult Lwt.t + + (** Retrieves the value from the storage bucket ; returns [None] if + the data is not initialized, or {!Storage_helpers.Storage_error} + if the deserialisation fails *) + val find : context -> value option tzresult Lwt.t + + (** Allocates the storage bucket and initializes it ; returns a + {!Storage_error Existing_key} if the bucket exists *) + val init : context -> value -> context tzresult Lwt.t + + (** Updates the content of the bucket ; returns a {!Storage_Error + Missing_key} if the value does not exists *) + val update : context -> value -> context tzresult Lwt.t + + (** Allocates the data and initializes it with a value ; just + updates it if the bucket exists *) + val add : context -> value -> context Lwt.t + + (** When the value is [Some v], allocates the data and initializes + it with [v] ; just updates it if the bucket exists. When the + value is [None], delete the storage bucket when the value ; does + nothing if the bucket does not exists. *) + val add_or_remove : context -> value option -> context Lwt.t + + (** Delete the storage bucket ; returns a {!Storage_error + Missing_key} if the bucket does not exists *) val remove_existing : context -> context tzresult Lwt.t + (** Removes the storage bucket and its contents ; does nothing if + the bucket does not exists *) val remove : context -> context Lwt.t end end -- GitLab From acd81174bca345395f66606866551198221b834f Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Fri, 29 Jul 2022 16:44:24 +0900 Subject: [PATCH 05/20] Protocol Storage : comments --- .../lib_protocol/raw_context_intf.ml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/raw_context_intf.ml b/src/proto_alpha/lib_protocol/raw_context_intf.ml index f6534819ea33..ea9b413c6b6f 100644 --- a/src/proto_alpha/lib_protocol/raw_context_intf.ml +++ b/src/proto_alpha/lib_protocol/raw_context_intf.ml @@ -560,11 +560,16 @@ module type T = sig val description : t Storage_description.t - (** The type for relative context accesses instead from the root. In order for - the carbonated storage functions to consume the gas, this has gas infomation - *) + (** The type for local context accesses instead from the root. In order for + the carbonated storage functions to consume the gas, this has gas + infomation *) type local_context + (** + Use for local access from the directory of [key]. + If you want to write access, set [add_back] to [true]. + Otherwise, the written content will be ignored. + *) val with_local_context : add_back:bool -> t -> @@ -573,6 +578,8 @@ module type T = sig (t * 'a) tzresult Lwt.t module Local_context : sig + (** [Local_context] provides functions for local access from a specific + directory. *) include VIEW with type t = local_context @@ -580,9 +587,14 @@ module type T = sig and type key := key and type value := value + (** Internally used in {!Storage_functors} to consume gas from + within a view. May raise {!Block_quota_exceeded} or + {!Operation_quota_exceeded}. *) val consume_gas : local_context -> Gas_limit_repr.cost -> local_context tzresult + (** Internally used in {!Storage_functors} to retrieve a full key + from partial key relative a view. *) val absolute_key : local_context -> key -> key end end -- GitLab From ae6e3207104333c9bed0c6c429059a045a3ae04c Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Wed, 10 Aug 2022 16:57:50 +0900 Subject: [PATCH 06/20] Protocol Storage : local_context is substituted same as global context `t` see: https://gitlab.com/tezos/tezos/-/merge_requests/5922#note_1041534358 --- src/proto_alpha/lib_protocol/raw_context.ml | 21 +++++++++---------- src/proto_alpha/lib_protocol/raw_context.mli | 3 +-- .../lib_protocol/storage_functors.ml | 17 +++++++++++---- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 79caf278d4d3..ee6017a10389 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1021,23 +1021,12 @@ type value = bytes type tree = Context.tree -(* The type for relative context accesses instead from the root. In order for - the carbonated storage functions to consume the gas, this has gas infomation -*) -type local_context = { - tree : tree; - path : key; - remaining_operation_gas : Gas_limit_repr.Arith.fp; - unlimited_operation_gas : bool; -} - module type T = Raw_context_intf.T with type root := root and type key := key and type value := value and type tree := tree - and type local_context := local_context let mem ctxt k = Context.mem (context ctxt) k @@ -1565,6 +1554,16 @@ module Dal = struct let shards ctxt ~endorser = compute_shards ~index:0 ctxt ~endorser end +(* The type for relative context accesses instead from the root. In order for + the carbonated storage functions to consume the gas, this has gas infomation +*) +type local_context = { + tree : tree; + path : key; + remaining_operation_gas : Gas_limit_repr.Arith.fp; + unlimited_operation_gas : bool; +} + let with_local_context ~add_back ctxt key f = (find_tree ctxt key >|= function None -> Tree.empty ctxt | Some tree -> tree) >>= fun tree -> diff --git a/src/proto_alpha/lib_protocol/raw_context.mli b/src/proto_alpha/lib_protocol/raw_context.mli index 8c44aaf2752e..f261d227478a 100644 --- a/src/proto_alpha/lib_protocol/raw_context.mli +++ b/src/proto_alpha/lib_protocol/raw_context.mli @@ -189,9 +189,8 @@ module type T = and type key := key and type value := value and type tree := tree - and type local_context := local_context -include T with type t := t +include T with type t := t and type local_context := local_context (** Initialize the local nonce used for preventing a script to duplicate an internal operation to replay it. *) diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 717816e4d286..ccdf4b38ece4 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -68,9 +68,12 @@ let decode_len_value key len = | Some len -> ok len module Make_subcontext (R : REGISTER) (C : Raw_context.T) (N : NAME) : - Raw_context.T with type t = C.t = struct + Raw_context.T with type t = C.t and type local_context = C.local_context = +struct type t = C.t + type local_context = C.local_context + let to_key k = N.name @ k let mem t k = C.mem t (to_key k) @@ -659,7 +662,8 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : Indexed_raw_context with type t = C.t and type key = I.t - and type 'a ipath = 'a I.ipath = struct + and type 'a ipath = 'a I.ipath + and type local_context = C.local_context = struct type t = C.t type context = t @@ -668,7 +672,7 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : type 'a ipath = 'a I.ipath - type local_context = Raw_context.local_context + type local_context = C.local_context let clear t = C.remove t [] >|= fun t -> C.project t @@ -705,9 +709,14 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : let pack = Storage_description.pack I.args - module Raw_context : Raw_context.T with type t = C.t I.ipath = struct + module Raw_context : + Raw_context.T + with type t = C.t I.ipath + and type local_context = C.local_context = struct type t = C.t I.ipath + type local_context = C.local_context + let to_key i k = I.to_path i k let mem c k = -- GitLab From 363905726c8bd0e1658504c42d1e6d3542cc8705 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Thu, 17 Jun 2021 10:32:55 +0900 Subject: [PATCH 07/20] Storage Protocol: optimize Big_map updating using local tree Protocol Storage: introduce gas_info Protocol Storage: show tree type Protocol Storage: Add local access functions to Make_indexed_carbonated_data_storage Protocol Storage: local remove and add for Big_map.Constants Protocol Storage: update gas Storage Protocol : gas_info set/get from constexts Protocol Storage : using local api Protocol Storage : apply update diff using local access Protocol Storage : fmt Protocol Storage: rebase on master Storage protocol : choose improved one Storage protocol: licenses Protocol Storage: @fmt Storage protocol: .. Storage Protocol: introduce local context Storage Protocol: fix the problem of add local Protocol Storage: rename functions for reviews: * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_806513139 * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_806514454 * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_806515367 * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_806536934 Protocol Storage: hide tree type Protocol Storage: move local_context to the interface Raw_context.T Protocol storage: add function apis for local access to Non_iterable_indexed_carbonated_storage_with_local_context Protocol Storage: rename Protocol Storage: Remove unneeded type interfaces https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_827410999 Protocol Storage: Expose only abstract function to treat local context (thanks the review: https://gitlab.com/tezos/tezos/-/merge_requests/3685) Protocol Storage: introduce Local sub module Thanks for the review https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_835825685 Protocol Storage: revert an unnecessary change review: https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_835788002 Storage protocol : refactor for reviews: * using Option.map: https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_842760659 * rename to Local_context : https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_842761340 * remove a unnecessary comment https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_842763436 * fix a comment: https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_842763559 Protocol Storage: refactor * rename using_... to with_...: https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_842776474 Protocol Storage: remove unneccessary rename for https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_862461337 Protocol Storage: renamed for the review https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_862452452 Storage Protocol: rename variables for the review: https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_862490858 Protocol Storage: delete unnecessary lines Protocol Storage : Some functions are defined locally to prevent mosusing. Thanks to the review: https://gitlab.com/tezos/tezos/-/merge_requests/3685/diffs#note_866531180 Protocol Storage : fix comments. * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_881720668 * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_881727142 * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_881772339 Protocol Storage : move lines of Local module * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_882018721 Protocol Storage : avoid hardcording of ["contents"] directory path. * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_881694117 * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_881693055 Protocol Storage : fix for reviews * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_882418153 * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_882367554 * https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_882329904 Protocol Storage : deserializing gas cost * for the review: https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_882333499 Protocol Storage : move the function `with_local_context` to more generic signature * for the review: https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_882337575 Protocol Storage : fix a comment review: https://gitlab.com/tezos/tezos/-/merge_requests/3685/diffs#note_882329243 Protocol Storage : rebased --- .../lib_protocol/lazy_storage_diff.ml | 29 ++-- src/proto_alpha/lib_protocol/raw_context.ml | 50 ++++-- .../lib_protocol/raw_context_intf.ml | 3 + src/proto_alpha/lib_protocol/storage.ml | 28 ++++ src/proto_alpha/lib_protocol/storage.mli | 2 +- .../lib_protocol/storage_functors.ml | 146 +++++++++++++++++- .../lib_protocol/storage_functors.mli | 2 +- src/proto_alpha/lib_protocol/storage_sigs.ml | 35 ++++- 8 files changed, 263 insertions(+), 32 deletions(-) diff --git a/src/proto_alpha/lib_protocol/lazy_storage_diff.ml b/src/proto_alpha/lib_protocol/lazy_storage_diff.ml index 791b3f828448..53cdddde6397 100644 --- a/src/proto_alpha/lib_protocol/lazy_storage_diff.ml +++ b/src/proto_alpha/lib_protocol/lazy_storage_diff.ml @@ -118,7 +118,8 @@ module Big_map = struct Storage.Big_map.Key_type.init ctxt id key_type >>=? fun ctxt -> Storage.Big_map.Value_type.init ctxt id value_type - let apply_update ctxt ~id + (* [local_ctxt] points to the directory of the big_map *) + let apply_update local_ctxt { key = _key_is_shown_only_on_the_receipt_in_print_big_map_diff; key_hash; @@ -126,27 +127,29 @@ module Big_map = struct } = match value with | None -> - Storage.Big_map.Contents.remove (ctxt, id) key_hash - >|=? fun (ctxt, freed, existed) -> + Storage.Big_map.Contents.Local.remove local_ctxt key_hash + >|=? fun (local_ctxt, freed, existed) -> let freed = if existed then freed + bytes_size_for_big_map_key else freed in - (ctxt, Z.of_int ~-freed) + (local_ctxt, Z.of_int ~-freed) | Some v -> - Storage.Big_map.Contents.add (ctxt, id) key_hash v - >|=? fun (ctxt, size_diff, existed) -> + Storage.Big_map.Contents.Local.add local_ctxt key_hash v + >|=? fun (local_ctxt, size_diff, existed) -> let size_diff = if existed then size_diff else size_diff + bytes_size_for_big_map_key in - (ctxt, Z.of_int size_diff) + (local_ctxt, Z.of_int size_diff) let apply_updates ctxt ~id updates = - List.fold_left_es - (fun (ctxt, size) update -> - apply_update ctxt ~id update >|=? fun (ctxt, added_size) -> - (ctxt, Z.add size added_size)) - (ctxt, Z.zero) - updates + Storage.Big_map.Contents.with_local_context (ctxt, id) (fun local_ctxt -> + List.fold_left_es + (fun (local_ctxt, size) update -> + apply_update local_ctxt update >|=? fun (local_ctxt, added_size) -> + (local_ctxt, Z.add size added_size)) + (local_ctxt, Z.zero) + updates) + >|=? fun ((ctxt, _id), size_diff) -> (ctxt, size_diff) include Storage.Big_map end diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index ee6017a10389..96f395134a1b 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1583,19 +1583,43 @@ let with_local_context ~add_back ctxt key f = update_unlimited_operation_gas ctxt local_ctxt.unlimited_operation_gas |> fun ctxt -> ok (ctxt, res) -module Local_context : sig - include - Raw_context_intf.VIEW - with type t = local_context - and type key := key - and type value := value - and type tree := tree - - val consume_gas : - local_context -> Gas_limit_repr.cost -> local_context tzresult - - val absolute_key : local_context -> key -> key -end = struct +let make_local_context ctxt path = + { + tree = Tree.empty ctxt; + path; + remaining_operation_gas = remaining_operation_gas ctxt; + unlimited_operation_gas = unlimited_operation_gas ctxt; + } + +let with_local_context ctxt key f = + let find_local_context ctxt key = + find_tree ctxt key + >|= Option.map (fun tree -> + { + tree; + path = key; + remaining_operation_gas = remaining_operation_gas ctxt; + unlimited_operation_gas = unlimited_operation_gas ctxt; + }) + in + (find_local_context ctxt key >>= function + | Some local_ctxt -> + f local_ctxt >>=? fun (local_ctxt, res) -> + update_tree ctxt key local_ctxt.tree >|=? fun ctxt -> + (ctxt, local_ctxt, res) + | None -> + let local_ctxt = make_local_context ctxt key in + f local_ctxt >>=? fun (local_ctxt, res) -> + add_tree ctxt key local_ctxt.tree >|= fun ctxt -> + ok (ctxt, local_ctxt, res)) + >|=? fun (ctxt, local_ctxt, res) -> + update_remaining_operation_gas ctxt local_ctxt.remaining_operation_gas + |> fun ctxt -> + update_unlimited_operation_gas ctxt local_ctxt.unlimited_operation_gas + |> fun ctxt -> (ctxt, res) + + +module Local_context = struct type t = local_context let consume_gas local cost = diff --git a/src/proto_alpha/lib_protocol/raw_context_intf.ml b/src/proto_alpha/lib_protocol/raw_context_intf.ml index ea9b413c6b6f..17150ca713f1 100644 --- a/src/proto_alpha/lib_protocol/raw_context_intf.ml +++ b/src/proto_alpha/lib_protocol/raw_context_intf.ml @@ -457,6 +457,9 @@ module type T = sig include VIEW + (** The type for relative context accesses instead from the root *) + type local_context + module Tree : TREE with type t := t diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 0902183524b8..1226237990a2 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -542,7 +542,35 @@ module Big_map = struct | Some value -> consume_deserialize_gas ctxt value >|? fun ctxt -> (ctxt, value_opt) + let keys_unaccounted = I.keys_unaccounted + + let with_local_context = I.with_local_context + + module Local = struct + include I.Local + + let consume_deserialize_gas local_ctxt value = + Raw_context.Local_context.consume_gas + local_ctxt + (Script_repr.deserialized_cost value) + + let get local_ctxt contract = + I.Local.get local_ctxt contract >>=? fun (local_ctxt, value) -> + Lwt.return + ( consume_deserialize_gas local_ctxt value >|? fun local_ctxt -> + (local_ctxt, value) ) + + let find local_ctxt contract = + I.Local.find local_ctxt contract >>=? fun (local_ctxt, value_opt) -> + Lwt.return + @@ + match value_opt with + | None -> ok (local_ctxt, None) + | Some value -> + consume_deserialize_gas local_ctxt value >|? fun local_ctxt -> + (local_ctxt, value_opt) + end end end diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index bc1845e62d1c..64469afb3855 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -244,7 +244,7 @@ module Big_map : sig module Contents : sig include - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_local_context with type key = Script_expr_hash.t and type value = Script_repr.expr and type t := key diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index ccdf4b38ece4..2db81b5abe78 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -149,7 +149,17 @@ struct let with_local_context ~add_back ctxt k f = C.with_local_context ~add_back ctxt (to_key k) f - module Local_context = C.Local_context + module Local_context = struct + type t = C.Local_context.t + + let consume_gas = C.Local_context.consume_gas + + let tree = C.Local_context.tree + + let update_tree = C.Local_context.update_tree + + let absolute_key local key = C.Local_context.absolute_key local (to_key key) + end end module Make_single_data_storage @@ -471,6 +481,122 @@ module Make_indexed_carbonated_data_storage_INTERNAL let add_or_remove s i v = match v with None -> remove s i | Some v -> add s i v + let with_local_context s f = C.with_local_context s [] f + + module Local = struct + type context = Raw_context.local_context + + let consume_mem_gas local key = + C.Local_context.consume_gas + local + (Storage_costs.read_access ~path_length:(List.length key) ~read_bytes:0) + + let existing_size tree i = + C.Tree.find tree (len_key i) >|= function + | None -> ok (0, false) + | Some len -> decode_len_value (len_key i) len >|? fun len -> (len, true) + + let consume_read_gas get local i = + let len_key = len_key i in + get (C.Local_context.tree local) len_key >>=? fun len -> + Lwt.return + ( decode_len_value len_key len >>? fun read_bytes -> + let cost = + Storage_costs.read_access + ~path_length:(List.length len_key) + ~read_bytes + in + C.Local_context.consume_gas local cost ) + + let consume_serialize_write_gas set local i v = + let bytes = to_bytes v in + let len = Bytes.length bytes in + C.Local_context.consume_gas local (Gas_limit_repr.alloc_mbytes_cost len) + >>?= fun local -> + let cost = Storage_costs.write_access ~written_bytes:len in + C.Local_context.consume_gas local cost >>?= fun local -> + set (C.Local_context.tree local) (len_key i) (encode_len_value bytes) + >|=? fun tree -> (C.Local_context.update_tree local tree, bytes) + + let consume_remove_gas del local i = + C.Local_context.consume_gas + local + (Storage_costs.write_access ~written_bytes:0) + >>?= fun local -> + del (C.Local_context.tree local) (len_key i) >|=? fun tree -> + C.Local_context.update_tree local tree + + let mem local i = + let key = data_key i in + consume_mem_gas local key >>?= fun local -> + let tree = C.Local_context.tree local in + C.Tree.mem tree key >|= fun exists -> ok (local, exists) + + let get local i = + let get tree i = C.Tree.get tree i in + consume_read_gas get local i >>=? fun local -> + get (C.Local_context.tree local) (data_key i) >>=? fun b -> + let key () = C.Local_context.absolute_key local (data_key i) in + Lwt.return (of_bytes ~key b >|? fun v -> (local, v)) + + let find local i = + let key = data_key i in + consume_mem_gas local key >>?= fun local -> + let tree = C.Local_context.tree local in + C.Tree.mem tree key >>= fun exists -> + if exists then get local i >|=? fun (local, v) -> (local, Some v) + else return (local, None) + + let update local i v = + let tree = C.Local_context.tree local in + existing_size tree i >>=? fun (prev_size, _) -> + let update tree key b = C.Tree.update tree key b in + consume_serialize_write_gas update local i v >>=? fun (local, bytes) -> + update tree (data_key i) bytes >|=? fun tree -> + let size_diff = Bytes.length bytes - prev_size in + let local = C.Local_context.update_tree local tree in + (local, size_diff) + + let init local i v = + let init tree key b = C.Tree.init tree key b in + consume_serialize_write_gas init local i v >>=? fun (local, bytes) -> + let tree = C.Local_context.tree local in + init tree (data_key i) bytes >|=? fun tree -> + let local = C.Local_context.update_tree local tree in + let size = Bytes.length bytes in + (local, size) + + let add local i v = + let add tree i b = C.Tree.add tree i b >|= fun tree -> ok tree in + let tree = C.Local_context.tree local in + existing_size tree i >>=? fun (prev_size, existed) -> + consume_serialize_write_gas add local i v >>=? fun (local, bytes) -> + add (C.Local_context.tree local) (data_key i) bytes >|=? fun tree -> + let local = C.Local_context.update_tree local tree in + let size_diff = Bytes.length bytes - prev_size in + (local, size_diff, existed) + + let remove local i = + let remove tree i = C.Tree.remove tree i >|= ok in + let tree = C.Local_context.tree local in + existing_size tree i >>=? fun (prev_size, existed) -> + consume_remove_gas remove local i >>=? fun local -> + remove tree (data_key i) >|=? fun tree -> + let local = C.Local_context.update_tree local tree in + (local, prev_size, existed) + + let remove_existing local i = + existing_size (C.Local_context.tree local) i >>=? fun (prev_size, _) -> + let remove_existing tree key = C.Tree.remove_existing tree key in + consume_remove_gas remove_existing local i >>=? fun local -> + remove_existing (C.Local_context.tree local) (data_key i) >|=? fun tree -> + let local = C.Local_context.update_tree local tree in + (local, prev_size) + + let add_or_remove local i v = + match v with None -> remove local i | Some v -> add local i v + end + (** Because big map values are not stored under some common key, we have no choice but to fold over all nodes with a path of length [I.path_length] to retrieve actual keys and then paginate. @@ -553,7 +679,7 @@ module Make_indexed_carbonated_data_storage : functor (I : INDEX) (V : VALUE) -> - Non_iterable_indexed_carbonated_data_storage_with_values + Non_iterable_indexed_carbonated_data_storage_with_local_context with type t = C.t and type key = I.t and type value = V.t = @@ -846,7 +972,21 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : C.with_local_context ~add_back t (to_key i k) f >|=? fun (t, res) -> (pack t i, res) - module Local_context = C.Local_context + let with_local_context c k f = + let (t, i) = unpack c in + C.with_local_context t (to_key i k) f >|=? fun (t, res) -> (pack t i, res) + + module Local_context = struct + type t = C.Local_context.t + + let consume_gas local gas = C.Local_context.consume_gas local gas + + let tree = C.Local_context.tree + + let update_tree = C.Local_context.update_tree + + let absolute_key = C.Local_context.absolute_key + end end let with_local_context ~add_back s i f = diff --git a/src/proto_alpha/lib_protocol/storage_functors.mli b/src/proto_alpha/lib_protocol/storage_functors.mli index e83a1f9da791..0b1dcbb8edf5 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.mli +++ b/src/proto_alpha/lib_protocol/storage_functors.mli @@ -84,7 +84,7 @@ module Make_indexed_carbonated_data_storage (C : Raw_context.T) (I : INDEX) (V : VALUE) : - Non_iterable_indexed_carbonated_data_storage_with_values + Non_iterable_indexed_carbonated_data_storage_with_local_context with type t = C.t and type key = I.t and type value = V.t diff --git a/src/proto_alpha/lib_protocol/storage_sigs.ml b/src/proto_alpha/lib_protocol/storage_sigs.ml index 3921221ad5c3..2d57bb85a16d 100644 --- a/src/proto_alpha/lib_protocol/storage_sigs.ml +++ b/src/proto_alpha/lib_protocol/storage_sigs.ml @@ -226,9 +226,42 @@ module type Non_iterable_indexed_carbonated_data_storage_with_values = sig (Raw_context.t * (key * value) list) tzresult Lwt.t end -module type Non_iterable_indexed_carbonated_data_storage_INTERNAL = sig +module type Non_iterable_indexed_carbonated_data_storage_with_local_context = sig include Non_iterable_indexed_carbonated_data_storage_with_values + val with_local_context : + context -> + (Raw_context.local_context -> + (Raw_context.local_context * 'a) tzresult Lwt.t) -> + (context * 'a) tzresult Lwt.t + + module Local : sig + type context = Raw_context.local_context + + val mem : context -> key -> (context * bool) tzresult Lwt.t + + val get : context -> key -> (context * value) tzresult Lwt.t + + val find : context -> key -> (context * value option) tzresult Lwt.t + + val update : context -> key -> value -> (context * int) tzresult Lwt.t + + val init : context -> key -> value -> (context * int) tzresult Lwt.t + + val add : context -> key -> value -> (context * int * bool) tzresult Lwt.t + + val add_or_remove : + context -> key -> value option -> (context * int * bool) tzresult Lwt.t + + val remove_existing : context -> key -> (context * int) tzresult Lwt.t + + val remove : context -> key -> (context * int * bool) tzresult Lwt.t + end +end + +module type Non_iterable_indexed_carbonated_data_storage_INTERNAL = sig + include Non_iterable_indexed_carbonated_data_storage_with_local_context + val fold_keys_unaccounted : context -> order:[`Sorted | `Undefined] -> -- GitLab From bca212090f842a3eaa2e3b446e7b5f4fdd03af47 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Fri, 1 Apr 2022 14:51:10 +0900 Subject: [PATCH 08/20] Protocol Storage: Fixed a bug that `len` file was not removed --- src/proto_alpha/lib_protocol/storage_functors.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 2db81b5abe78..d36aa7a292b8 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -581,6 +581,7 @@ module Make_indexed_carbonated_data_storage_INTERNAL let tree = C.Local_context.tree local in existing_size tree i >>=? fun (prev_size, existed) -> consume_remove_gas remove local i >>=? fun local -> + let tree = C.Local_context.tree local in remove tree (data_key i) >|=? fun tree -> let local = C.Local_context.update_tree local tree in (local, prev_size, existed) -- GitLab From e7e440853f5f51af3733257f24612f2d8f1f71d0 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Fri, 1 Apr 2022 20:42:35 +0900 Subject: [PATCH 09/20] Protocol Storage : refactored `with_local_context` * review: https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_882367554 --- src/proto_alpha/lib_protocol/raw_context.ml | 33 ++++++++------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 96f395134a1b..5c7a2789e8ef 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1592,31 +1592,22 @@ let make_local_context ctxt path = } let with_local_context ctxt key f = - let find_local_context ctxt key = - find_tree ctxt key - >|= Option.map (fun tree -> - { - tree; - path = key; - remaining_operation_gas = remaining_operation_gas ctxt; - unlimited_operation_gas = unlimited_operation_gas ctxt; - }) + (find_tree ctxt key >|= function None -> Tree.empty ctxt | Some tree -> tree) + >>= fun tree -> + let local_ctxt = + { + tree; + path = key; + remaining_operation_gas = remaining_operation_gas ctxt; + unlimited_operation_gas = unlimited_operation_gas ctxt; + } in - (find_local_context ctxt key >>= function - | Some local_ctxt -> - f local_ctxt >>=? fun (local_ctxt, res) -> - update_tree ctxt key local_ctxt.tree >|=? fun ctxt -> - (ctxt, local_ctxt, res) - | None -> - let local_ctxt = make_local_context ctxt key in - f local_ctxt >>=? fun (local_ctxt, res) -> - add_tree ctxt key local_ctxt.tree >|= fun ctxt -> - ok (ctxt, local_ctxt, res)) - >|=? fun (ctxt, local_ctxt, res) -> + f local_ctxt >>=? fun (local_ctxt, res) -> + add_tree ctxt key local_ctxt.tree >|= fun ctxt -> update_remaining_operation_gas ctxt local_ctxt.remaining_operation_gas |> fun ctxt -> update_unlimited_operation_gas ctxt local_ctxt.unlimited_operation_gas - |> fun ctxt -> (ctxt, res) + |> fun ctxt -> ok (ctxt, res) module Local_context = struct -- GitLab From e78aba4f0e24d26957895071121fac857551e689 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Fri, 1 Apr 2022 22:37:33 +0900 Subject: [PATCH 10/20] Protocol Storage: Take into account the gas cost of local tree access. --- src/proto_alpha/lib_protocol/storage_functors.ml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index d36aa7a292b8..8647dba7a27a 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -481,7 +481,16 @@ module Make_indexed_carbonated_data_storage_INTERNAL let add_or_remove s i v = match v with None -> remove s i | Some v -> add s i v - let with_local_context s f = C.with_local_context s [] f + let with_local_context s f = + (* The gas cost for using C.with_local_context are: + - find_tree : To access the directory + - add_tree : `write_access` does not charge the path length. Then no need + to reduce the gas *) + let consume_find_tree_gas c = + let path_length = List.length @@ C.absolute_key c [] in + C.consume_gas c (Storage_costs.read_access ~path_length ~read_bytes:0) + in + consume_find_tree_gas s >>?= fun s -> C.with_local_context s [] f module Local = struct type context = Raw_context.local_context -- GitLab From ffdd8c37723808b8eb0c1af799442fc597b0dad5 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Sat, 2 Apr 2022 01:59:59 +0900 Subject: [PATCH 11/20] Storage Protocol: refactoring that internal tree field of local_context is now encapsulated and cannot be referenced directly. --- src/proto_alpha/lib_protocol/raw_context.ml | 1 + .../lib_protocol/storage_functors.ml | 107 ++++++++++-------- 2 files changed, 59 insertions(+), 49 deletions(-) diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 5c7a2789e8ef..6648f9f47d42 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1678,4 +1678,5 @@ module Local_context = struct let config local = Tree.config (tree local) let length local i = Tree.length (tree local) i + end diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 8647dba7a27a..d46a1e85c12a 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -154,11 +154,24 @@ struct let consume_gas = C.Local_context.consume_gas - let tree = C.Local_context.tree + let absolute_key local key = C.Local_context.absolute_key local (to_key key) - let update_tree = C.Local_context.update_tree + let mem local key = C.Local_context.mem local (to_key key) - let absolute_key local key = C.Local_context.absolute_key local (to_key key) + let get local key = C.Local_context.get local (to_key key) + + let find local key = C.Local_context.find local (to_key key) + + let init local key = C.Local_context.init local (to_key key) + + let update local key = C.Local_context.update local (to_key key) + + let add local key = C.Local_context.add local (to_key key) + + let remove local key = C.Local_context.remove local (to_key key) + + let remove_existing local key = + C.Local_context.remove_existing local (to_key key) end end @@ -500,14 +513,14 @@ module Make_indexed_carbonated_data_storage_INTERNAL local (Storage_costs.read_access ~path_length:(List.length key) ~read_bytes:0) - let existing_size tree i = - C.Tree.find tree (len_key i) >|= function + let existing_size local i = + C.Local_context.find local (len_key i) >|= function | None -> ok (0, false) | Some len -> decode_len_value (len_key i) len >|? fun len -> (len, true) let consume_read_gas get local i = let len_key = len_key i in - get (C.Local_context.tree local) len_key >>=? fun len -> + get local len_key >>=? fun len -> Lwt.return ( decode_len_value len_key len >>? fun read_bytes -> let cost = @@ -524,83 +537,67 @@ module Make_indexed_carbonated_data_storage_INTERNAL >>?= fun local -> let cost = Storage_costs.write_access ~written_bytes:len in C.Local_context.consume_gas local cost >>?= fun local -> - set (C.Local_context.tree local) (len_key i) (encode_len_value bytes) - >|=? fun tree -> (C.Local_context.update_tree local tree, bytes) + set local (len_key i) (encode_len_value bytes) >|=? fun local -> + (local, bytes) let consume_remove_gas del local i = C.Local_context.consume_gas local (Storage_costs.write_access ~written_bytes:0) - >>?= fun local -> - del (C.Local_context.tree local) (len_key i) >|=? fun tree -> - C.Local_context.update_tree local tree + >>?= fun local -> del local (len_key i) let mem local i = let key = data_key i in consume_mem_gas local key >>?= fun local -> - let tree = C.Local_context.tree local in - C.Tree.mem tree key >|= fun exists -> ok (local, exists) + C.Local_context.mem local key >|= fun exists -> ok (local, exists) let get local i = - let get tree i = C.Tree.get tree i in - consume_read_gas get local i >>=? fun local -> - get (C.Local_context.tree local) (data_key i) >>=? fun b -> + consume_read_gas C.Local_context.get local i >>=? fun local -> + C.Local_context.get local (data_key i) >>=? fun b -> let key () = C.Local_context.absolute_key local (data_key i) in Lwt.return (of_bytes ~key b >|? fun v -> (local, v)) let find local i = let key = data_key i in consume_mem_gas local key >>?= fun local -> - let tree = C.Local_context.tree local in - C.Tree.mem tree key >>= fun exists -> + C.Local_context.mem local key >>= fun exists -> if exists then get local i >|=? fun (local, v) -> (local, Some v) else return (local, None) let update local i v = - let tree = C.Local_context.tree local in - existing_size tree i >>=? fun (prev_size, _) -> - let update tree key b = C.Tree.update tree key b in - consume_serialize_write_gas update local i v >>=? fun (local, bytes) -> - update tree (data_key i) bytes >|=? fun tree -> + existing_size local i >>=? fun (prev_size, _) -> + consume_serialize_write_gas C.Local_context.update local i v + >>=? fun (local, bytes) -> + C.Local_context.update local (data_key i) bytes >|=? fun local -> let size_diff = Bytes.length bytes - prev_size in - let local = C.Local_context.update_tree local tree in (local, size_diff) let init local i v = - let init tree key b = C.Tree.init tree key b in - consume_serialize_write_gas init local i v >>=? fun (local, bytes) -> - let tree = C.Local_context.tree local in - init tree (data_key i) bytes >|=? fun tree -> - let local = C.Local_context.update_tree local tree in + consume_serialize_write_gas C.Local_context.init local i v + >>=? fun (local, bytes) -> + C.Local_context.init local (data_key i) bytes >|=? fun local -> let size = Bytes.length bytes in (local, size) let add local i v = - let add tree i b = C.Tree.add tree i b >|= fun tree -> ok tree in - let tree = C.Local_context.tree local in - existing_size tree i >>=? fun (prev_size, existed) -> + let add local i v = C.Local_context.add local i v >|= ok in + existing_size local i >>=? fun (prev_size, existed) -> consume_serialize_write_gas add local i v >>=? fun (local, bytes) -> - add (C.Local_context.tree local) (data_key i) bytes >|=? fun tree -> - let local = C.Local_context.update_tree local tree in + add local (data_key i) bytes >|=? fun local -> let size_diff = Bytes.length bytes - prev_size in (local, size_diff, existed) let remove local i = - let remove tree i = C.Tree.remove tree i >|= ok in - let tree = C.Local_context.tree local in - existing_size tree i >>=? fun (prev_size, existed) -> + let remove local i = C.Local_context.remove local i >|= ok in + existing_size local i >>=? fun (prev_size, existed) -> consume_remove_gas remove local i >>=? fun local -> - let tree = C.Local_context.tree local in - remove tree (data_key i) >|=? fun tree -> - let local = C.Local_context.update_tree local tree in - (local, prev_size, existed) + remove local (data_key i) >|=? fun local -> (local, prev_size, existed) let remove_existing local i = - existing_size (C.Local_context.tree local) i >>=? fun (prev_size, _) -> - let remove_existing tree key = C.Tree.remove_existing tree key in - consume_remove_gas remove_existing local i >>=? fun local -> - remove_existing (C.Local_context.tree local) (data_key i) >|=? fun tree -> - let local = C.Local_context.update_tree local tree in + existing_size local i >>=? fun (prev_size, _) -> + consume_remove_gas C.Local_context.remove_existing local i + >>=? fun local -> + C.Local_context.remove_existing local (data_key i) >|=? fun local -> (local, prev_size) let add_or_remove local i v = @@ -991,11 +988,23 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : let consume_gas local gas = C.Local_context.consume_gas local gas - let tree = C.Local_context.tree + let absolute_key = C.Local_context.absolute_key - let update_tree = C.Local_context.update_tree + let mem local k = C.Local_context.mem local k - let absolute_key = C.Local_context.absolute_key + let get local k = C.Local_context.get local k + + let find local k = C.Local_context.find local k + + let init local k = C.Local_context.init local k + + let update local k = C.Local_context.update local k + + let add local k = C.Local_context.add local k + + let remove local k = C.Local_context.remove local k + + let remove_existing local k = C.Local_context.remove_existing local k end end -- GitLab From d79c557eaa72fc579583b35ad4eb1dc9596dd6fa Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Tue, 26 Apr 2022 12:19:31 +0900 Subject: [PATCH 12/20] Protocol Storage : use VIEW interface for local context module --- src/proto_alpha/lib_protocol/raw_context.ml | 1 - .../lib_protocol/storage_functors.ml | 56 +++---------------- 2 files changed, 8 insertions(+), 49 deletions(-) diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 6648f9f47d42..26e2ca07ece8 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1609,7 +1609,6 @@ let with_local_context ctxt key f = update_unlimited_operation_gas ctxt local_ctxt.unlimited_operation_gas |> fun ctxt -> ok (ctxt, res) - module Local_context = struct type t = local_context diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index d46a1e85c12a..3c7e78fae062 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -149,30 +149,7 @@ struct let with_local_context ~add_back ctxt k f = C.with_local_context ~add_back ctxt (to_key k) f - module Local_context = struct - type t = C.Local_context.t - - let consume_gas = C.Local_context.consume_gas - - let absolute_key local key = C.Local_context.absolute_key local (to_key key) - - let mem local key = C.Local_context.mem local (to_key key) - - let get local key = C.Local_context.get local (to_key key) - - let find local key = C.Local_context.find local (to_key key) - - let init local key = C.Local_context.init local (to_key key) - - let update local key = C.Local_context.update local (to_key key) - - let add local key = C.Local_context.add local (to_key key) - - let remove local key = C.Local_context.remove local (to_key key) - - let remove_existing local key = - C.Local_context.remove_existing local (to_key key) - end + module Local_context = C.Local_context end module Make_single_data_storage @@ -503,7 +480,12 @@ module Make_indexed_carbonated_data_storage_INTERNAL let path_length = List.length @@ C.absolute_key c [] in C.consume_gas c (Storage_costs.read_access ~path_length ~read_bytes:0) in - consume_find_tree_gas s >>?= fun s -> C.with_local_context s [] f + let consume_add_tree_gas c = + C.consume_gas c (Storage_costs.write_access ~written_bytes:0) + in + consume_find_tree_gas s >>?= fun s -> + C.with_local_context s [] f >>=? fun (s, x) -> + consume_add_tree_gas s >>?= fun s -> return (s, x) module Local = struct type context = Raw_context.local_context @@ -983,29 +965,7 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : let (t, i) = unpack c in C.with_local_context t (to_key i k) f >|=? fun (t, res) -> (pack t i, res) - module Local_context = struct - type t = C.Local_context.t - - let consume_gas local gas = C.Local_context.consume_gas local gas - - let absolute_key = C.Local_context.absolute_key - - let mem local k = C.Local_context.mem local k - - let get local k = C.Local_context.get local k - - let find local k = C.Local_context.find local k - - let init local k = C.Local_context.init local k - - let update local k = C.Local_context.update local k - - let add local k = C.Local_context.add local k - - let remove local k = C.Local_context.remove local k - - let remove_existing local k = C.Local_context.remove_existing local k - end + module Local_context = C.Local_context end let with_local_context ~add_back s i f = -- GitLab From 34b48d5e92f0ac9ea609874799b5a09041b80774 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Tue, 26 Apr 2022 16:18:23 +0900 Subject: [PATCH 13/20] Protocol Storage : introduce length function for local context --- src/proto_alpha/lib_protocol/raw_context.ml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 26e2ca07ece8..2c8f10e59391 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1677,5 +1677,4 @@ module Local_context = struct let config local = Tree.config (tree local) let length local i = Tree.length (tree local) i - end -- GitLab From dbc2530fdcb1c121b5f5c26e68a9595c6bcf434c Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Tue, 17 May 2022 19:37:38 +0900 Subject: [PATCH 14/20] Protocol Storage : To the consumption costs remain the same, the additional gas cost when for_write is true is set to zero. --- .../lib_protocol/lazy_storage_diff.ml | 5 ++++- src/proto_alpha/lib_protocol/storage_functors.ml | 16 ++++++++-------- src/proto_alpha/lib_protocol/storage_sigs.ml | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_protocol/lazy_storage_diff.ml b/src/proto_alpha/lib_protocol/lazy_storage_diff.ml index 53cdddde6397..5b3613dbfcf0 100644 --- a/src/proto_alpha/lib_protocol/lazy_storage_diff.ml +++ b/src/proto_alpha/lib_protocol/lazy_storage_diff.ml @@ -142,7 +142,10 @@ module Big_map = struct (local_ctxt, Z.of_int size_diff) let apply_updates ctxt ~id updates = - Storage.Big_map.Contents.with_local_context (ctxt, id) (fun local_ctxt -> + Storage.Big_map.Contents.with_local_context + ~for_write:true + (ctxt, id) + (fun local_ctxt -> List.fold_left_es (fun (local_ctxt, size) update -> apply_update local_ctxt update >|=? fun (local_ctxt, added_size) -> diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 3c7e78fae062..db0e4555da54 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -471,11 +471,14 @@ module Make_indexed_carbonated_data_storage_INTERNAL let add_or_remove s i v = match v with None -> remove s i | Some v -> add s i v - let with_local_context s f = + let with_local_context ~for_write s f = (* The gas cost for using C.with_local_context are: - find_tree : To access the directory - add_tree : `write_access` does not charge the path length. Then no need to reduce the gas *) + (* Remark: To the consumption costs remain the same, the additional gas cost + when for_write is true is set to zero. + *) let consume_find_tree_gas c = let path_length = List.length @@ C.absolute_key c [] in C.consume_gas c (Storage_costs.read_access ~path_length ~read_bytes:0) @@ -483,9 +486,10 @@ module Make_indexed_carbonated_data_storage_INTERNAL let consume_add_tree_gas c = C.consume_gas c (Storage_costs.write_access ~written_bytes:0) in - consume_find_tree_gas s >>?= fun s -> - C.with_local_context s [] f >>=? fun (s, x) -> - consume_add_tree_gas s >>?= fun s -> return (s, x) + (if not for_write then consume_find_tree_gas s else ok s) >>?= fun s -> + C.with_local_context ~for_write s [] f >>=? fun (s, x) -> + (if not for_write then consume_add_tree_gas s else ok s) >>?= fun s -> + return (s, x) module Local = struct type context = Raw_context.local_context @@ -961,10 +965,6 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : C.with_local_context ~add_back t (to_key i k) f >|=? fun (t, res) -> (pack t i, res) - let with_local_context c k f = - let (t, i) = unpack c in - C.with_local_context t (to_key i k) f >|=? fun (t, res) -> (pack t i, res) - module Local_context = C.Local_context end diff --git a/src/proto_alpha/lib_protocol/storage_sigs.ml b/src/proto_alpha/lib_protocol/storage_sigs.ml index 2d57bb85a16d..ffebed95c5ec 100644 --- a/src/proto_alpha/lib_protocol/storage_sigs.ml +++ b/src/proto_alpha/lib_protocol/storage_sigs.ml @@ -230,6 +230,7 @@ module type Non_iterable_indexed_carbonated_data_storage_with_local_context = si include Non_iterable_indexed_carbonated_data_storage_with_values val with_local_context : + for_write:bool -> context -> (Raw_context.local_context -> (Raw_context.local_context * 'a) tzresult Lwt.t) -> -- GitLab From d6eb3e040922f724a85a566d8d98b233b11dfb07 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Fri, 29 Jul 2022 10:26:26 +0900 Subject: [PATCH 15/20] Protocol Storage: rebased --- .../lib_protocol/lazy_storage_diff.ml | 2 +- src/proto_alpha/lib_protocol/raw_context.ml | 26 ------------------- .../lib_protocol/raw_context_intf.ml | 3 --- src/proto_alpha/lib_protocol/storage.ml | 1 - .../lib_protocol/storage_functors.ml | 10 +++---- src/proto_alpha/lib_protocol/storage_sigs.ml | 2 +- 6 files changed, 7 insertions(+), 37 deletions(-) diff --git a/src/proto_alpha/lib_protocol/lazy_storage_diff.ml b/src/proto_alpha/lib_protocol/lazy_storage_diff.ml index 5b3613dbfcf0..7ad9016e67eb 100644 --- a/src/proto_alpha/lib_protocol/lazy_storage_diff.ml +++ b/src/proto_alpha/lib_protocol/lazy_storage_diff.ml @@ -143,7 +143,7 @@ module Big_map = struct let apply_updates ctxt ~id updates = Storage.Big_map.Contents.with_local_context - ~for_write:true + ~add_back:true (ctxt, id) (fun local_ctxt -> List.fold_left_es diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 2c8f10e59391..28ccf79af711 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1583,32 +1583,6 @@ let with_local_context ~add_back ctxt key f = update_unlimited_operation_gas ctxt local_ctxt.unlimited_operation_gas |> fun ctxt -> ok (ctxt, res) -let make_local_context ctxt path = - { - tree = Tree.empty ctxt; - path; - remaining_operation_gas = remaining_operation_gas ctxt; - unlimited_operation_gas = unlimited_operation_gas ctxt; - } - -let with_local_context ctxt key f = - (find_tree ctxt key >|= function None -> Tree.empty ctxt | Some tree -> tree) - >>= fun tree -> - let local_ctxt = - { - tree; - path = key; - remaining_operation_gas = remaining_operation_gas ctxt; - unlimited_operation_gas = unlimited_operation_gas ctxt; - } - in - f local_ctxt >>=? fun (local_ctxt, res) -> - add_tree ctxt key local_ctxt.tree >|= fun ctxt -> - update_remaining_operation_gas ctxt local_ctxt.remaining_operation_gas - |> fun ctxt -> - update_unlimited_operation_gas ctxt local_ctxt.unlimited_operation_gas - |> fun ctxt -> ok (ctxt, res) - module Local_context = struct type t = local_context diff --git a/src/proto_alpha/lib_protocol/raw_context_intf.ml b/src/proto_alpha/lib_protocol/raw_context_intf.ml index 17150ca713f1..ea9b413c6b6f 100644 --- a/src/proto_alpha/lib_protocol/raw_context_intf.ml +++ b/src/proto_alpha/lib_protocol/raw_context_intf.ml @@ -457,9 +457,6 @@ module type T = sig include VIEW - (** The type for relative context accesses instead from the root *) - type local_context - module Tree : TREE with type t := t diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 1226237990a2..ed912f88612d 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -542,7 +542,6 @@ module Big_map = struct | Some value -> consume_deserialize_gas ctxt value >|? fun ctxt -> (ctxt, value_opt) - let keys_unaccounted = I.keys_unaccounted let with_local_context = I.with_local_context diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index db0e4555da54..9a829bfcafdd 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -471,13 +471,13 @@ module Make_indexed_carbonated_data_storage_INTERNAL let add_or_remove s i v = match v with None -> remove s i | Some v -> add s i v - let with_local_context ~for_write s f = + let with_local_context ~add_back s f = (* The gas cost for using C.with_local_context are: - find_tree : To access the directory - add_tree : `write_access` does not charge the path length. Then no need to reduce the gas *) (* Remark: To the consumption costs remain the same, the additional gas cost - when for_write is true is set to zero. + when add_back is true is set to zero. *) let consume_find_tree_gas c = let path_length = List.length @@ C.absolute_key c [] in @@ -486,9 +486,9 @@ module Make_indexed_carbonated_data_storage_INTERNAL let consume_add_tree_gas c = C.consume_gas c (Storage_costs.write_access ~written_bytes:0) in - (if not for_write then consume_find_tree_gas s else ok s) >>?= fun s -> - C.with_local_context ~for_write s [] f >>=? fun (s, x) -> - (if not for_write then consume_add_tree_gas s else ok s) >>?= fun s -> + (if not add_back then consume_find_tree_gas s else ok s) >>?= fun s -> + C.with_local_context ~add_back s [] f >>=? fun (s, x) -> + (if not add_back then consume_add_tree_gas s else ok s) >>?= fun s -> return (s, x) module Local = struct diff --git a/src/proto_alpha/lib_protocol/storage_sigs.ml b/src/proto_alpha/lib_protocol/storage_sigs.ml index ffebed95c5ec..b3bdcba53ac6 100644 --- a/src/proto_alpha/lib_protocol/storage_sigs.ml +++ b/src/proto_alpha/lib_protocol/storage_sigs.ml @@ -230,7 +230,7 @@ module type Non_iterable_indexed_carbonated_data_storage_with_local_context = si include Non_iterable_indexed_carbonated_data_storage_with_values val with_local_context : - for_write:bool -> + add_back:bool -> context -> (Raw_context.local_context -> (Raw_context.local_context * 'a) tzresult Lwt.t) -> -- GitLab From 851274a67eb1bac14d2eae6da83e37f76e6cf380 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Tue, 9 Aug 2022 16:18:32 +0900 Subject: [PATCH 16/20] Protocol Storage : gas for write mode --- src/proto_alpha/lib_protocol/storage_functors.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 9a829bfcafdd..08d7df26fb70 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -486,7 +486,7 @@ module Make_indexed_carbonated_data_storage_INTERNAL let consume_add_tree_gas c = C.consume_gas c (Storage_costs.write_access ~written_bytes:0) in - (if not add_back then consume_find_tree_gas s else ok s) >>?= fun s -> + consume_find_tree_gas s >>?= fun s -> C.with_local_context ~add_back s [] f >>=? fun (s, x) -> (if not add_back then consume_add_tree_gas s else ok s) >>?= fun s -> return (s, x) -- GitLab From ffaa8cee014c9ff47410ebc91e0c637b1afd724c Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Thu, 11 Aug 2022 11:30:22 +0900 Subject: [PATCH 17/20] Protocol Storage : rebased --- src/proto_alpha/lib_protocol/storage.ml | 2 ++ src/proto_alpha/lib_protocol/storage_functors.ml | 6 +++++- src/proto_alpha/lib_protocol/storage_functors.mli | 4 +++- src/proto_alpha/lib_protocol/storage_sigs.ml | 10 ++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index ed912f88612d..0141fd76bf0c 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -502,6 +502,8 @@ module Big_map = struct type context = I.context + type local_context = I.local_context + type key = I.key type value = I.value diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 08d7df26fb70..3d2e09c791c3 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -367,12 +367,15 @@ module Make_indexed_carbonated_data_storage_INTERNAL (V : VALUE) : Non_iterable_indexed_carbonated_data_storage_INTERNAL with type t = C.t + and type local_context = C.local_context and type key = I.t and type value = V.t = struct type t = C.t type context = t + type local_context = C.local_context + type key = I.t type value = V.t @@ -492,7 +495,7 @@ module Make_indexed_carbonated_data_storage_INTERNAL return (s, x) module Local = struct - type context = Raw_context.local_context + type context = local_context let consume_mem_gas local key = C.Local_context.consume_gas @@ -674,6 +677,7 @@ module Make_indexed_carbonated_data_storage : functor -> Non_iterable_indexed_carbonated_data_storage_with_local_context with type t = C.t + and type local_context = C.local_context and type key = I.t and type value = V.t = Make_indexed_carbonated_data_storage_INTERNAL diff --git a/src/proto_alpha/lib_protocol/storage_functors.mli b/src/proto_alpha/lib_protocol/storage_functors.mli index 0b1dcbb8edf5..efae12c80110 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.mli +++ b/src/proto_alpha/lib_protocol/storage_functors.mli @@ -42,7 +42,7 @@ module Ghost : REGISTER a given subtree. Similar to a {i functional lens}. *) module Make_subcontext (_ : REGISTER) (C : Raw_context.T) (_ : NAME) : - Raw_context.T with type t = C.t + Raw_context.T with type t = C.t and type local_context = C.local_context module Make_single_data_storage (_ : REGISTER) @@ -86,6 +86,7 @@ module Make_indexed_carbonated_data_storage (V : VALUE) : Non_iterable_indexed_carbonated_data_storage_with_local_context with type t = C.t + and type local_context = C.local_context and type key = I.t and type value = V.t @@ -103,6 +104,7 @@ module Make_indexed_data_snapshotable_storage module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : Indexed_raw_context with type t = C.t + and type local_context = C.local_context and type key = I.t and type 'a ipath = 'a I.ipath diff --git a/src/proto_alpha/lib_protocol/storage_sigs.ml b/src/proto_alpha/lib_protocol/storage_sigs.ml index b3bdcba53ac6..7a8456617a99 100644 --- a/src/proto_alpha/lib_protocol/storage_sigs.ml +++ b/src/proto_alpha/lib_protocol/storage_sigs.ml @@ -229,15 +229,16 @@ end module type Non_iterable_indexed_carbonated_data_storage_with_local_context = sig include Non_iterable_indexed_carbonated_data_storage_with_values + type local_context + val with_local_context : add_back:bool -> context -> - (Raw_context.local_context -> - (Raw_context.local_context * 'a) tzresult Lwt.t) -> + (local_context -> (local_context * 'a) tzresult Lwt.t) -> (context * 'a) tzresult Lwt.t module Local : sig - type context = Raw_context.local_context + type context = local_context val mem : context -> key -> (context * bool) tzresult Lwt.t @@ -516,5 +517,6 @@ module type Indexed_raw_context = sig and type key = key and type value = V.t - module Raw_context : Raw_context.T with type t = t ipath + module Raw_context : + Raw_context.T with type t = t ipath and type local_context = local_context end -- GitLab From 4ce1a070203479fa045fd586ff66dee452f0fa01 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Tue, 13 Sep 2022 16:07:20 +0900 Subject: [PATCH 18/20] Protocol Storage : apply review comments: - renamed https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_1095735050 - added a comment https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_1095736132 - renamed Local_context -> Local https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_1095736136 - provide local api https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_1095744752 - provide local api for ather modules https://gitlab.com/tezos/tezos/-/merge_requests/3685#note_1095756350 --- src/proto_alpha/lib_protocol/raw_context.ml | 2 +- .../lib_protocol/raw_context_intf.ml | 4 +- src/proto_alpha/lib_protocol/storage.ml | 8 +- src/proto_alpha/lib_protocol/storage.mli | 32 ++++---- .../lib_protocol/storage_functors.ml | 79 +++++++++---------- .../lib_protocol/storage_functors.mli | 2 +- src/proto_alpha/lib_protocol/storage_sigs.ml | 5 +- 7 files changed, 63 insertions(+), 69 deletions(-) diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 28ccf79af711..587b1b9ef1e4 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1583,7 +1583,7 @@ let with_local_context ~add_back ctxt key f = update_unlimited_operation_gas ctxt local_ctxt.unlimited_operation_gas |> fun ctxt -> ok (ctxt, res) -module Local_context = struct +module Local = struct type t = local_context let consume_gas local cost = diff --git a/src/proto_alpha/lib_protocol/raw_context_intf.ml b/src/proto_alpha/lib_protocol/raw_context_intf.ml index ea9b413c6b6f..3521bcf2dae7 100644 --- a/src/proto_alpha/lib_protocol/raw_context_intf.ml +++ b/src/proto_alpha/lib_protocol/raw_context_intf.ml @@ -577,8 +577,8 @@ module type T = sig (local_context -> (local_context * 'a) tzresult Lwt.t) -> (t * 'a) tzresult Lwt.t - module Local_context : sig - (** [Local_context] provides functions for local access from a specific + module Local : sig + (** [Local] provides functions for local access from a specific directory. *) include VIEW diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 0141fd76bf0c..11296b5e42ae 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -391,7 +391,7 @@ end module Global_constants = struct module Map : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type t := Raw_context.t and type key = Script_expr_hash.t and type value = Script_repr.expr = @@ -552,7 +552,7 @@ module Big_map = struct include I.Local let consume_deserialize_gas local_ctxt value = - Raw_context.Local_context.consume_gas + Raw_context.Local.consume_gas local_ctxt (Script_repr.deserialized_cost value) @@ -638,7 +638,7 @@ module Sapling = struct (Sapling_repr.Memo_size) module Commitments : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type t := Raw_context.t * id and type key = int64 and type value = Sapling.Hash.t = @@ -686,7 +686,7 @@ module Sapling = struct >|= fun (ctx, _id) -> ctx module Ciphertexts : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type t := Raw_context.t * id and type key = int64 and type value = Sapling.Ciphertext.t = diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 64469afb3855..569a190bc1c1 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -102,7 +102,7 @@ module Contract : sig - [missed_levels] represents the number of missed levels (for endorsing). *) module Missed_endorsements : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = missed_endorsements_info and type t := Raw_context.t @@ -117,7 +117,7 @@ module Contract : sig (** The delegate of a contract, if any. *) module Delegate : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = Signature.Public_key_hash.t and type t := Raw_context.t @@ -134,7 +134,7 @@ module Contract : sig have current_amount <= initial_amount and current_amount < initial_amount iff the delegate was slashed. *) module Frozen_deposits : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = deposits and type t := Raw_context.t @@ -142,7 +142,7 @@ module Contract : sig (** If there is a value, the frozen balance for the contract won't exceed it (starting in preserved_cycles + 1). *) module Frozen_deposits_limit : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = Tez_repr.t and type t := Raw_context.t @@ -153,7 +153,7 @@ module Contract : sig (** The last cycle where the delegate is considered active; that is, at the next cycle it will be considered inactive. *) module Delegate_last_cycle_before_deactivation : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = Cycle_repr.t and type t := Raw_context.t @@ -209,7 +209,7 @@ module Contract : sig (** Associates a contract with the total of all its frozen bonds. *) module Total_frozen_bonds : - Indexed_data_storage + Indexed_data_storage_with_local_context with type key = Contract_repr.t and type value = Tez_repr.t and type t := Raw_context.t @@ -244,7 +244,7 @@ module Big_map : sig module Contents : sig include - Non_iterable_indexed_carbonated_data_storage_with_local_context + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type key = Script_expr_hash.t and type value = Script_repr.expr and type t := key @@ -305,7 +305,7 @@ module Sapling : sig Single_data_storage with type t := Raw_context.t * id and type value = int module Commitments : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type t := Raw_context.t * id and type key = int64 and type value = Sapling.Hash.t @@ -313,7 +313,7 @@ module Sapling : sig val commitments_init : Raw_context.t -> id -> Raw_context.t Lwt.t module Ciphertexts : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type t := Raw_context.t * id and type key = int64 and type value = Sapling.Ciphertext.t @@ -585,7 +585,7 @@ end [Michelson_v1_primitives.H_constant]. *) module Global_constants : sig module Map : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type t := Raw_context.t and type key = Script_expr_hash.t and type value = Script_repr.expr @@ -601,7 +601,7 @@ end *) module Ticket_balance : sig module Table : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type t := Raw_context.t and type key = Ticket_hash_repr.t and type value = Z.t @@ -746,7 +746,7 @@ module Sc_rollup : sig and type t := Raw_context.t module Stakers : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type key = Signature.Public_key_hash.t and type value = Sc_rollup_commitment_repr.Hash.t and type t = Raw_context.t * Sc_rollup_repr.t @@ -800,13 +800,13 @@ module Sc_rollup : sig of steps with respect to the total number of commitments. *) module Commitment_stake_count : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type key = Sc_rollup_commitment_repr.Hash.t and type value = int32 and type t = Raw_context.t * Sc_rollup_repr.t module Commitment_added : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type key = Sc_rollup_commitment_repr.Hash.t and type value = Raw_level_repr.t and type t = Raw_context.t * Sc_rollup_repr.t @@ -827,7 +827,7 @@ module Sc_rollup : sig not duplicated. *) module Game_timeout : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type key = Sc_rollup_game_repr.Index.t and type value = Raw_level_repr.t and type t = Raw_context.t * Sc_rollup_repr.t @@ -838,7 +838,7 @@ module Sc_rollup : sig for searching for current game by staker. *) module Opponent : - Non_iterable_indexed_carbonated_data_storage + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type key = Signature.Public_key_hash.t and type value = Sc_rollup_repr.Staker.t and type t = Raw_context.t * Sc_rollup_repr.t diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 3d2e09c791c3..39c36ccb09e2 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -149,7 +149,7 @@ struct let with_local_context ~add_back ctxt k f = C.with_local_context ~add_back ctxt (to_key k) f - module Local_context = C.Local_context + module Local = C.Local end module Make_single_data_storage @@ -498,12 +498,12 @@ module Make_indexed_carbonated_data_storage_INTERNAL type context = local_context let consume_mem_gas local key = - C.Local_context.consume_gas + C.Local.consume_gas local (Storage_costs.read_access ~path_length:(List.length key) ~read_bytes:0) let existing_size local i = - C.Local_context.find local (len_key i) >|= function + C.Local.find local (len_key i) >|= function | None -> ok (0, false) | Some len -> decode_len_value (len_key i) len >|? fun len -> (len, true) @@ -517,59 +517,57 @@ module Make_indexed_carbonated_data_storage_INTERNAL ~path_length:(List.length len_key) ~read_bytes in - C.Local_context.consume_gas local cost ) + C.Local.consume_gas local cost ) let consume_serialize_write_gas set local i v = let bytes = to_bytes v in let len = Bytes.length bytes in - C.Local_context.consume_gas local (Gas_limit_repr.alloc_mbytes_cost len) + C.Local.consume_gas local (Gas_limit_repr.alloc_mbytes_cost len) >>?= fun local -> let cost = Storage_costs.write_access ~written_bytes:len in - C.Local_context.consume_gas local cost >>?= fun local -> + C.Local.consume_gas local cost >>?= fun local -> set local (len_key i) (encode_len_value bytes) >|=? fun local -> (local, bytes) let consume_remove_gas del local i = - C.Local_context.consume_gas - local - (Storage_costs.write_access ~written_bytes:0) + C.Local.consume_gas local (Storage_costs.write_access ~written_bytes:0) >>?= fun local -> del local (len_key i) let mem local i = let key = data_key i in consume_mem_gas local key >>?= fun local -> - C.Local_context.mem local key >|= fun exists -> ok (local, exists) + C.Local.mem local key >|= fun exists -> ok (local, exists) let get local i = - consume_read_gas C.Local_context.get local i >>=? fun local -> - C.Local_context.get local (data_key i) >>=? fun b -> - let key () = C.Local_context.absolute_key local (data_key i) in + consume_read_gas C.Local.get local i >>=? fun local -> + C.Local.get local (data_key i) >>=? fun b -> + let key () = C.Local.absolute_key local (data_key i) in Lwt.return (of_bytes ~key b >|? fun v -> (local, v)) let find local i = let key = data_key i in consume_mem_gas local key >>?= fun local -> - C.Local_context.mem local key >>= fun exists -> + C.Local.mem local key >>= fun exists -> if exists then get local i >|=? fun (local, v) -> (local, Some v) else return (local, None) let update local i v = existing_size local i >>=? fun (prev_size, _) -> - consume_serialize_write_gas C.Local_context.update local i v + consume_serialize_write_gas C.Local.update local i v >>=? fun (local, bytes) -> - C.Local_context.update local (data_key i) bytes >|=? fun local -> + C.Local.update local (data_key i) bytes >|=? fun local -> let size_diff = Bytes.length bytes - prev_size in (local, size_diff) let init local i v = - consume_serialize_write_gas C.Local_context.init local i v + consume_serialize_write_gas C.Local.init local i v >>=? fun (local, bytes) -> - C.Local_context.init local (data_key i) bytes >|=? fun local -> + C.Local.init local (data_key i) bytes >|=? fun local -> let size = Bytes.length bytes in (local, size) let add local i v = - let add local i v = C.Local_context.add local i v >|= ok in + let add local i v = C.Local.add local i v >|= ok in existing_size local i >>=? fun (prev_size, existed) -> consume_serialize_write_gas add local i v >>=? fun (local, bytes) -> add local (data_key i) bytes >|=? fun local -> @@ -577,16 +575,15 @@ module Make_indexed_carbonated_data_storage_INTERNAL (local, size_diff, existed) let remove local i = - let remove local i = C.Local_context.remove local i >|= ok in + let remove local i = C.Local.remove local i >|= ok in existing_size local i >>=? fun (prev_size, existed) -> consume_remove_gas remove local i >>=? fun local -> remove local (data_key i) >|=? fun local -> (local, prev_size, existed) let remove_existing local i = existing_size local i >>=? fun (prev_size, _) -> - consume_remove_gas C.Local_context.remove_existing local i - >>=? fun local -> - C.Local_context.remove_existing local (data_key i) >|=? fun local -> + consume_remove_gas C.Local.remove_existing local i >>=? fun local -> + C.Local.remove_existing local (data_key i) >|=? fun local -> (local, prev_size) let add_or_remove local i v = @@ -675,7 +672,7 @@ module Make_indexed_carbonated_data_storage : functor (I : INDEX) (V : VALUE) -> - Non_iterable_indexed_carbonated_data_storage_with_local_context + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type t = C.t and type local_context = C.local_context and type key = I.t @@ -838,6 +835,8 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : and type local_context = C.local_context = struct type t = C.t I.ipath + (* Not [C.local_context I.ipath]. For faster local context access, + [local_context] must be the direct pointer to the tree of the index *) type local_context = C.local_context let to_key i k = I.to_path i k @@ -969,7 +968,7 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : C.with_local_context ~add_back t (to_key i k) f >|=? fun (t, res) -> (pack t i, res) - module Local_context = C.Local_context + module Local = C.Local end let with_local_context ~add_back s i f = @@ -1125,40 +1124,34 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : V.encoding module Local = struct - type context = Raw_context.Local_context.t + type context = Raw_context.Local.t - let mem local = Raw_context.Local_context.mem local N.name + let mem local = Raw_context.Local.mem local N.name let get local = - Raw_context.Local_context.get local N.name >|= fun r -> - let key () = Raw_context.Local_context.absolute_key local N.name in + Raw_context.Local.get local N.name >|= fun r -> + let key () = Raw_context.Local.absolute_key local N.name in r >>? of_bytes ~key let find local = - Raw_context.Local_context.find local N.name >|= function + Raw_context.Local.find local N.name >|= function | None -> Result.return_none | Some b -> - let key () = Raw_context.Local_context.absolute_key local N.name in + let key () = Raw_context.Local.absolute_key local N.name in of_bytes ~key b >|? fun v -> Some v - let init local v = - Raw_context.Local_context.init local N.name (to_bytes v) + let init local v = Raw_context.Local.init local N.name (to_bytes v) - let update local v = - Raw_context.Local_context.update local N.name (to_bytes v) + let update local v = Raw_context.Local.update local N.name (to_bytes v) - let add local v = Raw_context.Local_context.add local N.name (to_bytes v) + let add local v = Raw_context.Local.add local N.name (to_bytes v) let add_or_remove local vo = - Raw_context.Local_context.add_or_remove - local - N.name - (Option.map to_bytes vo) + Raw_context.Local.add_or_remove local N.name (Option.map to_bytes vo) - let remove_existing local = - Raw_context.Local_context.remove_existing local N.name + let remove_existing local = Raw_context.Local.remove_existing local N.name - let remove local = Raw_context.Local_context.remove local N.name + let remove local = Raw_context.Local.remove local N.name end end diff --git a/src/proto_alpha/lib_protocol/storage_functors.mli b/src/proto_alpha/lib_protocol/storage_functors.mli index efae12c80110..c6ed5087bfe3 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.mli +++ b/src/proto_alpha/lib_protocol/storage_functors.mli @@ -84,7 +84,7 @@ module Make_indexed_carbonated_data_storage (C : Raw_context.T) (I : INDEX) (V : VALUE) : - Non_iterable_indexed_carbonated_data_storage_with_local_context + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context with type t = C.t and type local_context = C.local_context and type key = I.t diff --git a/src/proto_alpha/lib_protocol/storage_sigs.ml b/src/proto_alpha/lib_protocol/storage_sigs.ml index 7a8456617a99..19b54a2841c2 100644 --- a/src/proto_alpha/lib_protocol/storage_sigs.ml +++ b/src/proto_alpha/lib_protocol/storage_sigs.ml @@ -226,7 +226,7 @@ module type Non_iterable_indexed_carbonated_data_storage_with_values = sig (Raw_context.t * (key * value) list) tzresult Lwt.t end -module type Non_iterable_indexed_carbonated_data_storage_with_local_context = sig +module type Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context = sig include Non_iterable_indexed_carbonated_data_storage_with_values type local_context @@ -262,7 +262,8 @@ module type Non_iterable_indexed_carbonated_data_storage_with_local_context = si end module type Non_iterable_indexed_carbonated_data_storage_INTERNAL = sig - include Non_iterable_indexed_carbonated_data_storage_with_local_context + include + Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context val fold_keys_unaccounted : context -> -- GitLab From 3467c9b98a2386be1f7fd45d13b96e5e445f1427 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Mon, 3 Oct 2022 11:09:15 +0900 Subject: [PATCH 19/20] Protocol Storage: The module structure has been reorganized and simplified --- .../lib_protocol/contract_storage.ml | 9 +- src/proto_alpha/lib_protocol/raw_context.ml | 6 + .../lib_protocol/raw_context_intf.ml | 6 +- src/proto_alpha/lib_protocol/storage.ml | 101 ++++++++- src/proto_alpha/lib_protocol/storage.mli | 57 +++-- .../lib_protocol/storage_functors.ml | 205 ++++++++++++++++-- .../lib_protocol/storage_functors.mli | 9 +- src/proto_alpha/lib_protocol/storage_sigs.ml | 117 +++++----- 8 files changed, 390 insertions(+), 120 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 05b6cdba17d1..4fd545b2068e 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -446,11 +446,12 @@ let delete c contract = c contract (fun local -> - Storage.Contract.Spendable_balance.Local.remove_existing local + Storage.Contract.Spendable_balance.Local.remove_existing local () >>=? fun local -> - Storage.Contract.Manager.Local.remove_existing local >>=? fun local -> - Storage.Contract.Counter.Local.remove_existing local >|=? fun local -> - (local, ())) + Storage.Contract.Manager.Local.remove_existing local () + >>=? fun local -> + Storage.Contract.Counter.Local.remove_existing local () + >|=? fun local -> (local, ())) >|=? fun (c, ()) -> c let allocated c contract = Storage.Contract.Spendable_balance.mem c contract diff --git a/src/proto_alpha/lib_protocol/raw_context.ml b/src/proto_alpha/lib_protocol/raw_context.ml index 587b1b9ef1e4..960075715f1b 100644 --- a/src/proto_alpha/lib_protocol/raw_context.ml +++ b/src/proto_alpha/lib_protocol/raw_context.ml @@ -1586,6 +1586,12 @@ let with_local_context ~add_back ctxt key f = module Local = struct type t = local_context + type context = t + + type nonrec key = key + + type nonrec value = value + let consume_gas local cost = match Gas_limit_repr.raw_consume local.remaining_operation_gas cost with | Some gas_counter -> Ok {local with remaining_operation_gas = gas_counter} diff --git a/src/proto_alpha/lib_protocol/raw_context_intf.ml b/src/proto_alpha/lib_protocol/raw_context_intf.ml index 3521bcf2dae7..9d838cd12d71 100644 --- a/src/proto_alpha/lib_protocol/raw_context_intf.ml +++ b/src/proto_alpha/lib_protocol/raw_context_intf.ml @@ -584,8 +584,10 @@ module type T = sig VIEW with type t = local_context and type tree := tree - and type key := key - and type value := value + and type key = key + and type value = value + + type context = t (** Internally used in {!Storage_functors} to consume gas from within a view. May raise {!Block_quota_exceeded} or diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 11296b5e42ae..1aa843130b39 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -256,7 +256,9 @@ module Contract = struct Storage_sigs.Non_iterable_indexed_carbonated_data_storage with type key = Contract_repr.t and type value = Script_repr.lazy_expr - and type t := Raw_context.t = struct + and type t := Raw_context.t + and type local_context = Counter.local_context + and type Local.key = unit = struct module I = Indexed_context.Make_carbonated_map (N) @@ -318,6 +320,12 @@ module Contract = struct I.add ctxt contract value let keys_unaccounted = I.keys_unaccounted + + type local_context = I.local_context + + let with_local_context = I.with_local_context + + module Local = I.Local end module Code = Make_carbonated_map_expr (struct @@ -391,7 +399,7 @@ end module Global_constants = struct module Map : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type t := Raw_context.t and type key = Script_expr_hash.t and type value = Script_repr.expr = @@ -638,7 +646,7 @@ module Sapling = struct (Sapling_repr.Memo_size) module Commitments : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type t := Raw_context.t * id and type key = int64 and type value = Sapling.Hash.t = @@ -686,7 +694,7 @@ module Sapling = struct >|= fun (ctx, _id) -> ctx module Ciphertexts : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type t := Raw_context.t * id and type key = int64 and type value = Sapling.Ciphertext.t = @@ -1271,11 +1279,14 @@ module Seed = struct Non_iterable_indexed_data_storage with type key := Level_repr.t and type value := nonce_status - and type t := Raw_context.t = struct + and type t := Raw_context.t + and type Local.key = Level_repr.t = struct open Level_repr type context = Raw_context.t + type local_context = Cycle.Nonce.Local.t + let mem ctxt (l : Level_repr.t) = Cycle.Nonce.mem (ctxt, l.cycle) l.level let get ctxt (l : Level_repr.t) = Cycle.Nonce.get (ctxt, l.cycle) l.level @@ -1299,6 +1310,34 @@ module Seed = struct let remove ctxt (l : Level_repr.t) = Cycle.Nonce.remove (ctxt, l.cycle) l.level + + module Local = struct + type t = local_context + + type context = t + + type key = Level_repr.t + + let mem c (l : Level_repr.t) = Cycle.Nonce.Local.mem c l.level + + let get c (l : Level_repr.t) = Cycle.Nonce.Local.get c l.level + + let find c (l : Level_repr.t) = Cycle.Nonce.Local.find c l.level + + let update c (l : Level_repr.t) v = Cycle.Nonce.Local.update c l.level v + + let init c (l : Level_repr.t) v = Cycle.Nonce.Local.init c l.level v + + let add c (l : Level_repr.t) v = Cycle.Nonce.Local.add c l.level v + + let add_or_remove c (l : Level_repr.t) v = + Cycle.Nonce.Local.add_or_remove c l.level v + + let remove_existing c (l : Level_repr.t) = + Cycle.Nonce.Local.remove_existing c l.level + + let remove c (l : Level_repr.t) = Cycle.Nonce.Local.remove c l.level + end end module VDF_setup = @@ -1600,6 +1639,37 @@ module Sc_rollup = struct key -> value option -> (Raw_context.t * int * bool) tzresult Lwt.t + + module Local : sig + type t + + type context + + type key + + val mem : context -> key -> (context * bool) tzresult Lwt.t + + val remove : context -> key -> (context * int * bool) tzresult Lwt.t + + val remove_existing : context -> key -> (context * int) tzresult Lwt.t + + val get : context -> key -> (context * value) tzresult Lwt.t + + val find : context -> key -> (context * value option) tzresult Lwt.t + + val update : context -> key -> value -> (context * int) tzresult Lwt.t + + val init : context -> key -> value -> (context * int) tzresult Lwt.t + + val add : + context -> key -> value -> (context * int * bool) tzresult Lwt.t + + val add_or_remove : + context -> + key -> + value option -> + (context * int * bool) tzresult Lwt.t + end end) = struct include Data_storage @@ -1625,6 +1695,27 @@ module Sc_rollup = struct let add_or_remove ctxt key value = add_or_remove ctxt key (Option.map Versioned_value.to_versioned value) + + module Local = struct + include Data_storage.Local + + let get c key = + get c key >|=? fun (c, versioned) -> + (c, Versioned_value.of_versioned versioned) + + let find c key = + find c key >|=? fun (c, versioned) -> + (c, Option.map Versioned_value.of_versioned versioned) + + let update c key value = update c key (Versioned_value.to_versioned value) + + let init c key value = init c key (Versioned_value.to_versioned value) + + let add c key value = add c key (Versioned_value.to_versioned value) + + let add_or_remove c key value = + add_or_remove c key (Option.map Versioned_value.to_versioned value) + end end module PVM_kind = diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 569a190bc1c1..7d9bc026ff64 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -83,11 +83,12 @@ module Contract : sig tez) are only allowed for originated contracts, not for implicit ones. *) module Spendable_balance : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = Tez_repr.t and type t := Raw_context.t - and type local_context := local_context + and type local_context = local_context + and type Local.key := unit (** If the value is not set, the delegate didn't miss any endorsing opportunity. If it is set, this value is a record of type @@ -102,25 +103,28 @@ module Contract : sig - [missed_levels] represents the number of missed levels (for endorsing). *) module Missed_endorsements : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = missed_endorsements_info and type t := Raw_context.t + and type Local.key := unit (** The manager of a contract *) module Manager : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = Manager_repr.t and type t := Raw_context.t and type local_context := local_context + and type Local.key := unit (** The delegate of a contract, if any. *) module Delegate : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = Signature.Public_key_hash.t and type t := Raw_context.t + and type Local.key := unit (** All contracts (implicit and originated) that are delegated, if any *) module Delegated : @@ -134,18 +138,20 @@ module Contract : sig have current_amount <= initial_amount and current_amount < initial_amount iff the delegate was slashed. *) module Frozen_deposits : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = deposits and type t := Raw_context.t + and type Local.key := unit (** If there is a value, the frozen balance for the contract won't exceed it (starting in preserved_cycles + 1). *) module Frozen_deposits_limit : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = Tez_repr.t and type t := Raw_context.t + and type Local.key := unit module Inactive_delegate : Data_set_storage with type elt = Contract_repr.t and type t = Raw_context.t @@ -153,17 +159,19 @@ module Contract : sig (** The last cycle where the delegate is considered active; that is, at the next cycle it will be considered inactive. *) module Delegate_last_cycle_before_deactivation : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = Cycle_repr.t and type t := Raw_context.t + and type Local.key := unit module Counter : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = Z.t and type t := Raw_context.t and type local_context := local_context + and type Local.key := unit module Code : Non_iterable_indexed_carbonated_data_storage @@ -180,17 +188,19 @@ module Contract : sig (** Current storage space in bytes. Includes code, global storage and big map elements. *) module Used_storage_space : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = Z.t and type t := Raw_context.t + and type Local.key := unit (** Maximal space available without needing to burn new fees. *) module Paid_storage_space : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = Z.t and type t := Raw_context.t + and type Local.key := unit (** Associates a contract and a bond_id with a bond, i.e. an amount of tez that is frozen. *) @@ -209,10 +219,11 @@ module Contract : sig (** Associates a contract with the total of all its frozen bonds. *) module Total_frozen_bonds : - Indexed_data_storage_with_local_context + Indexed_data_storage with type key = Contract_repr.t and type value = Tez_repr.t and type t := Raw_context.t + and type Local.key := unit end module Big_map : sig @@ -244,10 +255,11 @@ module Big_map : sig module Contents : sig include - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type key = Script_expr_hash.t and type value = Script_repr.expr and type t := key + and type Local.key = Script_expr_hash.t (** HACK *) val list_values : @@ -305,7 +317,7 @@ module Sapling : sig Single_data_storage with type t := Raw_context.t * id and type value = int module Commitments : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type t := Raw_context.t * id and type key = int64 and type value = Sapling.Hash.t @@ -313,7 +325,7 @@ module Sapling : sig val commitments_init : Raw_context.t -> id -> Raw_context.t Lwt.t module Ciphertexts : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type t := Raw_context.t * id and type key = int64 and type value = Sapling.Ciphertext.t @@ -585,7 +597,7 @@ end [Michelson_v1_primitives.H_constant]. *) module Global_constants : sig module Map : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type t := Raw_context.t and type key = Script_expr_hash.t and type value = Script_repr.expr @@ -601,7 +613,7 @@ end *) module Ticket_balance : sig module Table : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type t := Raw_context.t and type key = Ticket_hash_repr.t and type value = Z.t @@ -738,6 +750,7 @@ module Sc_rollup : sig with type key = Sc_rollup_repr.t and type value = Sc_rollup_inbox_repr.t and type t := Raw_context.t + and type Local.key = unit module Last_cemented_commitment : Non_iterable_indexed_carbonated_data_storage @@ -746,7 +759,7 @@ module Sc_rollup : sig and type t := Raw_context.t module Stakers : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type key = Signature.Public_key_hash.t and type value = Sc_rollup_commitment_repr.Hash.t and type t = Raw_context.t * Sc_rollup_repr.t @@ -800,13 +813,13 @@ module Sc_rollup : sig of steps with respect to the total number of commitments. *) module Commitment_stake_count : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type key = Sc_rollup_commitment_repr.Hash.t and type value = int32 and type t = Raw_context.t * Sc_rollup_repr.t module Commitment_added : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type key = Sc_rollup_commitment_repr.Hash.t and type value = Raw_level_repr.t and type t = Raw_context.t * Sc_rollup_repr.t @@ -827,7 +840,7 @@ module Sc_rollup : sig not duplicated. *) module Game_timeout : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type key = Sc_rollup_game_repr.Index.t and type value = Raw_level_repr.t and type t = Raw_context.t * Sc_rollup_repr.t @@ -838,7 +851,7 @@ module Sc_rollup : sig for searching for current game by staker. *) module Opponent : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type key = Signature.Public_key_hash.t and type value = Sc_rollup_repr.Staker.t and type t = Raw_context.t * Sc_rollup_repr.t diff --git a/src/proto_alpha/lib_protocol/storage_functors.ml b/src/proto_alpha/lib_protocol/storage_functors.ml index 39c36ccb09e2..fb9bea6b15cd 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.ml +++ b/src/proto_alpha/lib_protocol/storage_functors.ml @@ -277,12 +277,17 @@ module Make_data_set_storage (C : Raw_context.T) (I : INDEX) : end module Make_indexed_data_storage (C : Raw_context.T) (I : INDEX) (V : VALUE) : - Indexed_data_storage with type t = C.t and type key = I.t and type value = V.t = -struct + Indexed_data_storage + with type t = C.t + and type key = I.t + and type value = V.t + and type Local.key = I.t = struct type t = C.t type context = t + type local_context = C.local_context + type key = I.t type value = V.t @@ -345,6 +350,41 @@ struct let keys s = fold_keys s ~order:`Sorted ~init:[] ~f:(fun p acc -> Lwt.return (p :: acc)) + module Local = struct + type t = local_context + + type context = t + + type nonrec key = I.t + + let mem c i = C.Local.mem c (I.to_path i []) + + let get c i = + C.Local.get c (I.to_path i []) >>=? fun b -> + let key () = C.Local.absolute_key c (I.to_path i []) in + Lwt.return (of_bytes ~key b) + + let find c i = + C.Local.find c (I.to_path i []) >|= function + | None -> Result.return_none + | Some b -> + let key () = C.Local.absolute_key c (I.to_path i []) in + of_bytes ~key b >|? fun v -> Some v + + let update c i v = C.Local.update c (I.to_path i []) (to_bytes v) + + let init c i v = C.Local.init c (I.to_path i []) (to_bytes v) + + let add c i v = C.Local.add c (I.to_path i []) (to_bytes v) + + let add_or_remove c i v = + C.Local.add_or_remove c (I.to_path i []) (Option.map to_bytes v) + + let remove c i = C.Local.remove c (I.to_path i []) + + let remove_existing c i = C.Local.remove_existing c (I.to_path i []) + end + let () = let open Storage_description in let unpack = unpack I.args in @@ -369,7 +409,8 @@ module Make_indexed_carbonated_data_storage_INTERNAL with type t = C.t and type local_context = C.local_context and type key = I.t - and type value = V.t = struct + and type value = V.t + and type Local.key = I.t = struct type t = C.t type context = t @@ -495,8 +536,12 @@ module Make_indexed_carbonated_data_storage_INTERNAL return (s, x) module Local = struct + type t = local_context + type context = local_context + type nonrec key = key + let consume_mem_gas local key = C.Local.consume_gas local @@ -672,11 +717,12 @@ module Make_indexed_carbonated_data_storage : functor (I : INDEX) (V : VALUE) -> - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type t = C.t and type local_context = C.local_context and type key = I.t - and type value = V.t = + and type value = V.t + and type Local.key = I.t = Make_indexed_carbonated_data_storage_INTERNAL module Make_carbonated_data_set_storage (C : Raw_context.T) (I : INDEX) : @@ -1028,11 +1074,12 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : end module Make_map (N : NAME) (V : VALUE) : - Indexed_data_storage_with_local_context + Indexed_data_storage with type t = t and type key = key and type value = V.t - and type local_context = local_context = struct + and type local_context = local_context + and type Local.key = unit = struct type t = C.t type context = t @@ -1126,32 +1173,37 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : module Local = struct type context = Raw_context.Local.t - let mem local = Raw_context.Local.mem local N.name + type t = context - let get local = + type key = unit + + let mem local () = Raw_context.Local.mem local N.name + + let get local () = Raw_context.Local.get local N.name >|= fun r -> let key () = Raw_context.Local.absolute_key local N.name in r >>? of_bytes ~key - let find local = + let find local () = Raw_context.Local.find local N.name >|= function | None -> Result.return_none | Some b -> let key () = Raw_context.Local.absolute_key local N.name in of_bytes ~key b >|? fun v -> Some v - let init local v = Raw_context.Local.init local N.name (to_bytes v) + let init local () v = Raw_context.Local.init local N.name (to_bytes v) - let update local v = Raw_context.Local.update local N.name (to_bytes v) + let update local () v = Raw_context.Local.update local N.name (to_bytes v) - let add local v = Raw_context.Local.add local N.name (to_bytes v) + let add local () v = Raw_context.Local.add local N.name (to_bytes v) - let add_or_remove local vo = + let add_or_remove local () vo = Raw_context.Local.add_or_remove local N.name (Option.map to_bytes vo) - let remove_existing local = Raw_context.Local.remove_existing local N.name + let remove_existing local () = + Raw_context.Local.remove_existing local N.name - let remove local = Raw_context.Local.remove local N.name + let remove local () = Raw_context.Local.remove local N.name end end @@ -1159,7 +1211,9 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : Non_iterable_indexed_carbonated_data_storage with type t = t and type key = key - and type value = V.t = struct + and type value = V.t + and type local_context = local_context + and type Local.key = unit = struct type t = C.t type context = t @@ -1168,6 +1222,8 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : type value = V.t + type nonrec local_context = local_context + include Make_encoder (V) let len_name = len_name :: N.name @@ -1280,6 +1336,117 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX) : find c k >|=? fun (_, v) -> v) (register_named_subcontext Raw_context.description N.name) V.encoding + + let with_local_context ~add_back s f = + let consume_find_tree_gas c = + let path_length = List.length @@ C.absolute_key c [] in + C.consume_gas c (Storage_costs.read_access ~path_length ~read_bytes:0) + in + let consume_add_tree_gas c = + C.consume_gas c (Storage_costs.write_access ~written_bytes:0) + in + consume_find_tree_gas s >>?= fun s -> + C.with_local_context ~add_back s [] f >>=? fun (s, x) -> + (if not add_back then consume_add_tree_gas s else ok s) >>?= fun s -> + return (s, x) + + module Local = struct + type context = local_context + + type t = context + + type key = unit + + let consume_mem_gas local key = + let path_length = List.length key in + Raw_context.Local.consume_gas + local + (Storage_costs.read_access ~path_length ~read_bytes:0) + + let existing_size local = + Raw_context.Local.find local len_name >|= function + | None -> ok (0, false) + | Some len -> decode_len_value len_name len >|? fun len -> (len, true) + + let consume_read_gas get local = + get local len_name >>=? fun len -> + Lwt.return + ( decode_len_value len_name len >>? fun read_bytes -> + let path_length = List.length len_name in + let cost = Storage_costs.read_access ~path_length ~read_bytes in + C.Local.consume_gas local cost ) + + let consume_serialize_write_gas set local v = + let bytes = to_bytes v in + let len = Bytes.length bytes in + C.Local.consume_gas local (Gas_limit_repr.alloc_mbytes_cost len) + >>?= fun local -> + let cost = Storage_costs.write_access ~written_bytes:len in + C.Local.consume_gas local cost >>?= fun local -> + set local len_name (encode_len_value bytes) >|=? fun local -> + (local, bytes) + + let consume_remove_gas del local = + let cost = Storage_costs.write_access ~written_bytes:0 in + Raw_context.Local.consume_gas local cost >>?= fun local -> + del local len_name + + let mem local () = + consume_mem_gas local data_name >>?= fun local -> + Raw_context.Local.mem local data_name >|= fun exists -> + ok (local, exists) + + let get local () = + consume_read_gas Raw_context.Local.get local >>=? fun local -> + Raw_context.Local.get local data_name >>=? fun b -> + let key () = C.Local.absolute_key local data_name in + Lwt.return (of_bytes ~key b >|? fun v -> (local, v)) + + let find local () = + consume_mem_gas local data_name >>?= fun local -> + Raw_context.Local.mem local data_name >>= fun exists -> + if exists then get local () >|=? fun (local, v) -> (local, Some v) + else return (local, None) + + let update local () v = + existing_size local >>=? fun (prev_size, _) -> + consume_serialize_write_gas Raw_context.Local.update local v + >>=? fun (local, bytes) -> + Raw_context.Local.update local data_name bytes >|=? fun local -> + let size_diff = Bytes.length bytes - prev_size in + (local, size_diff) + + let init local () v = + consume_serialize_write_gas Raw_context.Local.init local v + >>=? fun (local, bytes) -> + Raw_context.Local.init local data_name bytes >|=? fun local -> + let size = Bytes.length bytes in + (local, size) + + let add local () v = + let add local i v = Raw_context.Local.add local i v >|= ok in + existing_size local >>=? fun (prev_size, existed) -> + consume_serialize_write_gas add local v >>=? fun (local, bytes) -> + add local data_name bytes >|=? fun local -> + let size_diff = Bytes.length bytes - prev_size in + (local, size_diff, existed) + + let remove c () = + let remove c k = Raw_context.Local.remove c k >|= ok in + existing_size c >>=? fun (prev_size, existed) -> + consume_remove_gas remove c >>=? fun c -> + remove c data_name >|=? fun c -> (c, prev_size, existed) + + let remove_existing local () = + existing_size local >>=? fun (prev_size, _) -> + consume_remove_gas Raw_context.Local.remove_existing local + >>=? fun local -> + C.Local.remove_existing local data_name >|=? fun local -> + (local, prev_size) + + let add_or_remove local () v = + match v with None -> remove local () | Some v -> add local () v + end end end @@ -1304,6 +1471,8 @@ module Wrap_indexed_data_storage type context = C.t + type local_context = C.local_context + type key = K.t type value = C.value @@ -1342,4 +1511,6 @@ module Wrap_indexed_data_storage let keys s = fold_keys s ~order:`Sorted ~init:[] ~f:(fun p acc -> Lwt.return (p :: acc)) + + module Local = C.Local end diff --git a/src/proto_alpha/lib_protocol/storage_functors.mli b/src/proto_alpha/lib_protocol/storage_functors.mli index c6ed5087bfe3..8659c22f0645 100644 --- a/src/proto_alpha/lib_protocol/storage_functors.mli +++ b/src/proto_alpha/lib_protocol/storage_functors.mli @@ -77,18 +77,23 @@ module Make_carbonated_data_set_storage (C : Raw_context.T) (I : INDEX) : (** This functor creates storage for types with a notion of an index. *) module Make_indexed_data_storage (C : Raw_context.T) (I : INDEX) (V : VALUE) : - Indexed_data_storage with type t = C.t and type key = I.t and type value = V.t + Indexed_data_storage + with type t = C.t + and type key = I.t + and type value = V.t + and type Local.key = I.t (** Like [Make_indexed_data_storage], adding tracking of storage cost. *) module Make_indexed_carbonated_data_storage (C : Raw_context.T) (I : INDEX) (V : VALUE) : - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + Non_iterable_indexed_carbonated_data_storage_with_values with type t = C.t and type local_context = C.local_context and type key = I.t and type value = V.t + and type Local.key = I.t module Make_indexed_data_snapshotable_storage (C : Raw_context.T) diff --git a/src/proto_alpha/lib_protocol/storage_sigs.ml b/src/proto_alpha/lib_protocol/storage_sigs.ml index 19b54a2841c2..37fce3873969 100644 --- a/src/proto_alpha/lib_protocol/storage_sigs.ml +++ b/src/proto_alpha/lib_protocol/storage_sigs.ml @@ -128,6 +128,34 @@ module type Non_iterable_indexed_data_storage = sig (** Removes a storage bucket and its contents ; does nothing if the bucket does not exists. *) val remove : context -> key -> Raw_context.t Lwt.t + + type local_context + + module Local : sig + type t = local_context + + type context = t + + type key + + val mem : context -> key -> bool Lwt.t + + val get : context -> key -> value tzresult Lwt.t + + val find : context -> key -> value option tzresult Lwt.t + + val update : context -> key -> value -> context tzresult Lwt.t + + val init : context -> key -> value -> context tzresult Lwt.t + + val add : context -> key -> value -> context Lwt.t + + val add_or_remove : context -> key -> value option -> context Lwt.t + + val remove_existing : context -> key -> context tzresult Lwt.t + + val remove : context -> key -> context Lwt.t + end end (** Variant of {!Non_iterable_indexed_data_storage} with gas accounting. *) @@ -213,21 +241,6 @@ module type Non_iterable_indexed_carbonated_data_storage = sig (** Returns the list of all storage bucket keys. Not carbonated (i.e. gas is not consumed); use with care. *) val keys_unaccounted : context -> key list Lwt.t -end - -module type Non_iterable_indexed_carbonated_data_storage_with_values = sig - include Non_iterable_indexed_carbonated_data_storage - - (* HACK *) - val list_values : - ?offset:int -> - ?length:int -> - t -> - (Raw_context.t * (key * value) list) tzresult Lwt.t -end - -module type Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context = sig - include Non_iterable_indexed_carbonated_data_storage_with_values type local_context @@ -238,7 +251,11 @@ module type Non_iterable_indexed_carbonated_data_storage_with_value_and_local_co (context * 'a) tzresult Lwt.t module Local : sig - type context = local_context + type t = local_context + + type context = t + + type key val mem : context -> key -> (context * bool) tzresult Lwt.t @@ -261,9 +278,19 @@ module type Non_iterable_indexed_carbonated_data_storage_with_value_and_local_co end end +module type Non_iterable_indexed_carbonated_data_storage_with_values = sig + include Non_iterable_indexed_carbonated_data_storage + + (* HACK *) + val list_values : + ?offset:int -> + ?length:int -> + t -> + (Raw_context.t * (key * value) list) tzresult Lwt.t +end + module type Non_iterable_indexed_carbonated_data_storage_INTERNAL = sig - include - Non_iterable_indexed_carbonated_data_storage_with_value_and_local_context + include Non_iterable_indexed_carbonated_data_storage_with_values val fold_keys_unaccounted : context -> @@ -305,55 +332,6 @@ module type Indexed_data_storage = sig 'a Lwt.t end -module type Indexed_data_storage_with_local_context = sig - include Indexed_data_storage - - type local_context - - module Local : sig - type context = local_context - - (** Tells if the data is already defined *) - val mem : context -> bool Lwt.t - - (** Retrieve the value from the storage bucket ; returns a - {!Storage_error} if the key is not set or if the deserialisation - fails *) - val get : context -> value tzresult Lwt.t - - (** Retrieves the value from the storage bucket ; returns [None] if - the data is not initialized, or {!Storage_helpers.Storage_error} - if the deserialisation fails *) - val find : context -> value option tzresult Lwt.t - - (** Allocates the storage bucket and initializes it ; returns a - {!Storage_error Existing_key} if the bucket exists *) - val init : context -> value -> context tzresult Lwt.t - - (** Updates the content of the bucket ; returns a {!Storage_Error - Missing_key} if the value does not exists *) - val update : context -> value -> context tzresult Lwt.t - - (** Allocates the data and initializes it with a value ; just - updates it if the bucket exists *) - val add : context -> value -> context Lwt.t - - (** When the value is [Some v], allocates the data and initializes - it with [v] ; just updates it if the bucket exists. When the - value is [None], delete the storage bucket when the value ; does - nothing if the bucket does not exists. *) - val add_or_remove : context -> value option -> context Lwt.t - - (** Delete the storage bucket ; returns a {!Storage_error - Missing_key} if the bucket does not exists *) - val remove_existing : context -> context tzresult Lwt.t - - (** Removes the storage bucket and its contents ; does nothing if - the bucket does not exists *) - val remove : context -> context Lwt.t - end -end - module type Indexed_data_snapshotable_storage = sig type snapshot @@ -506,17 +484,20 @@ module type Indexed_raw_context = sig Data_set_storage with type t = t and type elt = key module Make_map (_ : NAME) (V : VALUE) : - Indexed_data_storage_with_local_context + Indexed_data_storage with type t = t and type key = key and type value = V.t and type local_context = local_context + and type Local.key = unit module Make_carbonated_map (_ : NAME) (V : VALUE) : Non_iterable_indexed_carbonated_data_storage with type t = t and type key = key and type value = V.t + and type local_context = local_context + and type Local.key = unit module Raw_context : Raw_context.T with type t = t ipath and type local_context = local_context -- GitLab From 5cb2172651369c99e03619b84ba9e0ce1a51a8be Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Mon, 3 Oct 2022 12:00:29 +0900 Subject: [PATCH 20/20] Protocol Storage : reset python regression tests --- ...igination::test_big_map_origination_literal.out | 12 ++++++------ ...ddApproveTransferRemove::test_add_liquidity.out | 14 +++++++------- ...TestAddApproveTransferRemove::test_approval.out | 12 ++++++------ ...proveTransferRemove::test_approved_transfer.out | 12 ++++++------ ...ddApproveTransferRemove::test_call_approve1.out | 12 ++++++------ ...ddApproveTransferRemove::test_call_approve2.out | 12 ++++++------ ...ddApproveTransferRemove::test_call_approve3.out | 12 ++++++------ ...proveTransferRemove::test_call_mint_or_burn.out | 12 ++++++------ ...pproveTransferRemove::test_remove_liquidity.out | 14 +++++++------- ...idity_baking.TestTrades::test_add_liquidity.out | 14 +++++++------- ...t_liquidity_baking.TestTrades::test_buy_tok.out | 12 ++++++------ ...idity_baking.TestTrades::test_call_approve1.out | 12 ++++++------ ...idity_baking.TestTrades::test_call_approve2.out | 12 ++++++------ ...idity_baking.TestTrades::test_call_approve3.out | 12 ++++++------ ...y_baking.TestTrades::test_call_mint_or_burn.out | 12 ++++++------ ..._liquidity_baking.TestTrades::test_sell_tok.out | 12 ++++++------ ..._liquidity_baking.TestTrades::test_transfer.out | 12 ++++++------ 17 files changed, 105 insertions(+), 105 deletions(-) diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractBigMapOrigination::test_big_map_origination_literal.out b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractBigMapOrigination::test_big_map_origination_literal.out index 48012737a2ba..ad9b2582fcec 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractBigMapOrigination::test_big_map_origination_literal.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractBigMapOrigination::test_big_map_origination_literal.out @@ -1,7 +1,7 @@ tests_alpha/test_contract_onchain_opcodes.py::TestContractBigMapOrigination::test_big_map_origination_literal Node is bootstrapped. -Estimated gas: 1641.662 units (will add 100 for safety) +Estimated gas: 1861.662 units (will add 100 for safety) Estimated storage: 403 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000461 + Fee to the baker: ꜩ0.000483 Expected counter: [EXPECTED_COUNTER] - Gas limit: 1742 + Gas limit: 1962 Storage limit: 423 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000461 - payload fees(the block proposer) ....... +ꜩ0.000461 + [CONTRACT_HASH] ... -ꜩ0.000483 + payload fees(the block proposer) ....... +ꜩ0.000483 Origination: From: [CONTRACT_HASH] Credit: ꜩ1000 @@ -36,7 +36,7 @@ This sequence of operations was run: New map(4) of type (big_map int int) Set map(4)[0] to 0 Paid storage size diff: 146 bytes - Consumed gas: 1641.662 + Consumed gas: 1861.662 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0365 storage fees ........................... +ꜩ0.0365 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out index 781ca61eb5e0..50e3b32a73cd 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_add_liquidity.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_add_liquidity Node is bootstrapped. -Estimated gas: 8553.386 units (will add 100 for safety) +Estimated gas: 9433.386 units (will add 100 for safety) Estimated storage: 141 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.001221 + Fee to the baker: ꜩ0.001309 Expected counter: [EXPECTED_COUNTER] - Gas limit: 8654 + Gas limit: 9534 Storage limit: 161 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.001221 - payload fees(the block proposer) ....... +ꜩ0.001221 + [CONTRACT_HASH] ... -ꜩ0.001309 + payload fees(the block proposer) ....... +ꜩ0.001309 Transaction: Amount: ꜩ9001 From: [CONTRACT_HASH] @@ -58,7 +58,7 @@ This sequence of operations was run: Set map(0)[0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600] to 721 Storage size: 2263 bytes Paid storage size diff: 68 bytes - Consumed gas: 3065.552 + Consumed gas: 3505.552 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 @@ -75,7 +75,7 @@ This sequence of operations was run: Set map(2)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 72007 Storage size: 2048 bytes Paid storage size diff: 70 bytes - Consumed gas: 3213.097 + Consumed gas: 3653.097 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0175 storage fees ........................... +ꜩ0.0175 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approval.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approval.out index f7a5aa87445f..4a00d1c367b3 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approval.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approval.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_approval Node is bootstrapped. -Estimated gas: 1679.709 units (will add 100 for safety) +Estimated gas: 2119.709 units (will add 100 for safety) Estimated storage: 68 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000485 + Fee to the baker: ꜩ0.000529 Expected counter: [EXPECTED_COUNTER] - Gas limit: 1780 + Gas limit: 2220 Storage limit: 88 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000485 - payload fees(the block proposer) ....... +ꜩ0.000485 + [CONTRACT_HASH] ... -ꜩ0.000529 + payload fees(the block proposer) ....... +ꜩ0.000529 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -33,7 +33,7 @@ This sequence of operations was run: 0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c)] to 1000 Storage size: 2116 bytes Paid storage size diff: 68 bytes - Consumed gas: 1679.709 + Consumed gas: 2119.709 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approved_transfer.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approved_transfer.out index 9489d1e04057..272fd6c78dff 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approved_transfer.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_approved_transfer.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_approved_transfer Node is bootstrapped. -Estimated gas: 3044.096 units (will add 100 for safety) +Estimated gas: 3484.096 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000672 + Fee to the baker: ꜩ0.000716 Expected counter: [EXPECTED_COUNTER] - Gas limit: 3145 + Gas limit: 3585 Storage limit: 0 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000672 - payload fees(the block proposer) ....... +ꜩ0.000672 + [CONTRACT_HASH] ... -ꜩ0.000716 + payload fees(the block proposer) ....... +ꜩ0.000716 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -36,6 +36,6 @@ This sequence of operations was run: Set map(2)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 71007 Set map(2)[0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c] to 1000 Storage size: 2116 bytes - Consumed gas: 3044.096 + Consumed gas: 3484.096 Injected block at minimal timestamp diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve1.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve1.out index 67447b407567..9bd467dbb36c 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve1.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve1.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_call_approve1 Node is bootstrapped. -Estimated gas: 1679.785 units (will add 100 for safety) +Estimated gas: 2119.785 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000488 + Fee to the baker: ꜩ0.000532 Expected counter: [EXPECTED_COUNTER] - Gas limit: 1780 + Gas limit: 2220 Storage limit: 91 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000488 - payload fees(the block proposer) ....... +ꜩ0.000488 + [CONTRACT_HASH] ... -ꜩ0.000532 + payload fees(the block proposer) ....... +ꜩ0.000532 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2053 bytes Paid storage size diff: 71 bytes - Consumed gas: 1679.785 + Consumed gas: 2119.785 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve2.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve2.out index 6867eeba7a81..85d96ced7281 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve2.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve2.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_call_approve2 Node is bootstrapped. -Estimated gas: 1679.785 units (will add 100 for safety) +Estimated gas: 2119.785 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000488 + Fee to the baker: ꜩ0.000532 Expected counter: [EXPECTED_COUNTER] - Gas limit: 1780 + Gas limit: 2220 Storage limit: 91 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000488 - payload fees(the block proposer) ....... +ꜩ0.000488 + [CONTRACT_HASH] ... -ꜩ0.000532 + payload fees(the block proposer) ....... +ꜩ0.000532 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2124 bytes Paid storage size diff: 71 bytes - Consumed gas: 1679.785 + Consumed gas: 2119.785 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve3.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve3.out index 5b2d8a22ea12..cf0e7e37af7f 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve3.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_approve3.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_call_approve3 Node is bootstrapped. -Estimated gas: 1679.785 units (will add 100 for safety) +Estimated gas: 2119.785 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000488 + Fee to the baker: ꜩ0.000532 Expected counter: [EXPECTED_COUNTER] - Gas limit: 1780 + Gas limit: 2220 Storage limit: 91 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000488 - payload fees(the block proposer) ....... +ꜩ0.000488 + [CONTRACT_HASH] ... -ꜩ0.000532 + payload fees(the block proposer) ....... +ꜩ0.000532 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2195 bytes Paid storage size diff: 71 bytes - Consumed gas: 1679.785 + Consumed gas: 2119.785 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_mint_or_burn.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_mint_or_burn.out index f40670ce15c1..3f32e08d9e6d 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_mint_or_burn.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_call_mint_or_burn.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_call_mint_or_burn Node is bootstrapped. -Estimated gas: 3217.054 units (will add 100 for safety) +Estimated gas: 3657.054 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000644 + Fee to the baker: ꜩ0.000688 Expected counter: [EXPECTED_COUNTER] - Gas limit: 3318 + Gas limit: 3758 Storage limit: 91 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000644 - payload fees(the block proposer) ....... +ꜩ0.000644 + [CONTRACT_HASH] ... -ꜩ0.000688 + payload fees(the block proposer) ....... +ꜩ0.000688 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -32,7 +32,7 @@ This sequence of operations was run: Set map(0)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 100000000 Storage size: 1982 bytes Paid storage size diff: 71 bytes - Consumed gas: 3217.527 + Consumed gas: 3657.527 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out index 763556d3762b..d527dd742d8b 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestAddApproveTransferRemove::test_remove_liquidity.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestAddApproveTransferRemove::test_remove_liquidity Node is bootstrapped. -Estimated gas: 7517.418 units (will add 100 for safety) +Estimated gas: 8397.418 units (will add 100 for safety) Estimated storage: 67 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.001114 + Fee to the baker: ꜩ0.001202 Expected counter: [EXPECTED_COUNTER] - Gas limit: 7618 + Gas limit: 8498 Storage limit: 87 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.001114 - payload fees(the block proposer) ....... +ꜩ0.001114 + [CONTRACT_HASH] ... -ꜩ0.001202 + payload fees(the block proposer) ....... +ꜩ0.001202 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -47,7 +47,7 @@ This sequence of operations was run: Updated big_maps: Unset map(2)[0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c] Storage size: 2048 bytes - Consumed gas: 1873.230 + Consumed gas: 2313.230 Internal Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -63,7 +63,7 @@ This sequence of operations was run: Set map(0)[0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c] to 10 Storage size: 2330 bytes Paid storage size diff: 67 bytes - Consumed gas: 2367.837 + Consumed gas: 2807.837 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01675 storage fees ........................... +ꜩ0.01675 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out index f2f97a201b2e..fe4a28b599a2 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_add_liquidity.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_add_liquidity Node is bootstrapped. -Estimated gas: 8553.386 units (will add 100 for safety) +Estimated gas: 9433.386 units (will add 100 for safety) Estimated storage: 141 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.001221 + Fee to the baker: ꜩ0.001309 Expected counter: [EXPECTED_COUNTER] - Gas limit: 8654 + Gas limit: 9534 Storage limit: 161 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.001221 - payload fees(the block proposer) ....... +ꜩ0.001221 + [CONTRACT_HASH] ... -ꜩ0.001309 + payload fees(the block proposer) ....... +ꜩ0.001309 Transaction: Amount: ꜩ9001 From: [CONTRACT_HASH] @@ -58,7 +58,7 @@ This sequence of operations was run: Set map(0)[0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600] to 721 Storage size: 2263 bytes Paid storage size diff: 68 bytes - Consumed gas: 3065.552 + Consumed gas: 3505.552 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 @@ -75,7 +75,7 @@ This sequence of operations was run: Set map(2)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 72007 Storage size: 2048 bytes Paid storage size diff: 70 bytes - Consumed gas: 3213.097 + Consumed gas: 3653.097 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0175 storage fees ........................... +ꜩ0.0175 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out index 3a325d5c51f2..944ac12de52e 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_buy_tok.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_buy_tok Node is bootstrapped. -Estimated gas: 5113.046 units (will add 100 for safety) +Estimated gas: 5553.046 units (will add 100 for safety) Estimated storage: 326 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000869 + Fee to the baker: ꜩ0.000913 Expected counter: [EXPECTED_COUNTER] - Gas limit: 5214 + Gas limit: 5654 Storage limit: 346 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000869 - payload fees(the block proposer) ....... +ꜩ0.000869 + [CONTRACT_HASH] ... -ꜩ0.000913 + payload fees(the block proposer) ....... +ꜩ0.000913 Transaction: Amount: ꜩ9001 From: [CONTRACT_HASH] @@ -56,7 +56,7 @@ This sequence of operations was run: Set map(0)[0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c] to 360 Storage size: 2331 bytes Paid storage size diff: 68 bytes - Consumed gas: 2367.841 + Consumed gas: 2807.841 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve1.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve1.out index d620099096ac..3a2713894d79 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve1.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve1.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_call_approve1 Node is bootstrapped. -Estimated gas: 1679.785 units (will add 100 for safety) +Estimated gas: 2119.785 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000488 + Fee to the baker: ꜩ0.000532 Expected counter: [EXPECTED_COUNTER] - Gas limit: 1780 + Gas limit: 2220 Storage limit: 91 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000488 - payload fees(the block proposer) ....... +ꜩ0.000488 + [CONTRACT_HASH] ... -ꜩ0.000532 + payload fees(the block proposer) ....... +ꜩ0.000532 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2053 bytes Paid storage size diff: 71 bytes - Consumed gas: 1679.785 + Consumed gas: 2119.785 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve2.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve2.out index 66000869c7e0..b7dd20d39cf7 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve2.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve2.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_call_approve2 Node is bootstrapped. -Estimated gas: 1679.785 units (will add 100 for safety) +Estimated gas: 2119.785 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000488 + Fee to the baker: ꜩ0.000532 Expected counter: [EXPECTED_COUNTER] - Gas limit: 1780 + Gas limit: 2220 Storage limit: 91 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000488 - payload fees(the block proposer) ....... +ꜩ0.000488 + [CONTRACT_HASH] ... -ꜩ0.000532 + payload fees(the block proposer) ....... +ꜩ0.000532 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2124 bytes Paid storage size diff: 71 bytes - Consumed gas: 1679.785 + Consumed gas: 2119.785 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve3.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve3.out index 7350f75c01f5..73012de775f8 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve3.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_approve3.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_call_approve3 Node is bootstrapped. -Estimated gas: 1679.785 units (will add 100 for safety) +Estimated gas: 2119.785 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000488 + Fee to the baker: ꜩ0.000532 Expected counter: [EXPECTED_COUNTER] - Gas limit: 1780 + Gas limit: 2220 Storage limit: 91 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000488 - payload fees(the block proposer) ....... +ꜩ0.000488 + [CONTRACT_HASH] ... -ꜩ0.000532 + payload fees(the block proposer) ....... +ꜩ0.000532 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -33,7 +33,7 @@ This sequence of operations was run: 0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600)] to 1000000000 Storage size: 2195 bytes Paid storage size diff: 71 bytes - Consumed gas: 1679.785 + Consumed gas: 2119.785 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_mint_or_burn.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_mint_or_burn.out index 6ad10428b7b0..f9713059d4d0 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_mint_or_burn.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_call_mint_or_burn.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_call_mint_or_burn Node is bootstrapped. -Estimated gas: 3217.054 units (will add 100 for safety) +Estimated gas: 3657.054 units (will add 100 for safety) Estimated storage: 71 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000644 + Fee to the baker: ꜩ0.000688 Expected counter: [EXPECTED_COUNTER] - Gas limit: 3318 + Gas limit: 3758 Storage limit: 91 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000644 - payload fees(the block proposer) ....... +ꜩ0.000644 + [CONTRACT_HASH] ... -ꜩ0.000688 + payload fees(the block proposer) ....... +ꜩ0.000688 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -32,7 +32,7 @@ This sequence of operations was run: Set map(0)[0x000002298c03ed7d454a101eb7022bc95f7e5f41ac78] to 100000000 Storage size: 1982 bytes Paid storage size diff: 71 bytes - Consumed gas: 3217.527 + Consumed gas: 3657.527 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01775 storage fees ........................... +ꜩ0.01775 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out index 4659d038264f..e6826ed04063 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_sell_tok.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_sell_tok Node is bootstrapped. -Estimated gas: 7011.441 units (will add 100 for safety) +Estimated gas: 7451.441 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.001057 + Fee to the baker: ꜩ0.001101 Expected counter: [EXPECTED_COUNTER] - Gas limit: 7112 + Gas limit: 7552 Storage limit: 0 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.001057 - payload fees(the block proposer) ....... +ꜩ0.001057 + [CONTRACT_HASH] ... -ꜩ0.001101 + payload fees(the block proposer) ....... +ꜩ0.001101 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -51,7 +51,7 @@ This sequence of operations was run: Unset map(0)[0x0000dac9f52543da1aed0bc1d6b46bf7c10db7014cd6] Set map(0)[0x01d496def47a3be89f5d54c6e6bb13cc6645d6e16600] to 461 Storage size: 2331 bytes - Consumed gas: 3265.588 + Consumed gas: 3705.588 Internal Transaction: Amount: ꜩ3891.966034 From: [CONTRACT_HASH] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_transfer.out b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_transfer.out index 9f7c7516026e..295c90ebb4e0 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_transfer.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_liquidity_baking.TestTrades::test_transfer.out @@ -1,7 +1,7 @@ tests_alpha/test_liquidity_baking.py::TestTrades::test_transfer Node is bootstrapped. -Estimated gas: 2376.541 units (will add 100 for safety) +Estimated gas: 2816.541 units (will add 100 for safety) Estimated storage: 68 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000605 + Fee to the baker: ꜩ0.000649 Expected counter: [EXPECTED_COUNTER] - Gas limit: 2477 + Gas limit: 2917 Storage limit: 88 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000605 - payload fees(the block proposer) ....... +ꜩ0.000605 + [CONTRACT_HASH] ... -ꜩ0.000649 + payload fees(the block proposer) ....... +ꜩ0.000649 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -35,7 +35,7 @@ This sequence of operations was run: Set map(0)[0x0000e7670f32038107a59a2b9cfefae36ea21f5aa63c] to 260 Storage size: 2399 bytes Paid storage size diff: 68 bytes - Consumed gas: 2376.541 + Consumed gas: 2816.541 Balance updates: [CONTRACT_HASH] ... -ꜩ0.017 storage fees ........................... +ꜩ0.017 -- GitLab