From ee4e53b192b817473b04763733f21d4383380483 Mon Sep 17 00:00:00 2001 From: Yann Regis-Gianas Date: Thu, 16 Dec 2021 11:14:30 +0100 Subject: [PATCH 1/2] Proto: Do not count the size of type annotation Signed-off-by: Yann Regis-Gianas --- .../lib_protocol/script_typed_ir_size.ml | 52 +++++-------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml index 29949bcaaf65..839a6ec28a22 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml @@ -29,21 +29,11 @@ include Cache_memory_helpers let script_string_size s = Script_string.to_string s |> string_size -(* The model assumes that annotations' sizes are counted once in the - Micheline representation and that the strings are always - shared. (One can check that they are never copied.) Besides, the - following types are unboxed so that they have no tags. *) -let type_annot_size (Script_ir_annot.Type_annot _) = !!0 - -let field_annot_size (Script_ir_annot.Field_annot _) = !!0 - -let var_annot_size (Script_ir_annot.Var_annot _) = !!0 - (* Memo-sizes are 16-bit integers *) let sapling_memo_size_size = !!0 let (comparable_ty_size, ty_size) = - let base {annot; size = _} = hh3w +! option_size type_annot_size annot in + let base {annot = _; size = _} = hh3w in let apply_comparable : type a. nodes_and_size -> a comparable_ty -> nodes_and_size = fun accu cty -> @@ -62,16 +52,10 @@ let (comparable_ty_size, ty_size) = | Bool_key a -> ret_succ_adding accu (base a) | Chain_id_key a -> ret_succ_adding accu (base a) | Never_key a -> ret_succ_adding accu (base a) - | Pair_key ((_ty1, fa1), (_ty2, fa2), a) -> - ret_succ_adding accu - @@ base a +! hh6w - +! option_size field_annot_size fa1 - +! option_size field_annot_size fa2 - | Union_key ((_ty1, fa1), (_ty2, fa2), a) -> - ret_succ_adding accu - @@ base a +! hh6w - +! option_size field_annot_size fa1 - +! option_size field_annot_size fa2 + | Pair_key ((_ty1, _fa1), (_ty2, _fa2), a) -> + ret_succ_adding accu @@ (base a +! hh6w) + | Union_key ((_ty1, _fa1), (_ty2, _fa2), a) -> + ret_succ_adding accu @@ (base a +! hh6w) | Option_key (_ty, a) -> ret_succ_adding accu @@ (base a +! word_size) and apply : type a. nodes_and_size -> a ty -> nodes_and_size = fun accu ty -> @@ -96,18 +80,10 @@ let (comparable_ty_size, ty_size) = | Bls12_381_fr_t a -> ret_succ_adding accu @@ base a | Chest_key_t a -> ret_succ_adding accu @@ base a | Chest_t a -> ret_succ_adding accu @@ base a - | Pair_t ((_ty1, fa1, va1), (_ty2, fa2, va2), a) -> - ret_succ_adding accu - @@ base a +! hh8w - +! option_size field_annot_size fa1 - +! option_size var_annot_size va1 - +! option_size field_annot_size fa2 - +! option_size var_annot_size va2 - | Union_t ((_ty1, fa1), (_ty2, fa2), a) -> - ret_succ_adding accu - @@ base a +! hh6w - +! option_size field_annot_size fa1 - +! option_size field_annot_size fa2 + | Pair_t ((_ty1, _fa1, _va1), (_ty2, _fa2, _va2), a) -> + ret_succ_adding accu @@ (base a +! hh8w) + | Union_t ((_ty1, _fa1), (_ty2, _fa2), a) -> + ret_succ_adding accu @@ (base a +! hh6w) | Lambda_t (_ty1, _ty2, a) -> ret_succ_adding accu @@ (base a +! (word_size *? 2)) | Option_t (_ty, a) -> ret_succ_adding accu @@ (base a +! word_size) @@ -133,10 +109,7 @@ let stack_ty_size s = fun accu s -> match s with | Bot_t -> ret_succ accu - | Item_t (ty, _, annot) -> - ret_succ_adding - (accu ++ ty_size ty) - (h3w +! option_size var_annot_size annot) + | Item_t (ty, _, _annot) -> ret_succ_adding (accu ++ ty_size ty) h3w in stack_ty_traverse s zero {apply} @@ -554,13 +527,12 @@ and kinstr_size : | ITransfer_tokens (kinfo, _) -> ret_succ_adding accu (base kinfo) | IImplicit_account (kinfo, _) -> ret_succ_adding accu (base kinfo) | ICreate_contract - {kinfo; storage_type; arg_type; lambda; root_name; views; k = _} -> + {kinfo; storage_type; arg_type; lambda; root_name = _; views; k = _} -> let accu = ret_succ_adding (accu ++ ty_size storage_type ++ ty_size arg_type ++ views_size views) - (base kinfo +! (word_size *? 4) - +! option_size field_annot_size root_name) + (base kinfo +! (word_size *? 4)) in (lambda_size [@ocaml.tailcall]) ~count_lambda_nodes accu lambda | ISet_delegate (kinfo, _) -> ret_succ_adding accu (base kinfo) -- GitLab From 314bba50a0e3bed351ba8de7da0770ea4f466165 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 16 Dec 2021 17:10:25 +0100 Subject: [PATCH 2/2] Tests/python: regenerate regtest outputs --- ...odes.TestContractOnchainOpcodes::test_set_delegate.out | 4 ++-- ...codes.TestContractOnchainOpcodes::test_split_bytes.out | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_set_delegate.out b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_set_delegate.out index f982a33c286e..dc85dd773ec9 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_set_delegate.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_set_delegate.out @@ -48,7 +48,7 @@ Injected block at minimal timestamp Injected block at minimal timestamp none Node is bootstrapped. -Estimated gas: 3056.175 units (will add 100 for safety) +Estimated gas: 3056.118 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -74,7 +74,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 51 bytes - Consumed gas: 2056.175 + Consumed gas: 2056.118 Internal operations: Delegation: Contract: [CONTRACT_HASH] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_split_bytes.out b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_split_bytes.out index afae1a432d76..51842f5fb369 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_split_bytes.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_split_bytes.out @@ -68,7 +68,7 @@ New contract [CONTRACT_HASH] originated. Contract memorized as split_bytes. Injected block at minimal timestamp Node is bootstrapped. -Estimated gas: 2097.375 units (will add 100 for safety) +Estimated gas: 2097.318 units (will add 100 for safety) Estimated storage: 18 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -95,7 +95,7 @@ This sequence of operations was run: Updated storage: { 0xaa ; 0xbb ; 0xcc } Storage size: 272 bytes Paid storage size diff: 18 bytes - Consumed gas: 2097.375 + Consumed gas: 2097.318 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0045 storage fees ........................... +ꜩ0.0045 @@ -103,7 +103,7 @@ This sequence of operations was run: Injected block at minimal timestamp { 0xaa ; 0xbb ; 0xcc } Node is bootstrapped. -Estimated gas: 1206.814 units (will add 100 for safety) +Estimated gas: 1206.757 units (will add 100 for safety) Estimated storage: 18 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -130,7 +130,7 @@ This sequence of operations was run: Updated storage: { 0xaa ; 0xbb ; 0xcc ; 0xdd ; 0xee ; 0xff } Storage size: 290 bytes Paid storage size diff: 18 bytes - Consumed gas: 1206.814 + Consumed gas: 1206.757 Balance updates: [CONTRACT_HASH] ... -ꜩ0.0045 storage fees ........................... +ꜩ0.0045 -- GitLab