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:
Wei Tang
2019-01-08 11:14:18 +01:00
committed by Benjamin Kampmann
parent 043831cfb0
commit 71d889b692
46 changed files with 234 additions and 216 deletions
@@ -19,7 +19,7 @@
use rstd::prelude::*;
use codec::{Decode, Encode, Codec, Input};
use traits::{self, Member, DigestItem as DigestItemT, MaybeSerializeDebug};
use traits::{self, Member, DigestItem as DigestItemT, MaybeSerializeDebug, MaybeHash};
use substrate_primitives::hash::H512 as Signature;
@@ -124,7 +124,7 @@ impl<Hash, AuthorityId> DigestItem<Hash, AuthorityId> {
impl<
Hash: Codec + Member + MaybeSerializeDebug,
AuthorityId: Codec + Member + MaybeSerializeDebug
AuthorityId: Codec + Member + MaybeSerializeDebug + MaybeHash
> traits::DigestItem for DigestItem<Hash, AuthorityId> {
type Hash = Hash;
type AuthorityId = AuthorityId;
+21 -3
View File
@@ -19,12 +19,30 @@
use serde::{Serialize, Serializer, Deserialize, de::Error as DeError, Deserializer};
use std::{fmt::Debug, ops::Deref, fmt};
use codec::{Codec, Encode, Decode};
use traits::{self, Checkable, Applyable, BlakeTwo256};
use traits::{self, Checkable, Applyable, BlakeTwo256, Convert};
use generic::DigestItem as GenDigestItem;
pub use substrate_primitives::{H256, AuthorityId};
pub use substrate_primitives::{H256, Ed25519AuthorityId};
use substrate_primitives::U256;
pub type DigestItem = GenDigestItem<H256, u64>;
#[derive(Default, PartialEq, Eq, Clone, Decode, Encode, Debug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct UintAuthorityId(pub u64);
impl Into<Ed25519AuthorityId> for UintAuthorityId {
fn into(self) -> Ed25519AuthorityId {
let bytes: [u8; 32] = U256::from(self.0).into();
Ed25519AuthorityId(bytes)
}
}
pub struct ConvertUintAuthorityId;
impl Convert<u64, UintAuthorityId> for ConvertUintAuthorityId {
fn convert(a: u64) -> UintAuthorityId {
UintAuthorityId(a)
}
}
pub type DigestItem = GenDigestItem<H256, Ed25519AuthorityId>;
#[derive(Default, PartialEq, Eq, Clone, Serialize, Debug, Encode, Decode)]
pub struct Digest {
+13 -1
View File
@@ -413,6 +413,16 @@ pub trait MaybeDisplay {}
#[cfg(not(feature = "std"))]
impl<T> MaybeDisplay for T {}
#[cfg(feature = "std")]
pub trait MaybeHash: ::rstd::hash::Hash {}
#[cfg(feature = "std")]
impl<T: ::rstd::hash::Hash> MaybeHash for T {}
#[cfg(not(feature = "std"))]
pub trait MaybeHash {}
#[cfg(not(feature = "std"))]
impl<T> MaybeHash for T {}
#[cfg(feature = "std")]
pub trait MaybeDecode: ::codec::Decode {}
#[cfg(feature = "std")]
@@ -500,6 +510,8 @@ pub type NumberFor<B> = <<B as Block>::Header as Header>::Number;
pub type DigestFor<B> = <<B as Block>::Header as Header>::Digest;
/// Extract the digest item type for a block.
pub type DigestItemFor<B> = <DigestFor<B> as Digest>::Item;
/// Extract the authority ID type for a block.
pub type AuthorityIdFor<B> = <DigestItemFor<B> as DigestItem>::AuthorityId;
/// A "checkable" piece of information, used by the standard Substrate Executive in order to
/// check the validity of a piece of extrinsic information, usually by verifying the signature.
@@ -575,7 +587,7 @@ pub trait Digest: Member + MaybeSerializeDebugButNotDeserialize + Default {
/// If the runtime does not supports some 'system' items, use `()` as a stub.
pub trait DigestItem: Codec + Member + MaybeSerializeDebugButNotDeserialize {
type Hash: Member + MaybeSerializeDebugButNotDeserialize;
type AuthorityId: Member + MaybeSerializeDebugButNotDeserialize;
type AuthorityId: Member + MaybeSerializeDebugButNotDeserialize + MaybeHash + codec::Encode + codec::Decode;
/// Returns Some if the entry is the `AuthoritiesChange` entry.
fn as_authorities_change(&self) -> Option<&[Self::AuthorityId]>;