Skip to content

Commit 44d6859

Browse files
authored
Merge pull request #1024 from opentensor/hotfix/reg_disabled_payouts
hotfix: dont payout if reg disabled
2 parents 4e2c494 + e91aadd commit 44d6859

File tree

5 files changed

+50882
-50827
lines changed

5 files changed

+50882
-50827
lines changed

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<T: Config> Pallet<T> {
4848
// --- 3. Drain the subnet block emission and accumulate it as subnet emission, which increases until the tempo is reached in #4.
4949
// subnet_blockwise_emission -> subnet_pending_emission
5050
for netuid in subnets.clone().iter() {
51-
if *netuid == 0 {
51+
if *netuid == 0 || !Self::is_registration_allowed(*netuid) {
5252
continue;
5353
}
5454
// --- 3.1 Get the network's block-wise emission amount.
@@ -90,7 +90,7 @@ impl<T: Config> Pallet<T> {
9090
Self::set_blocks_since_last_step(*netuid, 0);
9191
Self::set_last_mechanism_step_block(*netuid, current_block);
9292

93-
if *netuid == 0 {
93+
if *netuid == 0 || !Self::is_registration_allowed(*netuid) {
9494
// Skip netuid 0 payouts
9595
continue;
9696
}

pallets/subtensor/tests/coinbase.rs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused, clippy::indexing_slicing, clippy::panic, clippy::unwrap_used)]
22
use crate::mock::*;
33
mod mock;
4-
use frame_support::assert_ok;
4+
use frame_support::{assert_err, assert_ok};
55
use sp_core::U256;
66
use substrate_fixed::types::I64F64;
77

@@ -1448,3 +1448,58 @@ fn test_coinbase_nominator_drainage_with_net_negative_delta() {
14481448
log::debug!("Test completed");
14491449
});
14501450
}
1451+
1452+
/// Tests that emission rewards are not distributed when subnet registration is disabled
1453+
/// This test verifies that:
1454+
/// 1. A subnet with registration disabled does not distribute emissions
1455+
/// 2. Pending emissions remain at 0 even after multiple blocks
1456+
/// 3. Total stake remains unchanged when registration is disabled
1457+
// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --test coinbase test_emission_with_registration_disabled_subnet -- --nocapture
1458+
1459+
#[test]
1460+
fn test_emission_with_registration_disabled_subnet() {
1461+
new_test_ext(1).execute_with(|| {
1462+
// Initialize test network and accounts
1463+
let netuid: u16 = 1;
1464+
let hotkey = U256::from(0); // Validator hotkey
1465+
let coldkey = U256::from(1); // Validator coldkey
1466+
1467+
// Create network and disable registration
1468+
add_network(netuid, 1, 0); // Creates subnet with netuid=1, tempo=1, modality=0
1469+
SubtensorModule::set_network_registration_allowed(netuid, false); // Disable registration
1470+
1471+
// Set up validator accounts and stake
1472+
// This simulates an existing validator before registration was disabled
1473+
SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey);
1474+
SubtensorModule::increase_stake_on_coldkey_hotkey_account(&coldkey, &hotkey, 1000);
1475+
1476+
// Configure emission rate for the subnet
1477+
SubtensorModule::set_emission_values(&[netuid], vec![10]).unwrap();
1478+
assert_eq!(SubtensorModule::get_subnet_emission_value(netuid), 10);
1479+
1480+
// Verify initial emission state is zero
1481+
assert_eq!(SubtensorModule::get_pending_emission(netuid), 0);
1482+
assert_eq!(SubtensorModule::get_pending_hotkey_emission(&hotkey), 0);
1483+
1484+
// Advance chain by 100 blocks
1485+
step_block(100);
1486+
1487+
// Verify no emissions were distributed after 100 blocks
1488+
assert_eq!(
1489+
SubtensorModule::get_pending_hotkey_emission(&hotkey),
1490+
0,
1491+
"Hotkey pending emission should remain zero"
1492+
);
1493+
1494+
// Advance chain by 1000 more blocks
1495+
step_block(1000);
1496+
1497+
// Verify total stake remains unchanged after many blocks
1498+
// This confirms no emissions were added to stake
1499+
let total_stake = SubtensorModule::get_total_stake_for_hotkey(&hotkey);
1500+
assert_eq!(
1501+
total_stake, 1000,
1502+
"Total stake should not increase when registration is disabled"
1503+
);
1504+
});
1505+
}

plain_spec_finney.json

Lines changed: 50822 additions & 50822 deletions
Large diffs are not rendered by default.

plain_spec_testfinney.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
160160
// `spec_version`, and `authoring_version` are the same between Wasm and native.
161161
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
162162
// the compatible custom types.
163-
spec_version: 210,
163+
spec_version: 211,
164164
impl_version: 1,
165165
apis: RUNTIME_API_VERSIONS,
166166
transaction_version: 1,

0 commit comments

Comments
 (0)