From cdfa06bcec621c844c3ba75a9fd5a60df144a606 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Thu, 10 Mar 2022 15:37:12 +0900 Subject: [PATCH 1/2] Protocol Storage : introduce removing contract function --- src/proto_alpha/lib_protocol/storage.ml | 4 ++++ src/proto_alpha/lib_protocol/storage.mli | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index aa1b3825d99b..f40273a2720e 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -188,6 +188,10 @@ module Contract = struct let list = Indexed_context.keys + let remove ctxt contract = + Raw_context.consume_gas ctxt (Storage_costs.write_access ~written_bytes:0) >>?= fun ctxt -> + Indexed_context.remove ctxt contract >|= ok + 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 4cefe26a75fd..69a5083d4d11 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -69,6 +69,8 @@ module Contract : sig val list : Raw_context.t -> Contract_repr.t list Lwt.t + val remove : Raw_context.t -> Contract_repr.t -> Raw_context.t 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 -- GitLab From d8d6670e97f9bebd042ce5fa11d2c37b929c8a49 Mon Sep 17 00:00:00 2001 From: Yoshihiro Imai Date: Thu, 10 Mar 2022 17:14:22 +0900 Subject: [PATCH 2/2] Protocol Storage : When deleting contracts, the entire directory is deleted. --- src/proto_alpha/lib_protocol/contract_storage.ml | 9 +-------- src/proto_alpha/lib_protocol/storage.ml | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 97d6c4d925b5..b40489c5f0f4 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -443,14 +443,7 @@ let delete c contract = failwith "Non implicit contracts cannot be removed" | Some _ -> 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 >>=? fun c -> - Storage.Contract.Code.remove c contract >>=? fun (c, _, _) -> - Storage.Contract.Storage.remove c contract >>=? fun (c, _, _) -> - Storage.Contract.Paid_storage_space.remove c contract >>= fun c -> - Storage.Contract.Used_storage_space.remove c contract >|= ok + Storage.Contract.remove c contract let allocated c contract = Storage.Contract.Spendable_balance.find c contract >>=? function diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index f40273a2720e..9c152877f0ed 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -189,8 +189,8 @@ module Contract = struct let list = Indexed_context.keys let remove ctxt contract = - Raw_context.consume_gas ctxt (Storage_costs.write_access ~written_bytes:0) >>?= fun ctxt -> - Indexed_context.remove ctxt contract >|= ok + Raw_context.consume_gas ctxt (Storage_costs.write_access ~written_bytes:0) + >>?= fun ctxt -> Indexed_context.remove ctxt contract >|= ok module Spendable_balance = Indexed_context.Make_map -- GitLab