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
+12 -12
View File
@@ -248,8 +248,8 @@ mod tests {
use runtime_io::with_externalities;
use substrate_primitives::{H256, Blake2Hasher};
use primitives::BuildStorage;
use primitives::traits::{Identity, BlakeTwo256};
use primitives::testing::{Digest, DigestItem, Header};
use primitives::traits::BlakeTwo256;
use primitives::testing::{Digest, DigestItem, Header, UintAuthorityId, ConvertUintAuthorityId};
impl_outer_origin!{
pub enum Origin for Test {}
@@ -260,7 +260,7 @@ mod tests {
impl consensus::Trait for Test {
const NOTE_OFFLINE_POSITION: u32 = 1;
type Log = DigestItem;
type SessionKey = u64;
type SessionKey = UintAuthorityId;
type InherentOfflineReport = ();
}
impl system::Trait for Test {
@@ -281,7 +281,7 @@ mod tests {
type OnTimestampSet = ();
}
impl Trait for Test {
type ConvertAccountIdToSessionKey = Identity;
type ConvertAccountIdToSessionKey = ConvertUintAuthorityId;
type OnSessionChange = ();
type Event = ();
}
@@ -294,7 +294,7 @@ mod tests {
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
t.extend(consensus::GenesisConfig::<Test>{
code: vec![],
authorities: vec![1, 2, 3],
authorities: vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)],
}.build_storage().unwrap().0);
t.extend(timestamp::GenesisConfig::<Test>{
period: 5,
@@ -309,7 +309,7 @@ mod tests {
#[test]
fn simple_setup_should_work() {
with_externalities(&mut new_test_ext(), || {
assert_eq!(Consensus::authorities(), vec![1, 2, 3]);
assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1).into(), UintAuthorityId(2).into(), UintAuthorityId(3).into()]);
assert_eq!(Session::length(), 2);
assert_eq!(Session::validators(), vec![1, 2, 3]);
});
@@ -405,25 +405,25 @@ mod tests {
// Block 1: No change
System::set_block_number(1);
Session::check_rotate_session(1);
assert_eq!(Consensus::authorities(), vec![1, 2, 3]);
assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]);
// Block 2: Session rollover, but no change.
System::set_block_number(2);
Session::check_rotate_session(2);
assert_eq!(Consensus::authorities(), vec![1, 2, 3]);
assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]);
// Block 3: Set new key for validator 2; no visible change.
System::set_block_number(3);
assert_ok!(Session::set_key(Origin::signed(2), 5));
assert_eq!(Consensus::authorities(), vec![1, 2, 3]);
assert_ok!(Session::set_key(Origin::signed(2), UintAuthorityId(5)));
assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]);
Session::check_rotate_session(3);
assert_eq!(Consensus::authorities(), vec![1, 2, 3]);
assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]);
// Block 4: Session rollover, authority 2 changes.
System::set_block_number(4);
Session::check_rotate_session(4);
assert_eq!(Consensus::authorities(), vec![1, 5, 3]);
assert_eq!(Consensus::authorities(), vec![UintAuthorityId(1), UintAuthorityId(5), UintAuthorityId(3)]);
});
}
}