Update Substrate Dependency (#566)

* Update `sp-io` dependency

* Rename Trait to Config

* RustFmt

* Bump `sp-io` again

* Use new frame_system weight types in Rialto and Millau runtimes

* Update test Runtimes to use new weight types

* Bump `sp-io` again

* Update to not-the latest first.

* Update benchmarks.

* Another Trai.

* Move new weight types into runtime primitive crates

This allows us to check limits for extrinsics from other parts
of the codebase without pulling in the entire chain runtime.

* Remove leftover comments

* Move new functions to a better location

* Small formatting fixes

* Add actual documentation to new weight config types

* Decrease maximum block weight of Millau chain

* Decreease maximum block length of Millau chain

Co-authored-by: Tomasz Drwięga <tomasz@parity.io>
This commit is contained in:
Hernando Castano
2020-12-16 04:52:53 -05:00
committed by Bastian Köcher
parent 8a5b51a944
commit ee655b1057
31 changed files with 328 additions and 293 deletions
+13 -13
View File
@@ -60,13 +60,13 @@ mod mock;
mod fork_tests;
/// Block number of the bridged chain.
pub(crate) type BridgedBlockNumber<T> = BlockNumberOf<<T as Trait>::BridgedChain>;
pub(crate) type BridgedBlockNumber<T> = BlockNumberOf<<T as Config>::BridgedChain>;
/// Block hash of the bridged chain.
pub(crate) type BridgedBlockHash<T> = HashOf<<T as Trait>::BridgedChain>;
pub(crate) type BridgedBlockHash<T> = HashOf<<T as Config>::BridgedChain>;
/// Hasher of the bridged chain.
pub(crate) type BridgedBlockHasher<T> = HasherOf<<T as Trait>::BridgedChain>;
pub(crate) type BridgedBlockHasher<T> = HasherOf<<T as Config>::BridgedChain>;
/// Header of the bridged chain.
pub(crate) type BridgedHeader<T> = HeaderOf<<T as Trait>::BridgedChain>;
pub(crate) type BridgedHeader<T> = HeaderOf<<T as Config>::BridgedChain>;
/// A convenience type identifying headers.
#[derive(RuntimeDebug, PartialEq)]
@@ -77,13 +77,13 @@ pub struct HeaderId<H: HeaderT> {
pub hash: H::Hash,
}
pub trait Trait: frame_system::Trait {
pub trait Config: frame_system::Config {
/// Chain that we are bridging here.
type BridgedChain: Chain;
}
decl_storage! {
trait Store for Module<T: Trait> as SubstrateBridge {
trait Store for Module<T: Config> as SubstrateBridge {
/// The number of the highest block(s) we know of.
BestHeight: BridgedBlockNumber<T>;
/// Hash of the header at the highest known height.
@@ -137,7 +137,7 @@ decl_storage! {
}
decl_error! {
pub enum Error for Module<T: Trait> {
pub enum Error for Module<T: Config> {
/// This header has failed basic verification.
InvalidHeader,
/// This header has not been finalized.
@@ -156,7 +156,7 @@ decl_error! {
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
/// Import a signed Substrate header into the runtime.
@@ -277,7 +277,7 @@ decl_module! {
}
}
impl<T: Trait> Module<T> {
impl<T: Config> Module<T> {
/// Get the highest header(s) that the pallet knows of.
pub fn best_headers() -> Vec<(BridgedBlockNumber<T>, BridgedBlockHash<T>)> {
PalletStorage::<T>::new()
@@ -353,7 +353,7 @@ impl<T: Trait> Module<T> {
}
/// Ensure that the origin is either root, or `ModuleOwner`.
fn ensure_owner_or_root<T: Trait>(origin: T::Origin) -> Result<(), BadOrigin> {
fn ensure_owner_or_root<T: Config>(origin: T::Origin) -> Result<(), BadOrigin> {
match origin.into() {
Ok(RawOrigin::Root) => Ok(()),
Ok(RawOrigin::Signed(ref signer)) if Some(signer) == <Module<T>>::module_owner().as_ref() => Ok(()),
@@ -362,7 +362,7 @@ fn ensure_owner_or_root<T: Trait>(origin: T::Origin) -> Result<(), BadOrigin> {
}
/// Ensure that the pallet is in operational mode (not halted).
fn ensure_operational<T: Trait>() -> Result<(), Error<T>> {
fn ensure_operational<T: Config>() -> Result<(), Error<T>> {
if IsHalted::get() {
Err(<Error<T>>::Halted)
} else {
@@ -372,7 +372,7 @@ fn ensure_operational<T: Trait>() -> Result<(), Error<T>> {
/// Since this writes to storage with no real checks this should only be used in functions that were
/// called by a trusted origin.
fn initialize_bridge<T: Trait>(init_params: InitializationData<BridgedHeader<T>>) {
fn initialize_bridge<T: Config>(init_params: InitializationData<BridgedHeader<T>>) {
let InitializationData {
header,
authority_list,
@@ -488,7 +488,7 @@ impl<T> PalletStorage<T> {
}
}
impl<T: Trait> BridgeStorage for PalletStorage<T> {
impl<T: Config> BridgeStorage for PalletStorage<T> {
type Header = BridgedHeader<T>;
fn write_header(&mut self, header: &ImportedHeader<BridgedHeader<T>>) {
+10 -14
View File
@@ -20,7 +20,7 @@
#![cfg(test)]
use crate::Trait;
use crate::Config;
use bp_runtime::Chain;
use frame_support::{impl_outer_origin, parameter_types, weights::Weight};
use sp_runtime::{
@@ -45,7 +45,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for TestRuntime {
impl frame_system::Config for TestRuntime {
type Origin = Origin;
type Index = u64;
type Call = ();
@@ -57,13 +57,6 @@ impl frame_system::Trait for TestRuntime {
type Header = Header;
type Event = ();
type BlockHashCount = BlockHashCount;
type MaximumBlockWeight = MaximumBlockWeight;
type DbWeight = ();
type BlockExecutionWeight = ();
type ExtrinsicBaseWeight = ();
type MaximumExtrinsicWeight = ();
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
type Version = ();
type PalletInfo = ();
type AccountData = ();
@@ -71,9 +64,12 @@ impl frame_system::Trait for TestRuntime {
type OnKilledAccount = ();
type BaseCallFilter = ();
type SystemWeightInfo = ();
type DbWeight = ();
type BlockWeights = ();
type BlockLength = ();
}
impl Trait for TestRuntime {
impl Config for TestRuntime {
type BridgedChain = TestBridgedChain;
}
@@ -81,10 +77,10 @@ impl Trait for TestRuntime {
pub struct TestBridgedChain;
impl Chain for TestBridgedChain {
type BlockNumber = <TestRuntime as frame_system::Trait>::BlockNumber;
type Hash = <TestRuntime as frame_system::Trait>::Hash;
type Hasher = <TestRuntime as frame_system::Trait>::Hashing;
type Header = <TestRuntime as frame_system::Trait>::Header;
type BlockNumber = <TestRuntime as frame_system::Config>::BlockNumber;
type Hash = <TestRuntime as frame_system::Config>::Hash;
type Hasher = <TestRuntime as frame_system::Config>::Hashing;
type Header = <TestRuntime as frame_system::Config>::Header;
}
pub fn run_test<T>(test: impl FnOnce() -> T) -> T {
@@ -65,7 +65,7 @@ pub enum Error {
StorageValueUnavailable,
}
impl<T: crate::Trait> From<Error> for crate::Error<T> {
impl<T: crate::Config> From<Error> for crate::Error<T> {
fn from(error: Error) -> Self {
match error {
Error::StorageRootMismatch => crate::Error::StorageRootMismatch,