mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Make AuthorityId generic (#1296)
* BlockAuthorityId convenience type * Rename AuthorityId -> Ed25519AuthorityId to make it more precise * Generalize AuthorityId up to substrate-client * Fix in client-db * rename: BlockAuthorityId -> AuthorityIdFor * typo: should be digest item * Fix test-runtime authorityId mismatch One states that AuthorityId is u64 while the other states that it's Ed25519AuthorityId. * Fix more u64 - Ed25519AuthorityId mismatch * Fix compile of most of the srml modules * Continue to pin aura and grandpa with ed25519 and fix compile * Add MaybeHash trait * Fix node-runtime compile * Fix network tests
This commit is contained in:
committed by
Benjamin Kampmann
parent
043831cfb0
commit
71d889b692
@@ -16,8 +16,7 @@
|
||||
|
||||
//! Block import helpers.
|
||||
|
||||
use primitives::AuthorityId;
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, DigestItemFor};
|
||||
use runtime_primitives::traits::{AuthorityIdFor, Block as BlockT, Header as HeaderT, DigestItemFor};
|
||||
use runtime_primitives::Justification;
|
||||
use std::borrow::Cow;
|
||||
|
||||
@@ -146,6 +145,6 @@ pub trait BlockImport<B: BlockT> {
|
||||
/// Import a Block alongside the new authorities valid form this block forward
|
||||
fn import_block(&self,
|
||||
block: ImportBlock<B>,
|
||||
new_authorities: Option<Vec<AuthorityId>>
|
||||
new_authorities: Option<Vec<AuthorityIdFor<B>>>
|
||||
) -> Result<ImportResult, Self::Error>;
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ error_chain! {
|
||||
}
|
||||
|
||||
/// Error checking signature
|
||||
InvalidSignature(s: ::primitives::ed25519::Signature, a: ::primitives::AuthorityId) {
|
||||
InvalidSignature(s: ::primitives::ed25519::Signature, a: ::primitives::Ed25519AuthorityId) {
|
||||
description("Message signature is invalid"),
|
||||
display("Message signature {:?} by {:?} is invalid.", s, a),
|
||||
}
|
||||
|
||||
/// Account is not an authority.
|
||||
InvalidAuthority(a: ::primitives::AuthorityId) {
|
||||
InvalidAuthority(a: ::primitives::Ed25519AuthorityId) {
|
||||
description("Message sender is not a valid authority"),
|
||||
display("Message sender {:?} is not a valid authority.", a),
|
||||
}
|
||||
|
||||
@@ -29,10 +29,9 @@ use std::collections::{HashSet, VecDeque};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use parking_lot::{Condvar, Mutex, RwLock};
|
||||
use primitives::AuthorityId;
|
||||
|
||||
use runtime_primitives::Justification;
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero, AuthorityIdFor};
|
||||
|
||||
use error::Error as ConsensusError;
|
||||
|
||||
@@ -68,7 +67,7 @@ pub trait Verifier<B: BlockT>: Send + Sync + Sized {
|
||||
header: B::Header,
|
||||
justification: Option<Justification>,
|
||||
body: Option<Vec<B::Extrinsic>>
|
||||
) -> Result<(ImportBlock<B>, Option<Vec<AuthorityId>>), String>;
|
||||
) -> Result<(ImportBlock<B>, Option<Vec<AuthorityIdFor<B>>>), String>;
|
||||
}
|
||||
|
||||
/// Blocks import queue API.
|
||||
|
||||
@@ -40,9 +40,8 @@ extern crate error_chain;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use primitives::{ed25519, AuthorityId};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::traits::Block;
|
||||
use runtime_primitives::traits::{AuthorityIdFor, Block};
|
||||
use futures::prelude::*;
|
||||
|
||||
pub mod offline_tracker;
|
||||
@@ -60,7 +59,7 @@ pub use block_import::{BlockImport, ImportBlock, BlockOrigin, ImportResult, Fork
|
||||
/// Trait for getting the authorities at a given block.
|
||||
pub trait Authorities<B: Block> {
|
||||
type Error: ::std::error::Error + Send + 'static; /// Get the authorities at the given block.
|
||||
fn authorities(&self, at: &BlockId<B>) -> Result<Vec<AuthorityId>, Self::Error>;
|
||||
fn authorities(&self, at: &BlockId<B>) -> Result<Vec<AuthorityIdFor<B>>, Self::Error>;
|
||||
}
|
||||
|
||||
/// Environment producer for a Consensus instance. Creates proposer instance and communication streams.
|
||||
@@ -71,9 +70,8 @@ pub trait Environment<B: Block, ConsensusData> {
|
||||
type Error: From<Error>;
|
||||
|
||||
/// Initialize the proposal logic on top of a specific header. Provide
|
||||
/// the authorities at that header, and a local key to sign any additional
|
||||
/// consensus messages with as well.
|
||||
fn init(&self, parent_header: &B::Header, authorities: &[AuthorityId], sign_with: Arc<ed25519::Pair>)
|
||||
/// the authorities at that header.
|
||||
fn init(&self, parent_header: &B::Header, authorities: &[AuthorityIdFor<B>])
|
||||
-> Result<Self::Proposer, Self::Error>;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
//! Tracks offline validators.
|
||||
|
||||
use primitives::AuthorityId;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::time::{Instant, Duration};
|
||||
|
||||
@@ -55,11 +53,11 @@ impl Observed {
|
||||
}
|
||||
|
||||
/// Tracks offline validators and can issue a report for those offline.
|
||||
pub struct OfflineTracker {
|
||||
pub struct OfflineTracker<AuthorityId> {
|
||||
observed: HashMap<AuthorityId, Observed>,
|
||||
}
|
||||
|
||||
impl OfflineTracker {
|
||||
impl<AuthorityId: Eq + Clone + std::hash::Hash> OfflineTracker<AuthorityId> {
|
||||
/// Create a new tracker.
|
||||
pub fn new() -> Self {
|
||||
OfflineTracker { observed: HashMap::new() }
|
||||
@@ -114,10 +112,11 @@ impl OfflineTracker {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use primitives::Ed25519AuthorityId;
|
||||
|
||||
#[test]
|
||||
fn validator_offline() {
|
||||
let mut tracker = OfflineTracker::new();
|
||||
let mut tracker = OfflineTracker::<Ed25519AuthorityId>::new();
|
||||
let v = [0; 32].into();
|
||||
let v2 = [1; 32].into();
|
||||
let v3 = [2; 32].into();
|
||||
|
||||
Reference in New Issue
Block a user