Skip to content
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

Chore/clippy #740

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
141 changes: 119 additions & 22 deletions node/src/chain_spec/raonet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@

use super::*;

/// Generates the configuration for the Raonet chain.
///
/// # Returns
///
/// * `Result<ChainSpec, String>` - The chain specification or an error message.
///
/// # Example
///
/// ```rust
/// let chain_spec = raonet_config().expect("Failed to generate Raonet config");
/// ```
pub fn raonet_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

Expand Down Expand Up @@ -44,95 +55,181 @@ pub fn raonet_config() -> Result<ChainSpec, String> {
.build())
}

/// Generates the genesis configuration for the Raonet chain.
///
/// # Arguments
///
/// * `initial_authorities` - A vector of initial authorities (AuraId, GrandpaId).
/// * `_enable_println` - A boolean flag to enable println (currently unused).
///
/// # Returns
///
/// * `serde_json::Value` - The genesis configuration as a JSON value.
fn raonet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
_enable_println: bool,
) -> serde_json::Value {
let mut balances = vec![
// Add Alice, Bob, and Charlie with 10 trillion tokens each
(
<AccountId32 as Ss58Codec>::from_ss58check("5FRo4vab84LM3aiK4DijnVawGDKagLGLzfn95j9tjDaHja8Z").unwrap(),
get_account_id_from_seed::<sr25519::Public>("Alice"),
10_000_000_000_000u128,
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
10_000_000_000_000u128,
),
(
get_account_id_from_seed::<sr25519::Public>("Charlie"),
10_000_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check(
"5FRo4vab84LM3aiK4DijnVawGDKagLGLzfn95j9tjDaHja8Z",
)
.unwrap(),
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5H3qhPGzKMNV9fTPuizxzp8azyFRMd4BnheSuwN9Qxb5Cz3u").unwrap(), // Greg
<AccountId32 as Ss58Codec>::from_ss58check(
"5H3qhPGzKMNV9fTPuizxzp8azyFRMd4BnheSuwN9Qxb5Cz3u",
)
.unwrap(), // Greg
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5H8zkg8K9hkM5PSeumivNXGuK8J8cUjtwEL9PfyqmgWELPka").unwrap(), // William
<AccountId32 as Ss58Codec>::from_ss58check(
"5H8zkg8K9hkM5PSeumivNXGuK8J8cUjtwEL9PfyqmgWELPka",
)
.unwrap(), // William
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5Ckg2z5NdrfbXpsPtZuVYXxRWh283QWw1gbXfN8CJC3tmxnY").unwrap(), // Dick
<AccountId32 as Ss58Codec>::from_ss58check(
"5Ckg2z5NdrfbXpsPtZuVYXxRWh283QWw1gbXfN8CJC3tmxnY",
)
.unwrap(), // Dick
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5CiUxGA5dTh1cPdgH67Kt62x4w5aKubnmWZMYSrZzoB4hpQi").unwrap(), // Michal
<AccountId32 as Ss58Codec>::from_ss58check(
"5CiUxGA5dTh1cPdgH67Kt62x4w5aKubnmWZMYSrZzoB4hpQi",
)
.unwrap(), // Michal
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5FLHD4eZkPStKUG7p9B1VPjD4w93Fxncf6JG5EK2uRcELmJy").unwrap(), // Carlos
<AccountId32 as Ss58Codec>::from_ss58check(
"5FLHD4eZkPStKUG7p9B1VPjD4w93Fxncf6JG5EK2uRcELmJy",
)
.unwrap(), // Carlos
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5G4FseBtaQd8sqeC98ZEL7xgtF2GSdueMXwUs8vsBENs4Ysn").unwrap(), // Sai
<AccountId32 as Ss58Codec>::from_ss58check(
"5G4FseBtaQd8sqeC98ZEL7xgtF2GSdueMXwUs8vsBENs4Ysn",
)
.unwrap(), // Sai
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5DiJqQoQdpgKaLz97Fk8ZkChAxMqf2mF2pVa6xDKYH8Cf9Sx").unwrap(), // Xavier
<AccountId32 as Ss58Codec>::from_ss58check(
"5DiJqQoQdpgKaLz97Fk8ZkChAxMqf2mF2pVa6xDKYH8Cf9Sx",
)
.unwrap(), // Xavier
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5EUJyRh3x9QftnUw7taFk3Xen6fCQgdc9ko8ort51RnR6LCn").unwrap(), // Elo
<AccountId32 as Ss58Codec>::from_ss58check(
"5EUJyRh3x9QftnUw7taFk3Xen6fCQgdc9ko8ort51RnR6LCn",
)
.unwrap(), // Elo
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5FREUpwG4wJYr1Usyp1i5XmxM3ycGTfvtjJtrSZETPgvh4Hx").unwrap(), // Roman
<AccountId32 as Ss58Codec>::from_ss58check(
"5FREUpwG4wJYr1Usyp1i5XmxM3ycGTfvtjJtrSZETPgvh4Hx",
)
.unwrap(), // Roman
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5GxREgL1Kvuv1kixbY2oJe36Q2HnWqTcfakBZqTPKWiPpVxf").unwrap(), // Abe
<AccountId32 as Ss58Codec>::from_ss58check(
"5GxREgL1Kvuv1kixbY2oJe36Q2HnWqTcfakBZqTPKWiPpVxf",
)
.unwrap(), // Abe
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5GsSxM8p1TYrpXfCx7Un5cTp1fr1RwHJczYDUUn8Xjnqj9Sk").unwrap(), // Nico
<AccountId32 as Ss58Codec>::from_ss58check(
"5GsSxM8p1TYrpXfCx7Un5cTp1fr1RwHJczYDUUn8Xjnqj9Sk",
)
.unwrap(), // Nico
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5HjEUemUaXSkxPcxGYiLykHmi5VfXBh5NCeNXYMbj9akYHbn").unwrap(), // Jip
<AccountId32 as Ss58Codec>::from_ss58check(
"5HjEUemUaXSkxPcxGYiLykHmi5VfXBh5NCeNXYMbj9akYHbn",
)
.unwrap(), // Jip
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5DUFdkP4rJrkXq9pfrWMHQS8zgiwXBZRgw2MMEAnBot59Taz").unwrap(), // Bob
<AccountId32 as Ss58Codec>::from_ss58check(
"5DUFdkP4rJrkXq9pfrWMHQS8zgiwXBZRgw2MMEAnBot59Taz",
)
.unwrap(), // Bob
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5CoSC9nRDT4CbnEGLCHcC8PxgpJsWpSdF3RLnTx2aBvX3qPu").unwrap(), // Faybian
<AccountId32 as Ss58Codec>::from_ss58check(
"5CoSC9nRDT4CbnEGLCHcC8PxgpJsWpSdF3RLnTx2aBvX3qPu",
)
.unwrap(), // Faybian
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5CXgmrp6Ts5igz9uxSdQQy9ERUVaJFtswzaSBUXhb3Ci7drK").unwrap(), // Special K
<AccountId32 as Ss58Codec>::from_ss58check(
"5CXgmrp6Ts5igz9uxSdQQy9ERUVaJFtswzaSBUXhb3Ci7drK",
)
.unwrap(), // Special K
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5HDpGZLNYSxHGWVhsPgKRDKVM6oob7MMnwxdpU8dBP7N51dX").unwrap(), // Michal
<AccountId32 as Ss58Codec>::from_ss58check(
"5HDpGZLNYSxHGWVhsPgKRDKVM6oob7MMnwxdpU8dBP7N51dX",
)
.unwrap(), // Michal
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5GH3haJWuJjcZWuC7iFGtaVajJNEpNg2Guaqyf71y9uDfFrt").unwrap(), // Isa
<AccountId32 as Ss58Codec>::from_ss58check(
"5GH3haJWuJjcZWuC7iFGtaVajJNEpNg2Guaqyf71y9uDfFrt",
)
.unwrap(), // Isa
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5HTukLb2y59rrL5tM9RMw3baziCFZUeSZATWMWHgSrNknc9A").unwrap(), // Gus
<AccountId32 as Ss58Codec>::from_ss58check(
"5HTukLb2y59rrL5tM9RMw3baziCFZUeSZATWMWHgSrNknc9A",
)
.unwrap(), // Gus
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5CkV7PPFWh8EihTK5uLm7VNF4C9hiKJ9UeJJwQuByn3bx82L").unwrap(), // Carrot
<AccountId32 as Ss58Codec>::from_ss58check(
"5CkV7PPFWh8EihTK5uLm7VNF4C9hiKJ9UeJJwQuByn3bx82L",
)
.unwrap(), // Carrot
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5DV8tTjq8EXE6KmoCbJ3xaN54HTXsfev5ZyKJEQPyTcm4MmE").unwrap(), // Paul
<AccountId32 as Ss58Codec>::from_ss58check(
"5DV8tTjq8EXE6KmoCbJ3xaN54HTXsfev5ZyKJEQPyTcm4MmE",
)
.unwrap(), // Paul
100_000_000_000u128,
)
),
];

// Check if the environment variable is set
Expand Down
13 changes: 9 additions & 4 deletions pallets/subtensor/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub trait SubtensorCustomApi<BlockHash> {
fn get_dynamic_info(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;
#[method(name = "subnetInfo_getAllDynamicInfo")]
fn get_all_dynamic_info(&self, at: Option<BlockHash>) -> RpcResult<Vec<u8>>;

}

pub struct SubtensorCustom<C, P> {
Expand Down Expand Up @@ -216,12 +215,18 @@ where
fn get_all_dynamic_info(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);
api.get_all_dynamic_info(at).map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
api.get_all_dynamic_info(at)
.map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
}
fn get_dynamic_info(&self, netuid: u16, at: Option<<Block as BlockT>::Hash>) -> RpcResult<Vec<u8>> {
fn get_dynamic_info(
&self,
netuid: u16,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<Vec<u8>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);
api.get_dynamic_info(at, netuid).map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
api.get_dynamic_info(at, netuid)
.map_err(|e| Error::RuntimeError(format!("Unable to get subnets info: {:?}", e)).into())
}

fn get_network_lock_cost(&self, at: Option<<Block as BlockT>::Hash>) -> RpcResult<u64> {
Expand Down
3 changes: 2 additions & 1 deletion pallets/subtensor/src/coinbase/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ impl<T: Config> Pallet<T> {
Self::run_coinbase();
// --- 4. Adjust tempos every day.
// TODO(const) make this better.
if block_number.saturating_add(1) % 300 == 0 { // adjust every hour.
if block_number.saturating_add(1) % 300 == 0 {
// adjust every hour.
Self::adjust_tempos();
}
// Return ok.
Expand Down
15 changes: 8 additions & 7 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl<T: Config> Pallet<T> {
} // Skip root network
let mechid = SubnetMechanism::<T>::get(*netuid);
let subnet_tao = I96F32::from_num(SubnetTAO::<T>::get(*netuid));
*mechanism_tao.entry(mechid).or_insert(I96F32::from_num(0)) += subnet_tao;
let entry = mechanism_tao.entry(mechid).or_insert(I96F32::from_num(0));
*entry = entry.saturating_add(subnet_tao);
total_active_tao = total_active_tao.saturating_add(subnet_tao);
}
log::debug!("Mechanism TAO sums: {:?}", mechanism_tao);
Expand Down Expand Up @@ -341,7 +342,7 @@ impl<T: Config> Pallet<T> {
hotkey_emission_tuples.push((parent, netuid, total_emission));

// Keep track of total emission distributed to parents
to_parents += total_emission;
to_parents = to_parents.saturating_add(total_emission);
}

// Calculate the final emission for the hotkey itself
Expand Down Expand Up @@ -410,8 +411,8 @@ impl<T: Config> Pallet<T> {
I96F32::from_num(Alpha::<T>::get((&hotkey, nominator.clone(), netuid)));
let global_contribution: I96F32 =
I96F32::from_num(Self::get_global_for_hotkey_and_coldkey(hotkey, &nominator));
total_global += global_contribution;
total_alpha += alpha_contribution;
total_global = total_global.saturating_add(global_contribution);
total_alpha = total_alpha.saturating_add(alpha_contribution);
contributions.push((nominator.clone(), alpha_contribution, global_contribution));
}

Expand All @@ -438,7 +439,7 @@ impl<T: Config> Pallet<T> {
.to_num::<u64>();
if total_emission > 0 {
// Record the emission for this nominator
to_nominators += total_emission;
to_nominators = to_nominators.saturating_add(total_emission);
emission_tuples.push((
hotkey.clone(),
nominator.clone(),
Expand All @@ -455,7 +456,7 @@ impl<T: Config> Pallet<T> {
.to_num::<u64>()
.saturating_sub(hotkey_take.to_num::<u64>())
.saturating_sub(to_nominators);
let final_hotkey_emission: u64 = hotkey_take.to_num::<u64>() + remainder;
let final_hotkey_emission: u64 = hotkey_take.to_num::<u64>().saturating_add(remainder);
emission_tuples.push((
hotkey.clone(),
hotkey_owner.clone(),
Expand Down Expand Up @@ -553,7 +554,7 @@ impl<T: Config> Pallet<T> {
let netuid_plus_one = (netuid as u64).saturating_add(1);
let tempo_plus_one = (tempo as u64).saturating_add(1);
let adjusted_block = block_number.wrapping_add(netuid_plus_one);
let remainder = adjusted_block % tempo_plus_one;
let remainder = adjusted_block.rem_euclid(tempo_plus_one);
(tempo as u64).saturating_sub(remainder)
}

Expand Down
6 changes: 4 additions & 2 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,11 @@ pub mod pallet {
StorageMap<_, Identity, u16, T::AccountId, ValueQuery, DefaultSubnetOwner<T>>;
// DEPRECATED
#[pallet::storage] // --- MAP ( netuid ) --> total_subnet_locked
pub type SubnetLocked<T: Config> = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
pub type SubnetLocked<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
#[pallet::storage] // --- MAP ( netuid ) --> largest_locked
pub type LargestLocked<T: Config> = StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
pub type LargestLocked<T: Config> =
StorageMap<_, Identity, u16, u64, ValueQuery, DefaultZeroU64<T>>;
#[pallet::storage] // --- ITEM( last_network_lock_cost )
pub type LockIntervalBlocks<T> = StorageValue<_, u64, ValueQuery, DefaultLockIntervalBlocks<T>>;
#[pallet::storage] // --- NMAP ( netuid, cold, hot ) --> (amount, start, end) | Returns the lock associated with a hotkey.
Expand Down
8 changes: 7 additions & 1 deletion pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,13 @@ mod dispatches {
origin_netuid: u16,
destination_netuid: u16,
) -> DispatchResult {
Self::do_move_stake(origin, origin_hotkey, destination_hotkey, origin_netuid, destination_netuid)
Self::do_move_stake(
origin,
origin_hotkey,
destination_hotkey,
origin_netuid,
destination_netuid,
)
}
}
}
28 changes: 15 additions & 13 deletions pallets/subtensor/src/rpc_info/dynamic_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use codec::Compact;
use frame_support::pallet_prelude::{Decode, Encode};

#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)]
pub struct DynamicInfo<T: Config>{
pub struct DynamicInfo<T: Config> {
owner: T::AccountId,
netuid: Compact<u16>,
tempo: Compact<u16>,
Expand All @@ -20,22 +20,24 @@ pub struct DynamicInfo<T: Config>{

impl<T: Config> Pallet<T> {
pub fn get_dynamic_info(netuid: u16) -> Option<DynamicInfo<T>> {
if !Self::if_subnet_exist(netuid) {return None;}
let last_step: u64 = LastMechansimStepBlock::<T>::get( netuid );
if !Self::if_subnet_exist(netuid) {
return None;
}
let last_step: u64 = LastMechansimStepBlock::<T>::get(netuid);
let current_block: u64 = Pallet::<T>::get_current_block_as_u64();
let blocks_since_last_step: u64 = current_block - last_step;
let blocks_since_last_step: u64 = current_block.saturating_sub(last_step);
Some(DynamicInfo {
owner: SubnetOwner::<T>::get( netuid ).into(),
owner: SubnetOwner::<T>::get(netuid),
netuid: netuid.into(),
tempo: Tempo::<T>::get( netuid ).into(),
tempo: Tempo::<T>::get(netuid).into(),
last_step: last_step.into(),
blocks_since_last_step: blocks_since_last_step.into(),
emission: EmissionValues::<T>::get( netuid ).into(),
alpha_in: SubnetAlphaIn::<T>::get( netuid ).into(),
alpha_out: SubnetAlphaOut::<T>::get( netuid ).into(),
tao_in: SubnetTAO::<T>::get( netuid ).into(),
total_locked: SubnetLocked::<T>::get( netuid ).into(),
owner_locked: LargestLocked::<T>::get( netuid ).into(),
emission: EmissionValues::<T>::get(netuid).into(),
alpha_in: SubnetAlphaIn::<T>::get(netuid).into(),
alpha_out: SubnetAlphaOut::<T>::get(netuid).into(),
tao_in: SubnetTAO::<T>::get(netuid).into(),
total_locked: SubnetLocked::<T>::get(netuid).into(),
owner_locked: LargestLocked::<T>::get(netuid).into(),
})
}
pub fn get_all_dynamic_info() -> Vec<Option<DynamicInfo<T>>> {
Expand All @@ -46,4 +48,4 @@ impl<T: Config> Pallet<T> {
}
dynamic_info
}
}
}
Loading
Loading