From 2ae0d6eed81c85cb3eb5b68d6661d45598711e33 Mon Sep 17 00:00:00 2001 From: saiintbrisson Date: Thu, 18 Apr 2024 11:51:58 +0000 Subject: [PATCH] fix: remove subnet entirely --- Makefile | 2 +- pallets/subspace/src/migrations.rs | 40 +++++++++++------------------- pallets/subspace/src/module.rs | 1 - 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 7ef3d1461..b4b844c2a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/pallets/subspace/src/migrations.rs b/pallets/subspace/src/migrations.rs index 0c9be7fc5..a8251cdd2 100644 --- a/pallets/subspace/src/migrations.rs +++ b/pallets/subspace/src/migrations.rs @@ -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( ss58_address: &str, ) -> Result { @@ -177,6 +179,16 @@ pub mod v3 { for netuid in N::::iter_keys() { let module_count = Pallet::::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::::remove_subnet(netuid); + continue; + } + Burn::::insert(netuid, old_burn_min_burn); // update the emission that are below the threshold @@ -250,31 +262,8 @@ pub mod v3 { Nominator::::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::::iter() { - if netuid > target_subnets { - let subnet_module_count: u16 = - (Pallet::::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::::get_subnet_n(netuid) - 1) - { - log::warn!("Deregistering module with uid: {module_uid}"); - Pallet::::remove_module(netuid, module_uid); - } - } - } - // Finally update - MaxAllowedSubnets::::put(target_subnets); // Old 256 + MaxAllowedSubnets::::put(SUBNET_CEILING); // Old 256 log::info!("Max allowed subnets migrated"); // Migrate the proposal expiration to 12 days, @@ -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::::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::::insert(proposal.id, proposal); } } diff --git a/pallets/subspace/src/module.rs b/pallets/subspace/src/module.rs index 4a4127026..7e6c1f01b 100644 --- a/pallets/subspace/src/module.rs +++ b/pallets/subspace/src/module.rs @@ -176,7 +176,6 @@ impl Pallet { let mut validator_permit = ValidatorPermits::::get(netuid); let mut validator_trust = ValidatorTrust::::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];