Skip to content

Merge devnet to devnet ready with conflicts resolved #1042

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

Merged
merged 30 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e28dc9c
Merge pull request #976 from opentensor/devnet-ready
unconst Nov 13, 2024
feaa764
Merge pull request #978 from opentensor/devnet
unconst Nov 13, 2024
804c9fe
Merge pull request #987 from opentensor/devnet-ready
unconst Nov 16, 2024
6fdf21e
Merge pull request #989 from opentensor/devnet
unconst Nov 18, 2024
2bcdde0
Merge pull request #1001 from opentensor/devnet-ready
unconst Nov 19, 2024
f643d8f
Merge pull request #1004 from opentensor/devnet
unconst Nov 19, 2024
4e2c494
Merge pull request #1016 from opentensor/testnet
sam0x17 Nov 25, 2024
26ff5c3
hotfix: dont payout if reg disabled
distributedstatemachine Nov 27, 2024
f02c652
chore: remove extra ampersand
distributedstatemachine Nov 27, 2024
d68559e
fix: function name
distributedstatemachine Nov 27, 2024
eb7b365
fix: dereference netuid
distributedstatemachine Nov 27, 2024
3fa0814
Update chainspecs
distributedstatemachine Nov 27, 2024
320f058
Update pallets/subtensor/src/coinbase/run_coinbase.rs
distributedstatemachine Nov 27, 2024
7232e84
Update pallets/subtensor/src/coinbase/run_coinbase.rs
distributedstatemachine Nov 27, 2024
fbfd31d
Update chainspecs
distributedstatemachine Nov 27, 2024
2a13856
chore: tests
distributedstatemachine Nov 27, 2024
c730118
chore: bump spec version
distributedstatemachine Nov 27, 2024
e91aadd
Update chainspecs
distributedstatemachine Nov 27, 2024
44d6859
Merge pull request #1024 from opentensor/hotfix/reg_disabled_payouts
unconst Nov 27, 2024
5a71e08
Merge pull request #1028 from opentensor/main
unconst Nov 27, 2024
711bf98
Merge pull request #1034 from opentensor/testnet
unconst Nov 27, 2024
556086f
Merge branch 'devnet-ready' into merge-devnet-to-devnet-ready
gztensor Nov 29, 2024
a0526c4
Update chainspecs
gztensor Nov 29, 2024
4ff2e5b
bump CI
sam0x17 Nov 29, 2024
7e46bb5
Merge remote-tracking branch 'origin/devnet-ready' into merge-devnet-…
sam0x17 Dec 2, 2024
f0f34fb
fix clippy pt 1
sam0x17 Dec 2, 2024
bb2f560
fix doc comment
sam0x17 Dec 2, 2024
5ecb7a5
almost
sam0x17 Dec 2, 2024
1db2eb6
allow two stubborn non-local-definitions for now
sam0x17 Dec 2, 2024
b639263
cargo fmt
sam0x17 Dec 2, 2024
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
101,518 changes: 50,759 additions & 50,759 deletions chainspecs/plain_spec_finney.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chainspecs/plain_spec_testfinney.json

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ use substrate_fixed::types::I96F32;
impl<T: Config> Pallet<T> {
/// The `coinbase` function performs a four-part emission distribution process involving
/// subnets, epochs, hotkeys, and nominators.
// It is divided into several steps, each handling a specific part of the distribution:

// Step 1: Compute the block-wise emission for each subnet.
// This involves calculating how much (TAO) should be emitted into each subnet using the
// root epoch function.

// Step 2: Accumulate the subnet block emission.
// After calculating the block-wise emission, these values are accumulated to keep track
// of how much each subnet should emit before the next distribution phase. This accumulation
// is a running total that gets updated each block.

// Step 3: Distribute the accumulated emissions through epochs.
// Subnets periodically distribute their accumulated emissions to hotkeys (active validators/miners)
// in the network on a `tempo` --- the time between epochs. This step runs Yuma consensus to
// determine how emissions are split among hotkeys based on their contributions and roles.
// The accumulation of hotkey emissions is done through the `accumulate_hotkey_emission` function.
// The function splits the rewards for a hotkey amongst itself and its `parents`. The parents are
// the hotkeys that are delegating their stake to the hotkey.

// Step 4: Further distribute emissions from hotkeys to nominators.
// Finally, the emissions received by hotkeys are further distributed to their nominators,
// who are stakeholders that support the hotkeys.
/// It is divided into several steps, each handling a specific part of the distribution:
///
/// Step 1: Compute the block-wise emission for each subnet.
/// This involves calculating how much (TAO) should be emitted into each subnet using the
/// root epoch function.
///
/// Step 2: Accumulate the subnet block emission.
/// After calculating the block-wise emission, these values are accumulated to keep track
/// of how much each subnet should emit before the next distribution phase. This accumulation
/// is a running total that gets updated each block.
///
/// Step 3: Distribute the accumulated emissions through epochs.
/// Subnets periodically distribute their accumulated emissions to hotkeys (active validators/miners)
/// in the network on a `tempo` --- the time between epochs. This step runs Yuma consensus to
/// determine how emissions are split among hotkeys based on their contributions and roles.
/// The accumulation of hotkey emissions is done through the `accumulate_hotkey_emission` function.
/// The function splits the rewards for a hotkey amongst itself and its `parents`. The parents are
/// the hotkeys that are delegating their stake to the hotkey.
///
/// Step 4: Further distribute emissions from hotkeys to nominators.
/// Finally, the emissions received by hotkeys are further distributed to their nominators,
/// who are stakeholders that support the hotkeys.
pub fn run_coinbase() {
// --- 0. Get current block.
let current_block: u64 = Self::get_current_block_as_u64();
Expand All @@ -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 Expand Up @@ -134,7 +134,7 @@ impl<T: Config> Pallet<T> {
&hotkey,
*netuid,
validator_emission, // Amount received from validating
mining_emission, // Amount recieved from mining.
mining_emission, // Amount received from mining.
);
log::debug!("Accumulated emissions on hotkey {:?} for netuid {:?}: mining {:?}, validator {:?}", hotkey, *netuid, mining_emission, validator_emission);
}
Expand Down
12 changes: 5 additions & 7 deletions pallets/subtensor/src/epoch/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,24 @@ pub fn vec_max_upscale_to_u16(vec: &[I32F32]) -> Vec<u16> {
})
.collect();
}
return vec
.iter()
vec.iter()
.map(|e: &I32F32| {
e.saturating_mul(u16_max)
.saturating_div(*val)
.round()
.to_num::<u16>()
})
.collect();
.collect()
}
None => {
let sum: I32F32 = vec.iter().sum();
return vec
.iter()
vec.iter()
.map(|e: &I32F32| {
e.saturating_mul(u16_max)
.saturating_div(sum)
.to_num::<u16>()
})
.collect();
.collect()
}
}
}
Expand Down Expand Up @@ -246,7 +244,7 @@ pub fn is_topk(vector: &[I32F32], k: usize) -> Vec<bool> {
pub fn normalize(x: &[I32F32]) -> Vec<I32F32> {
let x_sum: I32F32 = sum(x);
if x_sum != I32F32::from_num(0.0_f32) {
return x.iter().map(|xi| xi.saturating_div(x_sum)).collect();
x.iter().map(|xi| xi.saturating_div(x_sum)).collect()
} else {
x.to_vec()
}
Expand Down
55 changes: 55 additions & 0 deletions pallets/subtensor/src/tests/coinbase.rs
Original file line number Diff line number Diff line change
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"
);
});
}
3 changes: 2 additions & 1 deletion pallets/subtensor/src/tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2736,6 +2736,7 @@ fn test_blocks_since_last_step() {
assert_eq!(SubtensorModule::get_blocks_since_last_step(netuid), 27);
});
}

// // Map the retention graph for consensus guarantees with an single epoch on a graph with 512 nodes, of which the first 64 are validators, the graph is split into a major and minor set, each setting specific weight on itself and the complement on the other.
// //
// // ```import torch
Expand Down Expand Up @@ -2835,7 +2836,7 @@ fn test_blocks_since_last_step() {
// println!("]");
// }

/// Helpers
// Helpers

/// Asserts that two I32F32 values are approximately equal within a given epsilon.
///
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,10 @@ impl_runtime_apis! {
use frame_system_benchmarking::Pallet as SystemBench;
use baseline::Pallet as BaselineBench;

#[allow(non_local_definitions)]
impl frame_system_benchmarking::Config for Runtime {}

#[allow(non_local_definitions)]
impl baseline::Config for Runtime {}

use frame_support::traits::WhitelistedStorageKeys;
Expand Down
Loading