Slashing for voted-offline validators. (#541)

[Backport] Vote out offline authorities
This commit is contained in:
Robert Habermeier
2018-08-10 16:12:17 +02:00
committed by GitHub
parent b2451ca6cc
commit 539650c063
18 changed files with 355 additions and 61 deletions
+11 -1
View File
@@ -16,9 +16,10 @@
//! Typesafe block interaction.
use super::{Call, Block, TIMESTAMP_SET_POSITION, PARACHAINS_SET_POSITION};
use super::{Call, Block, TIMESTAMP_SET_POSITION, PARACHAINS_SET_POSITION, NOTE_OFFLINE_POSITION};
use timestamp::Call as TimestampCall;
use parachains::Call as ParachainsCall;
use session::Call as SessionCall;
use primitives::parachain::CandidateReceipt;
/// Provides a type-safe wrapper around a structurally valid block.
@@ -47,6 +48,7 @@ impl CheckedBlock {
});
if !has_heads { return Err(block) }
Ok(CheckedBlock {
inner: block,
file_line: None,
@@ -88,6 +90,14 @@ impl CheckedBlock {
}
}
/// Extract the noted offline validator indices (if any) from the block.
pub fn noted_offline(&self) -> &[u32] {
self.inner.extrinsics.get(NOTE_OFFLINE_POSITION as usize).and_then(|xt| match xt.extrinsic.function {
Call::Session(SessionCall::note_offline(ref x)) => Some(&x[..]),
_ => None,
}).unwrap_or(&[])
}
/// Convert into inner block.
pub fn into_inner(self) -> Block { self.inner }
}
+5 -2
View File
@@ -85,6 +85,8 @@ pub use primitives::Header;
pub const TIMESTAMP_SET_POSITION: u32 = 0;
/// The position of the parachains set extrinsic.
pub const PARACHAINS_SET_POSITION: u32 = 1;
/// The position of the offline nodes noting extrinsic.
pub const NOTE_OFFLINE_POSITION: u32 = 2;
/// The address format for describing accounts.
pub type Address = staking::Address<Concrete>;
@@ -110,7 +112,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: ver_str!("polkadot"),
impl_name: ver_str!("parity-polkadot"),
authoring_version: 1,
spec_version: 2,
spec_version: 3,
impl_version: 0,
};
@@ -160,6 +162,7 @@ impl Convert<AccountId, SessionKey> for SessionKeyConversion {
}
impl session::Trait for Concrete {
const NOTE_OFFLINE_POSITION: u32 = NOTE_OFFLINE_POSITION;
type ConvertAccountIdToSessionKey = SessionKeyConversion;
type OnSessionChange = Staking;
}
@@ -247,7 +250,7 @@ pub mod api {
apply_extrinsic => |extrinsic| super::Executive::apply_extrinsic(extrinsic),
execute_block => |block| super::Executive::execute_block(block),
finalise_block => |()| super::Executive::finalise_block(),
inherent_extrinsics => |(timestamp, heads)| super::inherent_extrinsics(timestamp, heads),
inherent_extrinsics => |inherent| super::inherent_extrinsics(inherent),
validator_count => |()| super::Session::validator_count(),
validators => |()| super::Session::validators()
);
+1
View File
@@ -265,6 +265,7 @@ mod tests {
type Header = Header;
}
impl session::Trait for Test {
const NOTE_OFFLINE_POSITION: u32 = 1;
type ConvertAccountIdToSessionKey = Identity;
type OnSessionChange = ();
}
+23 -20
View File
@@ -19,30 +19,33 @@
use rstd::prelude::*;
use super::{Call, UncheckedExtrinsic, Extrinsic, Staking};
use runtime_primitives::traits::{Checkable, AuxLookup};
use primitives::parachain::CandidateReceipt;
use timestamp::Call as TimestampCall;
use parachains::Call as ParachainsCall;
use session::Call as SessionCall;
/// Produces the list of inherent extrinsics.
pub fn inherent_extrinsics(timestamp: ::primitives::Timestamp, parachain_heads: Vec<CandidateReceipt>) -> Vec<UncheckedExtrinsic> {
vec![
UncheckedExtrinsic::new(
Extrinsic {
signed: Default::default(),
function: Call::Timestamp(TimestampCall::set(timestamp)),
index: 0,
},
Default::default()
),
UncheckedExtrinsic::new(
Extrinsic {
signed: Default::default(),
function: Call::Parachains(ParachainsCall::set_heads(parachain_heads)),
index: 0,
},
Default::default()
)
]
pub fn inherent_extrinsics(data: ::primitives::InherentData) -> Vec<UncheckedExtrinsic> {
let make_inherent = |function| UncheckedExtrinsic::new(
Extrinsic {
signed: Default::default(),
function,
index: 0,
},
Default::default(),
);
let mut inherent = vec![
make_inherent(Call::Timestamp(TimestampCall::set(data.timestamp))),
make_inherent(Call::Parachains(ParachainsCall::set_heads(data.parachain_heads))),
];
if !data.offline_indices.is_empty() {
inherent.push(make_inherent(
Call::Session(SessionCall::note_offline(data.offline_indices))
));
}
inherent
}
/// Checks an unchecked extrinsic for validity.