diff --git a/Cargo.lock b/Cargo.lock index c0e22540ec..0a851684a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index 4ba7acb605..7e3eb2d88c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index db02374741..1c7ab7a254 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -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", diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_config.rs new file mode 100644 index 0000000000..3a62bd829d --- /dev/null +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_config.rs @@ -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 . + +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; + +// 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 { + _marker: sp_std::marker::PhantomData<(SourceBridgeHubChain, TargetBridgeHubChain)>, +} +pub struct FromBridgeHubWococoMessageDispatch { + _marker: sp_std::marker::PhantomData<(SourceBridgeHubChain, TargetBridgeHubChain)>, +} + +impl + MessageDispatch, BalanceOf> + for FromBridgeHubRococoMessageDispatch +{ + type DispatchPayload = FromBridgeHubRococoMessagePayload; + + fn dispatch_weight( + message: &mut DispatchMessage>, + ) -> Weight { + log::error!("[FromBridgeHubRococoMessageDispatch] TODO: change here to XCMv3 dispatch_weight with XcmExecutor"); + 0 + } + + fn dispatch( + relayer_account: &AccountIdOf, + message: DispatchMessage>, + ) -> MessageDispatchResult { + log::error!("[FromBridgeHubRococoMessageDispatch] TODO: change here to XCMv3 dispatch with XcmExecutor"); + todo!("TODO: implement XCMv3 dispatch") + } +} + +impl + MessageDispatch, BalanceOf> + for FromBridgeHubWococoMessageDispatch +{ + type DispatchPayload = FromBridgeHubWococoMessagePayload; + + fn dispatch_weight( + message: &mut DispatchMessage>, + ) -> Weight { + log::error!("[FromBridgeHubWococoMessageDispatch] TODO: change here to XCMv3 dispatch_weight with XcmExecutor"); + 0 + } + + fn dispatch( + relayer_account: &AccountIdOf, + message: DispatchMessage>, + ) -> MessageDispatchResult { + log::error!("[FromBridgeHubWococoMessageDispatch] TODO: change here to XCMv3 dispatch with XcmExecutor"); + todo!("TODO: implement XCMv3 dispatch") + } +} + +pub struct ToBridgeHubRococoMessageVerifier { + _marker: sp_std::marker::PhantomData<(Origin, Sender)>, +} +pub struct ToBridgeHubWococoMessageVerifier { + _marker: sp_std::marker::PhantomData<(Origin, Sender)>, +} + +impl + LaneMessageVerifier< + Origin, + AccountIdOf, + ToBridgeHubRococoMessagePayload, + BalanceOf, + > for ToBridgeHubRococoMessageVerifier +{ + type Error = &'static str; + + fn verify_message( + submitter: &Origin, + delivery_and_dispatch_fee: &BalanceOf, + lane: &LaneId, + outbound_data: &OutboundLaneData, + payload: &ToBridgeHubRococoMessagePayload, + ) -> Result<(), Self::Error> { + todo!("TODO: ToBridgeHubRococoMessageVerifier - fix verify_message - at the begining to allow all") + } +} + +impl + LaneMessageVerifier< + Origin, + AccountIdOf, + ToBridgeHubWococoMessagePayload, + BalanceOf, + > for ToBridgeHubWococoMessageVerifier +{ + type Error = &'static str; + + fn verify_message( + submitter: &Origin, + delivery_and_dispatch_fee: &BalanceOf, + 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 + for BridgeHubRococoMessagingSupport +{ + type Error = &'static str; + type MessagesProof = (); + + fn verify_messages_proof( + proof: Self::MessagesProof, + messages_count: u32, + ) -> Result>, 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::(payload) + todo!("TODO: fix implementation: TargetHeaderChain::verify_message") + } + + fn verify_messages_delivery_proof( + proof: Self::MessagesDeliveryProof, + ) -> Result< + (LaneId, InboundLaneData), + 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 + for BridgeHubWococoMessagingSupport +{ + type Error = &'static str; + type MessagesProof = (); + + fn verify_messages_proof( + proof: Self::MessagesProof, + messages_count: u32, + ) -> Result>, 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::(payload) + todo!("TODO: fix implementation: TargetHeaderChain::verify_message") + } + + fn verify_messages_delivery_proof( + proof: Self::MessagesDeliveryProof, + ) -> Result< + (LaneId, InboundLaneData), + 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") + } +} diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index bb5b4f55ae..9f4271d139 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -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 for Runtime { type BridgedChain = bp_wococo::Wococo; @@ -543,6 +544,70 @@ impl pallet_bridge_parachains::Config 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 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; + // TODO:check-parameter - add because of rewards? + type MessageDeliveryAndDispatchPayment = (); + type OnMessageAccepted = (); + type OnDeliveryConfirmed = (); + + type SourceHeaderChain = bridge_config::BridgeHubWococoMessagingSupport; + type MessageDispatch = bridge_config::FromBridgeHubWococoMessageDispatch; +} + +/// Add XCM messages support for BrigdeHubWococo to support Rococo->Wococo XCM messages +pub type WithBridgeHubRococoMessagesInstance = pallet_bridge_messages::Instance2; +impl pallet_bridge_messages::Config 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; + // TODO:check-parameter - add because of rewards? + type MessageDeliveryAndDispatchPayment = (); + type OnMessageAccepted = (); + type OnDeliveryConfirmed = (); + + type SourceHeaderChain = bridge_config::BridgeHubRococoMessagingSupport; + type MessageDispatch = bridge_config::FromBridgeHubRococoMessageDispatch; +} + /// 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::::{Pallet, Call, Storage, Config} = 41, BridgeWococoParachain: pallet_bridge_parachains::::{Pallet, Call, Storage, Event} = 42, + BridgeWococoMessages: pallet_bridge_messages::::{Pallet, Call, Storage, Event, Config} = 46, // Rococo bridge modules BridgeRococoGrandpa: pallet_bridge_grandpa::::{Pallet, Call, Storage, Config} = 43, BridgeRococoParachain: pallet_bridge_parachains::::{Pallet, Call, Storage, Event} = 44, + BridgeRococoMessages: pallet_bridge_messages::::{Pallet, Call, Storage, Event, Config} = 45, // Sudo Sudo: pallet_sudo::{Pallet, Call, Config, Event, Storage} = 100, diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index 543962807d..84a2aeb60d 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -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 . + use super::{ AccountId, Balance, Balances, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, XcmpQueue,