Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly bridge Rococo<>Bulletin #3085

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! BridgeHubRococo-to-RococoBulletin messages sync entrypoint.

use super::BridgeHubRococoAsBridgeHubPolkadot;
use relay_bridge_hub_rococo_client::BridgeHubRococo;
use relay_polkadot_bulletin_client::PolkadotBulletin as RococoBulletin;
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge},
Expand All @@ -28,7 +28,7 @@ use substrate_relay_helper::{
pub struct BridgeHubRococoToRococoBulletinMessagesCliBridge {}

impl CliBridgeBase for BridgeHubRococoToRococoBulletinMessagesCliBridge {
type Source = BridgeHubRococoAsBridgeHubPolkadot;
type Source = BridgeHubRococo;
type Target = RococoBulletin;
}

Expand All @@ -55,7 +55,7 @@ substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
pub struct BridgeHubRococoMessagesToRococoBulletinMessageLane;

impl SubstrateMessageLane for BridgeHubRococoMessagesToRococoBulletinMessageLane {
type SourceChain = BridgeHubRococoAsBridgeHubPolkadot;
type SourceChain = BridgeHubRococo;
type TargetChain = RococoBulletin;

type LaneId = bp_messages::LegacyLaneId;
Expand All @@ -65,6 +65,6 @@ impl SubstrateMessageLane for BridgeHubRococoMessagesToRococoBulletinMessageLane
type ReceiveMessagesDeliveryProofCallBuilder =
BridgeHubRococoMessagesToRococoBulletinMessageLaneReceiveMessagesDeliveryProofCallBuilder;

type SourceBatchCallBuilder = UtilityPalletBatchCallBuilder<BridgeHubRococoAsBridgeHubPolkadot>;
type SourceBatchCallBuilder = UtilityPalletBatchCallBuilder<BridgeHubRococo>;
type TargetBatchCallBuilder = ();
}
225 changes: 0 additions & 225 deletions substrate-relay/src/bridges/rococo_bulletin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,233 +16,8 @@

//! Declaration of all bridges between Rococo Bulletin Chain and Rococo Bridge Hub.

use bp_messages::MessageNonce;
use bp_runtime::{
AccountIdOf, BalanceOf, BlockNumberOf, ChainId, HashOf, HasherOf, HeaderOf, NonceOf,
SignatureOf,
};
use frame_support::{pallet_prelude::Weight, sp_runtime::StateVersion};
use relay_substrate_client::{
ChainWithRuntimeVersion, Error as SubstrateError, SignParam, SimpleRuntimeVersion,
UnsignedTransaction,
};
use sp_core::storage::StorageKey;
use std::time::Duration;

pub mod bridge_hub_rococo_messages_to_rococo_bulletin;
pub mod rococo_bulletin_headers_to_bridge_hub_rococo;
pub mod rococo_bulletin_messages_to_bridge_hub_rococo;
pub mod rococo_headers_to_rococo_bulletin;
pub mod rococo_parachains_to_rococo_bulletin;

/// Base `Chain` implementation of Rococo, pretending to be Polkadot.
pub struct RococoBaseAsPolkadot;

impl bp_runtime::Chain for RococoBaseAsPolkadot {
const ID: ChainId = relay_rococo_client::Rococo::ID;

type BlockNumber = BlockNumberOf<bp_rococo::Rococo>;
type Hash = HashOf<bp_rococo::Rococo>;
type Hasher = HasherOf<bp_rococo::Rococo>;
type Header = HeaderOf<bp_rococo::Rococo>;

type AccountId = AccountIdOf<bp_rococo::Rococo>;
type Balance = BalanceOf<bp_rococo::Rococo>;
type Nonce = NonceOf<bp_rococo::Rococo>;
type Signature = SignatureOf<bp_rococo::Rococo>;

const STATE_VERSION: StateVersion = StateVersion::V1;

fn max_extrinsic_size() -> u32 {
bp_rococo::Rococo::max_extrinsic_size()
}

fn max_extrinsic_weight() -> Weight {
bp_rococo::Rococo::max_extrinsic_weight()
}
}

impl bp_header_chain::ChainWithGrandpa for RococoBaseAsPolkadot {
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str =
bp_polkadot::Polkadot::WITH_CHAIN_GRANDPA_PALLET_NAME;
const MAX_AUTHORITIES_COUNT: u32 = bp_rococo::Rococo::MAX_AUTHORITIES_COUNT;
const REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY: u32 =
bp_rococo::Rococo::REASONABLE_HEADERS_IN_JUSTIFICATION_ANCESTRY;
const MAX_MANDATORY_HEADER_SIZE: u32 = bp_rococo::Rococo::MAX_MANDATORY_HEADER_SIZE;
const AVERAGE_HEADER_SIZE: u32 = bp_rococo::Rococo::AVERAGE_HEADER_SIZE;
}

/// Relay `Chain` implementation of Rococo, pretending to be Polkadot.
#[derive(Debug, Clone, Copy)]
pub struct RococoAsPolkadot;

impl bp_runtime::UnderlyingChainProvider for RococoAsPolkadot {
type Chain = RococoBaseAsPolkadot;
}

impl relay_substrate_client::Chain for RococoAsPolkadot {
const NAME: &'static str = relay_rococo_client::Rococo::NAME;
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
relay_polkadot_client::Polkadot::BEST_FINALIZED_HEADER_ID_METHOD;
const FREE_HEADERS_INTERVAL_METHOD: &'static str =
relay_polkadot_client::Polkadot::FREE_HEADERS_INTERVAL_METHOD;
const AVERAGE_BLOCK_INTERVAL: Duration = relay_rococo_client::Rococo::AVERAGE_BLOCK_INTERVAL;

type SignedBlock = <relay_rococo_client::Rococo as relay_substrate_client::Chain>::SignedBlock;
type Call = <relay_rococo_client::Rococo as relay_substrate_client::Chain>::Call;
}

impl relay_substrate_client::ChainWithGrandpa for RococoAsPolkadot {
const SYNCED_HEADERS_GRANDPA_INFO_METHOD: &'static str =
relay_polkadot_client::Polkadot::SYNCED_HEADERS_GRANDPA_INFO_METHOD;

type KeyOwnerProof =
<relay_rococo_client::Rococo as relay_substrate_client::ChainWithGrandpa>::KeyOwnerProof;
}

impl relay_substrate_client::ChainWithBalances for RococoAsPolkadot {
fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey {
relay_rococo_client::Rococo::account_info_storage_key(account_id)
}
}

impl relay_substrate_client::RelayChain for RococoAsPolkadot {
const PARAS_PALLET_NAME: &'static str = relay_rococo_client::Rococo::PARAS_PALLET_NAME;
const WITH_CHAIN_BRIDGE_PARACHAINS_PALLET_NAME: &'static str =
relay_rococo_client::Rococo::WITH_CHAIN_BRIDGE_PARACHAINS_PALLET_NAME;
}

impl relay_substrate_client::ChainWithTransactions for RococoAsPolkadot {
type AccountKeyPair = <relay_rococo_client::Rococo as relay_substrate_client::ChainWithTransactions>::AccountKeyPair;
type SignedTransaction = <relay_rococo_client::Rococo as relay_substrate_client::ChainWithTransactions>::SignedTransaction;

fn sign_transaction(
param: SignParam<Self>,
unsigned: UnsignedTransaction<Self>,
) -> Result<Self::SignedTransaction, SubstrateError> {
relay_rococo_client::Rococo::sign_transaction(
SignParam {
spec_version: param.spec_version,
transaction_version: param.transaction_version,
genesis_hash: param.genesis_hash,
signer: param.signer,
},
unsigned.switch_chain(),
)
}
}

impl ChainWithRuntimeVersion for RococoAsPolkadot {
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> = None;
}

/// Base `Chain` implementation of Rococo Bridge Hub, pretending to be a Polkadot Bridge Hub.
pub struct BaseBridgeHubRococoAsBridgeHubPolkadot;

impl bp_runtime::Chain for BaseBridgeHubRococoAsBridgeHubPolkadot {
const ID: ChainId = relay_bridge_hub_rococo_client::BridgeHubRococo::ID;

type BlockNumber = BlockNumberOf<bp_bridge_hub_rococo::BridgeHubRococo>;
type Hash = HashOf<bp_bridge_hub_rococo::BridgeHubRococo>;
type Hasher = HasherOf<bp_bridge_hub_rococo::BridgeHubRococo>;
type Header = HeaderOf<bp_bridge_hub_rococo::BridgeHubRococo>;

type AccountId = AccountIdOf<bp_bridge_hub_rococo::BridgeHubRococo>;
type Balance = BalanceOf<bp_bridge_hub_rococo::BridgeHubRococo>;
type Nonce = NonceOf<bp_bridge_hub_rococo::BridgeHubRococo>;
type Signature = SignatureOf<bp_bridge_hub_rococo::BridgeHubRococo>;

const STATE_VERSION: StateVersion = StateVersion::V1;

fn max_extrinsic_size() -> u32 {
bp_bridge_hub_rococo::BridgeHubRococo::max_extrinsic_size()
}

fn max_extrinsic_weight() -> Weight {
bp_bridge_hub_rococo::BridgeHubRococo::max_extrinsic_weight()
}
}

impl bp_runtime::Parachain for BaseBridgeHubRococoAsBridgeHubPolkadot {
const PARACHAIN_ID: u32 = bp_bridge_hub_rococo::BridgeHubRococo::PARACHAIN_ID;
const MAX_HEADER_SIZE: u32 = bp_bridge_hub_rococo::BridgeHubRococo::MAX_HEADER_SIZE;
}

impl bp_messages::ChainWithMessages for BaseBridgeHubRococoAsBridgeHubPolkadot {
const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
relay_bridge_hub_polkadot_client::BridgeHubPolkadot::WITH_CHAIN_MESSAGES_PALLET_NAME;

const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
relay_bridge_hub_rococo_client::BridgeHubRococo::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce =
relay_bridge_hub_rococo_client::BridgeHubRococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
}

/// Relay `Chain` implementation of Rococo Bridge Hub, pretending to be a Polkadot Bridge Hub.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BridgeHubRococoAsBridgeHubPolkadot;

impl bp_runtime::UnderlyingChainProvider for BridgeHubRococoAsBridgeHubPolkadot {
type Chain = BaseBridgeHubRococoAsBridgeHubPolkadot;
}

impl relay_substrate_client::Chain for BridgeHubRococoAsBridgeHubPolkadot {
const NAME: &'static str = relay_bridge_hub_rococo_client::BridgeHubRococo::NAME;
const BEST_FINALIZED_HEADER_ID_METHOD: &'static str =
relay_bridge_hub_polkadot_client::BridgeHubPolkadot::BEST_FINALIZED_HEADER_ID_METHOD;
const FREE_HEADERS_INTERVAL_METHOD: &'static str =
relay_bridge_hub_polkadot_client::BridgeHubPolkadot::FREE_HEADERS_INTERVAL_METHOD;
const AVERAGE_BLOCK_INTERVAL: Duration =
relay_bridge_hub_rococo_client::BridgeHubRococo::AVERAGE_BLOCK_INTERVAL;

type SignedBlock = <relay_bridge_hub_rococo_client::BridgeHubRococo as relay_substrate_client::Chain>::SignedBlock;
type Call =
<relay_bridge_hub_rococo_client::BridgeHubRococo as relay_substrate_client::Chain>::Call;
}

impl relay_substrate_client::ChainWithBalances for BridgeHubRococoAsBridgeHubPolkadot {
fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey {
relay_bridge_hub_rococo_client::BridgeHubRococo::account_info_storage_key(account_id)
}
}

impl relay_substrate_client::ChainWithUtilityPallet for BridgeHubRococoAsBridgeHubPolkadot {
type UtilityPallet = relay_substrate_client::MockedRuntimeUtilityPallet<
relay_bridge_hub_rococo_client::RuntimeCall,
>;
}

impl relay_substrate_client::ChainWithTransactions for BridgeHubRococoAsBridgeHubPolkadot {
type AccountKeyPair = <relay_bridge_hub_rococo_client::BridgeHubRococo as relay_substrate_client::ChainWithTransactions>::AccountKeyPair;
type SignedTransaction = <relay_bridge_hub_rococo_client::BridgeHubRococo as relay_substrate_client::ChainWithTransactions>::SignedTransaction;

fn sign_transaction(
param: SignParam<Self>,
unsigned: UnsignedTransaction<Self>,
) -> Result<Self::SignedTransaction, SubstrateError> {
relay_bridge_hub_rococo_client::BridgeHubRococo::sign_transaction(
SignParam {
spec_version: param.spec_version,
transaction_version: param.transaction_version,
genesis_hash: param.genesis_hash,
signer: param.signer,
},
unsigned.switch_chain(),
)
}
}

impl relay_substrate_client::ChainWithMessages for BridgeHubRococoAsBridgeHubPolkadot {
const WITH_CHAIN_RELAYERS_PALLET_NAME: Option<&'static str> =
relay_bridge_hub_polkadot_client::BridgeHubPolkadot::WITH_CHAIN_RELAYERS_PALLET_NAME;

const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
relay_bridge_hub_polkadot_client::BridgeHubPolkadot::TO_CHAIN_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
relay_bridge_hub_polkadot_client::BridgeHubPolkadot::FROM_CHAIN_MESSAGE_DETAILS_METHOD;
}

impl ChainWithRuntimeVersion for BridgeHubRococoAsBridgeHubPolkadot {
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> =
Some(SimpleRuntimeVersion { spec_version: 1_003_000, transaction_version: 3 });
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! RococoBulletin-to-BridgeHubRococo headers sync entrypoint.

use super::BridgeHubRococoAsBridgeHubPolkadot;
use relay_bridge_hub_rococo_client::BridgeHubRococo;

use async_trait::async_trait;
use substrate_relay_helper::{
Expand Down Expand Up @@ -51,7 +51,7 @@ substrate_relay_helper::generate_report_equivocation_call_builder!(
#[async_trait]
impl SubstrateFinalityPipeline for RococoBulletinFinalityToBridgeHubRococo {
type SourceChain = relay_polkadot_bulletin_client::PolkadotBulletin;
type TargetChain = BridgeHubRococoAsBridgeHubPolkadot;
type TargetChain = BridgeHubRococo;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
}
Expand All @@ -71,7 +71,7 @@ pub struct RococoBulletinToBridgeHubRococoCliBridge {}

impl CliBridgeBase for RococoBulletinToBridgeHubRococoCliBridge {
type Source = relay_polkadot_bulletin_client::PolkadotBulletin;
type Target = BridgeHubRococoAsBridgeHubPolkadot;
type Target = BridgeHubRococo;
}

impl RelayToRelayHeadersCliBridge for RococoBulletinToBridgeHubRococoCliBridge {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! RococoBulletin-to-BridgeHubRococo messages sync entrypoint.

use super::BridgeHubRococoAsBridgeHubPolkadot;
use relay_bridge_hub_rococo_client::BridgeHubRococo;
use relay_polkadot_bulletin_client::PolkadotBulletin as RococoBulletin;
use substrate_relay_helper::{
cli::bridge::{CliBridgeBase, MessagesCliBridge},
Expand All @@ -29,7 +29,7 @@ pub struct RococoBulletinToBridgeHubRococoMessagesCliBridge {}

impl CliBridgeBase for RococoBulletinToBridgeHubRococoMessagesCliBridge {
type Source = RococoBulletin;
type Target = BridgeHubRococoAsBridgeHubPolkadot;
type Target = BridgeHubRococo;
}

impl MessagesCliBridge for RococoBulletinToBridgeHubRococoMessagesCliBridge {
Expand All @@ -56,7 +56,7 @@ pub struct RococoBulletinMessagesToBridgeHubRococoMessageLane;

impl SubstrateMessageLane for RococoBulletinMessagesToBridgeHubRococoMessageLane {
type SourceChain = RococoBulletin;
type TargetChain = BridgeHubRococoAsBridgeHubPolkadot;
type TargetChain = BridgeHubRococo;

type LaneId = bp_messages::LegacyLaneId;

Expand All @@ -66,5 +66,5 @@ impl SubstrateMessageLane for RococoBulletinMessagesToBridgeHubRococoMessageLane
RococoBulletinMessagesToBridgeHubRococoMessageLaneReceiveMessagesDeliveryProofCallBuilder;

type SourceBatchCallBuilder = ();
type TargetBatchCallBuilder = UtilityPalletBatchCallBuilder<BridgeHubRococoAsBridgeHubPolkadot>;
type TargetBatchCallBuilder = UtilityPalletBatchCallBuilder<BridgeHubRococo>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Rococo-to-RococoBulletin headers sync entrypoint.

use super::RococoAsPolkadot;
use relay_rococo_client::Rococo;

use async_trait::async_trait;
use substrate_relay_helper::{
Expand Down Expand Up @@ -49,7 +49,7 @@ substrate_relay_helper::generate_report_equivocation_call_builder!(

#[async_trait]
impl SubstrateFinalityPipeline for RococoFinalityToRococoBulletin {
type SourceChain = RococoAsPolkadot;
type SourceChain = Rococo;
type TargetChain = relay_polkadot_bulletin_client::PolkadotBulletin;

type FinalityEngine = GrandpaFinalityEngine<Self::SourceChain>;
Expand All @@ -69,7 +69,7 @@ impl SubstrateEquivocationDetectionPipeline for RococoFinalityToRococoBulletin {
pub struct RococoToRococoBulletinCliBridge {}

impl CliBridgeBase for RococoToRococoBulletinCliBridge {
type Source = RococoAsPolkadot;
type Source = Rococo;
type Target = relay_polkadot_bulletin_client::PolkadotBulletin;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

//! Rococo-to-RococoBulletin parachains sync entrypoint.

use super::{BridgeHubRococoAsBridgeHubPolkadot, RococoAsPolkadot};
use relay_bridge_hub_rococo_client::BridgeHubRococo;
use relay_rococo_client::Rococo;

use bp_polkadot_core::parachains::{ParaHash, ParaHeadsProof, ParaId};
use bp_runtime::Chain;
Expand All @@ -32,8 +33,8 @@ use substrate_relay_helper::{
pub struct RococoToRococoBulletin;

impl SubstrateParachainsPipeline for RococoToRococoBulletin {
type SourceParachain = BridgeHubRococoAsBridgeHubPolkadot;
type SourceRelayChain = RococoAsPolkadot;
type SourceParachain = BridgeHubRococo;
type SourceRelayChain = Rococo;
type TargetChain = relay_polkadot_bulletin_client::PolkadotBulletin;

type SubmitParachainHeadsCallBuilder = RococoToRococoBulletinCallBuilder;
Expand Down Expand Up @@ -61,14 +62,14 @@ impl SubmitParachainHeadsCallBuilder<RococoToRococoBulletin> for RococoToRococoB
pub struct RococoToRococoBulletinCliBridge {}

impl ParachainToRelayHeadersCliBridge for RococoToRococoBulletinCliBridge {
type SourceRelay = RococoAsPolkadot;
type SourceRelay = Rococo;
type ParachainFinality = RococoToRococoBulletin;
type RelayFinality =
crate::bridges::rococo_bulletin::rococo_headers_to_rococo_bulletin::RococoFinalityToRococoBulletin;
}

impl CliBridgeBase for RococoToRococoBulletinCliBridge {
type Source = BridgeHubRococoAsBridgeHubPolkadot;
type Source = BridgeHubRococo;
type Target = relay_polkadot_bulletin_client::PolkadotBulletin;
}

Expand Down
Loading
Loading