mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 07:31:08 +00:00
Update to Substrate master (#176)
* Update to master This introduces a new type `CollatorId`, currently just `SessionKey` but which would forseeably change to its own thing. It seems to work like this (despite there being a lot of the new-incompatible `AccountId` replaced). No idea if it does anything sensible, though. * Cleanups * Fix tests * Remove commented code * Specify commit hash * Remove commented code * Correct version * Update runtime/Cargo.toml Co-Authored-By: gavofyork <github@gavwood.com> * PairT instead of _Pair * Update lock file * Remove rev causing upset
This commit is contained in:
@@ -22,8 +22,9 @@
|
||||
use sr_primitives::traits::ProvideRuntimeApi;
|
||||
use substrate_network::Context as NetContext;
|
||||
use polkadot_validation::{Network as ParachainNetwork, SharedTable, Collators, Statement, GenericStatement};
|
||||
use polkadot_primitives::{AccountId, Block, Hash, SessionKey};
|
||||
use polkadot_primitives::parachain::{Id as ParaId, Collation, Extrinsic, ParachainHost, BlockData};
|
||||
use polkadot_primitives::{Block, Hash};
|
||||
use polkadot_primitives::parachain::{Id as ParaId, Collation, Extrinsic, ParachainHost, BlockData, ValidatorId,
|
||||
CollatorId};
|
||||
use codec::Decode;
|
||||
|
||||
use futures::prelude::*;
|
||||
@@ -208,7 +209,7 @@ impl<P, E, N, T> ParachainNetwork for ValidationNetwork<P, E, N, T> where
|
||||
&self,
|
||||
table: Arc<SharedTable>,
|
||||
outgoing: polkadot_validation::Outgoing,
|
||||
authorities: &[SessionKey],
|
||||
authorities: &[ValidatorId],
|
||||
) -> Self::TableRouter {
|
||||
let parent_hash = table.consensus_parent_hash().clone();
|
||||
|
||||
@@ -310,15 +311,15 @@ impl<P, E: Clone, N, T: Clone> Collators for ValidationNetwork<P, E, N, T> where
|
||||
}
|
||||
|
||||
|
||||
fn note_bad_collator(&self, collator: AccountId) {
|
||||
fn note_bad_collator(&self, collator: CollatorId) {
|
||||
self.network.with_spec(move |spec, ctx| spec.disconnect_bad_collator(ctx, collator));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct KnowledgeEntry {
|
||||
knows_block_data: Vec<SessionKey>,
|
||||
knows_extrinsic: Vec<SessionKey>,
|
||||
knows_block_data: Vec<ValidatorId>,
|
||||
knows_extrinsic: Vec<ValidatorId>,
|
||||
block_data: Option<BlockData>,
|
||||
extrinsic: Option<Extrinsic>,
|
||||
}
|
||||
@@ -337,19 +338,19 @@ impl Knowledge {
|
||||
}
|
||||
|
||||
/// Note a statement seen from another validator.
|
||||
pub(crate) fn note_statement(&mut self, from: SessionKey, statement: &Statement) {
|
||||
pub(crate) fn note_statement(&mut self, from: ValidatorId, statement: &Statement) {
|
||||
// those proposing the candidate or declaring it valid know everything.
|
||||
// those claiming it invalid do not have the extrinsic data as it is
|
||||
// generated by valid execution.
|
||||
match *statement {
|
||||
GenericStatement::Candidate(ref c) => {
|
||||
let mut entry = self.candidates.entry(c.hash()).or_insert_with(Default::default);
|
||||
entry.knows_block_data.push(from);
|
||||
entry.knows_block_data.push(from.clone());
|
||||
entry.knows_extrinsic.push(from);
|
||||
}
|
||||
GenericStatement::Valid(ref hash) => {
|
||||
let mut entry = self.candidates.entry(*hash).or_insert_with(Default::default);
|
||||
entry.knows_block_data.push(from);
|
||||
entry.knows_block_data.push(from.clone());
|
||||
entry.knows_extrinsic.push(from);
|
||||
}
|
||||
GenericStatement::Invalid(ref hash) => self.candidates.entry(*hash)
|
||||
@@ -370,12 +371,12 @@ impl Knowledge {
|
||||
/// A current validation session instance.
|
||||
pub(crate) struct ValidationSession {
|
||||
knowledge: Arc<Mutex<Knowledge>>,
|
||||
local_session_key: SessionKey,
|
||||
local_session_key: ValidatorId,
|
||||
}
|
||||
|
||||
impl ValidationSession {
|
||||
#[cfg(test)]
|
||||
pub(crate) fn new(knowledge: Arc<Mutex<Knowledge>>, local_session_key: SessionKey) -> Self {
|
||||
pub(crate) fn new(knowledge: Arc<Mutex<Knowledge>>, local_session_key: ValidatorId) -> Self {
|
||||
ValidationSession {
|
||||
knowledge,
|
||||
local_session_key
|
||||
@@ -385,7 +386,7 @@ impl ValidationSession {
|
||||
// execute a closure with locally stored block data for a candidate, or a slice of session identities
|
||||
// we believe should have the data.
|
||||
fn with_block_data<F, U>(&self, hash: &Hash, f: F) -> U
|
||||
where F: FnOnce(Result<&BlockData, &[SessionKey]>) -> U
|
||||
where F: FnOnce(Result<&BlockData, &[ValidatorId]>) -> U
|
||||
{
|
||||
let knowledge = self.knowledge.lock();
|
||||
let res = knowledge.candidates.get(hash)
|
||||
@@ -407,19 +408,19 @@ pub(crate) enum InsertedRecentKey {
|
||||
/// Key was already known.
|
||||
AlreadyKnown,
|
||||
/// Key was new and pushed out optional old item.
|
||||
New(Option<SessionKey>),
|
||||
New(Option<ValidatorId>),
|
||||
}
|
||||
|
||||
/// Wrapper for managing recent session keys.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct RecentSessionKeys {
|
||||
inner: ArrayVec<[SessionKey; RECENT_SESSIONS]>,
|
||||
pub(crate) struct RecentValidatorIds {
|
||||
inner: ArrayVec<[ValidatorId; RECENT_SESSIONS]>,
|
||||
}
|
||||
|
||||
impl RecentSessionKeys {
|
||||
impl RecentValidatorIds {
|
||||
/// Insert a new session key. This returns one to be pushed out if the
|
||||
/// set is full.
|
||||
pub(crate) fn insert(&mut self, key: SessionKey) -> InsertedRecentKey {
|
||||
pub(crate) fn insert(&mut self, key: ValidatorId) -> InsertedRecentKey {
|
||||
if self.inner.contains(&key) { return InsertedRecentKey::AlreadyKnown }
|
||||
|
||||
let old = if self.inner.len() == RECENT_SESSIONS {
|
||||
@@ -433,11 +434,11 @@ impl RecentSessionKeys {
|
||||
}
|
||||
|
||||
/// As a slice.
|
||||
pub(crate) fn as_slice(&self) -> &[SessionKey] {
|
||||
pub(crate) fn as_slice(&self) -> &[ValidatorId] {
|
||||
&*self.inner
|
||||
}
|
||||
|
||||
fn remove(&mut self, key: &SessionKey) {
|
||||
fn remove(&mut self, key: &ValidatorId) {
|
||||
self.inner.retain(|k| k != key)
|
||||
}
|
||||
}
|
||||
@@ -445,7 +446,7 @@ impl RecentSessionKeys {
|
||||
/// Manages requests and keys for live validation session instances.
|
||||
pub(crate) struct LiveValidationSessions {
|
||||
// recent local session keys.
|
||||
recent: RecentSessionKeys,
|
||||
recent: RecentValidatorIds,
|
||||
// live validation session instances, on `parent_hash`.
|
||||
live_instances: HashMap<Hash, ValidationSession>,
|
||||
}
|
||||
@@ -465,10 +466,10 @@ impl LiveValidationSessions {
|
||||
&mut self,
|
||||
parent_hash: Hash,
|
||||
session: ValidationSession,
|
||||
) -> Option<SessionKey> {
|
||||
let inserted_key = self.recent.insert(session.local_session_key);
|
||||
) -> Option<ValidatorId> {
|
||||
let inserted_key = self.recent.insert(session.local_session_key.clone());
|
||||
let maybe_new = if let InsertedRecentKey::New(_) = inserted_key {
|
||||
Some(session.local_session_key)
|
||||
Some(session.local_session_key.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -491,7 +492,7 @@ impl LiveValidationSessions {
|
||||
}
|
||||
|
||||
/// Recent session keys as a slice.
|
||||
pub(crate) fn recent_keys(&self) -> &[SessionKey] {
|
||||
pub(crate) fn recent_keys(&self) -> &[ValidatorId] {
|
||||
self.recent.as_slice()
|
||||
}
|
||||
|
||||
@@ -501,7 +502,7 @@ impl LiveValidationSessions {
|
||||
/// `Err(Some(keys))` when the session is live but the data unknown, with a list of keys
|
||||
/// who have the data, and `Err(None)` where the session is unknown.
|
||||
pub(crate) fn with_block_data<F, U>(&self, parent_hash: &Hash, c_hash: &Hash, f: F) -> U
|
||||
where F: FnOnce(Result<&BlockData, Option<&[SessionKey]>>) -> U
|
||||
where F: FnOnce(Result<&BlockData, Option<&[ValidatorId]>>) -> U
|
||||
{
|
||||
match self.live_instances.get(parent_hash) {
|
||||
Some(c) => c.with_block_data(c_hash, |res| f(res.map_err(Some))),
|
||||
@@ -513,27 +514,28 @@ impl LiveValidationSessions {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use substrate_primitives::crypto::UncheckedInto;
|
||||
|
||||
#[test]
|
||||
fn last_keys_works() {
|
||||
let a = [1; 32].into();
|
||||
let b = [2; 32].into();
|
||||
let c = [3; 32].into();
|
||||
let d = [4; 32].into();
|
||||
let a: ValidatorId = [1; 32].unchecked_into();
|
||||
let b: ValidatorId = [2; 32].unchecked_into();
|
||||
let c: ValidatorId = [3; 32].unchecked_into();
|
||||
let d: ValidatorId = [4; 32].unchecked_into();
|
||||
|
||||
let mut recent = RecentSessionKeys::default();
|
||||
let mut recent = RecentValidatorIds::default();
|
||||
|
||||
match recent.insert(a) {
|
||||
match recent.insert(a.clone()) {
|
||||
InsertedRecentKey::New(None) => {},
|
||||
_ => panic!("is new, not at capacity"),
|
||||
}
|
||||
|
||||
match recent.insert(a) {
|
||||
match recent.insert(a.clone()) {
|
||||
InsertedRecentKey::AlreadyKnown => {},
|
||||
_ => panic!("not new"),
|
||||
}
|
||||
|
||||
match recent.insert(b) {
|
||||
match recent.insert(b.clone()) {
|
||||
InsertedRecentKey::New(None) => {},
|
||||
_ => panic!("is new, not at capacity"),
|
||||
}
|
||||
@@ -543,7 +545,7 @@ mod tests {
|
||||
_ => panic!("not new"),
|
||||
}
|
||||
|
||||
match recent.insert(c) {
|
||||
match recent.insert(c.clone()) {
|
||||
InsertedRecentKey::New(None) => {},
|
||||
_ => panic!("is new, not at capacity"),
|
||||
}
|
||||
@@ -553,7 +555,7 @@ mod tests {
|
||||
_ => panic!("not new"),
|
||||
}
|
||||
|
||||
match recent.insert(d) {
|
||||
match recent.insert(d.clone()) {
|
||||
InsertedRecentKey::New(Some(old)) => assert_eq!(old, a),
|
||||
_ => panic!("is new, and at capacity"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user