diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 8d424782b4..ae403b30f8 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1988,7 +1988,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 9b964fcb07..f90cd5d882 100644 --- a/pallets/subtensor/tests/mock.rs +++ b/pallets/subtensor/tests/mock.rs @@ -141,7 +141,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 63ef2b9473..540e004ec2 100644 --- a/pallets/subtensor/tests/registration.rs +++ b/pallets/subtensor/tests/registration.rs @@ -249,9 +249,10 @@ 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; + SubtensorModule::set_target_registrations_per_interval(netuid, target_registrants); + SubtensorModule::set_registrations_this_interval(netuid, max_registrants); let (nonce, work) = SubtensorModule::create_work_for_block_number( netuid, @@ -290,18 +291,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 { @@ -317,21 +318,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); }); } @@ -340,11 +335,15 @@ fn test_burned_registration_rate_limit_exceeded() { new_test_ext(1).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 { @@ -369,6 +368,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(1).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(1).execute_with(|| {