diff --git a/src/proto_alpha/bin_sc_rollup_node/injector.ml b/src/proto_alpha/bin_sc_rollup_node/injector.ml index 982460e53953e6c87c7999ab26577bf922975ea7..f34cfe5bd865da12667c987fa9dbe1e0fb0997bf 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_client/annotated_manager_operation.ml b/src/proto_alpha/lib_client/annotated_manager_operation.ml index 96ce163f52957835a010ef593dddd41328fb771b..7aa1a7fc7080f5db712e83aa87aa7dfd45e9edb3 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 4eebe07b7a599a6ee581323022e4a1652d23a9d1..0fc7a472f84216d878749fbc2f5192edc543be77 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 @@ -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_args.ml b/src/proto_alpha/lib_client/client_proto_args.ml index 416901802ab023335980b0a97a31506747faa814..068a034119df0f78f20a0501933767ec2b9ba5c2 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_client/client_proto_args.mli b/src/proto_alpha/lib_client/client_proto_args.mli index c0a0f0a488abcb6038b043e30f024f943964c62a..79ffb850794016f17d74573d23bcce03bec9eacb 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 e25b0a0aa97a584207e42524a9eb1a89fd7648af..17e25123bc716f639cd9d955c90100f96110122e 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 -> @@ -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 -> @@ -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 -> @@ -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 14f56e24cb57949700e4f3de1727e80722d5b98b..cfd100f44a46010c0ae3f41c03fd67493bec7ed4 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) @@ -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/client_proto_multisig.mli b/src/proto_alpha/lib_client/client_proto_multisig.mli index bd2f3d746552f6a392a419a1654013952d0417b7..5ebfd1448d0fe6c47ff0f8fc30c943acc51e2c5a 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 bec0a611639205922f1063c497241756ab86c71a..a05bf5079bdaeb38efe4df1580140b2656813e02 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 -> @@ -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 @@ -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/injection.mli b/src/proto_alpha/lib_client/injection.mli index 6275db8033e1c7d42abde993696a628f0461f4d3..d66775157c80a34c0ea1bc2469c28e4d062a5ef5 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/managed_contract.mli b/src/proto_alpha/lib_client/managed_contract.mli index aea7fb7763fd945af872ae222fee7871eee63852..b459230ae8b390e5c949fb3c022e005d04e40d85 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_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index 0c95c2b04f098e2b34b188e3b608d306c70e6503..f0fc58ae69475812352895d429a65e53c829c26c 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 140d2ab47d8ad1e08e22b18d24678d5b5a7c4e7d..8b81d1661024b9ce2156c234b6aa4a3d31eb0d28 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; } @@ -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 { @@ -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)) @@ -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 @@ -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)) @@ -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_delegate/operation_selection.ml b/src/proto_alpha/lib_delegate/operation_selection.ml index a658661df026589db7ffb88d4b2b797ab9da7f68..9a4fbf4d0b92ed64ffd2016bea743c8cebfca75b 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 @@ -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_injector/injector_sigs.ml b/src/proto_alpha/lib_injector/injector_sigs.ml index 29bd400af4065e0229e4e9d415ad3a07c8aeedcc..d9c56fda0736559cceb04078d5444cdb18be6d7a 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_plugin/test/generators.ml b/src/proto_alpha/lib_plugin/test/generators.ml index 014defb7a3660a06757100eede11ad60253e4552..afe935242a1ba02da6463c00c0e821aa9c68aeba 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/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 00bf18b7e7e791eb3b387d230d96de3041625e28..fb3eb85045a76f3b58563d1465a5f71a38a3b083 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/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 40e163c86ab0f4f6914d18953c1290df0406f777..6403ff9bd3cf95dfac39c966ed09295832bde693 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 ef244db926944a80f352f4f3608589fbcdff7430..02aa58e382f50e2501f4735f4528c597b63a29ba 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1597,6 +1597,29 @@ module Ticket_hash : sig end end +(** This module re-exports definitions from {!Manager_counter_repr}. *) +module Manager_counter : sig + include Compare.S + + val succ : t -> t + + val pp : Format.formatter -> t -> unit + + 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 + + val to_int : t -> int + + val add : t -> int -> t + end +end + (** This module re-exports definitions from {!Contract_repr} and {!Contract_storage}. *) module Contract : sig @@ -1664,12 +1687,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 : @@ -4346,7 +4370,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 +4527,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 b55fa2740e7b1370a78ee33588a5294864e1cb6a..0708612f1b4cef206c153c2ebb9c9eaa272ed928 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; } @@ -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/contract_services.mli b/src/proto_alpha/lib_protocol/contract_services.mli index e37d2ce837f658572727122eedb3eb7b9a6a18db..7ea8996b24ab3b652a14a18a28c52a41d9901e0b 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/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 1368f75f7aeb3607b88ef792570bc4ce69426729..ee95dfadaf3e38bc8a9e518e7e54d91d0c5a1b1b 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 @@ -88,17 +88,17 @@ 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 (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) @@ -114,17 +114,17 @@ 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 (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) @@ -504,18 +504,24 @@ 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 - if Compare.Z.(expected = counter) then return_unit - else if Compare.Z.(expected > counter) then + let expected = Manager_counter_repr.succ contract_counter in + 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}) 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 @@ -634,7 +640,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/contract_storage.mli b/src/proto_alpha/lib_protocol/contract_storage.mli index e553be0458957fa2294b742e63ffae16f6eba838..23c062aad53bf2e5fd68847c38ce4a3235a3c3da 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/dune b/src/proto_alpha/lib_protocol/dune index 65a9fe15d97539f3bfc335c7eba269ceb1ddc3fb..70b931f52b641519290273a132ad23232974a7b7 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 0000000000000000000000000000000000000000..9e93014af743ab107c4490076a8559d4d54b44d1 --- /dev/null +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.ml @@ -0,0 +1,61 @@ +(*****************************************************************************) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +include Compare.Z + +let init = Z.zero + +let succ = Z.succ + +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 + +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)) ; + 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) ; + c +end 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 0000000000000000000000000000000000000000..50fdf8e1ded5dbba6bbb391b5bd44b4038c9a279 --- /dev/null +++ b/src/proto_alpha/lib_protocol/manager_counter_repr.mli @@ -0,0 +1,69 @@ +(*****************************************************************************) +(* *) +(* 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. *) + +include Compare.S + +(** Initial value for a counter (zero). *) +val init : t + +(** Successor of a counter. *) +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 + +(** 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 + +(** 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 + + val to_int : t -> int + + val add : t -> int -> t +end diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 41ad4307c084dd1963a3082d587218939829b54f..44a02137c32c8a84568df22b341c486400b194e6 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 = Z.t - let manager_kind : type kind. kind manager_operation -> kind Kind.manager = function | Reveal _ -> Kind.Reveal_manager_kind @@ -1607,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)) diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 27cc6c17cfd7ff2c6c632e87658a3318bf39dfba..18573215474ba8682a8fa1a3e8fd546834d0ae09 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,13 +581,6 @@ 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 - type packed_manager_operation = | Manager : 'kind manager_operation -> packed_manager_operation diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index f75a7e0216f4a45944e316ff2bfb65ca1331f839..274acf2e0491674f1002a960311dea33b7a6db8b 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 @@ -169,12 +175,13 @@ 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"] end) - (Encoding.Z) + (Encoding.Manager_counter) module Indexed_context = Make_indexed_subcontext @@ -271,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 3c545c6b4c66378835938f2e4b7c7bfbd314603b..7e6da9f6dd3d11f2ae3ad33d62e8b92bba58d789 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 diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index 6d6e1d44f703ea716b4315664506437a08c81bc5..22366748fc543ad72786f25f48d46e7d513e8089 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.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index 134d1d8ba66ac4029e51571f95c63e045cfb01e6..77943cf8968029ce63926da8545841cd31367f59 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/helpers/op.mli b/src/proto_alpha/lib_protocol/test/helpers/op.mli index ce21e0ee036ad61b492e96f311a8f46146a1f35e..4b9df5708427d82fd52cced1afa55e7477d5042e 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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> @@ -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 -> 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 55f556658c09424c127a79359993b80620659f06..d15e2e74dfc39a381f4d959f97cb3e53bff60e15 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 8caf7bf01e6aee66dfeea834b17a88c84019580f..f813f58e7085c8276aafd35b2c62f3af328db65a 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 376ce44906d2a6cc0760dc4e5b36cd7264d3ec3d..8fc28644d5da08b44feda6dd38b4ceb073a4dcd7 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 b0c1e8d97f9c905422543491f0ca688e712bfa7e..bb5d8af9c57ff860997aa905654ed5ebb0288348 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_transfer.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml index 6331befc44d7e344136e1d0a6b86261d9137052e..c1ab45367f30c142cc3809a74f2290ba0ca3c2a2 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/operations/test_tx_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml index fb6d287d19742a3936bd93d370766e1c141b864c..aa59f2a42e715a82fd31557df251cebcf2d7d644 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 @@ -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 -> @@ -1125,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 @@ -1268,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 @@ -1319,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 @@ -1376,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/generator_descriptors.ml b/src/proto_alpha/lib_protocol/test/integration/validate/generator_descriptors.ml index 712a0a7554fc7cc86755fe4b5abce55c9ae221fc..14c622a5fd6e70d8cd67f7a7da186b96ff792bf5 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/generators.ml b/src/proto_alpha/lib_protocol/test/integration/validate/generators.ml index 9db10ff3124b2c1d49cfe0ff7b02459be39ebcea..30967c0027ffb6ca5d934c05f32fd6d2a07575d3 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 @@ -212,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 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 8bacf024020b697c631d70c79cbf3e2cfab0a51e..4bb617d0b1f5b4624f996d2ade99889e2c5e6595 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; @@ -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 @@ -421,12 +421,12 @@ 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 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 @@ -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 -> @@ -1385,10 +1387,10 @@ 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 + Manager_counter.pp c_out c_expected in 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 d5e81108f4266c0124aad7ff958ac9c2f9fbe038..e0ab92846cc9716979b7a02b006c15be10aa001e 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 @@ -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 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 beff404e811fc454f8d59e9d81107089a4128f9f..ba364f0dc2f406015e5008bfd7e87b63ace740e8 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 83414ab00446f2e0b37bcf6e15d09af57b7b3f92..bf3b54d7aa631318e16f51fb019f499771d7c9e3 100644 --- a/src/proto_alpha/lib_protocol/validate.ml +++ b/src/proto_alpha/lib_protocol/validate.ml @@ -2129,13 +2129,13 @@ module Manager = struct Inconsistent_sources in error_unless - Compare.Z.(Z.succ previous_counter = counter) + Manager_counter.(succ previous_counter = counter) Inconsistent_counters in 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; _}) diff --git a/src/proto_alpha/lib_tx_rollup/injector.ml b/src/proto_alpha/lib_tx_rollup/injector.ml index 9d54d22f9e6ac7e478a520d76ef3fa5ac5564c58..108583dcae88e31dfe2596079b70cea930120c8d 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; }