From 5cb9c73954ec59df3a5ef48c82ac50d029babf9c Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 13:09:37 +0200 Subject: [PATCH 1/4] Proto/Contract_storage: manager is used by create_implicit only --- src/proto_alpha/lib_protocol/contract_storage.ml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 6e06ef64ad23..fe1ae366bc7e 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -405,7 +405,7 @@ let update_script_lazy_storage c = function let create_base c ~prepaid_bootstrap_storage (* Free space for bootstrap contracts *) - contract ~balance ~manager ?script () = + contract ~balance ?script () = (match contract with | Contract_repr.Originated _ -> return c | Implicit _ -> @@ -413,11 +413,6 @@ let create_base c ~prepaid_bootstrap_storage Storage.Contract.Counter.init c contract counter) >>=? fun c -> Storage.Contract.Spendable_balance.init c contract balance >>=? fun c -> - (match manager with - | Some manager -> - Contract_manager_storage.init c contract (Manager_repr.Hash manager) - | None -> return c) - >>=? fun c -> match script with | Some ({Script_repr.code; storage}, lazy_storage_diff) -> Storage.Contract.Code.init c contract code >>=? fun (c, code_size) -> @@ -448,19 +443,20 @@ let raw_originate c ~prepaid_bootstrap_storage contract ~script = ~prepaid_bootstrap_storage contract ~balance:Tez_repr.zero - ~manager:None ~script () let create_implicit c manager ~balance = + let contract = Contract_repr.Implicit manager in create_base c ~prepaid_bootstrap_storage:false - (Contract_repr.Implicit manager) + contract ~balance - ~manager:(Some manager) ?script:None () + >>=? fun c -> + Contract_manager_storage.init c contract (Manager_repr.Hash manager) let delete c contract = match contract with -- GitLab From 3115394feba379b5c5059579201fb22d92a46fc9 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 13:10:42 +0200 Subject: [PATCH 2/4] Proto/Contract_storage: counter is created for implicit accounts only --- src/proto_alpha/lib_protocol/contract_storage.ml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index fe1ae366bc7e..d295f90dfb2c 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -406,12 +406,6 @@ let update_script_lazy_storage c = function let create_base c ~prepaid_bootstrap_storage (* Free space for bootstrap contracts *) contract ~balance ?script () = - (match contract with - | Contract_repr.Originated _ -> return c - | Implicit _ -> - Storage.Contract.Global_counter.get c >>=? fun counter -> - Storage.Contract.Counter.init c contract counter) - >>=? fun c -> Storage.Contract.Spendable_balance.init c contract balance >>=? fun c -> match script with | Some ({Script_repr.code; storage}, lazy_storage_diff) -> @@ -448,6 +442,8 @@ let raw_originate c ~prepaid_bootstrap_storage contract ~script = let create_implicit c manager ~balance = let contract = Contract_repr.Implicit manager in + Storage.Contract.Global_counter.get c >>=? fun counter -> + Storage.Contract.Counter.init c contract counter >>=? fun c -> create_base c ~prepaid_bootstrap_storage:false -- GitLab From 9d1aec515d992e784dcf97a623721596483f2054 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 13:12:37 +0200 Subject: [PATCH 3/4] Proto/Contract_storage: only originated accounts have a script --- .../lib_protocol/contract_storage.ml | 65 ++++++------------- 1 file changed, 21 insertions(+), 44 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index d295f90dfb2c..137d5f9aa11b 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -403,55 +403,32 @@ let update_script_lazy_storage c = function | None -> return (c, Z.zero) | Some diffs -> Lazy_storage_diff.apply c diffs -let create_base c ~prepaid_bootstrap_storage - (* Free space for bootstrap contracts *) - contract ~balance ?script () = - Storage.Contract.Spendable_balance.init c contract balance >>=? fun c -> - match script with - | Some ({Script_repr.code; storage}, lazy_storage_diff) -> - Storage.Contract.Code.init c contract code >>=? fun (c, code_size) -> - Storage.Contract.Storage.init c contract storage - >>=? fun (c, storage_size) -> - update_script_lazy_storage c lazy_storage_diff - >>=? fun (c, lazy_storage_size) -> - let total_size = - Z.add - (Z.add (Z.of_int code_size) (Z.of_int storage_size)) - lazy_storage_size - in - assert (Compare.Z.(total_size >= Z.zero)) ; - let prepaid_bootstrap_storage = - if prepaid_bootstrap_storage then total_size else Z.zero - in - Storage.Contract.Paid_storage_space.init - c - contract - prepaid_bootstrap_storage - >>=? fun c -> - Storage.Contract.Used_storage_space.init c contract total_size - | None -> return c - -let raw_originate c ~prepaid_bootstrap_storage contract ~script = - create_base - c - ~prepaid_bootstrap_storage - contract - ~balance:Tez_repr.zero - ~script - () +let create_base c contract ~balance = + Storage.Contract.Spendable_balance.init c contract balance + +let raw_originate c ~prepaid_bootstrap_storage + (* Free space for bootstrap contracts *) contract ~script = + create_base c contract ~balance:Tez_repr.zero >>=? fun c -> + let {Script_repr.code; storage}, lazy_storage_diff = script in + Storage.Contract.Code.init c contract code >>=? fun (c, code_size) -> + Storage.Contract.Storage.init c contract storage >>=? fun (c, storage_size) -> + update_script_lazy_storage c lazy_storage_diff + >>=? fun (c, lazy_storage_size) -> + let total_size = + Z.add (Z.add (Z.of_int code_size) (Z.of_int storage_size)) lazy_storage_size + in + assert (Compare.Z.(total_size >= Z.zero)) ; + let prepaid_bootstrap_storage = + if prepaid_bootstrap_storage then total_size else Z.zero + in + Storage.Contract.Paid_storage_space.init c contract prepaid_bootstrap_storage + >>=? fun c -> Storage.Contract.Used_storage_space.init c contract total_size let create_implicit c manager ~balance = let contract = Contract_repr.Implicit manager in Storage.Contract.Global_counter.get c >>=? fun counter -> Storage.Contract.Counter.init c contract counter >>=? fun c -> - create_base - c - ~prepaid_bootstrap_storage:false - contract - ~balance - ?script:None - () - >>=? fun c -> + create_base c contract ~balance >>=? fun c -> Contract_manager_storage.init c contract (Manager_repr.Hash manager) let delete c contract = -- GitLab From 63362595bf04eda156767ed1e76a78d1c324bc74 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 17 May 2022 19:36:00 +0200 Subject: [PATCH 4/4] Proto/Contract_storage: inline create_base --- src/proto_alpha/lib_protocol/contract_storage.ml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 137d5f9aa11b..3f82716ae57c 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -403,12 +403,9 @@ let update_script_lazy_storage c = function | None -> return (c, Z.zero) | Some diffs -> Lazy_storage_diff.apply c diffs -let create_base c contract ~balance = - Storage.Contract.Spendable_balance.init c contract balance - let raw_originate c ~prepaid_bootstrap_storage (* Free space for bootstrap contracts *) contract ~script = - create_base c contract ~balance:Tez_repr.zero >>=? fun c -> + Storage.Contract.Spendable_balance.init c contract Tez_repr.zero >>=? fun c -> let {Script_repr.code; storage}, lazy_storage_diff = script in Storage.Contract.Code.init c contract code >>=? fun (c, code_size) -> Storage.Contract.Storage.init c contract storage >>=? fun (c, storage_size) -> @@ -428,7 +425,7 @@ let create_implicit c manager ~balance = let contract = Contract_repr.Implicit manager in Storage.Contract.Global_counter.get c >>=? fun counter -> Storage.Contract.Counter.init c contract counter >>=? fun c -> - create_base c contract ~balance >>=? fun c -> + Storage.Contract.Spendable_balance.init c contract balance >>=? fun c -> Contract_manager_storage.init c contract (Manager_repr.Hash manager) let delete c contract = -- GitLab