Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
142f6ac
notify when an authority appears to have missed their block
rphmeier Aug 9, 2018
3f09f5c
Runtime API
gavofyork Aug 9, 2018
6095a6d
offline tracker
rphmeier Aug 9, 2018
21f40e5
Merge branch 'rh-note-offline-validator' of github.com:paritytech/pol…
rphmeier Aug 9, 2018
13a5e89
Move to consensus
gavofyork Aug 9, 2018
8c0fd55
Merge branch 'rh-note-offline-validator' of github.com:paritytech/pol…
gavofyork Aug 9, 2018
de23e91
generating reports of offline indices
rphmeier Aug 9, 2018
5433ef3
stubbed-out evaluation logic
rphmeier Aug 9, 2018
603e5a2
Slashing data pathwat
gavofyork Aug 9, 2018
08f598e
Merge branch 'rh-note-offline-validator' of github.com:paritytech/pol…
rphmeier Aug 9, 2018
4e2ceef
usize -> u32
rphmeier Aug 9, 2018
cff0577
Slash bad validators.
gavofyork Aug 9, 2018
825e1a4
Merge branch 'rh-note-offline-validator' of github.com:paritytech/pol…
gavofyork Aug 9, 2018
14b27cc
update to rhododendron 0.3
rphmeier Aug 9, 2018
00f23eb
Merge branch 'rh-note-offline-validator' of github.com:paritytech/pol…
rphmeier Aug 9, 2018
b827eec
fix compilation of polkadot-consensus
rphmeier Aug 9, 2018
6dd3524
Support offline noting in checked_block
gavofyork Aug 9, 2018
1cb58de
Merge branch 'rh-note-offline-validator' of github.com:paritytech/pol…
gavofyork Aug 9, 2018
241f28f
include offline reports in block authorship voting
rphmeier Aug 10, 2018
614b011
do not vote validators offline after some time
rphmeier Aug 10, 2018
b122ed4
add test for offline-tracker
rphmeier Aug 10, 2018
9724a69
fix test build
rphmeier Aug 10, 2018
60aadd3
bump spec version
rphmeier Aug 10, 2018
2fb0343
Merge remote-tracking branch 'upstream/master' into rh-note-offline-v…
rphmeier Aug 10, 2018
7602e59
update wasm
rphmeier Aug 10, 2018
922035d
Only allow validators that are possible to slash
gavofyork Aug 10, 2018
a6bea42
Fix grumble
tomusdrw Aug 3, 2018
a61396e
More idiomatic
gavofyork Aug 10, 2018
1d787e1
New Wasm.
gavofyork Aug 10, 2018
ab6957f
update rhododendron
rphmeier Aug 10, 2018
7696119
improve logging and reduce round time exponent
rphmeier Aug 10, 2018
2446ded
format offline validators in ss58
rphmeier Aug 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
include offline reports in block authorship voting
  • Loading branch information
rphmeier committed Aug 10, 2018
commit 241f28fb7b0226465626e0c99d55417ce8f91f09
15 changes: 9 additions & 6 deletions polkadot/api/src/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ use state_machine;

use runtime::Address;
use runtime_primitives::traits::AuxLookup;
use primitives::{AccountId, Block, Header, BlockId, Hash, Index, SessionKey, Timestamp, UncheckedExtrinsic};
use primitives::parachain::{CandidateReceipt, DutyRoster, Id as ParaId};
use primitives::{
AccountId, Block, Header, BlockId, Hash, Index, InherentData,
SessionKey, Timestamp, UncheckedExtrinsic,
};
use primitives::parachain::{DutyRoster, Id as ParaId};

use {BlockBuilder, PolkadotApi, LocalPolkadotApi, ErrorKind, Error, Result};

Expand Down Expand Up @@ -132,20 +135,20 @@ impl<B: LocalBackend<Block>> PolkadotApi for Client<B, LocalCallExecutor<B, Nati
with_runtime!(self, at, || ::runtime::Parachains::parachain_head(parachain))
}

fn build_block(&self, at: &BlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder> {
fn build_block(&self, at: &BlockId, inherent_data: InherentData) -> Result<Self::BlockBuilder> {
let mut block_builder = self.new_block_at(at)?;
for inherent in self.inherent_extrinsics(at, timestamp, new_heads)? {
for inherent in self.inherent_extrinsics(at, inherent_data)? {
block_builder.push(inherent)?;
}

Ok(block_builder)
}

fn inherent_extrinsics(&self, at: &BlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Vec<UncheckedExtrinsic>> {
fn inherent_extrinsics(&self, at: &BlockId, inherent_data: InherentData) -> Result<Vec<UncheckedExtrinsic>> {
use codec::{Encode, Decode};

with_runtime!(self, at, || {
let extrinsics = ::runtime::inherent_extrinsics(timestamp, new_heads);
let extrinsics = ::runtime::inherent_extrinsics(inherent_data);
extrinsics.into_iter()
.map(|x| x.encode()) // get encoded representation
.map(|x| Decode::decode(&mut &x[..])) // get byte-vec equivalent to extrinsic
Expand Down
12 changes: 7 additions & 5 deletions polkadot/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ extern crate substrate_keyring as keyring;
pub mod full;
pub mod light;

use primitives::{AccountId, Block, BlockId, Hash, Index, SessionKey, Timestamp,
UncheckedExtrinsic};
use primitives::{
AccountId, Block, BlockId, Hash, Index, SessionKey, Timestamp,
UncheckedExtrinsic, InherentData,
};
use runtime::Address;
use primitives::parachain::{CandidateReceipt, DutyRoster, Id as ParaId};
use primitives::parachain::{DutyRoster, Id as ParaId};

error_chain! {
errors {
Expand Down Expand Up @@ -128,11 +130,11 @@ pub trait PolkadotApi {
fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<bool>;

/// Build a block on top of the given, with inherent extrinsics pre-pushed.
fn build_block(&self, at: &BlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder>;
fn build_block(&self, at: &BlockId, inherent_data: InherentData) -> Result<Self::BlockBuilder>;

/// Attempt to produce the (encoded) inherent extrinsics for a block being built upon the given.
/// This may vary by runtime and will fail if a runtime doesn't follow the same API.
fn inherent_extrinsics(&self, at: &BlockId, timestamp: Timestamp, new_heads: Vec<CandidateReceipt>) -> Result<Vec<UncheckedExtrinsic>>;
fn inherent_extrinsics(&self, at: &BlockId, inherent_data: InherentData) -> Result<Vec<UncheckedExtrinsic>>;
}

/// Mark for all Polkadot API implementations, that are making use of state data, stored locally.
Expand Down
11 changes: 7 additions & 4 deletions polkadot/api/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ use std::sync::Arc;
use client::backend::{Backend, RemoteBackend};
use client::{Client, CallExecutor};
use codec::Decode;
use primitives::{AccountId, Block, BlockId, Hash, Index, SessionKey, Timestamp, UncheckedExtrinsic};
use primitives::{
AccountId, Block, BlockId, Hash, Index, InherentData,
SessionKey, Timestamp, UncheckedExtrinsic,
};
use runtime::Address;
use primitives::parachain::{CandidateReceipt, DutyRoster, Id as ParaId};
use primitives::parachain::{DutyRoster, Id as ParaId};
use {PolkadotApi, BlockBuilder, RemotePolkadotApi, Result, ErrorKind};

/// Light block builder. TODO: make this work (efficiently)
Expand Down Expand Up @@ -92,11 +95,11 @@ impl<B: Backend<Block>, E: CallExecutor<Block>> PolkadotApi for RemotePolkadotAp
Err(ErrorKind::UnknownRuntime.into())
}

fn build_block(&self, _at: &BlockId, _timestamp: Timestamp, _new_heads: Vec<CandidateReceipt>) -> Result<Self::BlockBuilder> {
fn build_block(&self, _at: &BlockId, _inherent: InherentData) -> Result<Self::BlockBuilder> {
Err(ErrorKind::UnknownRuntime.into())
}

fn inherent_extrinsics(&self, _at: &BlockId, _timestamp: Timestamp, _new_heads: Vec<CandidateReceipt>) -> Result<Vec<Vec<u8>>> {
fn inherent_extrinsics(&self, _at: &BlockId, _inherent: InherentData) -> Result<Vec<Vec<u8>>> {
Err(ErrorKind::UnknownRuntime.into())
}
}
Expand Down
51 changes: 31 additions & 20 deletions polkadot/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ use std::time::{Duration, Instant};
use codec::{Decode, Encode};
use extrinsic_store::Store as ExtrinsicStore;
use polkadot_api::PolkadotApi;
use polkadot_primitives::{Hash, Block, BlockId, BlockNumber, Header, Timestamp, SessionKey};
use polkadot_primitives::{AccountId, Hash, Block, BlockId, BlockNumber, Header, Timestamp, SessionKey};
use polkadot_primitives::parachain::{Id as ParaId, Chain, DutyRoster, BlockData, Extrinsic as ParachainExtrinsic, CandidateReceipt, CandidateSignature};
use primitives::AuthorityId;
use transaction_pool::TransactionPool;
Expand Down Expand Up @@ -339,6 +339,7 @@ impl<C, N, P> bft::Environment<Block> for ProposerFactory<C, N, P>
table,
transaction_pool: self.transaction_pool.clone(),
offline: self.offline.clone(),
validators,
_drop_signal: drop_signal,
};

Expand Down Expand Up @@ -417,6 +418,7 @@ pub struct Proposer<C: PolkadotApi> {
table: Arc<SharedTable>,
transaction_pool: Arc<TransactionPool<C>>,
offline: SharedOfflineTracker,
validators: Vec<AccountId>,
_drop_signal: exit_future::Signal,
}

Expand Down Expand Up @@ -467,6 +469,7 @@ impl<C> bft::Proposer<Block> for Proposer<C>
transaction_pool: self.transaction_pool.clone(),
table: self.table.clone(),
offline: self.offline.clone(),
validators: self.validators.clone(),
timing,
})
}
Expand Down Expand Up @@ -541,10 +544,12 @@ impl<C> bft::Proposer<Block> for Proposer<C>
includability_tracker.join(temporary_delay)
};

// let offline = block.get_offline_reports();
// if !self.offline.read().check_consistency(&validators[..], &offline[..]) {
// return futures::empty()
// }
// refuse to vote if this block says a validator is offline that we
// think isn't.
let offline = proposal.noted_offline();
if !self.offline.read().check_consistency(&self.validators[..], offline) {
return Box::new(futures::empty());
}

// evaluate whether the block is actually valid.
// TODO: is it better to delay this until the delays are finished?
Expand Down Expand Up @@ -639,23 +644,25 @@ impl<C> bft::Proposer<Block> for Proposer<C>
}

fn on_round_end(&self, round_number: usize, was_proposed: bool) {
let validators = match self.client.validators(&self.parent_id) {
Ok(v) => v,
Err(e) => {
warn!("Failed to fetch validator set: {:?}", e);
return
}
};

let primary_validator = validators[self.primary_index(round_number, validators.len())];
let primary_validator = self.validators[
self.primary_index(round_number, self.validators.len())
];

// alter the message based on whether we think the empty proposer was forced to skip the round.
// this is determined by checking if our local validator would have been forced to skip the round.
let consider_online = was_proposed || {
let forced_delay = self.dynamic_inclusion.acceptable_in(Instant::now(), self.table.includable_count());
match forced_delay {
None => info!("Potential Offline Validator: {:?} failed to propose during assigned slot: {}", primary_validator, round_number),
Some(_) => info!("Potential Offline Validator {:?} potentially forced to skip assigned slot: {}", primary_validator, round_number),
None => info!(
"Potential Offline Validator: {:?} failed to propose during assigned slot: {}",
primary_validator,
round_number,
),
Some(_) => info!(
"Potential Offline Validator {:?} potentially forced to skip assigned slot: {}",
primary_validator,
round_number,
),
}

forced_delay.is_some()
Expand Down Expand Up @@ -719,22 +726,26 @@ pub struct CreateProposal<C: PolkadotApi> {
transaction_pool: Arc<TransactionPool<C>>,
table: Arc<SharedTable>,
timing: ProposalTiming,
validators: Vec<AccountId>,
offline: SharedOfflineTracker,
}

impl<C> CreateProposal<C> where C: PolkadotApi {
fn propose_with(&self, candidates: Vec<CandidateReceipt>) -> Result<Block, Error> {
use polkadot_api::BlockBuilder;
use runtime_primitives::traits::{Hash as HashT, BlakeTwo256};
use polkadot_primitives::InherentData;

// TODO: handle case when current timestamp behind that in state.
let timestamp = current_timestamp();

// TODO: include reports into block.
let validators = self.client.validators(&self.parent_id)?;
let _reports = self.offline.read().reports(&validators[..]);
let inherent_data = InherentData {
timestamp,
parachain_heads: candidates,
offline_indices: self.offline.read().reports(&self.validators[..]),
};

let mut block_builder = self.client.build_block(&self.parent_id, timestamp, candidates)?;
let mut block_builder = self.client.build_block(&self.parent_id, inherent_data)?;

{
let mut unqueue_invalid = Vec::new();
Expand Down
11 changes: 11 additions & 0 deletions polkadot/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,14 @@ pub type BlockId = generic::BlockId<Block>;
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
pub struct Log(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);

/// Inherent data to include in a block.
#[derive(Encode, Decode)]
pub struct InherentData {
/// Current timestamp.
pub timestamp: Timestamp,
/// Parachain heads update.
pub parachain_heads: Vec<::parachain::CandidateReceipt>,
/// Indices of offline validators.
pub offline_indices: Vec<u32>,
}
6 changes: 3 additions & 3 deletions polkadot/runtime/src/checked_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ impl CheckedBlock {
}

/// Extract the noted offline validator indices (if any) from the block.
pub fn noted_offline(&self) -> Vec<u32> {
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.clone()),
Call::Session(SessionCall::note_offline(ref x)) => Some(&x[..]),
_ => None,
}).unwrap_or_else(Vec::new)
}).unwrap_or(&[])
}

/// Convert into inner block.
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,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()
);
Expand Down
43 changes: 23 additions & 20 deletions polkadot/runtime/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down