Skip to content

Commit

Permalink
Load AssetHub's ParaId from runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Dec 13, 2024
1 parent a7cb93d commit 277d51b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ substrate.code-workspace
target/
*.scale
justfile
python-venv
18 changes: 13 additions & 5 deletions bridges/snowbridge/primitives/router/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,47 @@ use sp_std::{iter::Peekable, marker::PhantomData, prelude::*};
use xcm::prelude::*;
use xcm_executor::traits::{ConvertLocation, ExportXcm};

pub const ASSET_HUB_PARA_ID:u32 = 1000;

pub struct EthereumBlobExporter<
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
AssetHubParaId,
>(
PhantomData<(
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
AssetHubParaId,
)>,
);

impl<UniversalLocation, EthereumNetwork, OutboundQueue, AgentHashedDescription, ConvertAssetId>
ExportXcm
impl<
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
AssetHubParaId,
> ExportXcm
for EthereumBlobExporter<
UniversalLocation,
EthereumNetwork,
OutboundQueue,
AgentHashedDescription,
ConvertAssetId,
AssetHubParaId,
>
where
UniversalLocation: Get<InteriorLocation>,
EthereumNetwork: Get<NetworkId>,
OutboundQueue: SendMessage<Balance = u128>,
AgentHashedDescription: ConvertLocation<H256>,
ConvertAssetId: MaybeEquivalence<TokenId, Location>,
AssetHubParaId: Get<ParaId>,
{
type Ticket = (Vec<u8>, XcmHash);

Expand Down Expand Up @@ -98,7 +106,7 @@ where

// Check the location here can only be AssetHub sovereign
let para_id = match local_sub.as_slice() {
[Parachain(para_id)] if *para_id == ASSET_HUB_PARA_ID => *para_id,
[Parachain(para_id)] if ParaId::from(*para_id) == AssetHubParaId::get() => *para_id,
_ => {
log::debug!(target: "xcm::ethereum_blob_exporter", "only supports Asset Hub root location as the universal source '{local_sub:?}'.");
return Err(SendError::NotApplicable);
Expand Down
17 changes: 17 additions & 0 deletions bridges/snowbridge/primitives/router/src/outbound/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ parameter_types! {
UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(1013)].into();
const BridgedNetwork: NetworkId = Ethereum{ chain_id: 1 };
const NonBridgedNetwork: NetworkId = Ethereum{ chain_id: 2 };
pub AssetHubParaId: ParaId = ParaId::from(1000);
}

struct MockOkOutboundQueue;
Expand Down Expand Up @@ -86,6 +87,7 @@ fn exporter_validate_with_unknown_network_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -105,6 +107,7 @@ fn exporter_validate_with_invalid_destination_yields_missing_argument() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::MissingArgument));
}
Expand All @@ -127,6 +130,7 @@ fn exporter_validate_with_x8_destination_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -146,6 +150,7 @@ fn exporter_validate_without_universal_source_yields_missing_argument() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::MissingArgument));
}
Expand All @@ -165,6 +170,7 @@ fn exporter_validate_without_global_universal_location_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -184,6 +190,7 @@ fn exporter_validate_without_global_bridge_location_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -204,6 +211,7 @@ fn exporter_validate_with_remote_universal_source_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -223,6 +231,7 @@ fn exporter_validate_without_para_id_in_source_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -243,6 +252,7 @@ fn exporter_validate_complex_para_id_in_source_yields_not_applicable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::NotApplicable));
}
Expand All @@ -263,6 +273,7 @@ fn exporter_validate_without_xcm_message_yields_missing_argument() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);
assert_eq!(result, Err(XcmSendError::MissingArgument));
}
Expand Down Expand Up @@ -310,6 +321,7 @@ fn exporter_validate_with_max_target_fee_yields_unroutable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);

assert_eq!(result, Err(XcmSendError::Unroutable));
Expand Down Expand Up @@ -337,6 +349,7 @@ fn exporter_validate_with_unparsable_xcm_yields_unroutable() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);

assert_eq!(result, Err(XcmSendError::Unroutable));
Expand Down Expand Up @@ -383,6 +396,7 @@ fn exporter_validate_xcm_success_case_1() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(network, channel, &mut universal_source, &mut destination, &mut message);

assert!(result.is_ok());
Expand All @@ -396,6 +410,7 @@ fn exporter_deliver_with_submit_failure_yields_unroutable() {
MockErrOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::deliver((hex!("deadbeef").to_vec(), XcmHash::default()));
assert_eq!(result, Err(XcmSendError::Transport("other transport error")))
}
Expand Down Expand Up @@ -1208,6 +1223,7 @@ fn exporter_validate_with_invalid_dest_does_not_alter_destination() {
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(
network, channel, &mut universal_source_wrapper, &mut dest_wrapper, &mut msg_wrapper
);
Expand Down Expand Up @@ -1261,6 +1277,7 @@ fn exporter_validate_with_invalid_universal_source_does_not_alter_universal_sour
MockOkOutboundQueue,
AgentIdOf,
MockTokenIdConvert,
AssetHubParaId,
>::validate(
network, channel, &mut universal_source_wrapper, &mut dest_wrapper, &mut msg_wrapper
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use testnet_parachains_constants::rococo::{
use crate::xcm_config::RelayNetwork;
#[cfg(feature = "runtime-benchmarks")]
use benchmark_helpers::DoNothingRouter;
use cumulus_primitives_core::ParaId;
use frame_support::{parameter_types, weights::ConstantMultiplier};
use pallet_xcm::EnsureXcm;
use sp_runtime::{
Expand All @@ -50,11 +51,13 @@ pub type SnowbridgeExporter = EthereumBlobExporter<
snowbridge_pallet_outbound_queue::Pallet<Runtime>,
snowbridge_core::AgentIdOf,
EthereumSystem,
AssetHubParaId,
>;

// Ethereum Bridge
parameter_types! {
pub storage EthereumGatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"));
pub AssetHubParaId: ParaId = ParaId::from(rococo_runtime_constants::system_parachain::ASSET_HUB_ID);
}

parameter_types! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use testnet_parachains_constants::westend::{
use crate::xcm_config::RelayNetwork;
#[cfg(feature = "runtime-benchmarks")]
use benchmark_helpers::DoNothingRouter;
use cumulus_primitives_core::ParaId;
use frame_support::{parameter_types, weights::ConstantMultiplier};
use pallet_xcm::EnsureXcm;
use sp_runtime::{
Expand All @@ -53,11 +54,13 @@ pub type SnowbridgeExporter = EthereumBlobExporter<
snowbridge_pallet_outbound_queue::Pallet<Runtime>,
snowbridge_core::AgentIdOf,
EthereumSystem,
AssetHubParaId,
>;

// Ethereum Bridge
parameter_types! {
pub storage EthereumGatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"));
pub AssetHubParaId: ParaId = ParaId::from(westend_runtime_constants::system_parachain::ASSET_HUB_ID);
}

parameter_types! {
Expand Down

0 comments on commit 277d51b

Please sign in to comment.