Skip to content

Commit

Permalink
refac: run cargo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
My Name committed Feb 22, 2024
1 parent e7f721c commit 1f4585e
Show file tree
Hide file tree
Showing 27 changed files with 228 additions and 327 deletions.
35 changes: 5 additions & 30 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use node_subspace_runtime::{
AccountId, AuraConfig, BalancesConfig, GrandpaConfig, Precompiles, RuntimeGenesisConfig,
Signature, SubspaceModuleConfig, SudoConfig, SystemConfig, WASM_BINARY,
SubspaceModuleConfig, SudoConfig, SystemConfig, WASM_BINARY,
};
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{crypto::Ss58Codec, sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

// The URL for the telemetry server.
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
Expand All @@ -16,38 +15,16 @@ pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig>;

// Generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
<TPublic::Pair as Pair>::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}

type AccountPublic = <Signature as Verify>::Signer;

/// Generate an account ID from seed.
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}

/// Generate an Aura authority key.
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
}

pub fn authority_keys_from_ss58(s_aura: &str, s_grandpa: &str) -> (AuraId, GrandpaId) {
(get_aura_from_ss58_addr(s_aura), get_grandpa_from_ss58_addr(s_grandpa))
}

pub fn get_aura_from_ss58_addr(s: &str) -> AuraId {
Ss58Codec::from_ss58check(s).unwrap()
}

pub fn get_grandpa_from_ss58_addr(s: &str) -> GrandpaId {
Ss58Codec::from_ss58check(s).unwrap()
}

// Includes for nakamoto genesis
use serde::Deserialize;
use serde_json as json;
Expand All @@ -71,6 +48,7 @@ struct SubspaceJSONState {
block: u32,

// version
#[allow(unused)]
version: u32,
}

Expand Down Expand Up @@ -120,7 +98,7 @@ pub fn generate_config(network: String) -> Result<ChainSpec, String> {

// Add modules
modules.push(Vec::new());
for (uid, module) in state.modules[netuid].iter().enumerate() {
for module in state.modules[netuid].iter() {
modules[netuid].push((
sp_runtime::AccountId32::from(
// module_key
Expand Down Expand Up @@ -211,9 +189,6 @@ pub fn mainnet_config() -> Result<ChainSpec, String> {
return generate_config("main".to_string())
}

pub fn devnet_config() -> Result<ChainSpec, String> {
return generate_config("dev".to_string())
}
pub fn testnet_config() -> Result<ChainSpec, String> {
return generate_config("test".to_string())
}
Expand All @@ -229,7 +204,7 @@ fn network_genesis(
stake_to: Vec<Vec<(AccountId, Vec<(AccountId, u64)>)>>,
block: u32,
) -> RuntimeGenesisConfig {
use node_subspace_runtime::{EVMChainIdConfig, EVMConfig};
use node_subspace_runtime::EVMConfig;

RuntimeGenesisConfig {
system: SystemConfig {
Expand Down
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE};
use node_subspace_runtime::{Block, EXISTENTIAL_DEPOSIT};
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
use sc_cli::SubstrateCli;
use sc_service::PartialComponents;
use sp_keyring::Sr25519Keyring;

Expand Down
1 change: 0 additions & 1 deletion node/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Substrate Node Subspace CLI library.
#![allow(warnings)]
#![warn(missing_docs)]

mod chain_spec;
Expand Down
4 changes: 2 additions & 2 deletions pallets/subspace/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![cfg_attr(not(feature = "std"), no_std)]

use parity_scale_codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_arithmetic::per_things::Percent;
use sp_runtime::{
sp_std::prelude::Vec,
traits::{IdentifyAccount, Verify},
ArithmeticError, DispatchError, MultiSignature,
DispatchError, MultiSignature,
};

type Result<T> = core::result::Result<T, DispatchError>;
Expand Down
3 changes: 1 addition & 2 deletions pallets/subspace/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use jsonrpsee::{
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, IdentifyAccount, Verify},
DispatchError, MultiSignature,
MultiSignature,
};
use std::sync::Arc;
use subspace_runtime_api::ModuleInfo;
Expand Down
4 changes: 2 additions & 2 deletions pallets/subspace/src/global.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use crate::utils::is_vec_str;
use frame_support::pallet_prelude::DispatchResult;
use sp_runtime::DispatchError;

use system::ensure_root;

impl<T: Config> Pallet<T> {
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<T: Config> Pallet<T> {
return BurnRate::<T>::get().min(100);
}

pub fn set_burn_rate(mut burn_rate: u16) {
pub fn set_burn_rate(burn_rate: u16) {
BurnRate::<T>::put(burn_rate.min(100));
}

Expand Down
19 changes: 8 additions & 11 deletions pallets/subspace/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// disable all warnings
#![allow(warnings)]
#![cfg_attr(not(feature = "std"), no_std)]
#![recursion_limit = "512"]
use frame_system::{self as system, ensure_signed};
Expand Down Expand Up @@ -53,9 +52,7 @@ pub mod pallet {
use super::*;
use frame_support::{pallet_prelude::*, traits::Currency};
use frame_system::pallet_prelude::*;
use scale_info::prelude::string::String;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};

use sp_arithmetic::per_things::Percent;
pub use sp_std::{vec, vec::Vec};

Expand Down Expand Up @@ -260,12 +257,12 @@ pub mod pallet {
pub struct SubnetParams<T: Config> {
// --- parameters
pub founder: T::AccountId,
pub founder_share: u16, // out of 100
pub immunity_period: u16, // immunity period
pub incentive_ratio: u16, // out of 100
pub max_allowed_uids: u16, /* max number of weights allowed to be registered in this
* pub max_allowed_uids: u16, // max number of uids
* allowed to be registered in this subne */
pub founder_share: u16, // out of 100
pub immunity_period: u16, // immunity period
pub incentive_ratio: u16, // out of 100
pub max_allowed_uids: u16, /* max number of weights allowed to be registered in this
* pub max_allowed_uids: u16, // max number of uids
* allowed to be registered in this subne */
pub max_allowed_weights: u16, /* max number of weights allowed to be registered in this
* pub max_allowed_uids: u16, // max number of uids
* allowed to be registered in this subnet */
Expand Down Expand Up @@ -923,7 +920,7 @@ pub mod pallet {
}
}
// Now we can add the stake to the network
for (subnet_idx, subnet) in self.subnets.iter().enumerate() {
for (subnet_idx, _subnet) in self.subnets.iter().enumerate() {
let netuid: u16 = subnet_idx as u16;

for (key, stake_to) in self.stake_to[netuid as usize].iter() {
Expand Down
2 changes: 1 addition & 1 deletion pallets/subspace/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ mod tests {
use rand::{seq::SliceRandom, thread_rng, Rng};
use substrate_fixed::{
transcendental::exp,
types::{I110F18, I32F32, I64F64, I96F32},
types::{I32F32, I64F64, I96F32},
};

fn assert_float_compare(a: I32F32, b: I32F32, epsilon: I32F32) {
Expand Down
14 changes: 4 additions & 10 deletions pallets/subspace/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
// disable all warnings
#![allow(warnings)]
use crate as pallet_subspace;
use frame_support::{
assert_ok, parameter_types,
traits::{Everything, Hash, Hooks, StorageMapShim},
weights,
};
use frame_support::{parameter_types, traits::Everything};
use frame_system as system;
use frame_system::{limits, Config, EnsureNever, EnsureRoot, RawOrigin};
use sp_core::{ConstU32, Get, H256, U256};

use sp_core::{Get, H256, U256};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage, DispatchResult,
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
Expand Down
11 changes: 5 additions & 6 deletions pallets/subspace/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use frame_support::{

extern crate alloc;
use alloc::vec::Vec;
use codec::Compact;

use sp_arithmetic::per_things::Percent;
use sp_std::vec;

#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)]
pub struct ModuleStats<T: Config> {
Expand Down Expand Up @@ -43,7 +42,7 @@ impl<T: Config> Pallet<T> {
Ok(())
}

pub fn check_module_params(netuid: u16, params: ModuleParams<T>) -> DispatchResult {
pub fn check_module_params(_netuid: u16, params: ModuleParams<T>) -> DispatchResult {
// if len(name) > 0, then we update the name.
assert!(params.name.len() > 0);
ensure!(
Expand Down Expand Up @@ -85,7 +84,7 @@ impl<T: Config> Pallet<T> {

pub fn get_module_delegation_fee(netuid: u16, uid: u16) -> Percent {
let key = Self::get_key_for_uid(netuid, uid);
let mut delegation_fee: Percent = DelegationFee::<T>::get(netuid, key);
let delegation_fee: Percent = DelegationFee::<T>::get(netuid, key);
return delegation_fee
}

Expand Down Expand Up @@ -132,7 +131,7 @@ impl<T: Config> Pallet<T> {
let mut dividends: Vec<u16> = Dividends::<T>::get(netuid);
let mut last_update: Vec<u64> = LastUpdate::<T>::get(netuid);
let mut emission: Vec<u64> = Emission::<T>::get(netuid);
let mut delegation_fee: Percent = DelegationFee::<T>::get(netuid, uid_key.clone());
let _delegation_fee: Percent = DelegationFee::<T>::get(netuid, uid_key.clone());

// swap consensus vectors

Expand Down Expand Up @@ -249,7 +248,7 @@ impl<T: Config> Pallet<T> {
let incentive = Self::get_incentive_for_uid(netuid, uid as u16);
let dividends = Self::get_dividends_for_uid(netuid, uid as u16);
let last_update = Self::get_last_update_for_uid(netuid, uid as u16);
let registration_block = Self::get_registration_block_for_uid(netuid, uid as u16);
let _registration_block = Self::get_registration_block_for_uid(netuid, uid as u16);
let weights = <Weights<T>>::get(netuid, uid)
.iter()
.filter_map(|(i, w)| if *w > 0 { Some(((*i).into(), (*w).into())) } else { None })
Expand Down
6 changes: 3 additions & 3 deletions pallets/subspace/src/profit_share.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use frame_support::pallet_prelude::DispatchResult;
use substrate_fixed::types::{I110F18, I32F32, I64F64, I96F32};
use substrate_fixed::types::{I64F64, I96F32};

use super::*;

Expand All @@ -18,7 +18,7 @@ impl<T: Config> Pallet<T> {

// make sure the keys are unique and the shares are unique

let mut total_shares: u32 = shares.iter().map(|x| *x as u32).sum();
let total_shares: u32 = shares.iter().map(|x| *x as u32).sum();
assert!(total_shares > 0);
let mut normalized_shares_float: Vec<I64F64> = Vec::new();
// normalize shares
Expand Down Expand Up @@ -54,7 +54,7 @@ impl<T: Config> Pallet<T> {
);

// check tssat the normalized shares add up to the unit
let total_normalized_shares: u16 = normalize_shares.iter().sum::<u16>();
let _total_normalized_shares: u16 = normalize_shares.iter().sum::<u16>();

// now send the normalized shares to the profit share pallet
let profit_share_tuples: Vec<(T::AccountId, u16)> =
Expand Down
19 changes: 9 additions & 10 deletions pallets/subspace/src/registration.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use super::*;
use crate::system::ensure_root;

use frame_support::pallet_prelude::DispatchResult;
use frame_system::ensure_signed;
use sp_arithmetic::per_things::Percent;
use sp_core::{H256, U256};
use sp_io::hashing::{keccak_256, sha2_256};
use sp_std::{convert::TryInto, vec, vec::Vec};
use substrate_fixed::types::I32F32;
use system::pallet_prelude::BlockNumberFor;

use sp_core::H256;

use sp_std::vec::Vec;

// IterableStorageMap
use frame_support::storage::IterableStorageMap;

Expand Down Expand Up @@ -104,7 +103,7 @@ impl<T: Config> Pallet<T> {
}

pub fn enough_stake_to_register(
netuid: u16,
_netuid: u16,
min_stake: u64,
min_burn: u64,
stake_amount: u64,
Expand Down Expand Up @@ -137,7 +136,7 @@ impl<T: Config> Pallet<T> {

let mut min_score: u64 = u64::MAX;
let mut lowest_priority_uid: u16 = 0;
let mut prune_uids: Vec<u16> = Vec::new();
let _prune_uids: Vec<u16> = Vec::new();
let current_block = Self::get_current_block_as_u64();
let immunity_period: u64 = Self::get_immunity_period(netuid) as u64;

Expand Down Expand Up @@ -192,7 +191,7 @@ impl<T: Config> Pallet<T> {
let mut params: SubnetParams<T> = Self::default_subnet_params();
params.name = name.clone();
params.founder = founder_key.clone();
let netuid = Self::add_subnet(params);
let _netuid = Self::add_subnet(params);

Ok(())
}
Expand Down
Loading

0 comments on commit 1f4585e

Please sign in to comment.