Skip to content

Commit

Permalink
Use pallet instance in inbound queue origin (#1033)
Browse files Browse the repository at this point in the history
* use pallet instance in inbound queue origin

* cleanup

* update polkadot-sdk

* Move DescendOrigin to first (#1034)

* update polkadot-sdk

* fix test

* remove patch in snowbridge workspace

* adds patch back in

* Include runtime utilities and tests in workspace (#1037)

* update polkadot sdk and fmt

---------

Co-authored-by: claravanstaden <Cats 4 life!>
Co-authored-by: Ron <yrong1997@gmail.com>
Co-authored-by: Vincent Geddes <vincent@snowfork.com>
  • Loading branch information
3 people authored Dec 2, 2023
1 parent cedd900 commit c2142e4
Show file tree
Hide file tree
Showing 11 changed files with 10,509 additions and 15,940 deletions.
13,380 changes: 10,461 additions & 2,919 deletions parachain/Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"pallets/system/runtime-api",
"runtime/runtime-common",
"runtime/rococo-common",
"runtime/tests",
]

[patch.'https://github.com/snowfork/snowbridge']
Expand All @@ -27,3 +28,4 @@ snowbridge-outbound-queue = { path = "./pallets/outbound-queue" }
snowbridge-outbound-queue-runtime-api = { path = "./pallets/outbound-queue/runtime-api" }
snowbridge-router-primitives = { path = "./primitives/router" }
snowbridge-runtime-common = { path = "./runtime/runtime-common" }
snowbridge-rococo-common = { path = "./runtime/rococo-common" }
9 changes: 8 additions & 1 deletion parachain/pallets/inbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ parameter_types! {
pub const CreateAssetDeposit: u128 = 100_000_000_000;
pub const SendTokenExecutionFee: u128 = 1_000_000_000;
pub const InitialFund: u128 = 1_000_000_000_000;
pub const InboundQueuePalletInstance: u8 = 80;
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -205,7 +206,13 @@ impl inbound_queue::Config for Test {
type XcmSender = MockXcmSender;
type WeightInfo = ();
type GatewayAddress = GatewayAddress;
type MessageConverter = MessageToXcm<CreateAssetCall, CreateAssetDeposit, AccountId, Balance>;
type MessageConverter = MessageToXcm<
CreateAssetCall,
CreateAssetDeposit,
InboundQueuePalletInstance,
AccountId,
Balance,
>;
type PricingParameters = Parameters;
type ChannelLookup = MockChannelLookup;
#[cfg(feature = "runtime-benchmarks")]
Expand Down
4 changes: 2 additions & 2 deletions parachain/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ fn test_submit_happy_path() {
.into(),
nonce: 1,
message_id: [
156, 20, 62, 219, 36, 60, 225, 79, 64, 233, 45, 201, 222, 208, 39, 132, 37, 103,
46, 160, 28, 26, 185, 50, 112, 230, 213, 92, 157, 236, 44, 190,
87, 139, 41, 107, 220, 225, 189, 145, 129, 58, 178, 27, 103, 150, 141, 241, 152,
122, 46, 202, 151, 237, 245, 152, 195, 58, 50, 16, 71, 96, 89, 87,
],
}
.into()]);
Expand Down
39 changes: 31 additions & 8 deletions parachain/primitives/router/src/inbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,24 @@ pub enum Destination {
},
}

pub struct MessageToXcm<CreateAssetCall, CreateAssetDeposit, AccountId, Balance>
where
pub struct MessageToXcm<
CreateAssetCall,
CreateAssetDeposit,
InboundQueuePalletInstance,
AccountId,
Balance,
> where
CreateAssetCall: Get<CallIndex>,
CreateAssetDeposit: Get<u128>,
Balance: BalanceT,
{
_phantom: PhantomData<(CreateAssetCall, CreateAssetDeposit, AccountId, Balance)>,
_phantom: PhantomData<(
CreateAssetCall,
CreateAssetDeposit,
InboundQueuePalletInstance,
AccountId,
Balance,
)>,
}

/// Reason why a message conversion failed.
Expand All @@ -113,11 +124,18 @@ pub trait ConvertMessage {

pub type CallIndex = [u8; 2];

impl<CreateAssetCall, CreateAssetDeposit, AccountId, Balance> ConvertMessage
for MessageToXcm<CreateAssetCall, CreateAssetDeposit, AccountId, Balance>
where
impl<CreateAssetCall, CreateAssetDeposit, InboundQueuePalletInstance, AccountId, Balance>
ConvertMessage
for MessageToXcm<
CreateAssetCall,
CreateAssetDeposit,
InboundQueuePalletInstance,
AccountId,
Balance,
> where
CreateAssetCall: Get<CallIndex>,
CreateAssetDeposit: Get<u128>,
InboundQueuePalletInstance: Get<u8>,
Balance: BalanceT + From<u128>,
AccountId: Into<[u8; 32]>,
{
Expand All @@ -136,11 +154,12 @@ where
}
}

impl<CreateAssetCall, CreateAssetDeposit, AccountId, Balance>
MessageToXcm<CreateAssetCall, CreateAssetDeposit, AccountId, Balance>
impl<CreateAssetCall, CreateAssetDeposit, InboundQueuePalletInstance, AccountId, Balance>
MessageToXcm<CreateAssetCall, CreateAssetDeposit, InboundQueuePalletInstance, AccountId, Balance>
where
CreateAssetCall: Get<CallIndex>,
CreateAssetDeposit: Get<u128>,
InboundQueuePalletInstance: Get<u8>,
Balance: BalanceT + From<u128>,
AccountId: Into<[u8; 32]>,
{
Expand All @@ -157,8 +176,10 @@ where
let owner = GlobalConsensusEthereumConvertsFor::<[u8; 32]>::from_chain_id(&chain_id);
let asset_id = Self::convert_token_address(network, token);
let create_call_index: [u8; 2] = CreateAssetCall::get();
let inbound_queue_pallet_index = InboundQueuePalletInstance::get();

let xcm: Xcm<()> = vec![
DescendOrigin(X1(PalletInstance(inbound_queue_pallet_index))),
// Teleport required fees.
ReceiveTeleportedAsset(total.into()),
// Pay for execution.
Expand Down Expand Up @@ -226,10 +247,12 @@ where

let total_fees = asset_hub_fee.saturating_add(dest_para_fee);
let total_fee_asset: MultiAsset = (MultiLocation::parent(), total_fees).into();
let inbound_queue_pallet_index = InboundQueuePalletInstance::get();

let mut instructions = vec![
ReceiveTeleportedAsset(total_fee_asset.into()),
BuyExecution { fees: asset_hub_fee_asset, weight_limit: Unlimited },
DescendOrigin(X1(PalletInstance(inbound_queue_pallet_index))),
UniversalOrigin(GlobalConsensus(network)),
ReserveAssetDeposited(asset.clone().into()),
ClearOrigin,
Expand Down
2 changes: 2 additions & 0 deletions parachain/runtime/rococo-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use frame_support::parameter_types;
use xcm::opaque::lts::NetworkId;

pub const INBOUND_QUEUE_MESSAGES_PALLET_INDEX: u8 = 80;

parameter_types! {
// Network and location for the Ethereum chain.
pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
Expand Down
Loading

0 comments on commit c2142e4

Please sign in to comment.