Skip to content

Commit

Permalink
implemented (1), (2), (4), (5) from paritytech/parity-bridges-common#…
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik committed Mar 18, 2024
1 parent ba62cdc commit 084e58c
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 17 deletions.
2 changes: 2 additions & 0 deletions 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 @@ -22,6 +22,7 @@ scale-info = { version = "2.10.0", default-features = false, features = [
"derive",
] }
serde = { optional = true, features = ["derive"], workspace = true, default-features = true }
tuplex = { version = "0.1", default-features = false }

# Substrate
frame-benchmarking = { path = "../../../../../substrate/frame/benchmarking", default-features = false, optional = true }
Expand Down Expand Up @@ -216,6 +217,7 @@ std = [
"sp-version/std",
"substrate-wasm-builder",
"testnet-parachains-constants/std",
"tuplex/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use super::{
};
use bp_parachains::SingleParaStoredHeaderDataBuilder;
use bp_runtime::UnderlyingChainProvider;
use bridge_runtime_common::messages::ThisChainWithMessages;
use bridge_runtime_common::{messages::ThisChainWithMessages, FreeParachainUpdateForFreeRelayHeader, RefundableParachain};
use frame_support::{parameter_types, traits::ConstU32};
use sp_runtime::RuntimeDebug;

Expand All @@ -49,7 +49,8 @@ pub type BridgeGrandpaWestendInstance = pallet_bridge_grandpa::Instance3;
impl pallet_bridge_grandpa::Config<BridgeGrandpaWestendInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type BridgedChain = bp_westend::Westend;
type MaxFreeMandatoryHeadersPerBlock = ConstU32<4>;
type MaxFreeHeadersPerBlock = ConstU32<4>;
type FreeHeadersInterval = ConstU32<5>;
type HeadersToKeep = RelayChainHeadersToKeep;
type WeightInfo = weights::pallet_bridge_grandpa::WeightInfo<Runtime>;
}
Expand All @@ -61,6 +62,14 @@ impl pallet_bridge_parachains::Config<BridgeParachainWestendInstance> for Runtim
type WeightInfo = weights::pallet_bridge_parachains::WeightInfo<Runtime>;
type BridgesGrandpaPalletInstance = BridgeGrandpaWestendInstance;
type ParasPalletName = WestendBridgeParachainPalletName;
type FreeHeadsUpdateFilter = FreeParachainUpdateForFreeRelayHeader<
Runtime,
Self::BridgesGrandpaPalletInstance,
RefundableParachain<
BridgeParachainWestendInstance,
bp_bridge_hub_westend::BridgeHubWestend,
>,
>;
type ParaStoredHeaderDataBuilder =
SingleParaStoredHeaderDataBuilder<bp_bridge_hub_westend::BridgeHubWestend>;
type HeadsToKeep = ParachainHeadsToKeep;
Expand Down Expand Up @@ -89,7 +98,8 @@ pub type BridgeGrandpaRococoBulletinInstance = pallet_bridge_grandpa::Instance4;
impl pallet_bridge_grandpa::Config<BridgeGrandpaRococoBulletinInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type BridgedChain = bp_polkadot_bulletin::PolkadotBulletin;
type MaxFreeMandatoryHeadersPerBlock = ConstU32<4>;
type MaxFreeHeadersPerBlock = ConstU32<4>;
type FreeHeadersInterval = ConstU32<5>;
type HeadersToKeep = RelayChainHeadersToKeep;
// Technically this is incorrect - we have two pallet instances and ideally we shall
// benchmark every instance separately. But the benchmarking engine has a flaw - it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use bridge_runtime_common::{
SenderAndLane, XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter,
XcmBlobMessageDispatch, XcmVersionOfDestAndRemoteBridge,
},
refund_relayer_extension::{
extensions::refund_relayer_extension::{
ActualFeeRefund, RefundBridgedGrandpaMessages, RefundTransactionExtensionAdapter,
RefundableMessagesLane,
},
Expand Down Expand Up @@ -90,6 +90,8 @@ parameter_types! {
/// meaning of this value.
pub PriorityBoostPerMessage: u64 = 182_044_444_444_444;

pub PriorityBoostPerHeader: u64 = PriorityBoostPerMessage::get() / 1_000_000; // TODO

/// Identifier of the sibling Rococo People parachain.
pub RococoPeopleParaId: cumulus_primitives_core::ParaId = rococo_runtime_constants::system_parachain::PEOPLE_ID.into();
/// A route (XCM location and bridge lane) that the Rococo People Chain -> Rococo Bulletin Chain
Expand Down Expand Up @@ -273,7 +275,7 @@ mod tests {
// Bulletin chain - it has the same (almost) runtime for Polkadot Bulletin and Rococo
// Bulletin, so we have to adhere Polkadot names here

bridge_runtime_common::priority_calculator::ensure_priority_boost_is_sane::<
bridge_runtime_common::extensions::priority_calculator::ensure_priority_boost_is_sane::<
Runtime,
WithRococoBulletinMessagesInstance,
PriorityBoostPerMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ use bridge_runtime_common::{
SenderAndLane, XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter,
XcmBlobMessageDispatch, XcmVersionOfDestAndRemoteBridge,
},
refund_relayer_extension::{
extensions::refund_relayer_extension::{
ActualFeeRefund, RefundBridgedParachainMessages, RefundTransactionExtensionAdapter,
RefundableMessagesLane, RefundableParachain,
RefundableMessagesLane,
},
RefundableParachain,
};

use codec::Encode;
Expand All @@ -68,6 +69,8 @@ parameter_types! {
// see the `FEE_BOOST_PER_MESSAGE` constant to get the meaning of this value
pub PriorityBoostPerMessage: u64 = 182_044_444_444_444;

pub PriorityBoostPerHeader: u64 = PriorityBoostPerMessage::get() / 1_000_000; // TODO

pub AssetHubRococoParaId: cumulus_primitives_core::ParaId = bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID.into();
pub AssetHubWestendParaId: cumulus_primitives_core::ParaId = bp_asset_hub_westend::ASSET_HUB_WESTEND_PARACHAIN_ID.into();

Expand Down Expand Up @@ -318,7 +321,7 @@ mod tests {
},
});

bridge_runtime_common::priority_calculator::ensure_priority_boost_is_sane::<
bridge_runtime_common::extensions::priority_calculator::ensure_priority_boost_is_sane::<
Runtime,
WithBridgeHubWestendMessagesInstance,
PriorityBoostPerMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H160};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{Block as BlockT, Keccak256},
traits::{Block as BlockT, Get, Keccak256},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedU128,
};
Expand Down Expand Up @@ -78,6 +78,7 @@ use bridge_hub_common::{
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
AggregateMessageOrigin,
};
use bridge_runtime_common::extensions::check_obsolete_extension::CheckAndBoostBridgeGrandpaTransactions;
use pallet_xcm::EnsureXcm;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
Expand Down Expand Up @@ -749,8 +750,18 @@ pub type XcmOverRococoBulletin = XcmOverPolkadotBulletin;
bridge_runtime_common::generate_bridge_reject_obsolete_headers_and_messages! {
RuntimeCall, AccountId,
// Grandpa
BridgeWestendGrandpa,
BridgeRococoBulletinGrandpa,
CheckAndBoostBridgeGrandpaTransactions<
Runtime,
bridge_common_config::BridgeGrandpaWestendInstance,
bridge_to_westend_config::PriorityBoostPerHeader,
xcm_config::TreasuryAccount,
>,
CheckAndBoostBridgeGrandpaTransactions<
Runtime,
bridge_common_config::BridgeGrandpaRococoBulletinInstance,
bridge_to_bulletin_config::PriorityBoostPerHeader,
xcm_config::TreasuryAccount,
>,
// Parachains
BridgeWestendParachains,
// Messages
Expand Down Expand Up @@ -949,6 +960,9 @@ impl_runtime_apis! {
fn best_finalized() -> Option<HeaderId<bp_westend::Hash, bp_westend::BlockNumber>> {
BridgeWestendGrandpa::best_finalized()
}
fn free_headers_interval() -> Option<bp_westend::BlockNumber> {
<Runtime as pallet_bridge_grandpa::Config<bridge_common_config::BridgeGrandpaWestendInstance>>::MaxFreeHeadersPerBlock::get()
}
fn synced_headers_grandpa_info(
) -> Vec<bp_header_chain::StoredHeaderGrandpaInfo<bp_westend::Header>> {
BridgeWestendGrandpa::synced_headers_grandpa_info()
Expand All @@ -961,6 +975,9 @@ impl_runtime_apis! {
bp_bridge_hub_westend::BridgeHubWestend
>().unwrap_or(None)
}
fn free_headers_interval() -> Option<bp_westend::BlockNumber> {
None
}
}

// This is exposed by BridgeHubRococo
Expand Down Expand Up @@ -995,6 +1012,10 @@ impl_runtime_apis! {
BridgePolkadotBulletinGrandpa::best_finalized()
}

fn free_headers_interval() -> Option<bp_polkadot_bulletin::BlockNumber> {
<Runtime as pallet_bridge_grandpa::Config<bridge_common_config::BridgeGrandpaRococoBulletinInstance>>::MaxFreeHeadersPerBlock::get()
}

fn synced_headers_grandpa_info(
) -> Vec<bp_header_chain::StoredHeaderGrandpaInfo<bp_polkadot_bulletin::Header>> {
BridgePolkadotBulletinGrandpa::synced_headers_grandpa_info()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

//! Expose the auto generated weight files.
use ::pallet_bridge_grandpa::WeightInfoExt as GrandpaWeightInfoExt;
use ::pallet_bridge_messages::WeightInfoExt as MessagesWeightInfoExt;
use ::pallet_bridge_parachains::WeightInfoExt as ParachainsWeightInfoExt;

Expand Down Expand Up @@ -58,6 +59,12 @@ use frame_support::weights::Weight;
// import trait from dependency module
use ::pallet_bridge_relayers::WeightInfoExt as _;

impl GrandpaWeightInfoExt for pallet_bridge_grandpa::WeightInfo<crate::Runtime> {
fn submit_finality_proof_overhead_from_runtime() -> Weight {
pallet_bridge_relayers::WeightInfo::<Runtime>::receive_messages_proof_overhead_from_runtime()
}
}

impl MessagesWeightInfoExt
for pallet_bridge_messages_rococo_to_rococo_bulletin::WeightInfo<crate::Runtime>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ hex-literal = { version = "0.4.1" }
log = { workspace = true }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
serde = { optional = true, features = ["derive"], workspace = true, default-features = true }
tuplex = { version = "0.1", default-features = false }

# Substrate
frame-benchmarking = { path = "../../../../../substrate/frame/benchmarking", default-features = false, optional = true }
Expand Down Expand Up @@ -177,6 +178,7 @@ std = [
"sp-version/std",
"substrate-wasm-builder",
"testnet-parachains-constants/std",
"tuplex/std",
"westend-runtime-constants/std",
"xcm-builder/std",
"xcm-executor/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ use bridge_runtime_common::{
SenderAndLane, XcmAsPlainPayload, XcmBlobHauler, XcmBlobHaulerAdapter,
XcmBlobMessageDispatch, XcmVersionOfDestAndRemoteBridge,
},
refund_relayer_extension::{
extensions::refund_relayer_extension::{
ActualFeeRefund, RefundBridgedParachainMessages, RefundTransactionExtensionAdapter,
RefundableMessagesLane, RefundableParachain,
RefundableMessagesLane,
},
FreeParachainUpdateForFreeRelayHeader, RefundableParachain,
};
use codec::Encode;
use frame_support::{
Expand Down Expand Up @@ -73,6 +74,8 @@ parameter_types! {
// see the `FEE_BOOST_PER_MESSAGE` constant to get the meaning of this value
pub PriorityBoostPerMessage: u64 = 182_044_444_444_444;

pub PriorityBoostPerHeader: u64 = PriorityBoostPerMessage::get() / 1_000_000; // TODO

pub AssetHubWestendParaId: cumulus_primitives_core::ParaId = bp_asset_hub_westend::ASSET_HUB_WESTEND_PARACHAIN_ID.into();
pub AssetHubRococoParaId: cumulus_primitives_core::ParaId = bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID.into();

Expand Down Expand Up @@ -210,7 +213,8 @@ pub type BridgeGrandpaRococoInstance = pallet_bridge_grandpa::Instance1;
impl pallet_bridge_grandpa::Config<BridgeGrandpaRococoInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type BridgedChain = bp_rococo::Rococo;
type MaxFreeMandatoryHeadersPerBlock = ConstU32<4>;
type MaxFreeHeadersPerBlock = ConstU32<4>;
type FreeHeadersInterval = ConstU32<5>;
type HeadersToKeep = RelayChainHeadersToKeep;
type WeightInfo = weights::pallet_bridge_grandpa::WeightInfo<Runtime>;
}
Expand All @@ -222,6 +226,14 @@ impl pallet_bridge_parachains::Config<BridgeParachainRococoInstance> for Runtime
type WeightInfo = weights::pallet_bridge_parachains::WeightInfo<Runtime>;
type BridgesGrandpaPalletInstance = BridgeGrandpaRococoInstance;
type ParasPalletName = RococoBridgeParachainPalletName;
type FreeHeadsUpdateFilter = FreeParachainUpdateForFreeRelayHeader<
Runtime,
Self::BridgesGrandpaPalletInstance,
RefundableParachain<
BridgeParachainRococoInstance,
bp_bridge_hub_rococo::BridgeHubRococo,
>,
>;
type ParaStoredHeaderDataBuilder =
SingleParaStoredHeaderDataBuilder<bp_bridge_hub_rococo::BridgeHubRococo>;
type HeadsToKeep = ParachainHeadsToKeep;
Expand Down Expand Up @@ -352,7 +364,7 @@ mod tests {
},
});

bridge_runtime_common::priority_calculator::ensure_priority_boost_is_sane::<
bridge_runtime_common::extensions::priority_calculator::ensure_priority_boost_is_sane::<
Runtime,
WithBridgeHubRococoMessagesInstance,
PriorityBoostPerMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::Block as BlockT,
traits::{Block as BlockT, Get},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult,
};
Expand All @@ -52,6 +52,7 @@ use bridge_hub_common::{
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
AggregateMessageOrigin,
};
use bridge_runtime_common::extensions::check_obsolete_extension::CheckAndBoostBridgeGrandpaTransactions;
use frame_support::{
construct_runtime, derive_impl,
dispatch::DispatchClass,
Expand Down Expand Up @@ -505,7 +506,12 @@ construct_runtime!(
bridge_runtime_common::generate_bridge_reject_obsolete_headers_and_messages! {
RuntimeCall, AccountId,
// Grandpa
BridgeRococoGrandpa,
CheckAndBoostBridgeGrandpaTransactions<
Runtime,
bridge_to_rococo_config::BridgeGrandpaRococoInstance,
bridge_to_rococo_config::PriorityBoostPerHeader,
xcm_config::TreasuryAccount,
>,
// Parachains
BridgeRococoParachains,
// Messages
Expand Down Expand Up @@ -697,6 +703,9 @@ impl_runtime_apis! {
fn best_finalized() -> Option<HeaderId<bp_rococo::Hash, bp_rococo::BlockNumber>> {
BridgeRococoGrandpa::best_finalized()
}
fn free_headers_interval() -> Option<bp_rococo::BlockNumber> {
<Runtime as pallet_bridge_grandpa::Config<bridge_to_rococo_config::BridgeGrandpaRococoInstance>>::MaxFreeHeadersPerBlock::get()
}
fn synced_headers_grandpa_info(
) -> Vec<bp_header_chain::StoredHeaderGrandpaInfo<bp_rococo::Header>> {
BridgeRococoGrandpa::synced_headers_grandpa_info()
Expand All @@ -709,6 +718,9 @@ impl_runtime_apis! {
bp_bridge_hub_rococo::BridgeHubRococo
>().unwrap_or(None)
}
fn free_headers_interval() -> Option<bp_rococo::BlockNumber> {
None
}
}

impl bp_bridge_hub_rococo::FromBridgeHubRococoInboundLaneApi<Block> for Runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

//! Expose the auto generated weight files.
use ::pallet_bridge_grandpa::WeightInfoExt as GrandpaWeightInfoExt;
use ::pallet_bridge_messages::WeightInfoExt as MessagesWeightInfoExt;
use ::pallet_bridge_parachains::WeightInfoExt as ParachainsWeightInfoExt;

Expand Down Expand Up @@ -53,6 +54,12 @@ use frame_support::weights::Weight;
// import trait from dependency module
use ::pallet_bridge_relayers::WeightInfoExt as _;

impl GrandpaWeightInfoExt for pallet_bridge_grandpa::WeightInfo<crate::Runtime> {
fn submit_finality_proof_overhead_from_runtime() -> Weight {
pallet_bridge_relayers::WeightInfo::<Runtime>::receive_messages_proof_overhead_from_runtime()
}
}

impl MessagesWeightInfoExt for pallet_bridge_messages::WeightInfo<crate::Runtime> {
fn expected_extra_storage_proof_size() -> u32 {
bp_bridge_hub_rococo::EXTRA_STORAGE_PROOF_SIZE
Expand Down

0 comments on commit 084e58c

Please sign in to comment.