diff --git a/src/proto_alpha/lib_protocol/alpha_context.ml b/src/proto_alpha/lib_protocol/alpha_context.ml index f7e302b37e08eb9fc6ca8965582561681c423f12..b717217919900acf3467c1af89a1caf8ba456402 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.ml +++ b/src/proto_alpha/lib_protocol/alpha_context.ml @@ -635,6 +635,7 @@ end module Token = Token module Cache = Cache_repr module Unstake_requests = Unstake_requests_storage +module Unstaked_frozen_deposits = Unstaked_frozen_deposits_storage module Staking_pseudotokens = struct include Staking_pseudotoken_repr diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 935006bc2158fa9ce8eb331a0e2cae897b3ea8b7..43c37e43059ff71a2dfeb4a5a12964d9db93ec6d 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -4873,6 +4873,10 @@ module Unstake_requests : sig context tzresult Lwt.t end +module Unstaked_frozen_deposits : sig + val balance : context -> public_key_hash -> Cycle.t -> Tez.t tzresult Lwt.t +end + (** This module re-exports definitions from {!Staking_pseudotoken_repr} and {!Staking_pseudotokens_storage}. *) module Staking_pseudotokens : sig diff --git a/src/proto_alpha/lib_protocol/delegate_services.ml b/src/proto_alpha/lib_protocol/delegate_services.ml index 8c370b12f405311e8e0fb53c007ebd3cb3eedfb9..497daaa32d3e89cd0022bf89235d07cd419b5446 100644 --- a/src/proto_alpha/lib_protocol/delegate_services.ml +++ b/src/proto_alpha/lib_protocol/delegate_services.ml @@ -230,6 +230,15 @@ let participation_info_encoding = (req "remaining_allowed_missed_slots" int31) (req "expected_endorsing_rewards" Tez.encoding)) +type deposit_per_cycle = {cycle : Cycle.t; deposit : Tez.t} + +let deposit_per_cycle_encoding : deposit_per_cycle Data_encoding.t = + let open Data_encoding in + conv + (fun {cycle; deposit} -> (cycle, deposit)) + (fun (cycle, deposit) -> {cycle; deposit}) + (obj2 (req "cycle" Cycle.encoding) (req "deposit" Tez.encoding)) + module S = struct let raw_path = RPC_path.(open_root / "context" / "delegates") @@ -303,6 +312,16 @@ module S = struct ~output:Tez.encoding RPC_path.(path / "frozen_deposits") + let unstaked_frozen_deposits = + RPC_service.get_service + ~description: + "Returns, for each cycle, the sum of unstaked-but-frozen deposits for \ + this cycle. Cycles go from the last unslashable cycle to the current \ + cycle." + ~query:RPC_query.empty + ~output:(Data_encoding.list deposit_per_cycle_encoding) + RPC_path.(path / "unstaked_frozen_deposits") + let staking_balance = RPC_service.get_service ~description: @@ -478,6 +497,22 @@ let register () = check_delegate_registered ctxt pkh >>=? fun () -> Delegate.frozen_deposits ctxt pkh >>=? fun deposits -> return deposits.initial_amount) ; + register1 ~chunked:false S.unstaked_frozen_deposits (fun ctxt pkh () () -> + check_delegate_registered ctxt pkh >>=? fun () -> + let ctxt_cycle = (Alpha_context.Level.current ctxt).cycle in + let csts = (Constants.all ctxt).parametric in + let last_unslashable_cycle = + Option.value ~default:Cycle.root + @@ Cycle.sub + ctxt_cycle + (csts.preserved_cycles + csts.max_slashing_period) + in + let cycles = Cycle.(last_unslashable_cycle ---> ctxt_cycle) in + List.map_es + (fun cycle -> + Unstaked_frozen_deposits.balance ctxt pkh cycle >>=? fun deposit -> + return {cycle; deposit}) + cycles) ; register1 ~chunked:false S.staking_balance (fun ctxt pkh () () -> check_delegate_registered ctxt pkh >>=? fun () -> Delegate.staking_balance ctxt pkh) ; @@ -538,6 +573,9 @@ let current_frozen_deposits ctxt block pkh = let frozen_deposits ctxt block pkh = RPC_context.make_call1 S.frozen_deposits ctxt block pkh () () +let unstaked_frozen_deposits ctxt block pkh = + RPC_context.make_call1 S.unstaked_frozen_deposits ctxt block pkh () () + let staking_balance ctxt block pkh = RPC_context.make_call1 S.staking_balance ctxt block pkh () () diff --git a/src/proto_alpha/lib_protocol/delegate_services.mli b/src/proto_alpha/lib_protocol/delegate_services.mli index 79a1a760ef50f442d41e4509735082a6db6435e4..c78efbb728c39f780066c53b2d2d160db38b9d3e 100644 --- a/src/proto_alpha/lib_protocol/delegate_services.mli +++ b/src/proto_alpha/lib_protocol/delegate_services.mli @@ -67,6 +67,8 @@ type info = { pending_consensus_keys : (Cycle.t * Signature.Public_key_hash.t) list; } +type deposit_per_cycle = {cycle : Cycle.t; deposit : Tez.t} + val info_encoding : info Data_encoding.t val info : @@ -93,6 +95,12 @@ val frozen_deposits : Signature.Public_key_hash.t -> Tez.t shell_tzresult Lwt.t +val unstaked_frozen_deposits : + 'a #RPC_context.simple -> + 'a -> + Signature.Public_key_hash.t -> + deposit_per_cycle list shell_tzresult Lwt.t + val staking_balance : 'a #RPC_context.simple -> 'a ->