[BridgeHub] Initial commit for XCM messaging support

This commit is contained in:
Branislav Kontur
2022-09-28 13:40:33 +02:00
parent c0c1c1e2a4
commit e2731be509
6 changed files with 382 additions and 7 deletions
Generated
+26 -3
View File
@@ -713,6 +713,25 @@ dependencies = [
"thiserror",
]
[[package]]
name = "bp-bridge-hub-rococo"
version = "0.1.0"
dependencies = [
"bp-polkadot-core",
"bp-runtime",
"frame-support",
"sp-api",
]
[[package]]
name = "bp-bridge-hub-wococo"
version = "0.1.0"
dependencies = [
"bp-bridge-hub-rococo",
"bp-runtime",
"sp-api",
]
[[package]]
name = "bp-header-chain"
version = "0.1.0"
@@ -992,9 +1011,13 @@ dependencies = [
name = "bridge-hub-rococo-runtime"
version = "0.1.0"
dependencies = [
"bp-polkadot-core 0.1.0",
"bp-rococo 0.1.0",
"bp-wococo 0.1.0",
"bp-bridge-hub-rococo",
"bp-bridge-hub-wococo",
"bp-messages",
"bp-polkadot-core",
"bp-rococo",
"bp-runtime",
"bp-wococo",
"cumulus-pallet-aura-ext",
"cumulus-pallet-dmp-queue",
"cumulus-pallet-parachain-system",
+2 -2
View File
@@ -7,8 +7,8 @@ members = [
"bridges/modules/shift-session-manager",
"bridges/primitives/polkadot-core",
"bridges/primitives/runtime",
"bridges/primitives/chain-rococo",
"bridges/primitives/chain-wococo",
"bridges/primitives/chain-bridge-hub-rococo",
"bridges/primitives/chain-bridge-hub-wococo",
"client/cli",
"client/consensus/aura",
"client/consensus/common",
@@ -68,6 +68,9 @@ parachain-info = { path = "../../../../parachains/pallets/parachain-info", defau
parachains-common = { path = "../../../../parachains/common", default-features = false }
# Bridges
bp-bridge-hub-rococo = { path = "../../../../bridges/primitives/chain-bridge-hub-rococo", default-features = false }
bp-bridge-hub-wococo = { path = "../../../../bridges/primitives/chain-bridge-hub-wococo", default-features = false }
bp-messages = { path = "../../../../bridges/primitives/messages", default-features = false }
bp-polkadot-core = { path = "../../../../bridges/primitives/polkadot-core", default-features = false }
bp-runtime = { path = "../../../../bridges/primitives/runtime", default-features = false }
bp-rococo = { path = "../../../../bridges/primitives/chain-rococo", default-features = false }
@@ -83,7 +86,10 @@ default = [
"std",
]
std = [
"bp-bridge-hub-rococo/std",
"bp-bridge-hub-wococo/std",
"bp-polkadot-core/std",
"bp-messages/std",
"bp-runtime/std",
"bp-rococo/std",
"bp-wococo/std",
@@ -0,0 +1,263 @@
// Copyright 2022 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use bp_messages::{
source_chain::{LaneMessageVerifier, TargetHeaderChain},
target_chain::{DispatchMessage, MessageDispatch, ProvedMessages, SourceHeaderChain},
InboundLaneData, LaneId, Message, OutboundLaneData,
};
use bp_polkadot_core::Balance;
use bp_runtime::{messages::MessageDispatchResult, AccountIdOf, BalanceOf, Chain};
use codec::Decode;
use frame_support::{dispatch::Weight, parameter_types, RuntimeDebug};
parameter_types! {
// TODO:check-parameter
pub const BridgeHubRococoMaxMessagesToPruneAtOnce: bp_messages::MessageNonce = 8;
pub const BridgeHubWococoMaxMessagesToPruneAtOnce: bp_messages::MessageNonce = 8;
// TODO:check-parameter
pub const BridgeHubRococoMaxUnrewardedRelayerEntriesAtInboundLane: bp_messages::MessageNonce =
bp_bridge_hub_rococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
pub const BridgeHubWococoMaxUnrewardedRelayerEntriesAtInboundLane: bp_messages::MessageNonce =
bp_bridge_hub_wococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
// TODO:check-parameter
pub const BridgeHubRococoMaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
bp_bridge_hub_rococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
pub const BridgeHubWococoMaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
bp_bridge_hub_wococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
pub const BridgeHubRococoChainId: bp_runtime::ChainId = bp_runtime::BRIDGE_HUB_ROCOCO_CHAIN_ID;
pub const BridgeHubWococoChainId: bp_runtime::ChainId = bp_runtime::BRIDGE_HUB_WOCOCO_CHAIN_ID;
}
// TODO:check-parameter - when integration XCMv3 change this to struct
pub type PlainXcmPayload = sp_std::prelude::Vec<u8>;
// TODO:check-parameter - when integration XCMv3 change this to struct
pub type FromBridgeHubRococoMessagePayload = PlainXcmPayload;
pub type FromBridgeHubWococoMessagePayload = PlainXcmPayload;
pub type ToBridgeHubRococoMessagePayload = PlainXcmPayload;
pub type ToBridgeHubWococoMessagePayload = PlainXcmPayload;
// TODO:check-parameter - when integrating XCMv3 change this to FromBridgedChainMessagePayload
pub struct FromBridgeHubRococoMessageDispatch<SourceBridgeHubChain, TargetBridgeHubChain> {
_marker: sp_std::marker::PhantomData<(SourceBridgeHubChain, TargetBridgeHubChain)>,
}
pub struct FromBridgeHubWococoMessageDispatch<SourceBridgeHubChain, TargetBridgeHubChain> {
_marker: sp_std::marker::PhantomData<(SourceBridgeHubChain, TargetBridgeHubChain)>,
}
impl<SourceBridgeHubChain: Chain, TargetBridgeHubChain: Chain>
MessageDispatch<AccountIdOf<SourceBridgeHubChain>, BalanceOf<TargetBridgeHubChain>>
for FromBridgeHubRococoMessageDispatch<SourceBridgeHubChain, TargetBridgeHubChain>
{
type DispatchPayload = FromBridgeHubRococoMessagePayload;
fn dispatch_weight(
message: &mut DispatchMessage<Self::DispatchPayload, BalanceOf<TargetBridgeHubChain>>,
) -> Weight {
log::error!("[FromBridgeHubRococoMessageDispatch] TODO: change here to XCMv3 dispatch_weight with XcmExecutor");
0
}
fn dispatch(
relayer_account: &AccountIdOf<SourceBridgeHubChain>,
message: DispatchMessage<Self::DispatchPayload, BalanceOf<TargetBridgeHubChain>>,
) -> MessageDispatchResult {
log::error!("[FromBridgeHubRococoMessageDispatch] TODO: change here to XCMv3 dispatch with XcmExecutor");
todo!("TODO: implement XCMv3 dispatch")
}
}
impl<SourceBridgeHubChain: Chain, TargetBridgeHubChain: Chain>
MessageDispatch<AccountIdOf<SourceBridgeHubChain>, BalanceOf<TargetBridgeHubChain>>
for FromBridgeHubWococoMessageDispatch<SourceBridgeHubChain, TargetBridgeHubChain>
{
type DispatchPayload = FromBridgeHubWococoMessagePayload;
fn dispatch_weight(
message: &mut DispatchMessage<Self::DispatchPayload, BalanceOf<TargetBridgeHubChain>>,
) -> Weight {
log::error!("[FromBridgeHubWococoMessageDispatch] TODO: change here to XCMv3 dispatch_weight with XcmExecutor");
0
}
fn dispatch(
relayer_account: &AccountIdOf<SourceBridgeHubChain>,
message: DispatchMessage<Self::DispatchPayload, BalanceOf<TargetBridgeHubChain>>,
) -> MessageDispatchResult {
log::error!("[FromBridgeHubWococoMessageDispatch] TODO: change here to XCMv3 dispatch with XcmExecutor");
todo!("TODO: implement XCMv3 dispatch")
}
}
pub struct ToBridgeHubRococoMessageVerifier<Origin, Sender> {
_marker: sp_std::marker::PhantomData<(Origin, Sender)>,
}
pub struct ToBridgeHubWococoMessageVerifier<Origin, Sender> {
_marker: sp_std::marker::PhantomData<(Origin, Sender)>,
}
impl<Origin: Clone, Sender: Chain>
LaneMessageVerifier<
Origin,
AccountIdOf<Sender>,
ToBridgeHubRococoMessagePayload,
BalanceOf<Sender>,
> for ToBridgeHubRococoMessageVerifier<Origin, Sender>
{
type Error = &'static str;
fn verify_message(
submitter: &Origin,
delivery_and_dispatch_fee: &BalanceOf<Sender>,
lane: &LaneId,
outbound_data: &OutboundLaneData,
payload: &ToBridgeHubRococoMessagePayload,
) -> Result<(), Self::Error> {
todo!("TODO: ToBridgeHubRococoMessageVerifier - fix verify_message - at the begining to allow all")
}
}
impl<Origin: Clone, Sender: Chain>
LaneMessageVerifier<
Origin,
AccountIdOf<Sender>,
ToBridgeHubWococoMessagePayload,
BalanceOf<Sender>,
> for ToBridgeHubWococoMessageVerifier<Origin, Sender>
{
type Error = &'static str;
fn verify_message(
submitter: &Origin,
delivery_and_dispatch_fee: &BalanceOf<Sender>,
lane: &LaneId,
outbound_data: &OutboundLaneData,
payload: &ToBridgeHubWococoMessagePayload,
) -> Result<(), Self::Error> {
todo!("TODO: ToBridgeHubWococoMessageVerifier - fix verify_message - at the begining to allow all")
}
}
/// BridgeHubRococo chain from message lane point of view.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct BridgeHubRococoMessagingSupport;
/// BridgeHubWococo chain from message lane point of view.
#[derive(RuntimeDebug, Clone, Copy)]
pub struct BridgeHubWococoMessagingSupport;
impl SourceHeaderChain<crate::Balance /* bp_bridge_hub_rococo::Balance */>
for BridgeHubRococoMessagingSupport
{
type Error = &'static str;
type MessagesProof = ();
fn verify_messages_proof(
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message<crate::Balance>>, Self::Error> {
// TODO: need to add, bridges-runtime-common and refactor out of bin
// messages::target::verify_messages_proof_from_parachain::<
// WithRialtoParachainMessageBridge,
// bp_bridge_hub_rococo::Header,
// crate::Runtime,
// crate::WithRialtoParachainsInstance,
// >(ParaId(bp_rialto_parachain::RIALTO_PARACHAIN_ID), proof, messages_count)
todo!("TODO: fix and implement SourceHeaderChain::verify_messages_proof")
}
}
impl
TargetHeaderChain<
ToBridgeHubRococoMessagePayload,
crate::AccountId, /* bp_bridge_hub_wococo::AccountId */
> for BridgeHubRococoMessagingSupport
{
type Error = &'static str;
type MessagesDeliveryProof = ();
fn verify_message(payload: &ToBridgeHubRococoMessagePayload) -> Result<(), Self::Error> {
// messages::source::verify_chain_message::<WithRialtoParachainMessageBridge>(payload)
todo!("TODO: fix implementation: TargetHeaderChain::verify_message")
}
fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<
(LaneId, InboundLaneData<crate::AccountId /* bp_bridge_hub_wococo::AccountId */>),
Self::Error,
> {
// messages::source::verify_messages_delivery_proof_from_parachain::<
// WithRialtoParachainMessageBridge,
// bp_rialto_parachain::Header,
// Runtime,
// crate::WithRialtoParachainsInstance,
// >(ParaId(bp_rialto_parachain::RIALTO_PARACHAIN_ID), proof)
todo!("TODO: fix implementation: TargetHeaderChain::verify_messages_delivery_proof")
}
}
impl SourceHeaderChain<crate::Balance /* bp_bridge_hub_wococo::Balance */>
for BridgeHubWococoMessagingSupport
{
type Error = &'static str;
type MessagesProof = ();
fn verify_messages_proof(
proof: Self::MessagesProof,
messages_count: u32,
) -> Result<ProvedMessages<Message<crate::Balance>>, Self::Error> {
// TODO: need to add, bridges-runtime-common and refactor out of bin
// messages::target::verify_messages_proof_from_parachain::<
// WithMIllauParachainMessageBridge,
// bp_bridge_hub_wococo::Header,
// crate::Runtime,
// crate::WithRialtoParachainsInstance,
// >(ParaId(bp_rialto_parachain::RIALTO_PARACHAIN_ID), proof, messages_count)
todo!("TODO: fix and implement SourceHeaderChain::verify_messages_proof")
}
}
impl
TargetHeaderChain<
ToBridgeHubWococoMessagePayload,
crate::AccountId, /* bp_bridge_hub_rococo::AccountId */
> for BridgeHubWococoMessagingSupport
{
type Error = &'static str;
type MessagesDeliveryProof = ();
fn verify_message(payload: &ToBridgeHubWococoMessagePayload) -> Result<(), Self::Error> {
// messages::source::verify_chain_message::<WithRialtoParachainMessageBridge>(payload)
todo!("TODO: fix implementation: TargetHeaderChain::verify_message")
}
fn verify_messages_delivery_proof(
proof: Self::MessagesDeliveryProof,
) -> Result<
(LaneId, InboundLaneData<crate::AccountId /* bp_bridge_hub_rococo::AccountId */>),
Self::Error,
> {
// messages::source::verify_messages_delivery_proof_from_parachain::<
// WithRialtoParachainMessageBridge,
// bp_rialto_parachain::Header,
// Runtime,
// crate::WithRialtoParachainsInstance,
// >(ParaId(bp_rialto_parachain::RIALTO_PARACHAIN_ID), proof)
todo!("TODO: fix implementation: TargetHeaderChain::verify_messages_delivery_proof")
}
}
@@ -1,4 +1,4 @@
// Copyright 2020-2021 Parity Technologies (UK) Ltd.
// Copyright 2022 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
@@ -24,6 +24,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
mod weights;
pub mod xcm_config;
mod bridge_config;
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use smallvec::smallvec;
@@ -491,7 +492,7 @@ parameter_types! {
pub const HeadersToKeep: u32 = 1024;
}
/// Add granda bridge pallet to track Wococo relay chain
/// Add granda bridge pallet to track Wococo relay chain on Rococo BridgeHub
pub type BridgeGrandpaWococoInstance = pallet_bridge_grandpa::Instance1;
impl pallet_bridge_grandpa::Config<BridgeGrandpaWococoInstance> for Runtime {
type BridgedChain = bp_wococo::Wococo;
@@ -543,6 +544,70 @@ impl pallet_bridge_parachains::Config<BridgeParachainRococoInstance> for Runtime
type HeadsToKeep = ParachainHeadsToKeep;
}
/// Add XCM messages support for BrigdeHubRococo to support Wococo->Rococo XCM messages
pub type WithBridgeHubWococoMessagesInstance = pallet_bridge_messages::Instance1;
impl pallet_bridge_messages::Config<WithBridgeHubWococoMessagesInstance> for Runtime {
type Event = Event;
// TODO:check-parameter - copy of MillauWeigth + refactor
type WeightInfo = ();
type BridgedChainId = bridge_config::BridgeHubWococoChainId;
// TODO:check-parameter - do we need any conversion rate or what ever?
type Parameter = ();
type MaxMessagesToPruneAtOnce = bridge_config::BridgeHubWococoMaxMessagesToPruneAtOnce;
type MaxUnrewardedRelayerEntriesAtInboundLane = bridge_config::BridgeHubWococoMaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = bridge_config::BridgeHubWococoMaxUnconfirmedMessagesAtInboundLane;
type MaximalOutboundPayloadSize = ();
type OutboundPayload = bridge_config::ToBridgeHubWococoMessagePayload;
type OutboundMessageFee = crate::Balance; /* bp_bridge_hub_rococo::Balance */
type InboundPayload = bridge_config::FromBridgeHubWococoMessagePayload;
type InboundMessageFee = crate::Balance; /* bp_bridge_hub_wococo::Balance */
type InboundRelayer = crate::AccountId; /* bp_bridge_hub_wococo::AccountId */
type TargetHeaderChain = bridge_config::BridgeHubWococoMessagingSupport;
type LaneMessageVerifier = bridge_config::ToBridgeHubWococoMessageVerifier<Self::Origin, bp_bridge_hub_rococo::BridgeHubRococo>;
// TODO:check-parameter - add because of rewards?
type MessageDeliveryAndDispatchPayment = ();
type OnMessageAccepted = ();
type OnDeliveryConfirmed = ();
type SourceHeaderChain = bridge_config::BridgeHubWococoMessagingSupport;
type MessageDispatch = bridge_config::FromBridgeHubWococoMessageDispatch<bp_bridge_hub_wococo::BridgeHubWococo, bp_bridge_hub_rococo::BridgeHubRococo>;
}
/// Add XCM messages support for BrigdeHubWococo to support Rococo->Wococo XCM messages
pub type WithBridgeHubRococoMessagesInstance = pallet_bridge_messages::Instance2;
impl pallet_bridge_messages::Config<WithBridgeHubRococoMessagesInstance> for Runtime {
type Event = Event;
// TODO:check-parameter - copy of MillauWeigth + refactor
type WeightInfo = ();
type BridgedChainId = bridge_config::BridgeHubRococoChainId;
// TODO:check-parameter - do we need any conversion rate or what ever?
type Parameter = ();
type MaxMessagesToPruneAtOnce = bridge_config::BridgeHubRococoMaxMessagesToPruneAtOnce;
type MaxUnrewardedRelayerEntriesAtInboundLane = bridge_config::BridgeHubRococoMaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = bridge_config::BridgeHubRococoMaxUnconfirmedMessagesAtInboundLane;
type MaximalOutboundPayloadSize = ();
type OutboundPayload = bridge_config::ToBridgeHubRococoMessagePayload;
type OutboundMessageFee = crate::Balance; /* bp_bridge_hub_wococo::Balance */
type InboundPayload = bridge_config::FromBridgeHubRococoMessagePayload;
type InboundMessageFee = crate::Balance; /* bp_bridge_hub_rococo::Balance */
type InboundRelayer = crate::AccountId; /* bp_bridge_hub_rococo::AccountId */
type TargetHeaderChain = bridge_config::BridgeHubRococoMessagingSupport;
type LaneMessageVerifier = bridge_config::ToBridgeHubRococoMessageVerifier<Self::Origin, bp_bridge_hub_wococo::BridgeHubWococo>;
// TODO:check-parameter - add because of rewards?
type MessageDeliveryAndDispatchPayment = ();
type OnMessageAccepted = ();
type OnDeliveryConfirmed = ();
type SourceHeaderChain = bridge_config::BridgeHubRococoMessagingSupport;
type MessageDispatch = bridge_config::FromBridgeHubRococoMessageDispatch<bp_bridge_hub_rococo::BridgeHubRococo, bp_bridge_hub_wococo::BridgeHubWococo>;
}
/// Add shift session manager
impl pallet_shift_session_manager::Config for Runtime {}
@@ -584,10 +649,12 @@ construct_runtime!(
// Wococo bridge modules
BridgeWococoGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Storage, Config<T>} = 41,
BridgeWococoParachain: pallet_bridge_parachains::<Instance1>::{Pallet, Call, Storage, Event<T>} = 42,
BridgeWococoMessages: pallet_bridge_messages::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>} = 46,
// Rococo bridge modules
BridgeRococoGrandpa: pallet_bridge_grandpa::<Instance2>::{Pallet, Call, Storage, Config<T>} = 43,
BridgeRococoParachain: pallet_bridge_parachains::<Instance2>::{Pallet, Call, Storage, Event<T>} = 44,
BridgeRococoMessages: pallet_bridge_messages::<Instance2>::{Pallet, Call, Storage, Event<T>, Config<T>} = 45,
// Sudo
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Event<T>, Storage} = 100,
@@ -1,3 +1,19 @@
// Copyright 2022 Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use super::{
AccountId, Balance, Balances, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime,
XcmpQueue,