Proto: split `delegate_storage.ml`
While trying to understand the delegation and staking code, I found the file delegate_storage.ml a bit harsh to grasp. It is a huge file: ~1000 lines. I tried to split the file in multiple files, with separate concerns to guide my understanding. Just like there is already smaller files like delegate_activation_storage.ml responsible for only one or two keys in the store (for instance delegate_activation_storage.ml manages Storage.Contract.Delegate_last_cycle_before_deactivation and Storage.Contract.Inactive_delegate).
Is there any interest for such a refactoring?
Here is the proposed split:
-
delegate_storage.mlStorage.DelegatesStorage.Contract.Frozen_deposits_limit
-
delegate_missed_endorsements_storage.mlStorage.Contract.Missed_endorsement
-
delegate_slashed_deposits_storage.mlStorage.Slashed_deposits
-
delegate_sampler.mlStorage.Delegate_sampler_state
-
delegate_cycles.ml-
cycle_endandinit_first_cycles
-
The MR also contains eight related minor refactoring, which simplify some interfaces:
-
Proto: move
set_activeintoStake_storageIt merges
Delegate_table_storage.set_activeintoStake_storage.set_active. The function inDelegate_table_storage, do not require access to the part ofStoragefrom whichDelegate_table_storageis responsible. Merging the two function simplify the interfaces and avoid having three distinctset_activefunctions. -
Proto: Rename
Delegate.check_delegateintoDelegate.checkJust a renaming.
-
Proto: simplify
Delegate.registeredThe function
Contract_delegate_storage.registeredis based on invariant ensured byDelegate_table_storage(i.e. a delegate is self delegated), better to move the function. Then, we simplify the function implementation by requiring only one read access into the context. -
Proto: remove
freeze_deposits_do_not_call_except_for_migrationThis function is only called once in the whole protocol code. I suggest to inline it for avoiding incorrect usage. Besides, the name is a bit misleading, the function is only used while migrating from genesis, which is more a chain initialization that a protocol migration.
-
Proto: merge
Seed.cycle_endintoDelegate.cycle_endIt is to enforce a little bit more the following comment in
seed_storage.ml:(* NB: the clearing of past seeds is done elsewhere by the caller *). -
Proto: introduce
Alpha_context.Contract.DelegateMove the functions
Alpha_context.Delegate.{init,set,find}intoAlpha_context.Contract.Delegate. These functions basically handle the field 'delegate' of a contract. They do not handle storage related to a given delegate, like other function inAlpha_context.Delegate. -
Prote: rename
Delegate.delegate_participation_infointoDelegate.participation_infoJust a renaming.
-
Proto/Delegate: remove dead code
Remove the duplicate function
Stake.delegate_pubkey(also available asDelegate.pubkey)