Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

use crate::imports::*;

use sp_keyring::AccountKeyring::Alice;
use sp_runtime::{generic, MultiSignature};
use frame_system::RawOrigin;
use xcm_fee_payment_runtime_api::{
dry_run::runtime_decl_for_xcm_dry_run_api::XcmDryRunApiV1,
fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV1,
Expand All @@ -42,6 +41,7 @@ fn teleport_relay_system_para_works() {
<Westend as TestExt>::new_ext().execute_with(|| {
type Runtime = <Westend as Chain>::Runtime;
type RuntimeCall = <Westend as Chain>::RuntimeCall;
type OriginCaller = <Westend as Chain>::OriginCaller;

let call = RuntimeCall::XcmPallet(pallet_xcm::Call::transfer_assets {
dest: Box::new(VersionedLocation::V4(destination.clone())),
Expand All @@ -50,9 +50,8 @@ fn teleport_relay_system_para_works() {
fee_asset_item: 0,
weight_limit: Unlimited,
});
let sender = Alice; // Is the same as `WestendSender`.
let extrinsic = construct_extrinsic_westend(sender, call);
let result = Runtime::dry_run_extrinsic(extrinsic).unwrap();
let origin = OriginCaller::system(RawOrigin::Signed(WestendSender::get()));
let result = Runtime::dry_run_call(origin, call).unwrap();
assert_eq!(result.forwarded_xcms.len(), 1);
let (destination_to_query, messages_to_query) = &result.forwarded_xcms[0];
assert_eq!(messages_to_query.len(), 1);
Expand Down Expand Up @@ -142,6 +141,7 @@ fn multi_hop_works() {
<PenpalA as TestExt>::execute_with(|| {
type Runtime = <PenpalA as Chain>::Runtime;
type RuntimeCall = <PenpalA as Chain>::RuntimeCall;
type OriginCaller = <PenpalA as Chain>::OriginCaller;

let call = RuntimeCall::PolkadotXcm(pallet_xcm::Call::transfer_assets {
dest: Box::new(VersionedLocation::V4(destination.clone())),
Expand All @@ -150,9 +150,8 @@ fn multi_hop_works() {
fee_asset_item: 0,
weight_limit: Unlimited,
});
let sender = Alice; // Same as `PenpalASender`.
let extrinsic = construct_extrinsic_penpal(sender, call);
let result = Runtime::dry_run_extrinsic(extrinsic).unwrap();
let origin = OriginCaller::system(RawOrigin::Signed(PenpalASender::get()));
let result = Runtime::dry_run_call(origin, call).unwrap();
assert_eq!(result.forwarded_xcms.len(), 1);
let (destination_to_query, messages_to_query) = &result.forwarded_xcms[0];
assert_eq!(messages_to_query.len(), 1);
Expand Down Expand Up @@ -304,68 +303,3 @@ fn transfer_assets_para_to_para(test: ParaToParaThroughRelayTest) -> DispatchRes
test.args.weight_limit,
)
}

// Constructs the SignedExtra component of an extrinsic for the Westend runtime.
fn construct_extrinsic_westend(
sender: sp_keyring::AccountKeyring,
call: westend_runtime::RuntimeCall,
) -> westend_runtime::UncheckedExtrinsic {
type Runtime = <Westend as Chain>::Runtime;
let account_id = <Runtime as frame_system::Config>::AccountId::from(sender.public());
let tip = 0;
let extra: westend_runtime::SignedExtra = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckMortality::<Runtime>::from(sp_runtime::generic::Era::immortal()),
frame_system::CheckNonce::<Runtime>::from(
frame_system::Pallet::<Runtime>::account(&account_id).nonce,
),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(false),
);
let raw_payload = westend_runtime::SignedPayload::new(call, extra).unwrap();
let signature = raw_payload.using_encoded(|payload| sender.sign(payload));
let (call, extra, _) = raw_payload.deconstruct();
westend_runtime::UncheckedExtrinsic::new_signed(
call,
account_id.into(),
MultiSignature::Sr25519(signature),
extra,
)
}

// Constructs the SignedExtra component of an extrinsic for the Westend runtime.
fn construct_extrinsic_penpal(
sender: sp_keyring::AccountKeyring,
call: penpal_runtime::RuntimeCall,
) -> penpal_runtime::UncheckedExtrinsic {
type Runtime = <PenpalA as Chain>::Runtime;
let account_id = <Runtime as frame_system::Config>::AccountId::from(sender.public());
let tip = 0;
let extra: penpal_runtime::SignedExtra = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckEra::<Runtime>::from(generic::Era::immortal()),
frame_system::CheckNonce::<Runtime>::from(
frame_system::Pallet::<Runtime>::account(&account_id).nonce,
),
frame_system::CheckWeight::<Runtime>::new(),
pallet_asset_tx_payment::ChargeAssetTxPayment::<Runtime>::from(tip, None),
);
type SignedPayload =
generic::SignedPayload<penpal_runtime::RuntimeCall, penpal_runtime::SignedExtra>;
let raw_payload = SignedPayload::new(call, extra).unwrap();
let signature = raw_payload.using_encoded(|payload| sender.sign(payload));
let (call, extra, _) = raw_payload.deconstruct();
penpal_runtime::UncheckedExtrinsic::new_signed(
call,
account_id.into(),
MultiSignature::Sr25519(signature),
extra,
)
}
16 changes: 4 additions & 12 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, Saturating, Verify},
traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, Dispatchable, Saturating, Verify},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Permill,
};
Expand Down Expand Up @@ -1332,21 +1332,13 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, RuntimeCall, RuntimeEvent> for Runtime {
fn dry_run_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> Result<ExtrinsicDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<ExtrinsicDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
use xcm_builder::InspectMessageQueues;
use xcm_executor::RecordXcm;
use xcm::prelude::*;

pallet_xcm::Pallet::<Runtime>::set_record_xcm(true);
let result = Executive::apply_extrinsic(extrinsic).map_err(|error| {
log::error!(
target: "xcm::XcmDryRunApi::dry_run_extrinsic",
"Applying extrinsic failed with error {:?}",
error,
);
XcmDryRunApiError::InvalidExtrinsic
})?;
let result = call.dispatch(origin.into());
let local_xcm = pallet_xcm::Pallet::<Runtime>::recorded_xcm();
let forwarded_xcms = xcm_config::XcmRouter::get_messages();
let events: Vec<RuntimeEvent> = System::read_events_no_consensus().map(|record| record.event.clone()).collect();
Expand Down
16 changes: 4 additions & 12 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, Saturating, Verify},
traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, Dispatchable, Saturating, Verify},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Perbill, Permill, RuntimeDebug,
};
Expand Down Expand Up @@ -1368,21 +1368,13 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, RuntimeCall, RuntimeEvent> for Runtime {
fn dry_run_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> Result<ExtrinsicDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<ExtrinsicDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
use xcm_builder::InspectMessageQueues;
use xcm_executor::RecordXcm;
use xcm::prelude::*;

pallet_xcm::Pallet::<Runtime>::set_record_xcm(true);
let result = Executive::apply_extrinsic(extrinsic).map_err(|error| {
log::error!(
target: "xcm::XcmDryRunApi::dry_run_extrinsic",
"Applying extrinsic failed with error {:?}",
error,
);
XcmDryRunApiError::InvalidExtrinsic
})?;
let result = call.dispatch(origin.into());
let local_xcm = pallet_xcm::Pallet::<Runtime>::recorded_xcm();
let forwarded_xcms = xcm_config::XcmRouter::get_messages();
let events: Vec<RuntimeEvent> = System::read_events_no_consensus().map(|record| record.event.clone()).collect();
Expand Down
16 changes: 4 additions & 12 deletions cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT},
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, Dispatchable},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
Expand Down Expand Up @@ -886,21 +886,13 @@ impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, RuntimeCall, RuntimeEvent> for Runtime {
fn dry_run_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> Result<ExtrinsicDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<ExtrinsicDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
use xcm_builder::InspectMessageQueues;
use xcm_executor::RecordXcm;
use xcm::prelude::*;

pallet_xcm::Pallet::<Runtime>::set_record_xcm(true);
let result = Executive::apply_extrinsic(extrinsic).map_err(|error| {
log::error!(
target: "xcm::XcmDryRunApi::dry_run_extrinsic",
"Applying extrinsic failed with error {:?}",
error,
);
XcmDryRunApiError::InvalidExtrinsic
})?;
let result = call.dispatch(origin.into());
let local_xcm = pallet_xcm::Pallet::<Runtime>::recorded_xcm();
let forwarded_xcms = xcm_config::XcmRouter::get_messages();
let events: Vec<RuntimeEvent> = System::read_events_no_consensus().map(|record| record.event.clone()).collect();
Expand Down
3 changes: 3 additions & 0 deletions cumulus/xcm/xcm-emulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ pub trait Chain: TestExt {
type RuntimeOrigin;
type RuntimeEvent;
type System;
type OriginCaller;

fn account_id_of(seed: &str) -> AccountId {
helpers::get_account_id_from_seed::<sr25519::Public>(seed)
Expand Down Expand Up @@ -366,6 +367,7 @@ macro_rules! decl_test_relay_chains {
type RuntimeOrigin = $runtime::RuntimeOrigin;
type RuntimeEvent = $runtime::RuntimeEvent;
type System = $crate::SystemPallet::<Self::Runtime>;
type OriginCaller = $runtime::OriginCaller;

fn account_data_of(account: $crate::AccountIdOf<Self::Runtime>) -> $crate::AccountData<$crate::Balance> {
<Self as $crate::TestExt>::ext_wrapper(|| $crate::SystemPallet::<Self::Runtime>::account(account).data.into())
Expand Down Expand Up @@ -600,6 +602,7 @@ macro_rules! decl_test_parachains {
type RuntimeOrigin = $runtime::RuntimeOrigin;
type RuntimeEvent = $runtime::RuntimeEvent;
type System = $crate::SystemPallet::<Self::Runtime>;
type OriginCaller = $runtime::OriginCaller;
type Network = N;

fn account_data_of(account: $crate::AccountIdOf<Self::Runtime>) -> $crate::AccountData<$crate::Balance> {
Expand Down
4 changes: 2 additions & 2 deletions polkadot/node/service/src/fake_runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ sp_api::impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, (), ()> for Runtime {
fn dry_run_extrinsic(_: <Block as BlockT>::Extrinsic) -> Result<xcm_fee_payment_runtime_api::dry_run::ExtrinsicDryRunEffects<()>, xcm_fee_payment_runtime_api::dry_run::Error> {
impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, (), (), ()> for Runtime {
fn dry_run_call(_: (), _: ()) -> Result<xcm_fee_payment_runtime_api::dry_run::ExtrinsicDryRunEffects<()>, xcm_fee_payment_runtime_api::dry_run::Error> {
unimplemented!()
}

Expand Down
15 changes: 4 additions & 11 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ use sp_core::{ConstU128, ConstU8, OpaqueMetadata, H256};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
BlakeTwo256, Block as BlockT, ConstU32, ConvertInto, Extrinsic as ExtrinsicT,
BlakeTwo256, Block as BlockT, ConstU32, ConvertInto, Dispatchable, Extrinsic as ExtrinsicT,
IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Verify,
},
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
Expand Down Expand Up @@ -1809,19 +1809,12 @@ sp_api::impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, RuntimeCall, RuntimeEvent> for Runtime {
fn dry_run_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> Result<ExtrinsicDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<ExtrinsicDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
use xcm_builder::InspectMessageQueues;
use xcm_executor::RecordXcm;
pallet_xcm::Pallet::<Runtime>::set_record_xcm(true);
let result = Executive::apply_extrinsic(extrinsic).map_err(|error| {
log::error!(
target: "xcm::XcmDryRunApi::dry_run_extrinsic",
"Applying extrinsic failed with error {:?}",
error,
);
XcmDryRunApiError::InvalidExtrinsic
})?;
let result = call.dispatch(origin.into());
let local_xcm = pallet_xcm::Pallet::<Runtime>::recorded_xcm();
let forwarded_xcms = xcm_config::XcmRouter::get_messages();
let events: Vec<RuntimeEvent> = System::read_events_no_consensus().map(|record| record.event.clone()).collect();
Expand Down
17 changes: 5 additions & 12 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ use sp_runtime::{
curve::PiecewiseLinear,
generic, impl_opaque_keys,
traits::{
BlakeTwo256, Block as BlockT, ConvertInto, Extrinsic as ExtrinsicT, IdentityLookup,
Keccak256, OpaqueKeys, SaturatedConversion, Verify,
BlakeTwo256, Block as BlockT, ConvertInto, Dispatchable, Extrinsic as ExtrinsicT,
IdentityLookup, Keccak256, OpaqueKeys, SaturatedConversion, Verify,
},
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedU128, KeyTypeId, Perbill, Percent, Permill,
Expand Down Expand Up @@ -2271,19 +2271,12 @@ sp_api::impl_runtime_apis! {
}
}

impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, RuntimeCall, RuntimeEvent> for Runtime {
fn dry_run_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> Result<ExtrinsicDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
impl xcm_fee_payment_runtime_api::dry_run::XcmDryRunApi<Block, RuntimeCall, RuntimeEvent, OriginCaller> for Runtime {
fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result<ExtrinsicDryRunEffects<RuntimeEvent>, XcmDryRunApiError> {
use xcm_builder::InspectMessageQueues;
use xcm_executor::RecordXcm;
pallet_xcm::Pallet::<Runtime>::set_record_xcm(true);
let result = Executive::apply_extrinsic(extrinsic).map_err(|error| {
log::error!(
target: "xcm::XcmDryRunApi::dry_run_extrinsic",
"Applying extrinsic failed with error {:?}",
error,
);
XcmDryRunApiError::InvalidExtrinsic
})?;
let result = call.dispatch(origin.into());
let local_xcm = pallet_xcm::Pallet::<Runtime>::recorded_xcm();
let forwarded_xcms = xcm_config::XcmRouter::get_messages();
let events: Vec<RuntimeEvent> = System::read_events_no_consensus().map(|record| record.event.clone()).collect();
Expand Down
11 changes: 5 additions & 6 deletions polkadot/xcm/xcm-fee-payment-runtime-api/src/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
//! that need to be paid.

use codec::{Decode, Encode};
use frame_support::pallet_prelude::{DispatchResult, TypeInfo};
use sp_runtime::traits::Block as BlockT;
use frame_support::pallet_prelude::{DispatchResultWithPostInfo, TypeInfo};
use sp_std::vec::Vec;
use xcm::prelude::*;

/// Effects of dry-running an extrinsic.
#[derive(Encode, Decode, Debug, TypeInfo)]
pub struct ExtrinsicDryRunEffects<Event> {
/// The result of executing the extrinsic.
pub execution_result: DispatchResult,
pub execution_result: DispatchResultWithPostInfo,
/// The list of events fired by the extrinsic.
pub emitted_events: Vec<Event>,
/// The local XCM that was attempted to be executed, if any.
Expand Down Expand Up @@ -58,9 +57,9 @@ sp_api::decl_runtime_apis! {
/// Extrinsics or XCMs might fail when executed, this doesn't mean the result of these calls will be an `Err`.
/// In those cases, there might still be a valid result, with the execution error inside it.
/// The only reasons why these calls might return an error are listed in the [`Error`] enum.
pub trait XcmDryRunApi<Call, Event: Decode> {
/// Dry run extrinsic.
fn dry_run_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> Result<ExtrinsicDryRunEffects<Event>, Error>;
pub trait XcmDryRunApi<Call: Encode, Event: Decode, OriginCaller: Encode> {
/// Dry run call.
fn dry_run_call(origin: OriginCaller, call: Call) -> Result<ExtrinsicDryRunEffects<Event>, Error>;

/// Dry run XCM program
fn dry_run_xcm(origin_location: VersionedLocation, xcm: VersionedXcm<Call>) -> Result<XcmDryRunEffects<Event>, Error>;
Expand Down
Loading