diff --git a/node/src/command.rs b/node/src/command.rs index 2f4e3eb58..1370dc2b3 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -194,27 +194,6 @@ pub fn run() -> sc_cli::Result<()> { } }) } - #[cfg(feature = "try-runtime")] - Some(Subcommand::TryRuntime(cmd)) => { - use crate::service::ExecutorDispatch; - use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch}; - let runner = cli.create_runner(cmd)?; - runner.async_run(|config| { - // we don't need any of the components of new_partial, just a runtime, or a task - // manager to do `async_run`. - let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry); - let task_manager = - sc_service::TaskManager::new(config.tokio_handle.clone(), registry) - .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; - Ok(( - cmd.run::::ExtendHostFunctions, - >>(), - task_manager, - )) - }) - } Some(Subcommand::TryRuntime) => { Err("TryRuntime is available through its own CLI now: ".into()) } diff --git a/pallets/subspace/src/global.rs b/pallets/subspace/src/global.rs index 79a3b234c..18425a72f 100644 --- a/pallets/subspace/src/global.rs +++ b/pallets/subspace/src/global.rs @@ -40,7 +40,10 @@ impl Pallet { // check if the name already exists ensure!(params.max_name_length > 0, Error::::InvalidMaxNameLength); - ensure!(params.min_delegation_fee.deconstruct() <= 100, Error::::InvalidMinDelegationFee); + ensure!( + params.min_delegation_fee.deconstruct() <= 100, + Error::::InvalidMinDelegationFee + ); ensure!( params.max_allowed_subnets > 0, diff --git a/pallets/subspace/src/lib.rs b/pallets/subspace/src/lib.rs index 54c93408f..50f5a4dae 100644 --- a/pallets/subspace/src/lib.rs +++ b/pallets/subspace/src/lib.rs @@ -5,6 +5,9 @@ use frame_system::{self as system, ensure_signed}; pub use pallet::*; +// export the migrations here +pub mod migrations; + use frame_support::{ dispatch, dispatch::{DispatchInfo, PostDispatchInfo}, @@ -63,8 +66,11 @@ pub mod pallet { use sp_arithmetic::per_things::Percent; pub use sp_std::{vec, vec::Vec}; + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] + #[pallet::storage_version(STORAGE_VERSION)] #[pallet::without_storage_info] pub struct Pallet(_); @@ -242,8 +248,9 @@ pub mod pallet { Percent::from_percent(5u8) } - #[pallet::storage] - pub type MinDelegationFeeGlobal = StorageValue<_, Percent, ValueQuery, DefaultMinDelegationFeeGlobal>; + #[pallet::storage] + pub type MinDelegationFeeGlobal = + StorageValue<_, Percent, ValueQuery, DefaultMinDelegationFeeGlobal>; #[pallet::type_value] pub fn DefaultMinWeightStake() -> u64 { @@ -282,11 +289,11 @@ pub mod pallet { pub max_proposals: u64, // max number of proposals per block // mins - pub min_burn: u64, // min burn required - pub max_burn: u64, // max burn allowed - pub min_stake: u64, // min stake required + pub min_burn: u64, // min burn required + pub max_burn: u64, // max burn allowed + pub min_stake: u64, // min stake required pub min_delegation_fee: Percent, // min delegation fee - pub min_weight_stake: u64, // min weight stake required + pub min_weight_stake: u64, // min weight stake required // other pub target_registrations_per_interval: u16, // desired number of registrations per interval @@ -1073,6 +1080,10 @@ pub mod pallet { // # Args: // * 'n': (T::BlockNumber): // - The number of the block we are initializing. + // fn on_runtime_upgrade() -> frame_support::weights::Weight { + // migration::on_runtime_upgrade::() + // } + fn on_initialize(_block_number: BlockNumberFor) -> Weight { Self::block_step(); @@ -1170,7 +1181,8 @@ pub mod pallet { params.name = name; params.address = address; if let Some(delegation_fee) = delegation_fee { - ensure!(delegation_fee >= Self::get_min_deleg_fee_global(), + ensure!( + delegation_fee >= Self::get_min_deleg_fee_global(), Error::::InvalidMinDelegationFee ); params.delegation_fee = delegation_fee; diff --git a/pallets/subspace/src/migrations.rs b/pallets/subspace/src/migrations.rs new file mode 100644 index 000000000..beaea4439 --- /dev/null +++ b/pallets/subspace/src/migrations.rs @@ -0,0 +1,88 @@ +use super::*; + +use frame_support::{ + codec::{Decode, Encode}, + pallet_prelude::StorageValue, + traits::{Get, OnRuntimeUpgrade, StorageInstance, StorageVersion}, + weights::Weight, +}; +use scale_info::TypeInfo; + +#[derive(Decode, Encode, TypeInfo, Default)] +pub struct OldGlobalParams { + pub burn_rate: u16, + pub max_name_length: u16, + pub max_allowed_subnets: u16, + pub max_allowed_modules: u16, + pub max_registrations_per_block: u16, + pub max_allowed_weights: u16, + pub max_proposals: u64, + pub min_burn: u64, + pub min_stake: u64, + pub min_weight_stake: u64, + pub unit_emission: u64, + pub tx_rate_limit: u64, + pub vote_threshold: u16, + pub vote_mode: Vec, +} + +impl StorageInstance for Pallet { + fn pallet_prefix() -> &'static str { + "Subspace" + } + + const STORAGE_PREFIX: &'static str = "Subspace"; +} + +pub mod v1 { + use super::*; + + pub struct MigrateToV1(sp_std::marker::PhantomData); + + impl OnRuntimeUpgrade for MigrateToV1 { + fn on_runtime_upgrade() -> Weight { + let on_chain_version = StorageVersion::get::>(); + + // Migrate GlobalParams to v1 + if on_chain_version == 0 { + let encoded = + StorageValue::, OldGlobalParams>::get().unwrap_or_default().encode(); + let old_global_params = OldGlobalParams::decode(&mut encoded.as_slice()) + .expect("Decoding old global params failed"); + + let new_global_params = GlobalParams { + burn_rate: old_global_params.burn_rate, + max_name_length: old_global_params.max_name_length, + max_allowed_subnets: old_global_params.max_allowed_subnets, + max_allowed_modules: old_global_params.max_allowed_modules, + max_registrations_per_block: old_global_params.max_registrations_per_block, + max_allowed_weights: old_global_params.max_allowed_weights, + max_proposals: old_global_params.max_proposals, + min_burn: old_global_params.min_burn, + min_stake: old_global_params.min_stake, + min_weight_stake: old_global_params.min_weight_stake, + unit_emission: old_global_params.unit_emission, + tx_rate_limit: old_global_params.tx_rate_limit, + vote_threshold: old_global_params.vote_threshold, + vote_mode: old_global_params.vote_mode, + max_burn: DefaultMaxBurn::::get(), + min_delegation_fee: DefaultMinDelegationFeeGlobal::::get(), + target_registrations_per_interval: + DefaultTargetRegistrationsPerInterval::::get(), + target_registrations_interval: DefaultTargetRegistrationsInterval::::get(), + adjustment_alpha: DefaultAdjustmentAlpha::::get(), + }; + + StorageValue::, GlobalParams>::put(&new_global_params); + StorageVersion::new(1).put::>(); + + log::info!("Migrated GlobalParams to v1"); + + T::DbWeight::get().writes(1) + } else { + log::info!("GlobalParams already updated"); + Weight::zero() + } + } + } +} diff --git a/pallets/subspace/src/staking.rs b/pallets/subspace/src/staking.rs index c84870656..f0bac902f 100644 --- a/pallets/subspace/src/staking.rs +++ b/pallets/subspace/src/staking.rs @@ -255,7 +255,7 @@ impl Pallet { pub fn get_delegation_fee(netuid: u16, module_key: &T::AccountId) -> Percent { let min_deleg_fee_global = Self::get_min_deleg_fee_global(); let delegation_fee = DelegationFee::::get(netuid, module_key); - + delegation_fee.max(min_deleg_fee_global) } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 091d20bc3..2daeab32d 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -122,6 +122,7 @@ pub mod opaque { } } +pub type Migrations = (pallet_subspace::migrations::v1::MigrateToV1,); // To learn more about runtime versioning, see: // https://docs.substrate.io/main-docs/build/upgrade#runtime-versioning #[sp_version::runtime_version] @@ -134,7 +135,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 102, + spec_version: 103, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -534,6 +535,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, + Migrations, >; impl fp_self_contained::SelfContainedCall for RuntimeCall {