@@ -210,7 +210,11 @@ impl<T: Config> Pallet<T> {
210210 . saturating_add ( T :: DbWeight :: get ( ) . reads ( 7_u64 ) )
211211 . saturating_add ( T :: DbWeight :: get ( ) . writes ( 5_u64 ) )
212212 }
213- pub fn root_claim_all ( hotkey : & T :: AccountId , coldkey : & T :: AccountId ) -> Weight {
213+ pub fn root_claim_all (
214+ hotkey : & T :: AccountId ,
215+ coldkey : & T :: AccountId ,
216+ subnets : Option < BTreeSet < NetUid > > ,
217+ ) -> Weight {
214218 let mut weight = Weight :: default ( ) ;
215219
216220 let root_claim_type = RootClaimType :: < T > :: get ( coldkey) ;
@@ -220,10 +224,19 @@ impl<T: Config> Pallet<T> {
220224 let root_claimable = RootClaimable :: < T > :: get ( hotkey) ;
221225 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
222226
223- root_claimable. iter ( ) . for_each ( |( netuid, _) | {
227+ for ( netuid, _) in root_claimable. iter ( ) {
228+ let skip = subnets
229+ . as_ref ( )
230+ . map ( |subnets| !subnets. contains ( netuid) )
231+ . unwrap_or ( false ) ;
232+
233+ if skip {
234+ continue ;
235+ }
236+
224237 Self :: root_claim_on_subnet ( hotkey, coldkey, * netuid, root_claim_type. clone ( ) , false ) ;
225238 weight. saturating_accrue ( Self :: root_claim_on_subnet_weight ( root_claim_type. clone ( ) ) ) ;
226- } ) ;
239+ }
227240
228241 weight
229242 }
@@ -278,15 +291,15 @@ impl<T: Config> Pallet<T> {
278291 }
279292 }
280293
281- pub fn do_root_claim ( coldkey : T :: AccountId ) -> Weight {
294+ pub fn do_root_claim ( coldkey : T :: AccountId , subnets : Option < BTreeSet < NetUid > > ) -> Weight {
282295 let mut weight = Weight :: default ( ) ;
283296
284297 let hotkeys = StakingHotkeys :: < T > :: get ( & coldkey) ;
285298 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
286299
287300 hotkeys. iter ( ) . for_each ( |hotkey| {
288301 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
289- weight. saturating_accrue ( Self :: root_claim_all ( hotkey, & coldkey) ) ;
302+ weight. saturating_accrue ( Self :: root_claim_all ( hotkey, & coldkey, subnets . clone ( ) ) ) ;
290303 } ) ;
291304
292305 Self :: deposit_event ( Event :: RootClaimed { coldkey } ) ;
@@ -321,7 +334,7 @@ impl<T: Config> Pallet<T> {
321334 for i in coldkeys_to_claim. iter ( ) {
322335 weight. saturating_accrue ( T :: DbWeight :: get ( ) . reads ( 1 ) ) ;
323336 if let Ok ( coldkey) = StakingColdkeysByIndex :: < T > :: try_get ( i) {
324- weight. saturating_accrue ( Self :: do_root_claim ( coldkey. clone ( ) ) ) ;
337+ weight. saturating_accrue ( Self :: do_root_claim ( coldkey. clone ( ) , None ) ) ;
325338 }
326339
327340 continue ;
0 commit comments