diff --git a/src/proto_alpha/lib_protocol/delegate_cycles.ml b/src/proto_alpha/lib_protocol/delegate_cycles.ml index 9547c9fe549e2b26b5ba9cb1f9675ef07916e7b1..bc72d26f6ec36b51b60aad70599bf48437b7a0ca 100644 --- a/src/proto_alpha/lib_protocol/delegate_cycles.ml +++ b/src/proto_alpha/lib_protocol/delegate_cycles.ml @@ -35,7 +35,7 @@ let update_activity ctxt last_cycle = ctxt ~order:`Sorted ~init:(Ok (ctxt, [])) - ~f:(fun delegate () acc -> + ~f:(fun delegate acc -> let*? ctxt, deactivated = acc in let* cycle = Delegate_activation_storage.last_cycle_before_deactivation diff --git a/src/proto_alpha/lib_protocol/init_storage.ml b/src/proto_alpha/lib_protocol/init_storage.ml index a63583e0c2307e7d099bbac7e71eb9df88a8f750..ab5cec87df84592bd6c21eaa8be8a90e2a2eb723 100644 --- a/src/proto_alpha/lib_protocol/init_storage.ml +++ b/src/proto_alpha/lib_protocol/init_storage.ml @@ -134,6 +134,29 @@ let migrate_already_denounced_from_Oxford ctxt = | None -> return ctxt | Some previous_cycle -> migrate_cycle ctxt previous_cycle +(* This removes snapshots and moves the current [staking_balance] one level + up. Same thing for active delegates with minimal stake but renames the key + at the same time. *) +let migrate_staking_balance_and_active_delegates_for_p ctxt = + let open Lwt_result_syntax in + let* staking_balance_tree = + Raw_context.get_tree ctxt ["staking_balance"; "current"] + in + let*! ctxt = + Raw_context.add_tree ctxt ["staking_balance"] staking_balance_tree + in + let* active_delegates_tree = + Raw_context.get_tree ctxt ["active_delegate_with_one_roll"; "current"] + in + let*! ctxt = Raw_context.remove ctxt ["active_delegate_with_one_roll"] in + let*! ctxt = + Raw_context.add_tree + ctxt + ["active_delegates_with_minimal_stake"] + active_delegates_tree + in + return ctxt + let prepare_first_block chain_id ctxt ~typecheck_smart_contract ~typecheck_smart_rollup ~level ~timestamp ~predecessor = let open Lwt_result_syntax in @@ -233,6 +256,7 @@ let prepare_first_block chain_id ctxt ~typecheck_smart_contract that are not slashed whereas unstake_requests are slashed. *) 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 return (ctxt, []) in let* ctxt = diff --git a/src/proto_alpha/lib_protocol/stake_storage.ml b/src/proto_alpha/lib_protocol/stake_storage.ml index 5475a531010a2f47529e3f1ce76e86e3a5e3a44c..0d1e84ab716bf20e141e21f46738fac683e05d03 100644 --- a/src/proto_alpha/lib_protocol/stake_storage.ml +++ b/src/proto_alpha/lib_protocol/stake_storage.ml @@ -94,7 +94,7 @@ let initialize_delegate ctxt delegate ~delegated = let* ctxt = Storage.Stake.Staking_balance.init ctxt delegate balance in if has_minimal_stake ctxt balance then let*! ctxt = - Storage.Stake.Active_delegates_with_minimal_stake.add ctxt delegate () + Storage.Stake.Active_delegates_with_minimal_stake.add ctxt delegate in return ctxt else return ctxt @@ -135,7 +135,7 @@ let update_stake ~f ctxt delegate = return ctxt else let*! ctxt = - Storage.Stake.Active_delegates_with_minimal_stake.add ctxt delegate () + Storage.Stake.Active_delegates_with_minimal_stake.add ctxt delegate in return ctxt | false, false | true, true -> return ctxt @@ -193,7 +193,7 @@ let set_active ctxt delegate = let* staking_balance = get_full_staking_balance ctxt delegate in if has_minimal_stake ctxt staking_balance then let*! ctxt = - Storage.Stake.Active_delegates_with_minimal_stake.add ctxt delegate () + Storage.Stake.Active_delegates_with_minimal_stake.add ctxt delegate in return ctxt else return ctxt @@ -213,7 +213,7 @@ let fold_on_active_delegates_with_minimal_stake_es ctxt ~f ~order ~init = ctxt ~order ~init:(Ok init) - ~f:(fun delegate () acc -> + ~f:(fun delegate acc -> let*? acc in f delegate acc) diff --git a/src/proto_alpha/lib_protocol/stake_storage.mli b/src/proto_alpha/lib_protocol/stake_storage.mli index 2c959aed04ac3a15e3fe73f19435e551bbaef90e..3b51335efb738d80a0f9ef2a927131f585c24c37 100644 --- a/src/proto_alpha/lib_protocol/stake_storage.mli +++ b/src/proto_alpha/lib_protocol/stake_storage.mli @@ -105,7 +105,7 @@ val fold_on_active_delegates_with_minimal_stake_s : Raw_context.t -> order:[`Sorted | `Undefined] -> init:'a -> - f:(Signature.Public_key_hash.t -> unit -> 'a -> 'a Lwt.t) -> + f:(Signature.Public_key_hash.t -> 'a -> 'a Lwt.t) -> 'a Lwt.t val get_selected_distribution : diff --git a/src/proto_alpha/lib_protocol/storage.ml b/src/proto_alpha/lib_protocol/storage.ml index 301ea5b28444ee74be8100415712f09bd4eb1e4a..c57acf3949e68b5b2781b6869db1fbfd6855fd93 100644 --- a/src/proto_alpha/lib_protocol/storage.ml +++ b/src/proto_alpha/lib_protocol/storage.ml @@ -1287,30 +1287,21 @@ module Pending_staking_parameters = Cycle.Pending_staking_parameters module Stake = struct module Staking_balance = - Make_indexed_data_snapshotable_storage + Make_indexed_data_storage (Make_subcontext (Registered) (Raw_context) (struct let name = ["staking_balance"] end)) - (Int31_index) - (Public_key_hash_index) + (Public_key_hash_index) (Full_staking_balance_repr) module Active_delegates_with_minimal_stake = - Make_indexed_data_snapshotable_storage + Make_data_set_storage (Make_subcontext (Registered) (Raw_context) (struct - (* This name is for historical reasons, when the stake was - expressed in rolls (that is, pre-Ithaca). *) - let name = ["active_delegate_with_one_roll"] + let name = ["active_delegates_with_minimal_stake"] end)) - (Int31_index) - (Public_key_hash_index) - (struct - type t = unit - - let encoding = Data_encoding.unit - end) + (Public_key_hash_index) module Selected_distribution_for_cycle = Cycle.Selected_stake_distribution module Total_active_stake = Cycle.Total_active_stake diff --git a/src/proto_alpha/lib_protocol/storage.mli b/src/proto_alpha/lib_protocol/storage.mli index 624308c5e63bbe7fcb28ad620d21f0a40d75f31a..d75ce4ffaae1e28b82f8466bfc93db6ebe6e1848 100644 --- a/src/proto_alpha/lib_protocol/storage.mli +++ b/src/proto_alpha/lib_protocol/storage.mli @@ -507,19 +507,15 @@ module Stake : sig less than {!Constants_parametric_repr.minimal_stake}. It might be large. *) module Staking_balance : - Indexed_data_snapshotable_storage + Indexed_data_storage with type key = Signature.Public_key_hash.t and type value = Full_staking_balance_repr.t - and type snapshot = int and type t := Raw_context.t - (** This is a set, encoded in a map with value unit. This should be - fairly small compared to staking balance *) + (** This should be fairly small compared to staking balance *) module Active_delegates_with_minimal_stake : - Indexed_data_snapshotable_storage - with type key = Signature.Public_key_hash.t - and type value = unit - and type snapshot = int + Data_set_storage + with type elt = Signature.Public_key_hash.t and type t := Raw_context.t (** Counter of stake storage snapshots taken since last cycle *)