@@ -182,6 +182,8 @@ pub mod pallet {
182182 type InitialSubnetLimit : Get < u16 > ;
183183 #[ pallet:: constant] // Initial network creation rate limit
184184 type InitialNetworkRateLimit : Get < u64 > ;
185+ #[ pallet:: constant] // Initial target stakes per interval issuance.
186+ type InitialTargetStakesPerInterval : Get < u64 > ;
185187 }
186188
187189 pub type AccountIdOf < T > = <T as frame_system:: Config >:: AccountId ;
@@ -212,6 +214,10 @@ pub mod pallet {
212214 0
213215 }
214216 #[ pallet:: type_value]
217+ pub fn DefaultStakesPerInterval < T : Config > ( ) -> ( u64 , u64 ) {
218+ ( 0 , 0 )
219+ }
220+ #[ pallet:: type_value]
215221 pub fn DefaultBlockEmission < T : Config > ( ) -> u64 {
216222 1_000_000_000
217223 }
@@ -227,6 +233,14 @@ pub mod pallet {
227233 pub fn DefaultAccount < T : Config > ( ) -> T :: AccountId {
228234 T :: AccountId :: decode ( & mut TrailingZeroInput :: zeroes ( ) ) . unwrap ( )
229235 }
236+ #[ pallet:: type_value]
237+ pub fn DefaultTargetStakesPerInterval < T : Config > ( ) -> u64 {
238+ T :: InitialTargetStakesPerInterval :: get ( )
239+ }
240+ #[ pallet:: type_value]
241+ pub fn DefaultStakeInterval < T : Config > ( ) -> u64 {
242+ 360
243+ }
230244
231245 #[ pallet:: storage] // --- ITEM ( total_stake )
232246 pub type TotalStake < T > = StorageValue < _ , u64 , ValueQuery > ;
@@ -236,12 +250,22 @@ pub mod pallet {
236250 pub type BlockEmission < T > = StorageValue < _ , u64 , ValueQuery , DefaultBlockEmission < T > > ;
237251 #[ pallet:: storage] // --- ITEM ( total_issuance )
238252 pub type TotalIssuance < T > = StorageValue < _ , u64 , ValueQuery , DefaultTotalIssuance < T > > ;
253+ #[ pallet:: storage] // --- ITEM (target_stakes_per_interval)
254+ pub type TargetStakesPerInterval < T > =
255+ StorageValue < _ , u64 , ValueQuery , DefaultTargetStakesPerInterval < T > > ;
256+ #[ pallet:: storage] // --- ITEM (default_stake_interval)
257+ pub type StakeInterval < T > = StorageValue < _ , u64 , ValueQuery , DefaultStakeInterval < T > > ;
239258 #[ pallet:: storage] // --- MAP ( hot ) --> stake | Returns the total amount of stake under a hotkey.
240259 pub type TotalHotkeyStake < T : Config > =
241260 StorageMap < _ , Identity , T :: AccountId , u64 , ValueQuery , DefaultAccountTake < T > > ;
242261 #[ pallet:: storage] // --- MAP ( cold ) --> stake | Returns the total amount of stake under a coldkey.
243262 pub type TotalColdkeyStake < T : Config > =
244263 StorageMap < _ , Identity , T :: AccountId , u64 , ValueQuery , DefaultAccountTake < T > > ;
264+ #[ pallet:: storage]
265+ // --- MAP (hot) --> stake | Returns a tuple (u64: stakes, u64: block_number)
266+ pub type TotalHotkeyStakesThisInterval < T : Config > =
267+ StorageMap < _ , Identity , T :: AccountId , ( u64 , u64 ) , ValueQuery , DefaultStakesPerInterval < T > > ;
268+
245269 #[ pallet:: storage] // --- MAP ( hot ) --> cold | Returns the controlling coldkey for a hotkey.
246270 pub type Owner < T : Config > =
247271 StorageMap < _ , Blake2_128Concat , T :: AccountId , T :: AccountId , ValueQuery , DefaultAccount < T > > ;
@@ -924,7 +948,9 @@ pub mod pallet {
924948 MaxAllowedUidsExceeded , // --- Thrown when number of accounts going to be registered exceeds MaxAllowedUids for the network.
925949 TooManyUids , // ---- Thrown when the caller attempts to set weights with more uids than allowed.
926950 TxRateLimitExceeded , // --- Thrown when a transactor exceeds the rate limit for transactions.
927- RegistrationDisabled , // --- Thrown when registration is disabled
951+ StakeRateLimitExceeded , // --- Thrown when a transactor exceeds the rate limit for stakes.
952+ UnstakeRateLimitExceeded , // --- Thrown when a transactor exceeds the rate limit for unstakes.
953+ RegistrationDisabled , // --- Thrown when registration is disabled
928954 TooManyRegistrationsThisInterval , // --- Thrown when registration attempt exceeds allowed in interval
929955 BenchmarkingOnly , // --- Thrown when a function is only available for benchmarking
930956 HotkeyOriginMismatch , // --- Thrown when the hotkey passed is not the origin, but it should be
@@ -1822,14 +1848,32 @@ where
18221848 return Err ( InvalidTransaction :: Call . into ( ) ) ;
18231849 }
18241850 }
1825- Some ( Call :: add_stake { .. } ) => Ok ( ValidTransaction {
1826- priority : Self :: get_priority_vanilla ( ) ,
1827- ..Default :: default ( )
1828- } ) ,
1829- Some ( Call :: remove_stake { .. } ) => Ok ( ValidTransaction {
1830- priority : Self :: get_priority_vanilla ( ) ,
1831- ..Default :: default ( )
1832- } ) ,
1851+ Some ( Call :: add_stake { hotkey, .. } ) => {
1852+ let stakes_this_interval = Pallet :: < T > :: get_stakes_this_interval_for_hotkey ( hotkey) ;
1853+ let max_stakes_per_interval = Pallet :: < T > :: get_target_stakes_per_interval ( ) ;
1854+
1855+ if stakes_this_interval >= max_stakes_per_interval {
1856+ return InvalidTransaction :: ExhaustsResources . into ( ) ;
1857+ }
1858+
1859+ Ok ( ValidTransaction {
1860+ priority : Self :: get_priority_vanilla ( ) ,
1861+ ..Default :: default ( )
1862+ } )
1863+ }
1864+ Some ( Call :: remove_stake { hotkey, .. } ) => {
1865+ let stakes_this_interval = Pallet :: < T > :: get_stakes_this_interval_for_hotkey ( hotkey) ;
1866+ let max_stakes_per_interval = Pallet :: < T > :: get_target_stakes_per_interval ( ) ;
1867+
1868+ if stakes_this_interval >= max_stakes_per_interval {
1869+ return InvalidTransaction :: ExhaustsResources . into ( ) ;
1870+ }
1871+
1872+ Ok ( ValidTransaction {
1873+ priority : Self :: get_priority_vanilla ( ) ,
1874+ ..Default :: default ( )
1875+ } )
1876+ }
18331877 Some ( Call :: register { netuid, .. } | Call :: burned_register { netuid, .. } ) => {
18341878 let registrations_this_interval =
18351879 Pallet :: < T > :: get_registrations_this_interval ( * netuid) ;
0 commit comments