diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 947dda705df036d68e8e57cc013ca93df337b535..f356a54c48407458cd24a56be357461a44890c0b 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -114,6 +114,13 @@ bls (tz4) 1671 gas units RPC Changes ----------- +- Add ``GET /helpers/attestation_rights`` that returns the attestation power for + delegates, replacing ``GET /helpers/endorsing_rights``, which is now + deprecated (MR :gl:`!8096`) + +- Deprecate ``endorsing_rights`` in favour of ``attestation_rights``. (MR + :gl:`!8096`) + Operation receipts ------------------ diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 1a4e65e795415578106c68ef683474f6f6c53c87..5ee643fa46a75e946bdcdddf35111fd6c198e4b4 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -3318,12 +3318,12 @@ module Baking_rights = struct () end -module Endorsing_rights = struct +module Attestation_rights = struct type delegate_rights = { delegate : Signature.Public_key_hash.t; consensus_key : Signature.Public_key_hash.t; first_slot : Slot.t; - endorsing_power : int; + attestation_power : int; } type t = { @@ -3332,20 +3332,22 @@ module Endorsing_rights = struct estimated_time : Time.t option; } - let delegate_rights_encoding = + let delegate_rights_encoding use_endorsement = let open Data_encoding in conv - (fun {delegate; consensus_key; first_slot; endorsing_power} -> - (delegate, first_slot, endorsing_power, consensus_key)) - (fun (delegate, first_slot, endorsing_power, consensus_key) -> - {delegate; first_slot; endorsing_power; consensus_key}) + (fun {delegate; consensus_key; first_slot; attestation_power} -> + (delegate, first_slot, attestation_power, consensus_key)) + (fun (delegate, first_slot, attestation_power, consensus_key) -> + {delegate; first_slot; attestation_power; consensus_key}) (obj4 (req "delegate" Signature.Public_key_hash.encoding) (req "first_slot" Slot.encoding) - (req "endorsing_power" uint16) + (req + (if use_endorsement then "endorsing_power" else "attestation_power") + uint16) (req "consensus_key" Signature.Public_key_hash.encoding)) - let encoding = + let encoding ~use_endorsement = let open Data_encoding in conv (fun {level; delegates_rights; estimated_time} -> @@ -3354,22 +3356,24 @@ module Endorsing_rights = struct {level; delegates_rights; estimated_time}) (obj3 (req "level" Raw_level.encoding) - (req "delegates" (list delegate_rights_encoding)) + (req "delegates" (list (delegate_rights_encoding use_endorsement))) (opt "estimated_time" Timestamp.encoding)) module S = struct open Data_encoding - let path = RPC_path.(path / "endorsing_rights") + let attestation_path = RPC_path.(path / "attestation_rights") + + let endorsing_path = RPC_path.(path / "endorsing_rights") - type endorsing_rights_query = { + type attestation_rights_query = { levels : Raw_level.t list; cycle : Cycle.t option; delegates : Signature.Public_key_hash.t list; consensus_keys : Signature.Public_key_hash.t list; } - let endorsing_rights_query = + let attestation_rights_query = let open RPC_query in query (fun levels cycle delegates consensus_keys -> {levels; cycle; delegates; consensus_keys}) @@ -3381,10 +3385,36 @@ module Endorsing_rights = struct t.consensus_keys) |> seal + let attestation_rights = + RPC_service.get_service + ~description: + "Retrieves the delegates allowed to attest a block.\n\ + By default, it gives the attestation power for delegates that have \ + at least one attestation slot for the next block.\n\ + Parameters `level` and `cycle` can be used to specify the (valid) \ + level(s) in the past or future at which the attestation rights have \ + to be returned. Parameter `delegate` can be used to restrict the \ + results to the given delegates.\n\ + Parameter `consensus_key` can be used to restrict the results to \ + the given consensus_keys. \n\ + Returns the smallest attestation slots and the attestation power. \ + Also returns the minimal timestamp that corresponds to attestation \ + at the given level. The timestamps are omitted for levels in the \ + past, and are only estimates for levels higher that the next \ + block's, based on the hypothesis that all predecessor blocks were \ + baked at the first round." + ~query:attestation_rights_query + ~output:(list (encoding ~use_endorsement:false)) + attestation_path + + (* TODO: https://gitlab.com/tezos/tezos/-/issues/5156 + endorsing_rights RPC should be removed once the depreciation period + will be over *) let endorsing_rights = RPC_service.get_service ~description: - "Retrieves the delegates allowed to endorse a block.\n\ + "Deprecated: use `attestation_rights` instead.\n\ + Retrieves the delegates allowed to endorse a block.\n\ By default, it gives the endorsing power for delegates that have at \ least one endorsing slot for the next block.\n\ Parameters `level` and `cycle` can be used to specify the (valid) \ @@ -3399,12 +3429,12 @@ module Endorsing_rights = struct are only estimates for levels higher that the next block's, based \ on the hypothesis that all predecessor blocks were baked at the \ first round." - ~query:endorsing_rights_query - ~output:(list encoding) - path + ~query:attestation_rights_query + ~output:(list (encoding ~use_endorsement:true)) + endorsing_path end - let endorsing_rights_at_level ctxt level = + let attestation_rights_at_level ctxt level = Baking.endorsing_rights_by_first_slot ctxt level >>=? fun (ctxt, rights) -> Round.get ctxt >>=? fun current_round -> let current_level = Level.current ctxt in @@ -3426,9 +3456,9 @@ module Endorsing_rights = struct consensus_pk = _; consensus_pkh = consensus_key; }, - endorsing_power ) + attestation_power ) acc -> - {delegate; consensus_key; first_slot; endorsing_power} :: acc) + {delegate; consensus_key; first_slot; attestation_power} :: acc) rights [] in @@ -3436,46 +3466,46 @@ module Endorsing_rights = struct return (ctxt, {level = level.level; delegates_rights = rights; estimated_time}) + let get_attestation_rights ctxt (q : S.attestation_rights_query) = + let cycles = match q.cycle with None -> [] | Some cycle -> [cycle] in + let levels = + requested_levels ~default_level:(Level.current ctxt) ctxt cycles q.levels + in + List.fold_left_map_es attestation_rights_at_level ctxt levels + >|=? fun (_ctxt, rights_per_level) -> + let rights_per_level = + match (q.consensus_keys, q.delegates) with + | [], [] -> rights_per_level + | _, _ -> + let is_requested p = + List.exists + (Signature.Public_key_hash.equal p.consensus_key) + q.consensus_keys + || List.exists + (Signature.Public_key_hash.equal p.delegate) + q.delegates + in + List.filter_map + (fun rights_at_level -> + match + List.filter is_requested rights_at_level.delegates_rights + with + | [] -> None + | delegates_rights -> Some {rights_at_level with delegates_rights}) + rights_per_level + in + rights_per_level + let register () = + Registration.register0 ~chunked:true S.attestation_rights (fun ctxt q () -> + get_attestation_rights ctxt q) ; Registration.register0 ~chunked:true S.endorsing_rights (fun ctxt q () -> - let cycles = match q.cycle with None -> [] | Some cycle -> [cycle] in - let levels = - requested_levels - ~default_level:(Level.current ctxt) - ctxt - cycles - q.levels - in - List.fold_left_map_es endorsing_rights_at_level ctxt levels - >|=? fun (_ctxt, rights_per_level) -> - let rights_per_level = - match (q.consensus_keys, q.delegates) with - | [], [] -> rights_per_level - | _, _ -> - let is_requested p = - List.exists - (Signature.Public_key_hash.equal p.consensus_key) - q.consensus_keys - || List.exists - (Signature.Public_key_hash.equal p.delegate) - q.delegates - in - List.filter_map - (fun rights_at_level -> - match - List.filter is_requested rights_at_level.delegates_rights - with - | [] -> None - | delegates_rights -> - Some {rights_at_level with delegates_rights}) - rights_per_level - in - rights_per_level) + get_attestation_rights ctxt q) let get ctxt ?(levels = []) ?cycle ?(delegates = []) ?(consensus_keys = []) block = RPC_context.make_call0 - S.endorsing_rights + S.attestation_rights ctxt block {levels; cycle; delegates; consensus_keys} @@ -3654,7 +3684,7 @@ let register () = Contract.register () ; Big_map.register () ; Baking_rights.register () ; - Endorsing_rights.register () ; + Attestation_rights.register () ; Validators.register () ; Sc_rollup.register () ; Dal.register () ; diff --git a/tezt/lib_tezos/RPC.ml b/tezt/lib_tezos/RPC.ml index fa46683814c4ee43d5be7288c98055f3821dd384..6df49ef2114548927339cbc0b8b6c2fb6bb2b971 100644 --- a/tezt/lib_tezos/RPC.ml +++ b/tezt/lib_tezos/RPC.ml @@ -635,6 +635,15 @@ let get_chain_block_helper_current_level ?(chain = "main") ?(block = "head") let expected_commitment = JSON.(json |-> "expected_commitment" |> as_bool) in {level; level_position; cycle; cycle_position; expected_commitment} +let get_chain_block_helper_attestation_rights ?(chain = "main") + ?(block = "head") ?delegate () = + let query_string = Query_arg.opt "delegate" Fun.id delegate in + make + ~query_string + GET + ["chains"; chain; "blocks"; block; "helpers"; "attestation_rights"] + Fun.id + let get_chain_block_helper_endorsing_rights ?(chain = "main") ?(block = "head") ?delegate () = let query_string = Query_arg.opt "delegate" Fun.id delegate in diff --git a/tezt/lib_tezos/RPC.mli b/tezt/lib_tezos/RPC.mli index 624b8f25c9fc60097d32a319e89e549a7a33c23e..5cc859bf30b17325f3f5ed43df7a333361e6326a 100644 --- a/tezt/lib_tezos/RPC.mli +++ b/tezt/lib_tezos/RPC.mli @@ -622,6 +622,14 @@ type level = { val get_chain_block_helper_current_level : ?chain:string -> ?block:string -> ?offset:int -> unit -> level t +(** RPC: [GET /chains//blocks//helpers/attestation_rights] + + [chain] defaults to ["main"]. + [block] defaults to ["head"]. +*) +val get_chain_block_helper_attestation_rights : + ?chain:string -> ?block:string -> ?delegate:string -> unit -> JSON.t t + (** RPC: [GET /chains//blocks//helpers/endorsing_rights] [chain] defaults to ["main"]. diff --git a/tezt/manual_tests/baker_test.ml b/tezt/manual_tests/baker_test.ml index 9c0c875889177adc9832f4991aec3d49a1b148db..00fa446f4d1ccb9f2f3418d40b01a8f2e90c7eed 100644 --- a/tezt/manual_tests/baker_test.ml +++ b/tezt/manual_tests/baker_test.ml @@ -217,8 +217,8 @@ let baker_early_preendorsement_test = client2 in - let recover_endorsing_rights ~max_round client level = - let* endorsing_rights = + let recover_baking_rights ~max_round client level = + let* baking_rights = RPC.Client.call client @@ RPC.get_chain_block_helper_baking_rights ~level () in @@ -237,7 +237,7 @@ let baker_early_preendorsement_test = Some (round, bootstrap.alias) else None) bootstraps) - JSON.(endorsing_rights |> as_list) + JSON.(baking_rights |> as_list) in (* This levels have been chosen such as the first baker can propose at round 0 on the [prev_level] and the [test_level], and that the second baker can @@ -253,27 +253,27 @@ let baker_early_preendorsement_test = test_lvl (Baker.name baker2) test_lvl ; - let* endorsing_rights_prev_lvl = - recover_endorsing_rights ~max_round:1 client1 prev_lvl + let* baking_rights_prev_lvl = + recover_baking_rights ~max_round:1 client1 prev_lvl in - let* endorsing_rights_test_lvl = - recover_endorsing_rights ~max_round:0 client1 test_lvl + let* baking_rights_test_lvl = + recover_baking_rights ~max_round:0 client1 test_lvl in - let print_endorsing_rights level rights = + let print_baking_rights level rights = Log.info - "Endorsing rights at level %d:%a" + "Baking rights at level %d:%a" level pp_list (List.map (fun (round, key) -> sf " round:%d -> key:%s" round key) rights) in - print_endorsing_rights prev_lvl endorsing_rights_prev_lvl ; - print_endorsing_rights test_lvl endorsing_rights_test_lvl ; + print_baking_rights prev_lvl baking_rights_prev_lvl ; + print_baking_rights test_lvl baking_rights_test_lvl ; assert ( List.for_all (fun (round, key) -> if round = 0 then List.mem key baker1_delegates_alias else List.mem key baker2_delegates_alias) - (endorsing_rights_prev_lvl @ endorsing_rights_test_lvl)) ; + (baking_rights_prev_lvl @ baking_rights_test_lvl)) ; Log.info "Wait for the nodes to reach level %d" prev_lvl ; Log.info diff --git a/tezt/tests/RPC_test.ml b/tezt/tests/RPC_test.ml index 46e8ff85efb81326ae74da224bbab35291fc00f2..76e4cdcc1568172148ebc62cec578aa329fb6be8 100644 --- a/tezt/tests/RPC_test.ml +++ b/tezt/tests/RPC_test.ml @@ -617,7 +617,7 @@ let test_votes _test_mode_tag _protocol ?endpoint client = unit (* Test the various other RPCs. *) -let test_misc_protocol _test_mode_tag _protocol ?endpoint client = +let test_misc_protocol _test_mode_tag protocol ?endpoint client = let* _ = RPC.Client.call ?endpoint ~hooks client @@ RPC.get_chain_block_context_constants () @@ -646,6 +646,21 @@ let test_misc_protocol _test_mode_tag _protocol ?endpoint client = ~delegate:Constant.bootstrap4.public_key_hash () in + let* () = + if Protocol.(number protocol > number Mumbai) then + let* _ = + RPC.Client.call ?endpoint ~hooks client + @@ RPC.get_chain_block_helper_attestation_rights () + in + let* _ = + RPC.Client.call ?endpoint ~hooks client + @@ RPC.get_chain_block_helper_attestation_rights + ~delegate:Constant.bootstrap4.public_key_hash + () + in + unit + else unit + in let* _ = RPC.Client.call ?endpoint ~hooks client @@ RPC.get_chain_block_helper_levels_in_current_cycle () diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out index dee4a83c6cd70a8a479d5a32b09122ec17b74131..9d5cab670056873710aae2cc17e485d81e0b2e34 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode client) RPC regression tests- misc_protocol.out @@ -116,5 +116,31 @@ "first_slot": 11, "endorsing_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] +./octez-client rpc get /chains/main/blocks/head/helpers/attestation_rights +[ { "level": 1, + "delegates": + [ { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 11, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 4, "attestation_power": 47, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 2, "attestation_power": 46, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 1, "attestation_power": 55, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 0, "attestation_power": 58, + "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] + +./octez-client rpc get '/chains/main/blocks/head/helpers/attestation_rights?delegate=[PUBLIC_KEY_HASH]' +[ { "level": 1, + "delegates": + [ { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 11, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] + ./octez-client rpc get /chains/main/blocks/head/helpers/levels_in_current_cycle { "first": 1, "last": 8 } diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out index dbe782d8770fad7435cae57501f46b1d307fe1f2..91b7ce05765eca138762ba3da6fa12ce1824dcf4 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode light) RPC regression tests- misc_protocol.out @@ -116,5 +116,31 @@ "first_slot": 11, "endorsing_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] +./octez-client --mode light rpc get /chains/main/blocks/head/helpers/attestation_rights +[ { "level": 1, + "delegates": + [ { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 11, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 4, "attestation_power": 47, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 2, "attestation_power": 46, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 1, "attestation_power": 55, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 0, "attestation_power": 58, + "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] + +./octez-client --mode light rpc get '/chains/main/blocks/head/helpers/attestation_rights?delegate=[PUBLIC_KEY_HASH]' +[ { "level": 1, + "delegates": + [ { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 11, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] + ./octez-client --mode light rpc get /chains/main/blocks/head/helpers/levels_in_current_cycle { "first": 1, "last": 8 } diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out index 880834e7ea6c28c1ad653f2c501aabff8eb22b32..66a74b8f74f273eed775f24a4b7f8a9fecd95938 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy) RPC regression tests- misc_protocol.out @@ -116,5 +116,31 @@ "first_slot": 11, "endorsing_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] +./octez-client --mode proxy rpc get /chains/main/blocks/head/helpers/attestation_rights +[ { "level": 1, + "delegates": + [ { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 11, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 4, "attestation_power": 47, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 2, "attestation_power": 46, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 1, "attestation_power": 55, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 0, "attestation_power": 58, + "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] + +./octez-client --mode proxy rpc get '/chains/main/blocks/head/helpers/attestation_rights?delegate=[PUBLIC_KEY_HASH]' +[ { "level": 1, + "delegates": + [ { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 11, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] + ./octez-client --mode proxy rpc get /chains/main/blocks/head/helpers/levels_in_current_cycle { "first": 1, "last": 8 } diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out index 6b0bc08d4e49a4a463026e45cb48e04d3bbded3a..4ea3f3d1f91239f15c8bc5202fe4cbdc2eb20d07 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_data_dir) RPC regression tests- misc_protocol.out @@ -116,5 +116,31 @@ "first_slot": 1, "endorsing_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] +./octez-client rpc get /chains/main/blocks/head/helpers/attestation_rights +[ { "level": 2, + "delegates": + [ { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 10, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 3, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 2, "attestation_power": 65, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 1, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 0, "attestation_power": 41, + "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] + +./octez-client rpc get '/chains/main/blocks/head/helpers/attestation_rights?delegate=[PUBLIC_KEY_HASH]' +[ { "level": 2, + "delegates": + [ { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 1, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] + ./octez-client rpc get /chains/main/blocks/head/helpers/levels_in_current_cycle { "first": 1, "last": 8 } diff --git a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out index 6b0bc08d4e49a4a463026e45cb48e04d3bbded3a..4ea3f3d1f91239f15c8bc5202fe4cbdc2eb20d07 100644 --- a/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out +++ b/tezt/tests/expected/RPC_test.ml/Alpha- (mode proxy_server_rpc) RPC regression tests- misc_protocol.out @@ -116,5 +116,31 @@ "first_slot": 1, "endorsing_power": 50, "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] +./octez-client rpc get /chains/main/blocks/head/helpers/attestation_rights +[ { "level": 2, + "delegates": + [ { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 10, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 3, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 2, "attestation_power": 65, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 1, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" }, + { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 0, "attestation_power": 41, + "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] + +./octez-client rpc get '/chains/main/blocks/head/helpers/attestation_rights?delegate=[PUBLIC_KEY_HASH]' +[ { "level": 2, + "delegates": + [ { "delegate": "[PUBLIC_KEY_HASH]", + "first_slot": 1, "attestation_power": 50, + "consensus_key": "[PUBLIC_KEY_HASH]" } ] } ] + ./octez-client rpc get /chains/main/blocks/head/helpers/levels_in_current_cycle { "first": 1, "last": 8 } diff --git a/tezt/tests/light.ml b/tezt/tests/light.ml index f002d986e0cb7322fa0094079daad17b258f5bd7..248556c26a9c647e1b416c452094ad67e232cf59 100644 --- a/tezt/tests/light.ml +++ b/tezt/tests/light.ml @@ -236,6 +236,11 @@ module NoUselessRpc = struct (["votes"; "proposals"], []); ] in + let paths = + if Protocol.(number protocol > number Mumbai) then + (["helpers"; "attestation_rights"], []) :: paths + else paths + in Lwt_list.iter_s (fun (sub_path, query_string) -> test_no_useless_rpc diff --git a/tezt/tests/proxy_server_test.ml b/tezt/tests/proxy_server_test.ml index 53caeb87f20cfc7f837b6a2265c45235db7b9c1a..a8b7fe3f2638cd11268373c1e89b693bb19bfef3 100644 --- a/tezt/tests/proxy_server_test.ml +++ b/tezt/tests/proxy_server_test.ml @@ -273,37 +273,54 @@ let test_multi_protocols = (* Launch the proxy server and plug the client to it *) let* proxy_server = Proxy_server.init node in Client.set_mode (Client (Some (Proxy_server proxy_server), None)) client ; - (* Ensure the proxy serves a query to a block in [to_protocol] *) - let* from_proto_rights = - Client.rpc - Client.GET - ["chains"; "main"; "blocks"; "3"; "helpers"; "endorsing_rights"] - client + let check_attestation_levels ~__LOC__ ?block ~expected_level proto = + let check levels = + let returned_level = + JSON.(levels |> geti 0 |> get "level" |> as_int) + in + Check.( + (expected_level = returned_level) + int + ~error_msg: + (sf + "%s: Unexpected level returned in proxy_server multi \ + protocol test, expected %%L instead of %%R" + __LOC__)) + in + let* () = + if Protocol.(number proto > number Mumbai) then ( + let* proto_attestation_rights = + RPC.Client.call client + @@ RPC.get_chain_block_helper_attestation_rights ?block () + in + check proto_attestation_rights ; + unit) + else unit + in + let* proto_endorsing_rights = + RPC.Client.call client + @@ RPC.get_chain_block_helper_endorsing_rights ?block () + in + check proto_endorsing_rights ; + unit in - let from_level_returned = - JSON.(from_proto_rights |> geti 0 |> get "level" |> as_int) + (* Ensure the proxy serves a query to a block in [to_protocol] *) + let* () = + check_attestation_levels + ~__LOC__ + ~block:"3" + ~expected_level:3 + from_protocol in - Check.( - (from_level_returned = 3) - int - ~error_msg: - "Unexpected level returned in proxy_server multi protocol test") ; (* Ensure the proxy serves a query to a block in [from_protocol] *) - let* to_proto_rights = - Client.rpc - Client.GET - ["chains"; "main"; "blocks"; "head~1"; "helpers"; "endorsing_rights"] - client - in - let to_level_returned = - JSON.(to_proto_rights |> geti 0 |> get "level" |> as_int) + let* () = + check_attestation_levels + ~__LOC__ + ~block:"head~1" + ~expected_level:5 + to_protocol in - Check.( - (to_level_returned = 5) - int - ~error_msg: - "Unexpected level returned in proxy_server multi protocol test") ; - Lwt.return_unit + unit let register ~protocols = let register mode =