From ec5ac0997462ac1e29001bd54446ed1af59a9729 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 13 Oct 2022 18:41:48 +0200 Subject: [PATCH 1/6] Proto/Tests/Manager_operation_helpers: turn nb_counter to int Because it is enough and will simplify a later change. --- .../integration/validate/manager_operation_helpers.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml index 1698cbaf4072..f26a0a8a7d39 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml @@ -1262,7 +1262,7 @@ type probes = { source : Signature.Public_key_hash.t; fee : Tez.tez; gas_limit : Gas.Arith.integral; - nb_counter : Z.t; + nb_counter : int; } let rec contents_infos : @@ -1271,12 +1271,12 @@ let rec contents_infos : let open Lwt_result_syntax in match op with | Single (Manager_operation {source; fee; gas_limit; _}) -> - return {source; fee; gas_limit; nb_counter = Z.one} + return {source; fee; gas_limit; nb_counter = 1} | Cons (Manager_operation manop, manops) -> let* probes = contents_infos manops in let*? fee = manop.fee +? probes.fee in let gas_limit = Gas.Arith.add probes.gas_limit manop.gas_limit in - let nb_counter = Z.succ probes.nb_counter in + let nb_counter = succ probes.nb_counter in let _ = Assert.equal_pkh ~loc:__LOC__ manop.source probes.source in return {fee; source = probes.source; gas_limit; nb_counter} @@ -1322,7 +1322,7 @@ let expected_witness witness probes ~mode ctxt = let open Lwt_result_syntax in let b_in, c_in, g_in = witness in let*? b_expected = b_in -? probes.fee in - let c_expected = Z.add c_in probes.nb_counter in + let c_expected = Z.add c_in (Z.of_int probes.nb_counter) in let+ g_expected = match (g_in, mode) with | Some g_in, Construction -> -- GitLab From 862b8eeee09cea880ea44253b807c422b4863169 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 15:50:39 +0200 Subject: [PATCH 2/6] Proto/Client and Tests: use Z.t rather than counter for storage limit --- .../lib_client/client_proto_context.mli | 16 +++++++------- .../lib_client/client_proto_fa12.mli | 2 +- .../lib_client/client_proto_multisig.ml | 2 +- .../lib_client/managed_contract.mli | 4 ++-- .../lib_protocol/test/helpers/op.mli | 22 +++++++++---------- .../validate/manager_operation_helpers.ml | 2 +- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index 4b83e4bdc119..cf0a45469f83 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -812,7 +812,7 @@ val sc_rollup_originate : ?simulation:bool -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?counter:counter -> source:public_key_hash -> kind:Sc_rollup.Kind.t -> @@ -839,7 +839,7 @@ val sc_rollup_add_messages : ?simulation:bool -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?counter:counter -> source:public_key_hash -> messages:string list -> @@ -863,7 +863,7 @@ val sc_rollup_cement : ?simulation:bool -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?counter:counter -> source:public_key_hash -> rollup:Alpha_context.Sc_rollup.t -> @@ -888,7 +888,7 @@ val sc_rollup_publish : ?simulation:bool -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?counter:counter -> source:public_key_hash -> rollup:Alpha_context.Sc_rollup.t -> @@ -913,7 +913,7 @@ val sc_rollup_execute_outbox_message : ?simulation:bool -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?counter:counter -> source:public_key_hash -> rollup:Sc_rollup.t -> @@ -965,7 +965,7 @@ val sc_rollup_refute : ?simulation:bool -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?counter:counter -> source:public_key_hash -> rollup:Alpha_context.Sc_rollup.t -> @@ -991,7 +991,7 @@ val sc_rollup_timeout : ?simulation:bool -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?counter:counter -> source:public_key_hash -> rollup:Alpha_context.Sc_rollup.t -> @@ -1017,7 +1017,7 @@ val sc_rollup_dal_slot_subscribe : ?simulation:bool -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?counter:counter -> source:public_key_hash -> rollup:Alpha_context.Sc_rollup.t -> diff --git a/src/proto_alpha/lib_client/client_proto_fa12.mli b/src/proto_alpha/lib_client/client_proto_fa12.mli index f3cafb56ef64..14f56e24cb57 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.mli +++ b/src/proto_alpha/lib_client/client_proto_fa12.mli @@ -143,7 +143,7 @@ val inject_token_transfer_batch : ?counter:counter -> ?default_fee:Tez.t -> ?default_gas_limit:Gas.Arith.integral -> - ?default_storage_limit:counter -> + ?default_storage_limit:Z.t -> unit -> unit tzresult Lwt.t diff --git a/src/proto_alpha/lib_client/client_proto_multisig.ml b/src/proto_alpha/lib_client/client_proto_multisig.ml index 45faac04e91d..f72d8bba1619 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.ml +++ b/src/proto_alpha/lib_client/client_proto_multisig.ml @@ -46,7 +46,7 @@ type error += Bytes_deserialisation_error of Bytes.t type error += Bad_deserialized_contract of (Contract_hash.t * Contract_hash.t) -type error += Bad_deserialized_counter of (counter * counter) +type error += Bad_deserialized_counter of (Z.t * Z.t) type error += Non_positive_threshold of int diff --git a/src/proto_alpha/lib_client/managed_contract.mli b/src/proto_alpha/lib_client/managed_contract.mli index e0cc3d291769..aea7fb7763fd 100644 --- a/src/proto_alpha/lib_client/managed_contract.mli +++ b/src/proto_alpha/lib_client/managed_contract.mli @@ -84,7 +84,7 @@ val build_transaction_operation : amount:Tez.t -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> unit -> Kind.transaction Annotated_manager_operation.t tzresult Lwt.t @@ -113,7 +113,7 @@ val transfer : amount:Tez.t -> ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?counter:counter -> fee_parameter:Injection.fee_parameter -> unit -> diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.mli b/src/proto_alpha/lib_protocol/test/helpers/op.mli index ed92eee6e7b4..ce21e0ee036a 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/op.mli @@ -125,7 +125,7 @@ val unsafe_transaction : ?counter:counter -> ?fee:Tez.t -> ?gas_limit:gas_limit -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?parameters: Michelson_v1_primitives.prim Micheline.canonical Data_encoding.lazy_t -> ?entrypoint:Entrypoint_repr.t -> @@ -184,13 +184,13 @@ val increase_paid_storage : {li [?forge_pkh]: use a provided [pkh] as source, instead of hashing [pkh]. Useful for forging non-honest reveal operations} - {li [?storage_limit:counter]: forces a storage limit, otherwise + {li [?storage_limit:Z.t]: forces a storage limit, otherwise set to [Z.zero]} *) val revelation : ?fee:Tez.t -> ?gas_limit:gas_limit -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?counter:counter -> ?forge_pkh:public_key_hash option -> Context.t -> @@ -489,7 +489,7 @@ val tx_rollup_dispatch_tickets : ?counter:counter -> ?fee:Tez.t -> ?gas_limit:gas_limit -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> Context.t -> source:Contract.t -> message_index:int -> @@ -529,7 +529,7 @@ val transfer_ticket : ?counter:counter -> ?fee:Tez.t -> ?gas_limit:gas_limit -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> Context.t -> source:Contract.t -> contents:Script.lazy_expr -> @@ -608,7 +608,7 @@ val sc_rollup_origination : ?counter:counter -> ?fee:Tez.t -> ?gas_limit:gas_limit -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?origination_proof:string -> Context.t -> Contract.t -> @@ -662,7 +662,7 @@ val sc_rollup_execute_outbox_message : ?counter:counter -> ?fee:Tez.t -> ?gas_limit:gas_limit -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> ?force_reveal:bool -> Context.t -> Contract.t -> @@ -724,7 +724,7 @@ val dal_publish_slot_header : ?counter:counter -> ?fee:Tez.t -> ?gas_limit:gas_limit -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> Context.t -> Contract.t -> Dal.Slot.Header.t -> @@ -737,7 +737,7 @@ val zk_rollup_origination : ?counter:Z.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> Context.t -> Contract.t -> public_parameters: @@ -753,7 +753,7 @@ val update_consensus_key : ?counter:counter -> ?fee:Tez.t -> ?gas_limit:gas_limit -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> Context.t -> Contract.t -> public_key -> @@ -773,7 +773,7 @@ val zk_rollup_publish : ?counter:Z.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> - ?storage_limit:counter -> + ?storage_limit:Z.t -> Context.t -> Contract.t -> zk_rollup:Zk_rollup.t -> diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml index f26a0a8a7d39..8bacf024020b 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml @@ -111,7 +111,7 @@ type operation_req = { counter : counter option; fee : Tez.t option; gas_limit : Op.gas_limit option; - storage_limit : counter option; + storage_limit : Z.t option; force_reveal : bool option; amount : Tez.t option; } -- GitLab From 801d4e463234bd917c90c5cf56b6146463ad148e Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 15:51:36 +0200 Subject: [PATCH 3/6] Proto/Tx_rollup_ticket: return Z.t rather than counter for number of bytes --- src/proto_alpha/lib_protocol/tx_rollup_ticket.mli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli b/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli index d900a644a817..83a5f38b5fdb 100644 --- a/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli +++ b/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli @@ -101,4 +101,4 @@ val transfer_ticket : dst:Destination.t -> Ticket_token.ex_token -> Script_typed_ir.ticket_amount -> - (context * counter, error trace) result Lwt.t + (context * Z.t, error trace) result Lwt.t -- GitLab From 575453b711d94a791af39e086927954dc1ae67f6 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 15:56:31 +0200 Subject: [PATCH 4/6] Proto/Client: name Bad_deserialized_counter fields --- .../lib_client/client_proto_multisig.ml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_multisig.ml b/src/proto_alpha/lib_client/client_proto_multisig.ml index f72d8bba1619..108233e7b2ab 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.ml +++ b/src/proto_alpha/lib_client/client_proto_multisig.ml @@ -46,7 +46,7 @@ type error += Bytes_deserialisation_error of Bytes.t type error += Bad_deserialized_contract of (Contract_hash.t * Contract_hash.t) -type error += Bad_deserialized_counter of (Z.t * Z.t) +type error += Bad_deserialized_counter of {received : Z.t; expected : Z.t} type error += Non_positive_threshold of int @@ -225,9 +225,12 @@ let () = expected) Data_encoding.(obj1 (req "received_expected" (tup2 int31 int31))) (function - | Bad_deserialized_counter (c1, c2) -> Some (Z.to_int c1, Z.to_int c2) + | Bad_deserialized_counter {received; expected} -> + Some (Z.to_int received, Z.to_int expected) | _ -> None) - (fun (c1, c2) -> Bad_deserialized_counter (Z.of_int c1, Z.of_int c2)) ; + (fun (received, expected) -> + Bad_deserialized_counter + {received = Z.of_int received; expected = Z.of_int expected}) ; register_error_kind `Permanent ~id:"thresholdTooHigh" @@ -1141,7 +1144,10 @@ let action_of_bytes ~multisig_contract ~stored_counter ~descr ~chain_id bytes = action_of_expr ~generic:descr.generic e else fail (Bad_deserialized_contract (contract, multisig_contract)) - else fail (Bad_deserialized_counter (counter, stored_counter)) + else + fail + (Bad_deserialized_counter + {received = counter; expected = stored_counter}) | Tezos_micheline.Micheline.Prim ( _, Script.D_Pair, @@ -1175,7 +1181,10 @@ let action_of_bytes ~multisig_contract ~stored_counter ~descr ~chain_id bytes = action_of_expr ~generic:descr.generic e else fail (Bad_deserialized_contract (contract, multisig_contract)) - else fail (Bad_deserialized_counter (counter, stored_counter)) + else + fail + (Bad_deserialized_counter + {received = counter; expected = stored_counter}) | _ -> fail (Bytes_deserialisation_error bytes)) else fail (Bytes_deserialisation_error bytes) -- GitLab From dd71387f9608e8deac29a5710549716937ab2854 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 13 Oct 2022 19:04:51 +0200 Subject: [PATCH 5/6] Proto/Contract_storage: name Counter_in_the_past/future fields --- .../lib_protocol/contract_storage.ml | 32 ++++++++++++++----- .../lib_protocol/contract_storage.mli | 12 +++++-- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 4f11a9171a4d..1368f75f7aeb 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -28,9 +28,17 @@ type error += | (* `Temporary *) Balance_too_low of Contract_repr.t * Tez_repr.t * Tez_repr.t | (* `Temporary *) - Counter_in_the_past of Contract_repr.t * Z.t * Z.t + Counter_in_the_past of { + contract : Contract_repr.t; + expected : Z.t; + found : Z.t; + } | (* `Branch *) - Counter_in_the_future of Contract_repr.t * Z.t * Z.t + Counter_in_the_future of { + contract : Contract_repr.t; + expected : Z.t; + found : Z.t; + } | (* `Temporary *) Non_existing_contract of Contract_repr.t | (* `Branch *) @@ -91,8 +99,12 @@ let () = (req "contract" Contract_repr.encoding) (req "expected" z) (req "found" z)) - (function Counter_in_the_future (c, x, y) -> Some (c, x, y) | _ -> None) - (fun (c, x, y) -> Counter_in_the_future (c, x, y)) ; + (function + | Counter_in_the_future {contract; expected; found} -> + Some (contract, expected, found) + | _ -> None) + (fun (contract, expected, found) -> + Counter_in_the_future {contract; expected; found}) ; register_error_kind `Branch ~id:"contract.counter_in_the_past" @@ -113,8 +125,12 @@ let () = (req "contract" Contract_repr.encoding) (req "expected" z) (req "found" z)) - (function Counter_in_the_past (c, x, y) -> Some (c, x, y) | _ -> None) - (fun (c, x, y) -> Counter_in_the_past (c, x, y)) ; + (function + | Counter_in_the_past {contract; expected; found} -> + Some (contract, expected, found) + | _ -> None) + (fun (contract, expected, found) -> + Counter_in_the_past {contract; expected; found}) ; register_error_kind `Temporary ~id:"contract.non_existing_contract" @@ -491,8 +507,8 @@ let check_counter_increment c manager counter = let expected = Z.succ contract_counter in if Compare.Z.(expected = counter) then return_unit else if Compare.Z.(expected > counter) then - fail (Counter_in_the_past (contract, expected, counter)) - else fail (Counter_in_the_future (contract, expected, counter)) + fail (Counter_in_the_past {contract; expected; found = counter}) + else fail (Counter_in_the_future {contract; expected; found = counter}) let increment_counter c manager = let contract = Contract_repr.Implicit manager in diff --git a/src/proto_alpha/lib_protocol/contract_storage.mli b/src/proto_alpha/lib_protocol/contract_storage.mli index 2f97c357c19e..e553be045895 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.mli +++ b/src/proto_alpha/lib_protocol/contract_storage.mli @@ -30,9 +30,17 @@ type error += | (* `Temporary *) Balance_too_low of Contract_repr.t * Tez_repr.t * Tez_repr.t | (* `Temporary *) - Counter_in_the_past of Contract_repr.t * Z.t * Z.t + Counter_in_the_past of { + contract : Contract_repr.t; + expected : Z.t; + found : Z.t; + } | (* `Branch *) - Counter_in_the_future of Contract_repr.t * Z.t * Z.t + Counter_in_the_future of { + contract : Contract_repr.t; + expected : Z.t; + found : Z.t; + } | (* `Temporary *) Non_existing_contract of Contract_repr.t | (* `Permanent *) -- GitLab From 89fde91ba479e2c765a2805fcd29fa6935fd7404 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 16:14:50 +0200 Subject: [PATCH 6/6] Proto/Tests/Operation_generator: add gen_ticket_amounts, do not use gen_counters --- .../lib_protocol/test/helpers/operation_generator.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml index 1cfcf7f17611..55f556658c09 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml @@ -329,6 +329,11 @@ let gen_counters = let+ i = nat in Z.of_int i +let gen_ticket_amounts = + let open QCheck2.Gen in + let+ i = nat in + Option.value (Ticket_amount.of_zint (Z.of_int i)) ~default:Ticket_amount.one + let gen_gas_limit = let open QCheck2.Gen in let+ i = nat in @@ -630,10 +635,7 @@ let generate_transfer_ticket = let open QCheck2.Gen in let* ticketer = random_contract in let* destination = random_contract in - let+ amount = gen_counters in - let amount = - Option.value (Ticket_amount.of_zint amount) ~default:Ticket_amount.one - in + let+ amount = gen_ticket_amounts in let contents = Script.lazy_expr (Expr.from_string "1") in let ty = Script.lazy_expr (Expr.from_string "nat") in let entrypoint = Entrypoint.default in -- GitLab