Skip to content
Open
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
10 changes: 6 additions & 4 deletions bridges/chains/chain-cumulus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ pub const MAX_BRIDGE_HUB_HEADER_SIZE: u32 = 4_096;

parameter_types! {
/// Size limit of the Cumulus-based bridge hub blocks.
pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio(
5 * 1024 * 1024,
NORMAL_DISPATCH_RATIO,
);
pub BlockLength: limits::BlockLength = limits::BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();

/// Importing a block with 0 Extrinsics.
pub const BlockExecutionWeight: Weight = Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS, 0)
Expand Down
10 changes: 6 additions & 4 deletions bridges/chains/chain-polkadot-bulletin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ parameter_types! {
// Note: Max transaction size is 8 MB. Set max block size to 10 MB to facilitate data storage.
// This is double the "normal" Relay Chain block length limit.
/// Maximal block length at Polkadot Bulletin chain.
pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio(
10 * 1024 * 1024,
NORMAL_DISPATCH_RATIO,
);
pub BlockLength: limits::BlockLength = limits::BlockLength::builder()
.max_length(10 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
}

/// Polkadot Bulletin Chain declaration.
Expand Down
10 changes: 6 additions & 4 deletions bridges/primitives/polkadot-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ parameter_types! {
/// All Polkadot-like chains have maximal block size set to 5MB.
///
/// This is a copy-paste from the Polkadot repo's `polkadot-runtime-common` crate.
pub BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio(
5 * 1024 * 1024,
NORMAL_DISPATCH_RATIO,
);
pub BlockLength: limits::BlockLength = limits::BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
/// All Polkadot-like chains have the same block weights.
///
/// This is a copy-paste from the Polkadot repo's `polkadot-runtime-common` crate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use super::{trie_cache, trie_recorder, MemoryOptimizedValidationParams};
use alloc::vec::Vec;
use codec::{Decode, Encode};
use cumulus_primitives_core::{
relay_chain::{BlockNumber as RNumber, Hash as RHash, UMPSignal, UMP_SEPARATOR},
relay_chain::{
BlockNumber as RNumber, Hash as RHash, UMPSignal, MAX_HEAD_DATA_SIZE, UMP_SEPARATOR,
},
ClaimQueueOffset, CoreSelector, ParachainBlockData, PersistedValidationData,
};
use frame_support::{
Expand Down Expand Up @@ -160,6 +162,13 @@ where
array_bytes::bytes2hex("0x", p.as_ref()),
array_bytes::bytes2hex("0x", b.header().parent_hash().as_ref()),
);
let encoded_header_size = b.header().encoded_size();
assert!(
encoded_header_size <= MAX_HEAD_DATA_SIZE as usize,
"Header size {} exceeds MAX_HEAD_DATA_SIZE {}",
encoded_header_size,
MAX_HEAD_DATA_SIZE
);
b.header().hash()
});

Expand Down
36 changes: 36 additions & 0 deletions cumulus/pallets/parachain-system/src/validate_block/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,39 @@ fn rejects_multiple_blocks_per_pov_when_applying_runtime_upgrade() {
.contains("only one block per PoV is allowed"));
}
}

#[test]
fn validate_block_rejects_huge_header_single_block() {
sp_tracing::try_init_simple();

if env::var("RUN_TEST").is_ok() {
let (client, parent_head) = create_test_client();

let digest_data_exceeding_max_head_data_size =
vec![0u8; relay_chain::MAX_HEAD_DATA_SIZE as usize + 1];
let pre_digests =
vec![DigestItem::PreRuntime(*b"TEST", digest_data_exceeding_max_head_data_size)];

let TestBlockData { block, validation_data } = build_block_with_witness(
&client,
Vec::new(),
parent_head.clone(),
Default::default(),
pre_digests,
);

call_validate_block(parent_head, block, validation_data.relay_parent_storage_root)
.unwrap_err();
} else {
let output = Command::new(env::current_exe().unwrap())
.args(["validate_block_rejects_huge_header_single_block", "--", "--nocapture"])
.env("RUN_TEST", "1")
.output()
.expect("Runs the test");
assert!(output.status.success());

assert!(
dbg!(String::from_utf8(output.stderr).unwrap()).contains("exceeds MAX_HEAD_DATA_SIZE")
);
}
}
6 changes: 3 additions & 3 deletions cumulus/pallets/weight-reclaim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,16 @@ where
// If we encounter a situation where the node-side proof size is already higher than
// what we have in the runtime bookkeeping, we add the difference to the `BlockWeight`.
// This prevents that the proof size grows faster than the runtime proof size.
let extrinsic_len = frame_system::AllExtrinsicsLen::<T>::get().unwrap_or(0);
let node_side_pov_size = proof_size_after_dispatch.saturating_add(extrinsic_len.into());
let block_size = frame_system::BlockSize::<T>::get().unwrap_or(0);
let node_side_pov_size = proof_size_after_dispatch.saturating_add(block_size.into());
let block_weight_proof_size = current_weight.total().proof_size();
let pov_size_missing_from_node =
node_side_pov_size.saturating_sub(block_weight_proof_size);
if pov_size_missing_from_node > 0 {
log::warn!(
target: LOG_TARGET,
"Node-side PoV size higher than runtime proof size weight. node-side: \
{node_side_pov_size} extrinsic_len: {extrinsic_len} runtime: \
{node_side_pov_size} block_size: {block_size} runtime: \
{block_weight_proof_size}, missing: {pov_size_missing_from_node}. Setting to \
node-side proof size."
);
Expand Down
4 changes: 3 additions & 1 deletion cumulus/parachains/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ mod tests {
);

parameter_types! {
pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024);
pub BlockLength: limits::BlockLength = limits::BlockLength::builder()
.max_length(2 * 1024)
.build();
pub const AvailableBlockRatio: Perbill = Perbill::one();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ pub fn native_version() -> NativeVersion {

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockLength: BlockLength = BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,12 @@ pub fn native_version() -> NativeVersion {

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockLength: BlockLength = BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,12 @@ pub fn native_version() -> NativeVersion {

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockLength: BlockLength = BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ pub fn native_version() -> NativeVersion {
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| { *m = NORMAL_DISPATCH_RATIO * *m; })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you also reuse m on the other places where you copied and pasted the max length?

.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ pub type RootOrAllianceTwoThirdsMajority = EitherOfDiverse<

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockLength: BlockLength = BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ pub fn native_version() -> NativeVersion {

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockLength: BlockLength = BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ pub fn native_version() -> NativeVersion {

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockLength: BlockLength = BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
parameter_types! {
pub const BlockHashCount: BlockNumber = 4096;
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockLength: BlockLength = BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
8 changes: 6 additions & 2 deletions cumulus/parachains/runtimes/people/people-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ pub fn native_version() -> NativeVersion {

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockLength: BlockLength = BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
8 changes: 6 additions & 2 deletions cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,12 @@ parameter_types! {
// The `RuntimeBlockLength` and `RuntimeBlockWeights` exist here because the
// `DeletionWeightLimit` and `DeletionQueueDepth` depend on those to parameterize
// the lazy contract deletion.
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockLength: BlockLength = BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000;
parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub RuntimeBlockLength: BlockLength = BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
6 changes: 3 additions & 3 deletions cumulus/primitives/storage-weight-reclaim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ where

let storage_size_diff = benchmarked_weight.abs_diff(consumed_weight as u64);

let extrinsic_len = frame_system::AllExtrinsicsLen::<T>::get().unwrap_or(0);
let node_side_pov_size = post_dispatch_proof_size.saturating_add(extrinsic_len.into());
let block_size = frame_system::BlockSize::<T>::get().unwrap_or(0);
let node_side_pov_size = post_dispatch_proof_size.saturating_add(block_size.into());

// This value will be reclaimed by [`frame_system::CheckWeight`], so we need to calculate
// that in.
Expand Down Expand Up @@ -217,7 +217,7 @@ where
if missing_from_node > 0 {
log::debug!(
target: LOG_TARGET,
"Node-side PoV size higher than runtime proof size weight. node-side: {node_side_pov_size} extrinsic_len: {extrinsic_len} runtime: {block_weight_proof_size}, missing: {missing_from_node}. Setting to node-side proof size."
"Node-side PoV size higher than runtime proof size weight. node-side: {node_side_pov_size} block_size: {block_size} runtime: {block_weight_proof_size}, missing: {missing_from_node}. Setting to node-side proof size."
);
current.accrue(Weight::from_parts(0, missing_from_node), info.class);
}
Expand Down
2 changes: 1 addition & 1 deletion cumulus/test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ parameter_types! {
pub const BlockHashCount: BlockNumber = 250;
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
BlockLength::builder().max_length(10 * 1024 * 1024).max_header_size(5 * 1024 * 1024).build();
pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
Expand Down
4 changes: 3 additions & 1 deletion polkadot/runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ mod tests {
weight.max_total = Some(Weight::from_parts(1024, u64::MAX));
})
.build_or_panic();
pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024);
pub BlockLength: limits::BlockLength = limits::BlockLength::builder()
.max_length(2 * 1024)
.build();
pub const AvailableBlockRatio: Perbill = Perbill::one();
}

Expand Down
8 changes: 6 additions & 2 deletions polkadot/runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ parameter_types! {
/// The maximum amount of the multiplier.
pub MaximumMultiplier: Multiplier = Bounded::max_value();
/// Maximum length of block. Up to 5MB.
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub BlockLength: limits::BlockLength = limits::BlockLength::builder()
.max_length(5 * 1024 * 1024)
.modify_max_length_for_class(frame_support::dispatch::DispatchClass::Normal, |m| {
*m = NORMAL_DISPATCH_RATIO * *m
})
.build();
}

/// Parameterized slow adjusting fee updated based on
Expand Down
9 changes: 7 additions & 2 deletions polkadot/runtime/common/src/paras_registrar/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ where
}

const NORMAL_RATIO: Perbill = Perbill::from_percent(75);
const MAX_BLOCK_LENGTH: u32 = 4 * 1024 * 1024;
parameter_types! {
pub BlockWeights: limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, u64::MAX));
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(4 * 1024 * 1024, NORMAL_RATIO);
pub BlockLength: limits::BlockLength = limits::BlockLength::builder()
.max_length(MAX_BLOCK_LENGTH)
.modify_max_length_for_class(frame_support::dispatch::DispatchClass::Normal, |m| {
*m = NORMAL_RATIO * MAX_BLOCK_LENGTH
})
.build();
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
Expand Down
7 changes: 6 additions & 1 deletion polkadot/runtime/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(
Weight::from_parts(4 * 1024 * 1024, u64::MAX),
);
pub static BlockLength: limits::BlockLength = limits::BlockLength::max_with_normal_ratio(u32::MAX, Perbill::from_percent(75));
pub static BlockLength: limits::BlockLength = limits::BlockLength::builder()
.max_length(u32::MAX)
.modify_max_length_for_class(frame_support::dispatch::DispatchClass::Normal, |m| {
*m = Perbill::from_percent(75) * u32::MAX
})
.build();
}

pub type AccountId = u64;
Expand Down
Loading