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

Commit

Permalink
add channel-id support
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeddes committed Nov 14, 2023
1 parent 9846b37 commit a7f55a8
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 131 deletions.
4 changes: 3 additions & 1 deletion 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 @@ -13,9 +13,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::*;
use codec::Encode;
use hex_literal::hex;
use integration_tests_common::{AssetHubRococoPallet, BridgeHubRococoPallet};
use snowbridge_control;
use snowbridge_core::outbound::OperatingMode;
use snowbridge_router_primitives::inbound::{Command, Destination, MessageV1, VersionedMessage};
use sp_core::H256;

Expand All @@ -31,10 +33,12 @@ const ETHEREUM_DESTINATION_ADDRESS: [u8; 20] = hex!("44a57ee2f2FCcb85FDa2B0B18EB

#[test]
fn create_agent() {
let origin_para: u32 = 1001;

BridgeHubRococo::fund_accounts(vec![(
BridgeHubRococo::sovereign_account_id_of(MultiLocation {
parents: 1,
interior: X1(Parachain(DEST_PARA_ID)),
interior: X1(Parachain(origin_para)),
}),
INITIAL_FUND,
)]);
Expand All @@ -44,11 +48,11 @@ fn create_agent() {

let remote_xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
DescendOrigin(X1(Parachain(DEST_PARA_ID))),
DescendOrigin(X1(Parachain(origin_para))),
Transact {
require_weight_at_most: 3000000000.into(),
origin_kind: OriginKind::Xcm,
call: vec![51, 1].into(),
call: vec![51, 2].into(),
},
]));

Expand Down Expand Up @@ -91,7 +95,9 @@ fn create_agent() {

#[test]
fn create_channel() {
let source_location = MultiLocation { parents: 1, interior: X1(Parachain(DEST_PARA_ID)) };
let origin_para: u32 = 1001;

let source_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para)) };

BridgeHubRococo::fund_accounts(vec![(
BridgeHubRococo::sovereign_account_id_of(source_location),
Expand All @@ -104,21 +110,21 @@ fn create_channel() {

let create_agent_xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
DescendOrigin(X1(Parachain(DEST_PARA_ID))),
DescendOrigin(X1(Parachain(origin_para))),
Transact {
require_weight_at_most: 3000000000.into(),
origin_kind: OriginKind::Xcm,
call: vec![51, 1].into(),
call: vec![51, 2].into(),
},
]));

let create_channel_xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
DescendOrigin(X1(Parachain(DEST_PARA_ID))),
DescendOrigin(X1(Parachain(origin_para))),
Transact {
require_weight_at_most: 3000000000.into(),
origin_kind: OriginKind::Xcm,
call: vec![51, 2].into(),
call: ([51u8, 3u8], OperatingMode::Normal, 1u128).encode().into(),
},
]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use bridge_hub_common::{
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
AggregateMessageOrigin,
};
use cumulus_primitives_core::ParaId;
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
Expand All @@ -62,6 +58,7 @@ use frame_system::{
EnsureRoot,
};
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm_config::{FellowshipLocation, GovernanceLocation, XcmOriginToTransactDispatchOrigin};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use bridge_hub_common::{
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
AggregateMessageOrigin,
};
use cumulus_primitives_core::ParaId;
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
Expand All @@ -62,6 +58,7 @@ use frame_system::{
EnsureRoot,
};
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm_config::{FellowshipLocation, GovernanceLocation, XcmOriginToTransactDispatchOrigin};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use cumulus_primitives_core::ParaId;
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
Expand All @@ -76,17 +76,14 @@ use frame_system::{
};

use pallet_xcm::EnsureXcm;

use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm::VersionedMultiLocation;
use xcm_config::{TreasuryAccount, XcmOriginToTransactDispatchOrigin, XcmRouter};

use bp_runtime::HeaderId;
use bridge_hub_common::{
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
AggregateMessageOrigin, BridgeHubMessageRouter,
};
use bridge_hub_common::BridgeHubMessageRouter;

#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
Expand Down Expand Up @@ -404,7 +401,7 @@ impl pallet_message_queue::Config for Runtime {
type Size = u32;
// The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin:
type QueueChangeHandler = NarrowOriginToSibling<XcmpQueue>;
type QueuePausedQuery = (NarrowOriginToSibling<XcmpQueue>, EthereumOutboundQueue);
type QueuePausedQuery = NarrowOriginToSibling<XcmpQueue>;
type HeapSize = sp_core::ConstU32<{ 64 * 1024 }>;
type MaxStale = sp_core::ConstU32<8>;
type ServiceWeight = MessageQueueServiceWeight;
Expand Down Expand Up @@ -549,7 +546,7 @@ impl snowbridge_inbound_queue::Config for Runtime {
type XcmSender = XcmRouter;
#[cfg(feature = "runtime-benchmarks")]
type XcmSender = DoNothingRouter;
type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo<Runtime>;
type ChannelLookup = EthereumControl;
type GatewayAddress = GatewayAddress;
#[cfg(feature = "runtime-benchmarks")]
type Helper = Runtime;
Expand All @@ -562,6 +559,7 @@ impl snowbridge_inbound_queue::Config for Runtime {
Balance,
>;
type WeightToFee = WeightToFee;
type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo<Runtime>;
}

impl snowbridge_outbound_queue::Config for Runtime {
Expand All @@ -571,7 +569,6 @@ impl snowbridge_outbound_queue::Config for Runtime {
type Decimals = ConstU8<12>;
type MaxMessagePayloadSize = ConstU32<2048>;
type MaxMessagesPerBlock = ConstU32<32>;
type OwnParaId = ParachainInfo;
type GasMeter = snowbridge_core::outbound::ConstantGasMeter;
type Balance = Balance;
type WeightToFee = WeightToFee;
Expand Down Expand Up @@ -646,9 +643,7 @@ impl snowbridge_control::BenchmarkHelper<RuntimeOrigin> for () {

impl snowbridge_control::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OwnParaId = ParachainInfo;
type OutboundQueue = EthereumOutboundQueue;
type MessageHasher = BlakeTwo256;
type SiblingOrigin = EnsureXcm<AllowSiblingsOnly>;
type AgentIdOf = xcm_config::AgentIdOf;
type TreasuryAccount = TreasuryAccount;
Expand Down Expand Up @@ -729,7 +724,7 @@ construct_runtime!(
EthereumInboundQueue: snowbridge_inbound_queue::{Pallet, Call, Storage, Event<T>} = 60,
EthereumOutboundQueue: snowbridge_outbound_queue::{Pallet, Call, Storage, Event<T>} = 61,
EthereumBeaconClient: snowbridge_ethereum_beacon_client::{Pallet, Call, Storage, Event<T>} = 62,
EthereumControl: snowbridge_control::{Pallet, Call, Storage, Event<T>} = 63,
EthereumControl: snowbridge_control::{Pallet, Call, Storage, Config<T>, Event<T>} = 63,

// Message Queue. Registered after EthereumOutboundQueue so that their `on_initialize` handlers
// run in the desired order.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ pub mod bridge_to_rococo_config;
mod weights;
pub mod xcm_config;

use bridge_hub_common::{
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
AggregateMessageOrigin,
};
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_primitives_core::ParaId;

use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
Expand All @@ -52,6 +48,7 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
Expand All @@ -65,6 +62,7 @@ use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot,
};
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm_config::{XcmOriginToTransactDispatchOrigin, XcmRouter};
Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

pub mod message_queue;

pub use message_queue::{AggregateMessageOrigin, BridgeHubMessageRouter, SnowbridgeMessageOrigin};
pub use message_queue::BridgeHubMessageRouter;
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! Runtime configuration for MessageQueue pallet
use codec::{Decode, Encode, MaxEncodedLen};
use cumulus_primitives_core::ParaId;
use cumulus_primitives_core::AggregateMessageOrigin;
use frame_support::{
traits::{ProcessMessage, ProcessMessageError, QueueFootprint, QueuePausedQuery},
traits::{ProcessMessage, ProcessMessageError},
weights::WeightMeter,
};
use pallet_message_queue::OnQueueChanged;
use scale_info::TypeInfo;
use sp_std::{marker::PhantomData, prelude::*};
use xcm::v3::{Junction, MultiLocation};

/// The aggregate origin of an inbound message.
/// This is specialized for BridgeHub, as the snowbridge-outbound-queue pallet is also using
/// the shared MessageQueue pallet.
#[derive(Encode, Decode, Copy, MaxEncodedLen, Clone, Eq, PartialEq, TypeInfo, Debug)]
pub enum AggregateMessageOrigin {
/// The message came from the para-chain itself.
Here,
/// The message came from the relay-chain.
///
/// This is used by the DMP queue.
Parent,
/// The message came from a sibling para-chain.
///
/// This is used by the HRMP queue.
Sibling(ParaId),
Snowbridge(SnowbridgeMessageOrigin),
}

/// The origin of an inbound message for Snowbridge.
#[derive(Encode, Decode, Copy, MaxEncodedLen, Clone, Eq, PartialEq, TypeInfo, Debug)]
pub enum SnowbridgeMessageOrigin {
/// The message came from the para-chain itself.
Here,
/// The message came from a sibling para-chain.
Sibling(ParaId),
}

impl From<AggregateMessageOrigin> for MultiLocation {
fn from(origin: AggregateMessageOrigin) -> Self {
use AggregateMessageOrigin::*;
match origin {
Here => MultiLocation::here(),
Parent => MultiLocation::parent(),
Sibling(id) => MultiLocation::new(1, Junction::Parachain(id.into())),
// NOTE: We don't need this conversion for Snowbridge. However we have to
// implement it anyway as xcm_builder::ProcessXcmMessage requires it.
Snowbridge(_) => MultiLocation::default(),
}
}
}

#[cfg(feature = "runtime-benchmarks")]
impl From<u32> for AggregateMessageOrigin {
fn from(x: u32) -> Self {
match x {
0 => Self::Here,
1 => Self::Parent,
p => Self::Sibling(ParaId::from(p)),
}
}
}
use sp_std::marker::PhantomData;

/// Routes messages to either the XCMP or Snowbridge processor.
pub struct BridgeHubMessageRouter<XcmpProcessor, SnowbridgeProcessor>(
PhantomData<(XcmpProcessor, SnowbridgeProcessor)>,
)
where
XcmpProcessor: ProcessMessage<Origin = AggregateMessageOrigin>,
SnowbridgeProcessor: ProcessMessage<Origin = AggregateMessageOrigin>;
);

impl<XcmpProcessor, SnowbridgeProcessor> ProcessMessage
for BridgeHubMessageRouter<XcmpProcessor, SnowbridgeProcessor>
Expand All @@ -102,37 +43,7 @@ where
match origin {
Here | Parent | Sibling(_) =>
XcmpProcessor::process_message(message, origin, meter, id),
Snowbridge(_) => SnowbridgeProcessor::process_message(message, origin, meter, id),
}
}
}

pub struct NarrowOriginToSibling<Inner>(PhantomData<Inner>);
impl<Inner: QueuePausedQuery<ParaId>> QueuePausedQuery<AggregateMessageOrigin>
for NarrowOriginToSibling<Inner>
{
fn is_paused(origin: &AggregateMessageOrigin) -> bool {
match origin {
AggregateMessageOrigin::Sibling(id) => Inner::is_paused(id),
_ => false,
GeneralKey(_) => SnowbridgeProcessor::process_message(message, origin, meter, id),
}
}
}

impl<Inner: OnQueueChanged<ParaId>> OnQueueChanged<AggregateMessageOrigin>
for NarrowOriginToSibling<Inner>
{
fn on_queue_changed(origin: AggregateMessageOrigin, fp: QueueFootprint) {
if let AggregateMessageOrigin::Sibling(id) = origin {
Inner::on_queue_changed(id, fp)
}
}
}

/// Convert a sibling `ParaId` to an `AggregateMessageOrigin`.
pub struct ParaIdToSibling;
impl sp_runtime::traits::Convert<ParaId, AggregateMessageOrigin> for ParaIdToSibling {
fn convert(para_id: ParaId) -> AggregateMessageOrigin {
AggregateMessageOrigin::Sibling(para_id)
}
}
4 changes: 4 additions & 0 deletions cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ pub mod rococo {
"bridgeWestendMessages": {
"owner": bridges_pallet_owner.clone(),
},
"ethereumControl": {
"paraId": id,
"assetHubParaId": 1000
}
})
}
}
Expand Down
Loading

0 comments on commit a7f55a8

Please sign in to comment.