-
Notifications
You must be signed in to change notification settings - Fork 294
Auto CK root validators on subnet registration. #2503
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
664e08b
8b25e71
625daf8
4cf5f64
02b447e
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 |
|---|---|---|
|
|
@@ -769,6 +769,67 @@ impl<T: Config> Pallet<T> { | |
| // State cleaners (for use in migration) | ||
| // TODO: Deprecate when the state is clean for a while | ||
|
|
||
| /// Establishes parent-child relationships between all root validators and | ||
| /// a subnet owner's hotkey on the specified subnet. | ||
| /// | ||
| /// For each validator on the root network (netuid 0), this function calls | ||
| /// `do_schedule_children` to schedule the subnet owner hotkey as a child | ||
| /// of that root validator on the given subnet, with full proportion (u64::MAX). | ||
| /// | ||
| /// # Arguments | ||
| /// * `netuid` - The subnet on which to establish relationships. | ||
| /// | ||
| /// # Returns | ||
| /// * `DispatchResult` - Ok if at least the setup completes; individual | ||
| /// scheduling failures per validator are logged but do not abort the loop. | ||
| pub fn do_set_root_validators_for_subnet(netuid: NetUid) -> DispatchResult { | ||
| // Cannot set children on root network itself. | ||
| ensure!( | ||
| !netuid.is_root(), | ||
| Error::<T>::RegistrationNotPermittedOnRootSubnet | ||
| ); | ||
|
|
||
| // Subnet must exist. | ||
| ensure!(Self::if_subnet_exist(netuid), Error::<T>::SubnetNotExists); | ||
|
|
||
| // Get the subnet owner hotkey. | ||
| let subnet_owner_hotkey = | ||
| SubnetOwnerHotkey::<T>::try_get(netuid).map_err(|_| Error::<T>::SubnetNotExists)?; | ||
|
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. need a different error type.
Collaborator
Author
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. Do we have a better one? It seems appropriate. We don't have subnet owner hotkey only when it doesn't exist. What do you suggest? |
||
|
|
||
| // Iterate over all root validators and schedule each one as a parent | ||
| // of the subnet owner hotkey. | ||
| for (_uid, root_validator_hotkey) in Keys::<T>::iter_prefix(NetUid::ROOT) { | ||
| // Skip if the root validator is the subnet owner hotkey itself | ||
| // (cannot be both parent and child). | ||
| if root_validator_hotkey == subnet_owner_hotkey { | ||
| continue; | ||
| } | ||
|
|
||
| // Look up the coldkey that owns this root validator hotkey. | ||
| let coldkey = Self::get_owning_coldkey_for_hotkey(&root_validator_hotkey); | ||
|
|
||
| // Build a signed origin from the coldkey. | ||
| let origin: <T as frame_system::Config>::RuntimeOrigin = | ||
| frame_system::RawOrigin::Signed(coldkey).into(); | ||
|
|
||
| // Schedule the subnet owner hotkey as a child with full proportion. | ||
| let children = vec![(u64::MAX, subnet_owner_hotkey.clone())]; | ||
|
|
||
| if let Err(e) = | ||
| Self::do_schedule_children(origin, root_validator_hotkey.clone(), netuid, children) | ||
| { | ||
| log::warn!( | ||
| "Failed to schedule children for root validator {:?} on netuid {:?}: {:?}", | ||
| root_validator_hotkey, | ||
| netuid, | ||
| e | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn clean_zero_childkey_vectors(weight: &mut Weight) { | ||
| // Collect keys to delete first to avoid mutating while iterating. | ||
| let mut to_remove: Vec<(T::AccountId, NetUid)> = Vec::new(); | ||
|
|
||
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.
need a different error type.
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.
Seems close enough. Also, I don't expect errors here at all because it's called only during subnet registration with concrete netuid. What do you suggest instead?