Skip to content

Commit

Permalink
Merge pull request #94 from darwinia-network/denny_staking_fixing
Browse files Browse the repository at this point in the history
Staking new era and slash validators fixing
  • Loading branch information
hackfisher committed Nov 18, 2019
2 parents 00e6501 + fe0283a commit 18a3e00
Show file tree
Hide file tree
Showing 13 changed files with 716 additions and 807 deletions.
20 changes: 17 additions & 3 deletions Cargo.lock

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

16 changes: 10 additions & 6 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,19 @@ 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),
// 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,
// 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 @@ -402,17 +404,19 @@ 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),
// 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,
// 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
8 changes: 5 additions & 3 deletions node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,20 @@ mod tests {
}),
staking: Some(StakingConfig {
current_era: 0,
current_era_total_reward: 1,
// current_era_total_reward: 1,
stakers: vec![
(dave(), alice(), 111, staking::StakerStatus::Validator),
(eve(), bob(), 100, staking::StakerStatus::Validator),
(ferdie(), charlie(), 100, staking::StakerStatus::Validator),
],
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
2 changes: 2 additions & 0 deletions node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ block-builder-api = { package = "substrate-block-builder-runtime-api", git = 'ht
tx-pool-api = { package = "substrate-transaction-pool-runtime-api", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }
inherents = { package = "substrate-inherents", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }

srml-staking-reward-curve = { git = 'https://github.com/darwinia-network/substrate.git' }

transaction-payment-rpc-runtime-api = { package = "srml-transaction-payment-rpc-runtime-api", git = 'https://github.com/darwinia-network/substrate.git', default-features = false }

kton = { package = "darwinia-kton", path = '../../srml/kton', default-features = false }
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
33 changes: 24 additions & 9 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
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};
//use im_online::sr25519::AuthorityId as ImOnlineId;

use node_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Moment, Signature};
use rstd::prelude::*;
use sr_primitives::curve::PiecewiseLinear;
use sr_primitives::traits::{self, BlakeTwo256, Block as BlockT, NumberFor, SaturatedConversion, StaticLookup};
use sr_primitives::transaction_validity::TransactionValidity;
use sr_primitives::weights::Weight;
Expand All @@ -49,24 +50,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 @@ -409,15 +409,30 @@ impl kton::Trait for Runtime {
type OnRemoval = ();
}

srml_staking_reward_curve::build! {
const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
min_inflation: 0_025_000,
max_inflation: 0_100_000,
ideal_stake: 0_500_000,
falloff: 0_050_000,
max_piece_count: 40,
test_precision: 0_005_000,
);
}

parameter_types! {
// decimal 9
pub const CAP: Balance = 10_000_000_000 * COIN;

pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
}

impl staking::Trait for Runtime {
type Ring = Balances;
type Kton = Kton;
type Time = Timestamp;
type CurrencyToVote = CurrencyToVoteHandler;
type RingRewardRemainder = ();
type Event = Event;
type RingSlash = ();
type RingReward = ();
Expand All @@ -427,8 +442,8 @@ impl staking::Trait for Runtime {
type BondingDuration = BondingDuration;
type Cap = CAP;
type ErasPerEpoch = ErasPerEpoch;
type SessionLength = Period;
type SessionInterface = Self;
type RewardCurve = RewardCurve;
}

impl eos_bridge::Trait for Runtime {
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 18a3e00

Please sign in to comment.