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

Fix bugs #138

Merged
merged 11 commits into from
Dec 4, 2019
10 changes: 10 additions & 0 deletions fe_develop_conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Darwinia-Alice",
"rpc-external": true,
"rpc-port": 23333,
"ws-external": true,
"ws-port": 23334,
"rpc-cors": "all",
"port": 23335,
"base-path": "/tmp/darwinia-alice"
}
98 changes: 49 additions & 49 deletions node/cli/res/crayfish-fir.json

Large diffs are not rendered by default.

181 changes: 42 additions & 139 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ use grandpa_primitives::AuthorityId as GrandpaId;
use hex_literal::hex;
use im_online::sr25519::AuthorityId as ImOnlineId;
use node_runtime::{
constants::currency::*, BalancesConfig, Block, ContractsConfig, IndicesConfig, KtonConfig, SessionConfig,
SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig, WASM_BINARY,
constants::currency::*, BabeConfig, BalancesConfig, Block, ContractsConfig, GrandpaConfig, ImOnlineConfig,
IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig,
WASM_BINARY,
};
use primitives::{crypto::UncheckedInto, sr25519, Pair, Public};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -133,7 +134,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {

let endowed_accounts: Vec<AccountId> = vec![root_key.clone()];

testnet_genesis(initial_authorities, root_key, Some(endowed_accounts), false)
darwinia_genesis(initial_authorities, root_key, Some(endowed_accounts), false)
}

/// Staging testnet config.
Expand Down Expand Up @@ -176,8 +177,8 @@ pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, Grandp
)
}

/// Helper function to create GenesisConfig for testing
pub fn testnet_genesis(
/// Helper function to create GenesisConfig for darwinia
pub fn darwinia_genesis(
initial_authorities: Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId)>,
root_key: AccountId,
endowed_accounts: Option<Vec<AccountId>>,
Expand All @@ -200,20 +201,20 @@ pub fn testnet_genesis(
]
});

const ENDOWMENT: Balance = 10_000_000 * COIN;
const ENDOWMENT: Balance = 1_000_000 * COIN;
const STASH: Balance = 100 * COIN;

GenesisConfig {
babe: Some(Default::default()),
babe: Some(BabeConfig { authorities: vec![] }),
contracts: Some(ContractsConfig {
current_schedule: contracts::Schedule {
enable_println, // this should only be enabled on development chains
..Default::default()
},
gas_price: 1 * MICRO,
}),
grandpa: Some(Default::default()),
im_online: Some(Default::default()),
grandpa: Some(GrandpaConfig { authorities: vec![] }),
im_online: Some(ImOnlineConfig { keys: vec![] }),
indices: Some(IndicesConfig {
ids: endowed_accounts
.iter()
Expand Down Expand Up @@ -247,18 +248,14 @@ pub fn testnet_genesis(
.iter()
.cloned()
.map(|k| (k, ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT)))
.collect(),
vesting: vec![],
}),
staking: Some(StakingConfig {
current_era: 0,
// current_era_total_reward: 80_000_000 * COIN / 63720,
// offline_slash: Perbill::from_parts(1_000_000),
session_reward: Perbill::from_percent(90),
validator_count: 7,
// offline_slash_grace: 4,
minimum_validator_count: 4,
validator_count: initial_authorities.len() as u32 * 2,
minimum_validator_count: initial_authorities.len() as u32,
stakers: initial_authorities
.iter()
.map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
Expand All @@ -270,17 +267,17 @@ pub fn testnet_genesis(
}
}

fn development_config_genesis() -> GenesisConfig {
testnet_genesis(
vec![get_authority_keys_from_seed("Alice")],
get_account_id_from_seed::<sr25519::Public>("Alice"),
None,
true,
)
}

/// Development config (single validator Alice)
pub fn development_config() -> ChainSpec {
fn development_config_genesis() -> GenesisConfig {
darwinia_genesis(
vec![get_authority_keys_from_seed("Alice")],
get_account_id_from_seed::<sr25519::Public>("Alice"),
None,
true,
)
}

ChainSpec::from_genesis(
"Development",
"dev",
Expand All @@ -293,20 +290,20 @@ pub fn development_config() -> ChainSpec {
)
}

fn local_testnet_genesis() -> GenesisConfig {
testnet_genesis(
vec![
get_authority_keys_from_seed("Alice"),
get_authority_keys_from_seed("Bob"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
None,
false,
)
}

/// Local testnet config (multivalidator Alice + Bob)
pub fn local_testnet_config() -> ChainSpec {
fn local_testnet_genesis() -> GenesisConfig {
darwinia_genesis(
vec![
get_authority_keys_from_seed("Alice"),
get_authority_keys_from_seed("Bob"),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
None,
false,
)
}

ChainSpec::from_genesis(
"Local Testnet",
"local_testnet",
Expand All @@ -319,111 +316,17 @@ pub fn local_testnet_config() -> ChainSpec {
)
}

/// Helper function to create GenesisConfig for darwinia
pub fn darwinia_genesis_verbose(
initial_authorities: Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId)>,
root_key: AccountId,
endowed_accounts: Option<Vec<AccountId>>,
enable_println: bool,
) -> GenesisConfig {
let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(|| {
vec![
/// c￿rayfish testnet config (multivalidator Alice + Bob)
pub fn crayfish_testnet_config() -> ChainSpec {
fn crayfish_config_genesis() -> GenesisConfig {
darwinia_genesis(
vec![get_authority_keys_from_seed("Alice")],
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
]
});

const ENDOWMENT: Balance = 1_000_000 * COIN;
const STASH: Balance = 100 * COIN;

GenesisConfig {
babe: Some(Default::default()),
contracts: Some(ContractsConfig {
current_schedule: contracts::Schedule {
enable_println, // this should only be enabled on development chains
..Default::default()
},
gas_price: 1 * MICRO,
}),
grandpa: Some(Default::default()),
im_online: Some(Default::default()),
indices: Some(IndicesConfig {
ids: endowed_accounts
.iter()
.cloned()
.chain(initial_authorities.iter().map(|x| x.0.clone()))
.collect::<Vec<_>>(),
}),
session: Some(SessionConfig {
keys: initial_authorities
.iter()
.map(|x| (x.0.clone(), session_keys(x.2.clone(), x.3.clone(), x.4.clone())))
.collect::<Vec<_>>(),
}),
sudo: Some(SudoConfig { key: root_key }),
system: Some(SystemConfig {
code: WASM_BINARY.to_vec(),
changes_trie_config: Default::default(),
}),

balances: Some(BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
.collect(),
vesting: vec![],
}),
kton: Some(KtonConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT)))
.collect(),
vesting: vec![],
}),
staking: Some(StakingConfig {
current_era: 0,
// current_era_total_reward: 80_000_000 * COIN / 63720,
// offline_slash: Perbill::from_parts(1_000_000),
session_reward: Perbill::from_percent(90),
validator_count: 7,
// offline_slash_grace: 4,
minimum_validator_count: 4,
stakers: initial_authorities
.iter()
.map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
.collect(),
invulnerables: initial_authorities.iter().map(|x| x.1.clone()).collect(),
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
}),
None,
true,
)
}
}

fn crayfish_config_genesis() -> GenesisConfig {
darwinia_genesis_verbose(
vec![get_authority_keys_from_seed("Alice")],
get_account_id_from_seed::<sr25519::Public>("Alice"),
None,
true,
)
}

/// c￿rayfish testnet config (multivalidator Alice + Bob)
pub fn crayfish_testnet_config() -> ChainSpec {
ChainSpec::from_genesis(
"Darwinia Crayfish Testnet",
"crayfish_testnet",
Expand Down
6 changes: 4 additions & 2 deletions srml/kton/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
mod imbalance;

use codec::{Codec, Decode, Encode};
#[cfg(not(feature = "std"))]
use rstd::borrow::ToOwned;
use rstd::{cmp, fmt::Debug, prelude::*, result};
#[cfg(feature = "std")]
use sr_primitives::traits::One;
Expand Down Expand Up @@ -113,7 +115,7 @@ decl_storage! {
let per_block = balance / length.max(One::one());
let offset = begin * per_block + balance;

(who.clone(), VestingSchedule { offset, per_block })
(who.to_owned(), VestingSchedule { offset, per_block })
})
}).collect::<Vec<_>>()
}): map T::AccountId => Option<VestingSchedule<T::Balance>>;
Expand Down Expand Up @@ -267,9 +269,9 @@ impl<T: Trait> Currency<T::AccountId> for Module<T> {

Self::set_free_balance(transactor, new_from_balance);
Self::set_free_balance(dest, new_to_balance);
Self::deposit_event(RawEvent::TokenTransfer(transactor.to_owned(), dest.to_owned(), value));
}

Self::deposit_event(RawEvent::TokenTransfer(transactor.clone(), dest.clone(), value));
Ok(())
}

Expand Down
10 changes: 1 addition & 9 deletions srml/staking/src/inflation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn compute_total_payout<T: Trait>(
total_left: u128,
) -> (RingBalanceOf<T>, RingBalanceOf<T>) {
// Milliseconds per year for the Julian year (365.25 days).
const MILLISECONDS_PER_YEAR: TimeStamp = 1000 * 3600 * 24 * 36525 / 100;
const MILLISECONDS_PER_YEAR: TimeStamp = ((36525 * 24 * 60 * 60) / 100) * 1000;

let year: u32 = (living_time / MILLISECONDS_PER_YEAR + 1).saturated_into::<u32>();

Expand Down Expand Up @@ -47,11 +47,3 @@ pub fn compute_kton_return<T: Trait>(value: RingBalanceOf<T>, months: u32) -> Kt
/ U256::from(1_970_000);
res.as_u128().try_into().unwrap_or_default()
}

#[cfg(any(feature = "std", test))]
mod test {
// use super::*;

#[test]
fn _test() {}
}
Loading