forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
697b51c
commit b20b728
Showing
9 changed files
with
145 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
//! Helpers for implementing runtime api | ||
use crate::{Config, Error}; | ||
use snowbridge_core::inbound::Proof; | ||
use snowbridge_router_primitives::inbound::v2::{ConvertMessage, Message}; | ||
use xcm::{ | ||
latest::Xcm, | ||
prelude::{Junction::*, Location, SendError as XcmpSendError, SendXcm}, | ||
}; | ||
pub fn dry_run<T>(message: Message, proof: Proof) -> Result<(Xcm<()>, u128), Error<T>> | ||
where | ||
T: Config, | ||
{ | ||
Ok((Xcm::<()>::new(), 0)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
use super::*; | ||
|
||
use crate::{self as inbound_queue}; | ||
use frame_support::{derive_impl, parameter_types, traits::ConstU32, weights::IdentityFee}; | ||
use hex_literal::hex; | ||
use snowbridge_beacon_primitives::{ | ||
|
@@ -11,15 +12,14 @@ use snowbridge_core::{ | |
inbound::{Log, Proof, VerificationError}, | ||
TokenId, | ||
}; | ||
use snowbridge_router_primitives::inbound::v2::MessageToXcm; | ||
use sp_core::{H160, H256}; | ||
use sp_runtime::{ | ||
traits::{IdentifyAccount, IdentityLookup, MaybeEquivalence, Verify}, | ||
BuildStorage, FixedU128, MultiSignature, | ||
}; | ||
use sp_std::{convert::From, default::Default}; | ||
use xcm::{latest::SendXcm, prelude::*}; | ||
use snowbridge_router_primitives::inbound::v2::MessageToXcm; | ||
use crate::{self as inbound_queue}; | ||
|
||
type Block = frame_system::mocking::MockBlock<Test>; | ||
|
||
|
@@ -158,10 +158,7 @@ impl inbound_queue::Config for Test { | |
type WeightInfo = (); | ||
type GatewayAddress = GatewayAddress; | ||
type AssetHubParaId = ConstU32<1000>; | ||
type MessageConverter = MessageToXcm< | ||
EthereumNetwork, | ||
InboundQueuePalletInstance, | ||
>; | ||
type MessageConverter = MessageToXcm<EthereumNetwork, InboundQueuePalletInstance>; | ||
#[cfg(feature = "runtime-benchmarks")] | ||
type Helper = Test; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
bridges/snowbridge/primitives/router/src/inbound/dry_run.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
use crate::inbound::v2::{ConvertMessage, Message}; | ||
use codec::{Decode, Encode}; | ||
use frame_support::{ | ||
dispatch::{GetDispatchInfo, PostDispatchInfo}, | ||
Parameter, | ||
}; | ||
use scale_info::TypeInfo; | ||
use sp_runtime::{ | ||
traits::{Dispatchable, PhantomData}, | ||
Weight, | ||
}; | ||
use xcm::{ | ||
latest::Xcm, | ||
opaque::latest::{ExecuteXcm, Junction, Junction::Parachain, Location}, | ||
}; | ||
use xcm_builder::InspectMessageQueues; | ||
|
||
#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] | ||
pub enum DryRunError { | ||
/// Message cannot be decoded. | ||
InvalidPayload, | ||
/// An API call is unsupported. | ||
Unimplemented, | ||
/// Converting a versioned data structure from one version to another failed. | ||
VersionedConversionFailed, | ||
} | ||
|
||
pub trait DryRunMessage { | ||
fn dry_run_xcm(message: Message) -> Result<Xcm<()>, DryRunError>; | ||
} | ||
|
||
pub struct MessageToFeeEstimate<Runtime, Router, RuntimeCall, XcmExecutor, MessageConverter> | ||
where | ||
Runtime: frame_system::Config, | ||
Router: InspectMessageQueues, | ||
RuntimeCall: Parameter | ||
+ GetDispatchInfo | ||
+ Dispatchable<RuntimeOrigin = <Runtime>::RuntimeOrigin, PostInfo = PostDispatchInfo>, | ||
XcmExecutor: ExecuteXcm<<Runtime>::RuntimeCall>, | ||
MessageConverter: ConvertMessage, | ||
{ | ||
_phantom: PhantomData<(Runtime, Router, RuntimeCall, XcmExecutor, MessageConverter)>, | ||
} | ||
|
||
impl<Runtime, Router, RuntimeCall, XcmExecutor, MessageConverter> DryRunMessage | ||
for MessageToFeeEstimate<Runtime, Router, RuntimeCall, XcmExecutor, MessageConverter> | ||
where | ||
Runtime: frame_system::Config<RuntimeCall = RuntimeCall>, | ||
Router: InspectMessageQueues, | ||
RuntimeCall: Parameter | ||
+ GetDispatchInfo | ||
+ Dispatchable<RuntimeOrigin = <Runtime>::RuntimeOrigin, PostInfo = PostDispatchInfo>, | ||
XcmExecutor: ExecuteXcm<<Runtime>::RuntimeCall>, | ||
MessageConverter: ConvertMessage, | ||
{ | ||
fn dry_run_xcm(message: Message) -> Result<Xcm<()>, DryRunError> { | ||
let message_xcm = | ||
MessageConverter::convert(message).map_err(|error| DryRunError::InvalidPayload)?; | ||
let origin_location = Location::new(1, Parachain(1002)); | ||
|
||
let xcm_program = Xcm::<RuntimeCall>::from(message_xcm.clone().try_into().unwrap()); | ||
|
||
let origin_location: Location = origin_location | ||
.try_into() | ||
.map_err(|error| DryRunError::VersionedConversionFailed)?; | ||
let xcm: Xcm<RuntimeCall> = | ||
xcm_program.try_into().map_err(|error| DryRunError::VersionedConversionFailed)?; | ||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256); | ||
frame_system::Pallet::<Runtime>::reset_events(); // To make sure we only record events from current call. | ||
let result = XcmExecutor::prepare_and_execute( | ||
origin_location, | ||
xcm, | ||
&mut hash, | ||
Weight::MAX, // Max limit available for execution. | ||
Weight::zero(), | ||
); | ||
let forwarded_xcms = Router::get_messages(); | ||
let events: Vec<<Runtime as frame_system::Config>::RuntimeEvent> = | ||
frame_system::Pallet::<Runtime>::read_events_no_consensus() | ||
.map(|record| record.event.clone()) | ||
.collect(); | ||
Ok(vec![].into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
// SPDX-FileCopyrightText: 2021-2022 Parity Technologies (UK) Ltd. | ||
|
||
pub mod dry_run; | ||
pub mod v1; | ||
pub mod v2; | ||
use codec::Encode; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters