Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix most of the grumbles.
  • Loading branch information
kianenigma committed Mar 8, 2019
commit 747d6500d9c8332bd4d63e3c34542f82fed89b33
64 changes: 34 additions & 30 deletions core/sr-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ macro_rules! create_runtime_str {
#[cfg(feature = "std")]
pub use serde::{Serialize, de::DeserializeOwned};
#[cfg(feature = "std")]
use serde_derive::{Serialize, Deserialize};
pub use serde_derive::{Serialize, Deserialize};

/// Complex storage builder stuff.
#[cfg(feature = "std")]
Expand Down Expand Up @@ -258,78 +258,82 @@ impl From<codec::Compact<Perbill>> for Perbill {
}
}

/// Perquill is parts-per-quintillion. It stores a value between 0 and 1 in fixed point and
/// Perquintill is parts-per-quintillion. It stores a value between 0 and 1 in fixed point and
/// provides a means to multiply some other value by that.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
#[derive(Encode, Decode, Default, Copy, Clone, PartialEq, Eq)]
pub struct Perquill(u64);
pub struct Perquintill(u64);

impl Perquill {
/// Returns the internal u64 value
pub fn extract(&self) -> u64 { self.0 }
const QUINTILLION: u64 = 1_000_000_000_000_000_000;

impl Perquintill {
/// Nothing.
pub fn zero() -> Perquill { Perquill(0) }

/// `true` if this is nothing.
pub fn is_zero(&self) -> bool { self.0 == 0 }
pub fn zero() -> Self { Self(0) }

/// Everything.
pub fn one() -> Perquill { Perquill(1_000_000_000_000_000_000) }
pub fn one() -> Self { Self(QUINTILLION) }

/// Construct new instance where `x` is in quilltionths. Value equivalent to `x / 1,000,000,000,000,000,000`.
pub fn from_quilltionths(x: u64) -> Perquill { Perquill(x.min(1_000_000_000_000_000_000)) }
/// Construct new instance where `x` is in quintillionths. Value equivalent to `x / 1,000,000,000,000,000,000`.
pub fn from_quintillionths(x: u64) -> Self { Self(x.min(QUINTILLION)) }

/// Construct new instance where `x` is in billionths. Value equivalent to `x / 1,000,000,000`.
pub fn from_billionths(x: u64) -> Perquill { Perquill(x.min(1_000_000_000) * 1_000_000_000 ) }
pub fn from_billionths(x: u64) -> Self { Self(x.min(1_000_000_000) * 1_000_000_000 ) }

/// Construct new instance where `x` is in millionths. Value equivalent to `x / 1,000,000`.
pub fn from_millionths(x: u64) -> Perquill { Perquill(x.min(1_000_000) * 1000_000_000_000) }
pub fn from_millionths(x: u64) -> Self { Self(x.min(1_000_000) * 1000_000_000_000) }

/// Construct new instance where `x` is denominator and the nominator is 1.
pub fn from_xth(x: u64) -> Perquill { Perquill(1_000_000_000_000_000_000 / x.min(1_000_000_000_000_000_000)) }
pub fn from_xth(x: u64) -> Self { Self(QUINTILLION / x.min(QUINTILLION)) }

#[cfg(feature = "std")]
/// Construct new instance whose value is equal to `x` (between 0 and 1).
pub fn from_fraction(x: f64) -> Perquill { Perquill((x.max(0.0).min(1.0) * 1_000_000_000_000_000_000.0) as u64) }
pub fn from_fraction(x: f64) -> Self { Self((x.max(0.0).min(1.0) * QUINTILLION as f64) as u64) }
}

impl ::rstd::ops::Deref for Perquintill {
type Target = u64;

fn deref(&self) -> &u64 {
&self.0
}
}

impl<N> ::rstd::ops::Mul<N> for Perquill
impl<N> ::rstd::ops::Mul<N> for Perquintill
where
N: traits::As<u64>
{
type Output = N;
fn mul(self, b: N) -> Self::Output {
<N as traits::As<u64>>::sa(b.as_().saturating_mul(self.0 as u64) / 1_000_000_000_000_000_000)
<N as traits::As<u64>>::sa(b.as_().saturating_mul(self.0) / QUINTILLION)
}
}

#[cfg(feature = "std")]
impl From<f64> for Perquill {
fn from(x: f64) -> Perquill {
Perquill::from_fraction(x)
impl From<f64> for Perquintill {
fn from(x: f64) -> Perquintill {
Perquintill::from_fraction(x)
}
}

#[cfg(feature = "std")]
impl From<f32> for Perquill {
fn from(x: f32) -> Perquill {
Perquill::from_fraction(x as f64)
impl From<f32> for Perquintill {
fn from(x: f32) -> Perquintill {
Perquintill::from_fraction(x as f64)
}
}

impl codec::CompactAs for Perquill {
impl codec::CompactAs for Perquintill {
type As = u64;
fn encode_as(&self) -> &u64 {
&self.0
}
fn decode_from(x: u64) -> Perquill {
Perquill(x)
fn decode_from(x: u64) -> Perquintill {
Perquintill(x)
}
}

impl From<codec::Compact<Perquill>> for Perquill {
fn from(x: codec::Compact<Perquill>) -> Perquill {
impl From<codec::Compact<Perquintill>> for Perquintill {
fn from(x: codec::Compact<Perquintill>) -> Perquintill {
x.0
}
}
Expand Down
8 changes: 3 additions & 5 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use primitives::{Ed25519AuthorityId as AuthorityId, ed25519};
use node_primitives::AccountId;
use node_runtime::{ConsensusConfig, CouncilSeatsConfig, CouncilVotingConfig, DemocracyConfig,
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig, TreasuryConfig,
SessionConfig, StakingConfig, StakerStatus, TimestampConfig, BalancesConfig, TreasuryConfig,
SudoConfig, ContractConfig, GrandpaConfig, IndicesConfig, FeesConfig, Permill, Perbill};
pub use node_runtime::GenesisConfig;
use substrate_service;
Expand Down Expand Up @@ -109,9 +109,8 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
bonding_duration: 60 * MINUTES,
offline_slash_grace: 4,
minimum_validator_count: 4,
stakers: initial_authorities.iter().map(|x| (x.0.into(), x.1.into(), STASH)).collect(),
stakers: initial_authorities.iter().map(|x| (x.0.into(), x.1.into(), STASH, StakerStatus::Validator)).collect(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gavofyork is this ok or should be more generic?

Copy link
Member

Choose a reason for hiding this comment

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

looks reasonable. how could it be more generic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just that using a data type deep from a module in here seemed a bit strange. Though it is also used directly inside build(); it makes sense.

invulnerables: initial_authorities.iter().map(|x| x.1.into()).collect(),
nominators: vec![],
}),
democracy: Some(DemocracyConfig {
launch_period: 10 * MINUTES, // 1 day per public referendum
Expand Down Expand Up @@ -255,9 +254,8 @@ pub fn testnet_genesis(
current_offline_slash: 0,
current_session_reward: 0,
offline_slash_grace: 0,
stakers: initial_authorities.iter().map(|x| (x.0.into(), x.1.into(), STASH)).collect(),
stakers: initial_authorities.iter().map(|x| (x.0.into(), x.1.into(), STASH, StakerStatus::Validator)).collect(),
invulnerables: initial_authorities.iter().map(|x| x.1.into()).collect(),
nominators: vec![],
}),
democracy: Some(DemocracyConfig {
launch_period: 9,
Expand Down
15 changes: 7 additions & 8 deletions node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod tests {
use node_primitives::{Hash, BlockNumber, AccountId};
use runtime_primitives::traits::{Header as HeaderT, Digest as DigestT, Hash as HashT};
use runtime_primitives::{generic, generic::Era, ApplyOutcome, ApplyError, ApplyResult, Perbill};
use {balances, indices, session, system, consensus, timestamp, treasury, contract};
use {balances, indices, session, system, staking, consensus, timestamp, treasury, contract};
use contract::ContractAddressFor;
use system::{EventRecord, Phase};
use node_runtime::{Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
Expand Down Expand Up @@ -298,7 +298,11 @@ mod tests {
staking: Some(StakingConfig {
sessions_per_era: 2,
current_era: 0,
stakers: vec![(dave(), alice(), 111), (eve(), bob(), 100), (ferdie(), charlie(), 100)],
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,
bonding_duration: 0,
Expand All @@ -308,7 +312,6 @@ mod tests {
current_session_reward: 0,
offline_slash_grace: 0,
invulnerables: vec![alice(), bob(), charlie()],
nominators: vec![],
}),
democracy: Some(Default::default()),
council_seats: Some(Default::default()),
Expand All @@ -318,11 +321,7 @@ mod tests {
contract: Some(Default::default()),
sudo: Some(Default::default()),
grandpa: Some(GrandpaConfig {
authorities: vec![ // set these so no GRANDPA events fire when session changes
// (keyring::ed25519::Keyring::Charlie.to_raw_public().into(), 1),
// (keyring::ed25519::Keyring::Bob.to_raw_public().into(), 1),
// (keyring::ed25519::Keyring::Alice.to_raw_public().into(), 1),
],
authorities: vec![],
}),
fees: Some(FeesConfig {
transaction_base_fee: 1,
Expand Down
1 change: 1 addition & 0 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall;
pub use runtime_primitives::{Permill, Perbill};
pub use support::StorageValue;
pub use staking::StakerStatus;

/// Runtime version.
pub const VERSION: RuntimeVersion = RuntimeVersion {
Expand Down
62 changes: 0 additions & 62 deletions srml/staking/Staking.md

This file was deleted.

Loading