From 65ee548c3f0b907bafa40c618dc890470c177d5c Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 9 Jun 2023 11:14:33 +0200 Subject: [PATCH 1/7] lib_shell_services: improve versioning in block_services --- src/lib_shell_services/block_services.ml | 74 ++++++++++++++--------- src/lib_shell_services/block_services.mli | 8 +-- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/lib_shell_services/block_services.ml b/src/lib_shell_services/block_services.ml index bad6d7f60f07..4cbd7dceb225 100644 --- a/src/lib_shell_services/block_services.ml +++ b/src/lib_shell_services/block_services.ml @@ -27,6 +27,46 @@ open Data_encoding module Proof = Tezos_context_sigs.Context.Proof_types +type version = Version_0 | Version_1 | Version_2 + +let string_of_version = function + | Version_0 -> "0" + | Version_1 -> "1" + | Version_2 -> "2" + +let unsupported_version_msg version supported = + Format.asprintf + "Unsupported version %s (supported versions %a)" + version + (Format.pp_print_list + ~pp_sep:(fun fmt () -> Format.fprintf fmt ",") + (fun fmt version -> + Format.fprintf fmt "\"%s\"" (string_of_version version))) + supported + +let is_supported_version version supported = + List.mem ~equal:( == ) version supported + +let version_of_string supported version = + let open Result_syntax in + let* version_t = + match version with + | "0" -> Ok Version_0 + | "1" -> Ok Version_1 + | "2" -> Ok Version_2 + | _ -> Error (unsupported_version_msg version supported) + in + if is_supported_version version_t supported then Ok version_t + else Error (unsupported_version_msg version supported) + +let version_arg supported = + let open Tezos_rpc.Arg in + make + ~name:"version" + ~destruct:(version_of_string supported) + ~construct:string_of_version + () + (* TODO: V2.Tree32 has been chosen arbitrarily ; maybe it's not the best option *) module Merkle_proof_encoding = Tezos_context_merkle_proof_encoding.Merkle_proof_encoding.V2.Tree32 @@ -1190,30 +1230,10 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct (* This encoding should be always the one by default. *) let encoding = version_1_encoding - type version = Version_0 | Version_1 | Version_2 - - let string_of_version = function - | Version_0 -> "0" - | Version_1 -> "1" - | Version_2 -> "2" - - let version_of_string = function - | "0" -> Ok Version_0 - | "1" -> Ok Version_1 - | "2" -> Ok Version_2 - | _ -> - Error - "Cannot parse version (supported versions \"0\", \"1\" and \"2\")" - let default_pending_operations_version = Version_1 - let version_arg = - let open Tezos_rpc.Arg in - make - ~name:"version" - ~destruct:version_of_string - ~construct:string_of_version - () + let pending_operations_supported_versions = + [Version_0; Version_1; Version_2] let pending_query = let open Tezos_rpc.Query in @@ -1244,7 +1264,7 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct end) |+ field "version" - version_arg + (version_arg pending_operations_supported_versions) default_pending_operations_version (fun t -> t#version) |+ field @@ -1736,14 +1756,12 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct unprocessed : Next_proto.operation Operation_hash.Map.t; } - type version = S.Mempool.version = Version_0 | Version_1 | Version_2 - let pending_operations ctxt ?(chain = `Main) ?(version = S.Mempool.default_pending_operations_version) ?(validated = true) ?(branch_delayed = true) ?(branch_refused = true) ?(refused = true) ?(outdated = true) ?(validation_passes = []) () = let open Lwt_result_syntax in - let* v = + let* _version, pending_operations = Tezos_rpc.Context.make_call1 (S.Mempool.pending_operations (mempool_path chain_path)) ctxt @@ -1765,9 +1783,7 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct end) () in - match v with - | (Version_2 | Version_1 | Version_0), pending_operations -> - return pending_operations + return pending_operations let ban_operation ctxt ?(chain = `Main) op_hash = let s = S.Mempool.ban_operation (mempool_path chain_path) in diff --git a/src/lib_shell_services/block_services.mli b/src/lib_shell_services/block_services.mli index 0cc9234260fa..b8189dbacb5c 100644 --- a/src/lib_shell_services/block_services.mli +++ b/src/lib_shell_services/block_services.mli @@ -26,6 +26,8 @@ module Proof = Tezos_context_sigs.Context.Proof_types +type version = Version_0 | Version_1 | Version_2 + type chain = [`Main | `Test | `Hash of Chain_id.t] type chain_prefix = unit * chain @@ -406,8 +408,6 @@ module Make (Proto : PROTO) (Next_proto : PROTO) : sig unprocessed : Next_proto.operation Operation_hash.Map.t; } - type version = Version_0 | Version_1 | Version_2 - (** Call RPC GET /chains/[chain]/mempool/pending_operations - Default [version] is [0]. @@ -725,7 +725,7 @@ module Make (Proto : PROTO) (Next_proto : PROTO) : sig ( [`GET], 'a, 'b, - < version : Mempool.version + < version : version ; validated : bool ; branch_delayed : bool ; branch_refused : bool @@ -733,7 +733,7 @@ module Make (Proto : PROTO) (Next_proto : PROTO) : sig ; outdated : bool ; validation_passes : int list >, unit, - Mempool.version * Mempool.t ) + version * Mempool.t ) Tezos_rpc.Service.t (** Define RPC POST /chains/[chain]/mempool/ban_operation *) -- GitLab From 7208ddd358aba5d857af60e924e263825d4438f0 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 9 Jun 2023 11:15:19 +0200 Subject: [PATCH 2/7] lib_shell_services: add version 1 to monitor_operations to allow it to output attestation kind --- src/lib_shell/prevalidator_internal.ml | 5 +- src/lib_shell_services/block_services.ml | 85 ++++++++++++++----- src/lib_shell_services/block_services.mli | 9 +- .../test/mockup_simulator/faked_services.ml | 6 +- .../test/mockup_simulator/mockup_simulator.ml | 7 +- .../test/mockup_simulator/faked_services.ml | 6 +- .../test/mockup_simulator/mockup_simulator.ml | 7 +- .../test/mockup_simulator/faked_services.ml | 6 +- .../test/mockup_simulator/mockup_simulator.ml | 7 +- 9 files changed, 101 insertions(+), 37 deletions(-) diff --git a/src/lib_shell/prevalidator_internal.ml b/src/lib_shell/prevalidator_internal.ml index 48a685141b6b..b38c496ad11c 100644 --- a/src/lib_shell/prevalidator_internal.ml +++ b/src/lib_shell/prevalidator_internal.ml @@ -1121,7 +1121,7 @@ module Make match !current_mempool with | Some mempool -> current_mempool := None ; - Lwt.return_some mempool + Lwt.return_some (params#version, mempool) | None -> ( let* o = Lwt_stream.get op_stream in match o with @@ -1135,7 +1135,8 @@ module Make | `Outdated errors -> Some errors in - Lwt.return_some [((op.hash, op.protocol), errors)] + Lwt.return_some + (params#version, [((op.hash, op.protocol), errors)]) | Some _ -> next () | None -> Lwt.return_none) in diff --git a/src/lib_shell_services/block_services.ml b/src/lib_shell_services/block_services.ml index 4cbd7dceb225..ff71c0267b49 100644 --- a/src/lib_shell_services/block_services.ml +++ b/src/lib_shell_services/block_services.ml @@ -524,7 +524,7 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct let next_operation_encoding_with_legacy_attestation_name = let open Data_encoding in - def "next_operation" + def "next_operation_with_legacy_attestation_name" @@ conv (fun Next_proto.{shell; protocol_data} -> ((), (shell, protocol_data))) (fun ((), (shell, protocol_data)) -> {shell; protocol_data}) @@ -1375,10 +1375,15 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct ~output:unit Tezos_rpc.Path.(path / "unban_all_operations") + let default_monitoring_operations_version = Version_0 + + let monitoring_operations_supported_versions = [Version_0; Version_1] + let mempool_query = let open Tezos_rpc.Query in query (fun + version validated refused outdated @@ -1387,6 +1392,8 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct validation_passes -> object + method version = version + method validated = validated method refused = refused @@ -1399,6 +1406,11 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct method validation_passes = validation_passes end) + |+ field + "version" + (version_arg monitoring_operations_supported_versions) + default_monitoring_operations_version + (fun t -> t#version) |+ field (* FIXME: https://gitlab.com/tezos/tezos/-/issues/5720 This RPC still uses the old term "applied", whereas the @@ -1442,18 +1454,42 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct (* We extend the object so that the fields of 'next_operation' stay toplevel, for backward compatibility. *) - let processed_operation_encoding = + + let monitor_operations_encoding ~use_legacy_name = merge_objs (merge_objs (obj1 (req "hash" Operation_hash.encoding)) - next_operation_encoding_with_legacy_attestation_name) + (if use_legacy_name then + next_operation_encoding_with_legacy_attestation_name + else next_operation_encoding)) (obj1 (dft "error" Tezos_rpc.Error.opt_encoding None)) + let processed_operation_encoding = + union + [ + case + ~title:"monitor_operations_with_attestation" + (Tag 1) + (list (monitor_operations_encoding ~use_legacy_name:false)) + (function + | Version_1, monitor_operations -> Some monitor_operations + | (Version_0 | Version_2), _ -> None) + (fun monitor_operations -> (Version_1, monitor_operations)); + case + ~title:"old_encoding_monitor_operations" + (Tag 0) + (list (monitor_operations_encoding ~use_legacy_name:true)) + (function + | Version_0, monitor_operations -> Some monitor_operations + | (Version_1 | Version_2), _ -> None) + (fun monitor_operations -> (Version_0, monitor_operations)); + ] + let monitor_operations path = Tezos_rpc.Service.get_service ~description:"Monitor the mempool operations." ~query:mempool_query - ~output:(list processed_operation_encoding) + ~output:processed_operation_encoding Tezos_rpc.Path.(path / "monitor_operations") let get_filter_query = @@ -1797,28 +1833,37 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct let s = S.Mempool.unban_all_operations (mempool_path chain_path) in Tezos_rpc.Context.make_call1 s ctxt chain () () - let monitor_operations ctxt ?(chain = `Main) ?(validated = true) - ?(branch_delayed = true) ?(branch_refused = false) ?(refused = false) - ?(outdated = false) ?(validation_passes = []) () = + let monitor_operations ctxt ?(chain = `Main) + ?(version = S.Mempool.default_monitoring_operations_version) + ?(validated = true) ?(branch_delayed = true) ?(branch_refused = false) + ?(refused = false) ?(outdated = false) ?(validation_passes = []) () = + let open Lwt_result_syntax in let s = S.Mempool.monitor_operations (mempool_path chain_path) in - Tezos_rpc.Context.make_streamed_call - s - ctxt - ((), chain) - (object - method validated = validated + let* stream, stopper = + Tezos_rpc.Context.make_streamed_call + s + ctxt + ((), chain) + (object + method version = version - method refused = refused + method validated = validated - method outdated = outdated + method refused = refused - method branch_refused = branch_refused + method outdated = outdated - method branch_delayed = branch_delayed + method branch_refused = branch_refused - method validation_passes = validation_passes - end) - () + method branch_delayed = branch_delayed + + method validation_passes = validation_passes + end) + () + in + return + ( Lwt_stream.map (fun (_version, operations) -> operations) stream, + stopper ) let request_operations ctxt ?(chain = `Main) ?peer_id () = let s = S.Mempool.request_operations (mempool_path chain_path) in diff --git a/src/lib_shell_services/block_services.mli b/src/lib_shell_services/block_services.mli index b8189dbacb5c..be26ee2122cf 100644 --- a/src/lib_shell_services/block_services.mli +++ b/src/lib_shell_services/block_services.mli @@ -455,6 +455,7 @@ module Make (Proto : PROTO) (Next_proto : PROTO) : sig val monitor_operations : #streamed -> ?chain:chain -> + ?version:version -> ?validated:bool -> ?branch_delayed:bool -> ?branch_refused:bool -> @@ -757,15 +758,17 @@ module Make (Proto : PROTO) (Next_proto : PROTO) : sig ( [`GET], 'a, 'b, - < validated : bool + < version : version + ; validated : bool ; branch_delayed : bool ; branch_refused : bool ; refused : bool ; outdated : bool ; validation_passes : int list >, unit, - ((Operation_hash.t * Next_proto.operation) * error trace option) list - ) + version + * ((Operation_hash.t * Next_proto.operation) * error trace option) + list ) Tezos_rpc.Service.t (** Define RPC GET /chains/[chain]/mempool/filter *) diff --git a/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/faked_services.ml b/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/faked_services.ml index 6498615c7c95..9a6603cbee91 100644 --- a/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/faked_services.ml +++ b/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/faked_services.ml @@ -65,11 +65,14 @@ module type Mocked_services_hooks = sig endorsements. Invariant: the stream becomes empty when the node changes head. *) val monitor_operations : + version:Block_services.version -> validated:bool -> branch_delayed:bool -> branch_refused:bool -> refused:bool -> - ((Operation_hash.t * Mockup.M.Protocol.operation) * error trace option) list + (Block_services.version + * ((Operation_hash.t * Mockup.M.Protocol.operation) * error trace option) + list) Tezos_rpc.Answer.stream (** Lists block hashes from the chain, up to the last checkpoint, sorted @@ -280,6 +283,7 @@ module Make (Hooks : Mocked_services_hooks) = struct (fun ((), _chain) flags () -> let stream = Hooks.monitor_operations + ~version:flags#version ~validated:flags#validated ~branch_delayed:flags#branch_delayed ~branch_refused:flags#branch_refused diff --git a/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 208aaec3cc35..3c023176b106 100644 --- a/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_016_PtMumbai/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -475,7 +475,8 @@ let make_mocked_services_hooks (state : state) (user_hooks : (module Hooks)) : unprocessed = Operation_hash.Map.empty; } - let monitor_operations ~validated ~branch_delayed ~branch_refused ~refused = + let monitor_operations ~version ~validated ~branch_delayed ~branch_refused + ~refused = ignore validated ; ignore branch_delayed ; ignore branch_refused ; @@ -488,11 +489,11 @@ let make_mocked_services_hooks (state : state) (user_hooks : (module Hooks)) : | None when !streamed -> Lwt.return None | None -> streamed := true ; - Lwt.return (Some []) + Lwt.return_some (version, []) | Some ops -> ( List.filter_map_s User_hooks.on_new_operation ops >>= function | [] -> loop () - | l -> Lwt.return_some (List.map (fun x -> (x, None)) l)) + | l -> Lwt.return_some (version, List.map (fun x -> (x, None)) l)) in loop () in diff --git a/src/proto_017_PtNairob/lib_delegate/test/mockup_simulator/faked_services.ml b/src/proto_017_PtNairob/lib_delegate/test/mockup_simulator/faked_services.ml index 2c9a6e367db9..e64e5a88da9e 100644 --- a/src/proto_017_PtNairob/lib_delegate/test/mockup_simulator/faked_services.ml +++ b/src/proto_017_PtNairob/lib_delegate/test/mockup_simulator/faked_services.ml @@ -65,11 +65,14 @@ module type Mocked_services_hooks = sig endorsements. Invariant: the stream becomes empty when the node changes head. *) val monitor_operations : + version:Block_services.version -> validated:bool -> branch_delayed:bool -> branch_refused:bool -> refused:bool -> - ((Operation_hash.t * Mockup.M.Protocol.operation) * error trace option) list + (Block_services.version + * ((Operation_hash.t * Mockup.M.Protocol.operation) * error trace option) + list) Tezos_rpc.Answer.stream (** Lists block hashes from the chain, up to the last checkpoint, sorted @@ -269,6 +272,7 @@ module Make (Hooks : Mocked_services_hooks) = struct (fun ((), _chain) flags () -> let stream = Hooks.monitor_operations + ~version:flags#version ~validated:flags#validated ~branch_delayed:flags#branch_delayed ~branch_refused:flags#branch_refused diff --git a/src/proto_017_PtNairob/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_017_PtNairob/lib_delegate/test/mockup_simulator/mockup_simulator.ml index 6e7eabda0bae..5fb836f50f34 100644 --- a/src/proto_017_PtNairob/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_017_PtNairob/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -476,7 +476,8 @@ let make_mocked_services_hooks (state : state) (user_hooks : (module Hooks)) : unprocessed = Operation_hash.Map.empty; } - let monitor_operations ~validated ~branch_delayed ~branch_refused ~refused = + let monitor_operations ~version ~validated ~branch_delayed ~branch_refused + ~refused = ignore validated ; ignore branch_delayed ; ignore branch_refused ; @@ -489,11 +490,11 @@ let make_mocked_services_hooks (state : state) (user_hooks : (module Hooks)) : | None when !streamed -> Lwt.return None | None -> streamed := true ; - Lwt.return (Some []) + Lwt.return_some (version, []) | Some ops -> ( List.filter_map_s User_hooks.on_new_operation ops >>= function | [] -> loop () - | l -> Lwt.return_some (List.map (fun x -> (x, None)) l)) + | l -> Lwt.return_some (version, List.map (fun x -> (x, None)) l)) in loop () in diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/faked_services.ml b/src/proto_alpha/lib_delegate/test/mockup_simulator/faked_services.ml index 2c9a6e367db9..e64e5a88da9e 100644 --- a/src/proto_alpha/lib_delegate/test/mockup_simulator/faked_services.ml +++ b/src/proto_alpha/lib_delegate/test/mockup_simulator/faked_services.ml @@ -65,11 +65,14 @@ module type Mocked_services_hooks = sig endorsements. Invariant: the stream becomes empty when the node changes head. *) val monitor_operations : + version:Block_services.version -> validated:bool -> branch_delayed:bool -> branch_refused:bool -> refused:bool -> - ((Operation_hash.t * Mockup.M.Protocol.operation) * error trace option) list + (Block_services.version + * ((Operation_hash.t * Mockup.M.Protocol.operation) * error trace option) + list) Tezos_rpc.Answer.stream (** Lists block hashes from the chain, up to the last checkpoint, sorted @@ -269,6 +272,7 @@ module Make (Hooks : Mocked_services_hooks) = struct (fun ((), _chain) flags () -> let stream = Hooks.monitor_operations + ~version:flags#version ~validated:flags#validated ~branch_delayed:flags#branch_delayed ~branch_refused:flags#branch_refused diff --git a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml index a08de0408a0e..0fe62d4c5fef 100644 --- a/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml +++ b/src/proto_alpha/lib_delegate/test/mockup_simulator/mockup_simulator.ml @@ -476,7 +476,8 @@ let make_mocked_services_hooks (state : state) (user_hooks : (module Hooks)) : unprocessed = Operation_hash.Map.empty; } - let monitor_operations ~validated ~branch_delayed ~branch_refused ~refused = + let monitor_operations ~version ~validated ~branch_delayed ~branch_refused + ~refused = ignore validated ; ignore branch_delayed ; ignore branch_refused ; @@ -489,11 +490,11 @@ let make_mocked_services_hooks (state : state) (user_hooks : (module Hooks)) : | None when !streamed -> Lwt.return None | None -> streamed := true ; - Lwt.return (Some []) + Lwt.return_some (version, []) | Some ops -> ( List.filter_map_s User_hooks.on_new_operation ops >>= function | [] -> loop () - | l -> Lwt.return_some (List.map (fun x -> (x, None)) l)) + | l -> Lwt.return_some (version, List.map (fun x -> (x, None)) l)) in loop () in -- GitLab From 1e6491acfb419fb12f7cbbf30252bd266a5d5e02 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 13 Jun 2023 10:19:34 +0200 Subject: [PATCH 3/7] lib_shell_services: add some documentation for unsupported version --- src/lib_shell_services/block_services.ml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib_shell_services/block_services.ml b/src/lib_shell_services/block_services.ml index ff71c0267b49..4299c6a8b5e7 100644 --- a/src/lib_shell_services/block_services.ml +++ b/src/lib_shell_services/block_services.ml @@ -1473,7 +1473,14 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct (list (monitor_operations_encoding ~use_legacy_name:false)) (function | Version_1, monitor_operations -> Some monitor_operations - | (Version_0 | Version_2), _ -> None) + | ( ( Version_0 + | Version_2 + (* The same [version] type is used for versioning all the + RPC. Even though this version is not supported for this + RPC we need to handle it. We rely on the supported + version list to fail at parsing for this version *) ), + _ ) -> + None) (fun monitor_operations -> (Version_1, monitor_operations)); case ~title:"old_encoding_monitor_operations" @@ -1862,7 +1869,15 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct () in return - ( Lwt_stream.map (fun (_version, operations) -> operations) stream, + ( Lwt_stream.map + (fun ( ( Version_0 | Version_1 + | Version_2 + (* The same [version] type is used for versioning all the + RPC. Even though this version is not supported for this + RPC we need to handle it. We rely on the supported + version list to fail at parsing for this version *) ), + operations ) -> operations) + stream, stopper ) let request_operations ctxt ?(chain = `Main) ?peer_id () = -- GitLab From 246ac32fc8f6a5ef1096baa06e9dc45621129d83 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 6 Jun 2023 11:32:27 +0200 Subject: [PATCH 4/7] tezt/lib_tezos: add monitor_operations RPC helper --- tezt/lib_tezos/RPC.ml | 20 ++++++++++++++++++++ tezt/lib_tezos/RPC.mli | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tezt/lib_tezos/RPC.ml b/tezt/lib_tezos/RPC.ml index 53b5bd79f0b5..723e7e1ba2e1 100644 --- a/tezt/lib_tezos/RPC.ml +++ b/tezt/lib_tezos/RPC.ml @@ -458,6 +458,26 @@ let get_chain_mempool_pending_operations ?(chain = "main") ?version ?applied ["chains"; chain; "mempool"; "pending_operations"] Fun.id +let get_chain_mempool_monitor_operations ?(chain = "main") ?version ?applied + ?branch_delayed ?branch_refused ?refused ?outdated ?validation_passes () = + let query_string = + Query_arg.opt "version" Fun.id version + @ Query_arg.opt_bool "applied" applied + @ Query_arg.opt_bool "refused" refused + @ Query_arg.opt_bool "outdated" outdated + @ Query_arg.opt_bool "branch_delayed" branch_delayed + @ Query_arg.opt_bool "branch_refused" branch_refused + @ Query_arg.opt_list + "validation_pass" + (fun name vp -> (name, string_of_int vp)) + validation_passes + in + make + ~query_string + GET + ["chains"; chain; "mempool"; "monitor_operations"] + Fun.id + let post_chain_mempool_request_operations ?(chain = "main") ?peer () = make ~query_string:(Query_arg.opt "peer_id" Fun.id peer) diff --git a/tezt/lib_tezos/RPC.mli b/tezt/lib_tezos/RPC.mli index 28d536f84fbf..e89a693052dc 100644 --- a/tezt/lib_tezos/RPC.mli +++ b/tezt/lib_tezos/RPC.mli @@ -460,6 +460,22 @@ val get_chain_mempool_pending_operations : unit -> JSON.t t +(** RPC: [GET /chains//mempool/monitor_operations] + + [chain] defaults to ["main"]. +*) +val get_chain_mempool_monitor_operations : + ?chain:string -> + ?version:string -> + ?applied:bool -> + ?branch_delayed:bool -> + ?branch_refused:bool -> + ?refused:bool -> + ?outdated:bool -> + ?validation_passes:int list -> + unit -> + JSON.t t + (** RPC: [POST /chains//mempool/request_operations] [chain] defaults to ["main"]. -- GitLab From 1bd108372d1b4f3e3e82e488c0a891c6d711c28e Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 6 Jun 2023 11:34:04 +0200 Subject: [PATCH 5/7] test/test: add monitor_operations tests for consensus operations --- tezt/tests/rpc_versioning_attestation.ml | 87 +++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/tezt/tests/rpc_versioning_attestation.ml b/tezt/tests/rpc_versioning_attestation.ml index 621c4794ed85..75b415e236da 100644 --- a/tezt/tests/rpc_versioning_attestation.ml +++ b/tezt/tests/rpc_versioning_attestation.ml @@ -570,11 +570,96 @@ module Mempool = struct Operation.Anonymous.Double_preattestation_evidence protocol + let monitor_mempool node ~use_legacy_name = + let monitor_operations_url = + RPC.( + make_uri + node + (get_chain_mempool_monitor_operations + ~refused:true + ~version:(if use_legacy_name then "0" else "1") + ()) + |> Uri.to_string) + in + RPC.Curl.get monitor_operations_url + + let check_monitor_mempool p name = + let* s = Process.check_and_read_stdout p in + try + let _ = Str.search_forward (Str.regexp name) s 0 in + unit + with Not_found -> Test.fail ~__LOC__ "Kind %s not found in %s" name s + + let check_invalid_monitor_mempool_version node = + let monitor_operations_url = + RPC.( + make_uri + node + (get_chain_mempool_monitor_operations ~refused:true ~version:"2" ()) + |> Uri.to_string) + in + let*? p = RPC.Curl.get monitor_operations_url in + let* s = Process.check_and_read_stdout p in + try + let _ = + Str.( + search_forward + (regexp + "Failed to parse the query string: Failed to parse argument \ + \'version\'")) + s + 0 + in + unit + with Not_found -> + Test.fail + ~__LOC__ + {|RPC call should have return: Failed to parse the query string: Failed to parse argument \'version\' ..|} + + let test_monitor_operations_consensus kind protocol = + let* node, client = Client.init_with_protocol ~protocol `Client () in + let signer = Constant.bootstrap1 in + + let*? p_legacy = monitor_mempool node ~use_legacy_name:true in + let*? p = monitor_mempool node ~use_legacy_name:false in + + let* consensus_op = + create_consensus_op ~use_legacy_name:true ~signer ~kind client + in + let* (`OpHash _) = + Operation.inject ~force:true ~request:`Inject consensus_op client + in + let* () = Client.bake_for_and_wait ~node client in + + let check_monitor_mempool p ~use_legacy_name = + let name = Operation.Consensus.kind_to_string kind use_legacy_name in + check_monitor_mempool p name + in + let* () = check_monitor_mempool p_legacy ~use_legacy_name:true in + let* () = check_monitor_mempool p ~use_legacy_name:false in + check_invalid_monitor_mempool_version node + + let test_monitor_consensus = + register_test + ~title:"Monitor consensus operations" + ~additionnal_tags:["mempool"; "monitor"; "operations"; "consensus"] + @@ fun protocol -> + test_monitor_operations_consensus Operation.Attestation protocol + + let test_monitor_preconsensus = + register_test + ~title:"Monitor pre-consensus operations" + ~additionnal_tags:["mempool"; "monitor"; "operations"; "consensus"; "pre"] + @@ fun protocol -> + test_monitor_operations_consensus Operation.Preattestation protocol + let register ~protocols = test_pending_consensus protocols ; test_pending_preconsensus protocols ; test_pending_double_consensus_evidence protocols ; - test_pending_double_preconsensus_evidence protocols + test_pending_double_preconsensus_evidence protocols ; + test_monitor_consensus protocols ; + test_monitor_preconsensus protocols end module Run_Simulate = struct -- GitLab From 41dacd5820531765f48f82b88d8eaf692f678430 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 6 Jun 2023 11:39:19 +0200 Subject: [PATCH 6/7] tezt/test: add monitor_operations tests for double consensus evidence operations --- tezt/tests/rpc_versioning_attestation.ml | 61 +++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/tezt/tests/rpc_versioning_attestation.ml b/tezt/tests/rpc_versioning_attestation.ml index 75b415e236da..7161aa6f00eb 100644 --- a/tezt/tests/rpc_versioning_attestation.ml +++ b/tezt/tests/rpc_versioning_attestation.ml @@ -653,13 +653,72 @@ module Mempool = struct @@ fun protocol -> test_monitor_operations_consensus Operation.Preattestation protocol + let test_monitor_operations_double_consensus_evidence double_evidence_kind + protocol = + let* node, client = Client.init_with_protocol ~protocol `Client () in + let* () = Client.bake_for_and_wait ~node client in + + let*? p_legacy = monitor_mempool node ~use_legacy_name:true in + let*? p = monitor_mempool node ~use_legacy_name:false in + + let* consensus_op = + create_double_consensus_evidence + ~use_legacy_name:true + ~double_evidence_kind + client + in + let* (`OpHash _) = + Operation.inject ~force:true ~request:`Inject consensus_op client + in + let* () = Client.bake_for_and_wait ~node client in + + let check_monitor_mempool p ~use_legacy_name = + let name = + Operation.Anonymous.kind_to_string double_evidence_kind use_legacy_name + in + check_monitor_mempool p name + in + let* () = check_monitor_mempool p_legacy ~use_legacy_name:true in + let* () = check_monitor_mempool p ~use_legacy_name:false in + check_invalid_monitor_mempool_version node + + let test_monitor_double_consensus_evidence = + register_test + ~title:"Monitor double consensus evidence operations" + ~additionnal_tags: + ["mempool"; "monitor"; "operations"; "double"; "consensus"; "evidence"] + @@ fun protocol -> + test_monitor_operations_double_consensus_evidence + Operation.Anonymous.Double_attestation_evidence + protocol + + let test_monitor_double_preconsensus_evidence = + register_test + ~title:"Monitor double pre-consensus evidence operations" + ~additionnal_tags: + [ + "mempool"; + "monitor"; + "operations"; + "double"; + "consensus"; + "pre"; + "evidence"; + ] + @@ fun protocol -> + test_monitor_operations_double_consensus_evidence + Operation.Anonymous.Double_preattestation_evidence + protocol + let register ~protocols = test_pending_consensus protocols ; test_pending_preconsensus protocols ; test_pending_double_consensus_evidence protocols ; test_pending_double_preconsensus_evidence protocols ; test_monitor_consensus protocols ; - test_monitor_preconsensus protocols + test_monitor_preconsensus protocols ; + test_monitor_double_consensus_evidence protocols ; + test_monitor_double_preconsensus_evidence protocols end module Run_Simulate = struct -- GitLab From eb5dbbdf9f4805d3905f5bf0b34623dba324f215 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 5 Jun 2023 17:33:33 +0200 Subject: [PATCH 7/7] changes: add entry for new version parameter of mempool/monitor_operations RPC --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 46587542c179..d3a0076e4c1e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -136,6 +136,12 @@ Node the "reverting its effect if it was applied" part since operations are never applied.) (MR :gl:`!8857`) +- Added version ``1`` to RPC ``POST ../mempool/monitor_operations``. It can be + used by calling the RPC with the parameter ``?version=1`` (default version is + still ``0``). Version ``1`` allows the RPC to output ``attestation``, + ``preattestation``, ``double_attestation_evidence`` and + ``double_preattestation_evidence`` kinds in the JSON result. (MR :gl:`!8980`) + Client ------ - Adding client commands to generate, open and verify a time-lock. -- GitLab