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,23 +19,23 @@
use std::collections::HashMap;
use runtime_io::twox_128;
use codec::{Encode, KeyedVec, Joiner};
use primitives::{AuthorityId, ChangesTrieConfiguration};
use primitives::{Ed25519AuthorityId, ChangesTrieConfiguration};
use primitives::storage::well_known_keys;
use runtime_primitives::traits::Block;
/// Configuration of a general Substrate test genesis block.
pub struct GenesisConfig {
pub changes_trie_config: Option<ChangesTrieConfiguration>,
pub authorities: Vec<AuthorityId>,
pub balances: Vec<(AuthorityId, u64)>,
pub authorities: Vec<Ed25519AuthorityId>,
pub balances: Vec<(Ed25519AuthorityId, u64)>,
}
impl GenesisConfig {
pub fn new_simple(authorities: Vec<AuthorityId>, balance: u64) -> Self {
pub fn new_simple(authorities: Vec<Ed25519AuthorityId>, balance: u64) -> Self {
Self::new(false, authorities, balance)
}
pub fn new(support_changes_trie: bool, authorities: Vec<AuthorityId>, balance: u64) -> Self {
pub fn new(support_changes_trie: bool, authorities: Vec<Ed25519AuthorityId>, balance: u64) -> Self {
GenesisConfig {
changes_trie_config: match support_changes_trie {
true => Some(super::changes_trie_config()),
+3 -4
View File
@@ -61,8 +61,7 @@ use runtime_primitives::{
};
use runtime_version::RuntimeVersion;
pub use primitives::hash::H256;
use primitives::AuthorityId;
use primitives::OpaqueMetadata;
use primitives::{Ed25519AuthorityId, OpaqueMetadata};
#[cfg(any(feature = "std", test))]
use runtime_version::NativeVersion;
use consensus_aura::api as aura_api;
@@ -143,7 +142,7 @@ pub type BlockNumber = u64;
/// Index of a transaction.
pub type Index = u64;
/// The item of a block digest.
pub type DigestItem = runtime_primitives::generic::DigestItem<H256, u64>;
pub type DigestItem = runtime_primitives::generic::DigestItem<H256, Ed25519AuthorityId>;
/// The digest of a block.
pub type Digest = runtime_primitives::generic::Digest<DigestItem>;
/// A test block.
@@ -197,7 +196,7 @@ impl_runtime_apis! {
version()
}
fn authorities() -> Vec<AuthorityId> {
fn authorities() -> Vec<Ed25519AuthorityId> {
system::authorities()
}
+4 -4
View File
@@ -25,7 +25,7 @@ use runtime_primitives::generic;
use runtime_primitives::{ApplyError, ApplyOutcome, ApplyResult, transaction_validity::TransactionValidity};
use codec::{KeyedVec, Encode};
use super::{AccountId, BlockNumber, Extrinsic, H256 as Hash, Block, Header, Digest};
use primitives::{Blake2Hasher};
use primitives::{Ed25519AuthorityId, Blake2Hasher};
use primitives::storage::well_known_keys;
const NONCE_OF: &[u8] = b"nonce:";
@@ -51,7 +51,7 @@ pub fn nonce_of(who: AccountId) -> u64 {
}
/// Get authorities ar given block.
pub fn authorities() -> Vec<::primitives::AuthorityId> {
pub fn authorities() -> Vec<Ed25519AuthorityId> {
let len: u32 = storage::unhashed::get(well_known_keys::AUTHORITY_COUNT)
.expect("There are always authorities in test-runtime");
(0..len)
@@ -94,7 +94,7 @@ pub fn execute_block(block: Block) {
// check digest
let mut digest = Digest::default();
if let Some(storage_changes_root) = storage_changes_root(header.parent_hash.into(), header.number - 1) {
digest.push(generic::DigestItem::ChangesTrieRoot::<Hash, u64>(storage_changes_root.into()));
digest.push(generic::DigestItem::ChangesTrieRoot(storage_changes_root.into()));
}
assert!(digest == header.digest, "Header digest items must match that calculated.");
}
@@ -164,7 +164,7 @@ pub fn finalise_block() -> Header {
let mut digest = Digest::default();
if let Some(storage_changes_root) = storage_changes_root {
digest.push(generic::DigestItem::ChangesTrieRoot::<Hash, u64>(storage_changes_root));
digest.push(generic::DigestItem::ChangesTrieRoot(storage_changes_root));
}
Header {