forked from commune-ai/subspace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: move storage DefaultMinValidatorStake to pallet Config (#201) * feat: add validator blacklist (#202) * feat: add validator blacklist * feat: remove check * big wip * adding missing file * feat: fixing linear consensus * feat: refactoring deregistration logic * fix: storage version * feat: add weights to yuma/linear * feat: updating benchmars * feat: updating non-running migration --------- Co-authored-by: João Victor <[email protected]> Co-authored-by: devwckd <[email protected]>
- Loading branch information
1 parent
4f687e8
commit 86cb133
Showing
16 changed files
with
425 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use crate::{Pallet as SubnetEmissionMod, *}; | ||
use frame_benchmarking::{account, benchmarks}; | ||
use frame_system::RawOrigin; | ||
pub use pallet::*; | ||
use pallet_subspace::{Pallet as SubspaceMod, SubnetBurn}; | ||
use sp_std::vec::Vec; | ||
|
||
fn register_mock<T: Config>( | ||
key: T::AccountId, | ||
module_key: T::AccountId, | ||
name: Vec<u8>, | ||
) -> Result<(), &'static str> { | ||
let address = "test".as_bytes().to_vec(); | ||
let network = "testnet".as_bytes().to_vec(); | ||
|
||
let enough_stake = 10000000000000u64; | ||
SubspaceMod::<T>::add_balance_to_account( | ||
&key, | ||
SubspaceMod::<T>::u64_to_balance(SubnetBurn::<T>::get() + enough_stake).unwrap(), | ||
); | ||
let metadata = Some("metadata".as_bytes().to_vec()); | ||
SubspaceMod::<T>::register( | ||
RawOrigin::Signed(key.clone()).into(), | ||
network, | ||
name, | ||
address, | ||
module_key.clone(), | ||
metadata, | ||
)?; | ||
SubspaceMod::<T>::increase_stake(&key, &module_key, enough_stake); | ||
Ok(()) | ||
} | ||
|
||
benchmarks! { | ||
process_subnets { | ||
let caller: T::AccountId = account("Alice", 0, 1); | ||
// Add Alice's funds to submit the proposal | ||
SubspaceMod::<T>::add_balance_to_account( | ||
&caller, | ||
SubspaceMod::<T>::u64_to_balance(1_000_000_000_000_000).unwrap() | ||
); | ||
|
||
register_mock::<T>(caller.clone(), caller.clone(), | ||
"test".as_bytes().to_vec())?; | ||
|
||
reigster_mock() | ||
}: process_subnets() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use super::*; | ||
use frame_support::{storage::with_storage_layer, traits::Get, weights::Weight}; | ||
use pallet_subnet_emission_api::SubnetConsensus; | ||
use pallet_subspace::{MaxAllowedUids, Pallet as PalletS, N}; | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub(crate) fn deregister_excess_modules(mut remaining: Weight) -> Weight { | ||
let netuid = Self::get_consensus_netuid(SubnetConsensus::Linear).unwrap_or(2); | ||
const MAX_MODULES_PER_ITERATION: usize = 5; | ||
const MAX_UIDS: u16 = 524; | ||
|
||
let db_weight = T::DbWeight::get(); | ||
let mut weight = db_weight.reads(2); | ||
let find_id_weight = db_weight.reads(1); | ||
let deregister_weight = Weight::from_parts(300_495_000, 21587) | ||
.saturating_add(T::DbWeight::get().reads(34_u64)) | ||
.saturating_add(T::DbWeight::get().writes(48_u64)); | ||
|
||
if !remaining | ||
.all_gte(weight.saturating_add(find_id_weight).saturating_add(deregister_weight)) | ||
{ | ||
log::info!("not enough weight remaining: {remaining:?}"); | ||
return Weight::zero(); | ||
} | ||
|
||
remaining = remaining.saturating_sub(weight); | ||
|
||
let mut module_count = N::<T>::get(netuid); | ||
while module_count > MAX_UIDS { | ||
for _ in 0..MAX_MODULES_PER_ITERATION { | ||
if !remaining.all_gte(find_id_weight.saturating_add(deregister_weight)) { | ||
log::info!("not enough weight remaining: {remaining:?}"); | ||
return weight; | ||
} | ||
|
||
if let Some(uid) = PalletS::<T>::get_lowest_uid(netuid, false) { | ||
log::info!("deregistering module with uid {uid}"); | ||
|
||
weight = weight.saturating_add(find_id_weight); | ||
remaining = remaining.saturating_sub(find_id_weight); | ||
|
||
let result = | ||
with_storage_layer(|| PalletS::<T>::remove_module(netuid, uid, true)); | ||
if result.is_ok() { | ||
weight = weight.saturating_add(deregister_weight); | ||
remaining = remaining.saturating_sub(deregister_weight); | ||
module_count = module_count.saturating_sub(1); | ||
} else { | ||
log::error!( | ||
"failed to deregister module {uid} due to: {:?}", | ||
result.unwrap_err() | ||
); | ||
} | ||
} else { | ||
// No more modules to deregister | ||
break; | ||
} | ||
|
||
if module_count <= MAX_UIDS { | ||
break; | ||
} | ||
} | ||
|
||
if module_count <= MAX_UIDS { | ||
break; | ||
} | ||
} | ||
|
||
MaxAllowedUids::<T>::set(netuid, MAX_UIDS); | ||
weight | ||
} | ||
} |
Oops, something went wrong.