Skip to content

Commit 535983f

Browse files
Merge pull request #602 from opentensor/fix/no_reg_emissions
Fix/no reg emissions
2 parents c6e1079 + 43f0402 commit 535983f

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

justfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export RUST_BACKTRACE := "full"
44
export SKIP_WASM_BUILD := "1"
55
export RUST_BIN_DIR := "target/x86_64-unknown-linux-gnu"
66
export TARGET := "x86_64-unknown-linux-gnu"
7-
export RUSTV := "nightly-2024-03-05"
7+
export RUSTV := "stable"
88
export RELEASE_NAME := "development"
99

1010
fmt:
@@ -25,13 +25,13 @@ benchmarks:
2525

2626
clippy:
2727
@echo "Running cargo clippy..."
28-
cargo +{{RUSTV}} clippy -- -D clippy::panic \
28+
cargo +{{RUSTV}} clippy --workspace --all-targets -- -D \
2929
-D clippy::todo \
3030
-D clippy::unimplemented
3131

3232
clippy-fix:
3333
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
34-
cargo +{{RUSTV}} clippy --fix --allow-dirty -- -A clippy::panic \
34+
cargo +{{RUSTV}} clippy --fix --allow-dirty --workspace --all-targets -- -A \
3535
-A clippy::todo \
3636
-A clippy::unimplemented
3737
fix:

pallets/subtensor/src/block_step.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,17 @@ impl<T: Config> Pallet<T> {
110110
// --- 1. Iterate across each network and add pending emission into stash.
111111
for (netuid, tempo) in <Tempo<T> as IterableStorageMap<u16, u16>>::iter() {
112112
// Skip the root network or subnets with registrations turned off
113-
if netuid == Self::get_root_netuid() || !Self::is_registration_allowed(netuid) {
113+
if netuid == Self::get_root_netuid() {
114114
// Root emission or subnet emission is burned
115115
continue;
116116
}
117117

118118
// --- 2. Queue the emission due to this network.
119-
let new_queued_emission: u64 = Self::get_subnet_emission_value(netuid);
119+
let mut new_queued_emission: u64 = Self::get_subnet_emission_value(netuid);
120+
if !Self::is_registration_allowed(netuid) {
121+
new_queued_emission = 0; // No emission for this network if registration is off.
122+
}
123+
120124
log::debug!(
121125
"generate_emission for netuid: {:?} with tempo: {:?} and emission: {:?}",
122126
netuid,

pallets/subtensor/tests/block_step.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,3 +895,45 @@ fn test_emission_based_on_registration_status() {
895895
);
896896
});
897897
}
898+
899+
#[test]
900+
fn test_epoch_runs_when_registration_disabled() {
901+
new_test_ext(1).execute_with(|| {
902+
let n: u16 = 100;
903+
let netuid_off: u16 = 1;
904+
let tempo: u16 = 1;
905+
let netuids: Vec<u16> = vec![netuid_off];
906+
let emissions: Vec<u64> = vec![1000000000];
907+
908+
// Add subnets with registration turned off and on
909+
add_network(netuid_off, tempo, 0);
910+
SubtensorModule::set_max_allowed_uids(netuid_off, n);
911+
SubtensorModule::set_emission_values(&netuids, emissions).unwrap();
912+
SubtensorModule::set_network_registration_allowed(netuid_off, false);
913+
914+
// Populate the subnets with neurons
915+
for i in 0..n {
916+
SubtensorModule::append_neuron(netuid_off, &U256::from(i), 0);
917+
}
918+
919+
// Generate emission at block 1
920+
let block: u64 = 1;
921+
SubtensorModule::generate_emission(block);
922+
923+
step_block(1); // Now block 2
924+
925+
// Verify blocks since last step was set
926+
assert_eq!(SubtensorModule::get_blocks_since_last_step(netuid_off), 1);
927+
928+
// Step to the next epoch block
929+
let epoch_block: u16 = tempo;
930+
step_block(epoch_block);
931+
932+
// Verify blocks since last step was set, this indicates we ran the epoch
933+
assert_eq!(
934+
SubtensorModule::get_blocks_since_last_step(netuid_off),
935+
0_u64
936+
);
937+
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_off).is_some());
938+
});
939+
}

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
135135
// `spec_version`, and `authoring_version` are the same between Wasm and native.
136136
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
137137
// the compatible custom types.
138-
spec_version: 152,
138+
spec_version: 153,
139139
impl_version: 1,
140140
apis: RUNTIME_API_VERSIONS,
141141
transaction_version: 1,

0 commit comments

Comments
 (0)