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 2 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
9 changes: 9 additions & 0 deletions parachain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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,
27, 217, 88, 127, 46, 143, 199, 70, 236, 66, 212, 244, 85, 221, 153, 104, 175, 37,
224, 20, 140, 95, 140, 7, 27, 74, 182, 199, 77, 12, 194, 236,
],
}
.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,6 +176,7 @@ 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![
// Teleport required fees.
Expand All @@ -165,6 +185,7 @@ where
BuyExecution { fees: xcm_fee, weight_limit: Unlimited },
// Fund the snowbridge sovereign with the required deposit for creation.
DepositAsset { assets: Definite(deposit.into()), beneficiary: bridge_location },
DescendOrigin(X1(PalletInstance(inbound_queue_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.

Shouldn't this DescendOrigin be placed at the start of message, before BuyExecution?

As otherwise, we have three origins in this message, which makes it more complicated.

cc @alistair-singh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't work, putting the DescendOrigin before BuyExecution then results in a barrier error. The way I understand it, the DescendOrigin shouldn't be before BuyExecution because it's not really related to the BuyExecution. BuyExecution is to pay for fees in DOT, and then the DescendOrigin is to further specialize the origin to be BridgeHub/Pallet(EthereumInboundQueue). @alistair-singh correct me if I am wrong.

Copy link
Contributor

@yrong yrong Dec 2, 2023

Choose a reason for hiding this comment

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

@claravanstaden I agree with @vgeddes here, IMO it's better to move DescendOrigin to first, add another PR with some revamp accordingly in
https://github.com/Snowfork/snowbridge/pull/1034/files#diff-9218e396410f01117c1c305b9cf006f6498bb0b3c0aedb8952a8450b4b1c5715 for us to review.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome! Thanks Ron, taking a look...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @yrong, I merged it.

// Change origin to the bridge.
UniversalOrigin(GlobalConsensus(network)),
// Call create_asset on foreign assets pallet.
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