From 968c81c9a92397acd06407d7b67fd7d4ae977cc3 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 19 Dec 2023 09:22:54 +0100 Subject: [PATCH] Proto: clean frozen deposits --- src/proto_alpha/lib_protocol/init_storage.ml | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index ab5cec87df84..b88044bf93e3 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -157,6 +157,28 @@ let migrate_staking_balance_and_active_delegates_for_p ctxt = in return ctxt +(* This should clean most of the remaining fields [frozen_deposits]. + The field was removed in Oxford but cleaning it using [remove] was too + costly as it iterated over all contracts. + Instead we iterate over activate delegates. + If there are remaining [frozen_deposits] once P activates, they can still be + removed one by one in Q. *) +let clean_frozen_deposits_for_p ctxt = + let open Lwt_result_syntax in + let contracts_index = ["contracts"; "index"] in + let* contracts_tree = Raw_context.get_tree ctxt contracts_index in + let field = ["frozen_deposits"] in + let*! contracts_tree = + Storage.Stake.Active_delegates_with_minimal_stake.fold + ctxt + ~order:`Undefined + ~init:contracts_tree + ~f:(fun pkh contracts_tree -> + let path = Contract_repr.Index.to_path (Implicit pkh) field in + Raw_context.Tree.remove contracts_tree path) + in + Raw_context.update_tree ctxt contracts_index contracts_tree + let prepare_first_block chain_id ctxt ~typecheck_smart_contract ~typecheck_smart_rollup ~level ~timestamp ~predecessor = let open Lwt_result_syntax in @@ -257,6 +279,7 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract let*! ctxt = Storage.Pending_denunciations.clear ctxt in let*! ctxt = migrate_already_denounced_from_Oxford ctxt in let* ctxt = migrate_staking_balance_and_active_delegates_for_p ctxt in + let* ctxt = clean_frozen_deposits_for_p ctxt in return (ctxt, []) in let* ctxt = -- GitLab