@@ -10,10 +10,10 @@ use pallet_rate_limiting::{
1010} ;
1111use pallet_subtensor:: {
1212 self , AssociatedEvmAddress , Axons , Config as SubtensorConfig , HasMigrationRun ,
13- LastRateLimitedBlock , LastUpdate , MaxUidsTrimmingRateLimit , MechanismCountCurrent ,
14- MechanismCountSetRateLimit , MechanismEmissionRateLimit , NetworkRateLimit ,
15- OwnerHyperparamRateLimit , Pallet , Prometheus , RateLimitKey , TransactionKeyLastBlock ,
16- TxChildkeyTakeRateLimit , TxDelegateTakeRateLimit , TxRateLimit , WeightsVersionKeyRateLimit ,
13+ LastRateLimitedBlock , LastUpdate , MaxUidsTrimmingRateLimit , MechanismCountSetRateLimit ,
14+ MechanismEmissionRateLimit , NetworkRateLimit , OwnerHyperparamRateLimit , Pallet , Prometheus ,
15+ RateLimitKey , TransactionKeyLastBlock , TxChildkeyTakeRateLimit , TxDelegateTakeRateLimit ,
16+ TxRateLimit , WeightsVersionKeyRateLimit ,
1717 utils:: rate_limiting:: { Hyperparameter , TransactionType } ,
1818} ;
1919use sp_runtime:: traits:: SaturatedConversion ;
@@ -22,14 +22,14 @@ use sp_std::{
2222 vec,
2323 vec:: Vec ,
2424} ;
25- use subtensor_runtime_common:: { MechId , NetUid } ;
25+ use subtensor_runtime_common:: NetUid ;
2626
27- use super :: { RateLimitScope , RateLimitUsageKey } ;
27+ use super :: RateLimitUsageKey ;
2828
2929type GroupIdOf < T > = <T as pallet_rate_limiting:: Config >:: GroupId ;
3030type LimitEntries < T > = Vec < (
3131 RateLimitTarget < GroupId > ,
32- RateLimit < RateLimitScope , BlockNumberFor < T > > ,
32+ RateLimit < NetUid , BlockNumberFor < T > > ,
3333) > ;
3434type LastSeenEntries < T > = Vec < (
3535 (
@@ -240,13 +240,6 @@ fn weight_calls_subnet(grouping: &Grouping) -> Vec<TransactionIdentifier> {
240240 . unwrap_or_default ( )
241241}
242242
243- fn weight_calls_mechanism ( grouping : & Grouping ) -> Vec < TransactionIdentifier > {
244- grouping
245- . members ( GROUP_WEIGHTS_MECHANISM )
246- . map ( |m| m. iter ( ) . copied ( ) . collect ( ) )
247- . unwrap_or_default ( )
248- }
249-
250243fn build_grouping ( ) -> Grouping {
251244 let mut grouping = Grouping :: default ( ) ;
252245
@@ -265,8 +258,7 @@ fn build_grouping() -> Grouping {
265258
266259pub fn migrate_rate_limiting < T > ( ) -> Weight
267260where
268- T : SubtensorConfig
269- + pallet_rate_limiting:: Config < LimitScope = RateLimitScope , GroupId = GroupId > ,
261+ T : SubtensorConfig + pallet_rate_limiting:: Config < LimitScope = NetUid , GroupId = GroupId > ,
270262 RateLimitUsageKey < T :: AccountId > : Into < <T as pallet_rate_limiting:: Config >:: UsageKey > ,
271263{
272264 let mut weight = T :: DbWeight :: get ( ) . reads ( 1 ) ;
@@ -449,12 +441,7 @@ fn gather_serving_limits<T: SubtensorConfig>(
449441 reads += 1 ;
450442 if let Some ( span) = block_number :: < T > ( Pallet :: < T > :: get_serving_rate_limit ( netuid) ) {
451443 for call in serve_calls ( grouping) {
452- set_scoped_limit :: < T > (
453- limits,
454- grouping. config_target ( call) ,
455- RateLimitScope :: Subnet ( netuid) ,
456- span,
457- ) ;
444+ set_scoped_limit :: < T > ( limits, grouping. config_target ( call) , netuid, span) ;
458445 }
459446 }
460447 }
@@ -469,40 +456,12 @@ fn gather_weight_limits<T: SubtensorConfig>(
469456 let mut reads: u64 = 0 ;
470457 let netuids = Pallet :: < T > :: get_all_subnet_netuids ( ) ;
471458
472- let mut subnet_limits = BTreeMap :: < NetUid , BlockNumberFor < T > > :: new ( ) ;
473459 let subnet_calls = weight_calls_subnet ( grouping) ;
474- let mechanism_calls = weight_calls_mechanism ( grouping) ;
475460 for netuid in & netuids {
476461 reads += 1 ;
477462 if let Some ( span) = block_number :: < T > ( Pallet :: < T > :: get_weights_set_rate_limit ( * netuid) ) {
478- subnet_limits. insert ( * netuid, span) ;
479463 for call in & subnet_calls {
480- set_scoped_limit :: < T > (
481- limits,
482- grouping. config_target ( * call) ,
483- RateLimitScope :: Subnet ( * netuid) ,
484- span,
485- ) ;
486- }
487- }
488- }
489-
490- for netuid in & netuids {
491- reads += 1 ;
492- let mech_count: u8 = MechanismCountCurrent :: < T > :: get ( * netuid) . into ( ) ;
493- if mech_count <= 1 {
494- continue ;
495- }
496- let Some ( span) = subnet_limits. get ( netuid) . copied ( ) else {
497- continue ;
498- } ;
499- for mecid in 1 ..mech_count {
500- let scope = RateLimitScope :: SubnetMechanism {
501- netuid : * netuid,
502- mecid : MechId :: from ( mecid) ,
503- } ;
504- for call in & mechanism_calls {
505- set_scoped_limit :: < T > ( limits, grouping. config_target ( * call) , scope. clone ( ) , span) ;
464+ set_scoped_limit :: < T > ( limits, grouping. config_target ( * call) , * netuid, span) ;
506465 }
507466 }
508467 }
@@ -621,18 +580,9 @@ fn import_last_update_entries<T: SubtensorConfig>(
621580) -> u64 {
622581 let mut reads: u64 = 0 ;
623582 let subnet_calls = weight_calls_subnet ( grouping) ;
624- let mechanism_calls = weight_calls_mechanism ( grouping) ;
625583 for ( index, blocks) in LastUpdate :: < T > :: iter ( ) {
626584 reads += 1 ;
627585 let netuid = Pallet :: < T > :: get_netuid ( index) ;
628- let sub_id = u16:: from ( index)
629- . checked_div ( pallet_subtensor:: subnets:: mechanism:: GLOBAL_MAX_SUBNET_COUNT )
630- . unwrap_or_default ( ) ;
631- let is_mechanism = sub_id != 0 ;
632- let Ok ( sub_id) = u8:: try_from ( sub_id) else {
633- continue ;
634- } ;
635- let mecid = MechId :: from ( sub_id) ;
636586
637587 for ( uid, last_block) in blocks. into_iter ( ) . enumerate ( ) {
638588 if last_block == 0 {
@@ -641,26 +591,12 @@ fn import_last_update_entries<T: SubtensorConfig>(
641591 let Ok ( uid_u16) = u16:: try_from ( uid) else {
642592 continue ;
643593 } ;
644- let usage = if is_mechanism {
645- RateLimitUsageKey :: SubnetMechanismNeuron {
646- netuid,
647- mecid,
648- uid : uid_u16,
649- }
650- } else {
651- RateLimitUsageKey :: SubnetNeuron {
652- netuid,
653- uid : uid_u16,
654- }
655- } ;
656-
657- let call_set: & [ TransactionIdentifier ] = if is_mechanism {
658- mechanism_calls. as_slice ( )
659- } else {
660- subnet_calls. as_slice ( )
594+ let usage = RateLimitUsageKey :: SubnetNeuron {
595+ netuid,
596+ uid : uid_u16,
661597 } ;
662598
663- for call in call_set {
599+ for call in & subnet_calls {
664600 record_last_seen_entry :: < T > (
665601 entries,
666602 grouping. usage_target ( * call) ,
@@ -743,8 +679,7 @@ fn import_evm_entries<T: SubtensorConfig>(
743679
744680fn convert_target < T > ( target : & RateLimitTarget < GroupId > ) -> RateLimitTarget < GroupIdOf < T > >
745681where
746- T : SubtensorConfig
747- + pallet_rate_limiting:: Config < LimitScope = RateLimitScope , GroupId = GroupId > ,
682+ T : SubtensorConfig + pallet_rate_limiting:: Config < LimitScope = NetUid , GroupId = GroupId > ,
748683 RateLimitUsageKey < T :: AccountId > : Into < <T as pallet_rate_limiting:: Config >:: UsageKey > ,
749684{
750685 match target {
@@ -755,8 +690,7 @@ where
755690
756691fn write_limits < T > ( limits : & LimitEntries < T > ) -> u64
757692where
758- T : SubtensorConfig
759- + pallet_rate_limiting:: Config < LimitScope = RateLimitScope , GroupId = GroupId > ,
693+ T : SubtensorConfig + pallet_rate_limiting:: Config < LimitScope = NetUid , GroupId = GroupId > ,
760694 RateLimitUsageKey < T :: AccountId > : Into < <T as pallet_rate_limiting:: Config >:: UsageKey > ,
761695{
762696 let mut writes: u64 = 0 ;
@@ -770,8 +704,7 @@ where
770704
771705fn write_last_seen < T > ( entries : & LastSeenEntries < T > ) -> u64
772706where
773- T : SubtensorConfig
774- + pallet_rate_limiting:: Config < LimitScope = RateLimitScope , GroupId = GroupId > ,
707+ T : SubtensorConfig + pallet_rate_limiting:: Config < LimitScope = NetUid , GroupId = GroupId > ,
775708 RateLimitUsageKey < T :: AccountId > : Into < <T as pallet_rate_limiting:: Config >:: UsageKey > ,
776709{
777710 let mut writes: u64 = 0 ;
@@ -786,8 +719,7 @@ where
786719
787720fn write_groups < T > ( grouping : & Grouping ) -> u64
788721where
789- T : SubtensorConfig
790- + pallet_rate_limiting:: Config < LimitScope = RateLimitScope , GroupId = GroupId > ,
722+ T : SubtensorConfig + pallet_rate_limiting:: Config < LimitScope = NetUid , GroupId = GroupId > ,
791723 RateLimitUsageKey < T :: AccountId > : Into < <T as pallet_rate_limiting:: Config >:: UsageKey > ,
792724{
793725 let mut writes: u64 = 0 ;
@@ -860,7 +792,7 @@ fn set_global_limit<T: SubtensorConfig>(
860792fn set_scoped_limit < T : SubtensorConfig > (
861793 limits : & mut LimitEntries < T > ,
862794 target : RateLimitTarget < GroupId > ,
863- scope : RateLimitScope ,
795+ scope : NetUid ,
864796 span : BlockNumberFor < T > ,
865797) {
866798 if let Some ( ( _, config) ) = limits. iter_mut ( ) . find ( |( id, _) | * id == target) {
@@ -905,8 +837,7 @@ pub struct Migration<T: SubtensorConfig>(PhantomData<T>);
905837
906838impl < T > frame_support:: traits:: OnRuntimeUpgrade for Migration < T >
907839where
908- T : SubtensorConfig
909- + pallet_rate_limiting:: Config < LimitScope = RateLimitScope , GroupId = GroupId > ,
840+ T : SubtensorConfig + pallet_rate_limiting:: Config < LimitScope = NetUid , GroupId = GroupId > ,
910841 RateLimitUsageKey < T :: AccountId > : Into < <T as pallet_rate_limiting:: Config >:: UsageKey > ,
911842{
912843 fn on_runtime_upgrade ( ) -> Weight {
0 commit comments