From 0ad171166de14cce2815e411d494431e4714a4a9 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 May 2024 13:31:01 +0200 Subject: [PATCH 1/4] alpha: remove supports for RPC version with legacy attestation --- src/proto_alpha/lib_plugin/RPC.ml | 145 +++++------------------------- 1 file changed, 24 insertions(+), 121 deletions(-) diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index e8c0d72df73a..1f6d9da372b1 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -29,60 +29,24 @@ open Protocol open Environment open Alpha_context -type version = Version_0 | Version_1 +type version = Version_1 -let string_of_version = function Version_0 -> "0" | Version_1 -> "1" +let string_of_version = function Version_1 -> "1" let version_of_string = function - | "0" -> Ok Version_0 + | "0" -> Error "Version \"0\" is not supported anymore" | "1" -> Ok Version_1 - | _ -> Error "Cannot parse version (supported versions \"0\" and \"1\")" - -let default_operations_version = Version_1 + | _ -> Error "Cannot parse version (supported version \"1\")" let version_arg = let open RPC_arg in make - ~descr: - "Supported RPC versions are version '1' (default) that will output \ - \"attestation\" in the \"kind\" field and version '0' (deprecated) that \ - will output \"endorsement\"" + ~descr:"Supported RPC version is version '1'" ~name:"version" ~destruct:version_of_string ~construct:string_of_version () -(* This function creates an encoding that use the [latest_encoding] in binary - and that can use [latest_encoding] and any [old_encodings] in JSON. The - version value is only used to decide which encoding to use in JSON. *) -let encoding_versioning ~encoding_name ~latest_encoding ~old_encodings = - let open Data_encoding in - let make_case ~version ~encoding = - case - ~title: - (Format.sprintf - "%s_encoding_v%s" - encoding_name - (string_of_version version)) - Json_only - encoding - (function v, value when v == version -> Some value | _v, _value -> None) - (fun value -> (version, value)) - in - let latest_version, latest_encoding = latest_encoding in - splitted - ~binary: - (conv - (fun (_, value) -> value) - (fun value -> (latest_version, value)) - latest_encoding) - ~json: - (union - (make_case ~version:latest_version ~encoding:latest_encoding - :: List.map - (fun (version, encoding) -> make_case ~version ~encoding) - old_encodings)) - (** The assumed number of blocks between operation-creation time and the actual time when the operation is included in a block. *) let default_operation_inclusion_latency = 3 @@ -553,39 +517,11 @@ module Scripts = struct object method version = version end) - |+ field "version" version_arg default_operations_version (fun t -> - t#version) + |+ opt_field "version" version_arg (fun t -> t#version) |> seal - let operations_encodings = - union - [ - case - ~title:"operations_encoding" - (Tag 0) - Operation.encoding - Option.some - Fun.id; - case - ~title:"operations_encoding_with_legacy_attestation_name" - Json_only - Operation.encoding_with_legacy_attestation_name - Option.some - Fun.id; - ] - let run_operation_output_encoding = - encoding_versioning - ~encoding_name:"run_operation_output" - ~latest_encoding: - (Version_1, Apply_results.operation_data_and_metadata_encoding) - ~old_encodings: - [ - ( Version_0, - Apply_results - .operation_data_and_metadata_encoding_with_legacy_attestation_name - ); - ] + Apply_results.operation_data_and_metadata_encoding let run_operation = RPC_service.post_service @@ -597,7 +533,7 @@ module Scripts = struct ~query:run_operation_query ~input: (obj2 - (req "operation" operations_encodings) + (req "operation" Operation.encoding) (req "chain_id" Chain_id.encoding)) ~output:run_operation_output_encoding RPC_path.(path / "run_operation") @@ -610,8 +546,7 @@ module Scripts = struct method successor_level = successor_level end) - |+ field "version" version_arg default_operations_version (fun t -> - t#version) + |+ opt_field "version" version_arg (fun t -> t#version) |+ flag ~descr: "If true, the simulation is done on the successor level of the \ @@ -634,7 +569,7 @@ module Scripts = struct ~input: (obj4 (opt "blocks_before_activation" int32) - (req "operation" operations_encodings) + (req "operation" Operation.encoding) (req "chain_id" Chain_id.encoding) (dft "latency" int16 default_operation_inclusion_latency)) ~output:run_operation_output_encoding @@ -1137,7 +1072,7 @@ module Scripts = struct Return the unchanged operation protocol data, and the operation receipt ie. metadata containing balance updates, consumed gas, application success or failure, etc. *) - let run_operation_service rpc_ctxt params (packed_operation, chain_id) = + let run_operation_service rpc_ctxt _params (packed_operation, chain_id) = let open Lwt_result_syntax in let {Services_registration.context; block_header; _} = rpc_ctxt in let*? () = @@ -1179,7 +1114,7 @@ module Scripts = struct let* _ctxt, op_metadata = Apply.apply_operation application_state oph packed_operation in - return (params#version, (packed_operation.protocol_data, op_metadata)) + return (packed_operation.protocol_data, op_metadata) (* @@ -2216,10 +2151,9 @@ module Scripts = struct let normalize_type ~ty ctxt block = RPC_context.make_call0 S.normalize_type ctxt block () ty - let run_operation ~op ~chain_id ?(version = default_operations_version) ctxt - block = + let run_operation ~op ~chain_id ?version ctxt block = let open Lwt_result_syntax in - let* (Version_0 | Version_1), run_operation = + let* run_operation = RPC_context.make_call0 S.run_operation ctxt @@ -2231,11 +2165,10 @@ module Scripts = struct in return run_operation - let simulate_operation ~op ~chain_id ~latency - ?(version = default_operations_version) ?(successor_level = false) - ?blocks_before_activation ctxt block = + let simulate_operation ~op ~chain_id ~latency ?version + ?(successor_level = false) ?blocks_before_activation ctxt block = let open Lwt_result_syntax in - let* (Version_0 | Version_1), simulate_operation = + let* simulate_operation = RPC_context.make_call0 S.simulate_operation ctxt @@ -3285,28 +3218,11 @@ module Forge = struct let path = RPC_path.(path / "forge") - let operations_encoding = - union - [ - case - ~title:"operations_encoding" - (Tag 0) - Operation.unsigned_encoding - Option.some - Fun.id; - case - ~title:"operations_encoding_with_legacy_attestation_name" - Json_only - Operation.unsigned_encoding_with_legacy_attestation_name - Option.some - Fun.id; - ] - let operations = RPC_service.post_service ~description:"Forge an operation" ~query:RPC_query.empty - ~input:operations_encoding + ~input:Operation.unsigned_encoding ~output:(bytes Hex) RPC_path.(path / "operations") @@ -3536,21 +3452,10 @@ module Parse = struct object method version = version end) - |+ field "version" version_arg default_operations_version (fun t -> - t#version) + |+ opt_field "version" version_arg (fun t -> t#version) |> seal - let parse_operations_encoding = - encoding_versioning - ~encoding_name:"parse_operations" - ~latest_encoding:(Version_1, list (dynamic_size Operation.encoding)) - ~old_encodings: - [ - ( Version_0, - list - (dynamic_size Operation.encoding_with_legacy_attestation_name) - ); - ] + let parse_operations_encoding = list (dynamic_size Operation.encoding) let operations = RPC_service.post_service @@ -3596,7 +3501,7 @@ module Parse = struct Registration.register0 ~chunked:true S.operations - (fun _ctxt params (operations, check) -> + (fun _ctxt _params (operations, check) -> let* ops = List.map_es (fun raw -> @@ -3614,13 +3519,11 @@ module Parse = struct return op) operations in - let version = params#version in - return (version, ops)) ; + return ops) ; Registration.register0_noctxt ~chunked:false S.block (fun () raw_block -> return @@ parse_protocol_data raw_block.protocol_data) - let operations ctxt block ?(version = default_operations_version) ?check - operations = + let operations ctxt block ?version ?check operations = let open Lwt_result_syntax in let*! v = RPC_context.make_call0 @@ -3634,7 +3537,7 @@ module Parse = struct in match v with | Error e -> tzfail e - | Ok ((Version_0 | Version_1), parse_operation) -> return parse_operation + | Ok parse_operation -> return parse_operation let block ctxt block shell protocol_data = RPC_context.make_call0 -- GitLab From 30c5a67e219ceb02cd01d46204f482dcf2667ad7 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 28 Jun 2024 11:09:29 +0200 Subject: [PATCH 2/4] tezt/tests: fix double_consensus tests --- tezt/tests/double_consensus.ml | 42 ++++++++++++---------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/tezt/tests/double_consensus.ml b/tezt/tests/double_consensus.ml index 603a27484828..5c0ec74649bf 100644 --- a/tezt/tests/double_consensus.ml +++ b/tezt/tests/double_consensus.ml @@ -32,22 +32,13 @@ let team = Tag.layer1 -let use_legacy_attestation_name protocol = Protocol.number protocol < 18 - -let get_consensus_operation_name protocol = - if use_legacy_attestation_name protocol then "endorsement" else "attestation" - -let double_attestation_waiter ~protocol accuser = - Accuser.wait_for - accuser - (sf "double_%s_denounced.v0" (get_consensus_operation_name protocol)) - (fun _ -> Some ()) +let double_attestation_waiter accuser = + Accuser.wait_for accuser (sf "double_attestation_denounced.v0") (fun _ -> + Some ()) -let double_preattestation_waiter ~protocol accuser = - Accuser.wait_for - accuser - (sf "double_pre%s_denounced.v0" (get_consensus_operation_name protocol)) - (fun _ -> Some ()) +let double_preattestation_waiter accuser = + Accuser.wait_for accuser (sf "double_preattestation_denounced.v0") (fun _ -> + Some ()) let double_consensus_already_denounced_waiter accuser oph = Accuser.wait_for accuser "double_consensus_already_denounced.v0" (fun json -> @@ -120,7 +111,6 @@ let double_attestation_init let double_consensus_wrong_slot (consensus_for, mk_consensus, consensus_waiter, consensus_name) protocol = - let consensus_name = consensus_name protocol in let* (client, accuser), (branch, level, round, slots, block_payload_hash) = double_attestation_init consensus_for consensus_name protocol () in @@ -128,7 +118,7 @@ let double_consensus_wrong_slot let op = mk_consensus ~slot:(List.nth slots 1) ~level ~round ~block_payload_hash in - let waiter = consensus_waiter ~protocol accuser in + let waiter = consensus_waiter accuser in let* _ = Operation.Consensus.inject ~branch ~signer:Constant.bootstrap1 op client in @@ -153,20 +143,20 @@ let attest_utils = ( Client.attest_for, (fun ~slot ~level ~round ~block_payload_hash -> Operation.Consensus.attestation - ~use_legacy_name:true + ~use_legacy_name:false ~slot ~level ~round ~block_payload_hash ()), double_attestation_waiter, - get_consensus_operation_name ) + "attestation" ) let preattest_utils = ( Client.preattest_for, - Operation.Consensus.preattestation ~use_legacy_name:true, + Operation.Consensus.preattestation ~use_legacy_name:false, double_preattestation_waiter, - fun protocol -> sf "pre%s" (get_consensus_operation_name protocol) ) + "preattestation" ) let double_attestation_wrong_slot = Protocol.register_test @@ -186,7 +176,6 @@ let double_preattestation_wrong_slot = let double_consensus_wrong_block_payload_hash (consensus_for, mk_consensus, consensus_waiter, consensus_name) protocol = - let consensus_name = consensus_name protocol in let* (client, accuser), (branch, level, round, slots, _block_payload_hash) = double_attestation_init consensus_for consensus_name protocol () in @@ -198,7 +187,7 @@ let double_consensus_wrong_block_payload_hash let op = mk_consensus ~slot:(List.nth slots 0) ~level ~round ~block_payload_hash in - let waiter = consensus_waiter ~protocol accuser in + let waiter = consensus_waiter accuser in let* _ = Operation.Consensus.inject ~force:true @@ -269,7 +258,6 @@ let double_preattestation_wrong_block_payload_hash = let double_consensus_wrong_branch (consensus_for, mk_consensus, consensus_waiter, consensus_name) protocol = - let consensus_name = consensus_name protocol in let* (client, accuser), (_branch, level, round, slots, block_payload_hash) = double_attestation_init consensus_for consensus_name protocol () in @@ -278,7 +266,7 @@ let double_consensus_wrong_branch let op = mk_consensus ~slot:(List.nth slots 0) ~level ~round ~block_payload_hash in - let waiter = consensus_waiter ~protocol accuser in + let waiter = consensus_waiter accuser in let* _ = Operation.Consensus.inject ~force:true @@ -374,7 +362,7 @@ let operation_too_old = [consensus_operation_too_old.v0] event from the accuser." ; let op = Operation.Consensus.attestation - ~use_legacy_name:(use_legacy_attestation_name protocol) + ~use_legacy_name:false ~slot ~level ~round:3 @@ -452,7 +440,7 @@ let operation_too_far_in_future = [consensus_operation_too_far_in_future.v0] event from the accuser." ; let op = Operation.Consensus.attestation - ~use_legacy_name:(use_legacy_attestation_name protocol) + ~use_legacy_name:false ~slot:(List.hd slots) ~level ~round:0 -- GitLab From af382e04978c165942d4a8534fc40aa0a492ec5e Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 28 Jun 2024 11:16:47 +0200 Subject: [PATCH 3/4] tezt/tests: fix prevalidator tests --- tezt/tests/prevalidator.ml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tezt/tests/prevalidator.ml b/tezt/tests/prevalidator.ml index f4dd089e61fa..00c6d63a4c2b 100644 --- a/tezt/tests/prevalidator.ml +++ b/tezt/tests/prevalidator.ml @@ -1890,7 +1890,7 @@ module Revamped = struct let inject_attestation (delegate : Account.key) = Operation.Consensus.inject (Operation.Consensus.attestation - ~use_legacy_name:true + ~use_legacy_name:false ~slot:(Operation.Consensus.first_slot ~slots_json delegate) ~level ~round:0 @@ -2142,7 +2142,7 @@ module Revamped = struct let* op = Operation.Consensus.operation (Operation.Consensus.attestation - ~use_legacy_name:true + ~use_legacy_name:false ~slot:(Operation.Consensus.first_slot ~slots_json delegate) ~level ~round:0 @@ -2404,7 +2404,7 @@ module Revamped = struct let inject_attestation (account : Account.key) = Operation.Consensus.inject (Operation.Consensus.attestation - ~use_legacy_name:true + ~use_legacy_name:false ~slot:(Operation.Consensus.first_slot ~slots_json account) ~level ~round:0 @@ -2538,7 +2538,7 @@ module Revamped = struct let inject_attestation ~(account : Account.key) ~(signer : Account.key) = Operation.Consensus.inject (Operation.Consensus.attestation - ~use_legacy_name:true + ~use_legacy_name:false ~slot:(Operation.Consensus.first_slot ~slots_json account) ~level ~round:0 @@ -2734,9 +2734,7 @@ module Revamped = struct let branch = JSON.(op |-> "branch" |> as_string) in let content = JSON.(op |-> "contents" |> as_list |> List.hd) in let kind = JSON.(content |-> "kind" |> as_string) in - let expected_kind = - if Protocol.number protocol < 018 then "endorsement" else "attestation" - in + let expected_kind = "attestation" in Check.( (expected_kind = kind) string @@ -2749,7 +2747,7 @@ module Revamped = struct in let op = Operation.Consensus.attestation - ~use_legacy_name:true + ~use_legacy_name:false ~slot ~level ~round -- GitLab From 90282d7fbcf78cd5960dbb57982774da13f23298 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Mon, 27 May 2024 13:45:04 +0200 Subject: [PATCH 4/4] changes: add entry for removal of RPC versions --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index ac4a940fe9fa..b02fe54c8ae7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -67,6 +67,10 @@ Node - Remove support for deprecated version ``1`` for RPC ``GET ../mempool/pending_operations``. (MR :gl:`!13449`) +- Remove support for deprecated version ``0`` from RPCs ``POST + ../helpers/parse/operations``, ``POST ../helpers/scripts/run_operation`` and + ``POST ../helpers/scripts/simulate_operation``. (MR :gl:`!13451`) + Client ------ -- GitLab