mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +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
@@ -19,23 +19,19 @@
|
||||
// FIXME: move this into substrate-consensus-common - https://github.com/paritytech/substrate/issues/1021
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::{self, Duration, Instant};
|
||||
use std::time;
|
||||
use std;
|
||||
|
||||
use client::{self, error, Client as SubstrateClient, CallExecutor};
|
||||
use client::{block_builder::api::BlockBuilder as BlockBuilderApi, runtime_api::Core};
|
||||
use codec::{Decode, Encode};
|
||||
use consensus_common::{self, evaluation, offline_tracker::OfflineTracker};
|
||||
use consensus_common::{self, evaluation};
|
||||
use primitives::{H256, AuthorityId, ed25519, Blake2Hasher};
|
||||
use runtime_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::BasicInherentData;
|
||||
use transaction_pool::txpool::{self, Pool as TransactionPool};
|
||||
|
||||
use parking_lot::RwLock;
|
||||
|
||||
/// Shared offline validator tracker.
|
||||
pub type SharedOfflineTracker = Arc<RwLock<OfflineTracker>>;
|
||||
type Timestamp = u64;
|
||||
|
||||
// block size limit.
|
||||
@@ -113,10 +109,6 @@ pub struct ProposerFactory<C, A> where A: txpool::ChainApi {
|
||||
pub client: Arc<C>,
|
||||
/// The transaction pool.
|
||||
pub transaction_pool: Arc<TransactionPool<A>>,
|
||||
/// Offline-tracker.
|
||||
pub offline: SharedOfflineTracker,
|
||||
/// Force delay in evaluation this long.
|
||||
pub force_delay: Timestamp,
|
||||
}
|
||||
|
||||
impl<C, A> consensus_common::Environment<<C as AuthoringApi>::Block> for ProposerFactory<C, A> where
|
||||
@@ -138,22 +130,14 @@ impl<C, A> consensus_common::Environment<<C as AuthoringApi>::Block> for Propose
|
||||
|
||||
let id = BlockId::hash(parent_hash);
|
||||
|
||||
let authorities: Vec<AuthorityId> = self.client.runtime_api().authorities(&id)?;
|
||||
self.offline.write().note_new_block(&authorities[..]);
|
||||
|
||||
info!("Starting consensus session on top of parent {:?}", parent_hash);
|
||||
|
||||
let now = Instant::now();
|
||||
let proposer = Proposer {
|
||||
client: self.client.clone(),
|
||||
start: now,
|
||||
parent_hash,
|
||||
parent_id: id,
|
||||
parent_number: *parent_header.number(),
|
||||
transaction_pool: self.transaction_pool.clone(),
|
||||
offline: self.offline.clone(),
|
||||
authorities,
|
||||
minimum_timestamp: current_timestamp() + self.force_delay,
|
||||
};
|
||||
|
||||
Ok(proposer)
|
||||
@@ -163,14 +147,10 @@ impl<C, A> consensus_common::Environment<<C as AuthoringApi>::Block> for Propose
|
||||
/// The proposer logic.
|
||||
pub struct Proposer<Block: BlockT, C, A: txpool::ChainApi> {
|
||||
client: Arc<C>,
|
||||
start: Instant,
|
||||
parent_hash: <Block as BlockT>::Hash,
|
||||
parent_id: BlockId<Block>,
|
||||
parent_number: <<Block as BlockT>::Header as HeaderT>::Number,
|
||||
transaction_pool: Arc<TransactionPool<A>>,
|
||||
offline: SharedOfflineTracker,
|
||||
authorities: Vec<AuthorityId>,
|
||||
minimum_timestamp: u64,
|
||||
}
|
||||
|
||||
impl<Block, C, A> consensus_common::Proposer<<C as AuthoringApi>::Block> for Proposer<Block, C, A> where
|
||||
@@ -186,24 +166,8 @@ impl<Block, C, A> consensus_common::Proposer<<C as AuthoringApi>::Block> for Pro
|
||||
fn propose(&self) -> Result<<C as AuthoringApi>::Block, error::Error> {
|
||||
use runtime_primitives::traits::BlakeTwo256;
|
||||
|
||||
const MAX_VOTE_OFFLINE_SECONDS: Duration = Duration::from_secs(60);
|
||||
|
||||
let timestamp = ::std::cmp::max(self.minimum_timestamp, current_timestamp());
|
||||
|
||||
let elapsed_since_start = self.start.elapsed();
|
||||
let offline_indices = if elapsed_since_start > MAX_VOTE_OFFLINE_SECONDS {
|
||||
Vec::new()
|
||||
} else {
|
||||
self.offline.read().reports(&self.authorities[..])
|
||||
};
|
||||
|
||||
if !offline_indices.is_empty() {
|
||||
info!("Submitting offline authorities {:?} for slash-vote",
|
||||
offline_indices.iter().map(|&i| self.authorities[i as usize]).collect::<Vec<_>>(),
|
||||
)
|
||||
}
|
||||
|
||||
let inherent_data = BasicInherentData::new(timestamp, offline_indices);
|
||||
let timestamp = current_timestamp();
|
||||
let inherent_data = BasicInherentData::new(timestamp, 0);
|
||||
|
||||
let block = self.client.build_block(
|
||||
&self.parent_id,
|
||||
|
||||
Reference in New Issue
Block a user