@@ -212,22 +212,31 @@ impl<T: Config> Pallet<T> {
212212 log:: debug!( "root_alpha: {root_alpha:?}" ) ;
213213
214214 if root_sell_flag {
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 }
219223
220- // Get pending alpha as original alpha_out - root_alpha.
221- let pending_alpha: U96F32 = alpha_out_i. saturating_sub ( root_alpha) ;
222- 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) ;
229+
230+ // The alpha validators don't get the root alpha.
231+ let pending_validator_alpha = total_validator_alpha. saturating_sub ( root_alpha) ;
223232
224- // Accumulate alpha emission in pending .
225- PendingEmission :: < T > :: mutate ( * netuid_i, |total| {
226- * total = total. saturating_add ( tou64 ! ( pending_alpha ) . into ( ) ) ;
233+ // Accumulate the server alpha emission .
234+ PendingServerEmission :: < T > :: mutate ( * netuid_i, |total| {
235+ * total = total. saturating_add ( tou64 ! ( pending_server_alpha ) . into ( ) ) ;
227236 } ) ;
228- // Accumulate total alpha emission, including burned alpha from root prop .
229- TotalEmission :: < T > :: mutate ( * netuid_i, |total| {
230- * total = total. saturating_add ( tou64 ! ( alpha_out_i ) . into ( ) ) ;
237+ // Accumulate the validator alpha emission .
238+ PendingValidatorEmission :: < T > :: mutate ( * netuid_i, |total| {
239+ * total = total. saturating_add ( tou64 ! ( pending_validator_alpha ) . into ( ) ) ;
231240 } ) ;
232241 }
233242
@@ -253,9 +262,29 @@ impl<T: Config> Pallet<T> {
253262 BlocksSinceLastStep :: < T > :: insert ( netuid, 0 ) ;
254263 LastMechansimStepBlock :: < T > :: insert ( netuid, current_block) ;
255264
256- // Get and drain the subnet pending emission.
257- let pending_alpha = PendingEmission :: < T > :: get ( netuid) ;
265+ // Get and drain the PendingEmission.
266+ // deprecated
267+ let pending_emission = PendingEmission :: < T > :: get ( netuid) ;
258268 PendingEmission :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
269+ // If pending_emission is not zero, we split it between the server emission and the validator emission.
270+ if !pending_emission. is_zero ( ) {
271+ let server_alpha = pending_emission. saturating_div ( 2 . into ( ) ) ;
272+ let validator_alpha = pending_emission. saturating_sub ( server_alpha) ;
273+
274+ PendingServerEmission :: < T > :: mutate ( netuid, |total| {
275+ * total = total. saturating_add ( server_alpha)
276+ } ) ;
277+ PendingValidatorEmission :: < T > :: mutate ( netuid, |total| {
278+ * total = total. saturating_add ( validator_alpha)
279+ } ) ;
280+ }
281+
282+ // Get and drain the subnet pending emission.
283+ let pending_server_alpha = PendingServerEmission :: < T > :: get ( netuid) ;
284+ PendingServerEmission :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
285+
286+ let pending_validator_alpha = PendingValidatorEmission :: < T > :: get ( netuid) ;
287+ PendingValidatorEmission :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
259288
260289 // Get and drain the subnet pending root alpha divs.
261290 let pending_root_alpha = PendingRootAlphaDivs :: < T > :: get ( netuid) ;
@@ -265,16 +294,12 @@ impl<T: Config> Pallet<T> {
265294 let owner_cut = PendingOwnerCut :: < T > :: get ( netuid) ;
266295 PendingOwnerCut :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
267296
268- // Get total emission and drain.
269- let total_emission = TotalEmission :: < T > :: get ( netuid) ;
270- TotalEmission :: < T > :: insert ( netuid, AlphaCurrency :: ZERO ) ;
271-
272297 // Distribute the emission.
273298 Self :: distribute_emission (
274299 netuid,
275- pending_alpha,
300+ pending_server_alpha,
301+ pending_validator_alpha,
276302 pending_root_alpha,
277- total_emission,
278303 owner_cut,
279304 ) ;
280305 } else {
@@ -645,20 +670,23 @@ impl<T: Config> Pallet<T> {
645670
646671 pub fn distribute_emission (
647672 netuid : NetUid ,
648- pending_alpha : AlphaCurrency ,
673+ pending_server_alpha : AlphaCurrency ,
674+ pending_validator_alpha : AlphaCurrency ,
649675 pending_root_alpha : AlphaCurrency ,
650- total_alpha : AlphaCurrency ,
651- owner_cut : AlphaCurrency ,
676+ pending_owner_cut : AlphaCurrency ,
652677 ) {
653678 log:: debug!(
654- "Draining pending alpha emission for netuid {netuid:?}, pending_alpha : {pending_alpha :?}, pending_root_alpha: {pending_root_alpha:?}, owner_cut : {owner_cut :?}"
679+ "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 :?}"
655680 ) ;
656681
657682 let tao_weight = Self :: get_tao_weight ( ) ;
683+ let total_alpha_minus_owner_cut = pending_server_alpha
684+ . saturating_add ( pending_validator_alpha)
685+ . saturating_add ( pending_root_alpha) ;
658686
659- // Run the epoch.
687+ // Run the epoch, using the alpha going to both the servers and the validators .
660688 let hotkey_emission: Vec < ( T :: AccountId , AlphaCurrency , AlphaCurrency ) > =
661- Self :: epoch_with_mechanisms ( netuid, total_alpha ) ;
689+ Self :: epoch_with_mechanisms ( netuid, total_alpha_minus_owner_cut ) ;
662690 log:: debug!( "hotkey_emission: {hotkey_emission:?}" ) ;
663691
664692 // Compute the pending validator alpha.
@@ -673,20 +701,20 @@ impl<T: Config> Pallet<T> {
673701 } ) ;
674702 log:: debug!( "incentive_sum: {incentive_sum:?}" ) ;
675703
676- let pending_validator_alpha = if !incentive_sum. is_zero ( ) {
677- total_alpha
678- . saturating_div ( 2 . into ( ) )
679- . saturating_sub ( pending_root_alpha)
704+ let validator_alpha = if !incentive_sum. is_zero ( ) {
705+ pending_validator_alpha
680706 } else {
681- // If the incentive is 0, then Validators get 100% of the alpha .
682- pending_alpha
707+ // If the incentive is 0, then Alpha Validators get .
708+ pending_validator_alpha . saturating_add ( pending_server_alpha )
683709 } ;
710+ let root_alpha = pending_root_alpha;
711+ let owner_cut = pending_owner_cut;
684712
685713 let ( incentives, ( alpha_dividends, root_alpha_dividends) ) =
686714 Self :: calculate_dividend_and_incentive_distribution (
687715 netuid,
688- pending_root_alpha ,
689- pending_validator_alpha ,
716+ root_alpha ,
717+ validator_alpha ,
690718 hotkey_emission,
691719 tao_weight,
692720 ) ;
0 commit comments