mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +00:00
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:
committed by
Benjamin Kampmann
parent
043831cfb0
commit
71d889b692
@@ -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 {Trait, Module, consensus, system, timestamp};
|
||||
@@ -34,7 +34,7 @@ pub struct Test;
|
||||
impl consensus::Trait for Test {
|
||||
const NOTE_OFFLINE_POSITION: u32 = 1;
|
||||
type Log = DigestItem;
|
||||
type SessionKey = u64;
|
||||
type SessionKey = UintAuthorityId;
|
||||
type InherentOfflineReport = ();
|
||||
}
|
||||
|
||||
@@ -66,7 +66,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(consensus::GenesisConfig::<Test>{
|
||||
code: vec![],
|
||||
authorities,
|
||||
authorities: authorities.into_iter().map(|a| UintAuthorityId(a)).collect(),
|
||||
}.build_storage().unwrap().0);
|
||||
t.extend(timestamp::GenesisConfig::<Test>{
|
||||
period: 1,
|
||||
|
||||
@@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -61,7 +61,7 @@ use runtime_support::dispatch::Result;
|
||||
use runtime_support::storage::StorageValue;
|
||||
use runtime_support::storage::unhashed::StorageVec;
|
||||
use primitives::traits::{CurrentHeight, Convert};
|
||||
use substrate_primitives::AuthorityId;
|
||||
use substrate_primitives::Ed25519AuthorityId;
|
||||
use system::ensure_signed;
|
||||
use primitives::traits::MaybeSerializeDebug;
|
||||
|
||||
@@ -105,7 +105,7 @@ impl<N: Clone, SessionKey> RawLog<N, SessionKey> {
|
||||
}
|
||||
|
||||
impl<N, SessionKey> GrandpaChangeSignal<N> for RawLog<N, SessionKey>
|
||||
where N: Clone, SessionKey: Clone + Into<AuthorityId>,
|
||||
where N: Clone, SessionKey: Clone + Into<Ed25519AuthorityId>,
|
||||
{
|
||||
fn as_signal(&self) -> Option<ScheduledChange<N>> {
|
||||
RawLog::as_signal(self).map(|(delay, next_authorities)| ScheduledChange {
|
||||
@@ -243,7 +243,7 @@ impl<T: Trait> Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> where AuthorityId: core::convert::From<<T as Trait>::SessionKey> {
|
||||
impl<T: Trait> Module<T> where Ed25519AuthorityId: core::convert::From<<T as Trait>::SessionKey> {
|
||||
/// See if the digest contains any scheduled change.
|
||||
pub fn scrape_digest_change(log: &Log<T>)
|
||||
-> Option<ScheduledChange<T::BlockNumber>>
|
||||
|
||||
@@ -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)]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use primitives::BuildStorage;
|
||||
use primitives::{Perbill, traits::Identity};
|
||||
use primitives::testing::{Digest, DigestItem, Header};
|
||||
use primitives::Perbill;
|
||||
use primitives::testing::{Digest, DigestItem, Header, UintAuthorityId, ConvertUintAuthorityId};
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use runtime_io;
|
||||
use {GenesisConfig, Module, Trait, consensus, session, system, timestamp, balances};
|
||||
@@ -35,7 +35,7 @@ pub struct Test;
|
||||
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 {
|
||||
@@ -58,7 +58,7 @@ impl balances::Trait for Test {
|
||||
type Event = ();
|
||||
}
|
||||
impl session::Trait for Test {
|
||||
type ConvertAccountIdToSessionKey = Identity;
|
||||
type ConvertAccountIdToSessionKey = ConvertUintAuthorityId;
|
||||
type OnSessionChange = Staking;
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
@@ -176,8 +176,7 @@ impl<Hash: Member> RawLog<Hash> {
|
||||
impl From<RawLog<substrate_primitives::H256>> for primitives::testing::DigestItem {
|
||||
fn from(log: RawLog<substrate_primitives::H256>) -> primitives::testing::DigestItem {
|
||||
match log {
|
||||
RawLog::ChangesTrieRoot(root) => primitives::generic::DigestItem::ChangesTrieRoot
|
||||
::<substrate_primitives::H256, u64>(root),
|
||||
RawLog::ChangesTrieRoot(root) => primitives::generic::DigestItem::ChangesTrieRoot(root),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ mod tests {
|
||||
use substrate_primitives::H256;
|
||||
use runtime_primitives::BuildStorage;
|
||||
use runtime_primitives::traits::BlakeTwo256;
|
||||
use runtime_primitives::testing::{Digest, DigestItem, Header};
|
||||
use runtime_primitives::testing::{Digest, DigestItem, Header, UintAuthorityId};
|
||||
|
||||
impl_outer_origin! {
|
||||
pub enum Origin for Test {}
|
||||
@@ -213,7 +213,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 Trait for Test {
|
||||
|
||||
Reference in New Issue
Block a user