Skip to content
Merged
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
48 changes: 2 additions & 46 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,52 +287,8 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
}

pub fn localnet_config() -> Result<ChainSpec, String> {
let path: PathBuf = std::path::PathBuf::from("./snapshot.json");
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

// We mmap the file into memory first, as this is *a lot* faster than using
// `serde_json::from_reader`. See https://github.com/serde-rs/json/issues/160
let file = File::open(&path)
.map_err(|e| format!("Error opening genesis file `{}`: {}", path.display(), e))?;

// SAFETY: `mmap` is fundamentally unsafe since technically the file can change
// underneath us while it is mapped; in practice it's unlikely to be a problem
let bytes = unsafe {
memmap2::Mmap::map(&file)
.map_err(|e| format!("Error mmaping genesis file `{}`: {}", path.display(), e))?
};

let old_state: ColdkeyHotkeys =
json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {}", e))?;

let mut processed_stakes: Vec<(sp_runtime::AccountId32, Vec<(sp_runtime::AccountId32, (u64, u16))>)> = Vec::new();
for (coldkey_str, hotkeys) in old_state.stakes.iter() {
let coldkey = <sr25519::Public as Ss58Codec>::from_ss58check(&coldkey_str).unwrap();
let coldkey_account = sp_runtime::AccountId32::from(coldkey);

let mut processed_hotkeys: Vec<(sp_runtime::AccountId32, (u64, u16))> = Vec::new();

for (hotkey_str, amount_uid) in hotkeys.iter() {
let (amount, uid) = amount_uid;
let hotkey = <sr25519::Public as Ss58Codec>::from_ss58check(&hotkey_str).unwrap();
let hotkey_account = sp_runtime::AccountId32::from(hotkey);

processed_hotkeys.push((hotkey_account, (*amount, *uid)));
}

processed_stakes.push((coldkey_account, processed_hotkeys));
}

let mut balances_issuance: u64 = 0;
let mut processed_balances: Vec<(sp_runtime::AccountId32, u64)> = Vec::new();
for (key_str, amount) in old_state.balances.iter() {
let key = <sr25519::Public as Ss58Codec>::from_ss58check(&key_str).unwrap();
let key_account = sp_runtime::AccountId32::from(key);

processed_balances.push((key_account, *amount));
balances_issuance += *amount;
}

// Give front-ends necessary data to present to users
let mut properties = sc_service::Properties::new();
properties.insert("tokenSymbol".into(), "TAO".into());
Expand Down Expand Up @@ -433,7 +389,7 @@ fn localnet_genesis(
fn testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
_root_key: AccountId,
_endowed_accounts: Vec<AccountId>,
_enable_println: bool,
_stakes: Vec<(AccountId, Vec<(AccountId, (u64, u16))>)>,
Expand Down Expand Up @@ -482,7 +438,7 @@ fn testnet_genesis(
fn finney_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
_root_key: AccountId,
_endowed_accounts: Vec<AccountId>,
_enable_println: bool,
stakes: Vec<(AccountId, Vec<(AccountId, (u64, u16))>)>,
Expand Down
2 changes: 1 addition & 1 deletion pallets/collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use frame_support::{
assert_noop, assert_ok,
dispatch::Pays,
parameter_types,
traits::{ConstU32, ConstU64, GenesisBuild, StorageVersion},
traits::{ConstU32, ConstU64, GenesisBuild},
Hashable,
};
use frame_system::{EnsureRoot, EventRecord, Phase};
Expand Down
4 changes: 1 addition & 3 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ use frame_support::{
traits::{
Currency,
ExistenceRequirement,
tokens::{
WithdrawReasons
},
tokens::WithdrawReasons,
IsSubType,
}
};
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/networks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use frame_support::{sp_std::vec};
use frame_support::sp_std::vec;
use sp_std::vec::Vec;
use frame_system::ensure_root;
use crate::math::checked_sum;
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/senate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<T: Config> Pallet<T> {
// Check all our leave requirements
ensure!(T::SenateMembers::is_member(&hotkey), Error::<T>::NotSenateMember);

T::TriumvirateInterface::remove_votes(&hotkey);
T::TriumvirateInterface::remove_votes(&hotkey)?;
T::SenateMembers::remove_member(&hotkey)
}

Expand Down Expand Up @@ -107,7 +107,7 @@ impl<T: Config> Pallet<T> {
ensure_root(origin)?;

ensure!(!T::SenateMembers::is_member(who), Error::<T>::SenateMember);
T::TriumvirateInterface::remove_votes(who);
T::TriumvirateInterface::remove_votes(who)?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl<T: Config> Pallet<T> {
} < SenateRequiredStakePercentage::<T>::get()
{
// This might cause a panic, but there shouldn't be any reason this will fail with the checks above.
T::TriumvirateInterface::remove_votes(&hotkey);
T::TriumvirateInterface::remove_votes(&hotkey)?;
T::SenateMembers::remove_member(&hotkey)?;
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

use super::*;
use frame_support::{inherent::Vec};
use frame_support::inherent::Vec;
use sp_core::U256;
use frame_support::pallet_prelude::DispatchResult;
use crate::system::ensure_root;
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ parameter_types! {
pub type AccountId = U256;

// The address format for describing accounts.
#[allow(dead_code)]
pub type Address = AccountId;

// Balance of an account.
Expand Down
Loading