Skip to content
1 change: 1 addition & 0 deletions pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,7 @@ mod pallet_benchmarks {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down
1 change: 0 additions & 1 deletion pallets/subtensor/src/coinbase/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ impl<T: Config> Pallet<T> {
RAORecycledForRegistration::<T>::remove(netuid);
MaxRegistrationsPerBlock::<T>::remove(netuid);
WeightsVersionKey::<T>::remove(netuid);
PendingRootAlphaDivs::<T>::remove(netuid);

// --- 17. Subtoken / feature flags.
LiquidAlphaOn::<T>::remove(netuid);
Expand Down
51 changes: 33 additions & 18 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,21 @@ impl<T: Config> Pallet<T> {
if price_i < tao_in_ratio {
tao_in_i = price_i.saturating_mul(U96F32::saturating_from_num(block_emission));
alpha_in_i = block_emission;
let difference_tao: U96F32 = default_tao_in_i.saturating_sub(tao_in_i);
let difference_tao: TaoCurrency =
tou64!(default_tao_in_i.saturating_sub(tao_in_i)).into();
TotalIssuance::<T>::mutate(|total| {
*total = total.saturating_add(difference_tao);
});
// Difference becomes buy.
let buy_swap_result = Self::swap_tao_for_alpha(
*netuid_i,
tou64!(difference_tao).into(),
difference_tao,
T::SwapInterface::max_price(),
true,
);
if let Ok(buy_swap_result_ok) = buy_swap_result {
let bought_alpha = AlphaCurrency::from(buy_swap_result_ok.amount_paid_out);
SubnetAlphaOut::<T>::mutate(*netuid_i, |total| {
*total = total.saturating_sub(bought_alpha);
});
Self::recycle_subnet_alpha(*netuid_i, bought_alpha);
}
is_subsidized.insert(*netuid_i, true);
} else {
Expand All @@ -106,6 +108,7 @@ impl<T: Config> Pallet<T> {
alpha_in.insert(*netuid_i, alpha_in_i);
alpha_out.insert(*netuid_i, alpha_out_i);
}
log::debug!("is_subsidized: {is_subsidized:?}");
log::debug!("tao_in: {tao_in:?}");
log::debug!("alpha_in: {alpha_in:?}");
log::debug!("alpha_out: {alpha_out:?}");
Expand Down Expand Up @@ -189,21 +192,23 @@ impl<T: Config> Pallet<T> {
.unwrap_or(asfloat!(0.0));
log::debug!("root_proportion: {root_proportion:?}");
// Get root proportion of alpha_out dividends.
let root_alpha: U96F32 = root_proportion
.saturating_mul(alpha_out_i) // Total alpha emission per block remaining.
.saturating_mul(asfloat!(0.5)); // 50% to validators.
// Remove root alpha from alpha_out.
log::debug!("root_alpha: {root_alpha:?}");
// Get pending alpha as original alpha_out - root_alpha.
let pending_alpha: U96F32 = alpha_out_i.saturating_sub(root_alpha);
log::debug!("pending_alpha: {pending_alpha:?}");

let mut root_alpha: U96F32 = asfloat!(0.0);
let subsidized: bool = *is_subsidized.get(netuid_i).unwrap_or(&false);
if !subsidized {
// Only give root alpha if not being subsidized.
root_alpha = root_proportion
.saturating_mul(alpha_out_i) // Total alpha emission per block remaining.
.saturating_mul(asfloat!(0.5)); // 50% to validators.
PendingRootAlphaDivs::<T>::mutate(*netuid_i, |total| {
*total = total.saturating_add(tou64!(root_alpha).into());
});
}
// Remove root alpha from alpha_out.
log::debug!("root_alpha: {root_alpha:?}");

// Get pending alpha as original alpha_out - root_alpha.
let pending_alpha: U96F32 = alpha_out_i.saturating_sub(root_alpha);
log::debug!("pending_alpha: {pending_alpha:?}");

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

// Drain pending root alpha divs, alpha emission, and owner cut.
Self::drain_pending_emission(netuid, pending_alpha, pending_root_alpha, owner_cut);
Self::drain_pending_emission(
netuid,
pending_alpha,
pending_root_alpha,
pending_alpha.saturating_add(pending_root_alpha),
owner_cut,
);
} else {
// Increment
BlocksSinceLastStep::<T>::mutate(netuid, |total| *total = total.saturating_add(1));
Expand Down Expand Up @@ -482,6 +493,7 @@ impl<T: Config> Pallet<T> {
let destination = maybe_dest.clone().unwrap_or(hotkey.clone());

if let Some(dest) = maybe_dest {
log::debug!("incentives: auto staking {incentive:?} to {dest:?}");
Self::deposit_event(Event::<T>::AutoStakeAdded {
netuid,
destination: dest,
Expand All @@ -490,6 +502,9 @@ impl<T: Config> Pallet<T> {
incentive,
});
}
log::debug!(
"incentives: increasing stake for {hotkey:?} to {incentive:?} with owner {owner:?}"
);
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
&destination,
&owner,
Expand Down Expand Up @@ -604,6 +619,7 @@ impl<T: Config> Pallet<T> {
netuid: NetUid,
pending_alpha: AlphaCurrency,
pending_root_alpha: AlphaCurrency,
total_alpha: AlphaCurrency,
owner_cut: AlphaCurrency,
) {
log::debug!(
Expand All @@ -614,7 +630,7 @@ impl<T: Config> Pallet<T> {

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

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

let pending_validator_alpha = if !incentive_sum.is_zero() {
pending_alpha
.saturating_add(pending_root_alpha)
total_alpha
.saturating_div(2.into())
.saturating_sub(pending_root_alpha)
} else {
Expand Down
14 changes: 14 additions & 0 deletions pallets/subtensor/src/tests/claim_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn test_claim_root_with_drain_emissions() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -144,6 +145,7 @@ fn test_claim_root_with_drain_emissions() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -245,6 +247,7 @@ fn test_claim_root_adding_stake_proportionally_for_two_stakers() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -346,6 +349,7 @@ fn test_claim_root_adding_stake_disproportionally_for_two_stakers() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -437,6 +441,7 @@ fn test_claim_root_with_changed_stake() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -489,6 +494,7 @@ fn test_claim_root_with_changed_stake() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -542,6 +548,7 @@ fn test_claim_root_with_changed_stake() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -634,6 +641,7 @@ fn test_claim_root_with_drain_emissions_and_swap_claim_type() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -678,6 +686,7 @@ fn test_claim_root_with_drain_emissions_and_swap_claim_type() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -714,6 +723,7 @@ fn test_claim_root_with_drain_emissions_and_swap_claim_type() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -1100,6 +1110,7 @@ fn test_claim_root_with_swap_coldkey() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -1190,6 +1201,7 @@ fn test_claim_root_with_swap_hotkey() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -1306,6 +1318,7 @@ fn test_claim_root_on_network_deregistration() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down Expand Up @@ -1446,6 +1459,7 @@ fn test_claim_root_with_unrelated_subnets() {
netuid,
AlphaCurrency::ZERO,
pending_root_alpha.into(),
pending_root_alpha.into(), // alpha out
AlphaCurrency::ZERO,
);

Expand Down
Loading
Loading