Skip to content

Commit d404554

Browse files
committed
post-merge compilation fixes
1 parent f0da041 commit d404554

File tree

6 files changed

+136
-126
lines changed

6 files changed

+136
-126
lines changed

Cargo.lock

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/subtensor/src/coinbase/root.rs

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ impl<T: Config> Pallet<T> {
462462
SubnetVolume::<T>::remove(netuid);
463463
SubnetMovingPrice::<T>::remove(netuid);
464464

465+
// --- 12. Add the balance back to the owner.
466+
SubnetOwner::<T>::remove(netuid);
467+
468+
// --- 13. Remove subnet identity if it exists.
465469
if SubnetIdentitiesV3::<T>::contains_key(netuid) {
466470
SubnetIdentitiesV3::<T>::remove(netuid);
467471
Self::deposit_event(Event::SubnetIdentityRemoved(netuid));
@@ -584,49 +588,54 @@ impl<T: Config> Pallet<T> {
584588

585589
// 2. Basic info.
586590
let owner_coldkey: T::AccountId = SubnetOwner::<T>::get(netuid);
587-
let lock_cost: u64 = Self::get_subnet_locked_balance(netuid);
591+
let lock_cost_u64: u64 = Self::get_subnet_locked_balance(netuid).into();
588592

589593
// Owner-cut already received from emissions.
590-
let total_emission: u64 = Emission::<T>::get(netuid).iter().sum();
594+
let total_emission_u64: u64 = Emission::<T>::get(netuid)
595+
.into_iter()
596+
.map(Into::<u64>::into)
597+
.sum();
591598
let owner_fraction = Self::get_float_subnet_owner_cut();
592-
let owner_received_emission = U96F32::from_num(total_emission)
599+
let owner_received_emission_u64 = U96F32::from_num(total_emission_u64)
593600
.saturating_mul(owner_fraction)
594601
.floor()
595602
.saturating_to_num::<u64>();
596603

597-
// 3. Gather α-out stakers.
598-
let mut total_alpha_out: u128 = 0;
604+
// 3. Gather α-out stakers (U64F64 -> use raw bits as weights).
605+
let mut total_alpha_bits: u128 = 0;
599606
let mut stakers: Vec<(T::AccountId, T::AccountId, u128)> = Vec::new();
600607

601608
for ((hot, cold, this_netuid), alpha) in Alpha::<T>::iter() {
602609
if this_netuid == netuid {
603-
let a = alpha.saturating_to_num::<u128>();
604-
total_alpha_out = total_alpha_out.saturating_add(a);
605-
stakers.push((hot, cold, a));
610+
let a_bits: u128 = alpha.to_bits(); // <- was `alpha.into()`; that doesn't exist
611+
total_alpha_bits = total_alpha_bits.saturating_add(a_bits);
612+
stakers.push((hot, cold, a_bits));
606613
}
607614
}
608615

609-
// 4. Pro-rata distribution – TAO restaked to ROOT.
610-
let subnet_tao: u128 = SubnetTAO::<T>::get(netuid) as u128;
616+
// 4. Prorata distribution – TAO restaked to ROOT.
617+
let subnet_tao_u64: u64 = SubnetTAO::<T>::get(netuid).into();
611618
let root_netuid = NetUid::ROOT;
612619

613-
if total_alpha_out > 0 && subnet_tao > 0 && !stakers.is_empty() {
620+
if total_alpha_bits > 0 && subnet_tao_u64 > 0 && !stakers.is_empty() {
614621
struct Portion<A, C> {
615622
hot: A,
616623
cold: C,
617624
share: u64,
618625
rem: u128,
619626
}
627+
628+
let pot_u128 = subnet_tao_u64 as u128;
620629
let mut portions: Vec<Portion<_, _>> = Vec::with_capacity(stakers.len());
621630
let mut distributed: u128 = 0;
622631

623-
for (hot, cold, a) in &stakers {
624-
let prod = subnet_tao.saturating_mul(*a);
625-
let share_u128 = prod.checked_div(total_alpha_out).unwrap_or_default();
632+
for (hot, cold, a_bits) in &stakers {
633+
let prod = pot_u128.saturating_mul(*a_bits);
634+
let share_u128 = prod.checked_div(total_alpha_bits).unwrap_or_default();
626635
let share_u64 = share_u128.min(u64::MAX as u128) as u64;
627636
distributed = distributed.saturating_add(share_u64 as u128);
628637

629-
let rem = prod.checked_rem(total_alpha_out).unwrap_or_default();
638+
let rem = prod.checked_rem(total_alpha_bits).unwrap_or_default();
630639
portions.push(Portion {
631640
hot: hot.clone(),
632641
cold: cold.clone(),
@@ -635,20 +644,27 @@ impl<T: Config> Pallet<T> {
635644
});
636645
}
637646

638-
// Handle leftover (< stakers.len()).
639-
let leftover = subnet_tao.saturating_sub(distributed);
647+
// Largest‑remainder method; clamp for wasm32 (usize = 32‑bit).
648+
let leftover = pot_u128.saturating_sub(distributed);
640649
if leftover > 0 {
641650
portions.sort_by(|a, b| b.rem.cmp(&a.rem));
642-
for p in portions.iter_mut().take(leftover as usize) {
651+
let give = core::cmp::min(leftover, portions.len() as u128) as usize;
652+
for p in portions.iter_mut().take(give) {
643653
p.share = p.share.saturating_add(1);
644654
}
645655
}
646656

647657
// Restake into root and clean α records.
648658
for p in portions {
649659
if p.share > 0 {
650-
// Zero-fee restake of TAO into the root network.
651-
Self::stake_into_subnet(&p.hot, &p.cold, root_netuid, p.share, 0u64)?;
660+
Self::stake_into_subnet(
661+
&p.hot,
662+
&p.cold,
663+
root_netuid,
664+
p.share.into(),
665+
TaoCurrency::from(0),
666+
false,
667+
)?;
652668
}
653669
Alpha::<T>::remove((&p.hot, &p.cold, netuid));
654670
}
@@ -659,42 +675,44 @@ impl<T: Config> Pallet<T> {
659675
}
660676
}
661677

662-
// 5. Reset α in/out counters.
663-
SubnetAlphaIn::<T>::insert(netuid, 0);
664-
SubnetAlphaOut::<T>::insert(netuid, 0);
678+
// 5. Reset α in/out counters — use typed zeros (no inference issues).
679+
SubnetAlphaIn::<T>::insert(netuid, AlphaCurrency::from(0));
680+
SubnetAlphaOut::<T>::insert(netuid, AlphaCurrency::from(0));
665681

666682
// 6. Refund remaining lock to subnet owner.
667-
let refund = lock_cost.saturating_sub(owner_received_emission);
668-
Self::set_subnet_locked_balance(netuid, 0);
669-
if refund > 0 {
670-
Self::add_balance_to_coldkey_account(&owner_coldkey, refund);
683+
let refund_u64 = lock_cost_u64.saturating_sub(owner_received_emission_u64);
684+
Self::set_subnet_locked_balance(netuid, TaoCurrency::from(0));
685+
if refund_u64 > 0 {
686+
// This helper expects runtime Balance (u64), not TaoCurrency.
687+
Self::add_balance_to_coldkey_account(&owner_coldkey, refund_u64);
671688
}
672689

673690
Ok(())
674691
}
675-
676692
pub fn get_network_to_prune() -> Option<NetUid> {
677693
let current_block: u64 = Self::get_current_block_as_u64();
678694
let total_networks: u16 = TotalNetworks::<T>::get();
679695

680696
let mut candidate_netuid: Option<NetUid> = None;
681-
let mut candidate_emission = u64::MAX;
682-
let mut candidate_timestamp = u64::MAX;
697+
let mut candidate_emission: u64 = u64::MAX;
698+
let mut candidate_timestamp: u64 = u64::MAX;
683699

684700
for net in 1..=total_networks {
685701
let netuid: NetUid = net.into();
686702
let registered_at = NetworkRegisteredAt::<T>::get(netuid);
687703

688-
// Skip immune networks
704+
// Skip immune networks.
689705
if current_block < registered_at.saturating_add(Self::get_network_immunity_period()) {
690706
continue;
691707
}
692708

693-
// We want total emission across all UIDs in this subnet:
694-
let emission_vec = Emission::<T>::get(netuid);
695-
let total_emission = emission_vec.iter().sum::<u64>();
709+
// Sum AlphaCurrency as u64 for comparison.
710+
let total_emission: u64 = Emission::<T>::get(netuid)
711+
.into_iter()
712+
.map(Into::<u64>::into)
713+
.sum();
696714

697-
// If tie on total_emission, earliest registration wins
715+
// If tie on total_emission, earliest registration wins.
698716
if total_emission < candidate_emission
699717
|| (total_emission == candidate_emission && registered_at < candidate_timestamp)
700718
{

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,7 @@ mod dispatches {
22222222

22232223
/// Remove a user's subnetwork
22242224
/// The caller must be root
2225-
#[pallet::call_index(110)]
2225+
#[pallet::call_index(114)]
22262226
#[pallet::weight((Weight::from_parts(119_000_000, 0)
22272227
.saturating_add(T::DbWeight::get().reads(6))
22282228
.saturating_add(T::DbWeight::get().writes(31)), DispatchClass::Operational, Pays::No))]

pallets/subtensor/src/macros/hooks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ mod hooks {
129129
// Migrate subnet symbols to fix the shift after subnet 81
130130
.saturating_add(migrations::migrate_subnet_symbols::migrate_subnet_symbols::<T>())
131131
// Migrate CRV3 add commit_block
132-
.saturating_add(migrations::migrate_crv3_commits_add_block::migrate_crv3_commits_add_block::<T>());
132+
.saturating_add(migrations::migrate_crv3_commits_add_block::migrate_crv3_commits_add_block::<T>())
133+
// Migrate Immunity Period
134+
.saturating_add(migrations::migrate_network_immunity_period::migrate_network_immunity_period::<T>());
133135
weight
134136
}
135137

pallets/subtensor/src/subnets/subnet.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,11 @@ impl<T: Config> Pallet<T> {
167167
Error::<T>::NotEnoughBalanceToStake
168168
);
169169

170-
// --- 6. Determine the netuid to register.
171-
let netuid_to_register = Self::get_next_netuid();
172-
173170
// --- 7. Perform the lock operation.
174171
let actual_tao_lock_amount =
175172
Self::remove_balance_from_coldkey_account(&coldkey, lock_amount.into())?;
176173
log::debug!("actual_tao_lock_amount: {actual_tao_lock_amount:?}");
177174

178-
// --- 8. Set the lock amount for use to determine pricing.
179175
// --- 8. Set the lock amount for use to determine pricing.
180176
Self::set_network_last_lock(actual_tao_lock_amount);
181177

@@ -208,11 +204,11 @@ impl<T: Config> Pallet<T> {
208204
NetworkLastRegistered::<T>::set(current_block);
209205
NetworkRegisteredAt::<T>::insert(netuid_to_register, current_block);
210206

211-
// --- 13. Set the symbol.
207+
// --- 15. Set the symbol.
212208
let symbol = Self::get_next_available_symbol(netuid_to_register);
213209
TokenSymbol::<T>::insert(netuid_to_register, symbol);
214210

215-
// --- 15. Init the pool by putting the lock as the initial alpha.
211+
// --- 16. Init the pool by putting the lock as the initial alpha.
216212
TokenSymbol::<T>::insert(
217213
netuid_to_register,
218214
Self::get_symbol_for_subnet(netuid_to_register),
@@ -239,7 +235,7 @@ impl<T: Config> Pallet<T> {
239235
Self::increase_total_stake(pool_initial_tao);
240236
}
241237

242-
// --- 16. Add the identity if it exists
238+
// --- 17. Add the identity if it exists
243239
if let Some(identity_value) = identity {
244240
ensure!(
245241
Self::is_valid_subnet_identity(&identity_value),
@@ -250,12 +246,11 @@ impl<T: Config> Pallet<T> {
250246
Self::deposit_event(Event::SubnetIdentitySet(netuid_to_register));
251247
}
252248

253-
254-
// --- 17. Emit the NetworkAdded event.
249+
// --- 18. Emit the NetworkAdded event.
255250
log::info!("NetworkAdded( netuid:{netuid_to_register:?}, mechanism:{mechid:?} )");
256251
Self::deposit_event(Event::NetworkAdded(netuid_to_register, mechid));
257252

258-
// --- 18. Return success.
253+
// --- 19. Return success.
259254
Ok(())
260255
}
261256

0 commit comments

Comments
 (0)