mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 16:01:04 +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
@@ -17,7 +17,7 @@
|
||||
//! Utilities for dealing with authorities, authority sets, and handoffs.
|
||||
|
||||
use parking_lot::RwLock;
|
||||
use substrate_primitives::AuthorityId;
|
||||
use substrate_primitives::Ed25519AuthorityId;
|
||||
|
||||
use std::cmp::Ord;
|
||||
use std::collections::HashMap;
|
||||
@@ -38,7 +38,7 @@ impl<H, N> Clone for SharedAuthoritySet<H, N> {
|
||||
|
||||
impl<H, N> SharedAuthoritySet<H, N> {
|
||||
/// The genesis authority set.
|
||||
pub(crate) fn genesis(initial: Vec<(AuthorityId, u64)>) -> Self {
|
||||
pub(crate) fn genesis(initial: Vec<(Ed25519AuthorityId, u64)>) -> Self {
|
||||
SharedAuthoritySet {
|
||||
inner: Arc::new(RwLock::new(AuthoritySet::genesis(initial)))
|
||||
}
|
||||
@@ -66,7 +66,7 @@ where
|
||||
}
|
||||
|
||||
/// Get the current authorities and their weights (for the current set ID).
|
||||
pub(crate) fn current_authorities(&self) -> HashMap<AuthorityId, u64> {
|
||||
pub(crate) fn current_authorities(&self) -> HashMap<Ed25519AuthorityId, u64> {
|
||||
self.inner.read().current_authorities.iter().cloned().collect()
|
||||
}
|
||||
}
|
||||
@@ -89,14 +89,14 @@ pub(crate) struct Status<H, N> {
|
||||
/// A set of authorities.
|
||||
#[derive(Debug, Clone, Encode, Decode)]
|
||||
pub(crate) struct AuthoritySet<H, N> {
|
||||
current_authorities: Vec<(AuthorityId, u64)>,
|
||||
current_authorities: Vec<(Ed25519AuthorityId, u64)>,
|
||||
set_id: u64,
|
||||
pending_changes: Vec<PendingChange<H, N>>,
|
||||
}
|
||||
|
||||
impl<H, N> AuthoritySet<H, N> {
|
||||
/// Get a genesis set with given authorities.
|
||||
pub(crate) fn genesis(initial: Vec<(AuthorityId, u64)>) -> Self {
|
||||
pub(crate) fn genesis(initial: Vec<(Ed25519AuthorityId, u64)>) -> Self {
|
||||
AuthoritySet {
|
||||
current_authorities: initial,
|
||||
set_id: 0,
|
||||
@@ -105,7 +105,7 @@ impl<H, N> AuthoritySet<H, N> {
|
||||
}
|
||||
|
||||
/// Get the current set id and a reference to the current authority set.
|
||||
pub(crate) fn current(&self) -> (u64, &[(AuthorityId, u64)]) {
|
||||
pub(crate) fn current(&self) -> (u64, &[(Ed25519AuthorityId, u64)]) {
|
||||
(self.set_id, &self.current_authorities[..])
|
||||
}
|
||||
}
|
||||
@@ -249,7 +249,7 @@ where
|
||||
#[derive(Debug, Clone, Encode, Decode, PartialEq)]
|
||||
pub(crate) struct PendingChange<H, N> {
|
||||
/// The new authorities and weights to apply.
|
||||
pub(crate) next_authorities: Vec<(AuthorityId, u64)>,
|
||||
pub(crate) next_authorities: Vec<(Ed25519AuthorityId, u64)>,
|
||||
/// How deep in the finalized chain the announcing block must be
|
||||
/// before the change is applied.
|
||||
pub(crate) finalization_depth: N,
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
use futures::prelude::*;
|
||||
use futures::sync::mpsc;
|
||||
use codec::{Encode, Decode};
|
||||
use substrate_primitives::{ed25519, AuthorityId};
|
||||
use substrate_primitives::{ed25519, Ed25519AuthorityId};
|
||||
use runtime_primitives::traits::Block as BlockT;
|
||||
use {Error, Network, Message, SignedMessage, Commit, CompactCommit};
|
||||
|
||||
@@ -34,7 +34,7 @@ fn localized_payload<E: Encode>(round: u64, set_id: u64, message: &E) -> Vec<u8>
|
||||
// check a message.
|
||||
pub(crate) fn check_message_sig<Block: BlockT>(
|
||||
message: &Message<Block>,
|
||||
id: &AuthorityId,
|
||||
id: &Ed25519AuthorityId,
|
||||
signature: &ed25519::Signature,
|
||||
round: u64,
|
||||
set_id: u64,
|
||||
@@ -55,7 +55,7 @@ pub(crate) fn checked_message_stream<Block: BlockT, S>(
|
||||
round: u64,
|
||||
set_id: u64,
|
||||
inner: S,
|
||||
voters: Arc<HashMap<AuthorityId, u64>>,
|
||||
voters: Arc<HashMap<Ed25519AuthorityId, u64>>,
|
||||
)
|
||||
-> impl Stream<Item=SignedMessage<Block>,Error=Error> where
|
||||
S: Stream<Item=Vec<u8>,Error=()>
|
||||
@@ -92,7 +92,7 @@ pub(crate) fn checked_message_stream<Block: BlockT, S>(
|
||||
struct OutgoingMessages<Block: BlockT, N: Network> {
|
||||
round: u64,
|
||||
set_id: u64,
|
||||
locals: Option<(Arc<ed25519::Pair>, AuthorityId)>,
|
||||
locals: Option<(Arc<ed25519::Pair>, Ed25519AuthorityId)>,
|
||||
sender: mpsc::UnboundedSender<SignedMessage<Block>>,
|
||||
network: N,
|
||||
}
|
||||
@@ -143,7 +143,7 @@ pub(crate) fn outgoing_messages<Block: BlockT, N: Network>(
|
||||
round: u64,
|
||||
set_id: u64,
|
||||
local_key: Option<Arc<ed25519::Pair>>,
|
||||
voters: Arc<HashMap<AuthorityId, u64>>,
|
||||
voters: Arc<HashMap<Ed25519AuthorityId, u64>>,
|
||||
network: N,
|
||||
) -> (
|
||||
impl Stream<Item=SignedMessage<Block>,Error=Error>,
|
||||
@@ -151,7 +151,7 @@ pub(crate) fn outgoing_messages<Block: BlockT, N: Network>(
|
||||
) {
|
||||
let locals = local_key.and_then(|pair| {
|
||||
let public = pair.public();
|
||||
let id = AuthorityId(public.0);
|
||||
let id = Ed25519AuthorityId(public.0);
|
||||
if voters.contains_key(&id) {
|
||||
Some((pair, id))
|
||||
} else {
|
||||
@@ -177,7 +177,7 @@ pub(crate) fn outgoing_messages<Block: BlockT, N: Network>(
|
||||
|
||||
fn check_compact_commit<Block: BlockT>(
|
||||
msg: CompactCommit<Block>,
|
||||
voters: &HashMap<AuthorityId, u64>,
|
||||
voters: &HashMap<Ed25519AuthorityId, u64>,
|
||||
round: u64,
|
||||
set_id: u64,
|
||||
) -> Option<CompactCommit<Block>> {
|
||||
@@ -216,7 +216,7 @@ fn check_compact_commit<Block: BlockT>(
|
||||
pub(crate) fn checked_commit_stream<Block: BlockT, S>(
|
||||
set_id: u64,
|
||||
inner: S,
|
||||
voters: Arc<HashMap<AuthorityId, u64>>,
|
||||
voters: Arc<HashMap<Ed25519AuthorityId, u64>>,
|
||||
)
|
||||
-> impl Stream<Item=(u64, CompactCommit<Block>),Error=Error> where
|
||||
S: Stream<Item=Vec<u8>,Error=()>
|
||||
|
||||
@@ -92,10 +92,11 @@ use codec::{Encode, Decode};
|
||||
use consensus_common::{BlockImport, Error as ConsensusError, ErrorKind as ConsensusErrorKind, ImportBlock, ImportResult, Authorities};
|
||||
use runtime_primitives::traits::{
|
||||
NumberFor, Block as BlockT, Header as HeaderT, DigestFor, ProvideRuntimeApi, Hash as HashT,
|
||||
DigestItemFor, DigestItem,
|
||||
};
|
||||
use fg_primitives::GrandpaApi;
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use substrate_primitives::{ed25519, H256, AuthorityId, Blake2Hasher};
|
||||
use substrate_primitives::{ed25519, H256, Ed25519AuthorityId, Blake2Hasher};
|
||||
use tokio::timer::Delay;
|
||||
|
||||
use grandpa::Error as GrandpaError;
|
||||
@@ -138,7 +139,7 @@ pub type SignedMessage<Block> = grandpa::SignedMessage<
|
||||
<Block as BlockT>::Hash,
|
||||
NumberFor<Block>,
|
||||
ed25519::Signature,
|
||||
AuthorityId,
|
||||
Ed25519AuthorityId,
|
||||
>;
|
||||
/// A prevote message for this chain's block type.
|
||||
pub type Prevote<Block> = grandpa::Prevote<<Block as BlockT>::Hash, NumberFor<Block>>;
|
||||
@@ -149,14 +150,14 @@ pub type Commit<Block> = grandpa::Commit<
|
||||
<Block as BlockT>::Hash,
|
||||
NumberFor<Block>,
|
||||
ed25519::Signature,
|
||||
AuthorityId
|
||||
Ed25519AuthorityId
|
||||
>;
|
||||
/// A compact commit message for this chain's block type.
|
||||
pub type CompactCommit<Block> = grandpa::CompactCommit<
|
||||
<Block as BlockT>::Hash,
|
||||
NumberFor<Block>,
|
||||
ed25519::Signature,
|
||||
AuthorityId
|
||||
Ed25519AuthorityId
|
||||
>;
|
||||
|
||||
/// Configuration for the GRANDPA service.
|
||||
@@ -306,7 +307,7 @@ impl<B, E, Block: BlockT<Hash=H256>, RA> BlockStatus<Block> for Arc<Client<B, E,
|
||||
/// The environment we run GRANDPA in.
|
||||
struct Environment<B, E, Block: BlockT, N: Network, RA> {
|
||||
inner: Arc<Client<B, E, Block, RA>>,
|
||||
voters: Arc<HashMap<AuthorityId, u64>>,
|
||||
voters: Arc<HashMap<Ed25519AuthorityId, u64>>,
|
||||
config: Config,
|
||||
authority_set: SharedAuthoritySet<Block::Hash, NumberFor<Block>>,
|
||||
network: N,
|
||||
@@ -381,7 +382,7 @@ struct NewAuthoritySet<H, N> {
|
||||
canon_number: N,
|
||||
canon_hash: H,
|
||||
set_id: u64,
|
||||
authorities: Vec<(AuthorityId, u64)>,
|
||||
authorities: Vec<(Ed25519AuthorityId, u64)>,
|
||||
}
|
||||
|
||||
/// Signals either an early exit of a voter or an error.
|
||||
@@ -432,7 +433,7 @@ impl<B, E, Block: BlockT<Hash=H256>, N, RA> voter::Environment<Block::Hash, Numb
|
||||
NumberFor<Block>: BlockNumberOps,
|
||||
{
|
||||
type Timer = Box<dyn Future<Item = (), Error = Self::Error> + Send>;
|
||||
type Id = AuthorityId;
|
||||
type Id = Ed25519AuthorityId;
|
||||
type Signature = ed25519::Signature;
|
||||
|
||||
// regular round message streams
|
||||
@@ -611,7 +612,7 @@ impl<Block: BlockT<Hash=H256>> GrandpaJustification<Block> {
|
||||
fn decode_and_verify(
|
||||
encoded: Vec<u8>,
|
||||
set_id: u64,
|
||||
voters: &HashMap<AuthorityId, u64>,
|
||||
voters: &HashMap<Ed25519AuthorityId, u64>,
|
||||
) -> Result<GrandpaJustification<Block>, ClientError> where
|
||||
NumberFor<Block>: grandpa::BlockNumberOps,
|
||||
{
|
||||
@@ -830,13 +831,14 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA> BlockImport<Block>
|
||||
B: Backend<Block, Blake2Hasher> + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
DigestFor<Block>: Encode,
|
||||
DigestItemFor<Block>: DigestItem<AuthorityId=Ed25519AuthorityId>,
|
||||
RA: Send + Sync,
|
||||
PRA: ProvideRuntimeApi,
|
||||
PRA::Api: GrandpaApi<Block>,
|
||||
{
|
||||
type Error = ConsensusError;
|
||||
|
||||
fn import_block(&self, mut block: ImportBlock<Block>, new_authorities: Option<Vec<AuthorityId>>)
|
||||
fn import_block(&self, mut block: ImportBlock<Block>, new_authorities: Option<Vec<Ed25519AuthorityId>>)
|
||||
-> Result<ImportResult, Self::Error>
|
||||
{
|
||||
use authorities::PendingChange;
|
||||
@@ -1030,10 +1032,11 @@ impl<B, E, Block: BlockT<Hash=H256>, RA, PRA> Authorities<Block> for GrandpaBloc
|
||||
where
|
||||
B: Backend<Block, Blake2Hasher> + 'static,
|
||||
E: CallExecutor<Block, Blake2Hasher> + 'static + Clone + Send + Sync,
|
||||
DigestItemFor<Block>: DigestItem<AuthorityId=Ed25519AuthorityId>,
|
||||
{
|
||||
|
||||
type Error = <Client<B, E, Block, RA> as Authorities<Block>>::Error;
|
||||
fn authorities(&self, at: &BlockId<Block>) -> Result<Vec<AuthorityId>, Self::Error> {
|
||||
fn authorities(&self, at: &BlockId<Block>) -> Result<Vec<Ed25519AuthorityId>, Self::Error> {
|
||||
self.inner.authorities_at(at)
|
||||
}
|
||||
}
|
||||
@@ -1158,16 +1161,16 @@ pub fn block_import<B, E, Block: BlockT<Hash=H256>, RA, PRA>(
|
||||
|
||||
fn committer_communication<Block: BlockT<Hash=H256>, B, E, N, RA>(
|
||||
set_id: u64,
|
||||
voters: &Arc<HashMap<AuthorityId, u64>>,
|
||||
voters: &Arc<HashMap<Ed25519AuthorityId, u64>>,
|
||||
client: &Arc<Client<B, E, Block, RA>>,
|
||||
network: &N,
|
||||
) -> (
|
||||
impl Stream<
|
||||
Item = (u64, ::grandpa::CompactCommit<H256, NumberFor<Block>, ed25519::Signature, AuthorityId>),
|
||||
Item = (u64, ::grandpa::CompactCommit<H256, NumberFor<Block>, ed25519::Signature, Ed25519AuthorityId>),
|
||||
Error = ExitOrError<H256, NumberFor<Block>>,
|
||||
>,
|
||||
impl Sink<
|
||||
SinkItem = (u64, ::grandpa::Commit<H256, NumberFor<Block>, ed25519::Signature, AuthorityId>),
|
||||
SinkItem = (u64, ::grandpa::Commit<H256, NumberFor<Block>, ed25519::Signature, Ed25519AuthorityId>),
|
||||
SinkError = ExitOrError<H256, NumberFor<Block>>,
|
||||
>,
|
||||
) where
|
||||
@@ -1176,6 +1179,7 @@ fn committer_communication<Block: BlockT<Hash=H256>, B, E, N, RA>(
|
||||
N: Network,
|
||||
RA: Send + Sync,
|
||||
NumberFor<Block>: BlockNumberOps,
|
||||
DigestItemFor<Block>: DigestItem<AuthorityId=Ed25519AuthorityId>,
|
||||
{
|
||||
// verification stream
|
||||
let commit_in = ::communication::checked_commit_stream::<Block, _>(
|
||||
@@ -1217,6 +1221,7 @@ pub fn run_grandpa<B, E, Block: BlockT<Hash=H256>, N, RA>(
|
||||
N::In: Send + 'static,
|
||||
NumberFor<Block>: BlockNumberOps,
|
||||
DigestFor<Block>: Encode,
|
||||
DigestItemFor<Block>: DigestItem<AuthorityId=Ed25519AuthorityId>,
|
||||
RA: Send + Sync + 'static,
|
||||
{
|
||||
use futures::future::{self, Loop as FutureLoop};
|
||||
|
||||
@@ -230,12 +230,12 @@ impl Network for MessageRouting {
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
struct TestApi {
|
||||
genesis_authorities: Vec<(AuthorityId, u64)>,
|
||||
genesis_authorities: Vec<(Ed25519AuthorityId, u64)>,
|
||||
scheduled_changes: Arc<Mutex<HashMap<Hash, ScheduledChange<BlockNumber>>>>,
|
||||
}
|
||||
|
||||
impl TestApi {
|
||||
fn new(genesis_authorities: Vec<(AuthorityId, u64)>) -> Self {
|
||||
fn new(genesis_authorities: Vec<(Ed25519AuthorityId, u64)>) -> Self {
|
||||
TestApi {
|
||||
genesis_authorities,
|
||||
scheduled_changes: Arc::new(Mutex::new(HashMap::new())),
|
||||
@@ -260,7 +260,7 @@ impl Core<Block> for RuntimeApi {
|
||||
unimplemented!("Not required for testing!")
|
||||
}
|
||||
|
||||
fn authorities(&self, _: &BlockId<Block>) -> Result<Vec<AuthorityId>> {
|
||||
fn authorities(&self, _: &BlockId<Block>) -> Result<Vec<Ed25519AuthorityId>> {
|
||||
unimplemented!("Not required for testing!")
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ impl GrandpaApi<Block> for RuntimeApi {
|
||||
fn grandpa_authorities(
|
||||
&self,
|
||||
at: &BlockId<Block>
|
||||
) -> Result<Vec<(AuthorityId, u64)>> {
|
||||
) -> Result<Vec<(Ed25519AuthorityId, u64)>> {
|
||||
if at == &BlockId::Number(0) {
|
||||
Ok(self.inner.genesis_authorities.clone())
|
||||
} else {
|
||||
@@ -325,9 +325,9 @@ impl GrandpaApi<Block> for RuntimeApi {
|
||||
const TEST_GOSSIP_DURATION: Duration = Duration::from_millis(500);
|
||||
const TEST_ROUTING_INTERVAL: Duration = Duration::from_millis(50);
|
||||
|
||||
fn make_ids(keys: &[Keyring]) -> Vec<(AuthorityId, u64)> {
|
||||
fn make_ids(keys: &[Keyring]) -> Vec<(Ed25519AuthorityId, u64)> {
|
||||
keys.iter()
|
||||
.map(|key| AuthorityId(key.to_raw_public()))
|
||||
.map(|key| Ed25519AuthorityId(key.to_raw_public()))
|
||||
.map(|id| (id, 1))
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use futures::prelude::*;
|
||||
use futures::stream::Fuse;
|
||||
use parking_lot::Mutex;
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor};
|
||||
use substrate_primitives::AuthorityId;
|
||||
use substrate_primitives::Ed25519AuthorityId;
|
||||
use tokio::timer::Interval;
|
||||
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
@@ -181,7 +181,7 @@ impl<Block: BlockT, Status, I, M> Stream for UntilImported<Block, Status, I, M>
|
||||
}
|
||||
}
|
||||
|
||||
fn warn_authority_wrong_target<H: ::std::fmt::Display>(hash: H, id: AuthorityId) {
|
||||
fn warn_authority_wrong_target<H: ::std::fmt::Display>(hash: H, id: Ed25519AuthorityId) {
|
||||
warn!(
|
||||
target: "afg",
|
||||
"Authority {:?} signed GRANDPA message with \
|
||||
|
||||
Reference in New Issue
Block a user