-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: making code more robust, fixing incentives #44
Conversation
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.
It's good practice to unify all validations in a single place. This makes searching for bugs a LOT easier in the future. Avoid writing security-crucial code more than once in the same codebase, prefer reusing functions
pallets/subspace/src/subnet.rs
Outdated
@@ -10,15 +10,71 @@ use sp_std::vec::Vec; | |||
use substrate_fixed::types::I64F64; | |||
extern crate alloc; | |||
|
|||
#[derive(Debug)] | |||
pub struct SubnetSet<T: Config> { |
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.
pub struct SubnetSet<T: Config> { | |
pub struct SubnetChangeset<T: Config> { |
pallets/subspace/src/subnet.rs
Outdated
|
||
impl<T: Config> SubnetSet<T> { | ||
#[must_use] | ||
pub fn new(name: &Vec<u8>, founder_key: &T::AccountId, params: SubnetParams<T>) -> Self { |
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.
pub fn new(name: &Vec<u8>, founder_key: &T::AccountId, params: SubnetParams<T>) -> Self { | |
pub fn new(name: &[u8], founder_key: &T::AccountId, params: SubnetParams<T>) -> Self { |
pallets/subspace/src/subnet.rs
Outdated
// check for name validity | ||
if let Some(name) = self.name { | ||
ensure!( | ||
!Pallet::<T>::if_subnet_name_exists(&name), |
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.
As for the module, this must only be checked if the subnet name is different from its current name. Check ModuleChangeset::new
to see how it's done.
pallets/subspace/src/subnet.rs
Outdated
ensure!( | ||
Pallet::<T>::if_subnet_netuid_exists(netuid), | ||
Error::<T>::NetuidDoesNotExist | ||
); |
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.
Doing this will make this changeset only work when updating a subnet, and not registering one, meaning the same validations will have to be re-done elsewhere, which fragments validation logic.
pallets/subspace/src/step.rs
Outdated
registrations_this_interval, | ||
target_registrations_per_interval, | ||
)); | ||
Self::set_burn( |
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.
I would split on a variable just to make easier to read
d03761b |
* feat: local subnet burn ! missing migrations * fixing potential problems after reaching global module limit * fix: ensuring subnet naming safety * feat: adding migrations + fixing subnet burn * applying PR suggestions * fix: clippy errors
Changes
I honestly think that we should change the
subneset
tosubnetchangeset
and also add the update for it, what do you think @saiintbrisson ?