@@ -124,6 +124,11 @@ impl<T: Config> Pallet<T> {
124124 let mut alpha_in: BTreeMap < NetUid , U96F32 > = BTreeMap :: new ( ) ;
125125 let mut alpha_out: BTreeMap < NetUid , U96F32 > = BTreeMap :: new ( ) ;
126126 let mut excess_tao: BTreeMap < NetUid , U96F32 > = BTreeMap :: new ( ) ;
127+ let tao_block_emission: U96F32 = U96F32 :: saturating_from_num (
128+ Self :: get_block_emission ( )
129+ . unwrap_or ( TaoCurrency :: ZERO )
130+ . to_u64 ( ) ,
131+ ) ;
127132
128133 // Only calculate for subnets that we are emitting to.
129134 for ( & netuid_i, & tao_emission_i) in subnet_emissions. iter ( ) {
@@ -142,8 +147,9 @@ impl<T: Config> Pallet<T> {
142147 let alpha_out_i: U96F32 = alpha_emission_i;
143148 let mut alpha_in_i: U96F32 = tao_emission_i. safe_div_or ( price_i, U96F32 :: from_num ( 0.0 ) ) ;
144149
145- if alpha_in_i > alpha_emission_i {
146- alpha_in_i = alpha_emission_i;
150+ let alpha_injection_cap: U96F32 = alpha_emission_i. min ( tao_block_emission) ;
151+ if alpha_in_i > alpha_injection_cap {
152+ alpha_in_i = alpha_injection_cap;
147153 tao_in_i = alpha_in_i. saturating_mul ( price_i) ;
148154 }
149155
@@ -178,13 +184,6 @@ impl<T: Config> Pallet<T> {
178184 // --- 3. Inject ALPHA for participants.
179185 let cut_percent: U96F32 = Self :: get_float_subnet_owner_cut ( ) ;
180186
181- // Get total TAO on root.
182- let root_tao: U96F32 = asfloat ! ( SubnetTAO :: <T >:: get( NetUid :: ROOT ) ) ;
183- log:: debug!( "root_tao: {root_tao:?}" ) ;
184- // Get tao_weight
185- let tao_weight: U96F32 = root_tao. saturating_mul ( Self :: get_tao_weight ( ) ) ;
186- log:: debug!( "tao_weight: {tao_weight:?}" ) ;
187-
188187 for netuid_i in subnets_to_emit_to. iter ( ) {
189188 // Get alpha_out for this block.
190189 let mut alpha_out_i: U96F32 = * alpha_out. get ( netuid_i) . unwrap_or ( & asfloat ! ( 0 ) ) ;
@@ -205,14 +204,8 @@ impl<T: Config> Pallet<T> {
205204 * total = total. saturating_add ( tou64 ! ( owner_cut_i) . into ( ) ) ;
206205 } ) ;
207206
208- // Get ALPHA issuance.
209- let alpha_issuance: U96F32 = asfloat ! ( Self :: get_alpha_issuance( * netuid_i) ) ;
210- log:: debug!( "alpha_issuance: {alpha_issuance:?}" ) ;
211-
212207 // Get root proportional dividends.
213- let root_proportion: U96F32 = tao_weight
214- . checked_div ( tao_weight. saturating_add ( alpha_issuance) )
215- . unwrap_or ( asfloat ! ( 0.0 ) ) ;
208+ let root_proportion = Self :: root_proportion ( * netuid_i) ;
216209 log:: debug!( "root_proportion: {root_proportion:?}" ) ;
217210
218211 // Get root alpha from root prop.
@@ -498,10 +491,11 @@ impl<T: Config> Pallet<T> {
498491
499492 // Insert subnet owner hotkey in the beginning of the list if valid and not
500493 // already present
501- if let Ok ( owner_hk) = SubnetOwnerHotkey :: < T > :: try_get ( netuid) {
502- if Uids :: < T > :: get ( netuid, & owner_hk) . is_some ( ) && !owner_hotkeys. contains ( & owner_hk) {
503- owner_hotkeys. insert ( 0 , owner_hk) ;
504- }
494+ if let Ok ( owner_hk) = SubnetOwnerHotkey :: < T > :: try_get ( netuid)
495+ && Uids :: < T > :: get ( netuid, & owner_hk) . is_some ( )
496+ && !owner_hotkeys. contains ( & owner_hk)
497+ {
498+ owner_hotkeys. insert ( 0 , owner_hk) ;
505499 }
506500
507501 owner_hotkeys
@@ -515,22 +509,22 @@ impl<T: Config> Pallet<T> {
515509 root_alpha_dividends : BTreeMap < T :: AccountId , U96F32 > ,
516510 ) {
517511 // Distribute the owner cut.
518- if let Ok ( owner_coldkey) = SubnetOwner :: < T > :: try_get ( netuid) {
519- if let Ok ( owner_hotkey) = SubnetOwnerHotkey :: < T > :: try_get ( netuid) {
520- // Increase stake for owner hotkey and coldkey.
521- log :: debug! (
522- "owner_hotkey: {owner_hotkey:?} owner_coldkey: {owner_coldkey:?}, owner_cut: {owner_cut:?}"
523- ) ;
524- let real_owner_cut = Self :: increase_stake_for_hotkey_and_coldkey_on_subnet (
525- & owner_hotkey ,
526- & owner_coldkey ,
527- netuid ,
528- owner_cut ,
529- ) ;
530- // If the subnet is leased, notify the lease logic that owner cut has been distributed.
531- if let Some ( lease_id ) = SubnetUidToLeaseId :: < T > :: get ( netuid ) {
532- Self :: distribute_leased_network_dividends ( lease_id , real_owner_cut ) ;
533- }
512+ if let Ok ( owner_coldkey) = SubnetOwner :: < T > :: try_get ( netuid)
513+ && let Ok ( owner_hotkey) = SubnetOwnerHotkey :: < T > :: try_get ( netuid)
514+ {
515+ // Increase stake for owner hotkey and coldkey.
516+ log :: debug! (
517+ "owner_hotkey: {owner_hotkey:?} owner_coldkey: {owner_coldkey:?}, owner_cut: {owner_cut:?}"
518+ ) ;
519+ let real_owner_cut = Self :: increase_stake_for_hotkey_and_coldkey_on_subnet (
520+ & owner_hotkey ,
521+ & owner_coldkey ,
522+ netuid ,
523+ owner_cut ,
524+ ) ;
525+ // If the subnet is leased, notify the lease logic that owner cut has been distributed.
526+ if let Some ( lease_id ) = SubnetUidToLeaseId :: < T > :: get ( netuid ) {
527+ Self :: distribute_leased_network_dividends ( lease_id , real_owner_cut ) ;
534528 }
535529 }
536530
0 commit comments