diff --git a/Cargo.lock b/Cargo.lock index 2d8f4590f..11d93ec37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4346,7 +4346,7 @@ dependencies = [ [[package]] name = "node-subspace" -version = "1.7.4" +version = "1.7.5" dependencies = [ "clap", "fp-evm", @@ -4397,7 +4397,7 @@ dependencies = [ [[package]] name = "node-subspace-runtime" -version = "1.7.4" +version = "1.7.5" dependencies = [ "fp-account", "fp-evm", @@ -4870,7 +4870,7 @@ dependencies = [ [[package]] name = "pallet-subspace" -version = "1.7.4" +version = "1.7.5" dependencies = [ "bty", "frame-benchmarking", diff --git a/node/Cargo.toml b/node/Cargo.toml index 7f6ae24e8..60707db89 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "node-subspace" -version = "1.7.4" +version = "1.7.5" description = "A fresh FRAME-based Substrate node, ready for hacking." authors = ["Substrate DevHub "] homepage = "https://substrate.io/" diff --git a/pallets/subspace/Cargo.toml b/pallets/subspace/Cargo.toml index b0609ced0..7be57b78c 100644 --- a/pallets/subspace/Cargo.toml +++ b/pallets/subspace/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-subspace" -version = "1.7.4" +version = "1.7.5" description = "FRAME pallet for runtime logic of Subspace Blockchain." authors = ["Commune Nucleus Team"] homepage = "https://commune.com" diff --git a/pallets/subspace/src/lib.rs b/pallets/subspace/src/lib.rs index 6d1bf8e78..0c38f5c20 100644 --- a/pallets/subspace/src/lib.rs +++ b/pallets/subspace/src/lib.rs @@ -20,7 +20,7 @@ use frame_support::{ use codec::{Decode, Encode}; use frame_support::sp_runtime::transaction_validity::ValidTransaction; use sp_runtime::{ - traits::{ConstU16, DispatchInfoOf, Dispatchable, PostDispatchInfoOf, SignedExtension}, + traits::{DispatchInfoOf, Dispatchable, PostDispatchInfoOf, SignedExtension}, transaction_validity::{TransactionValidity, TransactionValidityError}, }; use sp_std::marker::PhantomData; @@ -69,7 +69,7 @@ pub mod pallet { use sp_arithmetic::per_things::Percent; pub use sp_std::{vec, vec::Vec}; - const STORAGE_VERSION: StorageVersion = StorageVersion::new(8); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(9); #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] @@ -464,9 +464,14 @@ pub mod pallet { #[pallet::storage] // --- MAP ( netuid ) --> trarget_registrations_interval pub type TargetRegistrationsInterval = StorageMap<_, Identity, u16, u16, ValueQuery, DefaultTargetRegistrationsInterval>; + + #[pallet::type_value] + pub fn DefaultMaxRegistrationsPerInterval() -> u16 { + 42 + } #[pallet::storage] // --- MAP ( netuid ) --> trarget_registrations_interval pub type MaxRegistrationsPerInterval = - StorageMap<_, Identity, u16, u16, ValueQuery, ConstU16<42>>; + StorageMap<_, Identity, u16, u16, ValueQuery, DefaultMaxRegistrationsPerInterval>; #[pallet::type_value] pub fn DefaultMaxStake() -> u64 { diff --git a/pallets/subspace/src/migrations.rs b/pallets/subspace/src/migrations.rs index 5d00dbbee..98705d951 100644 --- a/pallets/subspace/src/migrations.rs +++ b/pallets/subspace/src/migrations.rs @@ -24,22 +24,30 @@ pub fn ss58_to_account_id( Ok(T::AccountId::decode(&mut &account_id_vec[..]).unwrap()) } -pub mod v8 { +pub mod v9 { use super::*; - pub struct MigrateToV8(sp_std::marker::PhantomData); + pub struct MigrateToV9(sp_std::marker::PhantomData); - impl OnRuntimeUpgrade for MigrateToV8 { + impl OnRuntimeUpgrade for MigrateToV9 { fn on_runtime_upgrade() -> Weight { let on_chain_version = StorageVersion::get::>(); - if on_chain_version != 7 { - log::info!("Storage v8 already updated"); + if on_chain_version != 8 { + log::info!("Storage v9 already updated"); return Weight::zero(); } + // Clear the old registration storages + // ==================================== + + let _ = TargetRegistrationsInterval::::clear(u32::MAX, None); + let _ = TargetRegistrationsPerInterval::::clear(u32::MAX, None); + let _ = MaxRegistrationsPerInterval::::clear(u32::MAX, None); + let new_registration_interval = 142; let new_target_registrations_per_interval = 4; + let max_registration_per_interval = 42; for netuid in N::::iter_keys() { TargetRegistrationsInterval::::insert(netuid, new_registration_interval); @@ -47,14 +55,27 @@ pub mod v8 { netuid, new_target_registrations_per_interval, ); + MaxRegistrationsPerInterval::::insert(netuid, max_registration_per_interval); } log::info!("Migrated Registration Intervals to V8"); - MaxRegistrationsPerBlock::::put(3); - log::info!("Migrated Registration Intervals to V8"); + log::info!( + "Target registration per interval are {:?}", + TargetRegistrationsPerInterval::::iter().collect::>() + ); - StorageVersion::new(8).put::>(); - log::info!("Migrated Registration Intervals to V8"); + log::info!( + "Target registration interval are {:?}", + TargetRegistrationsInterval::::iter().collect::>() + ); + + log::info!( + "Max registration per interval are {:?}", + MaxRegistrationsPerInterval::::iter().collect::>() + ); + + StorageVersion::new(9).put::>(); + log::info!("Migrated Registration Intervals to V9"); T::DbWeight::get().writes(1) } diff --git a/pallets/subspace/src/subnet.rs b/pallets/subspace/src/subnet.rs index 4ab728b0a..617f0bf27 100644 --- a/pallets/subspace/src/subnet.rs +++ b/pallets/subspace/src/subnet.rs @@ -29,6 +29,7 @@ impl SubnetChangeset { pub fn apply(self, netuid: u16) -> Result<(), sp_runtime::DispatchError> { Self::validate_params(Some(netuid), &self.params)?; + // TODO: implement check that all params are inserted SubnetNames::::insert(netuid, &self.params.name); Founder::::insert(netuid, &self.params.founder); FounderShare::::insert(netuid, self.params.founder_share); @@ -43,6 +44,16 @@ impl SubnetChangeset { TrustRatio::::insert(netuid, self.params.trust_ratio); IncentiveRatio::::insert(netuid, self.params.incentive_ratio); VoteModeSubnet::::insert(netuid, self.params.vote_mode); + BondsMovingAverage::::insert(netuid, self.params.bonds_ma); + TargetRegistrationsInterval::::insert(netuid, self.params.target_registrations_interval); + TargetRegistrationsPerInterval::::insert( + netuid, + self.params.target_registrations_per_interval, + ); + MaxRegistrationsPerInterval::::insert( + netuid, + self.params.max_registrations_per_interval, + ); if self.params.maximum_set_weight_calls_per_epoch == 0 { MaximumSetWeightCallsPerEpoch::::remove(netuid); diff --git a/pallets/subspace/tests/mock.rs b/pallets/subspace/tests/mock.rs index c85fd989f..1e1349d05 100644 --- a/pallets/subspace/tests/mock.rs +++ b/pallets/subspace/tests/mock.rs @@ -5,6 +5,7 @@ use frame_support::{ traits::{Everything, Hooks}, }; use frame_system as system; +use pallet_subspace::MaxRegistrationsPerInterval; use sp_core::{H256, U256}; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, @@ -195,7 +196,9 @@ pub fn register_module(netuid: u16, key: U256, stake: u64) -> DispatchResult { add_balance(key, stake + 1); - SubspaceModule::register(origin, network, name, address, stake, key, None) + let result = SubspaceModule::register(origin, network, name, address, stake, key, None); + MaxRegistrationsPerInterval::::set(netuid, 1000); + result } #[allow(dead_code)] diff --git a/pallets/subspace/tests/registration.rs b/pallets/subspace/tests/registration.rs index ee582f9ce..fee8c8cc8 100644 --- a/pallets/subspace/tests/registration.rs +++ b/pallets/subspace/tests/registration.rs @@ -9,7 +9,7 @@ use sp_core::U256; use log::info; use pallet_subspace::{ voting::ApplicationStatus, CuratorApplications, Emission, Error, MaxAllowedModules, - MaxAllowedUids, MaxRegistrationsPerInterval, MinStake, RemovedSubnets, Stake, SubnetNames, + MaxAllowedUids, MinStake, RemovedSubnets, Stake, SubnetNames, TotalSubnets, N, }; use sp_runtime::{DispatchResult, Percent}; @@ -65,7 +65,6 @@ fn test_max_registration() { let max_registrations_per_block = 100; // make sure that the results won´t get affected by burn SubspaceModule::set_min_burn(0); - MaxRegistrationsPerInterval::::set(netuid, 1000); assert_eq!(SubspaceModule::get_registrations_this_block(), 0); SubspaceModule::set_max_registrations_per_block(1000); @@ -144,7 +143,6 @@ fn test_many_registrations() { SubspaceModule::set_min_burn(0); SubspaceModule::set_max_registrations_per_block(n); - MaxRegistrationsPerInterval::::set(netuid, 1000); for i in 0..n { register_module(netuid, U256::from(i), stake).unwrap_or_else(|_| { panic!("Failed to register module with key: {i:?} and stake: {stake:?}",) diff --git a/pallets/subspace/tests/step_linear.rs b/pallets/subspace/tests/step_linear.rs index d16dc6736..2024a5cdf 100644 --- a/pallets/subspace/tests/step_linear.rs +++ b/pallets/subspace/tests/step_linear.rs @@ -4,7 +4,7 @@ use frame_support::assert_ok; use log::info; use mock::*; use pallet_subspace::{ - DaoTreasuryDistribution, GlobalDaoTreasury, MaxAllowedWeights, MaxRegistrationsPerInterval, + DaoTreasuryDistribution, GlobalDaoTreasury, MaxAllowedWeights, MinAllowedWeights, MinBurn, SubnetStakeThreshold, Tempo, }; use sp_core::U256; @@ -256,7 +256,6 @@ fn test_pruning() { let stake_per_module: u64 = 10_000; let tempo: u16 = 100; - MaxRegistrationsPerInterval::::insert(netuid, 1000); // make sure that the results won´t get affected by burn SubspaceModule::set_min_burn(0); SubspaceModule::set_max_registrations_per_block(1000); @@ -328,7 +327,6 @@ fn test_lowest_priority_mechanism() { // make sure that the results won´t get affected by burn SubspaceModule::set_min_burn(0); SubspaceModule::set_max_registrations_per_block(1000); - MaxRegistrationsPerInterval::::insert(netuid, 1000); // SETUP NETWORK register_n_modules(netuid, n, stake_per_module); @@ -924,7 +922,6 @@ fn test_dynamic_burn() { // Create the subnet let subnet_key = U256::from(2050); assert_ok!(register_module(netuid, subnet_key, initial_stake)); - MaxRegistrationsPerInterval::::set(netuid, 1000); // Using the default GlobalParameters: // - registration target interval = 2 * tempo (200 blocks) // - registration target for interval = registration_target_interval / 2 diff --git a/pallets/subspace/tests/subnet.rs b/pallets/subspace/tests/subnet.rs index f13cf1f14..a9ea02eb3 100644 --- a/pallets/subspace/tests/subnet.rs +++ b/pallets/subspace/tests/subnet.rs @@ -4,7 +4,7 @@ use frame_support::{assert_err, assert_ok}; use log::info; use mock::*; use pallet_subspace::{ - Dividends, Error, FounderShare, MaxRegistrationsPerInterval, MaximumSetWeightCallsPerEpoch, + Dividends, Error, FounderShare, MaximumSetWeightCallsPerEpoch, SubnetNames, Tempo, N, }; use sp_core::U256; @@ -135,7 +135,6 @@ fn test_set_max_allowed_uids_growing() { SubspaceModule::set_min_burn(0); assert_ok!(register_module(netuid, U256::from(0), stake)); - MaxRegistrationsPerInterval::::insert(netuid, 9999); SubspaceModule::set_max_registrations_per_block(max_uids + extra_uids * rounds); for i in 1..max_uids { assert_ok!(register_module(netuid, U256::from(i), stake)); @@ -185,7 +184,6 @@ fn test_set_max_allowed_uids_shrinking() { let max_uids: u16 = 100; let extra_uids: u16 = 20; - MaxRegistrationsPerInterval::::insert(netuid, 9999); // make sure that the results won´t get affected by burn SubspaceModule::set_min_burn(0); @@ -284,8 +282,6 @@ fn test_set_max_allowed_modules() { SubspaceModule::set_max_registrations_per_block(1000); SubspaceModule::set_max_allowed_modules(max_allowed_modules); // set max_total modules - MaxRegistrationsPerInterval::::insert(netuid, 9999); - for i in 1..(2 * max_allowed_modules) { assert_ok!(register_module(netuid, U256::from(i), stake)); let n = SubspaceModule::get_subnet_n(netuid); @@ -586,7 +582,6 @@ fn test_parasite_subnet_registrations() { let expected_module_amount: u16 = 5; SubspaceModule::set_max_allowed_modules(expected_module_amount); SubspaceModule::set_max_registrations_per_block(1000); - MaxRegistrationsPerInterval::::insert(0, 9999); let main_subnet_netuid: u16 = 0; let main_subnet_stake = to_nano(500_000); diff --git a/pallets/subspace/tests/weights.rs b/pallets/subspace/tests/weights.rs index 1fb2fbf37..d6835f91e 100644 --- a/pallets/subspace/tests/weights.rs +++ b/pallets/subspace/tests/weights.rs @@ -1,7 +1,7 @@ mod mock; use frame_support::{assert_err, assert_ok}; -use pallet_subspace::{Error, FloorFounderShare, MaxRegistrationsPerInterval}; +use pallet_subspace::{Error, FloorFounderShare}; use sp_core::U256; use sp_runtime::DispatchError; @@ -109,7 +109,6 @@ fn test_set_weight_not_enough_values() { new_test_ext().execute_with(|| { let netuid: u16 = 0; let n = 100; - MaxRegistrationsPerInterval::::insert(netuid, 9999); SubspaceModule::set_max_registrations_per_block(n); let account_id = U256::from(0); // make sure that the results won´t get affected by burn @@ -164,7 +163,6 @@ fn test_set_max_allowed_uids() { new_test_ext().execute_with(|| { let netuid: u16 = 0; let n = 100; - MaxRegistrationsPerInterval::::insert(netuid, 9999); SubspaceModule::set_max_registrations_per_block(n); let account_id = U256::from(0); // make sure that the results won´t get affected by burn @@ -270,7 +268,6 @@ fn test_weight_age() { const ACTIVE_VOTER: u16 = 1; SubspaceModule::set_max_registrations_per_block(1000); FloorFounderShare::::put(0); - MaxRegistrationsPerInterval::::insert(NETUID, 1000); // Register modules (0..MODULE_COUNT).for_each(|i| { assert_ok!(register_module(NETUID, U256::from(i), to_nano(10))); diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 25ff0e0e3..643337203 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "node-subspace-runtime" -version = "1.7.4" +version = "1.7.5" description = "A Substrate node for commune-ai" authors = [ "Sal Vivona ", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 2b5b2346d..2293e2393 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -123,7 +123,7 @@ pub mod opaque { } } -pub type Migrations = (pallet_subspace::migrations::v8::MigrateToV8,); +pub type Migrations = (pallet_subspace::migrations::v9::MigrateToV9,); // To learn more about runtime versioning, see: // https://docs.substrate.io/main-docs/build/upgrade#runtime-versioning #[sp_version::runtime_version] @@ -136,7 +136,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 114, + spec_version: 115, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,