Skip to content

Commit 3ce8ec5

Browse files
committed
Merge remote-tracking branch 'origin/devnet-ready' into feat/reject-incorrect-sudo-exts
2 parents 1f59643 + 7b027b7 commit 3ce8ec5

File tree

29 files changed

+324
-183
lines changed

29 files changed

+324
-183
lines changed

.github/workflows/cargo-audit.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ jobs:
4646
cargo audit --ignore RUSTSEC-2023-0091 \
4747
--ignore RUSTSEC-2024-0438 \
4848
--ignore RUSTSEC-2025-0009 \
49-
--ignore RUSTSEC-2025-0055
49+
--ignore RUSTSEC-2025-0055 \
50+
--ignore RUSTSEC-2025-0073 \
51+
--ignore RUSTSEC-2025-0118

.github/workflows/check-rust.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Install Rust Nightly
3939
uses: actions-rs/toolchain@v1
4040
with:
41-
toolchain: nightly
41+
toolchain: stable
4242
components: rustfmt
4343

4444
- name: Utilize Shared Rust Cache
@@ -48,7 +48,22 @@ jobs:
4848
cache-on-failure: true
4949

5050
- name: cargo fmt
51-
run: cargo +nightly fmt --check --all
51+
run: |
52+
set -euo pipefail
53+
# Run cargo fmt and capture both stdout and stderr
54+
output=$(cargo fmt --check --all 2>&1) || {
55+
echo "❌ cargo fmt failed with non-zero exit code"
56+
echo "$output"
57+
exit 1
58+
}
59+
# Check for panic/ICE messages even if exit code was 0
60+
if echo "$output" | grep -qiE "(the compiler unexpectedly panicked|panicked at|Internal Compiler Error|ICE|error: the compiler unexpectedly panicked)"; then
61+
echo "❌ rustfmt panicked (ICE detected) - this should fail the build"
62+
echo "$output"
63+
exit 1
64+
fi
65+
echo "$output"
66+
echo "✅ cargo fmt completed successfully"
5267
5368
cargo-clippy-default-features:
5469
name: cargo clippy

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@ specs/*.json
4646
bt.snap
4747

4848
# localnet spec
49-
scripts/specs/local.json
49+
scripts/specs/local.json
50+
51+
# Node modules
52+
node_modules

chain-extensions/src/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,12 @@ impl SubtensorExtensionEnv<AccountId> for MockEnv {
757757
}
758758

759759
fn charge_weight(&mut self, weight: Weight) -> Result<(), DispatchError> {
760-
if let Some(expected) = self.expected_weight {
761-
if weight != expected {
762-
return Err(DispatchError::Other(
763-
"unexpected weight charged by mock env",
764-
));
765-
}
760+
if let Some(expected) = self.expected_weight
761+
&& weight != expected
762+
{
763+
return Err(DispatchError::Other(
764+
"unexpected weight charged by mock env",
765+
));
766766
}
767767
self.charged_weight = Some(weight);
768768
Ok(())

node/src/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn start_babe_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> {
272272
{
273273
log::info!("Failed to aquire DB lock, trying again in 1s...");
274274
std::thread::sleep(std::time::Duration::from_secs(1));
275-
return start_babe_service(arg_matches);
275+
start_babe_service(arg_matches)
276276
// Unknown error, return it.
277277
} else {
278278
log::error!("Failed to start Babe service: {e:?}");

node/src/consensus/aura_consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl ConsensusMechanism for AuraConsensus {
120120
Self {}
121121
}
122122

123-
fn build_biq(&mut self) -> Result<BIQ, sc_service::Error>
123+
fn build_biq(&mut self) -> Result<BIQ<'_>, sc_service::Error>
124124
where
125125
NumberFor<Block>: BlockNumberOps,
126126
{

node/src/consensus/babe_consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl ConsensusMechanism for BabeConsensus {
128128
}
129129
}
130130

131-
fn build_biq(&mut self) -> Result<BIQ, sc_service::Error>
131+
fn build_biq(&mut self) -> Result<BIQ<'_>, sc_service::Error>
132132
where
133133
NumberFor<Block>: BlockNumberOps,
134134
{

node/src/consensus/consensus_mechanism.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub trait ConsensusMechanism {
7777
fn new() -> Self;
7878

7979
/// Builds a `BIQ` that uses the ConsensusMechanism.
80-
fn build_biq(&mut self) -> Result<BIQ, sc_service::Error>;
80+
fn build_biq(&mut self) -> Result<BIQ<'_>, sc_service::Error>;
8181

8282
/// Returns the slot duration.
8383
fn slot_duration(&self, client: &FullClient) -> Result<SlotDuration, ServiceError>;

pallets/subtensor/src/coinbase/block_step.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
2525
Self::run_coinbase(block_emission);
2626
// --- 5. Update moving prices AFTER using them for emissions.
2727
Self::update_moving_prices();
28-
// --- 6. Set pending children on the epoch; but only after the coinbase has been run.
28+
// --- 6. Update roop prop AFTER using them for emissions.
29+
Self::update_root_prop();
30+
// --- 7. Set pending children on the epoch; but only after the coinbase has been run.
2931
Self::try_set_pending_children(block_number);
30-
// --- 7. Run auto-claim root divs.
32+
// --- 8. Run auto-claim root divs.
3133
Self::run_auto_claim_root_divs(last_block_hash);
32-
// --- 8. Populate root coldkey maps.
34+
// --- 9. Populate root coldkey maps.
3335
Self::populate_root_coldkey_staking_maps();
3436

3537
// Return ok.
@@ -227,9 +229,9 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
227229
if next_value >= U110F18::saturating_from_num(Self::get_max_difficulty(netuid)) {
228230
Self::get_max_difficulty(netuid)
229231
} else if next_value <= U110F18::saturating_from_num(Self::get_min_difficulty(netuid)) {
230-
return Self::get_min_difficulty(netuid);
232+
Self::get_min_difficulty(netuid)
231233
} else {
232-
return next_value.saturating_to_num::<u64>();
234+
next_value.saturating_to_num::<u64>()
233235
}
234236
}
235237

@@ -261,9 +263,9 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
261263
if next_value >= U110F18::saturating_from_num(Self::get_max_burn(netuid)) {
262264
Self::get_max_burn(netuid)
263265
} else if next_value <= U110F18::saturating_from_num(Self::get_min_burn(netuid)) {
264-
return Self::get_min_burn(netuid);
266+
Self::get_min_burn(netuid)
265267
} else {
266-
return next_value.saturating_to_num::<u64>().into();
268+
next_value.saturating_to_num::<u64>().into()
267269
}
268270
}
269271

@@ -277,6 +279,29 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
277279
}
278280
}
279281

282+
pub fn update_root_prop() {
283+
let subnets_to_emit_to: Vec<NetUid> =
284+
Self::get_subnets_to_emit_to(&Self::get_all_subnet_netuids());
285+
// Only root_prop for subnets that we emit to.
286+
for netuid_i in subnets_to_emit_to.iter() {
287+
let root_prop = Self::root_proportion(*netuid_i);
288+
289+
RootProp::<T>::insert(netuid_i, root_prop);
290+
}
291+
}
292+
293+
pub fn root_proportion(netuid: NetUid) -> U96F32 {
294+
let alpha_issuance = U96F32::from_num(Self::get_alpha_issuance(netuid));
295+
let root_tao: U96F32 = U96F32::from_num(SubnetTAO::<T>::get(NetUid::ROOT));
296+
let tao_weight: U96F32 = root_tao.saturating_mul(Self::get_tao_weight());
297+
298+
let root_proportion: U96F32 = tao_weight
299+
.checked_div(tao_weight.saturating_add(alpha_issuance))
300+
.unwrap_or(U96F32::from_num(0.0));
301+
302+
root_proportion
303+
}
304+
280305
pub fn reveal_crv3_commits() {
281306
let netuids: Vec<NetUid> = Self::get_all_subnet_netuids();
282307
for netuid in netuids.into_iter().filter(|netuid| *netuid != NetUid::ROOT) {

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ impl<T: Config> Pallet<T> {
124124
let mut alpha_in: BTreeMap<NetUid, U96F32> = BTreeMap::new();
125125
let mut alpha_out: BTreeMap<NetUid, U96F32> = BTreeMap::new();
126126
let mut excess_tao: BTreeMap<NetUid, U96F32> = BTreeMap::new();
127+
let tao_block_emission: U96F32 = U96F32::saturating_from_num(
128+
Self::get_block_emission()
129+
.unwrap_or(TaoCurrency::ZERO)
130+
.to_u64(),
131+
);
127132

128133
// Only calculate for subnets that we are emitting to.
129134
for (&netuid_i, &tao_emission_i) in subnet_emissions.iter() {
@@ -142,8 +147,9 @@ impl<T: Config> Pallet<T> {
142147
let alpha_out_i: U96F32 = alpha_emission_i;
143148
let mut alpha_in_i: U96F32 = tao_emission_i.safe_div_or(price_i, U96F32::from_num(0.0));
144149

145-
if alpha_in_i > alpha_emission_i {
146-
alpha_in_i = alpha_emission_i;
150+
let alpha_injection_cap: U96F32 = alpha_emission_i.min(tao_block_emission);
151+
if alpha_in_i > alpha_injection_cap {
152+
alpha_in_i = alpha_injection_cap;
147153
tao_in_i = alpha_in_i.saturating_mul(price_i);
148154
}
149155

@@ -178,13 +184,6 @@ impl<T: Config> Pallet<T> {
178184
// --- 3. Inject ALPHA for participants.
179185
let cut_percent: U96F32 = Self::get_float_subnet_owner_cut();
180186

181-
// Get total TAO on root.
182-
let root_tao: U96F32 = asfloat!(SubnetTAO::<T>::get(NetUid::ROOT));
183-
log::debug!("root_tao: {root_tao:?}");
184-
// Get tao_weight
185-
let tao_weight: U96F32 = root_tao.saturating_mul(Self::get_tao_weight());
186-
log::debug!("tao_weight: {tao_weight:?}");
187-
188187
for netuid_i in subnets_to_emit_to.iter() {
189188
// Get alpha_out for this block.
190189
let mut alpha_out_i: U96F32 = *alpha_out.get(netuid_i).unwrap_or(&asfloat!(0));
@@ -205,14 +204,8 @@ impl<T: Config> Pallet<T> {
205204
*total = total.saturating_add(tou64!(owner_cut_i).into());
206205
});
207206

208-
// Get ALPHA issuance.
209-
let alpha_issuance: U96F32 = asfloat!(Self::get_alpha_issuance(*netuid_i));
210-
log::debug!("alpha_issuance: {alpha_issuance:?}");
211-
212207
// Get root proportional dividends.
213-
let root_proportion: U96F32 = tao_weight
214-
.checked_div(tao_weight.saturating_add(alpha_issuance))
215-
.unwrap_or(asfloat!(0.0));
208+
let root_proportion = Self::root_proportion(*netuid_i);
216209
log::debug!("root_proportion: {root_proportion:?}");
217210

218211
// Get root alpha from root prop.
@@ -498,10 +491,11 @@ impl<T: Config> Pallet<T> {
498491

499492
// Insert subnet owner hotkey in the beginning of the list if valid and not
500493
// already present
501-
if let Ok(owner_hk) = SubnetOwnerHotkey::<T>::try_get(netuid) {
502-
if Uids::<T>::get(netuid, &owner_hk).is_some() && !owner_hotkeys.contains(&owner_hk) {
503-
owner_hotkeys.insert(0, owner_hk);
504-
}
494+
if let Ok(owner_hk) = SubnetOwnerHotkey::<T>::try_get(netuid)
495+
&& Uids::<T>::get(netuid, &owner_hk).is_some()
496+
&& !owner_hotkeys.contains(&owner_hk)
497+
{
498+
owner_hotkeys.insert(0, owner_hk);
505499
}
506500

507501
owner_hotkeys
@@ -515,22 +509,22 @@ impl<T: Config> Pallet<T> {
515509
root_alpha_dividends: BTreeMap<T::AccountId, U96F32>,
516510
) {
517511
// Distribute the owner cut.
518-
if let Ok(owner_coldkey) = SubnetOwner::<T>::try_get(netuid) {
519-
if let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::try_get(netuid) {
520-
// Increase stake for owner hotkey and coldkey.
521-
log::debug!(
522-
"owner_hotkey: {owner_hotkey:?} owner_coldkey: {owner_coldkey:?}, owner_cut: {owner_cut:?}"
523-
);
524-
let real_owner_cut = Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
525-
&owner_hotkey,
526-
&owner_coldkey,
527-
netuid,
528-
owner_cut,
529-
);
530-
// If the subnet is leased, notify the lease logic that owner cut has been distributed.
531-
if let Some(lease_id) = SubnetUidToLeaseId::<T>::get(netuid) {
532-
Self::distribute_leased_network_dividends(lease_id, real_owner_cut);
533-
}
512+
if let Ok(owner_coldkey) = SubnetOwner::<T>::try_get(netuid)
513+
&& let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::try_get(netuid)
514+
{
515+
// Increase stake for owner hotkey and coldkey.
516+
log::debug!(
517+
"owner_hotkey: {owner_hotkey:?} owner_coldkey: {owner_coldkey:?}, owner_cut: {owner_cut:?}"
518+
);
519+
let real_owner_cut = Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
520+
&owner_hotkey,
521+
&owner_coldkey,
522+
netuid,
523+
owner_cut,
524+
);
525+
// If the subnet is leased, notify the lease logic that owner cut has been distributed.
526+
if let Some(lease_id) = SubnetUidToLeaseId::<T>::get(netuid) {
527+
Self::distribute_leased_network_dividends(lease_id, real_owner_cut);
534528
}
535529
}
536530

0 commit comments

Comments
 (0)