@@ -195,37 +195,48 @@ impl<T: Config> Pallet<T> {
195195 let alpha_out_i: U96F32 = * alpha_out. get ( netuid_i) . unwrap_or ( & asfloat ! ( 0.0 ) ) ;
196196 log:: debug!( "alpha_out_i: {alpha_out_i:?}" ) ;
197197
198- // Get root proportion of alpha_out dividends.
199- let mut root_alpha: U96F32 = asfloat ! ( 0.0 ) ;
198+ // Get ALPHA issuance.
199+ let alpha_issuance: U96F32 = asfloat ! ( Self :: get_alpha_issuance( * netuid_i) ) ;
200+ log:: debug!( "alpha_issuance: {alpha_issuance:?}" ) ;
201+
202+ // Get root proportional dividends.
203+ let root_proportion: U96F32 = tao_weight
204+ . checked_div ( tao_weight. saturating_add ( alpha_issuance) )
205+ . unwrap_or ( asfloat ! ( 0.0 ) ) ;
206+ log:: debug!( "root_proportion: {root_proportion:?}" ) ;
207+
208+ // Get root alpha from root prop.
209+ let root_alpha: U96F32 = root_proportion
210+ . saturating_mul ( alpha_out_i) // Total alpha emission per block remaining.
211+ . saturating_mul ( asfloat ! ( 0.5 ) ) ; // 50% to validators.
212+ log:: debug!( "root_alpha: {root_alpha:?}" ) ;
213+
200214 if root_sell_flag {
201- // Get ALPHA issuance.
202- let alpha_issuance: U96F32 = asfloat ! ( Self :: get_alpha_issuance( * netuid_i) ) ;
203- log:: debug!( "alpha_issuance: {alpha_issuance:?}" ) ;
204-
205- // Get root proportional dividends.
206- let root_proportion: U96F32 = tao_weight
207- . checked_div ( tao_weight. saturating_add ( alpha_issuance) )
208- . unwrap_or ( asfloat ! ( 0.0 ) ) ;
209- log:: debug!( "root_proportion: {root_proportion:?}" ) ;
210-
211- // Get root alpha from root prop.
212- root_alpha = root_proportion
213- . saturating_mul ( alpha_out_i) // Total alpha emission per block remaining.
214- . saturating_mul ( asfloat ! ( 0.5 ) ) ; // 50% to validators.
215+ // Only accumulate root alpha divs if root sell is allowed.
215216 PendingRootAlphaDivs :: < T > :: mutate ( * netuid_i, |total| {
216217 * total = total. saturating_add ( tou64 ! ( root_alpha) . into ( ) ) ;
217218 } ) ;
219+ } else {
220+ // If we are not selling the root alpha, we should recycle it.
221+ Self :: recycle_subnet_alpha ( * netuid_i, AlphaCurrency :: from ( tou64 ! ( root_alpha) ) ) ;
218222 }
219- // Remove root alpha from alpha_out.
220- log:: debug!( "root_alpha: {root_alpha:?}" ) ;
221223
222- // Get pending alpha as original alpha_out - root_alpha.
223- let pending_alpha: U96F32 = alpha_out_i. saturating_sub ( root_alpha) ;
224- log:: debug!( "pending_alpha: {pending_alpha:?}" ) ;
224+ // Get pending server alpha, which is the miner cut of the alpha out.
225+ // Currently miner cut is 50% of the alpha out.
226+ let pending_server_alpha = alpha_out_i. saturating_mul ( asfloat ! ( 0.5 ) ) ;
227+ // The total validator alpha is the remaining alpha out minus the server alpha.
228+ let total_validator_alpha = alpha_out_i. saturating_sub ( pending_server_alpha) ;
225229
226- // Accumulate alpha emission in pending.
227- PendingEmission :: < T > :: mutate ( * netuid_i, |total| {
228- * total = total. saturating_add ( tou64 ! ( pending_alpha) . into ( ) ) ;
230+ // The alpha validators don't get the root alpha.
231+ let pending_validator_alpha = total_validator_alpha. saturating_sub ( root_alpha) ;
232+
233+ // Accumulate the server alpha emission.
234+ PendingServerEmission :: < T > :: mutate ( * netuid_i, |total| {
235+ * total = total. saturating_add ( tou64 ! ( pending_server_alpha) . into ( ) ) ;
236+ } ) ;
237+ // Accumulate the validator alpha emission.
238+ PendingValidatorEmission :: < T > :: mutate ( * netuid_i, |total| {
239+ * total = total. saturating_add ( tou64 ! ( pending_validator_alpha) . into ( ) ) ;
229240 } ) ;
230241 }
231242
@@ -252,8 +263,11 @@ impl<T: Config> Pallet<T> {
252263 LastMechansimStepBlock :: < T > :: insert ( netuid, current_block) ;
253264
254265 // Get and drain the subnet pending emission.
255- let pending_alpha = PendingEmission :: < T > :: get ( netuid) ;
256- PendingEmission :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
266+ let pending_server_alpha = PendingServerEmission :: < T > :: get ( netuid) ;
267+ PendingServerEmission :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
268+
269+ let pending_validator_alpha = PendingValidatorEmission :: < T > :: get ( netuid) ;
270+ PendingValidatorEmission :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
257271
258272 // Get and drain the subnet pending root alpha divs.
259273 let pending_root_alpha = PendingRootAlphaDivs :: < T > :: get ( netuid) ;
@@ -264,7 +278,13 @@ impl<T: Config> Pallet<T> {
264278 PendingOwnerCut :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
265279
266280 // Distribute the emission.
267- Self :: distribute_emission ( netuid, pending_alpha, pending_root_alpha, owner_cut) ;
281+ Self :: distribute_emission (
282+ netuid,
283+ pending_server_alpha,
284+ pending_validator_alpha,
285+ pending_root_alpha,
286+ owner_cut,
287+ ) ;
268288 } else {
269289 // Increment
270290 BlocksSinceLastStep :: < T > :: mutate ( netuid, |total| * total = total. saturating_add ( 1 ) ) ;
@@ -633,20 +653,23 @@ impl<T: Config> Pallet<T> {
633653
634654 pub fn distribute_emission (
635655 netuid : NetUid ,
636- pending_alpha : AlphaCurrency ,
656+ pending_server_alpha : AlphaCurrency ,
657+ pending_validator_alpha : AlphaCurrency ,
637658 pending_root_alpha : AlphaCurrency ,
638- owner_cut : AlphaCurrency ,
659+ pending_owner_cut : AlphaCurrency ,
639660 ) {
640661 log:: debug!(
641- "Draining pending alpha emission for netuid {netuid:?}, pending_alpha : {pending_alpha :?}, pending_root_alpha: {pending_root_alpha:?}, owner_cut : {owner_cut :?}"
662+ "Draining pending alpha emission for netuid {netuid:?}, pending_server_alpha : {pending_server_alpha :?}, pending_validator_alpha: {pending_validator_alpha:?}, pending_root_alpha: {pending_root_alpha:?}, pending_owner_cut : {pending_owner_cut :?}"
642663 ) ;
643664
644665 let tao_weight = Self :: get_tao_weight ( ) ;
645- let total_alpha = pending_alpha. saturating_add ( pending_root_alpha) ;
666+ let total_alpha_minus_owner_cut = pending_server_alpha
667+ . saturating_add ( pending_validator_alpha)
668+ . saturating_add ( pending_root_alpha) ;
646669
647- // Run the epoch.
670+ // Run the epoch, using the alpha going to both the servers and the validators .
648671 let hotkey_emission: Vec < ( T :: AccountId , AlphaCurrency , AlphaCurrency ) > =
649- Self :: epoch_with_mechanisms ( netuid, total_alpha ) ;
672+ Self :: epoch_with_mechanisms ( netuid, total_alpha_minus_owner_cut ) ;
650673 log:: debug!( "hotkey_emission: {hotkey_emission:?}" ) ;
651674
652675 // Compute the pending validator alpha.
@@ -661,20 +684,20 @@ impl<T: Config> Pallet<T> {
661684 } ) ;
662685 log:: debug!( "incentive_sum: {incentive_sum:?}" ) ;
663686
664- let pending_validator_alpha = if !incentive_sum. is_zero ( ) {
665- total_alpha
666- . saturating_div ( 2 . into ( ) )
667- . saturating_sub ( pending_root_alpha)
687+ let validator_alpha = if !incentive_sum. is_zero ( ) {
688+ pending_validator_alpha
668689 } else {
669- // If the incentive is 0, then Validators get 100% of the alpha.
670- pending_alpha
690+ // If the incentive is 0, then Alpha Validators get both the server and validator alpha.
691+ pending_validator_alpha . saturating_add ( pending_server_alpha )
671692 } ;
693+ let root_alpha = pending_root_alpha;
694+ let owner_cut = pending_owner_cut;
672695
673696 let ( incentives, ( alpha_dividends, root_alpha_dividends) ) =
674697 Self :: calculate_dividend_and_incentive_distribution (
675698 netuid,
676- pending_root_alpha ,
677- pending_validator_alpha ,
699+ root_alpha ,
700+ validator_alpha ,
678701 hotkey_emission,
679702 tao_weight,
680703 ) ;
0 commit comments