Skip to content

Commit

Permalink
Merge pull request #602 from opentensor/fix/no_reg_emissions
Browse files Browse the repository at this point in the history
Fix/no reg emissions
  • Loading branch information
distributedstatemachine committed Jul 1, 2024
2 parents c6e1079 + 43f0402 commit 535983f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export RUST_BACKTRACE := "full"
export SKIP_WASM_BUILD := "1"
export RUST_BIN_DIR := "target/x86_64-unknown-linux-gnu"
export TARGET := "x86_64-unknown-linux-gnu"
export RUSTV := "nightly-2024-03-05"
export RUSTV := "stable"
export RELEASE_NAME := "development"

fmt:
Expand All @@ -25,13 +25,13 @@ benchmarks:

clippy:
@echo "Running cargo clippy..."
cargo +{{RUSTV}} clippy -- -D clippy::panic \
cargo +{{RUSTV}} clippy --workspace --all-targets -- -D \
-D clippy::todo \
-D clippy::unimplemented

clippy-fix:
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
cargo +{{RUSTV}} clippy --fix --allow-dirty -- -A clippy::panic \
cargo +{{RUSTV}} clippy --fix --allow-dirty --workspace --all-targets -- -A \
-A clippy::todo \
-A clippy::unimplemented
fix:
Expand Down
8 changes: 6 additions & 2 deletions pallets/subtensor/src/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,17 @@ impl<T: Config> Pallet<T> {
// --- 1. Iterate across each network and add pending emission into stash.
for (netuid, tempo) in <Tempo<T> as IterableStorageMap<u16, u16>>::iter() {
// Skip the root network or subnets with registrations turned off
if netuid == Self::get_root_netuid() || !Self::is_registration_allowed(netuid) {
if netuid == Self::get_root_netuid() {
// Root emission or subnet emission is burned
continue;
}

// --- 2. Queue the emission due to this network.
let new_queued_emission: u64 = Self::get_subnet_emission_value(netuid);
let mut new_queued_emission: u64 = Self::get_subnet_emission_value(netuid);
if !Self::is_registration_allowed(netuid) {
new_queued_emission = 0; // No emission for this network if registration is off.
}

log::debug!(
"generate_emission for netuid: {:?} with tempo: {:?} and emission: {:?}",
netuid,
Expand Down
42 changes: 42 additions & 0 deletions pallets/subtensor/tests/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,45 @@ fn test_emission_based_on_registration_status() {
);
});
}

#[test]
fn test_epoch_runs_when_registration_disabled() {
new_test_ext(1).execute_with(|| {
let n: u16 = 100;
let netuid_off: u16 = 1;
let tempo: u16 = 1;
let netuids: Vec<u16> = vec![netuid_off];
let emissions: Vec<u64> = vec![1000000000];

// Add subnets with registration turned off and on
add_network(netuid_off, tempo, 0);
SubtensorModule::set_max_allowed_uids(netuid_off, n);
SubtensorModule::set_emission_values(&netuids, emissions).unwrap();
SubtensorModule::set_network_registration_allowed(netuid_off, false);

// Populate the subnets with neurons
for i in 0..n {
SubtensorModule::append_neuron(netuid_off, &U256::from(i), 0);
}

// Generate emission at block 1
let block: u64 = 1;
SubtensorModule::generate_emission(block);

step_block(1); // Now block 2

// Verify blocks since last step was set
assert_eq!(SubtensorModule::get_blocks_since_last_step(netuid_off), 1);

// Step to the next epoch block
let epoch_block: u16 = tempo;
step_block(epoch_block);

// Verify blocks since last step was set, this indicates we ran the epoch
assert_eq!(
SubtensorModule::get_blocks_since_last_step(netuid_off),
0_u64
);
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_off).is_some());
});
}
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 152,
spec_version: 153,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit 535983f

Please sign in to comment.