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

Commit

Permalink
Merge to upstream updates (#57)
Browse files Browse the repository at this point in the history
* updates snowbridge dependencies to git repos

* use snowbridge v0.9.0

* Rename control to system

* Remove redundant address (#49)

* Fix compile error

* Load PricingParameters from control

* Load InboundDeliveryCost from EthereumInboundQueue

* Allow utility calls

* Fix integration tests

* Remove createAssetExecutionFee

* Fix breaking test

* fix benchmark weights

---------

Co-authored-by: Vincent Geddes <[email protected]>

* benchmark fixes (#55)

Co-authored-by: claravanstaden <Cats 4 life!>

* Update to EthereumSystem

* fixes related to pr comments

* fix exporter

* adds universal location check

* use ethereum network from snowbridge rococo common crate

* starts with pallet universal alias

* merge damage
Host snowbridge-dev

* use pallet instance in inbound queue origin

* cleanup

* TrustedTeleporters from SnowBridgeMessageQueue

---------

Co-authored-by: claravanstaden <Cats 4 life!>
Co-authored-by: ron <[email protected]>
Co-authored-by: Vincent Geddes <[email protected]>
  • Loading branch information
3 people authored Dec 4, 2023
1 parent d2e8a3f commit 0a842f9
Show file tree
Hide file tree
Showing 23 changed files with 3,684 additions and 2,714 deletions.
6,068 changes: 3,471 additions & 2,597 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ bridge-hub-rococo-runtime = { path = "../../../../../../runtimes/bridge-hubs/bri
bridge-hub-common = { path = "../../../../../../runtimes/bridge-hubs/common", default-features = false }

# Snowbridge
snowbridge-core = { path = "../../../../../../../../../parachain/primitives/core", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../../../../parachain/primitives/router", default-features = false }
snowbridge-control = { path = "../../../../../../../../../parachain/pallets/control", default-features = false }
snowbridge-inbound-queue = { path = "../../../../../../../../../parachain/pallets/inbound-queue", default-features = false }
snowbridge-outbound-queue = { path = "../../../../../../../../../parachain/pallets/outbound-queue", default-features = false }
snowbridge-core = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-router-primitives = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-system = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-inbound-queue = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-outbound-queue = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ decl_test_parachains! {
pallets = {
PolkadotXcm: bridge_hub_rococo_runtime::PolkadotXcm,
Balances: bridge_hub_rococo_runtime::Balances,
EthereumControl: bridge_hub_rococo_runtime::EthereumControl,
EthereumSystem: bridge_hub_rococo_runtime::EthereumSystem,
EthereumInboundQueue: bridge_hub_rococo_runtime::EthereumInboundQueue,
EthereumOutboundQueue: bridge_hub_rococo_runtime::EthereumOutboundQueue,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ penpal-runtime = { path = "../../../../../runtimes/testing/penpal" }
rococo-system-emulated-network ={ path = "../../../networks/rococo-system" }

# Snowbridge
snowbridge-core = { path = "../../../../../../../../parachain/primitives/core", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../../../parachain/primitives/router", default-features = false }
snowbridge-control = { path = "../../../../../../../../parachain/pallets/control", default-features = false }
snowbridge-inbound-queue = { path = "../../../../../../../../parachain/pallets/inbound-queue", default-features = false }
snowbridge-outbound-queue = { path = "../../../../../../../../parachain/pallets/outbound-queue", default-features = false }
snowbridge-core = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-router-primitives = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-system = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-inbound-queue = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-outbound-queue = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-rococo-common = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ use bridge_hub_rococo_emulated_chain::BridgeHubRococoParaPallet as BridgeHubRoco
use codec::{Decode, Encode};
use frame_support::pallet_prelude::TypeInfo;
use hex_literal::hex;
use snowbridge_control;
use snowbridge_core::outbound::OperatingMode;
use snowbridge_rococo_common::EthereumNetwork;
use snowbridge_router_primitives::inbound::{Command, Destination, MessageV1, VersionedMessage};
use snowbridge_system;
use sp_core::H256;

const INITIAL_FUND: u128 = 5_000_000_000 * ROCOCO_ED;
Expand All @@ -30,13 +31,14 @@ const TREASURY_ACCOUNT: [u8; 32] =
hex!("6d6f646c70792f74727372790000000000000000000000000000000000000000");
const WETH: [u8; 20] = hex!("87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d");
const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EBD0D8D2333700e");
const XCM_FEE: u128 = 4_000_000_000;

#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub enum ControlCall {
#[codec(index = 2)]
CreateAgent,
#[codec(index = 3)]
CreateChannel { mode: OperatingMode, outbound_fee: u128 },
CreateAgent,
#[codec(index = 4)]
CreateChannel { mode: OperatingMode },
}

#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -98,7 +100,7 @@ fn create_agent() {
assert_expected_events!(
BridgeHubRococo,
vec![
RuntimeEvent::EthereumControl(snowbridge_control::Event::CreateAgent {
RuntimeEvent::EthereumSystem(snowbridge_system::Event::CreateAgent {
..
}) => {},
]
Expand Down Expand Up @@ -133,10 +135,8 @@ fn create_channel() {
},
]));

let create_channel_call = SnowbridgeControl::Control(ControlCall::CreateChannel {
mode: OperatingMode::Normal,
outbound_fee: 1,
});
let create_channel_call =
SnowbridgeControl::Control(ControlCall::CreateChannel { mode: OperatingMode::Normal });

let create_channel_xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
Expand Down Expand Up @@ -179,7 +179,7 @@ fn create_channel() {
assert_expected_events!(
BridgeHubRococo,
vec![
RuntimeEvent::EthereumControl(snowbridge_control::Event::CreateChannel {
RuntimeEvent::EthereumSystem(snowbridge_system::Event::CreateChannel {
..
}) => {},
]
Expand All @@ -205,7 +205,7 @@ fn register_token() {
<BridgeHubRococo as BridgeHubRococoPallet>::EthereumInboundQueue;
let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::RegisterToken { token: WETH.into() },
command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE },
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap();
Expand Down Expand Up @@ -244,8 +244,7 @@ fn send_token_to_penpal() {
]);

let weth_asset_location: MultiLocation =
(Parent, Parent, Ethereum { chain_id: 15 }, AccountKey20 { network: None, key: WETH })
.into();
(Parent, Parent, EthereumNetwork::get(), AccountKey20 { network: None, key: WETH }).into();
let weth_asset_id = weth_asset_location.into();

let origin_location =
Expand Down Expand Up @@ -294,8 +293,10 @@ fn send_token_to_penpal() {
destination: Destination::ForeignAccountId32 {
para_id: 2000,
id: PenpalAReceiver::get().into(),
fee: XCM_FEE,
},
amount: 1_000_000_000,
fee: XCM_FEE,
},
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
Expand Down Expand Up @@ -354,7 +355,7 @@ fn send_token() {
<BridgeHubRococo as BridgeHubRococoPallet>::EthereumInboundQueue;
let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::RegisterToken { token: WETH.into() },
command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE },
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap();
Expand All @@ -364,6 +365,7 @@ fn send_token() {
token: WETH.into(),
destination: Destination::AccountId32 { id: AssetHubRococoReceiver::get().into() },
amount: 1_000_000_000,
fee: XCM_FEE,
},
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
Expand Down Expand Up @@ -409,7 +411,7 @@ fn reserve_transfer_token() {
<BridgeHubRococo as BridgeHubRococoPallet>::EthereumInboundQueue;
let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::RegisterToken { token: WETH.into() },
command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE },
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, ASSETHUB_PARA_ID.into()).unwrap();
Expand All @@ -419,6 +421,7 @@ fn reserve_transfer_token() {
token: WETH.into(),
destination: Destination::AccountId32 { id: AssetHubRococoReceiver::get().into() },
amount: WETH_AMOUNT,
fee: XCM_FEE,
},
});
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_, message).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ pallet-collator-selection = { path = "../../../../pallets/collator-selection", d
parachain-info = { package = "staging-parachain-info", path = "../../../pallets/parachain-info", default-features = false }
parachains-common = { path = "../../../common", default-features = false }
assets-common = { path = "../common", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../parachain/primitives/router", default-features = false }

snowbridge-router-primitives = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
snowbridge-rococo-common = { git = "https://github.com/Snowfork/snowbridge.git", tag = "v0.9.0", default-features = false }
# Bridges
pallet-xcm-bridge-hub-router = { path = "../../../../../bridges/modules/xcm-bridge-hub-router", default-features = false }
bp-asset-hub-rococo = { path = "../../../../../bridges/primitives/chain-asset-hub-rococo", default-features = false }
Expand Down Expand Up @@ -230,6 +230,7 @@ std = [
"rococo-runtime-constants/std",
"scale-info/std",
"snowbridge-router-primitives/std",
"snowbridge-rococo-common/std",
"sp-api/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
Expand Down
19 changes: 17 additions & 2 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,12 +887,12 @@ impl pallet_xcm_bridge_hub_router::Config<ToWestendXcmRouterInstance> for Runtim

/// XCM router instance to BridgeHub with bridging capabilities for `Ethereum` global
/// consensus with dynamic fees and back-pressure.
pub type ToEthereumXcmRouterInstance = pallet_assets::Instance4;
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 = xcm_config::bridging::to_ethereum::EthereumNetwork;
type BridgedNetworkId = snowbridge_rococo_common::EthereumNetwork;
type Bridges = xcm_config::bridging::NetworkExportTable;

#[cfg(not(feature = "runtime-benchmarks"))]
Expand Down Expand Up @@ -1030,6 +1030,7 @@ 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, PalletXcmExtrinsiscsBenchmark::<Runtime>]
// NOTE: Make sure you point to the individual modules below.
Expand Down Expand Up @@ -1369,6 +1370,20 @@ 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() -> MultiLocation {
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
xcm_config::bridging::SiblingBridgeHubParaId::get().into()
);
xcm_config::bridging::to_ethereum::EthereumLocation::get()
}
}

use xcm::latest::prelude::*;
use xcm_config::{TokenLocation, MaxAssetsIntoHolding};
use pallet_xcm_benchmarks::asset_instance_from;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ use parachains_common::{
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::xcm_sender::ExponentialPrice;
use rococo_runtime_constants::system_parachain;
use snowbridge_rococo_common::EthereumNetwork;
use snowbridge_router_primitives::inbound::GlobalConsensusEthereumConvertsFor;
use sp_runtime::traits::{AccountIdConversion, ConvertInto};
use sp_std::marker::PhantomData;
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses,
Expand All @@ -59,6 +61,7 @@ use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

#[cfg(feature = "runtime-benchmarks")]
use cumulus_primitives_core::ParaId;
use frame_support::traits::{ContainsPair, Get};

parameter_types! {
pub const TokenLocation: MultiLocation = MultiLocation::parent();
Expand Down Expand Up @@ -543,6 +546,7 @@ pub type WaivedLocations =
/// - Sibling parachains' assets from where they originate (as `ForeignCreators`).
pub type TrustedTeleporters = (
ConcreteAssetFromSystem<TokenLocation>,
ConcreteAssetFromSnowBridgeMessageQueue<TokenLocation>,
IsForeignConcreteAsset<FromSiblingParachain<parachain_info::Pallet<Runtime>>>,
);

Expand Down Expand Up @@ -726,6 +730,18 @@ where
}
}

pub struct ConcreteAssetFromSnowBridgeMessageQueue<AssetLocation>(PhantomData<AssetLocation>);
impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
for ConcreteAssetFromSnowBridgeMessageQueue<AssetLocation>
{
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::contains", "ConcreteAssetFromSystem asset: {:?}, origin: {:?}", asset, origin);
let from_snowbridge = origin
.eq(&bridging::to_ethereum::SiblingBridgeHubWithEthereumInboundQueueInstance::get());
matches!(asset.id, Concrete(id) if id == AssetLocation::get()) && from_snowbridge
}
}

/// All configuration related to bridging
pub mod bridging {
use super::*;
Expand Down Expand Up @@ -848,13 +864,20 @@ pub mod bridging {
use super::*;

parameter_types! {
pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 15 };
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));

/// User fee for ERC20 token transfer back to Ethereum.
/// (initially was calculated by test `OutboundQueue::calculate_fees` - ETH/ROC 1/400 and fee_per_gas 20 GWEI = 2200698000000 + *25%)
/// Needs to be more than fee calculated from DefaultFeeConfig FeeConfigRecord in snowbridge:parachain/pallets/outbound-queue/src/lib.rs
/// Polkadot uses 12 decimals, Kusama and Rococo 10 decimals.
pub const BridgeHubEthereumBaseFeeInROC: u128 = 2_750_872_500_000;
pub SiblingBridgeHubWithEthereumInboundQueueInstance: MultiLocation = MultiLocation::new(
1,
X2(
Parachain(SiblingBridgeHubParaId::get()),
PalletInstance(snowbridge_rococo_common::INBOUND_QUEUE_MESSAGES_PALLET_INDEX)
)
);

/// Set up exporters configuration.
/// `Option<MultiAsset>` represents static "base fee" which is used for total delivery fee calculation.
Expand All @@ -875,13 +898,13 @@ pub mod bridging {
/// Universal aliases
pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter(
sp_std::vec![
(SiblingBridgeHub::get(), GlobalConsensus(EthereumNetwork::get())),
(SiblingBridgeHubWithEthereumInboundQueueInstance::get(), GlobalConsensus(EthereumNetwork::get())),
]
);
}

pub type IsTrustedBridgedReserveLocationForForeignAsset =
matching::IsForeignConcreteAsset<FromNetwork<EthereumNetwork>>;
matching::IsForeignConcreteAsset<FromNetwork<UniversalLocation, EthereumNetwork>>;

impl Contains<(MultiLocation, Junction)> for UniversalAliases {
fn contains(alias: &(MultiLocation, Junction)) -> bool {
Expand Down
23 changes: 16 additions & 7 deletions cumulus/parachains/runtimes/assets/common/src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,30 @@ impl<SelfParaId: Get<ParaId>> ContainsPair<MultiLocation, MultiLocation>
}
}

pub struct FromNetwork<SelfNetworkId>(sp_std::marker::PhantomData<SelfNetworkId>);
impl<SelfNetworkId: Get<NetworkId>> ContainsPair<MultiLocation, MultiLocation>
for FromNetwork<SelfNetworkId>
pub struct FromNetwork<UniversalLocation, ExpectedNetworkId>(
sp_std::marker::PhantomData<(UniversalLocation, ExpectedNetworkId)>,
);
impl<UniversalLocation: Get<InteriorMultiLocation>, ExpectedNetworkId: Get<NetworkId>>
ContainsPair<MultiLocation, MultiLocation> for FromNetwork<UniversalLocation, ExpectedNetworkId>
{
fn contains(&a: &MultiLocation, b: &MultiLocation) -> bool {
// `a` needs to be from `b` at least
if !a.starts_with(b) {
return false
}

match a {
MultiLocation { parents: 2, interior } => {
matches!(interior.first(), Some(GlobalConsensus(network)) if *network == SelfNetworkId::get())
let universal_source = UniversalLocation::get();

return match ensure_is_remote(universal_source, a) {
Ok((network_id, _)) => network_id == ExpectedNetworkId::get(),
Err(e) => {
log::trace!(
target: "xcm::contains",
"FromNetwork origin: {:?} is not remote to the universal_source: {:?} {:?}",
a, universal_source, e
);
false
},
_ => false,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,8 @@ impl pallet_message_queue::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = weights::pallet_message_queue::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor<
cumulus_primitives_core::AggregateMessageOrigin,
>;
type MessageProcessor =
pallet_message_queue::mock_helpers::NoopMessageProcessor<AggregateMessageOrigin>;
#[cfg(not(feature = "runtime-benchmarks"))]
type MessageProcessor = xcm_builder::ProcessXcmMessage<
AggregateMessageOrigin,
Expand Down
Loading

0 comments on commit 0a842f9

Please sign in to comment.