Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/no reg emissions #602

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
39 changes: 39 additions & 0 deletions pallets/subtensor/tests/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,42 @@ 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 as 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
Loading