diff --git a/CHANGES.rst b/CHANGES.rst index 46587542c179edc49af6cdd4cdfba1713ac4f386..d3a0076e4c1edd3bf324946f7343e36b27466088 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. diff --git a/src/lib_shell/prevalidator_internal.ml b/src/lib_shell/prevalidator_internal.ml index 48a685141b6b437e5e21c9059f4954fd19dc1ede..b38c496ad11cd0baa21141f230615593c861c226 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 bad6d7f60f07554fc78dcededaff4b520511772f..4299c6a8b5e72506ff66728f928464b74b87d372 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 @@ -484,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}) @@ -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 @@ -1355,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 @@ -1367,6 +1392,8 @@ module Make (Proto : PROTO) (Next_proto : PROTO) = struct validation_passes -> object + method version = version + method validated = validated method refused = refused @@ -1379,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 @@ -1422,18 +1454,49 @@ 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 + (* 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" + (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 = @@ -1736,14 +1799,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 +1826,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 @@ -1781,28 +1840,45 @@ 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_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 () = 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 0cc9234260fa70b2174fa69b88e44b8e6309cddc..be26ee2122cf7e9537dd171c629dd1ccb17516c3 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]. @@ -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 -> @@ -725,7 +726,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 +734,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 *) @@ -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 6498615c7c95919f61dceacea6ab09bdfe40861f..9a6603cbee91e3fa2a813d3138aeba01348e0a02 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 208aaec3cc350dc43a0d9990b996ad5fd35600ad..3c023176b1060cbb21cf8d2f60b2b622c73cc128 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 2c9a6e367db94c017fcbdabcdd594b464f6a6c74..e64e5a88da9ee5ec4e999c3353aa1440997852c1 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 6e7eabda0bae2ca282191fbc78e4eed04062d109..5fb836f50f346606877e37ae9672cecbdc06339e 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 2c9a6e367db94c017fcbdabcdd594b464f6a6c74..e64e5a88da9ee5ec4e999c3353aa1440997852c1 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 a08de0408a0ee511ce9143bf9e289624ec879eab..0fe62d4c5fef666d0e172be1ac7850907178b039 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 diff --git a/tezt/lib_tezos/RPC.ml b/tezt/lib_tezos/RPC.ml index 53b5bd79f0b5f723d0b3ec279705f1aaa9b6c4d0..723e7e1ba2e1f637a66a42760f8a05e2c9bb7c6c 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 28d536f84fbfd03ded1f923447f6ded7d2fd7330..e89a693052dc9cb206b2ebd2b4915ca58000f60a 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"]. diff --git a/tezt/tests/rpc_versioning_attestation.ml b/tezt/tests/rpc_versioning_attestation.ml index 621c4794ed85e752961208ffa43c8b3bb1b4c9fd..7161aa6f00eb0cf82c31f1eee23f37af0be1310b 100644 --- a/tezt/tests/rpc_versioning_attestation.ml +++ b/tezt/tests/rpc_versioning_attestation.ml @@ -570,11 +570,155 @@ 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 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_pending_double_preconsensus_evidence protocols ; + test_monitor_consensus protocols ; + test_monitor_preconsensus protocols ; + test_monitor_double_consensus_evidence protocols ; + test_monitor_double_preconsensus_evidence protocols end module Run_Simulate = struct