Skip to content

Commit 2af7993

Browse files
committed
Merge remote-tracking branch 'origin/testnet' into devnet-ready
2 parents 6326a1a + e1feb05 commit 2af7993

File tree

6 files changed

+419
-21
lines changed

6 files changed

+419
-21
lines changed

pallets/subtensor/src/benchmarks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,7 @@ mod pallet_benchmarks {
16191619
netuid,
16201620
AlphaCurrency::ZERO,
16211621
pending_root_alpha.into(),
1622+
pending_root_alpha.into(), // alpha out
16221623
AlphaCurrency::ZERO,
16231624
);
16241625

pallets/subtensor/src/coinbase/root.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ impl<T: Config> Pallet<T> {
348348
RAORecycledForRegistration::<T>::remove(netuid);
349349
MaxRegistrationsPerBlock::<T>::remove(netuid);
350350
WeightsVersionKey::<T>::remove(netuid);
351-
PendingRootAlphaDivs::<T>::remove(netuid);
352351

353352
// --- 17. Subtoken / feature flags.
354353
LiquidAlphaOn::<T>::remove(netuid);

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,21 @@ impl<T: Config> Pallet<T> {
6969
if price_i < tao_in_ratio {
7070
tao_in_i = price_i.saturating_mul(U96F32::saturating_from_num(block_emission));
7171
alpha_in_i = block_emission;
72-
let difference_tao: U96F32 = default_tao_in_i.saturating_sub(tao_in_i);
72+
let difference_tao: TaoCurrency =
73+
tou64!(default_tao_in_i.saturating_sub(tao_in_i)).into();
74+
TotalIssuance::<T>::mutate(|total| {
75+
*total = total.saturating_add(difference_tao);
76+
});
7377
// Difference becomes buy.
7478
let buy_swap_result = Self::swap_tao_for_alpha(
7579
*netuid_i,
76-
tou64!(difference_tao).into(),
80+
difference_tao,
7781
T::SwapInterface::max_price(),
7882
true,
7983
);
8084
if let Ok(buy_swap_result_ok) = buy_swap_result {
8185
let bought_alpha = AlphaCurrency::from(buy_swap_result_ok.amount_paid_out);
82-
SubnetAlphaOut::<T>::mutate(*netuid_i, |total| {
83-
*total = total.saturating_sub(bought_alpha);
84-
});
86+
Self::recycle_subnet_alpha(*netuid_i, bought_alpha);
8587
}
8688
is_subsidized.insert(*netuid_i, true);
8789
} else {
@@ -106,6 +108,7 @@ impl<T: Config> Pallet<T> {
106108
alpha_in.insert(*netuid_i, alpha_in_i);
107109
alpha_out.insert(*netuid_i, alpha_out_i);
108110
}
111+
log::debug!("is_subsidized: {is_subsidized:?}");
109112
log::debug!("tao_in: {tao_in:?}");
110113
log::debug!("alpha_in: {alpha_in:?}");
111114
log::debug!("alpha_out: {alpha_out:?}");
@@ -189,21 +192,23 @@ impl<T: Config> Pallet<T> {
189192
.unwrap_or(asfloat!(0.0));
190193
log::debug!("root_proportion: {root_proportion:?}");
191194
// Get root proportion of alpha_out dividends.
192-
let root_alpha: U96F32 = root_proportion
193-
.saturating_mul(alpha_out_i) // Total alpha emission per block remaining.
194-
.saturating_mul(asfloat!(0.5)); // 50% to validators.
195-
// Remove root alpha from alpha_out.
196-
log::debug!("root_alpha: {root_alpha:?}");
197-
// Get pending alpha as original alpha_out - root_alpha.
198-
let pending_alpha: U96F32 = alpha_out_i.saturating_sub(root_alpha);
199-
log::debug!("pending_alpha: {pending_alpha:?}");
200-
195+
let mut root_alpha: U96F32 = asfloat!(0.0);
201196
let subsidized: bool = *is_subsidized.get(netuid_i).unwrap_or(&false);
202197
if !subsidized {
198+
// Only give root alpha if not being subsidized.
199+
root_alpha = root_proportion
200+
.saturating_mul(alpha_out_i) // Total alpha emission per block remaining.
201+
.saturating_mul(asfloat!(0.5)); // 50% to validators.
203202
PendingRootAlphaDivs::<T>::mutate(*netuid_i, |total| {
204203
*total = total.saturating_add(tou64!(root_alpha).into());
205204
});
206205
}
206+
// Remove root alpha from alpha_out.
207+
log::debug!("root_alpha: {root_alpha:?}");
208+
209+
// Get pending alpha as original alpha_out - root_alpha.
210+
let pending_alpha: U96F32 = alpha_out_i.saturating_sub(root_alpha);
211+
log::debug!("pending_alpha: {pending_alpha:?}");
207212

208213
// Accumulate alpha emission in pending.
209214
PendingEmission::<T>::mutate(*netuid_i, |total| {
@@ -246,7 +251,13 @@ impl<T: Config> Pallet<T> {
246251
PendingOwnerCut::<T>::insert(netuid, AlphaCurrency::ZERO);
247252

248253
// Drain pending root alpha divs, alpha emission, and owner cut.
249-
Self::drain_pending_emission(netuid, pending_alpha, pending_root_alpha, owner_cut);
254+
Self::drain_pending_emission(
255+
netuid,
256+
pending_alpha,
257+
pending_root_alpha,
258+
pending_alpha.saturating_add(pending_root_alpha),
259+
owner_cut,
260+
);
250261
} else {
251262
// Increment
252263
BlocksSinceLastStep::<T>::mutate(netuid, |total| *total = total.saturating_add(1));
@@ -482,6 +493,7 @@ impl<T: Config> Pallet<T> {
482493
let destination = maybe_dest.clone().unwrap_or(hotkey.clone());
483494

484495
if let Some(dest) = maybe_dest {
496+
log::debug!("incentives: auto staking {incentive:?} to {dest:?}");
485497
Self::deposit_event(Event::<T>::AutoStakeAdded {
486498
netuid,
487499
destination: dest,
@@ -490,6 +502,9 @@ impl<T: Config> Pallet<T> {
490502
incentive,
491503
});
492504
}
505+
log::debug!(
506+
"incentives: increasing stake for {hotkey:?} to {incentive:?} with owner {owner:?}"
507+
);
493508
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
494509
&destination,
495510
&owner,
@@ -604,6 +619,7 @@ impl<T: Config> Pallet<T> {
604619
netuid: NetUid,
605620
pending_alpha: AlphaCurrency,
606621
pending_root_alpha: AlphaCurrency,
622+
total_alpha: AlphaCurrency,
607623
owner_cut: AlphaCurrency,
608624
) {
609625
log::debug!(
@@ -614,7 +630,7 @@ impl<T: Config> Pallet<T> {
614630

615631
// Run the epoch.
616632
let hotkey_emission: Vec<(T::AccountId, AlphaCurrency, AlphaCurrency)> =
617-
Self::epoch_with_mechanisms(netuid, pending_alpha.saturating_add(pending_root_alpha));
633+
Self::epoch_with_mechanisms(netuid, total_alpha);
618634
log::debug!("hotkey_emission: {hotkey_emission:?}");
619635

620636
// Compute the pending validator alpha.
@@ -630,8 +646,7 @@ impl<T: Config> Pallet<T> {
630646
log::debug!("incentive_sum: {incentive_sum:?}");
631647

632648
let pending_validator_alpha = if !incentive_sum.is_zero() {
633-
pending_alpha
634-
.saturating_add(pending_root_alpha)
649+
total_alpha
635650
.saturating_div(2.into())
636651
.saturating_sub(pending_root_alpha)
637652
} else {

pallets/subtensor/src/tests/claim_root.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ fn test_claim_root_with_drain_emissions() {
7676
netuid,
7777
AlphaCurrency::ZERO,
7878
pending_root_alpha.into(),
79+
pending_root_alpha.into(), // alpha out
7980
AlphaCurrency::ZERO,
8081
);
8182

@@ -144,6 +145,7 @@ fn test_claim_root_with_drain_emissions() {
144145
netuid,
145146
AlphaCurrency::ZERO,
146147
pending_root_alpha.into(),
148+
pending_root_alpha.into(), // alpha out
147149
AlphaCurrency::ZERO,
148150
);
149151

@@ -245,6 +247,7 @@ fn test_claim_root_adding_stake_proportionally_for_two_stakers() {
245247
netuid,
246248
AlphaCurrency::ZERO,
247249
pending_root_alpha.into(),
250+
pending_root_alpha.into(), // alpha out
248251
AlphaCurrency::ZERO,
249252
);
250253

@@ -346,6 +349,7 @@ fn test_claim_root_adding_stake_disproportionally_for_two_stakers() {
346349
netuid,
347350
AlphaCurrency::ZERO,
348351
pending_root_alpha.into(),
352+
pending_root_alpha.into(), // alpha out
349353
AlphaCurrency::ZERO,
350354
);
351355

@@ -437,6 +441,7 @@ fn test_claim_root_with_changed_stake() {
437441
netuid,
438442
AlphaCurrency::ZERO,
439443
pending_root_alpha.into(),
444+
pending_root_alpha.into(), // alpha out
440445
AlphaCurrency::ZERO,
441446
);
442447

@@ -489,6 +494,7 @@ fn test_claim_root_with_changed_stake() {
489494
netuid,
490495
AlphaCurrency::ZERO,
491496
pending_root_alpha.into(),
497+
pending_root_alpha.into(), // alpha out
492498
AlphaCurrency::ZERO,
493499
);
494500

@@ -542,6 +548,7 @@ fn test_claim_root_with_changed_stake() {
542548
netuid,
543549
AlphaCurrency::ZERO,
544550
pending_root_alpha.into(),
551+
pending_root_alpha.into(), // alpha out
545552
AlphaCurrency::ZERO,
546553
);
547554

@@ -634,6 +641,7 @@ fn test_claim_root_with_drain_emissions_and_swap_claim_type() {
634641
netuid,
635642
AlphaCurrency::ZERO,
636643
pending_root_alpha.into(),
644+
pending_root_alpha.into(), // alpha out
637645
AlphaCurrency::ZERO,
638646
);
639647

@@ -678,6 +686,7 @@ fn test_claim_root_with_drain_emissions_and_swap_claim_type() {
678686
netuid,
679687
AlphaCurrency::ZERO,
680688
pending_root_alpha.into(),
689+
pending_root_alpha.into(), // alpha out
681690
AlphaCurrency::ZERO,
682691
);
683692

@@ -714,6 +723,7 @@ fn test_claim_root_with_drain_emissions_and_swap_claim_type() {
714723
netuid,
715724
AlphaCurrency::ZERO,
716725
pending_root_alpha.into(),
726+
pending_root_alpha.into(), // alpha out
717727
AlphaCurrency::ZERO,
718728
);
719729

@@ -1100,6 +1110,7 @@ fn test_claim_root_with_swap_coldkey() {
11001110
netuid,
11011111
AlphaCurrency::ZERO,
11021112
pending_root_alpha.into(),
1113+
pending_root_alpha.into(), // alpha out
11031114
AlphaCurrency::ZERO,
11041115
);
11051116

@@ -1190,6 +1201,7 @@ fn test_claim_root_with_swap_hotkey() {
11901201
netuid,
11911202
AlphaCurrency::ZERO,
11921203
pending_root_alpha.into(),
1204+
pending_root_alpha.into(), // alpha out
11931205
AlphaCurrency::ZERO,
11941206
);
11951207

@@ -1306,6 +1318,7 @@ fn test_claim_root_on_network_deregistration() {
13061318
netuid,
13071319
AlphaCurrency::ZERO,
13081320
pending_root_alpha.into(),
1321+
pending_root_alpha.into(), // alpha out
13091322
AlphaCurrency::ZERO,
13101323
);
13111324

@@ -1446,6 +1459,7 @@ fn test_claim_root_with_unrelated_subnets() {
14461459
netuid,
14471460
AlphaCurrency::ZERO,
14481461
pending_root_alpha.into(),
1462+
pending_root_alpha.into(), // alpha out
14491463
AlphaCurrency::ZERO,
14501464
);
14511465

0 commit comments

Comments
 (0)