From ce99fcaa1d2b55678980d11fadc591499ce117b7 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Thu, 22 Feb 2024 12:26:54 +0100 Subject: [PATCH] Proto: remove clear --- .../delegate_slashed_deposits_storage.ml | 40 ++++++++++++------- .../delegate_slashed_deposits_storage.mli | 3 +- src/proto_alpha/lib_protocol/init_storage.ml | 2 +- 3 files changed, 28 insertions(+), 17 deletions(-) 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 fdc370c7a5bc..b73cdc7a69e9 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.ml @@ -28,21 +28,31 @@ (* TODO #6918: Remove after P *) let update_slashing_storage_for_p ctxt = let open Lwt_result_syntax in - let*! ctxt = - Storage.Contract.Slashed_deposits__Oxford.fold - ctxt - ~order:`Undefined - ~init:ctxt - ~f:(fun contract slashed_history ctxt -> - let slashed_history = - List.map - (fun (cycle, percentage) -> - (cycle, Percentage.convert_from_o_to_p percentage)) - slashed_history - in - Storage.Contract.Slashed_deposits.add ctxt contract slashed_history) - in - Storage.Contract.Slashed_deposits__Oxford.clear ctxt + Storage.Delegates.fold + ctxt + ~init:(Ok ctxt) + ~order:`Undefined + ~f:(fun delegate ctxt -> + let*? ctxt in + let delegate = Contract_repr.Implicit delegate in + let* slashed_history = + Storage.Contract.Slashed_deposits__Oxford.find ctxt delegate + in + match slashed_history with + | None -> return ctxt + | Some slashed_history -> + let slashed_history = + List.map + (fun (cycle, percentage) -> + (cycle, Percentage.convert_from_o_to_p percentage)) + slashed_history + in + let*! ctxt = + Storage.Contract.Slashed_deposits.add ctxt delegate slashed_history + in + Storage.Contract.Slashed_deposits__Oxford.remove_existing + ctxt + delegate) type reward_and_burn = {reward : Tez_repr.t; amount_to_burn : Tez_repr.t} 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 3b08a5e4f6bb..7e525f4dd162 100644 --- a/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli +++ b/src/proto_alpha/lib_protocol/delegate_slashed_deposits_storage.mli @@ -83,7 +83,8 @@ val punish_double_signing : val apply_and_clear_denunciations : Raw_context.t -> (Raw_context.t * Receipt_repr.balance_updates) tzresult Lwt.t -val update_slashing_storage_for_p : Raw_context.t -> Raw_context.t Lwt.t +val update_slashing_storage_for_p : + Raw_context.t -> Raw_context.t tzresult Lwt.t module For_RPC : sig (** [get_estimated_shared_pending_slashed_amount ctxt delegate] diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index 8ba5ecaddcce..5ee8149b4cd7 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -344,7 +344,7 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract cleanup_values_for_protocol_p ctxt previous_proto_constants level in (* Update the percentage representation of the stored slashes *) - let*! ctxt = + let* ctxt = Delegate_slashed_deposits_storage.update_slashing_storage_for_p ctxt in let* ctxt = update_total_supply_for_p chain_id ctxt in -- GitLab