@@ -1309,9 +1309,17 @@ pub mod pallet {
13091309 }
13101310
13111311 /// Is the caller allowed to set weights
1312- pub fn check_weights_min_stake ( hotkey : & T :: AccountId ) -> bool {
1312+ pub fn check_weights_min_stake ( hotkey : & T :: AccountId , netuid : u16 ) -> bool {
1313+ let parent_stake = Self :: get_total_stake_for_hotkey ( hotkey) ;
1314+ let total_stake = ChildKeys :: < T > :: get ( hotkey, netuid) . into_iter ( ) . fold (
1315+ parent_stake,
1316+ |acc, ( _, child_key) | {
1317+ let child_stake = Self :: get_total_stake_for_hotkey ( & child_key) ;
1318+ acc. saturating_add ( child_stake)
1319+ } ,
1320+ ) ;
13131321 // Blacklist weights transactions for low stake peers.
1314- Self :: get_total_stake_for_hotkey ( hotkey ) >= Self :: get_weights_min_stake ( )
1322+ total_stake >= Self :: get_weights_min_stake ( )
13151323 }
13161324
13171325 /// Helper function to check if register is allowed
@@ -1404,8 +1412,8 @@ where
14041412 Pallet :: < T > :: get_priority_set_weights ( who, netuid)
14051413 }
14061414
1407- pub fn check_weights_min_stake ( who : & T :: AccountId ) -> bool {
1408- Pallet :: < T > :: check_weights_min_stake ( who)
1415+ pub fn check_weights_min_stake ( who : & T :: AccountId , netuid : u16 ) -> bool {
1416+ Pallet :: < T > :: check_weights_min_stake ( who, netuid )
14091417 }
14101418}
14111419
@@ -1443,7 +1451,7 @@ where
14431451 ) -> TransactionValidity {
14441452 match call. is_sub_type ( ) {
14451453 Some ( Call :: commit_weights { netuid, .. } ) => {
1446- if Self :: check_weights_min_stake ( who) {
1454+ if Self :: check_weights_min_stake ( who, * netuid ) {
14471455 let priority: u64 = Self :: get_priority_set_weights ( who, * netuid) ;
14481456 Ok ( ValidTransaction {
14491457 priority,
@@ -1455,7 +1463,7 @@ where
14551463 }
14561464 }
14571465 Some ( Call :: reveal_weights { netuid, .. } ) => {
1458- if Self :: check_weights_min_stake ( who) {
1466+ if Self :: check_weights_min_stake ( who, * netuid ) {
14591467 let priority: u64 = Self :: get_priority_set_weights ( who, * netuid) ;
14601468 Ok ( ValidTransaction {
14611469 priority,
@@ -1467,7 +1475,7 @@ where
14671475 }
14681476 }
14691477 Some ( Call :: batch_reveal_weights { netuid, .. } ) => {
1470- if Self :: check_weights_min_stake ( who) {
1478+ if Self :: check_weights_min_stake ( who, * netuid ) {
14711479 let priority: u64 = Self :: get_priority_set_weights ( who, * netuid) ;
14721480 Ok ( ValidTransaction {
14731481 priority,
@@ -1479,7 +1487,7 @@ where
14791487 }
14801488 }
14811489 Some ( Call :: set_weights { netuid, .. } ) => {
1482- if Self :: check_weights_min_stake ( who) {
1490+ if Self :: check_weights_min_stake ( who, * netuid ) {
14831491 let priority: u64 = Self :: get_priority_set_weights ( who, * netuid) ;
14841492 Ok ( ValidTransaction {
14851493 priority,
@@ -1491,7 +1499,7 @@ where
14911499 }
14921500 }
14931501 Some ( Call :: set_root_weights { netuid, hotkey, .. } ) => {
1494- if Self :: check_weights_min_stake ( hotkey) {
1502+ if Self :: check_weights_min_stake ( hotkey, * netuid ) {
14951503 let priority: u64 = Self :: get_priority_set_weights ( hotkey, * netuid) ;
14961504 Ok ( ValidTransaction {
14971505 priority,
0 commit comments