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
+3 -3
View File
@@ -143,12 +143,12 @@ impl<SessionKey: Member> RawLog<SessionKey> {
// Implementation for tests outside of this crate.
#[cfg(any(feature = "std", test))]
impl<N> From<RawLog<N>> for primitives::testing::DigestItem where N: Into<u64> {
impl<N> From<RawLog<N>> for primitives::testing::DigestItem where N: Into<substrate_primitives::Ed25519AuthorityId> {
fn from(log: RawLog<N>) -> primitives::testing::DigestItem {
match log {
RawLog::AuthoritiesChange(authorities) =>
primitives::generic::DigestItem::AuthoritiesChange
::<substrate_primitives::H256, u64>(authorities.into_iter()
primitives::generic::DigestItem::AuthoritiesChange(
authorities.into_iter()
.map(Into::into).collect()),
}
}
+3 -3
View File
@@ -18,7 +18,7 @@
#![cfg(test)]
use primitives::{BuildStorage, testing::{Digest, DigestItem, Header}};
use primitives::{BuildStorage, testing::{Digest, DigestItem, Header, UintAuthorityId}};
use runtime_io;
use substrate_primitives::{H256, Blake2Hasher};
use {GenesisConfig, Trait, Module, system};
@@ -33,7 +33,7 @@ pub struct Test;
impl Trait for Test {
const NOTE_OFFLINE_POSITION: u32 = 1;
type Log = DigestItem;
type SessionKey = u64;
type SessionKey = UintAuthorityId;
type InherentOfflineReport = ::InstantFinalityReportVec<()>;
}
impl system::Trait for Test {
@@ -53,7 +53,7 @@ pub fn new_test_ext(authorities: Vec<u64>) -> runtime_io::TestExternalities<Blak
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(GenesisConfig::<Test>{
code: vec![],
authorities,
authorities: authorities.into_iter().map(|a| UintAuthorityId(a)).collect(),
}.build_storage().unwrap().0);
t.into()
}
+5 -6
View File
@@ -18,21 +18,20 @@
#![cfg(test)]
use primitives::{generic, testing, traits::{OnFinalise, ProvideInherent}};
use primitives::{generic, testing::{self, UintAuthorityId}, traits::{OnFinalise, ProvideInherent}};
use runtime_io::with_externalities;
use substrate_primitives::H256;
use mock::{Consensus, System, new_test_ext};
#[test]
fn authorities_change_logged() {
with_externalities(&mut new_test_ext(vec![1, 2, 3]), || {
System::initialise(&1, &Default::default(), &Default::default());
Consensus::set_authorities(&[4, 5, 6]);
Consensus::set_authorities(&[UintAuthorityId(4), UintAuthorityId(5), UintAuthorityId(6)]);
Consensus::on_finalise(1);
let header = System::finalise();
assert_eq!(header.digest, testing::Digest {
logs: vec![
generic::DigestItem::AuthoritiesChange::<H256, u64>(vec![4, 5, 6]),
generic::DigestItem::AuthoritiesChange(vec![UintAuthorityId(4).into(), UintAuthorityId(5).into(), UintAuthorityId(6).into()]),
],
});
});
@@ -54,8 +53,8 @@ fn authorities_change_is_not_logged_when_not_changed() {
fn authorities_change_is_not_logged_when_changed_back_to_original() {
with_externalities(&mut new_test_ext(vec![1, 2, 3]), || {
System::initialise(&1, &Default::default(), &Default::default());
Consensus::set_authorities(&[4, 5, 6]);
Consensus::set_authorities(&[1, 2, 3]);
Consensus::set_authorities(&[UintAuthorityId(4), UintAuthorityId(5), UintAuthorityId(6)]);
Consensus::set_authorities(&[UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]);
Consensus::on_finalise(1);
let header = System::finalise();
assert_eq!(header.digest, testing::Digest {