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

Enable async backing for system parachains #266

Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -18,10 +18,12 @@ system-parachains-constants = { path = "../../../constants", default-features =
bp-bridge-hub-cumulus = { workspace = true }
bp-runtime = { workspace = true }
bp-messages = { workspace = true }
polkadot-primitives = { workspace = true }
snowbridge-core = { workspace = true }

# Substrate Based Dependencies
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-api = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,48 @@
#![cfg_attr(not(feature = "std"), no_std)]

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,
parameter_types,
sp_runtime::{MultiAddress, MultiSigner},
weights::constants,
};
use frame_system::limits;
use sp_runtime::{FixedPointNumber, FixedU128, RuntimeDebug, Saturating};

// TODO: Remove this as soon as the `bp-bridge-hub-cumulus` version is bumped to 0.10.0
// See https://github.com/polkadot-fellows/runtimes/issues/186
s0me0ne-unkn0wn marked this conversation as resolved.
Show resolved Hide resolved
const MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING: Weight = Weight::from_parts(
constants::WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
polkadot_primitives::MAX_POV_SIZE as u64,
);

parameter_types! {
pub BlockWeightsForAsyncBacking: limits::BlockWeights = limits::BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING);
// Operational transactions have an extra reserved space, so that they
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING,
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
}

/// BridgeHubKusama parachain.
#[derive(RuntimeDebug)]
pub struct BridgeHubKusama;
Expand All @@ -52,7 +84,7 @@ impl Chain for BridgeHubKusama {
}

fn max_extrinsic_weight() -> Weight {
BlockWeights::get()
BlockWeightsForAsyncBacking::get()
.get(DispatchClass::Normal)
.max_extrinsic
.unwrap_or(Weight::MAX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ mod tests {
>(AssertCompleteBridgeConstants {
this_chain_constants: AssertChainConstants {
block_length: bp_bridge_hub_kusama::BlockLength::get(),
block_weights: bp_bridge_hub_kusama::BlockWeights::get(),
block_weights: bp_bridge_hub_kusama::BlockWeightsForAsyncBacking::get(),
},
messages_pallet_constants: AssertBridgeMessagesPalletConstants {
max_unrewarded_relayers_in_bridged_confirmation_tx:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ system-parachains-constants = { path = "../../../constants", default-features =
bp-bridge-hub-cumulus = { workspace = true }
bp-runtime = { workspace = true }
bp-messages = { workspace = true }
polkadot-primitives = { workspace = true }
snowbridge-core = { workspace = true }

# Substrate Based Dependencies
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-api = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,38 @@ use bp_messages::*;
use bp_runtime::{
decl_bridge_finality_runtime_apis, decl_bridge_messages_runtime_apis, Chain, ChainId, Parachain,
};
use frame_support::dispatch::DispatchClass;
use frame_support::{dispatch::DispatchClass, parameter_types, weights::constants};
use frame_system::limits;
use sp_runtime::{FixedPointNumber, FixedU128, RuntimeDebug, Saturating};

// TODO: Remove this as soon as the `bp-bridge-hub-cumulus` version is bumped to 0.10.0
// See https://github.com/polkadot-fellows/runtimes/issues/186
const MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING: Weight = Weight::from_parts(
constants::WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
polkadot_primitives::MAX_POV_SIZE as u64,
);

parameter_types! {
pub BlockWeightsForAsyncBacking: limits::BlockWeights = limits::BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING);
// Operational transactions have an extra reserved space, so that they
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT_FOR_ASYNC_BACKING,
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();
}

/// BridgeHubPolkadot parachain.
#[derive(RuntimeDebug)]
pub struct BridgeHubPolkadot;
Expand All @@ -49,7 +78,7 @@ impl Chain for BridgeHubPolkadot {
}

fn max_extrinsic_weight() -> Weight {
BlockWeights::get()
BlockWeightsForAsyncBacking::get()
.get(DispatchClass::Normal)
.max_extrinsic
.unwrap_or(Weight::MAX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ mod tests {
>(AssertCompleteBridgeConstants {
this_chain_constants: AssertChainConstants {
block_length: bp_bridge_hub_polkadot::BlockLength::get(),
block_weights: bp_bridge_hub_polkadot::BlockWeights::get(),
block_weights: bp_bridge_hub_polkadot::BlockWeightsForAsyncBacking::get(),
},
messages_pallet_constants: AssertBridgeMessagesPalletConstants {
max_unrewarded_relayers_in_bridged_confirmation_tx:
Expand Down
Loading