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 primitives #105

Closed
wants to merge 3 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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 14 additions & 16 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,24 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Substrate chain configurations.
pub use node_runtime::GenesisConfig;

use babe_primitives::AuthorityId as BabeId;
use chain_spec::ChainSpecExtension;
use grandpa_primitives::AuthorityId as GrandpaId;
use hex_literal::hex;
use im_online::sr25519::AuthorityId as ImOnlineId;
use node_primitives::{AccountId, Balance};
use node_runtime::constants::currency::*;
use node_runtime::Block;
pub use node_runtime::GenesisConfig;
use node_runtime::{
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, GrandpaConfig, ImOnlineConfig,
IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig, COIN,
constants::currency::{COIN, MILLI},
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, Block, ContractsConfig, GrandpaConfig, ImOnlineConfig,
IndicesConfig, KtonConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig,
WASM_BINARY,
};
use primitives::{crypto::UncheckedInto, Pair, Public};
use serde::{Deserialize, Serialize};
use serde_json::de::ParserNumber;
use serde_json::Number;
use serde_json::{de::ParserNumber, Number};
use sr_primitives::Perbill;
use substrate_service;
use substrate_service::Properties;
use substrate_telemetry::TelemetryEndpoints;

Expand Down Expand Up @@ -195,8 +193,8 @@ pub fn testnet_genesis(
]
});

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

GenesisConfig {
system: Some(SystemConfig {
Expand Down Expand Up @@ -230,7 +228,7 @@ pub fn testnet_genesis(
enable_println, // this should only be enabled on development chains
..Default::default()
},
gas_price: 1 * MILLICENTS,
gas_price: 1 * MILLI,
}),
sudo: Some(SudoConfig { key: root_key }),
babe: Some(BabeConfig { authorities: vec![] }),
Expand All @@ -249,7 +247,7 @@ pub fn testnet_genesis(
}),
staking: Some(StakingConfig {
current_era: 0,
// current_era_total_reward: 80_000_000 * COIN / 63720,
// current_era_total_reward: 80_000_000 * MILLI / 63720,
// offline_slash: Perbill::from_parts(1_000_000),
session_reward: Perbill::from_percent(90),
validator_count: 7,
Expand Down Expand Up @@ -350,8 +348,8 @@ pub fn darwinia_genesis_verbose(
]
});

const ENDOWMENT: Balance = 100_000_000 * COIN;
const STASH: Balance = 100 * COIN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep COIN plz

const ENDOWMENT: Balance = 100_000_000 * MILLI;
const STASH: Balance = 100 * MILLI;

GenesisConfig {
system: Some(SystemConfig {
Expand Down Expand Up @@ -385,7 +383,7 @@ pub fn darwinia_genesis_verbose(
enable_println, // this should only be enabled on development chains
..Default::default()
},
gas_price: 1 * MILLICENTS,
gas_price: 1 * MILLI,
}),
sudo: Some(SudoConfig { key: root_key }),
babe: Some(BabeConfig { authorities: vec![] }),
Expand All @@ -404,7 +402,7 @@ pub fn darwinia_genesis_verbose(
}),
staking: Some(StakingConfig {
current_era: 0,
// current_era_total_reward: 80_000_000 * COIN / 63720,
// current_era_total_reward: 80_000_000 * MILLI / 63720,
// offline_slash: Perbill::from_parts(1_000_000),
session_reward: Perbill::from_percent(90),
validator_count: 7,
Expand Down
10 changes: 7 additions & 3 deletions node/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
pub mod currency {
use node_primitives::Balance;

pub const MILLICENTS: Balance = 1_000_000_000;
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
pub const DOLLARS: Balance = 100 * CENTS;
pub const NANO: Balance = 1;
pub const MICRO: Balance = 1_000 * NANO;
pub const MILLI: Balance = 1_000 * MICRO;
pub const COIN: Balance = 1_000 * MILLI;
// pub const MILLICENTS: Balance = 1_000 * MILLI;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments

// pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
// pub const DOLLARS: Balance = 100 * CENTS;
}

/// Time.
Expand Down
87 changes: 34 additions & 53 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,52 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![recursion_limit = "256"]

use authority_discovery_primitives::{AuthorityId as EncodedAuthorityId, Signature as EncodedSignature};
use babe_primitives::{AuthorityId as BabeId, AuthoritySignature as BabeSignature};
pub use balances::Call as BalancesCall;
use codec::{Decode, Encode};
pub use contracts::Gas;
use sr_api::impl_runtime_apis;
pub use timestamp::Call as TimestampCall;

//use grandpa::fg_primitives;
//use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
//use im_online::sr25519::AuthorityId as ImOnlineId;
pub use balances::Call as BalancesCall;
pub use staking::StakerStatus;

use authority_discovery_primitives::{AuthorityId as EncodedAuthorityId, Signature as EncodedSignature};
use babe_primitives::{AuthorityId as BabeId, AuthoritySignature as BabeSignature};
use codec::{Decode, Encode};
use grandpa::{fg_primitives, AuthorityList as GrandpaAuthorityList};
use im_online::sr25519::AuthorityId as ImOnlineId;
use node_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Moment, Signature};
use rstd::prelude::*;
use sr_primitives::traits::{
self, BlakeTwo256, Block as BlockT, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup,
use sr_api::impl_runtime_apis;
use sr_primitives::{
create_runtime_str, generic, impl_opaque_keys,
traits::{self, BlakeTwo256, Block as BlockT, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup},
transaction_validity::TransactionValidity,
weights::Weight,
ApplyResult, Perbill,
};
use sr_primitives::transaction_validity::TransactionValidity;
use sr_primitives::weights::Weight;
#[cfg(any(feature = "std", test))]
pub use sr_primitives::BuildStorage;

use sr_primitives::{create_runtime_str, generic, impl_opaque_keys, ApplyResult, Perbill};
use substrate_primitives::u32_trait::{_1, _4};

use support::traits::OnUnbalanced;
pub use support::StorageValue;
use substrate_primitives::OpaqueMetadata;
use support::{
construct_runtime, parameter_types,
traits::{Currency, Randomness, SplitTwoWays},
traits::{Currency, OnUnbalanced, Randomness, SplitTwoWays},
};

pub use timestamp::Call as TimestampCall;
use system::offchain::TransactionSubmitter;
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
#[cfg(any(feature = "std", test))]
use version::NativeVersion;
use version::RuntimeVersion;

use grandpa::fg_primitives;
use grandpa::AuthorityList as GrandpaAuthorityList;
use im_online::sr25519::AuthorityId as ImOnlineId;
use substrate_primitives::OpaqueMetadata;
use system::offchain::TransactionSubmitter;
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
//use grandpa::fg_primitives;
//use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
//use im_online::sr25519::AuthorityId as ImOnlineId;

use darwinia_support::TimeStamp;
use staking::EraIndex;
pub use staking::StakerStatus;

/// Constant values used within the runtime.
pub mod constants;
/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;
use impls::{Author, CurrencyToVoteHandler, LinearWeightToFee, TargetedFeeAdjustment};

/// Constant values used within the runtime.
pub mod constants;
use constants::time::*;
use constants::{currency::*, time::*};
use impls::{Author, CurrencyToVoteHandler, LinearWeightToFee, TargetedFeeAdjustment};

// Make the WASM binary available.
#[cfg(feature = "std")]
Expand All @@ -96,12 +88,15 @@ pub fn native_version() -> NativeVersion {
}
}

pub const NANO: Balance = 1;
pub const MICRO: Balance = 1_000 * NANO;
pub const MILLI: Balance = 1_000 * MICRO;
pub const COIN: Balance = 1_000 * MILLI;

type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
type DealWithFees = SplitTwoWays<
Balance,
NegativeImbalance,
_4,
MockTreasury, // 4 parts (80%) goes to the treasury.
_1,
Author, // 1 part (20%) goes to the block author.
>;

//pub struct Author;
//
Expand All @@ -118,20 +113,6 @@ impl OnUnbalanced<NegativeImbalance> for MockTreasury {
}
}

pub type DealWithFees = SplitTwoWays<
Balance,
NegativeImbalance,
_4,
MockTreasury, // 4 parts (80%) goes to the treasury.
_1,
Author, // 1 part (20%) goes to the block author.
>;

pub const SECS_PER_BLOCK: BlockNumber = 6;
pub const MINUTES: BlockNumber = 60 / SECS_PER_BLOCK;
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;

parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 1_000_000_000;
Expand Down
3 changes: 3 additions & 0 deletions srml/kton/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ darwinia-support = { path = "../support", default-features = false }
runtime_io = { package = "sr-io", git = 'https://github.com/darwinia-network/substrate.git' }
substrate-primitives = { git = 'https://github.com/darwinia-network/substrate.git' }

node-runtime = { path = "../../node/runtime" }
node-primitives = { path = "../../node/primitives" }

[features]
default = ["std"]
std = [
Expand Down
26 changes: 16 additions & 10 deletions srml/kton/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
pub use node_runtime::constants::currency::MILLICENTS;

use std::{cell::RefCell, collections::HashSet};

use sr_primitives::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
weights::Weight,
Perbill,
};
use srml_support::{impl_outer_origin, parameter_types};
use substrate_primitives::H256;

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

pub const COIN: u64 = 1_000_000_000;
use node_primitives::Balance;

thread_local! {
static SESSION: RefCell<(Vec<AccountId>, HashSet<AccountId>)> = RefCell::new(Default::default());
static EXISTENTIAL_DEPOSIT: RefCell<u64> = RefCell::new(0);
static EXISTENTIAL_DEPOSIT: RefCell<Balance> = RefCell::new(0);
}

/// The AccountId alias in this test module.
pub type AccountId = u64;
// FIXME:
// replace
// testing::Header.number: u64
// with
// node_primitives::BlockNumber
pub type BlockNumber = u64;
pub type Balance = u64;

impl_outer_origin! {
pub enum Origin for Test {}
Expand All @@ -31,8 +37,8 @@ impl_outer_origin! {
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const BlockHashCount: BlockNumber = 250;
pub const MaximumBlockWeight: Weight = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
Expand Down Expand Up @@ -71,7 +77,7 @@ impl Trait for Test {
}

pub struct ExtBuilder {
existential_deposit: u64,
existential_deposit: Balance,
}

impl Default for ExtBuilder {
Expand All @@ -81,7 +87,7 @@ impl Default for ExtBuilder {
}

impl ExtBuilder {
pub fn existential_deposit(mut self, existential_deposit: u64) -> Self {
pub fn existential_deposit(mut self, existential_deposit: Balance) -> Self {
self.existential_deposit = existential_deposit;
self
}
Expand All @@ -94,9 +100,9 @@ impl ExtBuilder {
self.set_associated_consts();
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
let balance_factor = if self.existential_deposit > 0 {
1_000 * COIN
1_000 * MILLICENTS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MILLICENTS already been removed?

} else {
1 * COIN
1 * MILLICENTS
};

let _ = GenesisConfig::<Test> {
Expand Down
3 changes: 2 additions & 1 deletion srml/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ substrate-primitives = { git = 'https://github.com/darwinia-network/substrate.gi
timestamp = { package = "srml-timestamp", git = 'https://github.com/darwinia-network/substrate.git' }
rand = "0.7.2"

balances = { package = "darwinia-balances", path = '../balances', default-features = false }
balances = { package = "darwinia-balances", path = '../balances' }
kton = { package = "darwinia-kton", path = "../kton" }
node-runtime = { path = "../../node/runtime" }
node-primitives = { path = "../../node/primitives" }

[features]
equalize = []
Expand Down
Loading