From fdddc09a94716ae9fc595ecbb76b7939be0d8dbf Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 12 Jun 2024 17:13:53 -0400 Subject: [PATCH 1/2] add test that epoch has run with emission off --- pallets/subtensor/tests/block_step.rs | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pallets/subtensor/tests/block_step.rs b/pallets/subtensor/tests/block_step.rs index eb97fe6923..a761dd6e92 100644 --- a/pallets/subtensor/tests/block_step.rs +++ b/pallets/subtensor/tests/block_step.rs @@ -894,3 +894,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 = vec![netuid_off]; + let emissions: Vec = 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()); + }); +} From 2aba3ebfab63ab2971efd926a0471c4a644b8fbe Mon Sep 17 00:00:00 2001 From: Cameron Fairchild Date: Wed, 12 Jun 2024 17:14:09 -0400 Subject: [PATCH 2/2] fix: skip emission but run epoch --- pallets/subtensor/src/block_step.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/block_step.rs b/pallets/subtensor/src/block_step.rs index 22ded6324d..d1ca829dfd 100644 --- a/pallets/subtensor/src/block_step.rs +++ b/pallets/subtensor/src/block_step.rs @@ -110,13 +110,17 @@ impl Pallet { // --- 1. Iterate across each network and add pending emission into stash. for (netuid, tempo) in as IterableStorageMap>::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,