Skip to content

Commit

Permalink
fixed remove module + test
Browse files Browse the repository at this point in the history
  • Loading branch information
YourUsername committed Mar 12, 2024
1 parent eee59a1 commit 2414c81
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pallets/subspace/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<T: Config> Pallet<T> {
incentive[uid as usize] = incentive[replace_uid as usize];
dividends[uid as usize] = dividends[replace_uid as usize];
emission[uid as usize] = emission[replace_uid as usize];
last_update[uid as usize] = emission[replace_uid as usize];
last_update[uid as usize] = last_update[replace_uid as usize];

// pop the last element (which is now a duplicate)
incentive.pop();
Expand Down
6 changes: 4 additions & 2 deletions pallets/subspace/src/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,16 @@ impl<T: Config> Pallet<T> {
let max_subnets: u16 = Self::get_global_max_allowed_subnets();
// if we have not reached the max number of subnets, then we can start a new one
if num_subnets >= max_subnets {
let mut min_stake: u64 = u64::MAX;
let mut min_stake_netuid: u16 = max_subnets.saturating_sub(1); // the default last ui
let mut min_stake: u64 = u64::MAX; // initially represents the maximum amount that is possible to have
let mut min_stake_netuid: u16 = max_subnets.saturating_sub(1); // initially represents the last netuid

for (netuid, net_stake) in <TotalStake<T> as IterableStorageMap<u16, u64>>::iter() {
if net_stake <= min_stake {
min_stake = net_stake;
min_stake_netuid = netuid;
}
}
// if the stake is greater than the least staked network, then we can start a new one
ensure!(stake > min_stake, Error::<T>::NotEnoughStakeToStartNetwork);
Self::remove_subnet(min_stake_netuid);
}
Expand Down
10 changes: 8 additions & 2 deletions pallets/subspace/tests/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,14 @@ fn test_dynamic_burn() {
// - adjustment alpha = 0
// - min_burn = 2 $COMAI
// - max_burn = 250 $COMAI

let token_amount = 100_000_000;
let mut params = SubspaceModule::global_params();
params.min_burn = 2 * token_amount;
params.max_burn = 250 * token_amount;
params.adjustment_alpha = 0;
params.target_registrations_interval = 200;
params.target_registrations_per_interval = 100;
SubspaceModule::set_global_params(params);
let netuid = 0;
// first register 1000 modules (10 * the default registration target interval)
// this is 5 modules per block
Expand Down Expand Up @@ -969,7 +975,7 @@ fn test_dynamic_burn() {
// burn is now at 11 instead of 2
assert!(
SubspaceModule::get_burn() == 11 * token_amount,
"current burn: {:?}",
"current burn {:?}",
SubspaceModule::get_burn()
);

Expand Down

0 comments on commit 2414c81

Please sign in to comment.