@@ -157,15 +157,8 @@ impl<T: Config> Pallet<T> {
157157 Error :: <T >:: NonAssociatedColdKey
158158 ) ;
159159
160- // --- 6. Ensure we don't exceed tx rate limit
161- let block: u64 = Self :: get_current_block_as_u64 ( ) ;
162- ensure ! (
163- !Self :: exceeds_tx_rate_limit( Self :: get_last_tx_block( & coldkey) , block) ,
164- Error :: <T >:: TxRateLimitExceeded
165- ) ;
166-
167- // --- 7. Ensure we don't exceed stake rate limit
168- let stakes_this_interval = Self :: get_stakes_this_interval_for_hotkey ( & hotkey) ;
160+ // --- 6. Ensure we don't exceed stake rate limit
161+ let stakes_this_interval = Self :: get_stakes_this_interval_for_coldkey_hotkey ( & coldkey, & hotkey) ;
169162 ensure ! (
170163 stakes_this_interval < Self :: get_target_stakes_per_interval( ) ,
171164 Error :: <T >:: StakeRateLimitExceeded
@@ -181,10 +174,12 @@ impl<T: Config> Pallet<T> {
181174 Self :: increase_stake_on_coldkey_hotkey_account ( & coldkey, & hotkey, stake_to_be_added) ;
182175
183176 // Set last block for rate limiting
177+ let block: u64 = Self :: get_current_block_as_u64 ( ) ;
184178 Self :: set_last_tx_block ( & coldkey, block) ;
185179
186- // --- 10. Emit the staking event.
187- Self :: set_stakes_this_interval_for_hotkey (
180+ // --- 9. Emit the staking event.
181+ Self :: set_stakes_this_interval_for_coldkey_hotkey (
182+ & coldkey,
188183 & hotkey,
189184 stakes_this_interval + 1 ,
190185 block,
@@ -196,7 +191,7 @@ impl<T: Config> Pallet<T> {
196191 ) ;
197192 Self :: deposit_event ( Event :: StakeAdded ( hotkey, stake_to_be_added) ) ;
198193
199- // --- 11 . Ok and return.
194+ // --- 10 . Ok and return.
200195 Ok ( ( ) )
201196 }
202197
@@ -278,31 +273,26 @@ impl<T: Config> Pallet<T> {
278273 Error :: <T >:: CouldNotConvertToBalance
279274 ) ;
280275
281- // --- 6. Ensure we don't exceed tx rate limit
282- let block: u64 = Self :: get_current_block_as_u64 ( ) ;
283- ensure ! (
284- !Self :: exceeds_tx_rate_limit( Self :: get_last_tx_block( & coldkey) , block) ,
285- Error :: <T >:: TxRateLimitExceeded
286- ) ;
287-
288- // --- 7. Ensure we don't exceed stake rate limit
289- let unstakes_this_interval = Self :: get_stakes_this_interval_for_hotkey ( & hotkey) ;
276+ // --- 6. Ensure we don't exceed stake rate limit
277+ let unstakes_this_interval = Self :: get_stakes_this_interval_for_coldkey_hotkey ( & coldkey, & hotkey) ;
290278 ensure ! (
291279 unstakes_this_interval < Self :: get_target_stakes_per_interval( ) ,
292280 Error :: <T >:: UnstakeRateLimitExceeded
293281 ) ;
294282
295- // --- 8 . We remove the balance from the hotkey.
283+ // --- 7 . We remove the balance from the hotkey.
296284 Self :: decrease_stake_on_coldkey_hotkey_account ( & coldkey, & hotkey, stake_to_be_removed) ;
297285
298- // --- 9 . We add the balancer to the coldkey. If the above fails we will not credit this coldkey.
286+ // --- 8 . We add the balancer to the coldkey. If the above fails we will not credit this coldkey.
299287 Self :: add_balance_to_coldkey_account ( & coldkey, stake_to_be_added_as_currency. unwrap ( ) ) ;
300288
301289 // Set last block for rate limiting
290+ let block: u64 = Self :: get_current_block_as_u64 ( ) ;
302291 Self :: set_last_tx_block ( & coldkey, block) ;
303292
304- // --- 10. Emit the unstaking event.
305- Self :: set_stakes_this_interval_for_hotkey (
293+ // --- 9. Emit the unstaking event.
294+ Self :: set_stakes_this_interval_for_coldkey_hotkey (
295+ & coldkey,
306296 & hotkey,
307297 unstakes_this_interval + 1 ,
308298 block,
@@ -314,7 +304,7 @@ impl<T: Config> Pallet<T> {
314304 ) ;
315305 Self :: deposit_event ( Event :: StakeRemoved ( hotkey, stake_to_be_removed) ) ;
316306
317- // --- 11 . Done and ok.
307+ // --- 10 . Done and ok.
318308 Ok ( ( ) )
319309 }
320310
@@ -367,15 +357,15 @@ impl<T: Config> Pallet<T> {
367357 }
368358
369359 // Retrieves the total stakes for a given hotkey (account ID) for the current staking interval.
370- pub fn get_stakes_this_interval_for_hotkey ( hotkey : & T :: AccountId ) -> u64 {
360+ pub fn get_stakes_this_interval_for_coldkey_hotkey ( coldkey : & T :: AccountId , hotkey : & T :: AccountId ) -> u64 {
371361 // Retrieve the configured stake interval duration from storage.
372362 let stake_interval = StakeInterval :: < T > :: get ( ) ;
373363
374364 // Obtain the current block number as an unsigned 64-bit integer.
375365 let current_block = Self :: get_current_block_as_u64 ( ) ;
376366
377367 // Fetch the total stakes and the last block number when stakes were made for the hotkey.
378- let ( stakes, block_last_staked_at) = TotalHotkeyStakesThisInterval :: < T > :: get ( hotkey) ;
368+ let ( stakes, block_last_staked_at) = TotalHotkeyColdkeyStakesThisInterval :: < T > :: get ( coldkey , hotkey) ;
379369
380370 // Calculate the block number after which the stakes for the hotkey should be reset.
381371 let block_to_reset_after = block_last_staked_at + stake_interval;
@@ -384,7 +374,7 @@ impl<T: Config> Pallet<T> {
384374 // it indicates the end of the staking interval for the hotkey.
385375 if block_to_reset_after <= current_block {
386376 // Reset the stakes for this hotkey for the current interval.
387- Self :: set_stakes_this_interval_for_hotkey ( hotkey, 0 , block_last_staked_at) ;
377+ Self :: set_stakes_this_interval_for_coldkey_hotkey ( coldkey , hotkey, 0 , block_last_staked_at) ;
388378 // Return 0 as the stake amount since we've just reset the stakes.
389379 return 0 ;
390380 }
0 commit comments