From c3b08776a11b27c97758e28116e8cf54238c286b Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 12:51:42 +0200 Subject: [PATCH 01/17] Proto: move manager counter to its own module --- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 1 + src/proto_alpha/lib_protocol/dune | 4 +++ .../lib_protocol/manager_counter_repr.ml | 27 ++++++++++++++++ .../lib_protocol/manager_counter_repr.mli | 32 +++++++++++++++++++ .../lib_protocol/operation_repr.ml | 2 +- .../lib_protocol/operation_repr.mli | 7 +--- 6 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 src/proto_alpha/lib_protocol/manager_counter_repr.ml create mode 100644 src/proto_alpha/lib_protocol/manager_counter_repr.mli diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 00bf18b7e7e7..fb3eb85045a7 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -44,6 +44,7 @@ "Sampler", "Voting_period_repr", "Ticket_hash_repr", + "Manager_counter_repr", "Contract_repr", "Indexable", "Entrypoint_repr", diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index 65a9fe15d975..70b931f52b64 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -72,6 +72,7 @@ Sampler Voting_period_repr Ticket_hash_repr + Manager_counter_repr Contract_repr Indexable Entrypoint_repr @@ -339,6 +340,7 @@ sampler.ml sampler.mli voting_period_repr.ml voting_period_repr.mli ticket_hash_repr.ml ticket_hash_repr.mli + manager_counter_repr.ml manager_counter_repr.mli contract_repr.ml contract_repr.mli indexable.ml indexable.mli entrypoint_repr.ml entrypoint_repr.mli @@ -588,6 +590,7 @@ sampler.ml sampler.mli voting_period_repr.ml voting_period_repr.mli ticket_hash_repr.ml ticket_hash_repr.mli + manager_counter_repr.ml manager_counter_repr.mli contract_repr.ml contract_repr.mli indexable.ml indexable.mli entrypoint_repr.ml entrypoint_repr.mli @@ -842,6 +845,7 @@ sampler.ml sampler.mli voting_period_repr.ml voting_period_repr.mli ticket_hash_repr.ml ticket_hash_repr.mli + manager_counter_repr.ml manager_counter_repr.mli contract_repr.ml contract_repr.mli indexable.ml indexable.mli entrypoint_repr.ml entrypoint_repr.mli diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml new file mode 100644 index 000000000000..4193acad5a18 --- /dev/null +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -0,0 +1,27 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2022 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +type t = Z.t diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli new file mode 100644 index 000000000000..4af5ccbc9792 --- /dev/null +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -0,0 +1,32 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. *) +(* Copyright (c) 2022 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Counters are used as anti-replay protection mechanism in + manager operations: each manager account stores a counter and + each manager operation declares a value for the counter. When + a manager operation is applied, the value of the counter of + its manager is checked and incremented. *) +type t = Z.t diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 41ad4307c084..29d70dfab658 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -489,7 +489,7 @@ and _ manager_operation = } -> Kind.zk_rollup_publish manager_operation -and counter = Z.t +and counter = Manager_counter_repr.t let manager_kind : type kind. kind manager_operation -> kind Kind.manager = function diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 27cc6c17cfd7..2c71631c2e70 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -581,12 +581,7 @@ and _ manager_operation = } -> Kind.zk_rollup_publish manager_operation -(** Counters are used as anti-replay protection mechanism in - manager operations: each manager account stores a counter and - each manager operation declares a value for the counter. When - a manager operation is applied, the value of the counter of - its manager is checked and incremented. *) -and counter = Z.t +and counter = Manager_counter_repr.t type packed_manager_operation = | Manager : 'kind manager_operation -> packed_manager_operation -- GitLab From 87ebcbfef7de190ed1e74751b6c0f5d2af3f4429 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 15:44:50 +0200 Subject: [PATCH 02/17] Proto: remove counter type alias --- .../lib_client/annotated_manager_operation.mli | 2 +- .../lib_client/client_proto_context.mli | 16 ++++++++-------- .../lib_client/client_proto_fa12.mli | 2 +- .../lib_client/managed_contract.mli | 2 +- .../lib_delegate/operation_selection.ml | 2 +- src/proto_alpha/lib_protocol/alpha_context.ml | 1 + src/proto_alpha/lib_protocol/alpha_context.mli | 9 ++++++--- .../lib_protocol/contract_services.ml | 2 +- .../lib_protocol/contract_services.mli | 4 ++-- src/proto_alpha/lib_protocol/operation_repr.ml | 4 +--- .../lib_protocol/operation_repr.mli | 4 +--- .../lib_protocol/test/helpers/op.mli | 18 +++++++++--------- .../validate/manager_operation_helpers.ml | 4 ++-- src/proto_alpha/lib_protocol/validate.ml | 4 ++-- 14 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/proto_alpha/lib_client/annotated_manager_operation.mli b/src/proto_alpha/lib_client/annotated_manager_operation.mli index 4eebe07b7a59..db6e868a01c1 100644 --- a/src/proto_alpha/lib_client/annotated_manager_operation.mli +++ b/src/proto_alpha/lib_client/annotated_manager_operation.mli @@ -85,7 +85,7 @@ val set_storage_limit : Z.t Limit.t -> 'a t -> 'a t (** Set the counter of the annotated operation. Fail if the counter is already set. *) -val set_counter : counter -> 'a t -> 'a t tzresult +val set_counter : Manager_counter.t -> 'a t -> 'a t tzresult (** Set the source of the operation. Fail if the source is already set. *) val set_source : public_key_hash -> 'a t -> 'a t tzresult diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index e25b0a0aa97a..76f034f3ddb4 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -822,7 +822,7 @@ val sc_rollup_originate : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:counter -> + ?counter:Manager_counter.t -> source:public_key_hash -> kind:Sc_rollup.Kind.t -> boot_sector:string -> @@ -849,7 +849,7 @@ val sc_rollup_add_messages : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:counter -> + ?counter:Manager_counter.t -> source:public_key_hash -> messages:string list -> src_pk:public_key -> @@ -873,7 +873,7 @@ val sc_rollup_cement : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:counter -> + ?counter:Manager_counter.t -> source:public_key_hash -> rollup:Alpha_context.Sc_rollup.t -> commitment:Alpha_context.Sc_rollup.Commitment.Hash.t -> @@ -898,7 +898,7 @@ val sc_rollup_publish : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:counter -> + ?counter:Manager_counter.t -> source:public_key_hash -> rollup:Alpha_context.Sc_rollup.t -> commitment:Alpha_context.Sc_rollup.Commitment.t -> @@ -923,7 +923,7 @@ val sc_rollup_execute_outbox_message : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:counter -> + ?counter:Manager_counter.t -> source:public_key_hash -> rollup:Sc_rollup.t -> cemented_commitment:Sc_rollup.Commitment.Hash.t -> @@ -975,7 +975,7 @@ val sc_rollup_refute : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:counter -> + ?counter:Manager_counter.t -> source:public_key_hash -> rollup:Alpha_context.Sc_rollup.t -> refutation:Alpha_context.Sc_rollup.Game.refutation option -> @@ -1001,7 +1001,7 @@ val sc_rollup_timeout : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:counter -> + ?counter:Manager_counter.t -> source:public_key_hash -> rollup:Alpha_context.Sc_rollup.t -> alice:Alpha_context.Sc_rollup.Staker.t -> @@ -1027,7 +1027,7 @@ val sc_rollup_dal_slot_subscribe : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:counter -> + ?counter:Manager_counter.t -> source:public_key_hash -> rollup:Alpha_context.Sc_rollup.t -> slot_index:int -> diff --git a/src/proto_alpha/lib_client/client_proto_fa12.mli b/src/proto_alpha/lib_client/client_proto_fa12.mli index 14f56e24cb57..01eada3c5951 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.mli +++ b/src/proto_alpha/lib_client/client_proto_fa12.mli @@ -140,7 +140,7 @@ val inject_token_transfer_batch : src_sk:Client_keys.sk_uri -> token_transfers:token_transfer list -> fee_parameter:Injection.fee_parameter -> - ?counter:counter -> + ?counter:Manager_counter.t -> ?default_fee:Tez.t -> ?default_gas_limit:Gas.Arith.integral -> ?default_storage_limit:Z.t -> diff --git a/src/proto_alpha/lib_client/managed_contract.mli b/src/proto_alpha/lib_client/managed_contract.mli index aea7fb7763fd..b459230ae8b3 100644 --- a/src/proto_alpha/lib_client/managed_contract.mli +++ b/src/proto_alpha/lib_client/managed_contract.mli @@ -114,7 +114,7 @@ val transfer : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:counter -> + ?counter:Manager_counter.t -> fee_parameter:Injection.fee_parameter -> unit -> (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) diff --git a/src/proto_alpha/lib_delegate/operation_selection.ml b/src/proto_alpha/lib_delegate/operation_selection.ml index a658661df026..bd4b069b980d 100644 --- a/src/proto_alpha/lib_delegate/operation_selection.ml +++ b/src/proto_alpha/lib_delegate/operation_selection.ml @@ -45,7 +45,7 @@ type prioritized_manager = { gas : Fixed_point_repr.integral_tag Gas.Arith.t; weight : Q.t; source : public_key_hash; - counter : counter; + counter : Manager_counter.t; } module PrioritizedManagerSet = Set.Make (struct diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 40e163c86ab0..6403ff9bd3cf 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -140,6 +140,7 @@ module Zk_rollup = struct end module Entrypoint = Entrypoint_repr +module Manager_counter = Manager_counter_repr include Operation_repr module Operation = struct diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index ef244db92694..153af43bcb75 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1597,6 +1597,11 @@ module Ticket_hash : sig end end +(** This module re-exports definitions from {!Manager_counter_repr}. *) +module Manager_counter : sig + type t = Z.t +end + (** This module re-exports definitions from {!Contract_repr} and {!Contract_storage}. *) module Contract : sig @@ -4346,7 +4351,7 @@ and _ contents = | Manager_operation : { source : public_key_hash; fee : Tez.tez; - counter : counter; + counter : Manager_counter.t; operation : 'kind manager_operation; gas_limit : Gas.Arith.integral; storage_limit : Z.t; @@ -4503,8 +4508,6 @@ and _ manager_operation = } -> Kind.zk_rollup_publish manager_operation -and counter = Z.t - type packed_manager_operation = | Manager : 'kind manager_operation -> packed_manager_operation diff --git a/src/proto_alpha/lib_protocol/contract_services.ml b/src/proto_alpha/lib_protocol/contract_services.ml index b55fa2740e7b..10886275d1ed 100644 --- a/src/proto_alpha/lib_protocol/contract_services.ml +++ b/src/proto_alpha/lib_protocol/contract_services.ml @@ -37,7 +37,7 @@ let big_map_root = type info = { balance : Tez.t; delegate : public_key_hash option; - counter : counter option; + counter : Manager_counter.t option; script : Script.t option; } diff --git a/src/proto_alpha/lib_protocol/contract_services.mli b/src/proto_alpha/lib_protocol/contract_services.mli index e37d2ce837f6..7ea8996b24ab 100644 --- a/src/proto_alpha/lib_protocol/contract_services.mli +++ b/src/proto_alpha/lib_protocol/contract_services.mli @@ -35,7 +35,7 @@ val list : 'a #RPC_context.simple -> 'a -> Contract.t list shell_tzresult Lwt.t type info = { balance : Tez.t; delegate : public_key_hash option; - counter : counter option; + counter : Manager_counter.t option; script : Script.t option; } @@ -79,7 +79,7 @@ val counter : 'a #RPC_context.simple -> 'a -> public_key_hash -> - counter shell_tzresult Lwt.t + Manager_counter.t shell_tzresult Lwt.t val script : 'a #RPC_context.simple -> diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 29d70dfab658..f538d4fa09bb 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -330,7 +330,7 @@ and _ contents = | Manager_operation : { source : Signature.public_key_hash; fee : Tez_repr.tez; - counter : counter; + counter : Manager_counter_repr.t; operation : 'kind manager_operation; gas_limit : Gas_limit_repr.Arith.integral; storage_limit : Z.t; @@ -489,8 +489,6 @@ and _ manager_operation = } -> Kind.zk_rollup_publish manager_operation -and counter = Manager_counter_repr.t - let manager_kind : type kind. kind manager_operation -> kind Kind.manager = function | Reveal _ -> Kind.Reveal_manager_kind diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 2c71631c2e70..18573215474b 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -354,7 +354,7 @@ and _ contents = | Manager_operation : { source : Signature.Public_key_hash.t; fee : Tez_repr.tez; - counter : counter; + counter : Manager_counter_repr.t; operation : 'kind manager_operation; gas_limit : Gas_limit_repr.Arith.integral; storage_limit : Z.t; @@ -581,8 +581,6 @@ and _ manager_operation = } -> Kind.zk_rollup_publish manager_operation -and counter = Manager_counter_repr.t - type packed_manager_operation = | Manager : 'kind manager_operation -> packed_manager_operation diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.mli b/src/proto_alpha/lib_protocol/test/helpers/op.mli index ce21e0ee036a..ae351b713ab4 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/op.mli @@ -122,7 +122,7 @@ val transaction : yet. Disabled (set to [false]) by default.}} *) val unsafe_transaction : ?force_reveal:bool -> - ?counter:counter -> + ?counter:Manager_counter.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -191,7 +191,7 @@ val revelation : ?fee:Tez.t -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> - ?counter:counter -> + ?counter:Manager_counter.t -> ?forge_pkh:public_key_hash option -> Context.t -> public_key -> @@ -282,7 +282,7 @@ val activation : val combine_operations : ?public_key:public_key -> - ?counter:counter -> + ?counter:Manager_counter.t -> ?spurious_operation:packed_operation -> source:Contract.t -> Context.t -> @@ -486,7 +486,7 @@ val tx_rollup_remove_commitment : yet. Disabled (set to [false]) by default.}} *) val tx_rollup_dispatch_tickets : ?force_reveal:bool -> - ?counter:counter -> + ?counter:Manager_counter.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -526,7 +526,7 @@ val tx_rollup_dispatch_tickets : yet. Disabled (set to [false]) by default.}} *) val transfer_ticket : ?force_reveal:bool -> - ?counter:counter -> + ?counter:Manager_counter.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -605,7 +605,7 @@ val tx_rollup_reject : yet. Disabled (set to [false]) by default.}} *) val sc_rollup_origination : ?force_reveal:bool -> - ?counter:counter -> + ?counter:Manager_counter.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -659,7 +659,7 @@ val sc_rollup_cement : Operation.packed tzresult Lwt.t val sc_rollup_execute_outbox_message : - ?counter:counter -> + ?counter:Manager_counter.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -721,7 +721,7 @@ val sc_rollup_timeout : val dal_publish_slot_header : ?force_reveal:bool -> - ?counter:counter -> + ?counter:Manager_counter.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -750,7 +750,7 @@ val zk_rollup_origination : val update_consensus_key : ?force_reveal:bool -> - ?counter:counter -> + ?counter:Manager_counter.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> ?storage_limit:Z.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 8bacf024020b..43358e5ce602 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 @@ -108,7 +108,7 @@ type manager_operation_kind = (** The requirements for a tested manager operation. *) type operation_req = { kind : manager_operation_kind; - counter : counter option; + counter : Manager_counter.t option; fee : Tez.t option; gas_limit : Op.gas_limit option; storage_limit : Z.t option; @@ -426,7 +426,7 @@ let fund_account_op block bootstrap account fund counter = let fund_account block bootstrap account fund = let open Lwt_result_syntax in let* counter = Context.Contract.counter (B block) bootstrap in - let* operation, (_counter : counter) = + let* operation, (_counter : Manager_counter.t) = fund_account_op block bootstrap account fund counter in let*! b = Block.bake ~operation block in diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 83414ab00446..cc7a856b66de 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2135,7 +2135,7 @@ module Manager = struct let rec check_batch_tail_sanity : type kind. public_key_hash -> - counter -> + Manager_counter.t -> kind Kind.manager contents_list -> unit tzresult = fun expected_source previous_counter -> function @@ -2163,7 +2163,7 @@ module Manager = struct let check_batch : type kind. kind Kind.manager contents_list -> - (public_key_hash * public_key option * counter) tzresult = + (public_key_hash * public_key option * Manager_counter.t) tzresult = fun contents_list -> match contents_list with | Single (Manager_operation {source; operation = Reveal key; counter; _}) -- GitLab From d784491462bda5e667a916c0e5f260fde4813add Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 16:07:46 +0200 Subject: [PATCH 03/17] Proto: use Manager_counter.t rather than Z.t --- .../lib_client/annotated_manager_operation.ml | 2 +- .../annotated_manager_operation.mli | 2 +- .../lib_client/client_proto_args.mli | 2 +- .../lib_client/client_proto_context.mli | 26 +++++------ .../lib_client/client_proto_fa12.mli | 2 +- .../lib_client/client_proto_multisig.mli | 4 +- src/proto_alpha/lib_client/injection.ml | 2 +- src/proto_alpha/lib_client/injection.mli | 2 +- .../client_proto_stresstest_commands.ml | 2 +- src/proto_alpha/lib_injector/injector_sigs.ml | 2 +- .../lib_protocol/alpha_context.mli | 5 +- .../lib_protocol/contract_storage.ml | 8 ++-- .../lib_protocol/contract_storage.mli | 17 ++++--- src/proto_alpha/lib_protocol/storage.ml | 3 +- .../lib_protocol/test/helpers/context.mli | 2 +- .../lib_protocol/test/helpers/op.mli | 46 +++++++++---------- 16 files changed, 67 insertions(+), 60 deletions(-) diff --git a/src/proto_alpha/lib_client/annotated_manager_operation.ml b/src/proto_alpha/lib_client/annotated_manager_operation.ml index 96ce163f5295..7aa1a7fc7080 100644 --- a/src/proto_alpha/lib_client/annotated_manager_operation.ml +++ b/src/proto_alpha/lib_client/annotated_manager_operation.ml @@ -33,7 +33,7 @@ type _ t = fee : Tez.t Limit.t; gas_limit : Gas.Arith.integral Limit.t; storage_limit : Z.t Limit.t; - counter : Z.t option; + counter : Manager_counter.t option; operation : 'kind manager_operation; } -> 'kind t diff --git a/src/proto_alpha/lib_client/annotated_manager_operation.mli b/src/proto_alpha/lib_client/annotated_manager_operation.mli index db6e868a01c1..0fc7a472f842 100644 --- a/src/proto_alpha/lib_client/annotated_manager_operation.mli +++ b/src/proto_alpha/lib_client/annotated_manager_operation.mli @@ -36,7 +36,7 @@ type _ t = fee : Tez.t Limit.t; gas_limit : Gas.Arith.integral Limit.t; storage_limit : Z.t Limit.t; - counter : Z.t option; + counter : Manager_counter.t option; operation : 'kind manager_operation; } -> 'kind t diff --git a/src/proto_alpha/lib_client/client_proto_args.mli b/src/proto_alpha/lib_client/client_proto_args.mli index c0a0f0a488ab..79ffb8507940 100644 --- a/src/proto_alpha/lib_client/client_proto_args.mli +++ b/src/proto_alpha/lib_client/client_proto_args.mli @@ -36,7 +36,7 @@ val fee_arg : (Tez.t option, full) Tezos_clic.arg val default_fee_arg : (Tez.t option, full) Tezos_clic.arg -val counter_arg : (Z.t option, full) Tezos_clic.arg +val counter_arg : (Manager_counter.t option, full) Tezos_clic.arg val gas_limit_arg : (Gas.Arith.integral option, full) Tezos_clic.arg diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index 76f034f3ddb4..17e25123bc71 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -80,7 +80,7 @@ val register_global_constant : ?fee:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> @@ -336,7 +336,7 @@ val transfer_with_script : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> fee_parameter:Injection.fee_parameter -> ?replace_by_fees:bool -> unit -> @@ -370,7 +370,7 @@ val transfer : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> fee_parameter:Injection.fee_parameter -> ?replace_by_fees:bool -> unit -> @@ -580,7 +580,7 @@ val originate_tx_rollup : ?fee:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> @@ -604,7 +604,7 @@ val submit_tx_rollup_batch : ?burn_limit:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> @@ -629,7 +629,7 @@ val submit_tx_rollup_commitment : ?fee:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> @@ -657,7 +657,7 @@ val submit_tx_rollup_finalize_commitment : ?fee:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> @@ -682,7 +682,7 @@ val submit_tx_rollup_remove_commitment : ?fee:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> @@ -706,7 +706,7 @@ val submit_tx_rollup_rejection : ?fee:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> @@ -740,7 +740,7 @@ val submit_tx_rollup_return_bond : ?fee:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> @@ -764,7 +764,7 @@ val tx_rollup_dispatch_tickets : ?fee:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> @@ -793,7 +793,7 @@ val transfer_ticket : ?fee:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> @@ -951,7 +951,7 @@ val sc_rollup_recover_bond : ?fee:Tez.tez -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> source:Signature.public_key_hash -> src_pk:Signature.public_key -> src_sk:Client_keys.sk_uri -> diff --git a/src/proto_alpha/lib_client/client_proto_fa12.mli b/src/proto_alpha/lib_client/client_proto_fa12.mli index 01eada3c5951..cfd100f44a46 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.mli +++ b/src/proto_alpha/lib_client/client_proto_fa12.mli @@ -106,7 +106,7 @@ val call_contract : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> fee_parameter:Injection.fee_parameter -> unit -> (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) diff --git a/src/proto_alpha/lib_client/client_proto_multisig.mli b/src/proto_alpha/lib_client/client_proto_multisig.mli index bd2f3d746552..5ebfd1448d0f 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.mli +++ b/src/proto_alpha/lib_client/client_proto_multisig.mli @@ -117,7 +117,7 @@ val call_multisig : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> fee_parameter:Injection.fee_parameter -> unit -> (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) @@ -144,7 +144,7 @@ val call_multisig_on_bytes : ?fee:Tez.t -> ?gas_limit:Gas.Arith.integral -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> fee_parameter:Injection.fee_parameter -> unit -> (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index bec0a6116392..d9ff4388c96f 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -1398,7 +1398,7 @@ let inject_manager_operation cctxt ~chain ~block ?successor_level ?branch in let rec build_contents : type kind. - Z.t -> + Manager_counter.t -> kind Annotated_manager_operation.annotated_list -> kind Annotated_manager_operation.annotated_list tzresult = fun counter -> function diff --git a/src/proto_alpha/lib_client/injection.mli b/src/proto_alpha/lib_client/injection.mli index 6275db8033e1..d66775157c80 100644 --- a/src/proto_alpha/lib_client/injection.mli +++ b/src/proto_alpha/lib_client/injection.mli @@ -109,7 +109,7 @@ val inject_manager_operation : fee:Tez.t Limit.t -> gas_limit:Gas.Arith.integral Limit.t -> storage_limit:Z.t Limit.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?replace_by_fees:bool -> fee_parameter:fee_parameter -> 'kind Annotated_manager_operation.annotated_list -> diff --git a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml index 140d2ab47d8a..11ab79390d1d 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml @@ -94,7 +94,7 @@ type transfer = { fee : Tez.t; gas_limit : Gas.Arith.integral; amount : Tez.t; - counter : Z.t option; + counter : Manager_counter.t option; fresh_dst : bool; } diff --git a/src/proto_alpha/lib_injector/injector_sigs.ml b/src/proto_alpha/lib_injector/injector_sigs.ml index 29bd400af406..d9c56fda0736 100644 --- a/src/proto_alpha/lib_injector/injector_sigs.ml +++ b/src/proto_alpha/lib_injector/injector_sigs.ml @@ -29,7 +29,7 @@ open Protocol.Alpha_context to compute an upper bound on the size (in bytes) of an operation. *) type approximate_fee_bound = { fee : Tez.t; - counter : Z.t; + counter : Manager_counter.t; gas_limit : Gas.Arith.integral; storage_limit : Z.t; } diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 153af43bcb75..316e673f586a 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1669,12 +1669,13 @@ module Contract : sig public_key -> context tzresult Lwt.t - val get_counter : context -> public_key_hash -> Z.t tzresult Lwt.t + val get_counter : + context -> public_key_hash -> Manager_counter.t tzresult Lwt.t val increment_counter : context -> public_key_hash -> context tzresult Lwt.t val check_counter_increment : - context -> public_key_hash -> Z.t -> unit tzresult Lwt.t + context -> public_key_hash -> Manager_counter.t -> unit tzresult Lwt.t (** See {!Contract_storage.check_allocated_and_get_balance}. *) val check_allocated_and_get_balance : diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 1368f75f7aeb..9f3eb7b1ee96 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -30,14 +30,14 @@ type error += | (* `Temporary *) Counter_in_the_past of { contract : Contract_repr.t; - expected : Z.t; - found : Z.t; + expected : Manager_counter_repr.t; + found : Manager_counter_repr.t; } | (* `Branch *) Counter_in_the_future of { contract : Contract_repr.t; - expected : Z.t; - found : Z.t; + expected : Manager_counter_repr.t; + found : Manager_counter_repr.t; } | (* `Temporary *) Non_existing_contract of Contract_repr.t diff --git a/src/proto_alpha/lib_protocol/contract_storage.mli b/src/proto_alpha/lib_protocol/contract_storage.mli index e553be045895..23c062aad53b 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.mli +++ b/src/proto_alpha/lib_protocol/contract_storage.mli @@ -32,14 +32,14 @@ type error += | (* `Temporary *) Counter_in_the_past of { contract : Contract_repr.t; - expected : Z.t; - found : Z.t; + expected : Manager_counter_repr.t; + found : Manager_counter_repr.t; } | (* `Branch *) Counter_in_the_future of { contract : Contract_repr.t; - expected : Z.t; - found : Z.t; + expected : Manager_counter_repr.t; + found : Manager_counter_repr.t; } | (* `Temporary *) Non_existing_contract of Contract_repr.t @@ -80,7 +80,10 @@ val must_be_allocated : Raw_context.t -> Contract_repr.t -> unit tzresult Lwt.t val list : Raw_context.t -> Contract_repr.t list Lwt.t val check_counter_increment : - Raw_context.t -> Signature.Public_key_hash.t -> Z.t -> unit tzresult Lwt.t + Raw_context.t -> + Signature.Public_key_hash.t -> + Manager_counter_repr.t -> + unit tzresult Lwt.t val increment_counter : Raw_context.t -> Signature.Public_key_hash.t -> Raw_context.t tzresult Lwt.t @@ -107,7 +110,9 @@ val check_allocated_and_get_balance : Raw_context.t -> Signature.public_key_hash -> Tez_repr.t tzresult Lwt.t val get_counter : - Raw_context.t -> Signature.Public_key_hash.t -> Z.t tzresult Lwt.t + Raw_context.t -> + Signature.Public_key_hash.t -> + Manager_counter_repr.t tzresult Lwt.t val get_script_code : Raw_context.t -> diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index f75a7e0216f4..dd40fb5e1235 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -169,7 +169,8 @@ module Contract = struct let name = ["contracts"] end) - module Global_counter : Simple_single_data_storage with type value = Z.t = + module Global_counter : + Simple_single_data_storage with type value = Manager_counter_repr.t = Make_single_data_storage (Registered) (Raw_context) (struct let name = ["global_counter"] diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index 6d6e1d44f703..22366748fc54 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/context.mli @@ -161,7 +161,7 @@ module Contract : sig val balance_and_frozen_bonds : t -> Contract.t -> Tez.t tzresult Lwt.t - val counter : t -> Contract.t -> Z.t tzresult Lwt.t + val counter : t -> Contract.t -> Manager_counter.t tzresult Lwt.t val manager : t -> Contract.t -> Account.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.mli b/src/proto_alpha/lib_protocol/test/helpers/op.mli index ae351b713ab4..4b9df5708427 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/op.mli @@ -96,7 +96,7 @@ val pp_gas_limit : Format.formatter -> gas_limit -> unit val transaction : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -139,7 +139,7 @@ val delegation : ?force_reveal:bool -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?storage_limit:Z.t -> Context.t -> Contract.t -> @@ -151,7 +151,7 @@ val set_deposits_limit : ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> Context.t -> Contract.t -> Tez.tez option -> @@ -159,7 +159,7 @@ val set_deposits_limit : val increase_paid_storage : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -214,7 +214,7 @@ val failing_noop : yet. Disabled (set to [false]) by default.}} *) val contract_origination : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?delegate:public_key_hash -> script:Script.t -> ?public_key:public_key -> @@ -228,7 +228,7 @@ val contract_origination : val contract_origination_hash : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?delegate:public_key_hash -> script:Script.t -> ?public_key:public_key -> @@ -244,7 +244,7 @@ val originated_contract : Operation.packed -> Contract.t val register_global_constant : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?public_key:Signature.public_key -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> @@ -372,7 +372,7 @@ val dummy_script_cost : Tez.t hash. *) val tx_rollup_origination : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -391,7 +391,7 @@ val tx_rollup_origination : yet. Disabled (set to [false]) by default.}} *) val tx_rollup_submit_batch : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?burn_limit:Tez.tez -> ?gas_limit:gas_limit -> @@ -412,7 +412,7 @@ val tx_rollup_submit_batch : yet. Disabled (set to [false]) by default.}} *) val tx_rollup_commit : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -432,7 +432,7 @@ val tx_rollup_commit : yet. Disabled (set to [false]) by default..}} *) val tx_rollup_return_bond : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -451,7 +451,7 @@ val tx_rollup_return_bond : yet. Disabled (set to [false]) by default.}} *) val tx_rollup_finalize : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -464,7 +464,7 @@ val tx_rollup_finalize : remove a commitment from the rollup context. *) val tx_rollup_remove_commitment : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -547,7 +547,7 @@ val transfer_ticket : protocol. *) val tx_rollup_raw_reject : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -575,7 +575,7 @@ val tx_rollup_raw_reject : yet. Disabled (set to [false]) by default.}} *) val tx_rollup_reject : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -628,7 +628,7 @@ val sc_rollup_origination : yet. Disabled (set to [false]) by default.}} *) val sc_rollup_publish : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -648,7 +648,7 @@ val sc_rollup_publish : yet. Disabled (set to [false]) by default.}} *) val sc_rollup_cement : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -673,7 +673,7 @@ val sc_rollup_execute_outbox_message : (** [sc_rollup_recover_bond ctxt source sc_rollup] returns a commitment bond. *) val sc_rollup_recover_bond : - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -685,7 +685,7 @@ val sc_rollup_recover_bond : val sc_rollup_add_messages : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -696,7 +696,7 @@ val sc_rollup_add_messages : val sc_rollup_refute : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -709,7 +709,7 @@ val sc_rollup_refute : val sc_rollup_timeout : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.tez -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -734,7 +734,7 @@ val dal_publish_slot_header : ~init_state ~nb_ops] tries to originate a ZK Rollup. *) val zk_rollup_origination : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> @@ -770,7 +770,7 @@ val drain_delegate : to the pending list of a ZK Rollup. *) val zk_rollup_publish : ?force_reveal:bool -> - ?counter:Z.t -> + ?counter:Manager_counter.t -> ?fee:Tez.t -> ?gas_limit:gas_limit -> ?storage_limit:Z.t -> -- GitLab From 6da30b156fd2a30ee8c8646a14b45c3c1d1fbdfa Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 20 Oct 2022 12:32:25 +0200 Subject: [PATCH 04/17] Proto/Manager_counter: add init --- src/proto_alpha/lib_protocol/contract_storage.ml | 2 +- src/proto_alpha/lib_protocol/manager_counter_repr.ml | 2 ++ src/proto_alpha/lib_protocol/manager_counter_repr.mli | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 9f3eb7b1ee96..3c01325f841e 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -634,7 +634,7 @@ let credit_only_call_from_token c contract amount = Stake_storage.add_contract_stake c contract amount let init c = - Storage.Contract.Global_counter.init c Z.zero >>=? fun c -> + Storage.Contract.Global_counter.init c Manager_counter_repr.init >>=? fun c -> Lazy_storage_diff.init c let used_storage_space c contract = diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index 4193acad5a18..0c5277e4bee6 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -25,3 +25,5 @@ (*****************************************************************************) type t = Z.t + +let init = Z.zero diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index 4af5ccbc9792..d4d4fbe54f0e 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -30,3 +30,6 @@ a manager operation is applied, the value of the counter of its manager is checked and incremented. *) type t = Z.t + +(** Initial value for a counter (zero). *) +val init : t -- GitLab From 931f5741beb1261975dc0c65182910aa83ef759d Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 16:01:24 +0200 Subject: [PATCH 05/17] Proto/Manager_counter: add succ --- src/proto_alpha/lib_client/injection.ml | 6 ++-- .../client_proto_stresstest_commands.ml | 8 ++--- .../lib_protocol/alpha_context.mli | 2 ++ .../lib_protocol/contract_storage.ml | 12 +++++-- .../lib_protocol/manager_counter_repr.ml | 2 ++ .../lib_protocol/manager_counter_repr.mli | 3 ++ .../lib_protocol/test/helpers/op.ml | 16 ++++----- .../integration/operations/test_tx_rollup.ml | 9 +++-- .../validate/generator_descriptors.ml | 3 +- .../validate/manager_operation_helpers.ml | 2 +- .../validate/test_validation_batch.ml | 34 +++++++++---------- src/proto_alpha/lib_protocol/validate.ml | 2 +- 12 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index d9ff4388c96f..a05bf5079bda 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -1375,7 +1375,7 @@ let inject_manager_operation cctxt ~chain ~block ?successor_level ?branch | None -> Alpha_services.Contract.counter cctxt (chain, block) source >>=? fun pcounter -> - let counter = Z.succ pcounter in + let counter = Manager_counter.succ pcounter in return counter | Some counter -> return counter) >>=? fun counter -> @@ -1407,7 +1407,7 @@ let inject_manager_operation cctxt ~chain ~block ?successor_level ?branch Annotated_manager_operation.Single_manager op | Cons_manager (op, rest) -> apply_specified_options counter op >>? fun op -> - build_contents (Z.succ counter) rest >|? fun rest -> + build_contents (Manager_counter.succ counter) rest >|? fun rest -> Annotated_manager_operation.Cons_manager (op, rest) in match key with @@ -1425,7 +1425,7 @@ let inject_manager_operation cctxt ~chain ~block ?successor_level ?branch in Annotated_manager_operation.set_source source reveal >>?= fun reveal -> Annotated_manager_operation.set_counter counter reveal >>?= fun reveal -> - build_contents (Z.succ counter) operations >>?= fun rest -> + build_contents (Manager_counter.succ counter) operations >>?= fun rest -> let contents = Annotated_manager_operation.Cons_manager (reveal, rest) in may_patch_limits cctxt diff --git a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml index 11ab79390d1d..39bcbc38a63a 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml @@ -570,8 +570,8 @@ let inject_transfer (cctxt : Protocol_client_context.full) parameters state in let*! r = if not already_revealed then - let reveal_counter = Z.succ current_counter in - let transf_counter = Z.succ reveal_counter in + let reveal_counter = Manager_counter.succ current_counter in + let transf_counter = Manager_counter.succ reveal_counter in let reveal = Manager_operation { @@ -608,7 +608,7 @@ let inject_transfer (cctxt : Protocol_client_context.full) parameters state all the operations we injected. *) inject_contents cctxt state.target_block transfer.src.sk list else - let transf_counter = Z.succ current_counter in + let transf_counter = Manager_counter.succ current_counter in let manager_op = manager_op_of_transfer parameters @@ -1274,7 +1274,7 @@ let estimate_transaction_cost ?smart_contracts let* current_counter = Alpha_services.Contract.counter cctxt (chain, block) src.source.pkh in - let transf_counter = Z.succ current_counter in + let transf_counter = Manager_counter.succ current_counter in let transfer = { src = src.source; diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 316e673f586a..639f48860d1e 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1600,6 +1600,8 @@ end (** This module re-exports definitions from {!Manager_counter_repr}. *) module Manager_counter : sig type t = Z.t + + val succ : t -> t end (** This module re-exports definitions from {!Contract_repr} and diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 3c01325f841e..6d27227ceced 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -504,7 +504,7 @@ let originated_from_current_nonce ~since:ctxt_since ~until:ctxt_until = let check_counter_increment c manager counter = let contract = Contract_repr.Implicit manager in Storage.Contract.Counter.get c contract >>=? fun contract_counter -> - let expected = Z.succ contract_counter in + let expected = Manager_counter_repr.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; found = counter}) @@ -513,9 +513,15 @@ let check_counter_increment c manager counter = let increment_counter c manager = let contract = Contract_repr.Implicit manager in Storage.Contract.Global_counter.get c >>=? fun global_counter -> - Storage.Contract.Global_counter.update c (Z.succ global_counter) >>=? fun c -> + Storage.Contract.Global_counter.update + c + (Manager_counter_repr.succ global_counter) + >>=? fun c -> Storage.Contract.Counter.get c contract >>=? fun contract_counter -> - Storage.Contract.Counter.update c contract (Z.succ contract_counter) + Storage.Contract.Counter.update + c + contract + (Manager_counter_repr.succ contract_counter) let get_script_code c contract_hash = let contract = Contract_repr.Originated contract_hash in diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index 0c5277e4bee6..39824a6fc4c8 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -27,3 +27,5 @@ type t = Z.t let init = Z.zero + +let succ = Z.succ diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index d4d4fbe54f0e..77e050494a16 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -33,3 +33,6 @@ type t = Z.t (** Initial value for a counter (zero). *) val init : t + +(** Successor of a counter. *) +val succ : t -> t diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index 134d1d8ba66a..77943cf89680 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -139,10 +139,10 @@ let batch_operations ?(recompute_counters = false) ~source ctxt List.fold_left (fun (counter, acc) -> function | Contents (Manager_operation m) -> - ( Z.succ counter, + ( Manager_counter.succ counter, Contents (Manager_operation {m with counter}) :: acc ) | x -> (counter, x :: acc)) - (Z.succ counter, []) + (Manager_counter.succ counter, []) operations in return (List.rev rev_operations) @@ -211,7 +211,7 @@ let combine_operations ?public_key ?counter ?spurious_operation ~source ctxt | None -> Context.Contract.counter ctxt source) >>=? fun counter -> (* We increment the counter *) - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in Context.Contract.manager ctxt source >>=? fun account -> let public_key = Option.value ~default:account.pk public_key in (Context.Contract.is_manager_key_revealed ctxt source >|=? function @@ -227,7 +227,7 @@ let combine_operations ?public_key ?counter ?spurious_operation ~source ctxt storage_limit = Z.zero; } in - (Some (Contents reveal_op), Z.succ counter) + (Some (Contents reveal_op), Manager_counter.succ counter) | true -> (None, counter)) >>=? fun (manager_op, counter) -> (* Update counters and transform into a contents_list *) @@ -235,7 +235,7 @@ let combine_operations ?public_key ?counter ?spurious_operation ~source ctxt List.fold_left (fun (counter, acc) -> function | Contents (Manager_operation m) -> - ( Z.succ counter, + ( Manager_counter.succ counter, Contents (Manager_operation {m with counter}) :: acc ) | x -> (counter, x :: acc)) (counter, match manager_op with None -> [] | Some op -> [op]) @@ -280,7 +280,7 @@ let manager_operation ?(force_reveal = false) ?counter ?(fee = Tez.zero) resolve_gas_limit ctxt gas_limit >>=? fun gas_limit -> Context.Contract.manager ctxt source >>=? fun account -> let public_key = Option.value ~default:account.pk public_key in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in Context.Contract.is_manager_key_revealed ctxt source >|=? fun revealed -> (* If the manager is revealed or we are not forcing reveals, we generate a singleton manager operation. *) @@ -317,7 +317,7 @@ let manager_operation ?(force_reveal = false) ?counter ?(fee = Tez.zero) { source = Signature.Public_key.hash public_key; fee; - counter = Z.succ counter; + counter = Manager_counter.succ counter; operation; gas_limit; storage_limit; @@ -343,7 +343,7 @@ let revelation ?(fee = Tez.zero) ?(gas_limit = High) ?(storage_limit = Z.zero) | Some ctr -> return ctr) >>=? fun counter -> Context.Contract.manager ctxt source >|=? fun account -> - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let sop = Contents_list (Single diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml index fb6d287d1974..3978a100f907 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml @@ -874,7 +874,7 @@ let test_add_two_batches () = Context.Contract.counter (B b) contract >>=? fun counter -> let contents2 = "batch2" in Op.tx_rollup_submit_batch - ~counter:Z.(add counter (of_int 1)) + ~counter:Manager_counter.(succ counter) (B b) contract tx_rollup @@ -954,7 +954,10 @@ let fill_inbox b tx_rollup contract contents k = >>=? fun operation -> let new_inbox_size = inbox_size + message_size in if new_inbox_size < tx_rollup_inbox_limit then - fill_inbox new_inbox_size (Z.succ counter) (operation :: operations) + fill_inbox + new_inbox_size + (Manager_counter.succ counter) + (operation :: operations) else Incremental.begin_construction b >>=? fun i -> k i inbox_size (operation, operations) @@ -1023,7 +1026,7 @@ let test_inbox_count_too_big () = (B b) [batch; op]) >>=? fun op -> - if n > 0 then fill_inbox b (Z.succ counter) (n - 1) (Some op) + if n > 0 then fill_inbox b (Manager_counter.succ counter) (n - 1) (Some op) else return (op, counter) in Context.Contract.counter (B b) contract >>=? fun counter -> diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml b/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml index 712a0a7554fc..14c622a5fd6e 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml @@ -705,7 +705,8 @@ let manager_prelude (infos : Manager.infos) b = let add bootstrap counter ops ops_by_bootstrap = List.map (fun (bootstrap', counter', ops') -> - if bootstrap' = bootstrap then (bootstrap, Z.succ counter, ops) + if bootstrap' = bootstrap then + (bootstrap, Manager_counter.succ counter, ops) else (bootstrap', counter', ops')) ops_by_bootstrap in 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 43358e5ce602..7cca6d144056 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 @@ -421,7 +421,7 @@ let fund_account_op block bootstrap account fund counter = (Contract.Implicit account) fund in - (op, Z.succ counter) + (op, Manager_counter.succ counter) let fund_account block bootstrap account fund = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/test_validation_batch.ml b/src/proto_alpha/lib_protocol/test/integration/validate/test_validation_batch.ml index beff404e811f..ba364f0dc2f4 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/test_validation_batch.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/test_validation_batch.ml @@ -63,7 +63,7 @@ let batch_in_the_middle infos kind1 kind2 = (B infos.ctxt.block) (contract_of (get_source infos)) in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let* operation1 = select_op { @@ -73,7 +73,7 @@ let batch_in_the_middle infos kind1 kind2 = } infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let* reveal = mk_reveal { @@ -83,7 +83,7 @@ let batch_in_the_middle infos kind1 kind2 = } infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let* operation2 = select_op { @@ -126,7 +126,7 @@ let batch_two_reveals infos kind = (B infos.ctxt.block) (contract_of (get_source infos)) in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let* reveal = mk_reveal { @@ -136,7 +136,7 @@ let batch_two_reveals infos kind = } infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let* reveal1 = mk_reveal { @@ -146,7 +146,7 @@ let batch_two_reveals infos kind = } infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let* operation = select_op { @@ -184,7 +184,7 @@ let batch_two_sources infos kind1 kind2 = let open Lwt_result_syntax in let source = contract_of (get_source infos) in let* counter = Context.Contract.counter (B infos.ctxt.block) source in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let* operation1 = select_op { @@ -225,9 +225,9 @@ let batch_incons_counters infos kind1 kind2 = let op_infos = {{op_infos with fee} with counter = Some counter} in let* reveal = mk_reveal op_infos infos in let counter0 = counter in - let counter = Z.succ counter in - let counter2 = Z.succ counter in - let counter3 = Z.succ counter2 in + let counter = Manager_counter.succ counter in + let counter2 = Manager_counter.succ counter in + let counter3 = Manager_counter.succ counter2 in let operation counter kind = select_op { @@ -328,7 +328,7 @@ let batch_emptying_balance_in_the_middle infos kind1 kind2 = {(operation_req_default K_Reveal) with counter = Some counter} infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let operation fee = select_op { @@ -339,7 +339,7 @@ let batch_emptying_balance_in_the_middle infos kind1 kind2 = } infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let operation2 fee = select_op { @@ -389,7 +389,7 @@ let batch_empty_at_end infos kind1 kind2 = {(operation_req_default K_Reveal) with counter = Some counter} infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let operation fee = select_op { @@ -400,7 +400,7 @@ let batch_empty_at_end infos kind1 kind2 = } infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let operation2 fee = select_op { @@ -449,7 +449,7 @@ let batch_reveal_transaction infos = } infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let* transaction = mk_transaction { @@ -484,7 +484,7 @@ let batch_exceeding_block_gas ~mempool_mode infos kind1 kind2 = {(operation_req_default K_Reveal) with counter = Some counter} infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let operation gas_limit = select_op { @@ -495,7 +495,7 @@ let batch_exceeding_block_gas ~mempool_mode infos kind1 kind2 = } infos in - let counter = Z.succ counter in + let counter = Manager_counter.succ counter in let operation2 gas_limit = select_op { diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index cc7a856b66de..1128d0ca64ef 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2129,7 +2129,7 @@ module Manager = struct Inconsistent_sources in error_unless - Compare.Z.(Z.succ previous_counter = counter) + Compare.Z.(Manager_counter.succ previous_counter = counter) Inconsistent_counters in let rec check_batch_tail_sanity : -- GitLab From 0b62912ead60f39bb19fe9b05c4d67daac656b24 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 16:00:03 +0200 Subject: [PATCH 06/17] Proto/Manager_counter: add comparison --- src/proto_alpha/lib_delegate/operation_selection.ml | 2 +- src/proto_alpha/lib_protocol/alpha_context.mli | 2 ++ src/proto_alpha/lib_protocol/contract_storage.ml | 4 ++-- src/proto_alpha/lib_protocol/manager_counter_repr.ml | 2 +- src/proto_alpha/lib_protocol/manager_counter_repr.mli | 2 ++ .../test/integration/validate/manager_operation_helpers.ml | 2 +- src/proto_alpha/lib_protocol/validate.ml | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_delegate/operation_selection.ml b/src/proto_alpha/lib_delegate/operation_selection.ml index bd4b069b980d..9a4fbf4d0b92 100644 --- a/src/proto_alpha/lib_delegate/operation_selection.ml +++ b/src/proto_alpha/lib_delegate/operation_selection.ml @@ -60,7 +60,7 @@ module PrioritizedManagerSet = Set.Make (struct let cmp_src = Signature.Public_key_hash.compare source source' in if cmp_src = 0 then (* we want the smallest counter first *) - let c = Z.compare counter counter' in + let c = Manager_counter.compare counter counter' in if c <> 0 then c else let c = Prioritized_operation.compare_priority op' op in diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 639f48860d1e..d3ee65c212f7 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1601,6 +1601,8 @@ end module Manager_counter : sig type t = Z.t + include Compare.S with type t := t + val succ : t -> t end diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 6d27227ceced..8c04cc3080d3 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -505,8 +505,8 @@ let check_counter_increment c manager counter = let contract = Contract_repr.Implicit manager in Storage.Contract.Counter.get c contract >>=? fun contract_counter -> let expected = Manager_counter_repr.succ contract_counter in - if Compare.Z.(expected = counter) then return_unit - else if Compare.Z.(expected > counter) then + if Manager_counter_repr.(expected = counter) then return_unit + else if Manager_counter_repr.(expected > counter) then fail (Counter_in_the_past {contract; expected; found = counter}) else fail (Counter_in_the_future {contract; expected; found = counter}) diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index 39824a6fc4c8..ded1aa1d5ca6 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -24,7 +24,7 @@ (* *) (*****************************************************************************) -type t = Z.t +include Compare.Z let init = Z.zero diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index 77e050494a16..f42479557c20 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -31,6 +31,8 @@ its manager is checked and incremented. *) type t = Z.t +include Compare.S with type t := t + (** Initial value for a counter (zero). *) val init : 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 7cca6d144056..026ffcd36c6e 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 @@ -1385,7 +1385,7 @@ let observe ~only_validate ~mode ctxt_pre ctxt_post op = let* () = b_cmp b_out b_expected in let _ = Assert.equal - Z.equal + Manager_counter.equal ~loc:__LOC__ "Counter incrementation" Z.pp_print diff --git a/src/proto_alpha/lib_protocol/validate.ml b/src/proto_alpha/lib_protocol/validate.ml index 1128d0ca64ef..bf3b54d7aa63 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2129,7 +2129,7 @@ module Manager = struct Inconsistent_sources in error_unless - Compare.Z.(Manager_counter.succ previous_counter = counter) + Manager_counter.(succ previous_counter = counter) Inconsistent_counters in let rec check_batch_tail_sanity : -- GitLab From d4df92d4c5892b9d4972bc4028a41b2512997a84 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 17:28:00 +0200 Subject: [PATCH 07/17] Proto/Manager_counter: add pp --- src/proto_alpha/lib_client/operation_result.ml | 2 +- .../client_proto_stresstest_commands.ml | 6 +++--- src/proto_alpha/lib_protocol/alpha_context.mli | 2 ++ src/proto_alpha/lib_protocol/contract_storage.ml | 8 ++++---- src/proto_alpha/lib_protocol/manager_counter_repr.ml | 2 ++ src/proto_alpha/lib_protocol/manager_counter_repr.mli | 3 +++ .../integration/validate/manager_operation_helpers.ml | 4 ++-- 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index 0c95c2b04f09..f0fc58ae6947 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -995,7 +995,7 @@ let pp_manager_operation_result ppf Format.fprintf ppf "@[Manager signed operations:" ; Format.fprintf ppf "@,From: %a" Signature.Public_key_hash.pp source ; Format.fprintf ppf "@,Fee to the baker: %s%a" tez_sym Tez.pp fee ; - Format.fprintf ppf "@,Expected counter: %a" Z.pp_print counter ; + Format.fprintf ppf "@,Expected counter: %a" Manager_counter.pp counter ; Format.fprintf ppf "@,Gas limit: %a" Gas.Arith.pp_integral gas_limit ; Format.fprintf ppf "@,Storage limit: %a bytes" Z.pp_print storage_limit ; pp_balance_updates ppf balance_updates ; diff --git a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml index 39bcbc38a63a..8b81d1661024 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml @@ -595,9 +595,9 @@ let inject_transfer (cctxt : Protocol_client_context.full) parameters state "injecting reveal+transfer from %a (counters=%a,%a) to %a" Signature.Public_key_hash.pp transfer.src.pkh - Z.pp_print + Manager_counter.pp reveal_counter - Z.pp_print + Manager_counter.pp transf_counter Contract.pp (destination_to_contract transfer.dst)) @@ -621,7 +621,7 @@ let inject_transfer (cctxt : Protocol_client_context.full) parameters state "injecting transfer from %a (counter=%a) to %a" Signature.Public_key_hash.pp transfer.src.pkh - Z.pp_print + Manager_counter.pp transf_counter Contract.pp (destination_to_contract transfer.dst)) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index d3ee65c212f7..e0775166ddd3 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1604,6 +1604,8 @@ module Manager_counter : sig include Compare.S with type t := t val succ : t -> t + + val pp : Format.formatter -> t -> unit end (** This module re-exports definitions from {!Contract_repr} and diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 8c04cc3080d3..6e3fd6c189a9 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -88,11 +88,11 @@ let () = Format.fprintf ppf "Counter %a not yet reached for contract %a (expected %a)" - Z.pp_print + Manager_counter_repr.pp found Contract_repr.pp contract - Z.pp_print + Manager_counter_repr.pp exp) Data_encoding.( obj3 @@ -114,11 +114,11 @@ let () = Format.fprintf ppf "Counter %a already used for contract %a (expected %a)" - Z.pp_print + Manager_counter_repr.pp found Contract_repr.pp contract - Z.pp_print + Manager_counter_repr.pp exp) Data_encoding.( obj3 diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index ded1aa1d5ca6..f1cd2c1f863a 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -29,3 +29,5 @@ include Compare.Z let init = Z.zero let succ = Z.succ + +let pp = Z.pp_print diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index f42479557c20..b46a50469f8c 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -38,3 +38,6 @@ val init : t (** Successor of a counter. *) val succ : t -> t + +(** Pretty-printer for counters. *) +val pp : Format.formatter -> t -> unit 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 026ffcd36c6e..9bd1f4004847 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 @@ -226,7 +226,7 @@ let pp_operation_req pp amount: %a@,\ @]" (kind_to_string kind) - (pp_opt Z.pp_print) + (pp_opt Manager_counter.pp) counter (pp_opt Tez.pp) fee @@ -1388,7 +1388,7 @@ let observe ~only_validate ~mode ctxt_pre ctxt_post op = Manager_counter.equal ~loc:__LOC__ "Counter incrementation" - Z.pp_print + Manager_counter.pp c_out c_expected in -- GitLab From c22f2160801f7df7df9497efaf30418653dd8dd4 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 13 Oct 2022 18:59:28 +0200 Subject: [PATCH 08/17] Proto: use Manager_counter in Storage --- src/proto_alpha/lib_protocol/manager_counter_repr.ml | 2 ++ src/proto_alpha/lib_protocol/manager_counter_repr.mli | 3 +++ src/proto_alpha/lib_protocol/storage.ml | 10 ++++++++-- src/proto_alpha/lib_protocol/storage.mli | 5 +++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index f1cd2c1f863a..3db15d9822b8 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -31,3 +31,5 @@ let init = Z.zero let succ = Z.succ let pp = Z.pp_print + +let encoding_for_storage = Data_encoding.z diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index b46a50469f8c..500d335b4de8 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -41,3 +41,6 @@ val succ : t -> t (** Pretty-printer for counters. *) val pp : Format.formatter -> t -> unit + +(** Encoding for a counter to be used in {!Storage}. *) +val encoding_for_storage : t Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index dd40fb5e1235..274acf2e0491 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -51,6 +51,12 @@ module Encoding = struct let encoding = Data_encoding.z end + + module Manager_counter : VALUE with type t = Manager_counter_repr.t = struct + type t = Manager_counter_repr.t + + let encoding = Manager_counter_repr.encoding_for_storage + end end module Int31_index : INDEX with type t = int = struct @@ -175,7 +181,7 @@ module Contract = struct (struct let name = ["global_counter"] end) - (Encoding.Z) + (Encoding.Manager_counter) module Indexed_context = Make_indexed_subcontext @@ -272,7 +278,7 @@ module Contract = struct (struct let name = ["counter"] end) - (Encoding.Z) + (Encoding.Manager_counter) (* Consume gas for serialization and deserialization of expr in this module *) diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 3c545c6b4c66..7e6da9f6dd3d 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -57,7 +57,8 @@ module Contract : sig (** Storage from this submodule must only be accessed through the module `Contract`. *) - module Global_counter : Simple_single_data_storage with type value = Z.t + module Global_counter : + Simple_single_data_storage with type value = Manager_counter_repr.t (** The domain of alive contracts *) val fold : @@ -176,7 +177,7 @@ module Contract : sig module Counter : Indexed_data_storage_with_local_context with type key = Contract_repr.t - and type value = Z.t + and type value = Manager_counter_repr.t and type t := Raw_context.t and type local_context := local_context -- GitLab From ddf0937b35421b202aaaed9ea0c5b543ce31895e Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Fri, 14 Oct 2022 18:22:01 +0200 Subject: [PATCH 09/17] Proto/Manager_coutner: add encoding for RPCs --- src/proto_alpha/lib_protocol/alpha_context.mli | 2 ++ src/proto_alpha/lib_protocol/contract_services.ml | 4 ++-- src/proto_alpha/lib_protocol/manager_counter_repr.ml | 2 ++ src/proto_alpha/lib_protocol/manager_counter_repr.mli | 3 +++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index e0775166ddd3..3fd7acaea982 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1606,6 +1606,8 @@ module Manager_counter : sig val succ : t -> t val pp : Format.formatter -> t -> unit + + val encoding_for_RPCs : t Data_encoding.t end (** This module re-exports definitions from {!Contract_repr} and diff --git a/src/proto_alpha/lib_protocol/contract_services.ml b/src/proto_alpha/lib_protocol/contract_services.ml index 10886275d1ed..0708612f1b4c 100644 --- a/src/proto_alpha/lib_protocol/contract_services.ml +++ b/src/proto_alpha/lib_protocol/contract_services.ml @@ -52,7 +52,7 @@ let info_encoding = (req "balance" Tez.encoding) (opt "delegate" Signature.Public_key_hash.encoding) (opt "script" Script.encoding) - (opt "counter" n) + (opt "counter" Manager_counter.encoding_for_RPCs) let legacy = Script_ir_translator_config.make ~legacy:true () @@ -102,7 +102,7 @@ module S = struct RPC_service.get_service ~description:"Access the counter of a contract, if any." ~query:RPC_query.empty - ~output:z + ~output:Manager_counter.encoding_for_RPCs RPC_path.(custom_root /: Contract.rpc_arg / "counter") let script = diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index 3db15d9822b8..a96607cb39bb 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -33,3 +33,5 @@ let succ = Z.succ let pp = Z.pp_print let encoding_for_storage = Data_encoding.z + +let encoding_for_RPCs = Data_encoding.n diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index 500d335b4de8..4318e5f66bd6 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -44,3 +44,6 @@ val pp : Format.formatter -> t -> unit (** Encoding for a counter to be used in {!Storage}. *) val encoding_for_storage : t Data_encoding.t + +(** Encoding for a counter to be used in RPCs. *) +val encoding_for_RPCs : t Data_encoding.t -- GitLab From 727d6b10371d1d29202af2b9eb0e2436d578e197 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 20 Oct 2022 12:27:06 +0200 Subject: [PATCH 10/17] Proto/Manager_counter: add encoding for operation --- src/proto_alpha/lib_protocol/manager_counter_repr.ml | 2 ++ src/proto_alpha/lib_protocol/manager_counter_repr.mli | 3 +++ src/proto_alpha/lib_protocol/operation_repr.ml | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index a96607cb39bb..ffc4ff00afc5 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -34,4 +34,6 @@ let pp = Z.pp_print let encoding_for_storage = Data_encoding.z +let encoding_for_operation = Data_encoding.(check_size 10 n) + let encoding_for_RPCs = Data_encoding.n diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index 4318e5f66bd6..5363b603df6e 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -45,5 +45,8 @@ val pp : Format.formatter -> t -> unit (** Encoding for a counter to be used in {!Storage}. *) val encoding_for_storage : t Data_encoding.t +(** Encoding for a counter to be used in {!Operation_repr}. *) +val encoding_for_operation : t Data_encoding.t + (** Encoding for a counter to be used in RPCs. *) val encoding_for_RPCs : t Data_encoding.t diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index f538d4fa09bb..44a02137c32c 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -1605,7 +1605,7 @@ module Encoding = struct obj5 (req "source" Signature.Public_key_hash.encoding) (req "fee" Tez_repr.encoding) - (req "counter" (check_size 10 n)) + (req "counter" Manager_counter_repr.encoding_for_operation) (req "gas_limit" (check_size 10 Gas_limit_repr.Arith.n_integral_encoding)) (req "storage_limit" (check_size 10 n)) -- GitLab From 40fd4138938884c5d1155a62107f85e68bdb8d2c Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 20 Oct 2022 12:28:49 +0200 Subject: [PATCH 11/17] Proto/Manager_counter: add encoding for errors --- src/proto_alpha/lib_protocol/contract_storage.ml | 8 ++++---- src/proto_alpha/lib_protocol/manager_counter_repr.ml | 2 ++ src/proto_alpha/lib_protocol/manager_counter_repr.mli | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 6e3fd6c189a9..ee95dfadaf3e 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -97,8 +97,8 @@ let () = Data_encoding.( obj3 (req "contract" Contract_repr.encoding) - (req "expected" z) - (req "found" z)) + (req "expected" Manager_counter_repr.encoding_for_errors) + (req "found" Manager_counter_repr.encoding_for_errors)) (function | Counter_in_the_future {contract; expected; found} -> Some (contract, expected, found) @@ -123,8 +123,8 @@ let () = Data_encoding.( obj3 (req "contract" Contract_repr.encoding) - (req "expected" z) - (req "found" z)) + (req "expected" Manager_counter_repr.encoding_for_errors) + (req "found" Manager_counter_repr.encoding_for_errors)) (function | Counter_in_the_past {contract; expected; found} -> Some (contract, expected, found) diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index ffc4ff00afc5..5572491577d3 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -37,3 +37,5 @@ let encoding_for_storage = Data_encoding.z let encoding_for_operation = Data_encoding.(check_size 10 n) let encoding_for_RPCs = Data_encoding.n + +let encoding_for_errors = Data_encoding.z diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index 5363b603df6e..26f993157324 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -50,3 +50,6 @@ val encoding_for_operation : t Data_encoding.t (** Encoding for a counter to be used in RPCs. *) val encoding_for_RPCs : t Data_encoding.t + +(** Encoding for a counter to be used in errors. *) +val encoding_for_errors : t Data_encoding.t -- GitLab From f3cc1a8091c3e32e5053cf05276557418940c789 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 16:09:45 +0200 Subject: [PATCH 12/17] Proto/Manager_counter: add Internal_for_tests.of_int --- .../bin_sc_rollup_node/injector.ml | 2 +- src/proto_alpha/lib_plugin/test/generators.ml | 2 +- .../lib_protocol/alpha_context.mli | 4 ++++ .../lib_protocol/manager_counter_repr.ml | 6 ++++++ .../lib_protocol/manager_counter_repr.mli | 4 ++++ .../test/helpers/operation_generator.ml | 2 +- .../michelson/test_typechecking.ml | 2 +- .../operations/test_combined_operations.ml | 19 +++++++++++++------ .../operations/test_origination.ml | 2 +- .../integration/operations/test_tx_rollup.ml | 10 +++++----- .../test_manager_operation_validation.ml | 2 +- src/proto_alpha/lib_tx_rollup/injector.ml | 2 +- 12 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/proto_alpha/bin_sc_rollup_node/injector.ml b/src/proto_alpha/bin_sc_rollup_node/injector.ml index 982460e53953..f34cfe5bd865 100644 --- a/src/proto_alpha/bin_sc_rollup_node/injector.ml +++ b/src/proto_alpha/bin_sc_rollup_node/injector.ml @@ -90,7 +90,7 @@ module Parameters : let approximate_fee_bound _ _ = { fee = Tez.of_mutez_exn 3_000_000L; - counter = Z.of_int 500_000; + counter = Manager_counter.Internal_for_tests.of_int 500_000; gas_limit = Gas.Arith.integral_of_int_exn 500_000; storage_limit = Z.of_int 500_000; } diff --git a/src/proto_alpha/lib_plugin/test/generators.ml b/src/proto_alpha/lib_plugin/test/generators.ml index 014defb7a366..afe935242a1b 100644 --- a/src/proto_alpha/lib_plugin/test/generators.ml +++ b/src/proto_alpha/lib_plugin/test/generators.ml @@ -48,7 +48,7 @@ let dummy_manager_op_info = let manager_op = let open Alpha_context in let source = Signature.Public_key_hash.zero in - let counter = Z.zero in + let counter = Manager_counter.Internal_for_tests.of_int 0 in let storage_limit = Z.zero in let operation = Set_deposits_limit None in let contents = diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 3fd7acaea982..fcef4aa43eae 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1608,6 +1608,10 @@ module Manager_counter : sig val pp : Format.formatter -> t -> unit val encoding_for_RPCs : t Data_encoding.t + + module Internal_for_tests : sig + val of_int : int -> t + end end (** This module re-exports definitions from {!Contract_repr} and diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index 5572491577d3..97131b14a9ed 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -39,3 +39,9 @@ let encoding_for_operation = Data_encoding.(check_size 10 n) let encoding_for_RPCs = Data_encoding.n let encoding_for_errors = Data_encoding.z + +module Internal_for_tests = struct + let of_int i = + assert (Compare.Int.(i >= 0)) ; + Z.of_int i +end diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index 26f993157324..3b5e136eb687 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -53,3 +53,7 @@ val encoding_for_RPCs : t Data_encoding.t (** Encoding for a counter to be used in errors. *) val encoding_for_errors : t Data_encoding.t + +module Internal_for_tests : sig + val of_int : int -> t +end 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 55f556658c09..d15e2e74dfc3 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml @@ -327,7 +327,7 @@ let random_contract_hash = QCheck2.Gen.oneofl contract_hashes let gen_counters = let open QCheck2.Gen in let+ i = nat in - Z.of_int i + Manager_counter.Internal_for_tests.of_int i let gen_ticket_amounts = let open QCheck2.Gen in diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml index 8caf7bf01e6a..f813f58e7085 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_typechecking.ml @@ -52,7 +52,7 @@ let sc_originate block contract parameters_ty = let kind = Sc_rollup.Kind.Example_arith in let* operation, rollup = Op.sc_rollup_origination - ~counter:(Z.of_int 0) + ~counter:(Manager_counter.Internal_for_tests.of_int 0) (B block) contract kind diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml index 376ce44906d2..8fc28644d5da 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml @@ -92,7 +92,7 @@ let test_multiple_origination_and_delegation () = Op.contract_origination ~gas_limit ~delegate:delegate_pkh - ~counter:(Z.of_int i) + ~counter:(Manager_counter.Internal_for_tests.of_int i) ~fee:Tez.zero ~script:Op.dummy_script ~credit:(Test_tez.of_int 10) @@ -327,7 +327,14 @@ let test_inconsistent_counters () = (* Make legit transfers, performing reveals *) Block.bake ~operations:[op1; op2] blk >>=? fun b -> (* Now, counter c1 = counter c2 = 1, Op.transaction builds with counter + 1 *) - Op.transaction ~gas_limit ~fee:Tez.one (B b) c1 c2 ~counter:Z.one Tez.one + Op.transaction + ~gas_limit + ~fee:Tez.one + (B b) + c1 + c2 + ~counter:(Manager_counter.Internal_for_tests.of_int 1) + Tez.one >>=? fun op1 -> Op.transaction ~gas_limit @@ -335,7 +342,7 @@ let test_inconsistent_counters () = (B b) c1 c2 - ~counter:(Z.of_int 2) + ~counter:(Manager_counter.Internal_for_tests.of_int 2) Tez.one >>=? fun op2 -> Op.transaction @@ -344,7 +351,7 @@ let test_inconsistent_counters () = (B b) c1 c2 - ~counter:(Z.of_int 2) + ~counter:(Manager_counter.Internal_for_tests.of_int 2) (Tez.of_mutez_exn 5_000L) >>=? fun op2' -> Op.transaction @@ -353,7 +360,7 @@ let test_inconsistent_counters () = (B b) c1 c2 - ~counter:(Z.of_int 3) + ~counter:(Manager_counter.Internal_for_tests.of_int 3) Tez.one >>=? fun op3 -> Op.transaction @@ -362,7 +369,7 @@ let test_inconsistent_counters () = (B b) c1 c2 - ~counter:(Z.of_int 4) + ~counter:(Manager_counter.Internal_for_tests.of_int 4) Tez.one >>=? fun op4 -> (* Canari: Check counters are ok *) diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_origination.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_origination.ml index b0c1e8d97f9c..bb5d8af9c57f 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_origination.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_origination.ml @@ -236,7 +236,7 @@ let test_unparsable_script () = { source = pkh; fee = Tez.one; - counter = Z.of_int 1; + counter = Manager_counter.Internal_for_tests.of_int 1; operation = origination; gas_limit; storage_limit = Z.zero; diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml index 3978a100f907..aa59f2a42e71 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml @@ -387,7 +387,7 @@ let make_deposit b tx_rollup l1_src addr = let parameters = print_deposit_arg (`Typed tx_rollup) (`Hash addr) in let fee = Test_tez.of_int 10 in Op.transaction - ~counter:(Z.of_int 2) + ~counter:(Manager_counter.Internal_for_tests.of_int 2) ~fee (B b) l1_src @@ -1128,7 +1128,7 @@ let test_additional_space_allocation_for_valid_deposit () = let parameters = print_deposit_arg (`Typed tx_rollup) (`Hash pkh) in let fee = Test_tez.of_int 10 in Op.transaction - ~counter:(Z.of_int 2) + ~counter:(Manager_counter.Internal_for_tests.of_int 2) ~fee (B b) account @@ -1271,7 +1271,7 @@ let test_invalid_deposit_too_big_ticket () = in let fee = Test_tez.of_int 10 in Op.transaction - ~counter:(Z.of_int 2) + ~counter:(Manager_counter.Internal_for_tests.of_int 2) ~fee (B b) account @@ -1322,7 +1322,7 @@ let test_invalid_deposit_too_big_ticket_type () = in let fee = Test_tez.of_int 10 in Op.transaction - ~counter:(Z.of_int 2) + ~counter:(Manager_counter.Internal_for_tests.of_int 2) ~fee (B b) account @@ -1379,7 +1379,7 @@ let test_valid_deposit_big_ticket () = in let fee = Test_tez.of_int 10 in Op.transaction - ~counter:(Z.of_int 2) + ~counter:(Manager_counter.Internal_for_tests.of_int 2) ~fee (B b) account diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/test_manager_operation_validation.ml b/src/proto_alpha/lib_protocol/test/integration/validate/test_manager_operation_validation.ml index d5e81108f426..49666defaa30 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/test_manager_operation_validation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/test_manager_operation_validation.ml @@ -164,7 +164,7 @@ let test_high_counter infos kind = { (operation_req_default kind) with force_reveal = Some true; - counter = Some (Z.of_int max_int); + counter = Some (Manager_counter.Internal_for_tests.of_int max_int); } infos in diff --git a/src/proto_alpha/lib_tx_rollup/injector.ml b/src/proto_alpha/lib_tx_rollup/injector.ml index 9d54d22f9e6a..108583dcae88 100644 --- a/src/proto_alpha/lib_tx_rollup/injector.ml +++ b/src/proto_alpha/lib_tx_rollup/injector.ml @@ -125,7 +125,7 @@ module Parameters = struct let approximate_fee_bound _ _ = { fee = Tez.of_mutez_exn 3_000_000L; - counter = Z.of_int 500_000; + counter = Manager_counter.Internal_for_tests.of_int 500_000; gas_limit = Gas.Arith.integral_of_int_exn 500_000; storage_limit = Z.of_int 500_000; } -- GitLab From bb212fdba0e1c99336bea325dd50678880010d10 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 13 Oct 2022 18:48:05 +0200 Subject: [PATCH 13/17] Proto/Tests/Generators: generator for Manager_counter --- .../test/integration/validate/generators.ml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/generators.ml b/src/proto_alpha/lib_protocol/test/integration/validate/generators.ml index 9db10ff3124b..957fed04551e 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/generators.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/generators.ml @@ -136,13 +136,20 @@ let gen_pos : cstrs -> int option QCheck2.Gen.t = let+ v = int_range ~origin min max in Some v -(** Generator for Z.t that is used for counter and gas limit. *) +(** Generator for Z.t that is used for gas limit. *) let gen_z : cstrs -> Z.t option QCheck2.Gen.t = fun cstrs -> let open QCheck2.Gen in let+ v = gen_pos cstrs in Option.map Z.of_int v +(** Generator for Manager_counter.t. *) +let gen_counter : cstrs -> Manager_counter.t option QCheck2.Gen.t = + fun cstrs -> + let open QCheck2.Gen in + let+ v = gen_pos cstrs in + Option.map Manager_counter.Internal_for_tests.of_int v + (** Generator for Tez.t. *) let gen_tez : cstrs -> Tez.t option QCheck2.Gen.t = fun cstrs -> @@ -194,7 +201,7 @@ let gen_operation_req : fun {counter; fee; gas_limit; storage_limit; force_reveal; amount} subjects -> let open QCheck2.Gen in let* kind = gen_kind subjects in - let* counter = gen_z counter in + let* counter = gen_counter counter in let* fee = gen_tez fee in let* gas_limit = gen_gas_limit gas_limit in let* storage_limit = gen_z storage_limit in -- GitLab From 3845a87ef2ecc5da11bb8c280a3063b55976dc78 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 17:25:28 +0200 Subject: [PATCH 14/17] Proto/Manager_counter: add Internal_for_tests.add --- src/proto_alpha/lib_protocol/alpha_context.mli | 2 ++ src/proto_alpha/lib_protocol/manager_counter_repr.ml | 5 +++++ src/proto_alpha/lib_protocol/manager_counter_repr.mli | 2 ++ .../test/integration/operations/test_transfer.ml | 2 +- .../test/integration/validate/manager_operation_helpers.ml | 4 +++- .../validate/test_manager_operation_validation.ml | 3 ++- 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index fcef4aa43eae..22691286751c 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1611,6 +1611,8 @@ module Manager_counter : sig module Internal_for_tests : sig val of_int : int -> t + + val add : t -> int -> t end end diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index 97131b14a9ed..d8b678be5dfb 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -44,4 +44,9 @@ module Internal_for_tests = struct let of_int i = assert (Compare.Int.(i >= 0)) ; Z.of_int i + + let add c i = + let c = Z.(add c (of_int i)) in + assert (c >= Z.zero) ; + c end diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index 3b5e136eb687..740b7656a5ef 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -56,4 +56,6 @@ val encoding_for_errors : t Data_encoding.t module Internal_for_tests : sig val of_int : int -> t + + val add : t -> int -> t end diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml index 6331befc44d7..c1ab45367f30 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml @@ -536,7 +536,7 @@ let invalid_counter_in_the_future () = Context.init2 () >>=? fun (b, (contract_1, contract_2)) -> Incremental.begin_construction b >>=? fun b -> Context.Contract.counter (I b) contract_1 >>=? fun cpt -> - let counter = Z.add cpt (Z.of_int 10) in + let counter = Manager_counter.Internal_for_tests.add cpt 10 in Op.transaction (I b) contract_1 contract_2 Tez.one ~counter >>=? fun op -> Incremental.add_operation b op >>= fun b -> Assert.proto_error ~loc:__LOC__ b (function 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 9bd1f4004847..4bb617d0b1f5 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 @@ -1322,7 +1322,9 @@ 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 (Z.of_int probes.nb_counter) in + let c_expected = + Manager_counter.Internal_for_tests.add c_in probes.nb_counter + in let+ g_expected = match (g_in, mode) with | Some g_in, Construction -> diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/test_manager_operation_validation.ml b/src/proto_alpha/lib_protocol/test/integration/validate/test_manager_operation_validation.ml index 49666defaa30..e0ab92846cc9 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/test_manager_operation_validation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/test_manager_operation_validation.ml @@ -202,7 +202,8 @@ let test_low_counter infos kind = { (operation_req_default kind) with force_reveal = Some true; - counter = Some (Z.sub current_counter Z.one); + counter = + Some (Manager_counter.Internal_for_tests.add current_counter (-1)); } infos in -- GitLab From 1bb77de13d999a4dfbca715ae1de8903eb9d4c9d Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 13 Oct 2022 18:50:05 +0200 Subject: [PATCH 15/17] Proto/Manager_counter: add Internal_for_tests.to_int --- src/proto_alpha/lib_protocol/alpha_context.mli | 2 ++ src/proto_alpha/lib_protocol/manager_counter_repr.ml | 2 ++ src/proto_alpha/lib_protocol/manager_counter_repr.mli | 2 ++ .../lib_protocol/test/integration/validate/generators.ml | 6 +++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 22691286751c..c3a71195d308 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1612,6 +1612,8 @@ module Manager_counter : sig module Internal_for_tests : sig val of_int : int -> t + val to_int : t -> int + val add : t -> int -> t end end diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index d8b678be5dfb..de230e591e1e 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -45,6 +45,8 @@ module Internal_for_tests = struct assert (Compare.Int.(i >= 0)) ; Z.of_int i + let to_int = Z.to_int + let add c i = let c = Z.(add c (of_int i)) in assert (c >= Z.zero) ; diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index 740b7656a5ef..1da3551192d0 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -57,5 +57,7 @@ val encoding_for_errors : t Data_encoding.t module Internal_for_tests : sig val of_int : int -> t + val to_int : t -> int + val add : t -> int -> t end diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/generators.ml b/src/proto_alpha/lib_protocol/test/integration/validate/generators.ml index 957fed04551e..30967c0027ff 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/generators.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/generators.ml @@ -219,7 +219,11 @@ let gen_2_operation_req : let* op1 = gen_operation_req {op_cstrs with force_reveal = Some true} subjects in - let counter = match op1.counter with Some x -> Z.to_int x | None -> 1 in + let counter = + match op1.counter with + | Some x -> Manager_counter.Internal_for_tests.to_int x + | None -> 1 + in let op_cstr = { {op_cstrs with counter = Pure (counter + 2)} with -- GitLab From f0a6759941311e17c60f201acfea0df241bd8613 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 17 Oct 2022 18:34:09 +0200 Subject: [PATCH 16/17] Proto/Manager_counter: add Internal_for_injection.of_string --- src/proto_alpha/lib_client/client_proto_args.ml | 8 +++++++- src/proto_alpha/lib_protocol/alpha_context.mli | 4 ++++ src/proto_alpha/lib_protocol/manager_counter_repr.ml | 7 +++++++ src/proto_alpha/lib_protocol/manager_counter_repr.mli | 7 +++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_client/client_proto_args.ml b/src/proto_alpha/lib_client/client_proto_args.ml index 416901802ab0..068a034119df 100644 --- a/src/proto_alpha/lib_client/client_proto_args.ml +++ b/src/proto_alpha/lib_client/client_proto_args.ml @@ -313,6 +313,12 @@ let non_negative_z_parameter = let non_negative_z_param ~name ~desc next = Tezos_clic.param ~name ~desc non_negative_z_parameter next +let counter_parameter = + Tezos_clic.parameter (fun _ s -> + match Manager_counter.Internal_for_injection.of_string s with + | None -> failwith "Invalid counter, must be a non-negative number." + | Some c -> return c) + let non_negative_parameter = Tezos_clic.parameter (fun _ s -> match int_of_string_opt s with @@ -450,7 +456,7 @@ let counter_arg = ~short:'C' ~placeholder:"counter" ~doc:"Set the counter to be used by the transaction" - non_negative_z_parameter + counter_parameter let max_priority_arg = Tezos_clic.arg diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index c3a71195d308..f5775a2ac88d 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1609,6 +1609,10 @@ module Manager_counter : sig val encoding_for_RPCs : t Data_encoding.t + module Internal_for_injection : sig + val of_string : string -> t option + end + module Internal_for_tests : sig val of_int : int -> t diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.ml b/src/proto_alpha/lib_protocol/manager_counter_repr.ml index de230e591e1e..9e93014af743 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.ml +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -40,6 +40,13 @@ let encoding_for_RPCs = Data_encoding.n let encoding_for_errors = Data_encoding.z +module Internal_for_injection = struct + let of_string s = + match Z.of_string s with + | exception _ -> None + | z -> if z < Z.zero then None else Some z +end + module Internal_for_tests = struct let of_int i = assert (Compare.Int.(i >= 0)) ; diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index 1da3551192d0..d2e0b8701888 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -54,6 +54,13 @@ val encoding_for_RPCs : t Data_encoding.t (** Encoding for a counter to be used in errors. *) val encoding_for_errors : t Data_encoding.t +(** To be used in client injection only. *) +module Internal_for_injection : sig + (** Converts a string to a counter. + Returns [None] if the string does not represent a valid counter. *) + val of_string : string -> t option +end + module Internal_for_tests : sig val of_int : int -> t -- GitLab From ba7f21dd1ce3faec2b490ac6b8d0e2018c8a8183 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Wed, 12 Oct 2022 17:14:29 +0200 Subject: [PATCH 17/17] Proto/Manager_counter: make it abstract --- src/proto_alpha/lib_protocol/alpha_context.mli | 4 +--- src/proto_alpha/lib_protocol/manager_counter_repr.mli | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index f5775a2ac88d..02aa58e382f5 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1599,9 +1599,7 @@ end (** This module re-exports definitions from {!Manager_counter_repr}. *) module Manager_counter : sig - type t = Z.t - - include Compare.S with type t := t + include Compare.S val succ : t -> t diff --git a/src/proto_alpha/lib_protocol/manager_counter_repr.mli b/src/proto_alpha/lib_protocol/manager_counter_repr.mli index d2e0b8701888..50fdf8e1ded5 100644 --- a/src/proto_alpha/lib_protocol/manager_counter_repr.mli +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -29,9 +29,8 @@ each manager operation declares a value for the counter. When a manager operation is applied, the value of the counter of its manager is checked and incremented. *) -type t = Z.t -include Compare.S with type t := t +include Compare.S (** Initial value for a counter (zero). *) val init : t -- GitLab