[big refactor] Remove crate aliasing. (#4395)

* Rename: Phase 1.

* Unify codec.

* Fixing: Phase 2

* Fixing: Phase 3.

* Fixing: Phase 4.

* Fixing: Phase 5.

* Fixing: Phase 6.

* Fixing: Phase 7.

* Fixing: Phase 8. Tests

* Fixing: Phase 9. Tests!!!

* Fixing: Phase 10. Moar tests!

* Finally done!

* More fixes.

* Rename primitives:: to sp_core::

* Apply renames in finality-grandpa.

* Fix benches.

* Fix benches 2.

* Revert node-template.

* Fix frame-system in our modules.
This commit is contained in:
Tomasz Drwięga
2019-12-16 13:36:49 +01:00
committed by Gavin Wood
parent f14d98a439
commit 8778ca7dc8
485 changed files with 4023 additions and 4005 deletions
+16 -17
View File
@@ -20,11 +20,10 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![forbid(unused_must_use, unsafe_code, unused_variables, unused_must_use)]
#![deny(unused_imports)]
pub use timestamp;
use sp_timestamp;
pub use pallet_timestamp;
use sp_std::{result, prelude::*};
use support::{decl_storage, decl_module, traits::FindAuthor, traits::Get};
use frame_support::{decl_storage, decl_module, traits::FindAuthor, traits::Get};
use sp_timestamp::OnTimestampSet;
use sp_runtime::{generic::DigestItem, ConsensusEngineId, Perbill};
use sp_runtime::traits::{IsMember, SaturatedConversion, Saturating, RandomnessBeacon};
@@ -34,12 +33,12 @@ use sp_staking::{
};
use codec::{Encode, Decode};
use inherents::{InherentIdentifier, InherentData, ProvideInherent, MakeFatalError};
use babe_primitives::{
use sp_inherents::{InherentIdentifier, InherentData, ProvideInherent, MakeFatalError};
use sp_consensus_babe::{
BABE_ENGINE_ID, ConsensusLog, BabeAuthorityWeight, NextEpochDescriptor, RawBabePreDigest,
SlotNumber, inherents::{INHERENT_IDENTIFIER, BabeInherentData}
};
pub use babe_primitives::{AuthorityId, VRF_OUTPUT_LENGTH, PUBLIC_KEY_LENGTH};
pub use sp_consensus_babe::{AuthorityId, VRF_OUTPUT_LENGTH, PUBLIC_KEY_LENGTH};
#[cfg(all(feature = "std", test))]
mod tests;
@@ -47,7 +46,7 @@ mod tests;
#[cfg(all(feature = "std", test))]
mod mock;
pub trait Trait: timestamp::Trait {
pub trait Trait: pallet_timestamp::Trait {
/// The amount of time, in slots, that each epoch should last.
type EpochDuration: Get<SlotNumber>;
@@ -228,11 +227,11 @@ impl<T: Trait> IsMember<AuthorityId> for Module<T> {
}
}
impl<T: Trait> session::ShouldEndSession<T::BlockNumber> for Module<T> {
impl<T: Trait> pallet_session::ShouldEndSession<T::BlockNumber> for Module<T> {
fn should_end_session(now: T::BlockNumber) -> bool {
// it might be (and it is in current implementation) that session module is calling
// should_end_session() from it's own on_initialize() handler
// => because session on_initialize() is called earlier than ours, let's ensure
// => because pallet_session on_initialize() is called earlier than ours, let's ensure
// that we have synced with digest before checking if session should be ended.
Self::do_initialize(now);
@@ -292,7 +291,7 @@ impl<T: Trait> Module<T> {
pub fn slot_duration() -> T::Moment {
// we double the minimum block-period so each author can always propose within
// the majority of their slot.
<T as timestamp::Trait>::MinimumPeriod::get().saturating_mul(2.into())
<T as pallet_timestamp::Trait>::MinimumPeriod::get().saturating_mul(2.into())
}
/// Determine whether an epoch change should take place at this block.
@@ -367,7 +366,7 @@ impl<T: Trait> Module<T> {
fn deposit_consensus<U: Encode>(new: U) {
let log: DigestItem<T::Hash> = DigestItem::Consensus(BABE_ENGINE_ID, new.encode());
<system::Module<T>>::deposit_log(log.into())
<frame_system::Module<T>>::deposit_log(log.into())
}
fn deposit_vrf_output(vrf_output: &[u8; VRF_OUTPUT_LENGTH]) {
@@ -393,7 +392,7 @@ impl<T: Trait> Module<T> {
return;
}
let maybe_pre_digest = <system::Module<T>>::digest()
let maybe_pre_digest = <frame_system::Module<T>>::digest()
.logs
.iter()
.filter_map(|s| s.as_pre_runtime())
@@ -476,7 +475,7 @@ impl<T: Trait> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
type Public = AuthorityId;
}
impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
impl<T: Trait> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {
type Key = AuthorityId;
fn on_genesis_session<'a, I: 'a>(validators: I)
@@ -527,8 +526,8 @@ fn compute_randomness(
}
impl<T: Trait> ProvideInherent for Module<T> {
type Call = timestamp::Call<T>;
type Error = MakeFatalError<inherents::Error>;
type Call = pallet_timestamp::Call<T>;
type Error = MakeFatalError<sp_inherents::Error>;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
fn create_inherent(_: &InherentData) -> Option<Self::Call> {
@@ -537,7 +536,7 @@ impl<T: Trait> ProvideInherent for Module<T> {
fn check_inherent(call: &Self::Call, data: &InherentData) -> result::Result<(), Self::Error> {
let timestamp = match call {
timestamp::Call::set(ref timestamp) => timestamp.clone(),
pallet_timestamp::Call::set(ref timestamp) => timestamp.clone(),
_ => return Ok(()),
};
@@ -547,7 +546,7 @@ impl<T: Trait> ProvideInherent for Module<T> {
if timestamp_based_slot == seal_slot {
Ok(())
} else {
Err(inherents::Error::from("timestamp set in block doesn't match slot in seal").into())
Err(sp_inherents::Error::from("timestamp set in block doesn't match slot in seal").into())
}
}
}
+11 -11
View File
@@ -18,17 +18,17 @@
#![allow(dead_code, unused_imports)]
use super::{Trait, Module, GenesisConfig};
use babe_primitives::AuthorityId;
use sp_consensus_babe::AuthorityId;
use sp_runtime::{
traits::IdentityLookup, Perbill, testing::{Header, UintAuthorityId}, impl_opaque_keys,
};
use sp_version::RuntimeVersion;
use support::{impl_outer_origin, parameter_types, weights::Weight};
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use sp_io;
use primitives::{H256, Blake2Hasher};
use sp_core::{H256, Blake2Hasher};
impl_outer_origin!{
pub enum Origin for Test {}
pub enum Origin for Test where system = frame_system {}
}
type DummyValidatorId = u64;
@@ -45,11 +45,11 @@ parameter_types! {
pub const MinimumPeriod: u64 = 1;
pub const EpochDuration: u64 = 3;
pub const ExpectedBlockTime: u64 = 1;
pub const Version: RuntimeVersion = test_runtime::VERSION;
pub const Version: RuntimeVersion = substrate_test_runtime::VERSION;
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(16);
}
impl system::Trait for Test {
impl frame_system::Trait for Test {
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
@@ -73,9 +73,9 @@ impl_opaque_keys! {
}
}
impl session::Trait for Test {
impl pallet_session::Trait for Test {
type Event = ();
type ValidatorId = <Self as system::Trait>::AccountId;
type ValidatorId = <Self as frame_system::Trait>::AccountId;
type ShouldEndSession = Babe;
type SessionHandler = (Babe,Babe,);
type OnSessionEnding = ();
@@ -85,7 +85,7 @@ impl session::Trait for Test {
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
}
impl timestamp::Trait for Test {
impl pallet_timestamp::Trait for Test {
type Moment = u64;
type OnTimestampSet = Babe;
type MinimumPeriod = MinimumPeriod;
@@ -98,12 +98,12 @@ impl Trait for Test {
}
pub fn new_test_ext(authorities: Vec<DummyValidatorId>) -> sp_io::TestExternalities {
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
GenesisConfig {
authorities: authorities.into_iter().map(|a| (UintAuthorityId(a).to_public_key(), 1)).collect(),
}.assimilate_storage::<Test>(&mut t).unwrap();
t.into()
}
pub type System = system::Module<Test>;
pub type System = frame_system::Module<Test>;
pub type Babe = Module<Test>;
+10 -10
View File
@@ -19,7 +19,7 @@
use super::*;
use mock::{new_test_ext, Babe, Test};
use sp_runtime::{traits::OnFinalize, testing::{Digest, DigestItem}};
use session::ShouldEndSession;
use pallet_session::ShouldEndSession;
const EMPTY_RANDOMNESS: [u8; 32] = [
74, 25, 49, 128, 53, 97, 244, 49,
@@ -29,18 +29,18 @@ const EMPTY_RANDOMNESS: [u8; 32] = [
];
fn make_pre_digest(
authority_index: babe_primitives::AuthorityIndex,
slot_number: babe_primitives::SlotNumber,
vrf_output: [u8; babe_primitives::VRF_OUTPUT_LENGTH],
vrf_proof: [u8; babe_primitives::VRF_PROOF_LENGTH],
authority_index: sp_consensus_babe::AuthorityIndex,
slot_number: sp_consensus_babe::SlotNumber,
vrf_output: [u8; sp_consensus_babe::VRF_OUTPUT_LENGTH],
vrf_proof: [u8; sp_consensus_babe::VRF_PROOF_LENGTH],
) -> Digest {
let digest_data = babe_primitives::RawBabePreDigest::Primary {
let digest_data = sp_consensus_babe::RawBabePreDigest::Primary {
authority_index,
slot_number,
vrf_output,
vrf_proof,
};
let log = DigestItem::PreRuntime(babe_primitives::BABE_ENGINE_ID, digest_data.encode());
let log = DigestItem::PreRuntime(sp_consensus_babe::BABE_ENGINE_ID, digest_data.encode());
Digest { logs: vec![log] }
}
@@ -66,7 +66,7 @@ fn check_module() {
})
}
type System = system::Module<Test>;
type System = frame_system::Module<Test>;
#[test]
fn first_block_epoch_zero_start() {
@@ -103,8 +103,8 @@ fn first_block_epoch_zero_start() {
assert_eq!(header.digest.logs[0], pre_digest.logs[0]);
let authorities = Babe::authorities();
let consensus_log = babe_primitives::ConsensusLog::NextEpochData(
babe_primitives::NextEpochDescriptor {
let consensus_log = sp_consensus_babe::ConsensusLog::NextEpochData(
sp_consensus_babe::NextEpochDescriptor {
authorities,
randomness: Babe::randomness(),
}