mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 19:07:57 +00:00
Punish offline validators, aura-style (#1216)
* make offline-reporting infrastructure more generic * add a listener-trait for watching when the timestamp has been set * prevent inclusion of empty offline reports * add test for exclusion * generate aura-offline reports * ability to slash many times for being offline "multiple" times * Logic for punishing validators for missing aura steps * stub tests * pave way for verification of timestamp vs slot * alter aura import queue to wait for timestamp * check timestamp matches seal * do inherent check properly * service compiles * all tests compile * test srml-aura logic * aura tests pass * everything builds * some more final tweaks to block authorship for aura * switch to manual delays before step * restore substrate-consensus-aura to always std and address grumbles * update some state roots in executor tests * node-executor tests pass * get most tests passing * address grumbles
This commit is contained in:
committed by
GitHub
parent
dcc38fe45a
commit
6299b42a4d
@@ -13,9 +13,10 @@ parity-codec-derive = "2.1"
|
||||
sr-std = { path = "../../core/sr-std" }
|
||||
srml-support = { path = "../../srml/support" }
|
||||
substrate-primitives = { path = "../../core/primitives" }
|
||||
substrate-finality-grandpa-primitives = { path = "../../core/finality-grandpa/primitives" }
|
||||
substrate-consensus-aura-primitives = { path = "../../core/consensus/aura/primitives", default-features = false }
|
||||
substrate-client = { path = "../../core/client" }
|
||||
substrate-keyring = { path = "../../core/keyring" }
|
||||
srml-aura = { path = "../../srml/aura" }
|
||||
srml-balances = { path = "../../srml/balances" }
|
||||
srml-consensus = { path = "../../srml/consensus" }
|
||||
srml-contract = { path = "../../srml/contract" }
|
||||
@@ -59,5 +60,5 @@ std = [
|
||||
"serde/std",
|
||||
"safe-mix/std",
|
||||
"substrate-client/std",
|
||||
"substrate-finality-grandpa-primitives/std",
|
||||
"substrate-consensus-aura-primitives/std",
|
||||
]
|
||||
|
||||
@@ -37,6 +37,7 @@ extern crate parity_codec_derive;
|
||||
extern crate parity_codec as codec;
|
||||
|
||||
extern crate sr_std as rstd;
|
||||
extern crate srml_aura as aura;
|
||||
extern crate srml_balances as balances;
|
||||
extern crate srml_consensus as consensus;
|
||||
extern crate srml_contract as contract;
|
||||
@@ -53,6 +54,7 @@ extern crate srml_upgrade_key as upgrade_key;
|
||||
#[macro_use]
|
||||
extern crate sr_version as version;
|
||||
extern crate node_primitives;
|
||||
extern crate substrate_consensus_aura_primitives as consensus_aura;
|
||||
|
||||
use rstd::prelude::*;
|
||||
use substrate_primitives::u32_trait::{_2, _4};
|
||||
@@ -76,6 +78,7 @@ use council::seats as council_seats;
|
||||
#[cfg(any(feature = "std", test))]
|
||||
use version::NativeVersion;
|
||||
use substrate_primitives::OpaqueMetadata;
|
||||
use consensus_aura::api as aura_api;
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub use runtime_primitives::BuildStorage;
|
||||
@@ -83,7 +86,6 @@ pub use consensus::Call as ConsensusCall;
|
||||
pub use timestamp::Call as TimestampCall;
|
||||
pub use balances::Call as BalancesCall;
|
||||
pub use runtime_primitives::{Permill, Perbill};
|
||||
pub use timestamp::BlockPeriod;
|
||||
pub use srml_support::{StorageValue, RuntimeMetadata};
|
||||
|
||||
const TIMESTAMP_SET_POSITION: u32 = 0;
|
||||
@@ -121,6 +123,10 @@ impl system::Trait for Runtime {
|
||||
type Log = Log;
|
||||
}
|
||||
|
||||
impl aura::Trait for Runtime {
|
||||
type HandleReport = aura::StakingSlasher<Runtime>;
|
||||
}
|
||||
|
||||
impl balances::Trait for Runtime {
|
||||
type Balance = Balance;
|
||||
type AccountIndex = AccountIndex;
|
||||
@@ -133,12 +139,16 @@ impl consensus::Trait for Runtime {
|
||||
const NOTE_OFFLINE_POSITION: u32 = NOTE_OFFLINE_POSITION;
|
||||
type Log = Log;
|
||||
type SessionKey = SessionKey;
|
||||
type OnOfflineValidator = Staking;
|
||||
|
||||
// the aura module handles offline-reports internally
|
||||
// rather than using an explicit report system.
|
||||
type InherentOfflineReport = ();
|
||||
}
|
||||
|
||||
impl timestamp::Trait for Runtime {
|
||||
const TIMESTAMP_SET_POSITION: u32 = TIMESTAMP_SET_POSITION;
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = Aura;
|
||||
}
|
||||
|
||||
/// Session key conversion.
|
||||
@@ -208,6 +218,7 @@ construct_runtime!(
|
||||
InherentData = BasicInherentData
|
||||
{
|
||||
System: system::{default, Log(ChangesTrieRoot)},
|
||||
Aura: aura::{Module},
|
||||
Timestamp: timestamp::{Module, Call, Storage, Config<T>, Inherent},
|
||||
Consensus: consensus::{Module, Call, Storage, Config<T>, Log(AuthoritiesChange), Inherent},
|
||||
Balances: balances,
|
||||
@@ -299,7 +310,26 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
fn check_inherents(block: Block, data: BasicInherentData) -> Result<(), CheckInherentError> {
|
||||
Runtime::check_inherents(block, data)
|
||||
let expected_slot = data.aura_expected_slot;
|
||||
|
||||
// draw timestamp out from extrinsics.
|
||||
let set_timestamp = block.extrinsics()
|
||||
.get(TIMESTAMP_SET_POSITION as usize)
|
||||
.and_then(|xt: &UncheckedExtrinsic| match xt.function {
|
||||
Call::Timestamp(TimestampCall::set(ref t)) => Some(t.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.ok_or_else(|| CheckInherentError::Other("No valid timestamp in block.".into()))?;
|
||||
|
||||
// take the "worse" result of normal verification and the timestamp vs. seal
|
||||
// check.
|
||||
CheckInherentError::combine_results(
|
||||
Runtime::check_inherents(block, data),
|
||||
|| {
|
||||
Aura::verify_inherent(set_timestamp.into(), expected_slot)
|
||||
.map_err(|s| CheckInherentError::Other(s.into()))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn random_seed() -> <Block as BlockT>::Hash {
|
||||
@@ -332,4 +362,10 @@ impl_runtime_apis! {
|
||||
Grandpa::grandpa_authorities()
|
||||
}
|
||||
}
|
||||
|
||||
impl aura_api::AuraApi<Block> for Runtime {
|
||||
fn slot_duration() -> u64 {
|
||||
Aura::slot_duration()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+34
@@ -507,6 +507,7 @@ dependencies = [
|
||||
"sr-primitives 0.1.0",
|
||||
"sr-std 0.1.0",
|
||||
"sr-version 0.1.0",
|
||||
"srml-aura 0.1.0",
|
||||
"srml-balances 0.1.0",
|
||||
"srml-consensus 0.1.0",
|
||||
"srml-contract 0.1.0",
|
||||
@@ -522,6 +523,7 @@ dependencies = [
|
||||
"srml-treasury 0.1.0",
|
||||
"srml-upgrade-key 0.1.0",
|
||||
"substrate-client 0.1.0",
|
||||
"substrate-consensus-aura-primitives 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
]
|
||||
|
||||
@@ -1063,6 +1065,25 @@ dependencies = [
|
||||
"sr-std 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "srml-aura"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec-derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-io 0.1.0",
|
||||
"sr-primitives 0.1.0",
|
||||
"sr-std 0.1.0",
|
||||
"srml-consensus 0.1.0",
|
||||
"srml-staking 0.1.0",
|
||||
"srml-support 0.1.0",
|
||||
"srml-system 0.1.0",
|
||||
"srml-timestamp 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "srml-balances"
|
||||
version = "0.1.0"
|
||||
@@ -1391,6 +1412,19 @@ dependencies = [
|
||||
"substrate-trie 0.4.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-consensus-aura-primitives"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"parity-codec 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-io 0.1.0",
|
||||
"sr-primitives 0.1.0",
|
||||
"sr-version 0.1.0",
|
||||
"srml-support 0.1.0",
|
||||
"substrate-client 0.1.0",
|
||||
"substrate-primitives 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-consensus-common"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -15,6 +15,7 @@ substrate-primitives = { path = "../../../core/primitives", default-features = f
|
||||
substrate-client = { path = "../../../core/client", default-features = false }
|
||||
sr-std = { path = "../../../core/sr-std", default-features = false }
|
||||
srml-support = { path = "../../../srml/support", default-features = false }
|
||||
srml-aura = { path = "../../../srml/aura", default-features = false }
|
||||
srml-balances = { path = "../../../srml/balances", default-features = false }
|
||||
srml-consensus = { path = "../../../srml/consensus", default-features = false }
|
||||
srml-contract = { path = "../../../srml/contract", default-features = false }
|
||||
@@ -31,6 +32,7 @@ srml-upgrade-key = { path = "../../../srml/upgrade-key", default-features = fals
|
||||
srml-grandpa = { path = "../../../srml/grandpa", default-features = false }
|
||||
sr-version = { path = "../../../core/sr-version", default-features = false }
|
||||
node-primitives = { path = "../../primitives", default-features = false }
|
||||
substrate-consensus-aura-primitives = { path = "../../../core/consensus/aura/primitives", default-features = false }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user