Skip to content

Commit

Permalink
Merge pull request #1034 from opentensor/testnet
Browse files Browse the repository at this point in the history
backpropagate hotfix to devnet
  • Loading branch information
unconst authored Nov 27, 2024
2 parents 2bcdde0 + 5a71e08 commit 711bf98
Show file tree
Hide file tree
Showing 5 changed files with 50,882 additions and 50,827 deletions.
4 changes: 2 additions & 2 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<T: Config> Pallet<T> {
// --- 3. Drain the subnet block emission and accumulate it as subnet emission, which increases until the tempo is reached in #4.
// subnet_blockwise_emission -> subnet_pending_emission
for netuid in subnets.clone().iter() {
if *netuid == 0 {
if *netuid == 0 || !Self::is_registration_allowed(*netuid) {
continue;
}
// --- 3.1 Get the network's block-wise emission amount.
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<T: Config> Pallet<T> {
Self::set_blocks_since_last_step(*netuid, 0);
Self::set_last_mechanism_step_block(*netuid, current_block);

if *netuid == 0 {
if *netuid == 0 || !Self::is_registration_allowed(*netuid) {
// Skip netuid 0 payouts
continue;
}
Expand Down
57 changes: 56 additions & 1 deletion pallets/subtensor/tests/coinbase.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(unused, clippy::indexing_slicing, clippy::panic, clippy::unwrap_used)]
use crate::mock::*;
mod mock;
use frame_support::assert_ok;
use frame_support::{assert_err, assert_ok};
use sp_core::U256;
use substrate_fixed::types::I64F64;

Expand Down Expand Up @@ -1448,3 +1448,58 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() {
log::debug!("Test completed");
});
}

/// Tests that emission rewards are not distributed when subnet registration is disabled
/// This test verifies that:
/// 1. A subnet with registration disabled does not distribute emissions
/// 2. Pending emissions remain at 0 even after multiple blocks
/// 3. Total stake remains unchanged when registration is disabled
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --test coinbase test_emission_with_registration_disabled_subnet -- --nocapture

#[test]
fn test_emission_with_registration_disabled_subnet() {
new_test_ext(1).execute_with(|| {
// Initialize test network and accounts
let netuid: u16 = 1;
let hotkey = U256::from(0); // Validator hotkey
let coldkey = U256::from(1); // Validator coldkey

// Create network and disable registration
add_network(netuid, 1, 0); // Creates subnet with netuid=1, tempo=1, modality=0
SubtensorModule::set_network_registration_allowed(netuid, false); // Disable registration

// Set up validator accounts and stake
// This simulates an existing validator before registration was disabled
SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey);
SubtensorModule::increase_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, 1000);

// Configure emission rate for the subnet
SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap();
assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10);

// Verify initial emission state is zero
assert_eq!(SubtensorModule::get_pending_emission(netuid), 0);
assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0);

// Advance chain by 100 blocks
step_block(100);

// Verify no emissions were distributed after 100 blocks
assert_eq!(
SubtensorModule::get_pending_hotkey_emission(&hotkey),
0,
"Hotkey pending emission should remain zero"
);

// Advance chain by 1000 more blocks
step_block(1000);

// Verify total stake remains unchanged after many blocks
// This confirms no emissions were added to stake
let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey);
assert_eq!(
total_stake, 1000,
"Total stake should not increase when registration is disabled"
);
});
}
101,644 changes: 50,822 additions & 50,822 deletions plain_spec_finney.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plain_spec_testfinney.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,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: 210,
spec_version: 211,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit 711bf98

Please sign in to comment.