Skip to content

Commit

Permalink
feat: decreasing DefaultSubnetStakeThreshold
Browse files Browse the repository at this point in the history
  • Loading branch information
YourUsername committed Apr 12, 2024
1 parent 1810cfe commit f676748
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
1 change: 0 additions & 1 deletion pallets/subspace/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ impl<T: Config> Pallet<T> {
}

// Whitelist management

pub fn is_in_legit_whitelist(account_id: &T::AccountId) -> bool {
LegitWhitelist::<T>::contains_key(account_id)
}
Expand Down
7 changes: 2 additions & 5 deletions pallets/subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub mod pallet {

#[pallet::type_value]
pub fn DefaultSubnetStakeThreshold<T: Config>() -> Percent {
Percent::from_percent(10)
Percent::from_percent(5)
}

#[pallet::storage]
Expand Down Expand Up @@ -985,10 +985,7 @@ pub mod pallet {
NetworkExist, // --- Thrown when the network already exist.
InvalidIpType, /* ---- Thrown when the user tries to serve an module which
* is not of type 4 (IPv4) or 6 (IPv6). */
InvalidIpAddress, /* --- Thrown when an invalid IP address is passed to the serve
* function. */
NotRegistered, /* ---- Thrown when the caller requests setting or removing data from a
* module which does not exist in the active set. */
NotRegistered, // module which does not exist in the active set.
NotEnoughStaketoWithdraw, /* ---- Thrown when the caller requests removing more stake
* then there exists in the staking account. See: fn
* remove_stake. */
Expand Down
52 changes: 42 additions & 10 deletions pallets/subspace/tests/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use frame_support::assert_ok;
use log::info;
use mock::*;
use sp_core::U256;
use sp_runtime::Percent;
use sp_std::vec;

/* TO DO SAM: write test for LatuUpdate after it is set */

#[test]
fn test_add_subnets() {
new_test_ext().execute_with(|| {
Expand Down Expand Up @@ -146,14 +145,6 @@ fn test_set_single_temple(tempo: u16) {
});
}

// TODO:
// #[test]
// fn test_set_tempo() {
// for tempo in [1, 2, 4, 8, 16, 32, 64, 128] {
// test_set_single_temple(tempo);
// }
// }

#[test]
fn test_emission_ratio() {
new_test_ext().execute_with(|| {
Expand Down Expand Up @@ -599,3 +590,44 @@ fn test_yuma_self_vote() {
assert_eq!(actual_stake_change, expected_stake_change);
});
}

#[test]
fn test_emission_activation() {
new_test_ext().execute_with(|| {
// Define the subnet stakes
let subnet_stakes = [
("Subnet A", to_nano(10), true),
("Subnet B", to_nano(4), false), // This one should not activate
("Subnet C", to_nano(86), true),
];

// Set the stake threshold and minimum burn
SubspaceModule::set_subnet_stake_threshold(Percent::from_percent(5));
SubspaceModule::set_min_burn(0);

// Register the subnets
for (i, (name, stake, _)) in subnet_stakes.iter().enumerate() {
assert_ok!(register_module(i as u16, U256::from(i as u64), *stake));
info!("Registered {name} with stake: {stake}");
}

step_block(1_000);

// Check if subnet rewards have increased, but Subnet B should not have activated
for (i, (name, initial_stake, should_activate)) in subnet_stakes.iter().enumerate() {
let current_stake = SubspaceModule::get_total_subnet_stake(i as u16);
if *should_activate {
assert!(
current_stake > *initial_stake,
"{name} should have activated and increased its stake"
);
} else {
assert_eq!(
current_stake, *initial_stake,
"{name} should not have activated"
);
}
info!("{name} current stake: {current_stake}");
}
});
}

0 comments on commit f676748

Please sign in to comment.