From 6ed091070d28beb65ebc8933e65ca5f35ad9f14b Mon Sep 17 00:00:00 2001 From: phink Date: Wed, 7 Feb 2024 19:13:17 +0100 Subject: [PATCH 1/2] Proto/Delegate_slashed_deposits_storage : add pending_denunciations RPC --- src/proto_alpha/lib_protocol/alpha_context.ml | 9 +-------- src/proto_alpha/lib_protocol/alpha_context.mli | 3 +++ src/proto_alpha/lib_protocol/delegate_services.ml | 14 +++++++++++++- .../lib_protocol/delegate_services.mli | 6 ++++++ .../delegate_slashed_deposits_storage.ml | 15 +++++++++++++++ .../delegate_slashed_deposits_storage.mli | 13 +++++++++++++ 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index 392d5284e3a9..5d1a46e276f4 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -560,14 +560,7 @@ module Delegate = struct include For_RPC include Delegate_storage.For_RPC include Delegate_missed_attestations_storage.For_RPC - - let pending_denunciations_list ctxt = - let open Lwt_syntax in - let* r = Storage.Pending_denunciations.bindings ctxt in - let r = - List.map (fun (x, l) -> List.map (fun y -> (x, y)) l) r |> List.flatten - in - return r + include Delegate_slashed_deposits_storage.For_RPC end end diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index a0c614317b05..abe5e3d38406 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2467,6 +2467,9 @@ module Delegate : sig val staking_balance : context -> public_key_hash -> Tez.t tzresult Lwt.t + val pending_denunciations : + context -> public_key_hash -> Denunciations_repr.t tzresult Lwt.t + val pending_denunciations_list : context -> (public_key_hash * Denunciations_repr.item) list Lwt.t end diff --git a/src/proto_alpha/lib_protocol/delegate_services.ml b/src/proto_alpha/lib_protocol/delegate_services.ml index 418baea47729..486f90e25433 100644 --- a/src/proto_alpha/lib_protocol/delegate_services.ml +++ b/src/proto_alpha/lib_protocol/delegate_services.ml @@ -511,6 +511,13 @@ module S = struct ~query:RPC_query.empty ~output:(list pending_staking_parameters_encoding) RPC_path.(path / "pending_staking_parameters") + + let pending_denunciations = + RPC_service.get_service + ~description:"Returns the pending denunciations for the given delegate." + ~query:RPC_query.empty + ~output:(list Denunciations_repr.item_encoding) + RPC_path.(path / "denunciations") end let check_delegate_registered ctxt pkh = @@ -710,7 +717,9 @@ let register () = register1 ~chunked:false S.active_staking_parameters (fun ctxt pkh () () -> Delegate.Staking_parameters.of_delegate ctxt pkh) ; register1 ~chunked:false S.pending_staking_parameters (fun ctxt pkh () () -> - Delegate.Staking_parameters.pending_updates ctxt pkh) + Delegate.Staking_parameters.pending_updates ctxt pkh) ; + register1 ~chunked:false S.pending_denunciations (fun ctxt pkh () () -> + Delegate.For_RPC.pending_denunciations ctxt pkh) let list ctxt block ?(active = true) ?(inactive = false) ?(with_minimal_stake = true) ?(without_minimal_stake = false) () = @@ -782,3 +791,6 @@ let active_staking_parameters ctxt block pkh = let pending_staking_parameters ctxt block pkh = RPC_context.make_call1 S.pending_staking_parameters ctxt block pkh () () + +let pending_denunciations ctxt block pkh = + RPC_context.make_call1 S.pending_denunciations ctxt block pkh () () diff --git a/src/proto_alpha/lib_protocol/delegate_services.mli b/src/proto_alpha/lib_protocol/delegate_services.mli index 9d0bf6c0b254..17cb85ed0b55 100644 --- a/src/proto_alpha/lib_protocol/delegate_services.mli +++ b/src/proto_alpha/lib_protocol/delegate_services.mli @@ -190,4 +190,10 @@ val pending_staking_parameters : public_key_hash -> (Cycle.t * Staking_parameters_repr.t) list shell_tzresult Lwt.t +val pending_denunciations : + 'a #RPC_context.simple -> + 'a -> + public_key_hash -> + Denunciations_repr.t shell_tzresult Lwt.t + val register : unit -> unit diff --git a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml index fcac690b50b0..2c6300cb622d 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml @@ -349,3 +349,18 @@ let apply_and_clear_denunciations ctxt = remaining_denunciations in return (ctxt, balance_updates) + +module For_RPC = struct + let pending_denunciations ctxt delegate = + let open Lwt_result_syntax in + let+ denunciations = Storage.Pending_denunciations.find ctxt delegate in + Option.value denunciations ~default:[] + + let pending_denunciations_list ctxt = + let open Lwt_syntax in + let* r = Storage.Pending_denunciations.bindings ctxt in + let r = + List.map (fun (x, l) -> List.map (fun y -> (x, y)) l) r |> List.flatten + in + return r +end diff --git a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli index 9d45a438aaa7..528d3f624aa5 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli @@ -90,3 +90,16 @@ val clear_outdated_already_denounced : val apply_and_clear_denunciations : Raw_context.t -> (Raw_context.t * Receipt_repr.balance_updates) tzresult Lwt.t + +module For_RPC : sig + (** Returns the pending denunciations for the given delegate. *) + val pending_denunciations : + Raw_context.t -> + Signature.Public_key_hash.t -> + Denunciations_repr.t tzresult Lwt.t + + (** Returns all the pending denunciations. *) + val pending_denunciations_list : + Raw_context.t -> + (Signature.Public_key_hash.t * Denunciations_repr.item) list Lwt.t +end -- GitLab From 99993d7839131aed50004c693f0154babb3bcb61 Mon Sep 17 00:00:00 2001 From: phink Date: Wed, 7 Feb 2024 19:15:27 +0100 Subject: [PATCH 2/2] Proto/Test: add get_denunciations_for_delegate --- src/proto_alpha/lib_protocol/test/helpers/context.ml | 3 +++ src/proto_alpha/lib_protocol/test/helpers/context.mli | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index 2e1cfa5e8b21..15422e52dc2f 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -335,6 +335,9 @@ let get_ai_expected_issuance ctxt = let get_denunciations ctxt = Alpha_services.Denunciations.denunciations rpc_ctxt ctxt +let get_denunciations_for_delegate ctxt = + Alpha_services.Delegate.pending_denunciations rpc_ctxt ctxt + module Dal = struct let shards ctxt = Plugin.RPC.Dal.dal_shards rpc_ctxt ctxt end diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index 9de054fa3869..50311775faf0 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/context.mli @@ -147,6 +147,11 @@ val get_denunciations : t -> (Signature.Public_key_hash.t * Denunciations_repr.item) list tzresult Lwt.t +val get_denunciations_for_delegate : + t -> + Signature.Public_key_hash.t -> + Denunciations_repr.item list tzresult Lwt.t + module Vote : sig val get_ballots : t -> Vote.ballots tzresult Lwt.t -- GitLab