Skip to content

Commit

Permalink
fixing Currency to Vote and new session related
Browse files Browse the repository at this point in the history
  • Loading branch information
hackfisher committed Nov 15, 2019
1 parent 12d92d0 commit e26e2ba
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 614 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

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

12 changes: 8 additions & 4 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,18 @@ pub fn testnet_genesis(
staking: Some(StakingConfig {
current_era: 0,
current_era_total_reward: 80_000_000 * COIN / 63720,
offline_slash: Perbill::from_parts(1_000_000),
// offline_slash: Perbill::from_parts(1_000_000),
session_reward: Perbill::from_percent(90),
validator_count: 7,
offline_slash_grace: 4,
// 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()
}),
}
}
Expand Down Expand Up @@ -403,16 +405,18 @@ pub fn darwinia_genesis_verbose(
staking: Some(StakingConfig {
current_era: 0,
current_era_total_reward: 80_000_000 * COIN / 63720,
offline_slash: Perbill::from_parts(1_000_000),
// offline_slash: Perbill::from_parts(1_000_000),
session_reward: Perbill::from_percent(90),
validator_count: 7,
offline_slash_grace: 4,
// 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()
}),
}
}
Expand Down
6 changes: 4 additions & 2 deletions node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,12 @@ mod tests {
],
validator_count: 3,
minimum_validator_count: 0,
offline_slash: Perbill::zero(),
// offline_slash: Perbill::zero(),
session_reward: Perbill::zero(),
offline_slash_grace: 0,
// offline_slash_grace: 0,
invulnerables: vec![alice(), bob(), charlie()],
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
}),
timestamp: Some(Default::default()),
contracts: Some(Default::default()),
Expand Down
17 changes: 15 additions & 2 deletions node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sr_primitives::traits::{Convert, Saturating};

use sr_primitives::weights::Weight;
use sr_primitives::{Fixed64, Perbill};
use support::traits::{OnUnbalanced, Currency, Get};
use support::traits::{Currency, Get, OnUnbalanced};

pub struct Author;
impl OnUnbalanced<NegativeImbalance> for Author {
Expand All @@ -37,7 +37,8 @@ pub struct CurrencyToVoteHandler;

impl CurrencyToVoteHandler {
fn factor() -> Balance {
(Balances::total_issuance() / u64::max_value() as Balance).max(1)
//(Balances::total_issuance() / u64::max_value() as Balance).max(1)
1
}
}

Expand All @@ -53,6 +54,18 @@ impl Convert<u128, Balance> for CurrencyToVoteHandler {
}
}

//impl Convert<u128, u64> for CurrencyToVoteHandler {
// fn convert(x: u128) -> u64 {
// x as u64
// }
//}
//
//impl Convert<u128, u128> for CurrencyToVoteHandler {
// fn convert(x: u128) -> u128 {
// x
// }
//}

/// Convert from weight to balance via a simple coefficient multiplication
/// The associated type C encapsulates a constant in units of balance per weight
pub struct LinearWeightToFee<C>(rstd::marker::PhantomData<C>);
Expand Down
16 changes: 8 additions & 8 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
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 sr_api::impl_runtime_apis;
use codec::{Decode, Encode};
pub use contracts::Gas;
use sr_api::impl_runtime_apis;

//use grandpa::fg_primitives;
//use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
Expand All @@ -49,24 +49,23 @@ use support::{
};

pub use timestamp::Call as TimestampCall;
use version::RuntimeVersion;
#[cfg(any(feature = "std", test))]

use version::NativeVersion;
use version::RuntimeVersion;

use substrate_primitives::OpaqueMetadata;
use grandpa::AuthorityList as GrandpaAuthorityList;
use grandpa::fg_primitives;
use im_online::sr25519::{AuthorityId as ImOnlineId};
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
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 staking::EraIndex;
pub use staking::StakerStatus;

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

/// Constant values used within the runtime.
pub mod constants;
Expand Down Expand Up @@ -417,6 +416,7 @@ parameter_types! {
impl staking::Trait for Runtime {
type Ring = Balances;
type Kton = Kton;
type Time = Timestamp;
type CurrencyToVote = CurrencyToVoteHandler;
type Event = Event;
type RingSlash = ();
Expand Down
6 changes: 3 additions & 3 deletions srml/staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "darwinia-staking"
version = "0.1.0"
authors = ["hammeWang <dsw0602@foxmail.com>"]
version = "0.2.0"
authors = ["darwinia <hello@darwinia.network>"]
edition = "2018"

[dependencies]
Expand All @@ -10,6 +10,7 @@ safe-mix = { version = "1.0.0", default-features = false }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
substrate-keyring = { git = 'https://github.com/darwinia-network/substrate.git', optional = true }
rstd = { package = "sr-std", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
phragmen = { package = "substrate-phragmen", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
runtime_io = { package = "sr-io", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
sr-primitives = { git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
srml-support = { git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
Expand All @@ -21,7 +22,6 @@ substrate-primitives = { git = 'https://github.com/darwinia-network/substrate.gi
sr-arithmetic = { git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
sr-staking-primitives = { git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
authorship = { package = "srml-authorship", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
#phragmen = { package = "substrate-phragmen", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }

[dev-dependencies]
substrate-primitives = { git = 'https://github.com/darwinia-network/substrate.git' }
Expand Down
Loading

0 comments on commit e26e2ba

Please sign in to comment.