-
Notifications
You must be signed in to change notification settings - Fork 272
Start call delay hyperparameter #2315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devnet-ready
Are you sure you want to change the base?
Changes from all commits
3954bf0
b5ce250
93c2e4e
55b0e90
745db21
f81c5db
7473584
c57c7c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,5 +124,8 @@ fn localnet_genesis( | |
| "evmChainId": { | ||
| "chainId": 42, | ||
| }, | ||
| "subtensorModule": { | ||
| "startCallDelay": 10, | ||
| }, | ||
|
Comment on lines
+127
to
+129
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It needs to be added to the |
||
| }) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2240,6 +2240,21 @@ pub mod pallet { | |
| pallet_subtensor::Pallet::<T>::set_min_non_immune_uids(netuid, min); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Sets the delay before a subnet can call start | ||
| #[pallet::call_index(85)] | ||
| #[pallet::weight(( | ||
| Weight::from_parts(14_000_000, 0) | ||
| .saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1)), | ||
| DispatchClass::Operational, | ||
| Pays::Yes | ||
| ))] | ||
| pub fn sudo_set_start_call_delay(origin: OriginFor<T>, delay: u64) -> DispatchResult { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it intentional to make it a global hyperparam (i.e. not per-subnet)? |
||
| ensure_root(origin)?; | ||
| pallet_subtensor::Pallet::<T>::set_start_call_delay(delay); | ||
| log::debug!("StartCallDelay( delay: {delay:?} ) "); | ||
| Ok(()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2887,3 +2887,101 @@ fn test_sudo_set_min_non_immune_uids() { | |||||||||||||||||||||||||||||||||||||||
| assert_eq!(SubtensorModule::get_min_non_immune_uids(netuid), to_be_set); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||
| fn test_sudo_set_start_call_delay_permissions_and_zero_delay() { | ||||||||||||||||||||||||||||||||||||||||
| new_test_ext().execute_with(|| { | ||||||||||||||||||||||||||||||||||||||||
| let netuid = NetUid::from(1); | ||||||||||||||||||||||||||||||||||||||||
| let tempo: u16 = 13; | ||||||||||||||||||||||||||||||||||||||||
| let coldkey_account_id = U256::from(0); | ||||||||||||||||||||||||||||||||||||||||
| let non_root_account = U256::from(1); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Get initial delay value (should be non-zero) | ||||||||||||||||||||||||||||||||||||||||
| let initial_delay = pallet_subtensor::StartCallDelay::<Test>::get(); | ||||||||||||||||||||||||||||||||||||||||
| assert!( | ||||||||||||||||||||||||||||||||||||||||
| initial_delay > 0, | ||||||||||||||||||||||||||||||||||||||||
| "Initial delay should be greater than zero" | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Test 1: Non-root account should fail to set delay | ||||||||||||||||||||||||||||||||||||||||
| assert_err!( | ||||||||||||||||||||||||||||||||||||||||
| AdminUtils::sudo_set_start_call_delay( | ||||||||||||||||||||||||||||||||||||||||
| <<Test as Config>::RuntimeOrigin>::signed(non_root_account), | ||||||||||||||||||||||||||||||||||||||||
| 0 | ||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||
| DispatchError::BadOrigin | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::StartCallDelay::<Test>::get(), | ||||||||||||||||||||||||||||||||||||||||
| initial_delay, | ||||||||||||||||||||||||||||||||||||||||
| "Delay should not have changed" | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2907
to
+2918
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Test 2: Create a subnet | ||||||||||||||||||||||||||||||||||||||||
| add_network(netuid, tempo); | ||||||||||||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::FirstEmissionBlockNumber::<Test>::get(netuid), | ||||||||||||||||||||||||||||||||||||||||
| None, | ||||||||||||||||||||||||||||||||||||||||
| "Emission block should not be set yet" | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::SubnetOwner::<Test>::get(netuid), | ||||||||||||||||||||||||||||||||||||||||
| coldkey_account_id, | ||||||||||||||||||||||||||||||||||||||||
| "Default owner should be account 0" | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Test 3: Try to start the subnet immediately - should FAIL (delay not passed) | ||||||||||||||||||||||||||||||||||||||||
| assert_err!( | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::Pallet::<Test>::start_call( | ||||||||||||||||||||||||||||||||||||||||
| <<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id), | ||||||||||||||||||||||||||||||||||||||||
| netuid | ||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::Error::<Test>::NeedWaitingMoreBlocksToStarCall | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Verify emission has not been set | ||||||||||||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::FirstEmissionBlockNumber::<Test>::get(netuid), | ||||||||||||||||||||||||||||||||||||||||
| None, | ||||||||||||||||||||||||||||||||||||||||
| "Emission should not be set yet" | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Test 4: Root sets delay to zero | ||||||||||||||||||||||||||||||||||||||||
| assert_ok!(AdminUtils::sudo_set_start_call_delay( | ||||||||||||||||||||||||||||||||||||||||
| <<Test as Config>::RuntimeOrigin>::root(), | ||||||||||||||||||||||||||||||||||||||||
| 0 | ||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::StartCallDelay::<Test>::get(), | ||||||||||||||||||||||||||||||||||||||||
| 0, | ||||||||||||||||||||||||||||||||||||||||
| "Delay should now be zero" | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Verify event was emitted | ||||||||||||||||||||||||||||||||||||||||
| frame_system::Pallet::<Test>::assert_last_event(RuntimeEvent::SubtensorModule( | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::Event::StartCallDelaySet(0), | ||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Test 5: Try to start the subnet again - should SUCCEED (delay is now zero) | ||||||||||||||||||||||||||||||||||||||||
| let current_block = frame_system::Pallet::<Test>::block_number(); | ||||||||||||||||||||||||||||||||||||||||
| assert_ok!(pallet_subtensor::Pallet::<Test>::start_call( | ||||||||||||||||||||||||||||||||||||||||
| <<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id), | ||||||||||||||||||||||||||||||||||||||||
| netuid | ||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::FirstEmissionBlockNumber::<Test>::get(netuid), | ||||||||||||||||||||||||||||||||||||||||
| Some(current_block + 1), | ||||||||||||||||||||||||||||||||||||||||
| "Emission should start at next block" | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Test 6: Try to start it a third time - should FAIL (already started) | ||||||||||||||||||||||||||||||||||||||||
| assert_err!( | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::Pallet::<Test>::start_call( | ||||||||||||||||||||||||||||||||||||||||
| <<Test as Config>::RuntimeOrigin>::signed(coldkey_account_id), | ||||||||||||||||||||||||||||||||||||||||
| netuid | ||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||
| pallet_subtensor::Error::<Test>::FirstEmissionBlockNumberAlreadySet | ||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -542,6 +542,13 @@ impl<T: Config> Pallet<T> { | |
| NetworkImmunityPeriod::<T>::set(net_immunity_period); | ||
| Self::deposit_event(Event::NetworkImmunityPeriodSet(net_immunity_period)); | ||
| } | ||
| pub fn get_start_call_delay() -> u64 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in my opinion we should avoid introducing more of these kind of getters. |
||
| StartCallDelay::<T>::get() | ||
| } | ||
| pub fn set_start_call_delay(delay: u64) { | ||
| StartCallDelay::<T>::set(delay); | ||
| Self::deposit_event(Event::StartCallDelaySet(delay)); | ||
| } | ||
| pub fn set_network_min_lock(net_min_lock: TaoCurrency) { | ||
| NetworkMinLockCost::<T>::set(net_min_lock); | ||
| Self::deposit_event(Event::NetworkMinLockCostSet(net_min_lock)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -640,6 +640,12 @@ pub mod pallet { | |||||||||
| T::InitialSubnetOwnerCut::get() | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /// Default value for start call delay. | ||||||||||
| #[pallet::type_value] | ||||||||||
| pub fn DefaultStartCallDelay<T: Config>() -> u64 { | ||||||||||
| T::InitialStartCallDelay::get() | ||||||||||
| } | ||||||||||
|
Comment on lines
+644
to
+647
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I suspect it may not be needed because the role of |
||||||||||
|
|
||||||||||
| /// Default value for recycle or burn. | ||||||||||
| #[pallet::type_value] | ||||||||||
| pub fn DefaultRecycleOrBurn<T: Config>() -> RecycleOrBurnEnum { | ||||||||||
|
|
@@ -1514,6 +1520,10 @@ pub mod pallet { | |||||||||
| pub type NetworkImmunityPeriod<T> = | ||||||||||
| StorageValue<_, u64, ValueQuery, DefaultNetworkImmunityPeriod<T>>; | ||||||||||
|
|
||||||||||
| /// ITEM( start_call_delay ) | ||||||||||
| #[pallet::storage] | ||||||||||
| pub type StartCallDelay<T> = StorageValue<_, u64, ValueQuery, DefaultStartCallDelay<T>>; | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| /// ITEM( min_network_lock_cost ) | ||||||||||
| #[pallet::storage] | ||||||||||
| pub type NetworkMinLockCost<T> = | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -233,9 +233,9 @@ mod config { | |||||
| /// Initial EMA price halving period | ||||||
| #[pallet::constant] | ||||||
| type InitialEmaPriceHalvingPeriod: Get<u64>; | ||||||
| /// Block number after a new subnet accept the start call extrinsic. | ||||||
| /// Initial block number after a new subnet accept the start call extrinsic. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| #[pallet::constant] | ||||||
| type DurationOfStartCall: Get<u64>; | ||||||
| type InitialStartCallDelay: Get<u64>; | ||||||
| /// Cost of swapping a hotkey in a subnet. | ||||||
| #[pallet::constant] | ||||||
| type KeySwapOnSubnetCost: Get<u64>; | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks all the benchmarks