mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 03:41:06 +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
@@ -12,7 +12,6 @@ futures = "0.1"
|
||||
exit-future = "0.1"
|
||||
substrate-cli = { path = "../../core/cli" }
|
||||
parity-codec = { version = "2.1" }
|
||||
parking_lot = "0.4"
|
||||
slog = "^2"
|
||||
sr-io = { path = "../../core/sr-io" }
|
||||
substrate-client = { path = "../../core/client" }
|
||||
@@ -24,7 +23,6 @@ substrate-service = { path = "../../core/service" }
|
||||
substrate-transaction-pool = { path = "../../core/transaction-pool" }
|
||||
substrate-network = { path = "../../core/network" }
|
||||
substrate-consensus-aura = { path = "../../core/consensus/aura" }
|
||||
substrate-consensus-common = { path = "../../core/consensus/common" }
|
||||
substrate-finality-grandpa = { path = "../../core/finality-grandpa" }
|
||||
sr-primitives = { path = "../../core/sr-primitives" }
|
||||
node-executor = { path = "../executor" }
|
||||
|
||||
@@ -50,7 +50,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
const CENTS: u128 = 1_000 * MILLICENTS; // assume this is worth about a cent.
|
||||
const DOLLARS: u128 = 100 * CENTS;
|
||||
|
||||
const SECS_PER_BLOCK: u64 = 4;
|
||||
const SECS_PER_BLOCK: u64 = 6;
|
||||
const MINUTES: u64 = 60 / SECS_PER_BLOCK;
|
||||
const HOURS: u64 = MINUTES * 60;
|
||||
const DAYS: u64 = HOURS * 24;
|
||||
@@ -111,7 +111,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
enact_delay_period: 0,
|
||||
}),
|
||||
timestamp: Some(TimestampConfig {
|
||||
period: SECS_PER_BLOCK,
|
||||
period: SECS_PER_BLOCK / 2, // due to the nature of aura the slots are 2*period
|
||||
}),
|
||||
treasury: Some(TreasuryConfig {
|
||||
proposal_bond: Permill::from_percent(5),
|
||||
@@ -234,7 +234,7 @@ pub fn testnet_genesis(
|
||||
enact_delay_period: 0,
|
||||
}),
|
||||
timestamp: Some(TimestampConfig {
|
||||
period: 5, // 5 second block time.
|
||||
period: 2, // 2*2=4 second block time.
|
||||
}),
|
||||
treasury: Some(TreasuryConfig {
|
||||
proposal_bond: Permill::from_percent(5),
|
||||
|
||||
@@ -33,7 +33,6 @@ extern crate substrate_transaction_pool as transaction_pool;
|
||||
#[macro_use]
|
||||
extern crate substrate_network as network;
|
||||
extern crate substrate_consensus_aura as consensus;
|
||||
extern crate substrate_consensus_common as consensus_common;
|
||||
extern crate substrate_client as client;
|
||||
extern crate substrate_finality_grandpa as grandpa;
|
||||
extern crate node_primitives;
|
||||
@@ -45,7 +44,6 @@ extern crate substrate_keystore;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate structopt;
|
||||
extern crate parking_lot;
|
||||
|
||||
pub use cli::error;
|
||||
pub mod chain_spec;
|
||||
|
||||
@@ -21,22 +21,18 @@
|
||||
use std::sync::Arc;
|
||||
use transaction_pool::{self, txpool::{Pool as TransactionPool}};
|
||||
use node_runtime::{GenesisConfig, RuntimeApi};
|
||||
use node_primitives::Block;
|
||||
use node_primitives::{Block, InherentData};
|
||||
use substrate_service::{
|
||||
FactoryFullConfiguration, LightComponents, FullComponents, FullBackend,
|
||||
FullClient, LightClient, LightBackend, FullExecutor, LightExecutor, TaskExecutor
|
||||
};
|
||||
use node_executor;
|
||||
use consensus::{import_queue, start_aura, Config as AuraConfig, AuraImportQueue, NothingExtra};
|
||||
use consensus_common::offline_tracker::OfflineTracker;
|
||||
use consensus::{import_queue, start_aura, AuraImportQueue, SlotDuration, NothingExtra};
|
||||
use primitives::ed25519::Pair;
|
||||
use client;
|
||||
use std::time::Duration;
|
||||
use parking_lot::RwLock;
|
||||
use grandpa;
|
||||
|
||||
const AURA_SLOT_DURATION: u64 = 6;
|
||||
|
||||
construct_simple_protocol! {
|
||||
/// Demo protocol attachment for substrate.
|
||||
pub struct NodeProtocol where Block = Block { }
|
||||
@@ -105,15 +101,13 @@ construct_service_factory! {
|
||||
let proposer = Arc::new(substrate_service::ProposerFactory {
|
||||
client: service.client(),
|
||||
transaction_pool: service.transaction_pool(),
|
||||
offline: Arc::new(RwLock::new(OfflineTracker::new())),
|
||||
force_delay: 0 // FIXME: allow this to be configured https://github.com/paritytech/substrate/issues/1170
|
||||
});
|
||||
|
||||
let client = service.client();
|
||||
executor.spawn(start_aura(
|
||||
AuraConfig {
|
||||
local_key: Some(key),
|
||||
slot_duration: AURA_SLOT_DURATION,
|
||||
},
|
||||
service.client(),
|
||||
SlotDuration::get_or_compute(&*client)?,
|
||||
key,
|
||||
client,
|
||||
block_import.clone(),
|
||||
proposer,
|
||||
service.network(),
|
||||
@@ -124,31 +118,39 @@ construct_service_factory! {
|
||||
},
|
||||
LightService = LightComponents<Self>
|
||||
{ |config, executor| <LightComponents<Factory>>::new(config, executor) },
|
||||
FullImportQueue = AuraImportQueue<Self::Block, grandpa::BlockImportForService<Self>, NothingExtra>
|
||||
FullImportQueue = AuraImportQueue<
|
||||
Self::Block,
|
||||
grandpa::BlockImportForService<Self>,
|
||||
NothingExtra,
|
||||
::consensus::InherentProducingFn<InherentData>,
|
||||
>
|
||||
{ |config: &mut FactoryFullConfiguration<Self> , client: Arc<FullClient<Self>>| {
|
||||
let slot_duration = SlotDuration::get_or_compute(&*client)?;
|
||||
let (block_import, link_half) = grandpa::block_import::<_, _, _, RuntimeApi, FullClient<Self>>(client.clone(), client)?;
|
||||
let block_import = Arc::new(block_import);
|
||||
|
||||
config.custom.grandpa_import_setup = Some((block_import.clone(), link_half));
|
||||
|
||||
Ok(import_queue(
|
||||
AuraConfig {
|
||||
local_key: None,
|
||||
slot_duration: 5
|
||||
},
|
||||
slot_duration,
|
||||
block_import,
|
||||
NothingExtra,
|
||||
::consensus::make_basic_inherent as _,
|
||||
))
|
||||
}},
|
||||
LightImportQueue = AuraImportQueue<Self::Block, LightClient<Self>, NothingExtra>
|
||||
{ |ref mut config, client| Ok(
|
||||
import_queue(AuraConfig {
|
||||
local_key: None,
|
||||
slot_duration: 5
|
||||
},
|
||||
client,
|
||||
NothingExtra,
|
||||
))
|
||||
LightImportQueue = AuraImportQueue<
|
||||
Self::Block,
|
||||
LightClient<Self>,
|
||||
NothingExtra,
|
||||
::consensus::InherentProducingFn<InherentData>,
|
||||
>
|
||||
{ |ref mut config, client: Arc<LightClient<Self>>|
|
||||
Ok(import_queue(
|
||||
SlotDuration::get_or_compute(&*client)?,
|
||||
client,
|
||||
NothingExtra,
|
||||
::consensus::make_basic_inherent as _,
|
||||
))
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -165,7 +167,6 @@ mod tests {
|
||||
let bob: Arc<ed25519::Pair> = Arc::new(Keyring::Bob.into());
|
||||
let validators = vec![alice.public().0.into(), bob.public().0.into()];
|
||||
let keys: Vec<&ed25519::Pair> = vec![&*alice, &*bob];
|
||||
let offline = Arc::new(RwLock::new(OfflineTracker::new()));
|
||||
let dummy_runtime = ::tokio::runtime::Runtime::new().unwrap();
|
||||
let block_factory = |service: &<Factory as service::ServiceFactory>::FullService| {
|
||||
let block_id = BlockId::number(service.client().info().unwrap().chain.best_number);
|
||||
@@ -175,7 +176,6 @@ mod tests {
|
||||
client: service.client().clone(),
|
||||
transaction_pool: service.transaction_pool().clone(),
|
||||
network: consensus_net,
|
||||
offline: offline.clone(),
|
||||
force_delay: 0,
|
||||
handle: dummy_runtime.executor(),
|
||||
};
|
||||
|
||||
@@ -311,13 +311,13 @@ mod tests {
|
||||
1,
|
||||
GENESIS_HASH.into(),
|
||||
if support_changes_trie {
|
||||
hex!("7c00d30974b6d709766e5b231295b6b5ff7ffd42ef1385853c0a29859723d147").into()
|
||||
hex!("dd0ab9b04b84b2a0704a6c38968d97a41e693345a9019dae880a80cf8176676c").into()
|
||||
} else {
|
||||
hex!("e96a29fe7f7aba0e4a06837d4a5a4201f60bf613b9947ce5772559ef525f4268").into()
|
||||
hex!("f5d85f3baebdd85aff8acfdeab0c6e00322d8b64b10a277a0231f4ca10dca7ee").into()
|
||||
},
|
||||
if support_changes_trie {
|
||||
vec![changes_trie_log(
|
||||
hex!("1f8f44dcae8982350c14dee720d34b147e73279f5a2ce1f9781195a991970978").into(),
|
||||
hex!("cda28e5c630db8eb0e4309b58ce504597c6cbb59bda43fd65e96bb2be73a4586").into(),
|
||||
)]
|
||||
} else {
|
||||
vec![]
|
||||
@@ -339,7 +339,7 @@ mod tests {
|
||||
construct_block(
|
||||
2,
|
||||
block1(false).1,
|
||||
hex!("80e77e443da5f81fab7265acae6cbdfff79e02eaa90306d9dd14dabddad5f99d").into(),
|
||||
hex!("807f9952d1962fcc62e8ee58fb4a3b5dc0247f314e9920a25354c1a1915e6941").into(),
|
||||
vec![ // session changes here, so we add a grandpa change signal log.
|
||||
Log::from(::grandpa::RawLog::AuthoritiesChangeSignal(0, vec![
|
||||
(Keyring::One.to_raw_public().into(), 1),
|
||||
@@ -368,7 +368,7 @@ mod tests {
|
||||
construct_block(
|
||||
1,
|
||||
GENESIS_HASH.into(),
|
||||
hex!("337c94adf2041fa953d5afaf8919032e3b88ee440c88c48a231856306991dca1").into(),
|
||||
hex!("5cc895b7c1d5fa824a2b6aefdcf34088156b3762509050bc384853106d48c7e4").into(),
|
||||
vec![],
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
@@ -658,7 +658,7 @@ mod tests {
|
||||
let b = construct_block(
|
||||
1,
|
||||
GENESIS_HASH.into(),
|
||||
hex!("10cb18e5a4e000690aaa3e2f0165c1cc563d38eb6736aa79c5a0ea4868042671").into(),
|
||||
hex!("06d7654fe2799df26ef3ae932b04d17c163b5a89e6e5bc4ad514acced17bf6c4").into(),
|
||||
vec![],
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
|
||||
@@ -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