Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
07d82af
Recompile runtime.
gavofyork Jun 22, 2018
d467109
Introduce and enforce block time
gavofyork Jun 22, 2018
f714307
Introduce early session ending.
gavofyork Jun 22, 2018
19fe55f
Report most of staking module
gavofyork Jun 23, 2018
b8f2689
rewards, proper early exit and slashing
gavofyork Jun 23, 2018
5ac27b5
Merge remote-tracking branch 'origin/master' into gav-staking-rewards
gavofyork Jun 24, 2018
2ac1ecd
Fix build & session logic, introduce tests
gavofyork Jun 24, 2018
bd41bbc
Fixed staking tests.
gavofyork Jun 24, 2018
9016bc6
Initial test for reward
gavofyork Jun 25, 2018
7a11706
Merge remote-tracking branch 'origin/master' into gav-staking-rewards
gavofyork Jun 25, 2018
f679c22
Fix test
gavofyork Jun 25, 2018
4fb942f
Tests for slashing
gavofyork Jun 25, 2018
4b19d28
Merge remote-tracking branch 'origin/master' into gav-staking-rewards
gavofyork Jun 25, 2018
1ac443b
Update/fix preset configs
gavofyork Jun 25, 2018
31284c3
Fix some tests.
gavofyork Jun 25, 2018
bc9ad04
Fix some staking tests
gavofyork Jun 25, 2018
bd1b4a4
Minor fix
gavofyork Jun 25, 2018
cdfa86b
minor cleanups
gavofyork Jun 25, 2018
3ce3ca7
Nominating.
gavofyork Jun 25, 2018
c2f95ca
Slash/reward nominators
gavofyork Jun 25, 2018
447538c
Tests for nominating + slash/reward
gavofyork Jun 25, 2018
8cd7914
Merge branch 'master' into gav-staking-rewards
gavofyork Jun 26, 2018
353f51c
Merge branch 'gav-staking-rewards' into gav-delegation
gavofyork Jun 26, 2018
fe75f9a
Fix build
gavofyork Jun 26, 2018
75e160f
Merge branch 'gav-staking-rewards' into gav-delegation
gavofyork Jun 26, 2018
5b92dc1
Rename timestamp::Value -> Moment
gavofyork Jun 27, 2018
924ca4b
Merge remote-tracking branch 'origin/master' into gav-staking-rewards
gavofyork Jun 27, 2018
a3e8fe2
Merge branch 'gav-staking-rewards' into gav-delegation
gavofyork Jun 27, 2018
217ecc1
Avoid double-nominating/staking
gavofyork Jun 28, 2018
71f2a9e
Fix comment
gavofyork Jun 28, 2018
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
6 changes: 6 additions & 0 deletions Cargo.lock

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

13 changes: 9 additions & 4 deletions demo/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ pub mod error;

use std::sync::Arc;
use demo_primitives::Hash;
use demo_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
SessionConfig, StakingConfig};
use demo_runtime::{Block, BlockId, UncheckedExtrinsic, BuildStorage};
use demo_runtime::{Block, BlockId, UncheckedExtrinsic, BuildStorage, GenesisConfig,
ConsensusConfig, CouncilConfig, DemocracyConfig, SessionConfig, StakingConfig,
TimestampConfig};
use futures::{Future, Sink, Stream};

struct DummyPool;
Expand Down Expand Up @@ -107,10 +107,10 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
authorities: vec![god_key.clone()],
}),
system: None,
// block_time: 5, // 5 second block time.
session: Some(SessionConfig {
validators: vec![god_key.clone().into()],
session_length: 720, // that's 1 hour per session.
broken_percent_late: 30,
}),
staking: Some(StakingConfig {
current_era: 0,
Expand All @@ -126,6 +126,8 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
validator_count: 12,
sessions_per_era: 24, // 24 hours per era.
bonding_duration: 90, // 90 days per bond.
early_era_slash: 10000,
session_reward: 100,
}),
democracy: Some(DemocracyConfig {
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
Expand All @@ -147,6 +149,9 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
}),
timestamp: Some(TimestampConfig {
period: 5, // 5 second block time.
}),
}.build_storage();

let client = Arc::new(client::new_in_mem::<_, Block, _>(executor, genesis_storage)?);
Expand Down
8 changes: 6 additions & 2 deletions demo/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ mod tests {
session: Some(SessionConfig {
session_length: 2,
validators: vec![One.to_raw_public().into(), Two.to_raw_public().into(), three],
broken_percent_late: 100,
}),
staking: Some(StakingConfig {
sessions_per_era: 2,
Expand All @@ -200,9 +201,12 @@ mod tests {
creation_fee: 0,
contract_fee: 0,
reclaim_rebate: 0,
early_era_slash: 0,
session_reward: 0,
}),
democracy: Some(Default::default()),
council: Some(Default::default()),
timestamp: Some(Default::default()),
}.build_storage()
}

Expand Down Expand Up @@ -238,7 +242,7 @@ mod tests {
construct_block(
1,
[69u8; 32].into(),
hex!("4f7a61bceecddc19d49fbee53f82402c2a8727c1b2aeb5e5070a59f0777a203b").into(),
hex!("786071057714fdd6ea4595eecd4a0f327908d65f462ff5bca0f700fafce588c9").into(),
vec![BareExtrinsic {
signed: alice(),
index: 0,
Expand All @@ -251,7 +255,7 @@ mod tests {
construct_block(
2,
block1().1,
hex!("67c588603dd727601263cf8d6138a2003ffc0df793c5ea34e7defc945da24bf0").into(),
hex!("a7f1259cc6b2fa758542f2996e737f8f0de9dec3a9d32641da348178f48b9fc2").into(),
vec![
BareExtrinsic {
signed: bob(),
Expand Down
6 changes: 4 additions & 2 deletions demo/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ impl consensus::Trait for Concrete {
pub type Consensus = consensus::Module<Concrete>;

impl timestamp::Trait for Concrete {
const SET_POSITION: u32 = 0;
const TIMESTAMP_SET_POSITION: u32 = 0;

type Value = u64;
type Moment = u64;
}

/// Timestamp module for this concrete runtime.
Expand All @@ -103,6 +103,7 @@ impl Convert<AccountId, SessionKey> for SessionKeyConversion {

impl session::Trait for Concrete {
type ConvertAccountIdToSessionKey = SessionKeyConversion;
type OnSessionChange = Staking;
}

/// Session module for this concrete runtime.
Expand Down Expand Up @@ -182,6 +183,7 @@ impl_outer_config! {
StakingConfig => staking,
DemocracyConfig => democracy,
CouncilConfig => council,
TimestampConfig => timestamp,
}
}

Expand Down
3 changes: 3 additions & 0 deletions demo/runtime/wasm/Cargo.lock

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

Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion polkadot/api/src/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<B: LocalBackend<Block>> PolkadotApi for Client<B, LocalCallExecutor<B, Nati
}

fn timestamp(&self, at: &CheckedId) -> Result<Timestamp> {
with_runtime!(self, at, ::runtime::Timestamp::now)
with_runtime!(self, at, ::runtime::Timestamp::get)
}

fn evaluate_block(&self, at: &CheckedId, block: Block) -> Result<bool> {
Expand Down Expand Up @@ -216,11 +216,13 @@ mod tests {
session: Some(SessionConfig {
validators: validators(),
session_length: 100,
broken_percent_late: 100,
}),
council: Some(Default::default()),
democracy: Some(Default::default()),
parachains: Some(Default::default()),
staking: Some(Default::default()),
timestamp: Some(Default::default()),
};

::client::new_in_mem(LocalDispatch::new(), genesis_config.build_storage()).unwrap()
Expand Down
42 changes: 27 additions & 15 deletions polkadot/cli/src/preset_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use serde_json;
use substrate_primitives::{AuthorityId, storage::{StorageKey, StorageData}};
use runtime_primitives::{MakeStorage, BuildStorage, StorageMap};
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
SessionConfig, StakingConfig};
SessionConfig, StakingConfig, TimestampConfig};
use chain_spec::ChainSpec;

enum Config {
Expand Down Expand Up @@ -98,7 +98,8 @@ impl PresetConfig {
system: None,
session: Some(SessionConfig {
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
session_length: 720, // that's 1 hour per session.
session_length: 60, // that's 5 minutes per session.
broken_percent_late: 50,
}),
staking: Some(StakingConfig {
current_era: 0,
Expand All @@ -110,32 +111,37 @@ impl PresetConfig {
creation_fee: 0,
contract_fee: 0,
reclaim_rebate: 0,
early_era_slash: 10000,
session_reward: 100,
balances: endowed_accounts.iter().map(|&k|(k, 1u128 << 60)).collect(),
validator_count: 12,
sessions_per_era: 24, // 24 hours per era.
bonding_duration: 90, // 90 days per bond.
sessions_per_era: 12, // 1 hour per era
bonding_duration: 24, // 1 day per bond.
}),
democracy: Some(DemocracyConfig {
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
launch_period: 12 * 60 * 24, // 1 day per public referendum
voting_period: 12 * 60 * 24 * 3, // 3 days to discuss & vote on an active referendum
minimum_deposit: 5000, // 12000 as the minimum deposit for a referendum
}),
council: Some(CouncilConfig {
active_council: vec![],
candidacy_bond: 1000, // 1000 to become a council candidate
voter_bond: 100, // 100 down to vote for a candidate
candidacy_bond: 5000, // 5000 to become a council candidate
voter_bond: 1000, // 1000 down to vote for a candidate
present_slash_per_voter: 1, // slash by 1 per voter for an invalid presentation.
carry_count: 24, // carry over the 24 runners-up to the next council election
presentation_duration: 120 * 24, // one day for presenting winners.
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
term_duration: 180 * 120 * 24, // 180 day term duration for the council.
carry_count: 6, // carry over the 6 runners-up to the next council election
presentation_duration: 12 * 60 * 24, // one day for presenting winners.
approval_voting_period: 12 * 60 * 24 * 2, // two days period between possible council elections.
term_duration: 12 * 60 * 24 * 24, // 24 day term duration for the council.
desired_seats: 0, // start with no council: we'll raise this once the stake has been dispersed a bit.
inactive_grace_period: 1, // one addition vote should go by before an inactive voter can be reaped.

cooloff_period: 90 * 120 * 24, // 90 day cooling off period if council member vetoes a proposal.
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
cooloff_period: 12 * 60 * 24 * 4, // 4 day cooling off period if council member vetoes a proposal.
voting_period: 12 * 60 * 24, // 1 day voting period for council members.
}),
parachains: Some(Default::default()),
timestamp: Some(TimestampConfig {
period: 5, // 5 second block time.
}),
});
let boot_nodes = vec![
"enode://a93a29fa68d965452bf0ff8c1910f5992fe2273a72a1ee8d3a3482f68512a61974211ba32bb33f051ceb1530b8ba3527fc36224ba6b9910329025e6d9153cf50@104.211.54.233:30333".into(),
Expand Down Expand Up @@ -163,6 +169,7 @@ impl PresetConfig {
session: Some(SessionConfig {
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
session_length: 10,
broken_percent_late: 30,
}),
staking: Some(StakingConfig {
current_era: 0,
Expand All @@ -178,6 +185,8 @@ impl PresetConfig {
validator_count: 2,
sessions_per_era: 5,
bonding_duration: 2,
early_era_slash: 0,
session_reward: 0,
}),
democracy: Some(DemocracyConfig {
launch_period: 9,
Expand All @@ -200,6 +209,9 @@ impl PresetConfig {
voting_period: 20,
}),
parachains: Some(Default::default()),
timestamp: Some(TimestampConfig {
period: 5, // 5 second block time.
}),
});
let boot_nodes = Vec::new();
PresetConfig { genesis_config, boot_nodes }
Expand Down
6 changes: 4 additions & 2 deletions polkadot/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ impl consensus::Trait for Concrete {
pub type Consensus = consensus::Module<Concrete>;

impl timestamp::Trait for Concrete {
const SET_POSITION: u32 = TIMESTAMP_SET_POSITION;
type Value = u64;
const TIMESTAMP_SET_POSITION: u32 = TIMESTAMP_SET_POSITION;
type Moment = u64;
}
/// Timestamp module for this concrete runtime.
pub type Timestamp = timestamp::Module<Concrete>;
Expand All @@ -142,6 +142,7 @@ impl Convert<AccountId, SessionKey> for SessionKeyConversion {

impl session::Trait for Concrete {
type ConvertAccountIdToSessionKey = SessionKeyConversion;
type OnSessionChange = Staking;
}
/// Session module for this concrete runtime.
pub type Session = session::Module<Concrete>;
Expand Down Expand Up @@ -213,6 +214,7 @@ impl_outer_config! {
StakingConfig => staking,
DemocracyConfig => democracy,
CouncilConfig => council,
TimestampConfig => timestamp,
ParachainsConfig => parachains,
}
}
Expand Down
10 changes: 8 additions & 2 deletions polkadot/runtime/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use rstd::marker::PhantomData;
#[cfg(any(feature = "std", test))]
use {runtime_io, runtime_primitives};

pub trait Trait: system::Trait<Hash = primitives::Hash> + session::Trait {
pub trait Trait: session::Trait<Hash = primitives::Hash> {
/// The position of the set_heads call in the block.
const SET_POSITION: u32;

Expand Down Expand Up @@ -232,7 +232,7 @@ mod tests {
use runtime_primitives::BuildStorage;
use runtime_primitives::traits::{HasPublicAux, Identity, BlakeTwo256};
use runtime_primitives::testing::{Digest, Header};
use consensus;
use {consensus, timestamp};

#[derive(Clone, Eq, PartialEq)]
pub struct Test;
Expand All @@ -254,6 +254,11 @@ mod tests {
}
impl session::Trait for Test {
type ConvertAccountIdToSessionKey = Identity;
type OnSessionChange = ();
}
impl timestamp::Trait for Test {
const TIMESTAMP_SET_POSITION: u32 = 0;
type Moment = u64;
}
impl Trait for Test {
const SET_POSITION: u32 = 0;
Expand All @@ -272,6 +277,7 @@ mod tests {
t.extend(session::GenesisConfig::<Test>{
session_length: 1000,
validators: vec![1, 2, 3, 4, 5, 6, 7, 8],
broken_percent_late: 100,
}.build_storage());
t.extend(GenesisConfig::<Test>{
parachains: parachains,
Expand Down
3 changes: 3 additions & 0 deletions polkadot/runtime/wasm/Cargo.lock

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

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading