From 955fc13b6e57ced0317b31b694e49bb2dac50266 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Tue, 9 May 2023 08:46:05 +0200 Subject: [PATCH 1/5] proto_alpha: factorise consensus_result type --- .../lib_client/operation_result.ml | 12 +++--- src/proto_alpha/lib_protocol/apply.ml | 8 ++-- src/proto_alpha/lib_protocol/apply_results.ml | 43 +++++++++---------- .../lib_protocol/apply_results.mli | 4 +- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index 5e2614aaee8d..ce9f58e15b9e 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -876,38 +876,38 @@ let pp_contents_and_result : bus | ( Preendorsement {level; _}, Preendorsement_result - {balance_updates; delegate; consensus_key; preendorsement_power} ) -> + {balance_updates; delegate; consensus_key; consensus_power} ) -> Format.fprintf ppf "@[Preendorsement:@,\ Level: %a@,\ Balance updates:%a@,\ Delegate: %a@,\ - Preendorsement Power: %d@]" + Consensus Power: %d@]" Raw_level.pp level pp_balance_updates balance_updates Consensus_key.pp {delegate; consensus_pkh = consensus_key} - preendorsement_power + consensus_power | ( Endorsement {level; _}, Endorsement_result - {balance_updates; delegate; consensus_key; endorsement_power} ) -> + {balance_updates; delegate; consensus_key; consensus_power} ) -> Format.fprintf ppf "@[Endorsement:@,\ Level: %a@,\ Balance updates:%a@,\ Delegate: %a@,\ - Endorsement power: %d@]" + Consensus Power: %d@]" Raw_level.pp level pp_balance_updates balance_updates Consensus_key.pp {delegate; consensus_pkh = consensus_key} - endorsement_power + consensus_power | Dal_attestation _, Dal_attestation_result {delegate} -> Format.fprintf ppf diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 36a7341e4a5f..ef8e834c63bc 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -1767,14 +1767,14 @@ let record_preendorsement ctxt (mode : mode) (content : consensus_content) : | Application _ | Partial_construction _ -> ctxt in let mk_preendorsement_result ({delegate; consensus_pkh; _} : Consensus_key.pk) - preendorsement_power = + consensus_power = Single_result (Preendorsement_result { balance_updates = []; delegate; consensus_key = consensus_pkh; - preendorsement_power; + consensus_power; }) in match mode with @@ -1808,14 +1808,14 @@ let record_endorsement ctxt (mode : mode) (content : consensus_content) : (context * Kind.endorsement contents_result_list) tzresult Lwt.t = let open Lwt_result_syntax in let mk_endorsement_result ({delegate; consensus_pkh; _} : Consensus_key.pk) - endorsement_power = + consensus_power = Single_result (Endorsement_result { balance_updates = []; delegate; consensus_key = consensus_pkh; - endorsement_power; + consensus_power; }) in match mode with diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index 9778fad1feb8..45526d861b6e 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -868,14 +868,14 @@ type 'kind contents_result = balance_updates : Receipt.balance_updates; delegate : Signature.public_key_hash; consensus_key : Signature.public_key_hash; - preendorsement_power : int; + consensus_power : int; } -> Kind.preendorsement contents_result | Endorsement_result : { balance_updates : Receipt.balance_updates; delegate : Signature.public_key_hash; consensus_key : Signature.public_key_hash; - endorsement_power : int; + consensus_power : int; } -> Kind.endorsement contents_result | Dal_attestation_result : { @@ -1001,6 +1001,14 @@ let equal_manager_kind : | Kind.Zk_rollup_update_manager_kind, _ -> None module Encoding = struct + let consensus_result_encoding power_name = + let open Data_encoding in + obj4 + (dft "balance_updates" Receipt.balance_updates_encoding []) + (req "delegate" Signature.Public_key_hash.encoding) + (req (Format.asprintf "%s_power" power_name) int31) + (req "consensus_key" Signature.Public_key_hash.encoding) + type 'kind case = | Case : { op_case : 'kind Operation.Encoding.case; @@ -1027,12 +1035,7 @@ module Encoding = struct Case { op_case = Operation.Encoding.preendorsement_case; - encoding = - obj4 - (dft "balance_updates" Receipt.balance_updates_encoding []) - (req "delegate" Signature.Public_key_hash.encoding) - (req "preendorsement_power" int31) - (req "consensus_key" Signature.Public_key_hash.encoding); + encoding = consensus_result_encoding "preendorsement"; select = (function | Contents_result (Preendorsement_result _ as op) -> Some op @@ -1044,25 +1047,19 @@ module Encoding = struct proj = (function | Preendorsement_result - {balance_updates; delegate; consensus_key; preendorsement_power} - -> - (balance_updates, delegate, preendorsement_power, consensus_key)); + {balance_updates; delegate; consensus_key; consensus_power} -> + (balance_updates, delegate, consensus_power, consensus_key)); inj = - (fun (balance_updates, delegate, preendorsement_power, consensus_key) -> + (fun (balance_updates, delegate, consensus_power, consensus_key) -> Preendorsement_result - {balance_updates; delegate; consensus_key; preendorsement_power}); + {balance_updates; delegate; consensus_key; consensus_power}); } let endorsement_case = Case { op_case = Operation.Encoding.endorsement_case; - encoding = - obj4 - (dft "balance_updates" Receipt.balance_updates_encoding []) - (req "delegate" Signature.Public_key_hash.encoding) - (req "endorsement_power" int31) - (req "consensus_key" Signature.Public_key_hash.encoding); + encoding = consensus_result_encoding "endorsement"; select = (function | Contents_result (Endorsement_result _ as op) -> Some op | _ -> None); @@ -1073,12 +1070,12 @@ module Encoding = struct proj = (function | Endorsement_result - {balance_updates; delegate; consensus_key; endorsement_power} -> - (balance_updates, delegate, endorsement_power, consensus_key)); + {balance_updates; delegate; consensus_key; consensus_power} -> + (balance_updates, delegate, consensus_power, consensus_key)); inj = - (fun (balance_updates, delegate, endorsement_power, consensus_key) -> + (fun (balance_updates, delegate, consensus_power, consensus_key) -> Endorsement_result - {balance_updates; delegate; consensus_key; endorsement_power}); + {balance_updates; delegate; consensus_key; consensus_power}); } let dal_attestation_case = diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index 6011179e6dd9..844b62a279ed 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -62,14 +62,14 @@ and 'kind contents_result = balance_updates : Receipt.balance_updates; delegate : Signature.public_key_hash; consensus_key : Signature.public_key_hash; - preendorsement_power : int; + consensus_power : int; } -> Kind.preendorsement contents_result | Endorsement_result : { balance_updates : Receipt.balance_updates; delegate : Signature.public_key_hash; consensus_key : Signature.public_key_hash; - endorsement_power : int; + consensus_power : int; } -> Kind.endorsement contents_result | Dal_attestation_result : { -- GitLab From b0be840ec18af7ef49d87b6807115f02b0751d3a Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 26 Apr 2023 16:23:41 +0200 Subject: [PATCH 2/5] proto_alpha: copy apply_results encodings as legacy ones --- src/proto_alpha/lib_plugin/RPC.ml | 8 +- src/proto_alpha/lib_protocol/apply_results.ml | 296 +++++++++++------- .../lib_protocol/apply_results.mli | 9 + src/proto_alpha/lib_protocol/main.ml | 6 +- 4 files changed, 202 insertions(+), 117 deletions(-) diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index cf0632ff6105..63cdadee13cb 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -430,7 +430,9 @@ module Scripts = struct (obj2 (req "operation" Operation.encoding_with_legacy_attestation_name) (req "chain_id" Chain_id.encoding)) - ~output:Apply_results.operation_data_and_metadata_encoding + ~output: + Apply_results + .operation_data_and_metadata_encoding_with_legacy_attestation_name RPC_path.(path / "run_operation") let simulate_query = @@ -464,7 +466,9 @@ module Scripts = struct (req "operation" Operation.encoding_with_legacy_attestation_name) (req "chain_id" Chain_id.encoding) (dft "latency" int16 default_operation_inclusion_latency)) - ~output:Apply_results.operation_data_and_metadata_encoding + ~output: + Apply_results + .operation_data_and_metadata_encoding_with_legacy_attestation_name RPC_path.(path / "simulate_operation") let entrypoint_type = diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index 45526d861b6e..0b1dbf8512d1 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -1009,7 +1009,7 @@ module Encoding = struct (req (Format.asprintf "%s_power" power_name) int31) (req "consensus_key" Signature.Public_key_hash.encoding) - type 'kind case = + type case = | Case : { op_case : 'kind Operation.Encoding.case; encoding : 'a Data_encoding.t; @@ -1020,7 +1020,7 @@ module Encoding = struct proj : 'kind contents_result -> 'a; inj : 'a -> 'kind contents_result; } - -> 'kind case + -> case let tagged_case tag name args proj inj = let open Data_encoding in @@ -1587,118 +1587,105 @@ module Encoding = struct | _ -> None) end -let contents_result_encoding = +let common_cases = let open Encoding in - let make - (Case - { - op_case = Operation.Encoding.Case {tag; name; _}; - encoding; - mselect = _; - select; - proj; - inj; - }) = - let proj x = match select x with None -> None | Some x -> Some (proj x) in - let inj x = Contents_result (inj x) in - tagged_case (Tag tag) name encoding proj inj - in + [ + seed_nonce_revelation_case; + vdf_revelation_case; + dal_attestation_case; + double_baking_evidence_case; + activate_account_case; + proposals_case; + ballot_case; + drain_delegate_case; + reveal_case; + transaction_case; + origination_case; + delegation_case; + register_global_constant_case; + set_deposits_limit_case; + increase_paid_storage_case; + update_consensus_key_case; + transfer_ticket_case; + dal_publish_slot_header_case; + sc_rollup_originate_case; + sc_rollup_add_messages_case; + sc_rollup_cement_case; + sc_rollup_publish_case; + sc_rollup_refute_case; + sc_rollup_timeout_case; + sc_rollup_execute_outbox_message_case; + sc_rollup_recover_bond_case; + zk_rollup_origination_case; + zk_rollup_publish_case; + zk_rollup_update_case; + ] + +let contents_cases = + let open Encoding in + endorsement_case :: preendorsement_case :: double_endorsement_evidence_case + :: double_preendorsement_evidence_case :: common_cases + +let contents_cases_with_legacy_attestation_name = + let open Encoding in + endorsement_case :: preendorsement_case :: double_endorsement_evidence_case + :: double_preendorsement_evidence_case :: common_cases + +let make_contents_result + (Encoding.Case + { + op_case = Operation.Encoding.Case {tag; name; _}; + encoding; + mselect = _; + select; + proj; + inj; + }) = + let proj x = match select x with None -> None | Some x -> Some (proj x) in + let inj x = Contents_result (inj x) in + Encoding.tagged_case (Tag tag) name encoding proj inj + +let contents_result_encoding = def "operation.alpha.contents_result" + @@ union (List.map make_contents_result contents_cases) + +let contents_result_encoding_with_legacy_attestation_name = + def "operation_with_legacy_attestation_name.alpha.contents_result" @@ union - [ - make seed_nonce_revelation_case; - make vdf_revelation_case; - make endorsement_case; - make preendorsement_case; - make dal_attestation_case; - make double_preendorsement_evidence_case; - make double_endorsement_evidence_case; - make double_baking_evidence_case; - make activate_account_case; - make proposals_case; - make ballot_case; - make drain_delegate_case; - make reveal_case; - make transaction_case; - make origination_case; - make delegation_case; - make register_global_constant_case; - make set_deposits_limit_case; - make increase_paid_storage_case; - make update_consensus_key_case; - make transfer_ticket_case; - make dal_publish_slot_header_case; - make sc_rollup_originate_case; - make sc_rollup_add_messages_case; - make sc_rollup_cement_case; - make sc_rollup_publish_case; - make sc_rollup_refute_case; - make sc_rollup_timeout_case; - make sc_rollup_execute_outbox_message_case; - make sc_rollup_recover_bond_case; - make zk_rollup_origination_case; - make zk_rollup_publish_case; - make zk_rollup_update_case; - ] + (List.map + make_contents_result + contents_cases_with_legacy_attestation_name) -let contents_and_result_encoding = - let open Encoding in - let make - (Case - { - op_case = Operation.Encoding.Case {tag; name; encoding; proj; inj; _}; - mselect; - encoding = meta_encoding; - proj = meta_proj; - inj = meta_inj; - _; - }) = - let proj c = - match mselect c with - | Some (op, res) -> Some (proj op, meta_proj res) - | _ -> None - in - let inj (op, res) = Contents_and_result (inj op, meta_inj res) in - let encoding = merge_objs encoding (obj1 (req "metadata" meta_encoding)) in - tagged_case (Tag tag) name encoding proj inj +let make_contents_and_result + (Encoding.Case + { + op_case = Operation.Encoding.Case {tag; name; encoding; proj; inj; _}; + mselect; + encoding = meta_encoding; + proj = meta_proj; + inj = meta_inj; + _; + }) = + let proj c = + match mselect c with + | Some (op, res) -> Some (proj op, meta_proj res) + | _ -> None in + let inj (op, res) = Contents_and_result (inj op, meta_inj res) in + let encoding = merge_objs encoding (obj1 (req "metadata" meta_encoding)) in + Encoding.tagged_case (Tag tag) name encoding proj inj + +let contents_and_result_encoding = def "operation.alpha.operation_contents_and_result" + @@ union (List.map make_contents_and_result contents_cases) + +let contents_and_result_encoding_with_legacy_attestation_name = + def + "operation_with_legacy_attestation_name.alpha.operation_contents_and_result" @@ union - [ - make seed_nonce_revelation_case; - make vdf_revelation_case; - make endorsement_case; - make preendorsement_case; - make dal_attestation_case; - make double_preendorsement_evidence_case; - make double_endorsement_evidence_case; - make double_baking_evidence_case; - make activate_account_case; - make proposals_case; - make ballot_case; - make reveal_case; - make transaction_case; - make origination_case; - make delegation_case; - make register_global_constant_case; - make set_deposits_limit_case; - make increase_paid_storage_case; - make update_consensus_key_case; - make drain_delegate_case; - make transfer_ticket_case; - make dal_publish_slot_header_case; - make sc_rollup_originate_case; - make sc_rollup_add_messages_case; - make sc_rollup_cement_case; - make sc_rollup_publish_case; - make sc_rollup_refute_case; - make sc_rollup_timeout_case; - make sc_rollup_execute_outbox_message_case; - make sc_rollup_recover_bond_case; - make zk_rollup_origination_case; - make zk_rollup_publish_case; - make zk_rollup_update_case; - ] + (List.map + make_contents_and_result + contents_cases_with_legacy_attestation_name) type 'kind contents_result_list = | Single_result : 'kind contents_result -> 'kind contents_result_list @@ -1712,7 +1699,8 @@ type packed_contents_result_list = 'kind contents_result_list -> packed_contents_result_list -let contents_result_list_encoding = +let contents_result_list_conv_with_guard = + let open Result_syntax in let rec to_list = function | Contents_result_list (Single_result o) -> [Contents_result o] | Contents_result_list (Cons_result (o, os)) -> @@ -1722,7 +1710,7 @@ let contents_result_list_encoding = | [] -> Error "cannot decode empty operation result" | [Contents_result o] -> Ok (Contents_result_list (Single_result o)) | Contents_result o :: os -> ( - of_list os >>? fun (Contents_result_list os) -> + let* (Contents_result_list os) = of_list os in match (o, os) with | Manager_operation_result _, Single_result (Manager_operation_result _) -> @@ -1731,8 +1719,16 @@ let contents_result_list_encoding = Ok (Contents_result_list (Cons_result (o, os))) | _ -> Error "cannot decode ill-formed operation result") in + conv_with_guard to_list of_list + +let contents_result_list_encoding = def "operation.alpha.contents_list_result" - @@ conv_with_guard to_list of_list (list contents_result_encoding) + @@ contents_result_list_conv_with_guard (list contents_result_encoding) + +let contents_result_list_encoding_with_legacy_attestation_name = + def "operation_with_legacy_attestation_name.alpha.contents_list_result" + @@ contents_result_list_conv_with_guard + (list contents_result_encoding_with_legacy_attestation_name) type 'kind contents_and_result_list = | Single_and_result : @@ -1749,7 +1745,8 @@ type packed_contents_and_result_list = 'kind contents_and_result_list -> packed_contents_and_result_list -let contents_and_result_list_encoding = +let contents_and_result_conv_with_guard = + let open Result_syntax in let rec to_list = function | Contents_and_result_list (Single_and_result (op, res)) -> [Contents_and_result (op, res)] @@ -1761,7 +1758,7 @@ let contents_and_result_list_encoding = | [Contents_and_result (op, res)] -> Ok (Contents_and_result_list (Single_and_result (op, res))) | Contents_and_result (op, res) :: rest -> ( - of_list rest >>? fun (Contents_and_result_list rest) -> + let* (Contents_and_result_list rest) = of_list rest in match (op, rest) with | Manager_operation _, Single_and_result (Manager_operation _, _) -> Ok (Contents_and_result_list (Cons_and_result (op, res, rest))) @@ -1769,7 +1766,15 @@ let contents_and_result_list_encoding = Ok (Contents_and_result_list (Cons_and_result (op, res, rest))) | _ -> Error "cannot decode ill-formed combined operation result") in - conv_with_guard to_list of_list (Variable.list contents_and_result_encoding) + conv_with_guard to_list of_list + +let contents_and_result_list_encoding = + contents_and_result_conv_with_guard + (Variable.list contents_and_result_encoding) + +let contents_and_result_list_encoding_with_legacy_attestation_name = + contents_and_result_conv_with_guard + (Variable.list contents_and_result_encoding_with_legacy_attestation_name) type 'kind operation_metadata = {contents : 'kind contents_result_list} @@ -1799,6 +1804,28 @@ let operation_metadata_encoding = (fun () -> No_operation_metadata); ] +let operation_metadata_encoding_with_legacy_attestation_name = + def "operation_with_legacy_attestation_name.alpha.result" + @@ union + [ + case + (Tag 0) + ~title:"Operation_metadata" + contents_result_list_encoding_with_legacy_attestation_name + (function + | Operation_metadata {contents} -> + Some (Contents_result_list contents) + | _ -> None) + (fun (Contents_result_list contents) -> + Operation_metadata {contents}); + case + (Tag 1) + ~title:"No_operation_metadata" + empty + (function No_operation_metadata -> Some () | _ -> None) + (fun () -> No_operation_metadata); + ] + let kind_equal : type kind kind2. kind contents -> kind2 contents_result -> (kind, kind2) eq option = @@ -2464,6 +2491,49 @@ let operation_data_and_metadata_encoding = let op_contents, res_contents = unpack_contents_list contents in ( Operation_data {contents = op_contents; signature}, Operation_metadata {contents = res_contents} )); + case + (Tag 1) + ~title:"Operation_without_metadata" + (obj2 + (req "contents" (dynamic_size Operation.contents_list_encoding)) + (opt "signature" Signature.encoding)) + (function + | Operation_data op, No_operation_metadata -> + Some (Contents_list op.contents, op.signature) + | Operation_data _, Operation_metadata _ -> None) + (fun (Contents_list contents, signature) -> + (Operation_data {contents; signature}, No_operation_metadata)); + ] + +let operation_data_and_metadata_encoding_with_legacy_attestation_name = + def "operation_with_legacy_attestation_name.alpha.operation_with_metadata" + @@ union + [ + case + (Tag 0) + ~title:"Operation_with_metadata" + (obj2 + (req + "contents" + (dynamic_size + contents_and_result_list_encoding_with_legacy_attestation_name)) + (opt "signature" Signature.encoding)) + (function + | Operation_data _, No_operation_metadata -> None + | Operation_data op, Operation_metadata res -> ( + match kind_equal_list op.contents res.contents with + | None -> + Pervasives.failwith + "cannot decode inconsistent combined operation result" + | Some Eq -> + Some + ( Contents_and_result_list + (pack_contents_list op.contents res.contents), + op.signature ))) + (fun (Contents_and_result_list contents, signature) -> + let op_contents, res_contents = unpack_contents_list contents in + ( Operation_data {contents = op_contents; signature}, + Operation_metadata {contents = res_contents} )); case (Tag 1) ~title:"Operation_without_metadata" diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index 844b62a279ed..0a6eb6b88f50 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -269,9 +269,15 @@ val pack_migration_operation_results : (** Serializer for {!packed_operation_result}. *) val operation_metadata_encoding : packed_operation_metadata Data_encoding.t +val operation_metadata_encoding_with_legacy_attestation_name : + packed_operation_metadata Data_encoding.t + val operation_data_and_metadata_encoding : (Operation.packed_protocol_data * packed_operation_metadata) Data_encoding.t +val operation_data_and_metadata_encoding_with_legacy_attestation_name : + (Operation.packed_protocol_data * packed_operation_metadata) Data_encoding.t + type 'kind contents_and_result_list = | Single_and_result : 'kind Alpha_context.contents * 'kind contents_result @@ -290,6 +296,9 @@ type packed_contents_and_result_list = val contents_and_result_list_encoding : packed_contents_and_result_list Data_encoding.t +val contents_and_result_list_encoding_with_legacy_attestation_name : + packed_contents_and_result_list Data_encoding.t + val pack_contents_list : 'kind contents_list -> 'kind contents_result_list -> diff --git a/src/proto_alpha/lib_protocol/main.ml b/src/proto_alpha/lib_protocol/main.ml index f94b7e1de2a4..07b27a1f15dc 100644 --- a/src/proto_alpha/lib_protocol/main.ml +++ b/src/proto_alpha/lib_protocol/main.ml @@ -53,10 +53,12 @@ type operation_receipt = Apply_results.packed_operation_metadata = -> operation_receipt | No_operation_metadata : operation_receipt -let operation_receipt_encoding = Apply_results.operation_metadata_encoding +let operation_receipt_encoding = + Apply_results.operation_metadata_encoding_with_legacy_attestation_name let operation_data_and_receipt_encoding = - Apply_results.operation_data_and_metadata_encoding + Apply_results + .operation_data_and_metadata_encoding_with_legacy_attestation_name type operation = Alpha_context.packed_operation = { shell : Operation.shell_header; -- GitLab From b8bbc548d3d7238108796933ad15358b8376a726 Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 26 Apr 2023 16:25:15 +0200 Subject: [PATCH 3/5] proto_alpha: export attestation encoding cases --- src/proto_alpha/lib_protocol/alpha_context.mli | 9 +++++++++ src/proto_alpha/lib_protocol/operation_repr.mli | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 8ad229b8dbea..a8d569e2d902 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -4390,8 +4390,12 @@ module Operation : sig val preendorsement_case : Kind.preendorsement case + val preattestation_case : Kind.preendorsement case + val endorsement_case : Kind.endorsement case + val attestation_case : Kind.endorsement case + val dal_attestation_case : Kind.dal_attestation case val seed_nonce_revelation_case : Kind.seed_nonce_revelation case @@ -4401,8 +4405,13 @@ module Operation : sig val double_preendorsement_evidence_case : Kind.double_preendorsement_evidence case + val double_preattestation_evidence_case : + Kind.double_preendorsement_evidence case + val double_endorsement_evidence_case : Kind.double_endorsement_evidence case + val double_attestation_evidence_case : Kind.double_endorsement_evidence case + val double_baking_evidence_case : Kind.double_baking_evidence case val activate_account_case : Kind.activate_account case diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index 100fafdb05d7..e777c3e60da7 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -689,8 +689,12 @@ module Encoding : sig val preendorsement_case : Kind.preendorsement case + val preattestation_case : Kind.preendorsement case + val endorsement_case : Kind.endorsement case + val attestation_case : Kind.endorsement case + val dal_attestation_case : Kind.dal_attestation case val seed_nonce_revelation_case : Kind.seed_nonce_revelation case @@ -700,8 +704,13 @@ module Encoding : sig val double_preendorsement_evidence_case : Kind.double_preendorsement_evidence case + val double_preattestation_evidence_case : + Kind.double_preendorsement_evidence case + val double_endorsement_evidence_case : Kind.double_endorsement_evidence case + val double_attestation_evidence_case : Kind.double_endorsement_evidence case + val double_baking_evidence_case : Kind.double_baking_evidence case val activate_account_case : Kind.activate_account case -- GitLab From 8ea0664e219944c2a87134d2da258ab9d5d2770b Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Wed, 26 Apr 2023 16:32:54 +0200 Subject: [PATCH 4/5] proto_alpha: introduce attestation encodings in the apply_results non legacy operations encodings --- src/proto_alpha/lib_protocol/apply_results.ml | 101 +++++++++++++++++- .../lib_protocol/apply_results.mli | 16 +++ 2 files changed, 113 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index 0b1dbf8512d1..a51dbfcc91cf 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -1009,6 +1009,11 @@ module Encoding = struct (req (Format.asprintf "%s_power" power_name) int31) (req "consensus_key" Signature.Public_key_hash.encoding) + let consensus_result_encoding_legacy power_name = + consensus_result_encoding power_name + + let consensus_result_encoding = consensus_result_encoding "consensus" + type case = | Case : { op_case : 'kind Operation.Encoding.case; @@ -1035,7 +1040,31 @@ module Encoding = struct Case { op_case = Operation.Encoding.preendorsement_case; - encoding = consensus_result_encoding "preendorsement"; + encoding = consensus_result_encoding_legacy "preendorsement"; + select = + (function + | Contents_result (Preendorsement_result _ as op) -> Some op + | _ -> None); + mselect = + (function + | Contents_and_result ((Preendorsement _ as op), res) -> Some (op, res) + | _ -> None); + proj = + (function + | Preendorsement_result + {balance_updates; delegate; consensus_key; consensus_power} -> + (balance_updates, delegate, consensus_power, consensus_key)); + inj = + (fun (balance_updates, delegate, consensus_power, consensus_key) -> + Preendorsement_result + {balance_updates; delegate; consensus_key; consensus_power}); + } + + let preattestation_case = + Case + { + op_case = Operation.Encoding.preattestation_case; + encoding = consensus_result_encoding; select = (function | Contents_result (Preendorsement_result _ as op) -> Some op @@ -1059,7 +1088,30 @@ module Encoding = struct Case { op_case = Operation.Encoding.endorsement_case; - encoding = consensus_result_encoding "endorsement"; + encoding = consensus_result_encoding_legacy "endorsement"; + select = + (function + | Contents_result (Endorsement_result _ as op) -> Some op | _ -> None); + mselect = + (function + | Contents_and_result ((Endorsement _ as op), res) -> Some (op, res) + | _ -> None); + proj = + (function + | Endorsement_result + {balance_updates; delegate; consensus_key; consensus_power} -> + (balance_updates, delegate, consensus_power, consensus_key)); + inj = + (fun (balance_updates, delegate, consensus_power, consensus_key) -> + Endorsement_result + {balance_updates; delegate; consensus_key; consensus_power}); + } + + let attestation_case = + Case + { + op_case = Operation.Encoding.attestation_case; + encoding = consensus_result_encoding; select = (function | Contents_result (Endorsement_result _ as op) -> Some op | _ -> None); @@ -1153,6 +1205,26 @@ module Encoding = struct inj = (fun bus -> Double_endorsement_evidence_result bus); } + let double_attestation_evidence_case = + Case + { + op_case = Operation.Encoding.double_attestation_evidence_case; + encoding = + obj1 (dft "balance_updates" Receipt.balance_updates_encoding []); + select = + (function + | Contents_result (Double_endorsement_evidence_result _ as op) -> + Some op + | _ -> None); + mselect = + (function + | Contents_and_result ((Double_endorsement_evidence _ as op), res) -> + Some (op, res) + | _ -> None); + proj = (fun (Double_endorsement_evidence_result bus) -> bus); + inj = (fun bus -> Double_endorsement_evidence_result bus); + } + let double_preendorsement_evidence_case = Case { @@ -1174,6 +1246,27 @@ module Encoding = struct inj = (fun bus -> Double_preendorsement_evidence_result bus); } + let double_preattestation_evidence_case = + Case + { + op_case = Operation.Encoding.double_preattestation_evidence_case; + encoding = + obj1 (dft "balance_updates" Receipt.balance_updates_encoding []); + select = + (function + | Contents_result (Double_preendorsement_evidence_result _ as op) -> + Some op + | _ -> None); + mselect = + (function + | Contents_and_result ((Double_preendorsement_evidence _ as op), res) + -> + Some (op, res) + | _ -> None); + proj = (fun (Double_preendorsement_evidence_result bus) -> bus); + inj = (fun bus -> Double_preendorsement_evidence_result bus); + } + let double_baking_evidence_case = Case { @@ -1623,8 +1716,8 @@ let common_cases = let contents_cases = let open Encoding in - endorsement_case :: preendorsement_case :: double_endorsement_evidence_case - :: double_preendorsement_evidence_case :: common_cases + attestation_case :: preattestation_case :: double_attestation_evidence_case + :: double_preattestation_evidence_case :: common_cases let contents_cases_with_legacy_attestation_name = let open Encoding in diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index 0a6eb6b88f50..3d098aa0f10c 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -269,12 +269,28 @@ val pack_migration_operation_results : (** Serializer for {!packed_operation_result}. *) val operation_metadata_encoding : packed_operation_metadata Data_encoding.t +(** Operation metadata encoding that accepts legacy attestation name : + `endorsement` (and preendorsement, double__evidence) in JSON + + https://gitlab.com/tezos/tezos/-/issues/5531 + + This encoding is temporary and should be removed when the protocol no longer + accepts JSON endorsements kinds +*) val operation_metadata_encoding_with_legacy_attestation_name : packed_operation_metadata Data_encoding.t val operation_data_and_metadata_encoding : (Operation.packed_protocol_data * packed_operation_metadata) Data_encoding.t +(** Operation data and metadata encoding that accepts legacy attestation name : + `endorsement` (and preendorsement, double__evidence) in JSON + + https://gitlab.com/tezos/tezos/-/issues/5531 + + This encoding is temporary and should be removed when the protocol no longer + accepts JSON endorsements kinds +*) val operation_data_and_metadata_encoding_with_legacy_attestation_name : (Operation.packed_protocol_data * packed_operation_metadata) Data_encoding.t -- GitLab From 51f170647fd890b45e21eaae1d4ff2b8c4f2de7f Mon Sep 17 00:00:00 2001 From: Albin Coquereau Date: Fri, 28 Apr 2023 10:38:42 +0200 Subject: [PATCH 5/5] changes/alpha: update the legacy operation encoding entry and add an entry for the power field from consensus operation receipt --- docs/protocols/alpha.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 1884efde0c84..a439721c0d97 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -101,7 +101,7 @@ Internal - Encoding that supports ``endorsement`` kind in JSON are now suffixed with ``_with_legacy_attestation_name``. Non legacy encoding supports - ``attestation`` kind. (MR :gl:`!8563`) + ``attestation`` kind. (MRs :gl:`!8563`, :gl:`!8531`) - Michelson: remove legacy behaviour related to contract type. (MR :gl:`!5800`) @@ -136,3 +136,7 @@ Internal delegate has a sufficient frozen deposit. (MR :gl:`!8722`) - Store a history of percentages of slashed deposits. (MR :gl:`!8828`) + +- Renaming the ``endorsement_power`` and ``preendorsement_power`` fields from + consensus operation receipt to ``consensus_power`` in the non legacy encoding. + (MR :gl:`!8531`) -- GitLab