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

Update and Fix #131

Merged
merged 19 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from 18 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
6 changes: 3 additions & 3 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ fn load_conf_from_file(cli: &mut RunCmd) -> error::Result<()> {
}

if let Some(shared_params) = conf.shared {
cli.shared_params.dev = shared_params.dev;
cli.shared_params = shared_params;
}
if let Some(validator) = conf.validator {
cli.validator = validator;
Expand Down Expand Up @@ -740,12 +740,12 @@ where
E: ChainSpecExtension,
S: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
{
load_conf_from_file(&mut cli)?;

let spec = load_spec(&cli.shared_params, spec_factory)?;
let base_path = base_path(&cli.shared_params, &version);
let mut config = service::Configuration::default_with_spec_and_base_path(spec.clone(), Some(base_path));

load_conf_from_file(&mut cli)?;

fill_config_keystore_password(&mut config, &cli)?;

config.impl_name = impl_name;
Expand Down
19 changes: 18 additions & 1 deletion core/cli/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl Default for TransactionPoolParams {

/// Execution strategies parameters.
#[derive(Clone, Debug, StructOpt, Deserialize)]
#[serde(rename_all = "kebab-case")]
#[serde(default, rename_all = "kebab-case")]
pub struct ExecutionStrategies {
/// The means of execution used when calling into the runtime while syncing blocks.
#[structopt(
Expand Down Expand Up @@ -379,6 +379,19 @@ pub struct ExecutionStrategies {
pub execution: Option<ExecutionStrategy>,
}

impl Default for ExecutionStrategies {
fn default() -> Self {
Self {
execution_syncing: ExecutionStrategy::NativeElseWasm,
execution_import_block: ExecutionStrategy::NativeElseWasm,
execution_block_construction: ExecutionStrategy::Wasm,
execution_offchain_worker: ExecutionStrategy::Native,
execution_other: ExecutionStrategy::Native,
execution: None,
}
}
}

/// The `run` command used to run a node.
#[derive(Debug, StructOpt, Clone)]
pub struct RunCmd {
Expand Down Expand Up @@ -981,6 +994,7 @@ pub struct Conf {
pub database_cache_size: Option<u32>,
pub state_cache_size: Option<usize>,

#[serde(flatten)]
pub shared: Option<SharedParams>,
pub validator: Option<bool>,
pub sentry: Option<bool>,
Expand All @@ -994,13 +1008,16 @@ pub struct Conf {
#[serde(rename = "wasm-execution")]
pub wasm_method: Option<WasmExecutionMethod>,

#[serde(flatten)]
pub execution_strategies: Option<ExecutionStrategies>,

pub offchain_worker: Option<OffchainWorkerEnabled>,

pub no_grandpa: Option<bool>,

#[serde(flatten)]
pub network_config: Option<NetworkConfigurationParams>,
#[serde(flatten)]
pub pool_config: Option<TransactionPoolParams>,

pub rpc_external: Option<bool>,
Expand Down
19 changes: 8 additions & 11 deletions darwinia_conf_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@

"wasm-execution": "interpreted",

"execution-strategies": {
"execution-syncing": "native",
"execution-import-block": "native",
"execution-block-construction": "native",
"execution-offchain-worker": "native",
"execution-other": "native",
"execution": "native"
},
"execution": "native-else-wasm",

"offchain-worker": "never",

"no-grandpa": true,

"rpc-external": false,
"rpc-external": true,
"rpc-port": 23333,

"ws-external": false,
"ws-port": 23334
"ws-external": true,
"ws-port": 23334,

"port": 23335,

"base-path": "/tmp"
}
141 changes: 71 additions & 70 deletions node/cli/res/crayfish-fir.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn testnet_genesis(
]
});

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

GenesisConfig {
Expand Down Expand Up @@ -263,7 +263,7 @@ pub fn testnet_genesis(
.iter()
.map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
.collect(),
invulnerables: initial_authorities.iter().map(|x| x.1.clone()).collect(),
invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(),
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
}),
Expand Down
33 changes: 16 additions & 17 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("darwinia-node"),
authoring_version: 2,
spec_version: 79,
impl_version: 79,
authoring_version: 3,
spec_version: 80,
impl_version: 80,
apis: RUNTIME_API_VERSIONS,
};

Expand Down Expand Up @@ -145,7 +145,7 @@ parameter_types! {
}
impl balances::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = (Staking, Session);
type OnFreeBalanceZero = ((Staking, Contracts), Session);
type OnNewAccount = Indices;
type TransferPayment = ();
type DustRemoval = ();
Expand Down Expand Up @@ -186,7 +186,7 @@ parameter_types! {
pub const MinimumPeriod: Moment = SLOT_DURATION / 2;
}
impl timestamp::Trait for Runtime {
type Moment = u64;
type Moment = Moment;
type OnTimestampSet = Babe;
type MinimumPeriod = MinimumPeriod;
}
Expand All @@ -206,7 +206,7 @@ impl authorship::Trait for Runtime {
type FindAuthor = session::FindAccountFromAuthorIndex<Self, Babe>;
type UncleGenerations = UncleGenerations;
type FilterUncle = ();
type EventHandler = Staking;
type EventHandler = (Staking, ImOnline);
}

// NOTE: `SessionHandler` and `SessionKeys` are co-dependent: One key will be used for each handler.
Expand Down Expand Up @@ -243,7 +243,7 @@ impl sudo::Trait for Runtime {
impl offences::Trait for Runtime {
type Event = Event;
type IdentificationTuple = session::historical::IdentificationTuple<Self>;
type OnOffenceHandler = ();
type OnOffenceHandler = Staking;
}

type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>;
Expand All @@ -264,11 +264,11 @@ impl grandpa::Trait for Runtime {
}

parameter_types! {
pub const WindowSize: BlockNumber = finality_tracker::DEFAULT_WINDOW_SIZE.into();
pub const ReportLatency: BlockNumber = finality_tracker::DEFAULT_REPORT_LATENCY.into();
pub const WindowSize: BlockNumber = 101;
pub const ReportLatency: BlockNumber = 1000;
}
impl finality_tracker::Trait for Runtime {
type OnFinalizationStalled = ();
type OnFinalizationStalled = Grandpa;
type WindowSize = WindowSize;
type ReportLatency = ReportLatency;
}
Expand Down Expand Up @@ -381,11 +381,11 @@ impl staking::Trait for Runtime {
type SessionInterface = Self;
}

//impl ethereum_bridge::Trait for Runtime {
// type Event = Event;
// type Ring = Balances;
// type Hash = Hash;
//}
impl ethereum_bridge::Trait for Runtime {
type Event = Event;
// type Ring = Balances;
// type Hash = Hash;
}

construct_runtime!(
pub enum Runtime where
Expand Down Expand Up @@ -419,7 +419,7 @@ construct_runtime!(
Sudo: sudo,
Utility: utility::{Module, Call, Event},

// EthereumBridge: ethereum_bridge::{Storage, Module, Event<T>, Call},
EthereumBridge: ethereum_bridge::{Storage, Module, Event<T>, Call},
}
);

Expand All @@ -432,7 +432,6 @@ pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// A Block signed with a Justification
pub type SignedBlock = generic::SignedBlock<Block>;
/// BlockId type as expected by this runtime.
/// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId<Block>;
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
Expand Down
9 changes: 4 additions & 5 deletions srml/kton/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

mod imbalance;

use codec::{Codec, Decode, Encode};
use rstd::{cmp, fmt::Debug, prelude::*, result};
#[cfg(feature = "std")]
Expand All @@ -22,14 +24,11 @@ use system::ensure_signed;
use darwinia_support::{BalanceLock, LockIdentifier, LockableCurrency, WithdrawLock, WithdrawReason, WithdrawReasons};
use imbalance::{NegativeImbalance, PositiveImbalance};

#[cfg(test)]
#[cfg(all(feature = "std", test))]
mod mock;

#[cfg(test)]
#[cfg(all(feature = "std", test))]
mod tests;

mod imbalance;

/// Struct to encode the vesting schedule of an individual account.
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, Default, RuntimeDebug)]
pub struct VestingSchedule<Balance> {
Expand Down
2 changes: 1 addition & 1 deletion srml/kton/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub use node_primitives::Balance;
pub use node_runtime::constants::currency::COIN;

use std::{cell::RefCell, collections::HashSet};
Expand All @@ -13,7 +14,6 @@ use substrate_primitives::H256;

use super::*;
use crate::{GenesisConfig, Module};
use node_primitives::Balance;

thread_local! {
static SESSION: RefCell<(Vec<AccountId>, HashSet<AccountId>)> = RefCell::new(Default::default());
Expand Down
104 changes: 58 additions & 46 deletions srml/kton/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,68 @@
use srml_support::{assert_err, assert_noop, assert_ok, traits::Currency};

use darwinia_support::{LockIdentifier, WithdrawReason, WithdrawReasons};
use darwinia_support::{LockIdentifier, NormalLock, TimeStamp, WithdrawLock, WithdrawReason, WithdrawReasons};

use super::*;
use crate::mock::*;

const ID_1: LockIdentifier = *b"1 ";
const ID_2: LockIdentifier = *b"2 ";
const ID_3: LockIdentifier = *b"3 ";

#[test]
fn transfer_should_work() {
ExtBuilder::default().existential_deposit(0).build().execute_with(|| {
let _ = Kton::deposit_creating(&666, 100);

assert_ok!(Kton::transfer(Origin::signed(666), 777, 50));
assert_eq!(Kton::total_balance(&666), 50);
assert_eq!(Kton::total_balance(&777), 50);

assert_ok!(Kton::transfer(Origin::signed(666), 777, 50));
assert_eq!(Kton::total_balance(&666), 0);
assert_eq!(Kton::total_balance(&777), 100);

assert_ok!(Kton::transfer(Origin::signed(666), 777, 0));
});
}

// TODO
//#[test]
//fn transfer_should_work() {
// ExtBuilder::default().existential_deposit(0).build().execute_with(|| {
// let _ = Kton::deposit_creating(&666, 100);
//
// assert_ok!(Kton::transfer(Origin::signed(666), 777, 50));
// assert_eq!(Kton::total_balance(&666), 50);
// assert_eq!(Kton::total_balance(&777), 50);
//
// assert_ok!(Kton::transfer(Origin::signed(666), 777, 50));
// assert_eq!(Kton::total_balance(&666), 0);
// assert_eq!(Kton::total_balance(&777), 100);
//
// assert_ok!(Kton::transfer(Origin::signed(666), 777, 0));
// });
//}
//
//#[test]
//fn transfer_should_fail() {
// ExtBuilder::default().existential_deposit(0).build().execute_with(|| {
// let _ = Kton::deposit_creating(&777, 1);
// assert_err!(
// Kton::transfer(Origin::signed(666), 777, 50),
// "balance too low to send value"
// );
//
// let _ = Kton::deposit_creating(&666, u64::max_value());
// assert_err!(
// Kton::transfer(Origin::signed(777), 666, 1),
// "destination balance too high to receive value"
// );
//
// assert_err!(
// Kton::transfer(Origin::signed(1), 777, Kton::vesting_balance(&1)),
// "vesting balance too high to send value"
// );
//
// Kton::set_lock(ID_1, &777, 1, u64::max_value(), WithdrawReasons::all());
// assert_err!(
// Kton::transfer(Origin::signed(777), 1, 1),
// "account liquidity restrictions prevent withdrawal"
// );
// });
//}
//
#[test]
fn transfer_should_fail() {
ExtBuilder::default().existential_deposit(0).build().execute_with(|| {
let _ = Kton::deposit_creating(&777, 1);
assert_err!(
Kton::transfer(Origin::signed(666), 777, 50),
"balance too low to send value",
);

let _ = Kton::deposit_creating(&666, Balance::max_value());
assert_err!(
Kton::transfer(Origin::signed(777), 666, 1),
"destination balance too high to receive value",
);

assert_err!(
Kton::transfer(Origin::signed(1), 777, Kton::vesting_balance(&1)),
"vesting balance too high to send value",
);

Kton::set_lock(
ID_1,
&777,
WithdrawLock::Normal(NormalLock {
amount: Balance::max_value(),
until: TimeStamp::max_value(),
}),
WithdrawReasons::all(),
);
assert_err!(
Kton::transfer(Origin::signed(777), 1, 1),
"account liquidity restrictions prevent withdrawal",
);
});
}

//#[test]
//fn set_lock_should_work() {
// ExtBuilder::default().existential_deposit(0).build().execute_with(|| {
Expand Down
2 changes: 1 addition & 1 deletion srml/staking/src/inflation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn compute_total_payout<T: Trait>(

let maximum = portion * total_left;

let maximum = maximum - maximum * 99_u128.pow(year.integer_sqrt()) / 100_u128.pow(year.integer_sqrt());
// let maximum = maximum - maximum * 99_u128.pow(year.integer_sqrt()) / 100_u128.pow(year.integer_sqrt());

let payout = maximum * 1; // TODO: add treasury ratio: Perbill::from_rational_approximation(npos_token_staked, total_tokens);

Expand Down
2 changes: 1 addition & 1 deletion srml/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod structs {

#[inline]
fn can_withdraw(&self, at: Moment, new_balance: Balance) -> bool {
self.valid_at(at) && self.amount > new_balance
!self.valid_at(at) || self.amount <= new_balance
}
}

Expand Down
Loading