Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Refactor with remote exporter #71

Merged
merged 8 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ rococo-westend-system-emulated-network = { path = "../../../networks/rococo-west
bridge-hub-rococo-emulated-chain = { path = "../../../chains/parachains/bridges/bridge-hub-rococo" }
asset-hub-rococo-emulated-chain = { path = "../../../chains/parachains/assets/asset-hub-rococo" }
penpal-emulated-chain = { path = "../../../chains/parachains/testing/penpal" }
penpal-runtime = { path = "../../../../../runtimes/testing/penpal" }
penpal-runtime = { path = "../../../../../runtimes/testing/penpal", default-features = false }
rococo-system-emulated-network = { path = "../../../networks/rococo-system" }
asset-hub-rococo-runtime = { path = "../../../../../runtimes/assets/asset-hub-rococo", default-features = false }

# Snowbridge
snowbridge-core = { path = "../../../../../../../../parachain/primitives/core", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ fn send_token() {

#[test]
fn reserve_transfer_token() {
use asset_hub_rococo_runtime::xcm_config::bridging::to_ethereum::DefaultBridgeHubEthereumBaseFee;
let assethub_sovereign = BridgeHubRococo::sovereign_account_id_of(MultiLocation {
parents: 1,
interior: X1(Parachain(ASSETHUB_PARA_ID)),
Expand Down Expand Up @@ -476,6 +477,9 @@ fn reserve_transfer_token() {
interior: X1(AccountKey20 { network: None, key: ETHEREUM_DESTINATION_ADDRESS.into() }),
});

let free_balance_before = <AssetHubRococo as AssetHubRococoPallet>::Balances::free_balance(
AssetHubRococoReceiver::get(),
);
<AssetHubRococo as AssetHubRococoPallet>::PolkadotXcm::reserve_transfer_assets(
RuntimeOrigin::signed(AssetHubRococoReceiver::get()),
Box::new(destination),
Expand All @@ -484,6 +488,12 @@ fn reserve_transfer_token() {
0,
)
.unwrap();
let free_balance_after = <AssetHubRococo as AssetHubRococoPallet>::Balances::free_balance(
AssetHubRococoReceiver::get(),
);
// assert at least DefaultBridgeHubEthereumBaseFee charged from the sender
let free_balance_diff = free_balance_before - free_balance_after;
assert!(free_balance_diff > DefaultBridgeHubEthereumBaseFee::get());
});

BridgeHubRococo::execute_with(|| {
Expand All @@ -508,7 +518,7 @@ fn reserve_transfer_token() {
events.iter().any(|event| matches!(
event,
RuntimeEvent::Balances(pallet_balances::Event::Deposit{ who, amount })
if *who == assethub_sovereign && *amount == 2680000000000
if *who == assethub_sovereign && *amount == 2680000000000,
)),
"Assethub sovereign takes remote fee."
);
Expand Down
66 changes: 0 additions & 66 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,38 +872,6 @@ impl pallet_xcm_bridge_hub_router::Config<ToWestendXcmRouterInstance> for Runtim
type FeeAsset = xcm_config::bridging::XcmBridgeHubRouterFeeAssetId;
}

/// XCM router instance to BridgeHub with bridging capabilities for `Ethereum` global
/// consensus with dynamic fees and back-pressure.
pub type ToEthereumXcmRouterInstance = pallet_xcm_bridge_hub_router::Instance4;
impl pallet_xcm_bridge_hub_router::Config<ToEthereumXcmRouterInstance> for Runtime {
type WeightInfo = weights::pallet_xcm_bridge_hub_router::WeightInfo<Runtime>;

type UniversalLocation = xcm_config::UniversalLocation;
type BridgedNetworkId = snowbridge_rococo_common::EthereumNetwork;
type Bridges = xcm_config::bridging::NetworkExportTable;
type DestinationVersion = PolkadotXcm;

#[cfg(not(feature = "runtime-benchmarks"))]
type BridgeHubOrigin = EnsureXcm<Equals<xcm_config::bridging::SiblingBridgeHub>>;
#[cfg(feature = "runtime-benchmarks")]
type BridgeHubOrigin = EitherOfDiverse<
// for running benchmarks
EnsureRoot<AccountId>,
// for running tests with `--feature runtime-benchmarks`
EnsureXcm<Equals<xcm_config::bridging::SiblingBridgeHub>>,
>;

type ToBridgeHubSender = XcmpQueue;
type WithBridgeHubChannel =
cumulus_pallet_xcmp_queue::bridging::InAndOutXcmpChannelStatusProvider<
xcm_config::bridging::SiblingBridgeHubParaId,
Runtime,
>;

type ByteFee = xcm_config::bridging::XcmBridgeHubRouterByteFee;
type FeeAsset = xcm_config::bridging::XcmBridgeHubRouterFeeAssetId;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime
Expand Down Expand Up @@ -941,8 +909,6 @@ construct_runtime!(

// Bridge utilities.
ToWestendXcmRouter: pallet_xcm_bridge_hub_router::<Instance3>::{Pallet, Storage, Call} = 45,
ToEthereumXcmRouter: pallet_xcm_bridge_hub_router::<Instance4>::{Pallet, Storage, Call} = 46,

// The main stage.
Assets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 50,
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,
Expand Down Expand Up @@ -1074,7 +1040,6 @@ mod benches {
[pallet_collator_selection, CollatorSelection]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_xcm_bridge_hub_router, ToWestend]
[pallet_xcm_bridge_hub_router, ToEthereum]
// XCM
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
// NOTE: Make sure you point to the individual modules below.
Expand Down Expand Up @@ -1332,7 +1297,6 @@ impl_runtime_apis! {
type Pool = pallet_assets::Pallet::<Runtime, PoolAssetsInstance>;

type ToWestend = XcmBridgeHubRouterBench<Runtime, ToWestendXcmRouterInstance>;
type ToEthereum = XcmBridgeHubRouterBench<Runtime, ToEthereumXcmRouterInstance>;

let mut list = Vec::<BenchmarkList>::new();
list_benchmarks!(list, extra);
Expand Down Expand Up @@ -1478,35 +1442,6 @@ impl_runtime_apis! {
}
}

impl XcmBridgeHubRouterConfig<ToEthereumXcmRouterInstance> for Runtime {
fn make_congested() {
cumulus_pallet_xcmp_queue::bridging::suspend_channel_for_benchmarks::<Runtime>(
xcm_config::bridging::SiblingBridgeHubParaId::get().into()
);
}
fn ensure_bridged_target_destination() -> Result<MultiLocation, BenchmarkError> {
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
xcm_config::bridging::SiblingBridgeHubParaId::get().into()
);
let bridged_network = xcm_config::bridging::to_ethereum::EthereumLocation::get();
let _ = PolkadotXcm::force_xcm_version(
RuntimeOrigin::root(),
Box::new(bridged_network),
XCM_VERSION,
).map_err(|e| {
log::error!(
"Failed to dispatch `force_xcm_version({:?}, {:?}, {:?})`, error: {:?}",
RuntimeOrigin::root(),
bridged_network,
XCM_VERSION,
e
);
BenchmarkError::Stop("XcmVersion was not stored!")
})?;
Ok(bridged_network)
}
}

use xcm::latest::prelude::*;
use xcm_config::{TokenLocation, MaxAssetsIntoHolding};
use pallet_xcm_benchmarks::asset_instance_from;
Expand Down Expand Up @@ -1642,7 +1577,6 @@ impl_runtime_apis! {
type Pool = pallet_assets::Pallet::<Runtime, PoolAssetsInstance>;

type ToWestend = XcmBridgeHubRouterBench<Runtime, ToWestendXcmRouterInstance>;
type ToEthereum = XcmBridgeHubRouterBench<Runtime, ToEthereumXcmRouterInstance>;

let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use super::{
AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, BaseDeliveryFee,
FeeAssetId, ForeignAssets, ForeignAssetsInstance, ParachainInfo, ParachainSystem, PolkadotXcm,
PoolAssets, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, ToEthereumXcmRouter,
ToWestendXcmRouter, TransactionByteFee, TrustBackedAssetsInstance, WeightToFee, XcmpQueue,
PoolAssets, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, ToWestendXcmRouter,
TransactionByteFee, TrustBackedAssetsInstance, WeightToFee, XcmpQueue,
};
use assets_common::{
local_and_foreign_assets::MatchesLocalAndForeignAssetsMultiLocation,
Expand Down Expand Up @@ -53,9 +53,10 @@ use xcm_builder::{
GlobalConsensusParachainConvertsFor, HashedDescription, IsConcrete, LocalMint,
NetworkExportTableItem, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus,
TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin,
WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount,
SignedToAccountId32, SovereignPaidRemoteExporter, SovereignSignedViaLocation, StartsWith,
StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
XcmFeeToAccount,
};
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

Expand Down Expand Up @@ -271,12 +272,10 @@ impl Contains<RuntimeCall> for SafeCallFilter {
RuntimeCall::System(frame_system::Call::set_storage { items })
if items.iter().all(|(k, _)| {
k.eq(&bridging::XcmBridgeHubRouterByteFee::key()) |
k.eq(&bridging::XcmBridgeHubRouterBaseFee::key()) |
k.eq(&bridging::to_ethereum::BridgeHubEthereumBaseFee::key())
k.eq(&bridging::XcmBridgeHubRouterBaseFee::key()) |
k.eq(&bridging::to_ethereum::BridgeHubEthereumBaseFee::key())
}) =>
{
return true
},
return true,
_ => (),
};

Expand Down Expand Up @@ -468,8 +467,6 @@ impl Contains<RuntimeCall> for SafeCallFilter {
pallet_uniques::Call::buy_item { .. }
) | RuntimeCall::ToWestendXcmRouter(
pallet_xcm_bridge_hub_router::Call::report_bridge_status { .. }
) | RuntimeCall::ToEthereumXcmRouter(
pallet_xcm_bridge_hub_router::Call::report_bridge_status { .. }
)
)
}
Expand Down Expand Up @@ -635,7 +632,7 @@ pub type XcmRouter = WithUniqueTopic<(
ToWestendXcmRouter,
// Router which wraps and sends xcm to BridgeHub to be delivered to the Ethereum
// GlobalConsensus
ToEthereumXcmRouter,
SovereignPaidRemoteExporter<bridging::EthereumNetworkExportTable, XcmpQueue, UniversalLocation>,
)>;

impl pallet_xcm::Config for Runtime {
Expand Down Expand Up @@ -768,12 +765,18 @@ pub mod bridging {
pub BridgeTable: sp_std::vec::Vec<NetworkExportTableItem> =
sp_std::vec::Vec::new().into_iter()
.chain(to_westend::BridgeTable::get())
.collect();

pub EthereumBridgeTable: sp_std::vec::Vec<NetworkExportTableItem> =
sp_std::vec::Vec::new().into_iter()
.chain(to_ethereum::BridgeTable::get())
.collect();
}

pub type NetworkExportTable = xcm_builder::NetworkExportTable<BridgeTable>;

pub type EthereumNetworkExportTable = xcm_builder::NetworkExportTable<EthereumBridgeTable>;

pub mod to_westend {
use super::*;

Expand Down Expand Up @@ -902,17 +905,6 @@ pub mod bridging {
UniversalAliases::get().contains(alias)
}
}

impl Contains<RuntimeCall> for ToEthereumXcmRouter {
fn contains(call: &RuntimeCall) -> bool {
matches!(
call,
RuntimeCall::ToEthereumXcmRouter(
pallet_xcm_bridge_hub_router::Call::report_bridge_status { .. }
)
)
}
}
}

/// Benchmarks helper for bridging configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl xcm_executor::Config for XcmConfig {
MaxInstructions,
>;
type Trader =
UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToStakingPot<Runtime>>;
UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToStakingPot<Runtime>>;
type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm;
type AssetLocker = ();
Expand Down Expand Up @@ -336,7 +336,7 @@ impl xcm_executor::Config for XcmConfig {
}

pub type PriceForParentDelivery =
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;

/// Converts a local signed origin into an XCM multilocation.
/// Forms the basis for local origins sending/executing XCMs.
Expand Down Expand Up @@ -402,19 +402,19 @@ pub struct XcmExportFeeToRelayerRewardAccounts<
>(PhantomData<(AssetTransactor, DestNetwork, DestParaId, DestBridgedChainId, BridgeLaneId)>);

impl<
AssetTransactor: TransactAsset,
DestNetwork: Get<NetworkId>,
DestParaId: Get<cumulus_primitives_core::ParaId>,
DestBridgedChainId: Get<ChainId>,
BridgeLaneId: Get<LaneId>,
> HandleFee
for XcmExportFeeToRelayerRewardAccounts<
AssetTransactor,
DestNetwork,
DestParaId,
DestBridgedChainId,
BridgeLaneId,
>
AssetTransactor: TransactAsset,
DestNetwork: Get<NetworkId>,
DestParaId: Get<cumulus_primitives_core::ParaId>,
DestBridgedChainId: Get<ChainId>,
BridgeLaneId: Get<LaneId>,
> HandleFee
for XcmExportFeeToRelayerRewardAccounts<
vgeddes marked this conversation as resolved.
Show resolved Hide resolved
AssetTransactor,
DestNetwork,
DestParaId,
DestBridgedChainId,
BridgeLaneId,
>
{
fn handle_fee(
fee: MultiAssets,
Expand Down Expand Up @@ -487,7 +487,7 @@ pub struct XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, HandleFee>(
PhantomData<(WaivedLocations, HandleFee)>,
);
impl<WaivedLocations: Contains<MultiLocation>, FeeHandler: HandleFee> FeeManager
for XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, FeeHandler>
for XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, FeeHandler>
Copy link

Choose a reason for hiding this comment

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

ditto, is problematic changing whitespace for code we do not own.

Copy link
Author

@yrong yrong Dec 19, 2023

Choose a reason for hiding this comment

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

{
fn is_waived(origin: Option<&MultiLocation>, fee_reason: FeeReason) -> bool {
let Some(loc) = origin else { return false };
Expand Down
Loading