From 2971ae05e4aa4a4953a2217f9a5174a2605c6b50 Mon Sep 17 00:00:00 2001 From: shibshib Date: Mon, 29 Apr 2024 23:35:30 +0000 Subject: [PATCH 1/4] Fix hotregs hotpatch rebased off of main --- pallets/subtensor/src/lib.rs | 2 +- pallets/subtensor/tests/mock.rs | 2 +- pallets/subtensor/tests/registration.rs | 95 ++++++++++++++++++------- runtime/src/lib.rs | 2 +- 4 files changed, 74 insertions(+), 27 deletions(-) diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index e9b55237ff..3204c7fbc6 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1875,7 +1875,7 @@ where Pallet::::get_registrations_this_interval(*netuid); let max_registrations_per_interval = Pallet::::get_target_registrations_per_interval(*netuid); - if registrations_this_interval >= max_registrations_per_interval { + if registrations_this_interval >= (max_registrations_per_interval * 3) { // If the registration limit for the interval is exceeded, reject the transaction return InvalidTransaction::ExhaustsResources.into(); } diff --git a/pallets/subtensor/tests/mock.rs b/pallets/subtensor/tests/mock.rs index 2a4424d408..524b3be07e 100644 --- a/pallets/subtensor/tests/mock.rs +++ b/pallets/subtensor/tests/mock.rs @@ -145,7 +145,7 @@ parameter_types! { pub const InitialAdjustmentInterval: u16 = 100; pub const InitialAdjustmentAlpha: u64 = 0; // no weight to previous value. pub const InitialMaxRegistrationsPerBlock: u16 = 3; - pub const InitialTargetRegistrationsPerInterval: u16 = 2; + pub const InitialTargetRegistrationsPerInterval: u16 = 3; pub const InitialPruningScore : u16 = u16::MAX; pub const InitialRegistrationRequirement: u16 = u16::MAX; // Top 100% pub const InitialMinDifficulty: u64 = 1; diff --git a/pallets/subtensor/tests/registration.rs b/pallets/subtensor/tests/registration.rs index 89bea43552..27e16621be 100644 --- a/pallets/subtensor/tests/registration.rs +++ b/pallets/subtensor/tests/registration.rs @@ -256,18 +256,18 @@ fn test_burned_registration_under_limit() { let netuid: u16 = 1; let hotkey_account_id: U256 = U256::from(1); let coldkey_account_id = U256::from(667); - let who: ::AccountId = hotkey_account_id; - let block_number: u64 = 0; + let who: ::AccountId = coldkey_account_id; + let burn_cost = 1000; + // Set the burn cost + SubtensorModule::set_burn(netuid, burn_cost); - let (nonce, work) = SubtensorModule::create_work_for_block_number( - netuid, - block_number, - 129123813, - &hotkey_account_id, - ); + add_network(netuid, 13, 0); // Add the network + // Give it some TAO to the coldkey balance; more than the burn cost + SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, burn_cost + 10_000); - let max_registrants = 2; - SubtensorModule::set_target_registrations_per_interval(netuid, max_registrants); + let target_registrants = 2; + let max_registrants = target_registrants * 3; // Maximum is 3 times the target + SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants); let call_burned_register: pallet_subtensor::Call = pallet_subtensor::Call::burned_register { @@ -283,21 +283,15 @@ fn test_burned_registration_under_limit() { extension.validate(&who, &call_burned_register.into(), &info, 10); assert_ok!(burned_register_result); - add_network(netuid, 13, 0); //actually call register - assert_ok!(SubtensorModule::register( - <::RuntimeOrigin>::signed(hotkey_account_id), + assert_ok!(SubtensorModule::burned_register( + <::RuntimeOrigin>::signed(coldkey_account_id), netuid, - block_number, - nonce, - work, hotkey_account_id, - coldkey_account_id )); let current_registrants = SubtensorModule::get_registrations_this_interval(netuid); - let target_registrants = SubtensorModule::get_target_registrations_per_interval(netuid); - assert!(current_registrants <= target_registrants); + assert!(current_registrants <= max_registrants); }); } @@ -306,11 +300,15 @@ fn test_burned_registration_rate_limit_exceeded() { new_test_ext().execute_with(|| { let netuid: u16 = 1; let hotkey_account_id: U256 = U256::from(1); - let who: ::AccountId = hotkey_account_id; - let max_registrants = 1; + let coldkey_account_id = U256::from(667); + let who: ::AccountId = coldkey_account_id; - SubtensorModule::set_target_registrations_per_interval(netuid, max_registrants); - SubtensorModule::set_registrations_this_interval(netuid, 1); + let target_registrants = 1; + let max_registrants = target_registrants * 3; // Maximum is 3 times the target + + SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants); + // Set the current registrations to the maximum; should not be able to register more + SubtensorModule::set_registrations_this_interval(netuid, max_registrants); let call_burned_register: pallet_subtensor::Call = pallet_subtensor::Call::burned_register { @@ -335,6 +333,55 @@ fn test_burned_registration_rate_limit_exceeded() { }); } +#[test] +fn test_burned_registration_rate_allows_burn_adjustment() { + // We need to be able to register more than the *target* registrations per interval + new_test_ext().execute_with(|| { + let netuid: u16 = 1; + let hotkey_account_id: U256 = U256::from(1); + let coldkey_account_id = U256::from(667); + let who: ::AccountId = coldkey_account_id; + + let burn_cost = 1000; + // Set the burn cost + SubtensorModule::set_burn(netuid, burn_cost); + + add_network(netuid, 13, 0); // Add the network + // Give it some TAO to the coldkey balance; more than the burn cost + SubtensorModule::add_balance_to_coldkey_account(&coldkey_account_id, burn_cost + 10_000); + + let target_registrants = 1; // Target is 1, but we can register more than that, up to some maximum. + SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants); + // Set the current registrations to above the target; we should be able to register at least 1 more + SubtensorModule::set_registrations_this_interval(netuid, target_registrants); + + // Register one more, so the current registrations are above the target + let call_burned_register: pallet_subtensor::Call = + pallet_subtensor::Call::burned_register { + netuid, + hotkey: hotkey_account_id, + }; + + let info: DispatchInfo = + DispatchInfoOf::<::RuntimeCall>::default(); + let extension = SubtensorSignedExtension::::new(); + //does not actually call register + let burned_register_result = + extension.validate(&who, &call_burned_register.into(), &info, 10); + assert_ok!(burned_register_result); + + //actually call register + assert_ok!(SubtensorModule::burned_register( + <::RuntimeOrigin>::signed(coldkey_account_id), + netuid, + hotkey_account_id + )); + + let current_registrants = SubtensorModule::get_registrations_this_interval(netuid); + assert!(current_registrants > target_registrants); // Should be able to register more than the target + }); +} + #[test] fn test_burned_registration_ok() { new_test_ext().execute_with(|| { @@ -1897,4 +1944,4 @@ fn test_hotkey_swap_registered_key() { Error::::AlreadyRegistered ); }); -} +} \ No newline at end of file diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 51baecea8a..5706376fc1 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -121,7 +121,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: 146, + spec_version: 147, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 981e6afdc2d23156bf67397de81e4fe471ed7981 Mon Sep 17 00:00:00 2001 From: shibshib Date: Mon, 29 Apr 2024 23:38:38 +0000 Subject: [PATCH 2/4] Fixed cargo fmt issue --- pallets/subtensor/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 3204c7fbc6..79d37a3772 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1875,7 +1875,7 @@ where Pallet::::get_registrations_this_interval(*netuid); let max_registrations_per_interval = Pallet::::get_target_registrations_per_interval(*netuid); - if registrations_this_interval >= (max_registrations_per_interval * 3) { + if registrations_this_interval >= (max_registrations_per_interval * 3) { // If the registration limit for the interval is exceeded, reject the transaction return InvalidTransaction::ExhaustsResources.into(); } From 3e97cb28869cb66ffc514a53bb3819ead4a4e0a0 Mon Sep 17 00:00:00 2001 From: shibshib Date: Mon, 29 Apr 2024 23:41:18 +0000 Subject: [PATCH 3/4] Fixed test_registration_rate_limit_exceeded test --- pallets/subtensor/tests/registration.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/tests/registration.rs b/pallets/subtensor/tests/registration.rs index 27e16621be..68d0663ba3 100644 --- a/pallets/subtensor/tests/registration.rs +++ b/pallets/subtensor/tests/registration.rs @@ -215,9 +215,12 @@ fn test_registration_rate_limit_exceeded() { let coldkey_account_id = U256::from(667); let who: ::AccountId = hotkey_account_id; - let max_registrants = 1; - SubtensorModule::set_target_registrations_per_interval(netuid, max_registrants); - SubtensorModule::set_registrations_this_interval(netuid, 1); + let target_registrants = 1; + let max_registrants = target_registrants * 3; // Maximum is 3 times the target + + SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants); + // Set the current registrations to the maximum; should not be able to register more + SubtensorModule::set_registrations_this_interval(netuid, max_registrants); let (nonce, work) = SubtensorModule::create_work_for_block_number( netuid, From f4869d99c5656e1aeab3fc8fff7bd4a0a0ffd2ba Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 29 Apr 2024 19:44:33 -0400 Subject: [PATCH 4/4] fix cargo fmt --- pallets/subtensor/tests/registration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/tests/registration.rs b/pallets/subtensor/tests/registration.rs index 68d0663ba3..147497c587 100644 --- a/pallets/subtensor/tests/registration.rs +++ b/pallets/subtensor/tests/registration.rs @@ -1947,4 +1947,4 @@ fn test_hotkey_swap_registered_key() { Error::::AlreadyRegistered ); }); -} \ No newline at end of file +}