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 24 commits
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
82 changes: 81 additions & 1 deletion 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,6 +258,86 @@ impl From<codec::Compact<Perbill>> for Perbill {
}
}

/// 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 Perquintill(u64);

const QUINTILLION: u64 = 1_000_000_000_000_000_000;

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

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

/// 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) -> 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) -> 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) -> 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) -> 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 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) / QUINTILLION)
}
}

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

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

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

impl From<codec::Compact<Perquintill>> for Perquintill {
fn from(x: codec::Compact<Perquintill>) -> Perquintill {
x.0
}
}

/// Ed25519 signature verify.
#[derive(Eq, PartialEq, Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
Expand Down
Binary file not shown.
6 changes: 3 additions & 3 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,7 +109,7 @@ 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(),
}),
democracy: Some(DemocracyConfig {
Expand Down Expand Up @@ -254,7 +254,7 @@ 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(),
}),
democracy: Some(DemocracyConfig {
Expand Down
22 changes: 9 additions & 13 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, staking, 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 @@ -317,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 Expand Up @@ -450,8 +450,8 @@ mod tests {
let mut digest = generic::Digest::<Log>::default();
digest.push(Log::from(::grandpa::RawLog::AuthoritiesChangeSignal(0, vec![
(Keyring::Charlie.to_raw_public().into(), 1),
(Keyring::Alice.to_raw_public().into(), 1),
(Keyring::Bob.to_raw_public().into(), 1),
(Keyring::Alice.to_raw_public().into(), 1),
])));
assert_eq!(Header::decode(&mut &block2.0[..]).unwrap().digest, digest);

Expand Down Expand Up @@ -585,16 +585,12 @@ mod tests {
phase: Phase::Finalization,
event: Event::session(session::RawEvent::NewSession(1))
},
// EventRecord {
// phase: Phase::Finalization,
// event: Event::staking(staking::RawEvent::Reward(0))
// },
EventRecord {
phase: Phase::Finalization,
event: Event::grandpa(::grandpa::RawEvent::NewAuthorities(vec![
(Keyring::Charlie.to_raw_public().into(), 1),
(Keyring::Alice.to_raw_public().into(), 1),
(Keyring::Bob.to_raw_public().into(), 1),
(Keyring::Alice.to_raw_public().into(), 1),
])),
},
EventRecord {
Expand Down
3 changes: 2 additions & 1 deletion node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ 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 {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 34,
spec_version: 35,
impl_version: 35,
apis: RUNTIME_API_VERSIONS,
};
Expand Down
Binary file not shown.
62 changes: 0 additions & 62 deletions srml/staking/Staking.md

This file was deleted.

Loading