diff --git a/pallets/subspace/src/global.rs b/pallets/subspace/src/global.rs index 577cf8759..ae8850958 100644 --- a/pallets/subspace/src/global.rs +++ b/pallets/subspace/src/global.rs @@ -55,6 +55,15 @@ impl Pallet { Error::::InvalidMinDelegationFee ); + // we can not increase the stake threshold without a migration + // that would mean that subnets that are getting emission would have to get them erased to 0 + ensure!( + params.subnet_stake_threshold.deconstruct() <= 100 + && params.subnet_stake_threshold.deconstruct() + <= old_params.subnet_stake_threshold.deconstruct(), + Error::::InvalidSubnetStakeThreshold + ); + ensure!( params.max_allowed_subnets > 0, Error::::InvalidMaxAllowedSubnets diff --git a/pallets/subspace/src/lib.rs b/pallets/subspace/src/lib.rs index 68c333225..a24870ebc 100644 --- a/pallets/subspace/src/lib.rs +++ b/pallets/subspace/src/lib.rs @@ -1071,6 +1071,7 @@ pub mod pallet { InvalidMaxAllowedWeights, InvalidMinStake, InvalidMinDelegationFee, + InvalidSubnetStakeThreshold, InvalidMaxNameLength, InvalidMinNameLenght, diff --git a/pallets/subspace/src/migrations.rs b/pallets/subspace/src/migrations.rs index f8d96d81f..6ee4d9146 100644 --- a/pallets/subspace/src/migrations.rs +++ b/pallets/subspace/src/migrations.rs @@ -56,6 +56,8 @@ pub mod v2 { // Migrate Burn to v2 if on_chain_version == 1 { + // Query for the threshold of stake that subnet needs to have + let subnet_stake_threshold = SubnetStakeThreshold::::get(); // Here we will just use the lower bound of the burn let old_burn = Pallet::::global_params().min_burn; @@ -66,6 +68,17 @@ pub mod v2 { // udpate for netuid in 0..=largest_netuid { Burn::::insert(netuid, old_burn); + // update the emission that are below the threshold + let emission_for_netuid = + Pallet::::calculate_network_emission(netuid, subnet_stake_threshold); + // empty out the module emissin on that subnet, as their epoch won't run, we + // don't want to confuse the user querying for the storage + if emission_for_netuid == 0 { + let name_count = Name::::iter_prefix(netuid).count(); + let new_emission = vec![0; name_count]; + Emission::::insert(netuid, new_emission); + } + SubnetEmission::::insert(netuid, emission_for_netuid); Active::::mutate(netuid, |v| v.push(true)); Consensus::::mutate(netuid, |v| v.push(0)); @@ -76,11 +89,11 @@ pub mod v2 { ValidatorTrust::::mutate(netuid, |v| v.push(0)); } - StorageVersion::new(2).put::>(); - log::info!("Migrated Burn to v2"); + StorageVersion::new(6).put::>(); + log::info!("Migrated subnets to v2"); T::DbWeight::get().writes(largest_netuid as u64) } else { - log::info!("Burn already updated"); + log::info!("Subnets already updated"); Weight::zero() } }