Skip to content

Commit

Permalink
profit share
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Dec 18, 2023
1 parent 177588b commit f2d481d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
8 changes: 4 additions & 4 deletions pallets/subspace/src/autogen_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof: `SubspaceModule::BurnRate` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SubspaceModule::VotePeriod` (r:1 w:0)
/// Proof: `SubspaceModule::VotePeriod` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SubspaceModule::SubnetVoteThreshold` (r:1 w:0)
/// Proof: `SubspaceModule::SubnetVoteThreshold` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SubspaceModule::VoteThresholdSubnet` (r:1 w:0)
/// Proof: `SubspaceModule::VoteThresholdSubnet` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SubspaceModule::TotalSubnets` (r:1 w:1)
/// Proof: `SubspaceModule::TotalSubnets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `SubspaceModule::Emission` (r:1 w:1)
Expand Down Expand Up @@ -489,8 +489,8 @@ impl WeightInfo for () {
/// Proof: `SubspaceModule::BurnRate` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SubspaceModule::VotePeriod` (r:1 w:0)
/// Proof: `SubspaceModule::VotePeriod` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SubspaceModule::SubnetVoteThreshold` (r:1 w:0)
/// Proof: `SubspaceModule::SubnetVoteThreshold` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SubspaceModule::VoteThresholdSubnet` (r:1 w:0)
/// Proof: `SubspaceModule::VoteThresholdSubnet` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `SubspaceModule::TotalSubnets` (r:1 w:1)
/// Proof: `SubspaceModule::TotalSubnets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `SubspaceModule::Emission` (r:1 w:1)
Expand Down
2 changes: 1 addition & 1 deletion pallets/subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ pub mod pallet {
#[pallet::type_value]
pub fn DefaultVoteThreshold<T: Config>() -> u16 {50} // out of 100
#[pallet::storage] // --- MAP ( netuid ) --> epoch
pub type SubnetVoteThreshold<T> = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultVoteThreshold<T>>;
pub type VoteThresholdSubnet<T> = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultVoteThreshold<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> epoch
pub type GlobalVoteThreshold<T> = StorageValue<_, u16, ValueQuery, DefaultVoteThreshold<T>>;

Expand Down
2 changes: 1 addition & 1 deletion pallets/subspace/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<T: Config> Pallet<T> {

// remove the network if it is empty
if N::<T>::get(netuid) == 0 {
Self::remove_network_for_netuid(netuid);
Self::remove_subnet(netuid);
}

// remove stake from old key and add to new key
Expand Down
2 changes: 1 addition & 1 deletion pallets/subspace/src/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl<T: Config> Pallet<T> {
}
}
ensure!(stake > min_stake , Error::<T>::NotEnoughStakeToStartNetwork);
Self::remove_network_for_netuid(min_stake_netuid);
Self::remove_subnet(min_stake_netuid);
}
// if we have reached the max number of subnets, then we can start a new one if the stake is
// greater than the least staked network
Expand Down
19 changes: 9 additions & 10 deletions pallets/subspace/src/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<T: Config> Pallet<T> {
ensure!(Self::if_subnet_netuid_exists(netuid), Error::<T>::SubnetNameAlreadyExists);
ensure!(Self::is_subnet_founder(netuid, &key), Error::<T>::NotFounder);

Self::remove_network_for_netuid(netuid);
Self::remove_subnet(netuid);
// --- 16. Ok and done.
Ok(())
}
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<T: Config> Pallet<T> {
min_stake: MinStake::<T>::get(netuid),
tempo: Tempo::<T>::get(netuid),
name: <Vec<u8>>::new(),
vote_threshold: SubnetVoteThreshold::<T>::get(netuid),
vote_threshold: VoteThresholdSubnet::<T>::get(netuid),
vote_mode:VoteModeSubnet::<T>::get(netuid),
trust_ratio: TrustRatio::<T>::get(netuid),
self_vote: SelfVote::<T>::get(netuid),
Expand Down Expand Up @@ -366,7 +366,7 @@ impl<T: Config> Pallet<T> {

pub fn remove_network_for_name(name: Vec<u8>) -> u16 {
let netuid = Self::get_netuid_for_name(name.clone());
return Self::remove_network_for_netuid(netuid)
return Self::remove_subnet(netuid)
}

pub fn remove_netuid_stake_strorage(netuid: u16) {
Expand All @@ -381,7 +381,7 @@ impl<T: Config> Pallet<T> {
TotalStake::<T>::remove(netuid);
}

pub fn remove_network_for_netuid(netuid: u16) -> u16 {
pub fn remove_subnet(netuid: u16) -> u16 {
// --- 2. Ensure the network to be removed exists.
if !Self::if_subnet_exist(netuid) {
return 0
Expand All @@ -408,7 +408,7 @@ impl<T: Config> Pallet<T> {
RegistrationBlock::<T>::clear_prefix(netuid, u32::max_value(), None);


// --- 2. Erase network parameters.
// --- 2. Erase subnet parameters.
Founder::<T>::remove(netuid);
FounderShare::<T>::remove(netuid);
ImmunityPeriod::<T>::remove(netuid);
Expand All @@ -419,11 +419,10 @@ impl<T: Config> Pallet<T> {
MinStake::<T>::remove(netuid);
SelfVote::<T>::remove(netuid);
SubnetEmission::<T>::remove(netuid);
SubnetVoteThreshold::<T>::remove(netuid);
VoteModeSubnet::<T>::remove(netuid);
Tempo::<T>::remove(netuid);
TrustRatio::<T>::remove(netuid);

VoteThresholdSubnet::<T>::remove(netuid);
VoteModeSubnet::<T>::remove(netuid);

// Adjust the total number of subnets. and remove the subnet from the list of subnets.
N::<T>::remove(netuid);
Expand Down Expand Up @@ -531,7 +530,7 @@ impl<T: Config> Pallet<T> {
// we need to prefix the voting power by the network uid

pub fn set_subnet_vote_threshold(netuid: u16, vote_threshold: u16) {
SubnetVoteThreshold::<T>::insert(netuid, vote_threshold);
VoteThresholdSubnet::<T>::insert(netuid, vote_threshold);
}

pub fn get_vote_mode_subnet(netuid: u16) -> Vec<u8> {
Expand All @@ -543,7 +542,7 @@ impl<T: Config> Pallet<T> {
}

pub fn get_subnet_vote_threshold(netuid: u16) -> u16 {
return SubnetVoteThreshold::<T>::get(netuid)
return VoteThresholdSubnet::<T>::get(netuid)
}

pub fn get_stake_for_key(netuid: u16, key: &T::AccountId) -> u64 {
Expand Down
5 changes: 0 additions & 5 deletions pallets/subspace/tests/test_profit_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ fn test_add_profit_share() {
assert!(sum_profit_share_balances > miner_emission - delta ||
sum_profit_share_balances < miner_emission + delta,
"profit share balances do not add up to the emission");








Expand Down
2 changes: 1 addition & 1 deletion pallets/subspace/tests/test_subnets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn test_add_subnets() {
}

for netuid in 0..num_subnets {
SubspaceModule::remove_network_for_netuid(netuid);
SubspaceModule::remove_subnet(netuid);
expected_subnets = expected_subnets.saturating_sub(1);
assert_eq!(
SubspaceModule::num_subnets(),
Expand Down

0 comments on commit f2d481d

Please sign in to comment.