-
Notifications
You must be signed in to change notification settings - Fork 149
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/limit nominators per delegate #367
Conversation
@@ -548,3 +548,37 @@ pub fn migrate_stake_to_substake<T: Config>() -> Weight { | |||
log::info!("Final weight: {:?}", weight); // Debug print | |||
weight | |||
} | |||
|
|||
pub fn migrate_nominator_counters<T: Config>() -> Weight { |
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.
We need to check that this is only migrating nominations and not self delegations i.e when the cold key owns the hot key
#[pallet::storage] // --- ITEM ( delegate_limit ) --> Maximmu number of nominators per subnet validator | ||
pub type DelegateLimit<T> = StorageValue<_, u32, ValueQuery, DefaultDelegateLimit<T>>; | ||
#[pallet::storage] // --- ITEM ( delegate_limit ) --> Maximum number of nominators per hotkey | ||
pub type NominatorLimit<T> = StorageValue<_, u32, ValueQuery, DefaultNominatorLimit<T>>; |
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.
Do you think NominationLimit
would be a more appropriate 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.
I think not, because we are counting unique nominators here, and one nominator can make multiple nominations that would only increase the counter by 1.
#[pallet::storage] // --- ITEM ( delegate_limit ) --> Maximum number of nominators per hotkey | ||
pub type NominatorLimit<T> = StorageValue<_, u32, ValueQuery, DefaultNominatorLimit<T>>; | ||
#[pallet::storage] // --- MAP ( hot ) --> count | Number of nominators per hotkey | ||
pub type NominatorCount<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.
same as above NominationCount
@@ -258,7 +258,7 @@ impl<T: Config> Pallet<T> { | |||
.collect() | |||
} | |||
|
|||
pub fn get_delegate_limit() -> u32 { | |||
DelegateLimit::<T>::get() | |||
pub fn get_nominator_limit() -> u32 { |
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.
get_nomination_limit
@@ -162,7 +162,7 @@ pub mod pallet { | |||
#[pallet::constant] // Initial default delegation take. | |||
type InitialDefaultTake: Get<u16>; | |||
#[pallet::constant] // Initial limit on number of nominators per subnet validator | |||
type InitialDelegateLimit: Get<u32>; | |||
type InitialNominatorLimit: Get<u32>; |
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.
InitialNominationLimit
@@ -357,7 +357,7 @@ impl pallet_subtensor::Config for Test { | |||
type InitialSubnetLimit = InitialSubnetLimit; | |||
type InitialNetworkRateLimit = InitialNetworkRateLimit; | |||
type InitialTargetStakesPerInterval = InitialTargetStakesPerInterval; | |||
type InitialDelegateLimit = InitialDelegateLimit; | |||
type InitialNominatorLimit = InitialNominatorLimit; |
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.
type InitialNominatorLimit = InitialNominatorLimit; | |
type InitialNominationLimit = InitialNominationLimit; |
pallets/subtensor/tests/staking.rs
Outdated
} | ||
|
||
// Nominate 11th time - fails | ||
let nominator11 = U256::from(11); |
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.
Do we need to add this case given that we already test for it in the previous test?
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.
True! Removing it.
@@ -644,7 +644,7 @@ parameter_types! { | |||
pub const SubtensorInitialScalingLawPower: u16 = 50; // 0.5 | |||
pub const SubtensorInitialMaxAllowedValidators: u16 = 128; | |||
pub const SubtensorInitialTempo: u16 = 99; | |||
pub const SubtensorInitialDelegateLimit: u32 = 128; // Limits the number of nominators per subnet validator | |||
pub const SubtensorInitialNominatorLimit: u32 = 128; // Limits the number of nominators per subnet validator |
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 const SubtensorInitialNominatorLimit: u32 = 128; // Limits the number of nominators per subnet validator | |
pub const SubtensorInitialNominationLimit: u32 = 128; // Limits the number of nominators per subnet validator |
@@ -696,7 +696,7 @@ impl pallet_subtensor::Config for Runtime { | |||
type InitialValidatorPruneLen = SubtensorInitialValidatorPruneLen; | |||
type InitialScalingLawPower = SubtensorInitialScalingLawPower; | |||
type InitialTempo = SubtensorInitialTempo; | |||
type InitialDelegateLimit = SubtensorInitialDelegateLimit; | |||
type InitialNominatorLimit = SubtensorInitialNominatorLimit; |
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.
type InitialNominatorLimit = SubtensorInitialNominatorLimit; | |
type InitialNominationLimit = SubtensorInitialNominationLimit; |
@@ -886,8 +886,8 @@ impl | |||
SubtensorModule::set_tempo(netuid, tempo); | |||
} | |||
|
|||
fn set_delegate_limit(limit: u32) { | |||
SubtensorModule::set_delegate_limit(limit); | |||
fn set_nominator_limit(limit: u32) { |
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.
fn set_nominator_limit(limit: u32) { | |
fn set_nomination_limit(limit: u32) { |
Also i think this PR should be going into development not dynamic. |
Description
This PR completes the feature of limiting the number of nominators per hotkey. Default value is set to 128, but it can be adjusted via admin extrinsic. Initially the code migrates by initializing counters using Stake state map, so that add_stake transaction don't need to run O(n) counting operation.
Related Issue(s)
Type of Change
Breaking Change
n/a
Checklist
cargo fmt
andcargo clippy
to ensure my code is formatted and linted correctlyScreenshots (if applicable)
n/a
Additional Notes
n/a