Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pallet instance in inbound queue origin #1033

Merged
merged 10 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is an API for retrieving a pallet's index: https://substrate.stackexchange.com/a/794

Copy link
Contributor Author

@claravanstaden claravanstaden Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works nicely in BridgeHub, but I need the EthereumInboundQueue pallet index on BridgeHub in the AssetHub runtime too: https://github.com/Snowfork/polkadot-sdk/pull/51/files#diff-a86375df98e04ca3cce1ea35c40257a222e2d5087f5f528ff33307678b78dc2dR863

I don't think it would be correct to import bridge hub as a dependency in the AssetHub crate, and I don't know how else to share the pallet index.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok makes sense 👌


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