Skip to content

Commit

Permalink
Simplify code by removing impl_runtime_apis
Browse files Browse the repository at this point in the history
  • Loading branch information
louismerlin committed Feb 7, 2024
1 parent 11302c9 commit 3281a1f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 129 deletions.
1 change: 0 additions & 1 deletion polkadot/xcm/xcm-simulator/fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ sp-core = { path = "../../../../substrate/primitives/core" }
sp-runtime = { path = "../../../../substrate/primitives/runtime" }
sp-io = { path = "../../../../substrate/primitives/io" }
sp-api = { path = "../../../../substrate/primitives/api" }
sp-version = { path = "../../../../substrate/primitives/version" }

xcm = { package = "staging-xcm", path = "../.." }
xcm-simulator = { path = ".." }
Expand Down
65 changes: 1 addition & 64 deletions polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use frame_support::{
use frame_system::EnsureRoot;
use sp_core::ConstU32;
use sp_runtime::{
create_runtime_str, generic,
generic,
traits::{AccountIdLookup, BlakeTwo256, Hash, IdentifyAccount, Verify},
MultiAddress, MultiSignature,
};
Expand All @@ -37,7 +37,6 @@ use polkadot_core_primitives::BlockNumber as RelayBlockNumber;
use polkadot_parachain_primitives::primitives::{
DmpMessageHandler, Id as ParaId, Sibling, XcmpMessageFormat, XcmpMessageHandler,
};
use sp_version::RuntimeVersion;
use xcm::{latest::prelude::*, VersionedXcm};
#[allow(deprecated)]
use xcm_builder::CurrencyAdapter as XcmCurrencyAdapter;
Expand All @@ -62,18 +61,6 @@ pub type Signature = MultiSignature;
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
pub type Balance = u128;

#[allow(unused_parens)]
type Migrations = ();

pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
Migrations,
>;

parameter_types! {
pub const BlockHashCount: u32 = 250;
}
Expand Down Expand Up @@ -370,53 +357,3 @@ construct_runtime!(
PolkadotXcm: pallet_xcm,
}
);

#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node-template"),
impl_name: create_runtime_str!("node-template"),
authoring_version: 1,
spec_version: 100,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
};

sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
}

fn execute_block(block: Block) {
Executive::execute_block(block);
}

fn initialize_block(header: &<Block as sp_runtime::traits::Block>::Header) {
Executive::initialize_block(header)
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here. If any of the pre/post migration checks fail, we shall stop
// right here and right now.
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, 0.into())
}

fn execute_block(
block: Block,
state_root_check: bool,
signature_check: bool,
select: frame_try_runtime::TryStateSelect
) -> Weight {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here.
Executive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed")
}
}
}
65 changes: 1 addition & 64 deletions polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use frame_support::{
use frame_system::EnsureRoot;
use sp_core::ConstU32;
use sp_runtime::{
create_runtime_str, generic,
generic,
traits::{BlakeTwo256, IdentifyAccount, Verify},
MultiAddress, MultiSignature,
};
Expand All @@ -36,7 +36,6 @@ use polkadot_runtime_parachains::{
inclusion::{AggregateMessageOrigin, UmpQueueId},
origin, shared,
};
use sp_version::RuntimeVersion;
use xcm::latest::prelude::*;
#[allow(deprecated)]
use xcm_builder::CurrencyAdapter as XcmCurrencyAdapter;
Expand All @@ -61,18 +60,6 @@ pub type Signature = MultiSignature;
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
pub type Balance = u128;

#[allow(unused_parens)]
type Migrations = ();

pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
Migrations,
>;

parameter_types! {
pub const BlockHashCount: u32 = 250;
}
Expand Down Expand Up @@ -265,53 +252,3 @@ construct_runtime!(
MessageQueue: pallet_message_queue,
}
);

#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node-template"),
impl_name: create_runtime_str!("node-template"),
authoring_version: 1,
spec_version: 100,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
};

sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
}

fn execute_block(block: Block) {
Executive::execute_block(block);
}

fn initialize_block(header: &<Block as sp_runtime::traits::Block>::Header) {
Executive::initialize_block(header)
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here. If any of the pre/post migration checks fail, we shall stop
// right here and right now.
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, 0.into())
}

fn execute_block(
block: Block,
state_root_check: bool,
signature_check: bool,
select: frame_try_runtime::TryStateSelect
) -> Weight {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here.
Executive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed")
}
}
}

0 comments on commit 3281a1f

Please sign in to comment.