@@ -49,8 +49,9 @@ impl<T: Config> Pallet<T> {
4949 Error :: <T >:: HotKeySetTxRateLimitExceeded
5050 ) ;
5151
52- weight
53- . saturating_accrue ( T :: DbWeight :: get ( ) . reads ( ( TotalNetworks :: < T > :: get ( ) + 1u16 ) as u64 ) ) ;
52+ weight. saturating_accrue (
53+ T :: DbWeight :: get ( ) . reads ( ( TotalNetworks :: < T > :: get ( ) . saturating_add ( 1u16 ) ) as u64 ) ,
54+ ) ;
5455
5556 let swap_cost = Self :: get_hotkey_swap_cost ( ) ;
5657 log:: debug!( "Swap cost: {:?}" , swap_cost) ;
@@ -189,20 +190,20 @@ impl<T: Config> Pallet<T> {
189190 /// * `new_hotkey` - The new hotkey.
190191 /// * `weight` - The weight of the transaction.
191192 pub fn swap_stake ( old_hotkey : & T :: AccountId , new_hotkey : & T :: AccountId , weight : & mut Weight ) {
192- let mut writes = 0 ;
193+ let mut writes: u64 = 0 ;
193194 let stakes: Vec < ( T :: AccountId , u64 ) > = Stake :: < T > :: iter_prefix ( old_hotkey) . collect ( ) ;
194195 let stake_count = stakes. len ( ) as u32 ;
195196
196197 for ( coldkey, stake_amount) in stakes {
197198 Stake :: < T > :: insert ( new_hotkey, & coldkey, stake_amount) ;
198- writes += 1 ; // One write for insert
199+ writes = writes . saturating_add ( 1u64 ) ; // One write for insert
199200 }
200201
201202 // Clear the prefix for the old hotkey after transferring all stakes
202203 let _ = Stake :: < T > :: clear_prefix ( old_hotkey, stake_count, None ) ;
203- writes += 1 ; // One write for clear_prefix
204+ writes = writes . saturating_add ( 1 ) ; // One write for insert ; // One write for clear_prefix
204205
205- * weight += T :: DbWeight :: get ( ) . writes ( writes as u64 ) ;
206+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . writes ( writes) ) ;
206207 }
207208
208209 /// Swaps the network membership status of the hotkey.
@@ -271,19 +272,19 @@ impl<T: Config> Pallet<T> {
271272 netuid_is_member : & [ u16 ] ,
272273 weight : & mut Weight ,
273274 ) {
274- let mut writes = 0 ;
275+ let mut writes: u64 = 0 ;
275276 for netuid in netuid_is_member {
276277 let keys: Vec < ( u16 , T :: AccountId ) > = Keys :: < T > :: iter_prefix ( netuid) . collect ( ) ;
277278 for ( uid, key) in keys {
278279 if key == * old_hotkey {
279280 log:: info!( "old hotkey found: {:?}" , old_hotkey) ;
280281 Keys :: < T > :: insert ( netuid, uid, new_hotkey. clone ( ) ) ;
281282 }
282- writes += 2 ;
283+ writes = writes . saturating_add ( 2u64 ) ;
283284 }
284285 }
285286 log:: info!( "writes: {:?}" , writes) ;
286- * weight += T :: DbWeight :: get ( ) . writes ( writes as u64 ) ;
287+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . writes ( writes) ) ;
287288 }
288289
289290 /// Swaps the loaded emission of the hotkey.
@@ -311,7 +312,7 @@ impl<T: Config> Pallet<T> {
311312 LoadedEmission :: < T > :: insert ( netuid, emissions) ;
312313 }
313314 }
314- * weight += T :: DbWeight :: get ( ) . writes ( netuid_is_member. len ( ) as u64 ) ;
315+ weight. saturating_accrue ( T :: DbWeight :: get ( ) . writes ( netuid_is_member. len ( ) as u64 ) ) ;
315316 }
316317
317318 /// Swaps the UIDs of the hotkey.
0 commit comments