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
+14 -14
View File
@@ -20,17 +20,17 @@ use H256;
/// An identifier for an authority in the consensus algorithm. The same size as ed25519::Public.
#[derive(Clone, Copy, PartialEq, Eq, Default, Encode, Decode)]
pub struct AuthorityId(pub [u8; 32]);
pub struct Ed25519AuthorityId(pub [u8; 32]);
#[cfg(feature = "std")]
impl ::std::fmt::Display for AuthorityId {
impl ::std::fmt::Display for Ed25519AuthorityId {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "{}", ::ed25519::Public(self.0).to_ss58check())
}
}
#[cfg(feature = "std")]
impl ::std::fmt::Debug for AuthorityId {
impl ::std::fmt::Debug for Ed25519AuthorityId {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
let h = format!("{}", ::hexdisplay::HexDisplay::from(&self.0));
write!(f, "{} ({}…{})", ::ed25519::Public(self.0).to_ss58check(), &h[0..8], &h[60..])
@@ -38,57 +38,57 @@ impl ::std::fmt::Debug for AuthorityId {
}
#[cfg(feature = "std")]
impl ::std::hash::Hash for AuthorityId {
impl ::std::hash::Hash for Ed25519AuthorityId {
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
}
impl AsRef<[u8; 32]> for AuthorityId {
impl AsRef<[u8; 32]> for Ed25519AuthorityId {
fn as_ref(&self) -> &[u8; 32] {
&self.0
}
}
impl AsRef<[u8]> for AuthorityId {
impl AsRef<[u8]> for Ed25519AuthorityId {
fn as_ref(&self) -> &[u8] {
&self.0[..]
}
}
impl Into<[u8; 32]> for AuthorityId {
impl Into<[u8; 32]> for Ed25519AuthorityId {
fn into(self) -> [u8; 32] {
self.0
}
}
impl From<[u8; 32]> for AuthorityId {
impl From<[u8; 32]> for Ed25519AuthorityId {
fn from(a: [u8; 32]) -> Self {
AuthorityId(a)
Ed25519AuthorityId(a)
}
}
impl AsRef<AuthorityId> for AuthorityId {
fn as_ref(&self) -> &AuthorityId {
impl AsRef<Ed25519AuthorityId> for Ed25519AuthorityId {
fn as_ref(&self) -> &Ed25519AuthorityId {
&self
}
}
impl Into<H256> for AuthorityId {
impl Into<H256> for Ed25519AuthorityId {
fn into(self) -> H256 {
self.0.into()
}
}
#[cfg(feature = "std")]
impl Serialize for AuthorityId {
impl Serialize for Ed25519AuthorityId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
::ed25519::serialize(&self, serializer)
}
}
#[cfg(feature = "std")]
impl<'de> Deserialize<'de> for AuthorityId {
impl<'de> Deserialize<'de> for Ed25519AuthorityId {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> {
::ed25519::deserialize(deserializer)
}
+6 -6
View File
@@ -21,7 +21,7 @@
use untrusted;
use blake2_rfc;
use ring::{rand, signature};
use {hash::H512, AuthorityId};
use {hash::H512, Ed25519AuthorityId};
use base58::{ToBase58, FromBase58};
#[cfg(feature = "std")]
@@ -169,14 +169,14 @@ impl AsRef<Pair> for Pair {
}
}
impl Into<AuthorityId> for Public {
fn into(self) -> AuthorityId {
AuthorityId(self.0)
impl Into<Ed25519AuthorityId> for Public {
fn into(self) -> Ed25519AuthorityId {
Ed25519AuthorityId(self.0)
}
}
impl From<AuthorityId> for Public {
fn from(id: AuthorityId) -> Self {
impl From<Ed25519AuthorityId> for Public {
fn from(id: Ed25519AuthorityId) -> Self {
Public(id.0)
}
}
+1 -1
View File
@@ -109,7 +109,7 @@ mod tests;
pub use self::hash::{H160, H256, H512, convert_hash};
pub use self::uint::U256;
pub use authority_id::AuthorityId;
pub use authority_id::Ed25519AuthorityId;
pub use changes_trie::ChangesTrieConfiguration;
pub use hash_db::Hasher;