mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 15:11:02 +00:00
Rewards and slashing, early-exit of bad sessions (#234)
* Recompile runtime. * Introduce and enforce block time * Introduce early session ending. * Report most of staking module * rewards, proper early exit and slashing * Fix build & session logic, introduce tests * Fixed staking tests. * Initial test for reward * Fix test * Tests for slashing * Update/fix preset configs * Fix some tests. * Fix some staking tests * Minor fix * minor cleanups * Fix build * Rename timestamp::Value -> Moment * Require final block of session to be timely
This commit is contained in:
@@ -112,7 +112,7 @@ impl<B: LocalBackend<Block>> PolkadotApi for Client<B, LocalCallExecutor<B, Nati
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp(&self, at: &CheckedId) -> Result<Timestamp> {
|
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> {
|
fn evaluate_block(&self, at: &CheckedId, block: Block) -> Result<bool> {
|
||||||
@@ -216,11 +216,13 @@ mod tests {
|
|||||||
session: Some(SessionConfig {
|
session: Some(SessionConfig {
|
||||||
validators: validators(),
|
validators: validators(),
|
||||||
session_length: 100,
|
session_length: 100,
|
||||||
|
broken_percent_late: 100,
|
||||||
}),
|
}),
|
||||||
council: Some(Default::default()),
|
council: Some(Default::default()),
|
||||||
democracy: Some(Default::default()),
|
democracy: Some(Default::default()),
|
||||||
parachains: Some(Default::default()),
|
parachains: Some(Default::default()),
|
||||||
staking: Some(Default::default()),
|
staking: Some(Default::default()),
|
||||||
|
timestamp: Some(Default::default()),
|
||||||
};
|
};
|
||||||
|
|
||||||
::client::new_in_mem(LocalDispatch::new(), genesis_config.build_storage()).unwrap()
|
::client::new_in_mem(LocalDispatch::new(), genesis_config.build_storage()).unwrap()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use serde_json;
|
|||||||
use substrate_primitives::{AuthorityId, storage::{StorageKey, StorageData}};
|
use substrate_primitives::{AuthorityId, storage::{StorageKey, StorageData}};
|
||||||
use runtime_primitives::{MakeStorage, BuildStorage, StorageMap};
|
use runtime_primitives::{MakeStorage, BuildStorage, StorageMap};
|
||||||
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
|
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
|
||||||
SessionConfig, StakingConfig};
|
SessionConfig, StakingConfig, TimestampConfig};
|
||||||
use chain_spec::ChainSpec;
|
use chain_spec::ChainSpec;
|
||||||
|
|
||||||
enum Config {
|
enum Config {
|
||||||
@@ -98,7 +98,8 @@ impl PresetConfig {
|
|||||||
system: None,
|
system: None,
|
||||||
session: Some(SessionConfig {
|
session: Some(SessionConfig {
|
||||||
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
|
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 {
|
staking: Some(StakingConfig {
|
||||||
current_era: 0,
|
current_era: 0,
|
||||||
@@ -110,32 +111,37 @@ impl PresetConfig {
|
|||||||
creation_fee: 0,
|
creation_fee: 0,
|
||||||
contract_fee: 0,
|
contract_fee: 0,
|
||||||
reclaim_rebate: 0,
|
reclaim_rebate: 0,
|
||||||
|
early_era_slash: 10000,
|
||||||
|
session_reward: 100,
|
||||||
balances: endowed_accounts.iter().map(|&k|(k, 1u128 << 60)).collect(),
|
balances: endowed_accounts.iter().map(|&k|(k, 1u128 << 60)).collect(),
|
||||||
validator_count: 12,
|
validator_count: 12,
|
||||||
sessions_per_era: 24, // 24 hours per era.
|
sessions_per_era: 12, // 1 hour per era
|
||||||
bonding_duration: 90, // 90 days per bond.
|
bonding_duration: 24, // 1 day per bond.
|
||||||
}),
|
}),
|
||||||
democracy: Some(DemocracyConfig {
|
democracy: Some(DemocracyConfig {
|
||||||
launch_period: 120 * 24 * 14, // 2 weeks per public referendum
|
launch_period: 12 * 60 * 24, // 1 day per public referendum
|
||||||
voting_period: 120 * 24 * 28, // 4 weeks to discuss & vote on an active referendum
|
voting_period: 12 * 60 * 24 * 3, // 3 days to discuss & vote on an active referendum
|
||||||
minimum_deposit: 1000, // 1000 as the minimum deposit for a referendum
|
minimum_deposit: 5000, // 12000 as the minimum deposit for a referendum
|
||||||
}),
|
}),
|
||||||
council: Some(CouncilConfig {
|
council: Some(CouncilConfig {
|
||||||
active_council: vec![],
|
active_council: vec![],
|
||||||
candidacy_bond: 1000, // 1000 to become a council candidate
|
candidacy_bond: 5000, // 5000 to become a council candidate
|
||||||
voter_bond: 100, // 100 down to vote for a 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.
|
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
|
carry_count: 6, // carry over the 6 runners-up to the next council election
|
||||||
presentation_duration: 120 * 24, // one day for presenting winners.
|
presentation_duration: 12 * 60 * 24, // one day for presenting winners.
|
||||||
approval_voting_period: 7 * 120 * 24, // one week period between possible council elections.
|
approval_voting_period: 12 * 60 * 24 * 2, // two days period between possible council elections.
|
||||||
term_duration: 180 * 120 * 24, // 180 day term duration for the council.
|
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.
|
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.
|
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.
|
cooloff_period: 12 * 60 * 24 * 4, // 4 day cooling off period if council member vetoes a proposal.
|
||||||
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
|
voting_period: 12 * 60 * 24, // 1 day voting period for council members.
|
||||||
}),
|
}),
|
||||||
parachains: Some(Default::default()),
|
parachains: Some(Default::default()),
|
||||||
|
timestamp: Some(TimestampConfig {
|
||||||
|
period: 5, // 5 second block time.
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
let boot_nodes = vec![
|
let boot_nodes = vec![
|
||||||
"enode://a93a29fa68d965452bf0ff8c1910f5992fe2273a72a1ee8d3a3482f68512a61974211ba32bb33f051ceb1530b8ba3527fc36224ba6b9910329025e6d9153cf50@104.211.54.233:30333".into(),
|
"enode://a93a29fa68d965452bf0ff8c1910f5992fe2273a72a1ee8d3a3482f68512a61974211ba32bb33f051ceb1530b8ba3527fc36224ba6b9910329025e6d9153cf50@104.211.54.233:30333".into(),
|
||||||
@@ -163,6 +169,7 @@ impl PresetConfig {
|
|||||||
session: Some(SessionConfig {
|
session: Some(SessionConfig {
|
||||||
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
|
validators: initial_authorities.iter().cloned().map(Into::into).collect(),
|
||||||
session_length: 10,
|
session_length: 10,
|
||||||
|
broken_percent_late: 30,
|
||||||
}),
|
}),
|
||||||
staking: Some(StakingConfig {
|
staking: Some(StakingConfig {
|
||||||
current_era: 0,
|
current_era: 0,
|
||||||
@@ -178,6 +185,8 @@ impl PresetConfig {
|
|||||||
validator_count: 2,
|
validator_count: 2,
|
||||||
sessions_per_era: 5,
|
sessions_per_era: 5,
|
||||||
bonding_duration: 2,
|
bonding_duration: 2,
|
||||||
|
early_era_slash: 0,
|
||||||
|
session_reward: 0,
|
||||||
}),
|
}),
|
||||||
democracy: Some(DemocracyConfig {
|
democracy: Some(DemocracyConfig {
|
||||||
launch_period: 9,
|
launch_period: 9,
|
||||||
@@ -200,6 +209,9 @@ impl PresetConfig {
|
|||||||
voting_period: 20,
|
voting_period: 20,
|
||||||
}),
|
}),
|
||||||
parachains: Some(Default::default()),
|
parachains: Some(Default::default()),
|
||||||
|
timestamp: Some(TimestampConfig {
|
||||||
|
period: 5, // 5 second block time.
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
let boot_nodes = Vec::new();
|
let boot_nodes = Vec::new();
|
||||||
PresetConfig { genesis_config, boot_nodes }
|
PresetConfig { genesis_config, boot_nodes }
|
||||||
|
|||||||
@@ -126,8 +126,8 @@ impl consensus::Trait for Concrete {
|
|||||||
pub type Consensus = consensus::Module<Concrete>;
|
pub type Consensus = consensus::Module<Concrete>;
|
||||||
|
|
||||||
impl timestamp::Trait for Concrete {
|
impl timestamp::Trait for Concrete {
|
||||||
const SET_POSITION: u32 = TIMESTAMP_SET_POSITION;
|
const TIMESTAMP_SET_POSITION: u32 = TIMESTAMP_SET_POSITION;
|
||||||
type Value = u64;
|
type Moment = u64;
|
||||||
}
|
}
|
||||||
/// Timestamp module for this concrete runtime.
|
/// Timestamp module for this concrete runtime.
|
||||||
pub type Timestamp = timestamp::Module<Concrete>;
|
pub type Timestamp = timestamp::Module<Concrete>;
|
||||||
@@ -142,6 +142,7 @@ impl Convert<AccountId, SessionKey> for SessionKeyConversion {
|
|||||||
|
|
||||||
impl session::Trait for Concrete {
|
impl session::Trait for Concrete {
|
||||||
type ConvertAccountIdToSessionKey = SessionKeyConversion;
|
type ConvertAccountIdToSessionKey = SessionKeyConversion;
|
||||||
|
type OnSessionChange = Staking;
|
||||||
}
|
}
|
||||||
/// Session module for this concrete runtime.
|
/// Session module for this concrete runtime.
|
||||||
pub type Session = session::Module<Concrete>;
|
pub type Session = session::Module<Concrete>;
|
||||||
@@ -213,6 +214,7 @@ impl_outer_config! {
|
|||||||
StakingConfig => staking,
|
StakingConfig => staking,
|
||||||
DemocracyConfig => democracy,
|
DemocracyConfig => democracy,
|
||||||
CouncilConfig => council,
|
CouncilConfig => council,
|
||||||
|
TimestampConfig => timestamp,
|
||||||
ParachainsConfig => parachains,
|
ParachainsConfig => parachains,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ use rstd::marker::PhantomData;
|
|||||||
#[cfg(any(feature = "std", test))]
|
#[cfg(any(feature = "std", test))]
|
||||||
use {runtime_io, runtime_primitives};
|
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.
|
/// The position of the set_heads call in the block.
|
||||||
const SET_POSITION: u32;
|
const SET_POSITION: u32;
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ mod tests {
|
|||||||
use runtime_primitives::BuildStorage;
|
use runtime_primitives::BuildStorage;
|
||||||
use runtime_primitives::traits::{HasPublicAux, Identity, BlakeTwo256};
|
use runtime_primitives::traits::{HasPublicAux, Identity, BlakeTwo256};
|
||||||
use runtime_primitives::testing::{Digest, Header};
|
use runtime_primitives::testing::{Digest, Header};
|
||||||
use consensus;
|
use {consensus, timestamp};
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq)]
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
pub struct Test;
|
pub struct Test;
|
||||||
@@ -254,6 +254,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
impl session::Trait for Test {
|
impl session::Trait for Test {
|
||||||
type ConvertAccountIdToSessionKey = Identity;
|
type ConvertAccountIdToSessionKey = Identity;
|
||||||
|
type OnSessionChange = ();
|
||||||
|
}
|
||||||
|
impl timestamp::Trait for Test {
|
||||||
|
const TIMESTAMP_SET_POSITION: u32 = 0;
|
||||||
|
type Moment = u64;
|
||||||
}
|
}
|
||||||
impl Trait for Test {
|
impl Trait for Test {
|
||||||
const SET_POSITION: u32 = 0;
|
const SET_POSITION: u32 = 0;
|
||||||
@@ -272,6 +277,7 @@ mod tests {
|
|||||||
t.extend(session::GenesisConfig::<Test>{
|
t.extend(session::GenesisConfig::<Test>{
|
||||||
session_length: 1000,
|
session_length: 1000,
|
||||||
validators: vec![1, 2, 3, 4, 5, 6, 7, 8],
|
validators: vec![1, 2, 3, 4, 5, 6, 7, 8],
|
||||||
|
broken_percent_late: 100,
|
||||||
}.build_storage());
|
}.build_storage());
|
||||||
t.extend(GenesisConfig::<Test>{
|
t.extend(GenesisConfig::<Test>{
|
||||||
parachains: parachains,
|
parachains: parachains,
|
||||||
|
|||||||
Generated
+3
@@ -905,6 +905,7 @@ dependencies = [
|
|||||||
"substrate-runtime-std 0.1.0",
|
"substrate-runtime-std 0.1.0",
|
||||||
"substrate-runtime-support 0.1.0",
|
"substrate-runtime-support 0.1.0",
|
||||||
"substrate-runtime-system 0.1.0",
|
"substrate-runtime-system 0.1.0",
|
||||||
|
"substrate-runtime-timestamp 0.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -927,6 +928,7 @@ dependencies = [
|
|||||||
"substrate-runtime-std 0.1.0",
|
"substrate-runtime-std 0.1.0",
|
||||||
"substrate-runtime-support 0.1.0",
|
"substrate-runtime-support 0.1.0",
|
||||||
"substrate-runtime-system 0.1.0",
|
"substrate-runtime-system 0.1.0",
|
||||||
|
"substrate-runtime-timestamp 0.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -977,6 +979,7 @@ dependencies = [
|
|||||||
"serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"substrate-codec 0.1.0",
|
"substrate-codec 0.1.0",
|
||||||
"substrate-primitives 0.1.0",
|
"substrate-primitives 0.1.0",
|
||||||
|
"substrate-runtime-consensus 0.1.0",
|
||||||
"substrate-runtime-io 0.1.0",
|
"substrate-runtime-io 0.1.0",
|
||||||
"substrate-runtime-primitives 0.1.0",
|
"substrate-runtime-primitives 0.1.0",
|
||||||
"substrate-runtime-std 0.1.0",
|
"substrate-runtime-std 0.1.0",
|
||||||
|
|||||||
BIN
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user