Skip to content

Commit

Permalink
fix: remove subnet entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
saiintbrisson committed Apr 18, 2024
1 parent 1ed2fcc commit 2ae0d6e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ RUST_LOG ?= info,pallet_subspace::migrations=debug

try-runtime-upgrade:
cargo build --release --features try-runtime
RUST_LOG="${RUST_LOG}"; try-runtime --runtime target/release/wbuild/node-subspace-runtime/node_subspace_runtime.compact.compressed.wasm on-runtime-upgrade live --uri wss://commune-api-node-0.communeai.net:443
RUST_BACKTRACE=1; RUST_LOG="${RUST_LOG}"; try-runtime --runtime target/release/wbuild/node-subspace-runtime/node_subspace_runtime.compact.compressed.wasm on-runtime-upgrade live --uri wss://commune-api-node-0.communeai.net:443
40 changes: 14 additions & 26 deletions pallets/subspace/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ pub mod v3 {
use sp_core::crypto::Ss58Codec;
use sp_runtime::AccountId32;

const SUBNET_CEILING: u16 = 42;

fn ss58_to_account_id<T: Config>(
ss58_address: &str,
) -> Result<T::AccountId, sp_core::crypto::PublicError> {
Expand Down Expand Up @@ -177,6 +179,16 @@ pub mod v3 {
for netuid in N::<T>::iter_keys() {
let module_count = Pallet::<T>::get_subnet_n(netuid) as usize;

// With the current subnet emission threshold (5%), only 20 subnets
// can actually activelly produce emission, the old value 256
// is in current model a security vounrability for cheap subnet DDOS.
// Make sure there is no subnet over target, if so deregister it.
if netuid > SUBNET_CEILING {
log::warn!("subnet {netuid} is over the limit ({SUBNET_CEILING}), deregistering {module_count} modules");
Pallet::<T>::remove_subnet(netuid);
continue;
}

Burn::<T>::insert(netuid, old_burn_min_burn);

// update the emission that are below the threshold
Expand Down Expand Up @@ -250,31 +262,8 @@ pub mod v3 {
Nominator::<T>::put(dao_bot_account_id); // Old empty
log::info!("Nominator migrated");

// With the current subnet emission threshold (5%), only 20 subnets
// can actually activelly produce emission, the old value 256
// is in current model a security vounrability for cheap subnet DDOS.
let target_subnets = 42;
// Make sure there is no subnet over target, if so deregister it.
// Iterate over all netuids and deregister subnets above the target
for (netuid, _) in N::<T>::iter() {
if netuid > target_subnets {
let subnet_module_count: u16 =
(Pallet::<T>::get_subnet_n(netuid)).saturating_sub(1);
log::warn!("Deregistering subnet with netuid: {}", netuid);
log::info!("Subnet module count: {subnet_module_count}");
// deregister all modules on the subnet, which will also
// remove the subnet itself
for module_uid in
0..=subnet_module_count.min(Pallet::<T>::get_subnet_n(netuid) - 1)
{
log::warn!("Deregistering module with uid: {module_uid}");
Pallet::<T>::remove_module(netuid, module_uid);
}
}
}

// Finally update
MaxAllowedSubnets::<T>::put(target_subnets); // Old 256
MaxAllowedSubnets::<T>::put(SUBNET_CEILING); // Old 256
log::info!("Max allowed subnets migrated");

// Migrate the proposal expiration to 12 days,
Expand All @@ -286,10 +275,9 @@ pub mod v3 {
// This logic is now automatically running onchain,
// but to avoid confustion on expired proposal 0, we migrate.
for mut proposal in Proposals::<T>::iter_values() {
if !matches!(proposal.status, ProposalStatus::Expired) {
if matches!(proposal.status, ProposalStatus::Expired) {
proposal.votes_for = Default::default();
proposal.votes_against = Default::default();

Proposals::<T>::insert(proposal.id, proposal);
}
}
Expand Down
1 change: 0 additions & 1 deletion pallets/subspace/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ impl<T: Config> Pallet<T> {
let mut validator_permit = ValidatorPermits::<T>::get(netuid);
let mut validator_trust = ValidatorTrust::<T>::get(netuid);

log::info!("active len: {:?}", active.len());
// swap consensus vectors
active[uid as usize] = active[replace_uid as usize];
consensus[uid as usize] = consensus[replace_uid as usize];
Expand Down

0 comments on commit 2ae0d6e

Please sign in to comment.