Skip to content

Commit

Permalink
Setup permissionless lanes for AssetHubRococo
Browse files Browse the repository at this point in the history
tmp
  • Loading branch information
bkontur committed Jan 30, 2025
1 parent c007bb4 commit 4bc29ca
Show file tree
Hide file tree
Showing 19 changed files with 1,768 additions and 30 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions bridges/chains/chain-asset-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ scale-info = { features = ["derive"], workspace = true }

# Substrate Dependencies
frame-support = { workspace = true }
sp-api = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

# Bridge Dependencies
bp-xcm-bridge-router = { workspace = true }
bp-bridge-hub-cumulus = { workspace = true }
bp-runtime = { workspace = true }
bp-messages = { workspace = true }
bp-xcm-bridge = { workspace = true }

# Polkadot dependencies
xcm = { workspace = true }
Expand All @@ -36,4 +43,13 @@ std = [
"scale-info/std",
"sp-core/std",
"xcm/std",
"bp-bridge-hub-cumulus/std",
"bp-messages/std",
"bp-runtime/std",
"bp-xcm-bridge/std",
"codec/std",
"frame-support/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
]
102 changes: 101 additions & 1 deletion bridges/chains/chain-asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

//! Module with configuration which reflects AssetHubRococo runtime setup.
//! Module with configuration which reflects AssetHubRococo runtime setup (AccountId, Headers,
//! Hashes...)
#![cfg_attr(not(feature = "std"), no_std)]

Expand All @@ -23,6 +24,15 @@ extern crate alloc;
use codec::{Decode, Encode};
use scale_info::TypeInfo;

pub use bp_bridge_hub_cumulus::*;
use bp_messages::*;
use bp_runtime::{
decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId, Parachain,
};
use frame_support::{
dispatch::DispatchClass,
sp_runtime::{MultiAddress, MultiSigner, RuntimeDebug, StateVersion},
};
pub use bp_xcm_bridge_router::XcmBridgeHubCall;
use xcm::latest::prelude::*;

Expand Down Expand Up @@ -71,3 +81,93 @@ pub fn build_congestion_message<RuntimeCall>(

/// Identifier of AssetHubRococo in the Rococo relay chain.
pub const ASSET_HUB_ROCOCO_PARACHAIN_ID: u32 = 1000;

/// AssetHubRococo parachain.
#[derive(RuntimeDebug)]
pub struct AssetHubRococo;

impl Chain for AssetHubRococo {
const ID: ChainId = *b"ahro";

type BlockNumber = BlockNumber;
type Hash = Hash;
type Hasher = Hasher;
type Header = Header;

type AccountId = AccountId;
type Balance = Balance;
type Nonce = Nonce;
type Signature = Signature;

const STATE_VERSION: StateVersion = StateVersion::V1;

fn max_extrinsic_size() -> u32 {
*BlockLength::get().max.get(DispatchClass::Normal)
}

fn max_extrinsic_weight() -> Weight {
BlockWeightsForAsyncBacking::get()
.get(DispatchClass::Normal)
.max_extrinsic
.unwrap_or(Weight::MAX)
}
}

impl Parachain for AssetHubRococo {
const PARACHAIN_ID: u32 = ASSET_HUB_ROCOCO_PARACHAIN_ID;
const MAX_HEADER_SIZE: u32 = MAX_BRIDGE_HUB_HEADER_SIZE;
}

/// Describing permissionless lanes instance
impl ChainWithMessages for AssetHubRococo {
const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
WITH_ASSET_HUB_ROCOCO_MESSAGES_PALLET_NAME;

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

/// Public key of the chain account that may be used to verify signatures.
pub type AccountSigner = MultiSigner;

/// The address format for describing accounts.
pub type Address = MultiAddress<AccountId, ()>;

/// Name of the With-AssetHubRococo messages pallet instance that is deployed at bridged chains.
pub const WITH_ASSET_HUB_ROCOCO_MESSAGES_PALLET_NAME: &str = "BridgeRococoMessages";

/// Name of the With-AssetHubRococo bridge-relayers pallet instance that is deployed at bridged
/// chains.
pub const WITH_ASSET_HUB_ROCOCO_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";

/// Pallet index of `BridgeWestendMessages: pallet_bridge_messages::<Instance1>`.
pub const WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX: u8 = 62;

decl_bridge_finality_runtime_apis!(asset_hub_rococo);
decl_bridge_messages_runtime_apis!(asset_hub_rococo, HashedLaneId);

frame_support::parameter_types! {
/// TODO: FAIL-CI - probably not needed or ise for MessageExporterPrice
/// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Rococo
/// BridgeHub.
/// (initially was calculated by test `AssetHubRococo::can_calculate_weight_for_paid_export_message_with_reserve_transfer` + `33%`)
pub const AssetHubRococoBaseXcmFeeInRocs: u128 = 57_325_000;

/// Transaction fee that is paid at the Rococo BridgeHub for delivering single inbound message.
/// (initially was calculated by test `AssetHubRococo::can_calculate_fee_for_standalone_message_delivery_transaction` + `33%`)
pub const AssetHubRococoBaseDeliveryFeeInRocs: u128 = 297_685_840;

/// Transaction fee that is paid at the Rococo BridgeHub for delivering single outbound message confirmation.
/// (initially was calculated by test `AssetHubRococo::can_calculate_fee_for_standalone_message_confirmation_transaction` + `33%`)
pub const AssetHubRococoBaseConfirmationFeeInRocs: u128 = 56_782_099;
}

/// Wrapper over `AssetHubRococo`'s `RuntimeCall` that can be used without a runtime.
#[derive(Decode, Encode)]
pub enum RuntimeCall {
/// Points to the `pallet_xcm_bridge` pallet instance for `AssetHubWestend`.
#[codec(index = 61)]
XcmOverAssetHubWestend(bp_xcm_bridge::XcmBridgeCall),
}
16 changes: 16 additions & 0 deletions bridges/chains/chain-asset-hub-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ scale-info = { features = ["derive"], workspace = true }

# Substrate Dependencies
frame-support = { workspace = true }
sp-api = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

# Bridge Dependencies
bp-xcm-bridge-router = { workspace = true }
bp-bridge-hub-cumulus = { workspace = true }
bp-runtime = { workspace = true }
bp-messages = { workspace = true }
bp-xcm-bridge = { workspace = true }

# Polkadot dependencies
xcm = { workspace = true }
Expand All @@ -36,4 +43,13 @@ std = [
"scale-info/std",
"sp-core/std",
"xcm/std",
"bp-bridge-hub-cumulus/std",
"bp-messages/std",
"bp-runtime/std",
"bp-xcm-bridge/std",
"codec/std",
"frame-support/std",
"sp-api/std",
"sp-runtime/std",
"sp-std/std",
]
103 changes: 102 additions & 1 deletion bridges/chains/chain-asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

//! Module with configuration which reflects AssetHubWestend runtime setup.
//! Module with configuration which reflects AssetHubWestend runtime setup (AccountId, Headers,
//! Hashes...)
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

pub use bp_bridge_hub_cumulus::*;
use bp_messages::*;
use bp_runtime::{
decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId, Parachain,
};
use frame_support::{
dispatch::DispatchClass,
sp_runtime::{MultiAddress, MultiSigner, RuntimeDebug, StateVersion},
};

use codec::{Decode, Encode};
use scale_info::TypeInfo;

Expand Down Expand Up @@ -71,3 +82,93 @@ pub fn build_congestion_message<RuntimeCall>(

/// Identifier of AssetHubWestend in the Westend relay chain.
pub const ASSET_HUB_WESTEND_PARACHAIN_ID: u32 = 1000;

/// Westend parachain.
#[derive(RuntimeDebug)]
pub struct AssetHubWestend;

impl Chain for AssetHubWestend {
const ID: ChainId = *b"ahwd";

type BlockNumber = BlockNumber;
type Hash = Hash;
type Hasher = Hasher;
type Header = Header;

type AccountId = AccountId;
type Balance = Balance;
type Nonce = Nonce;
type Signature = Signature;

const STATE_VERSION: StateVersion = StateVersion::V1;

fn max_extrinsic_size() -> u32 {
*BlockLength::get().max.get(DispatchClass::Normal)
}

fn max_extrinsic_weight() -> Weight {
BlockWeightsForAsyncBacking::get()
.get(DispatchClass::Normal)
.max_extrinsic
.unwrap_or(Weight::MAX)
}
}

impl Parachain for AssetHubWestend {
const PARACHAIN_ID: u32 = ASSET_HUB_WESTEND_PARACHAIN_ID;
const MAX_HEADER_SIZE: u32 = MAX_BRIDGE_HUB_HEADER_SIZE; // TODO: FAIL-CI - MAX_ASSET_HUB_HEADER_SIZE
}

/// Describing permissionless lanes instance
impl ChainWithMessages for AssetHubWestend {
const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str =
WITH_ASSET_HUB_WESTEND_MESSAGES_PALLET_NAME;

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

/// Public key of the chain account that may be used to verify signatures.
pub type AccountSigner = MultiSigner;

/// The address format for describing accounts.
pub type Address = MultiAddress<AccountId, ()>;

/// Name of the With-AssetHubWestend messages pallet instance that is deployed at bridged chains.
pub const WITH_ASSET_HUB_WESTEND_MESSAGES_PALLET_NAME: &str = "BridgeWestendMessages";

/// Name of the With-AssetHubWestend bridge-relayers pallet instance that is deployed at bridged
/// chains.
pub const WITH_ASSET_HUB_WESTEND_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";

/// Pallet index of `BridgeRococoMessages: pallet_bridge_messages::<Instance1>`.
pub const WITH_BRIDGE_WESTEND_TO_ROCOCO_MESSAGES_PALLET_INDEX: u8 = 60; // TODO: FAIL-CI - correct index when AssetHubWestend

decl_bridge_finality_runtime_apis!(asset_hub_westend);
decl_bridge_messages_runtime_apis!(asset_hub_westend, HashedLaneId);

frame_support::parameter_types! {
/// TODO: FAIL-CI - probably not needed
/// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Westend
/// AssetHub.
/// (initially was calculated by test `AssetHubWestend::can_calculate_weight_for_paid_export_message_with_reserve_transfer` + `33%`)
pub const AssetHubWestendBaseXcmFeeInWnds: u128 = 57_325_000;

/// Transaction fee that is paid at the Westend AssetHub for delivering single inbound message.
/// (initially was calculated by test `AssetHubWestend::can_calculate_fee_for_standalone_message_delivery_transaction` + `33%`)
pub const AssetHubWestendBaseDeliveryFeeInWnds: u128 = 297_685_840;

/// Transaction fee that is paid at the Westend AssetHub for delivering single outbound message confirmation.
/// (initially was calculated by test `AssetHubWestend::can_calculate_fee_for_standalone_message_confirmation_transaction` + `33%`)
pub const AssetHubWestendBaseConfirmationFeeInWnds: u128 = 56_782_099;
}

/// Wrapper over `AssetHubWestend`'s `RuntimeCall` that can be used without a runtime.
#[derive(Decode, Encode)]
pub enum RuntimeCall {
/// Points to the `pallet_xcm_bridge_hub` pallet instance for `AssetHubRococo`.
#[codec(index = 62)] // TODO: FAIL-CI - corect index when AssetHubWestend
XcmOverAssetHubRococo(bp_xcm_bridge::XcmBridgeCall),
}
Loading

0 comments on commit 4bc29ca

Please sign in to comment.