-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathmigrate_stake_threshold.rs
48 lines (38 loc) · 1.42 KB
/
migrate_stake_threshold.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use super::*;
use crate::HasMigrationRun;
use frame_support::pallet_prelude::ValueQuery;
use frame_support::storage_alias;
use frame_support::{traits::Get, weights::Weight};
use scale_info::prelude::string::String;
/// Module containing deprecated storage format for WeightsMinStake
pub mod deprecated_weights_min_stake {
use super::*;
#[storage_alias]
pub(super) type WeightsMinStake<T: Config> = StorageValue<Pallet<T>, u64, ValueQuery>;
}
pub fn migrate_stake_threshold<T: Config>() -> Weight {
let migration_name = b"migrate_stake_threshold".to_vec();
let mut weight = T::DbWeight::get().reads(1);
if HasMigrationRun::<T>::get(&migration_name) {
log::info!(
"Migration '{:?}' has already run. Skipping.",
migration_name
);
return weight;
}
log::info!(
"Running migration '{}'",
String::from_utf8_lossy(&migration_name)
);
let min_stake = deprecated_weights_min_stake::WeightsMinStake::<T>::get();
StakeThreshold::<T>::set(min_stake);
deprecated_weights_min_stake::WeightsMinStake::<T>::kill();
weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1));
HasMigrationRun::<T>::insert(&migration_name, true);
weight = weight.saturating_add(T::DbWeight::get().writes(1));
log::info!(
"Migration '{:?}' completed successfully.",
String::from_utf8_lossy(&migration_name)
);
weight
}