Skip to content

Commit

Permalink
feat: fixing migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Supremesource committed Apr 5, 2024
1 parent a8d7cd3 commit b94ffb7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
9 changes: 9 additions & 0 deletions pallets/subspace/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ impl<T: Config> Pallet<T> {
Error::<T>::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::<T>::InvalidSubnetStakeThreshold
);

ensure!(
params.max_allowed_subnets > 0,
Error::<T>::InvalidMaxAllowedSubnets
Expand Down
1 change: 1 addition & 0 deletions pallets/subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ pub mod pallet {
InvalidMaxAllowedWeights,
InvalidMinStake,
InvalidMinDelegationFee,
InvalidSubnetStakeThreshold,

InvalidMaxNameLength,
InvalidMinNameLenght,
Expand Down
19 changes: 16 additions & 3 deletions pallets/subspace/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::get();
// Here we will just use the lower bound of the burn
let old_burn = Pallet::<T>::global_params().min_burn;

Expand All @@ -66,6 +68,17 @@ pub mod v2 {
// udpate
for netuid in 0..=largest_netuid {
Burn::<T>::insert(netuid, old_burn);
// update the emission that are below the threshold
let emission_for_netuid =
Pallet::<T>::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::<T>::iter_prefix(netuid).count();
let new_emission = vec![0; name_count];
Emission::<T>::insert(netuid, new_emission);
}
SubnetEmission::<T>::insert(netuid, emission_for_netuid);

Active::<T>::mutate(netuid, |v| v.push(true));
Consensus::<T>::mutate(netuid, |v| v.push(0));
Expand All @@ -76,11 +89,11 @@ pub mod v2 {
ValidatorTrust::<T>::mutate(netuid, |v| v.push(0));
}

StorageVersion::new(2).put::<Pallet<T>>();
log::info!("Migrated Burn to v2");
StorageVersion::new(6).put::<Pallet<T>>();
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()
}
}
Expand Down

0 comments on commit b94ffb7

Please sign in to comment.