Skip to content

Commit d0953d8

Browse files
author
unconst
committed
Merge branch 'feat/rao-2025-01' of github.com:opentensor/subtensor into feat/rao-2025-01
2 parents 1c275ef + 5398a82 commit d0953d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3372
-3497
lines changed

pallets/admin-utils/src/tests/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use frame_support::sp_runtime::DispatchError;
22
use frame_support::{
3-
assert_err,
4-
assert_noop, assert_ok,
3+
assert_err, assert_noop, assert_ok,
54
dispatch::{DispatchClass, GetDispatchInfo, Pays},
65
traits::Hooks,
76
};
@@ -936,7 +935,6 @@ mod sudo_set_nominator_min_required_stake {
936935
#[test]
937936
fn clears_staker_nominations_below_min() {
938937
new_test_ext().execute_with(|| {
939-
940938
System::set_block_number(1);
941939

942940
// Create accounts.
@@ -1175,7 +1173,6 @@ fn test_set_alpha_values_dispatch_info_ok() {
11751173
#[test]
11761174
fn test_sudo_get_set_alpha() {
11771175
new_test_ext().execute_with(|| {
1178-
11791176
let netuid: u16 = 1;
11801177
let alpha_low: u16 = 12_u16;
11811178
let alpha_high: u16 = u16::MAX - 10;
@@ -1186,7 +1183,9 @@ fn test_sudo_get_set_alpha() {
11861183

11871184
// Enable Liquid Alpha and setup
11881185
SubtensorModule::set_liquid_alpha_enabled(netuid, true);
1189-
pallet_subtensor::migrations::migrate_create_root_network::migrate_create_root_network::<Test>();
1186+
pallet_subtensor::migrations::migrate_create_root_network::migrate_create_root_network::<
1187+
Test,
1188+
>();
11901189
SubtensorModule::add_balance_to_coldkey_account(&coldkey, 1_000_000_000_000_000);
11911190
assert_ok!(SubtensorModule::root_register(signer.clone(), hotkey,));
11921191

pallets/subtensor/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ std = [
104104
"ark-serialize/std",
105105
"w3f-bls/std",
106106
"rand_chacha/std",
107-
"sha2/std"
107+
"sha2/std",
108+
"share-pool/std"
108109
]
109110
runtime-benchmarks = [
110111
"frame-benchmarking/runtime-benchmarks",

pallets/subtensor/rpc/src/lib.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,33 @@ where
218218
fn get_all_dynamic_info(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
219219
let api = self.client.runtime_api();
220220
let at = at.unwrap_or_else(|| self.client.info().best_hash);
221-
api.get_all_dynamic_info(at)
222-
.map_err(|e| Error::RuntimeError(format!("Unable to get dynamic subnets info: {:?}", e)).into())
221+
api.get_all_dynamic_info(at).map_err(|e| {
222+
Error::RuntimeError(format!("Unable to get dynamic subnets info: {:?}", e)).into()
223+
})
223224
}
224225

225-
fn get_dynamic_info(&self, netuid: u16, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
226+
fn get_dynamic_info(
227+
&self,
228+
netuid: u16,
229+
at: Option<<Block as BlockT>::Hash>,
230+
) -> RpcResult<Vec<u8>> {
226231
let api = self.client.runtime_api();
227232
let at = at.unwrap_or_else(|| self.client.info().best_hash);
228-
api.get_dynamic_info(at, netuid)
229-
.map_err(|e| Error::RuntimeError(format!("Unable to get dynamic subnets info: {:?}", e)).into())
233+
api.get_dynamic_info(at, netuid).map_err(|e| {
234+
Error::RuntimeError(format!("Unable to get dynamic subnets info: {:?}", e)).into()
235+
})
230236
}
231237

232-
fn get_subnet_state(&self, netuid: u16, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
238+
fn get_subnet_state(
239+
&self,
240+
netuid: u16,
241+
at: Option<<Block as BlockT>::Hash>,
242+
) -> RpcResult<Vec<u8>> {
233243
let api = self.client.runtime_api();
234244
let at = at.unwrap_or_else(|| self.client.info().best_hash);
235-
api.get_subnet_state(at, netuid)
236-
.map_err(|e| Error::RuntimeError(format!("Unable to get subnet state info: {:?}", e)).into())
245+
api.get_subnet_state(at, netuid).map_err(|e| {
246+
Error::RuntimeError(format!("Unable to get subnet state info: {:?}", e)).into()
247+
})
237248
}
238249

239250
fn get_subnets_info(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {

pallets/subtensor/src/coinbase/block_emission.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
use super::*;
22
use frame_support::traits::Get;
3-
use substrate_fixed::{
4-
transcendental::log2,
5-
types::I96F32,
6-
};
3+
use substrate_fixed::{transcendental::log2, types::I96F32};
74

85
impl<T: Config> Pallet<T> {
9-
106
/// Calculates the dynamic TAO emission for a given subnet.
117
///
128
/// This function determines the three terms tao_in, alpha_in, alpha_out
13-
/// which are consequetively, 1) the amount of tao injected into the pool
14-
/// 2) the amount of alpha injected into the pool and 3) the amount of alpha
9+
/// which are consecutively, 1) the amount of tao injected into the pool
10+
/// 2) the amount of alpha injected into the pool, and 3) the amount of alpha
1511
/// left to be distributed towards miners/validators/owners per block.
1612
///
1713
/// # Arguments
@@ -21,14 +17,18 @@ impl<T: Config> Pallet<T> {
2117
///
2218
/// # Returns
2319
/// * `(u64, u64, u64)` - A tuple containing:
24-
/// - `tao_in_emission`: The adjusted TAO emission always lower or equalt to tao_emission
20+
/// - `tao_in_emission`: The adjusted TAO emission always lower or equal to tao_emission
2521
/// - `alpha_in_emission`: The adjusted alpha emission amount to be added into the pool.
26-
/// - `alpha_out_emission`: The remaining alpha emission after adjustments to be distributed to miners/validatods.
22+
/// - `alpha_out_emission`: The remaining alpha emission after adjustments to be distributed to miners/validators.
2723
///
2824
/// The algorithm ensures that the pool injection of tao_in_emission, alpha_in_emission does not effect the pool price
2925
/// It also ensures that the total amount of alpha_in_emission + alpha_out_emission sum to 2 * alpha_block_emission
30-
/// It also ensure that 1 < alpha_out_emission < 2 * alpha_block_emission and 0 < alpha_in_emission < alpha_block_emission.
31-
pub fn get_dynamic_tao_emission(netuid: u16, tao_emission: u64, alpha_block_emission: u64) -> (u64, u64, u64) {
26+
/// It also ensures that 1 < alpha_out_emission < 2 * alpha_block_emission and 0 < alpha_in_emission < alpha_block_emission.
27+
pub fn get_dynamic_tao_emission(
28+
netuid: u16,
29+
tao_emission: u64,
30+
alpha_block_emission: u64,
31+
) -> (u64, u64, u64) {
3232
// Init terms.
3333
let mut tao_in_emission: I96F32 = I96F32::from_num(tao_emission);
3434
let float_alpha_block_emission: I96F32 = I96F32::from_num(alpha_block_emission);
@@ -38,11 +38,18 @@ impl<T: Config> Pallet<T> {
3838
log::debug!("{:?} - alpha_price: {:?}", netuid, alpha_price);
3939

4040
// Get initial alpha_in
41-
let mut alpha_in_emission: I96F32 = I96F32::from_num(tao_emission).checked_div(alpha_price).unwrap_or(float_alpha_block_emission);
41+
let mut alpha_in_emission: I96F32 = I96F32::from_num(tao_emission)
42+
.checked_div(alpha_price)
43+
.unwrap_or(float_alpha_block_emission);
4244

4345
// Check if we are emitting too much alpha_in
4446
if alpha_in_emission >= float_alpha_block_emission {
45-
log::debug!("{:?} - alpha_in_emission: {:?} > alpha_block_emission: {:?}", netuid, alpha_in_emission, float_alpha_block_emission);
47+
log::debug!(
48+
"{:?} - alpha_in_emission: {:?} > alpha_block_emission: {:?}",
49+
netuid,
50+
alpha_in_emission,
51+
float_alpha_block_emission
52+
);
4653

4754
// Scale down tao_in
4855
tao_in_emission = alpha_price.saturating_mul(float_alpha_block_emission);
@@ -58,15 +65,25 @@ impl<T: Config> Pallet<T> {
5865
}
5966

6067
// Set Alpha in emission.
61-
let alpha_out_emission = I96F32::from_num(2).saturating_mul(float_alpha_block_emission).saturating_sub(alpha_in_emission);
68+
let alpha_out_emission = I96F32::from_num(2)
69+
.saturating_mul(float_alpha_block_emission)
70+
.saturating_sub(alpha_in_emission);
6271

6372
// Log results.
6473
log::debug!("{:?} - tao_in_emission: {:?}", netuid, tao_in_emission);
6574
log::debug!("{:?} - alpha_in_emission: {:?}", netuid, alpha_in_emission);
66-
log::debug!("{:?} - alpha_out_emission: {:?}", netuid, alpha_out_emission);
75+
log::debug!(
76+
"{:?} - alpha_out_emission: {:?}",
77+
netuid,
78+
alpha_out_emission
79+
);
6780

6881
// Return result.
69-
(tao_in_emission.to_num::<u64>(), alpha_in_emission.to_num::<u64>(), alpha_out_emission.to_num::<u64>())
82+
(
83+
tao_in_emission.to_num::<u64>(),
84+
alpha_in_emission.to_num::<u64>(),
85+
alpha_out_emission.to_num::<u64>(),
86+
)
7087
}
7188

7289
/// Calculates the block emission based on the total issuance.
@@ -133,5 +150,4 @@ impl<T: Config> Pallet<T> {
133150
}
134151
Ok(block_emission_u64)
135152
}
136-
137-
}
153+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::*;
2+
pub mod block_emission;
23
pub mod block_step;
34
pub mod root;
45
pub mod run_coinbase;
5-
pub mod block_emission;

pallets/subtensor/src/coinbase/root.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ use sp_std::vec;
2424
use substrate_fixed::types::I64F64;
2525

2626
impl<T: Config> Pallet<T> {
27-
28-
2927
/// Fetches the total count of root network validators
3028
///
3129
/// This function retrieves the total number of root network validators.
@@ -47,7 +45,7 @@ impl<T: Config> Pallet<T> {
4745
pub fn get_max_root_validators() -> u16 {
4846
Self::get_max_allowed_uids(Self::get_root_netuid())
4947
}
50-
48+
5149
/// Checks for any UIDs in the given list that are either equal to the root netuid or exceed the total number of subnets.
5250
///
5351
/// It's important to check for invalid UIDs to ensure data integrity and avoid referencing nonexistent subnets.
@@ -146,8 +144,6 @@ impl<T: Config> Pallet<T> {
146144
weights
147145
}
148146

149-
150-
151147
/// Registers a user's hotkey to the root network.
152148
///
153149
/// This function is responsible for registering the hotkey of a user.
@@ -392,7 +388,8 @@ impl<T: Config> Pallet<T> {
392388
});
393389

394390
if let Some(last) = sorted_members.last() {
395-
let last_stake = Self::get_stake_for_hotkey_on_subnet(last, Self::get_root_netuid());
391+
let last_stake =
392+
Self::get_stake_for_hotkey_on_subnet(last, Self::get_root_netuid());
396393

397394
if last_stake < current_stake {
398395
// Swap the member with the lowest stake.
@@ -408,8 +405,6 @@ impl<T: Config> Pallet<T> {
408405
Ok(last)
409406
}
410407

411-
412-
413408
pub fn do_vote_root(
414409
origin: T::RuntimeOrigin,
415410
hotkey: &T::AccountId,
@@ -456,8 +451,6 @@ impl<T: Config> Pallet<T> {
456451
.into())
457452
}
458453

459-
460-
461454
/// Facilitates the removal of a user's subnetwork.
462455
///
463456
/// # Args:
@@ -500,7 +493,6 @@ impl<T: Config> Pallet<T> {
500493
Ok(())
501494
}
502495

503-
504496
/// Removes a network (identified by netuid) and all associated parameters.
505497
///
506498
/// This function is responsible for cleaning up all the data associated with a network.

0 commit comments

Comments
 (0)