Skip to content

Commit

Permalink
storage version checks added
Browse files Browse the repository at this point in the history
  • Loading branch information
ipapandinas committed Jul 25, 2024
1 parent 5b5affa commit 68887d7
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 79 deletions.
61 changes: 34 additions & 27 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ use frame_support::{
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{
AsEnsureOriginWithArg, ConstBool, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance,
InstanceFilter, Nothing, OnFinalize, OnRuntimeUpgrade, OnUnbalanced, Randomness,
WithdrawReasons,
AsEnsureOriginWithArg, ConstBool, ConstU32, Contains, Currency, FindAuthor, Get,
GetStorageVersion, Imbalance, InstanceFilter, Nothing, OnFinalize, OnRuntimeUpgrade,
OnUnbalanced, Randomness, WithdrawReasons,
},
weights::{
constants::{
Expand Down Expand Up @@ -1265,30 +1265,37 @@ pub type Executive = frame_executive::Executive<
pub struct StaticTierParamsMigration;
impl OnRuntimeUpgrade for StaticTierParamsMigration {
fn on_runtime_upgrade() -> Weight {
let tier_thresholds = BoundedVec::try_from(vec![
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(35_700_000), // 3.57%
minimum_required_percentage: Perbill::from_parts(23_800_000), // 2.38%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(8_900_000), // 0.89%
minimum_required_percentage: Perbill::from_parts(6_000_000), // 0.6%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(23_800_000), // 2.38%
minimum_required_percentage: Perbill::from_parts(17_900_000), // 1.79%
},
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(6_000_000), // 0.6%
},
])
.unwrap();

pallet_dapp_staking_v3::StaticTierParams::<Runtime>::mutate(|config| {
config.tier_thresholds = tier_thresholds;
});

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
let onchain_storage_version =
pallet_dapp_staking_v3::Pallet::<Runtime>::on_chain_storage_version();

if onchain_storage_version < 8 {
let tier_thresholds = BoundedVec::try_from(vec![
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(35_700_000), // 3.57%
minimum_required_percentage: Perbill::from_parts(23_800_000), // 2.38%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(8_900_000), // 0.89%
minimum_required_percentage: Perbill::from_parts(6_000_000), // 0.6%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(23_800_000), // 2.38%
minimum_required_percentage: Perbill::from_parts(17_900_000), // 1.79%
},
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(6_000_000), // 0.6%
},
])
.unwrap();

pallet_dapp_staking_v3::StaticTierParams::<Runtime>::mutate(|config| {
config.tier_thresholds = tier_thresholds;
});

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
} else {
Weight::zero()
}
}
}

Expand Down
59 changes: 33 additions & 26 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use frame_support::{
fungible::HoldConsideration,
tokens::{PayFromAccount, UnityAssetBalanceConversion},
AsEnsureOriginWithArg, ConstU128, ConstU32, Contains, Currency, EqualPrivilegeOnly,
FindAuthor, Get, Imbalance, InstanceFilter, LinearStoragePrice, Nothing, OnFinalize,
OnRuntimeUpgrade, OnUnbalanced, WithdrawReasons,
FindAuthor, Get, GetStorageVersion, Imbalance, InstanceFilter, LinearStoragePrice, Nothing,
OnFinalize, OnRuntimeUpgrade, OnUnbalanced, WithdrawReasons,
},
weights::{
constants::{
Expand Down Expand Up @@ -1619,30 +1619,37 @@ pub type Executive = frame_executive::Executive<
pub struct StaticTierParamsMigration;
impl OnRuntimeUpgrade for StaticTierParamsMigration {
fn on_runtime_upgrade() -> Weight {
let tier_thresholds = BoundedVec::try_from(vec![
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(20_000), // 0.0020%
minimum_required_percentage: Perbill::from_parts(17_000), // 0.0017%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(10_000), // 0.0010%
minimum_required_percentage: Perbill::from_parts(6_800), // 0.00068%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(5_400), // 0.00054%
minimum_required_percentage: Perbill::from_parts(3_400), // 0.00034%
},
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(1_400), // 0.00014%
},
])
.unwrap();

pallet_dapp_staking_v3::StaticTierParams::<Runtime>::mutate(|config| {
config.tier_thresholds = tier_thresholds;
});

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
let onchain_storage_version =
pallet_dapp_staking_v3::Pallet::<Runtime>::on_chain_storage_version();

if onchain_storage_version < 8 {
let tier_thresholds = BoundedVec::try_from(vec![
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(20_000), // 0.0020%
minimum_required_percentage: Perbill::from_parts(17_000), // 0.0017%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(10_000), // 0.0010%
minimum_required_percentage: Perbill::from_parts(6_800), // 0.00068%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(5_400), // 0.00054%
minimum_required_percentage: Perbill::from_parts(3_400), // 0.00034%
},
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(1_400), // 0.00014%
},
])
.unwrap();

pallet_dapp_staking_v3::StaticTierParams::<Runtime>::mutate(|config| {
config.tier_thresholds = tier_thresholds;
});

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
} else {
Weight::zero()
}
}
}

Expand Down
60 changes: 34 additions & 26 deletions runtime/shiden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ use frame_support::{
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{
AsEnsureOriginWithArg, ConstU32, Contains, Currency, FindAuthor, Get, Imbalance,
InstanceFilter, Nothing, OnFinalize, OnRuntimeUpgrade, OnUnbalanced, WithdrawReasons,
AsEnsureOriginWithArg, ConstU32, Contains, Currency, FindAuthor, Get, GetStorageVersion,
Imbalance, InstanceFilter, Nothing, OnFinalize, OnRuntimeUpgrade, OnUnbalanced,
WithdrawReasons,
},
weights::{
constants::{
Expand Down Expand Up @@ -1266,30 +1267,37 @@ pub type Executive = frame_executive::Executive<
pub struct StaticTierParamsMigration;
impl OnRuntimeUpgrade for StaticTierParamsMigration {
fn on_runtime_upgrade() -> Weight {
let tier_thresholds = BoundedVec::try_from(vec![
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(35_700_000), // 3.57%
minimum_required_percentage: Perbill::from_parts(23_800_000), // 2.38%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(8_900_000), // 0.89%
minimum_required_percentage: Perbill::from_parts(6_000_000), // 0.6%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(23_800_000), // 2.38%
minimum_required_percentage: Perbill::from_parts(17_900_000), // 1.79%
},
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(6_000_000), // 0.6%
},
])
.unwrap();

pallet_dapp_staking_v3::StaticTierParams::<Runtime>::mutate(|config| {
config.tier_thresholds = tier_thresholds;
});

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
let onchain_storage_version =
pallet_dapp_staking_v3::Pallet::<Runtime>::on_chain_storage_version();

if onchain_storage_version < 8 {
let tier_thresholds = BoundedVec::try_from(vec![
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(35_700_000), // 3.57%
minimum_required_percentage: Perbill::from_parts(23_800_000), // 2.38%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(8_900_000), // 0.89%
minimum_required_percentage: Perbill::from_parts(6_000_000), // 0.6%
},
TierThreshold::DynamicPercentage {
current_percentage: Perbill::from_parts(23_800_000), // 2.38%
minimum_required_percentage: Perbill::from_parts(17_900_000), // 1.79%
},
TierThreshold::FixedPercentage {
required_percentage: Perbill::from_parts(6_000_000), // 0.6%
},
])
.unwrap();

pallet_dapp_staking_v3::StaticTierParams::<Runtime>::mutate(|config| {
config.tier_thresholds = tier_thresholds;
});

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 1)
} else {
Weight::zero()
}
}
}

Expand Down

0 comments on commit 68887d7

Please sign in to comment.