mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 07:45:49 +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:
@@ -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;
|
||||
@@ -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,
|
||||
@@ -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
|
||||
@@ -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)?);
|
||||
|
||||
@@ -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,
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -238,7 +242,7 @@ mod tests {
|
||||
construct_block(
|
||||
1,
|
||||
[69u8; 32].into(),
|
||||
hex!("4f7a61bceecddc19d49fbee53f82402c2a8727c1b2aeb5e5070a59f0777a203b").into(),
|
||||
hex!("786071057714fdd6ea4595eecd4a0f327908d65f462ff5bca0f700fafce588c9").into(),
|
||||
vec![BareExtrinsic {
|
||||
signed: alice(),
|
||||
index: 0,
|
||||
@@ -251,7 +255,7 @@ mod tests {
|
||||
construct_block(
|
||||
2,
|
||||
block1().1,
|
||||
hex!("67c588603dd727601263cf8d6138a2003ffc0df793c5ea34e7defc945da24bf0").into(),
|
||||
hex!("a7f1259cc6b2fa758542f2996e737f8f0de9dec3a9d32641da348178f48b9fc2").into(),
|
||||
vec![
|
||||
BareExtrinsic {
|
||||
signed: bob(),
|
||||
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
@@ -182,6 +183,7 @@ impl_outer_config! {
|
||||
StakingConfig => staking,
|
||||
DemocracyConfig => democracy,
|
||||
CouncilConfig => council,
|
||||
TimestampConfig => timestamp,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Generated
+3
@@ -905,6 +905,7 @@ dependencies = [
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-runtime-support 0.1.0",
|
||||
"substrate-runtime-system 0.1.0",
|
||||
"substrate-runtime-timestamp 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -927,6 +928,7 @@ dependencies = [
|
||||
"substrate-runtime-std 0.1.0",
|
||||
"substrate-runtime-support 0.1.0",
|
||||
"substrate-runtime-system 0.1.0",
|
||||
"substrate-runtime-timestamp 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -977,6 +979,7 @@ dependencies = [
|
||||
"serde_derive 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"substrate-codec 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
"substrate-runtime-consensus 0.1.0",
|
||||
"substrate-runtime-io 0.1.0",
|
||||
"substrate-runtime-primitives 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