Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Polkadot companion #6603: Use a BoundedVec in ValidationResult #2161

Merged
Merged
Show file tree
Hide file tree
Changes from 8 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
27 changes: 25 additions & 2 deletions client/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,34 @@ where
.ok()
.flatten()?;

let upward_messages = collation_info
.upward_messages
.try_into()
.map_err(|e| {
tracing::error!(
target: LOG_TARGET,
error = ?e,
"Number of upward messages should not be greater than `MAX_UPWARD_MESSAGE_NUM`",
)
})
.ok()?;
let horizontal_messages = collation_info
.horizontal_messages
.try_into()
.map_err(|e| {
tracing::error!(
target: LOG_TARGET,
error = ?e,
"Number of horizontal messages should not be greater than `MAX_HORIZONTAL_MESSAGE_NUM`",
)
})
.ok()?;

Some(Collation {
upward_messages: collation_info.upward_messages,
upward_messages,
new_validation_code: collation_info.new_validation_code,
processed_downward_messages: collation_info.processed_downward_messages,
horizontal_messages: collation_info.horizontal_messages,
horizontal_messages,
hrmp_watermark: collation_info.hrmp_watermark,
head_data: collation_info.head_data,
proof_of_validity: MaybeCompressedPoV::Compressed(pov),
Expand Down
4 changes: 2 additions & 2 deletions client/network/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ impl RelayChainInterface for DummyRelayChainInterface {
validation_code_hash: ValidationCodeHash::from(PHash::random()),
},
commitments: CandidateCommitments {
upward_messages: Vec::new(),
horizontal_messages: Vec::new(),
upward_messages: Default::default(),
horizontal_messages: Default::default(),
new_validation_code: None,
head_data: HeadData(Vec::new()),
processed_downward_messages: 0,
Expand Down
12 changes: 8 additions & 4 deletions pallets/parachain-system/src/validate_block/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ use polkadot_parachain::primitives::{
HeadData, RelayChainBlockNumber, ValidationParams, ValidationResult,
};

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

use frame_support::traits::{ExecuteBlock, ExtrinsicCall, Get, IsSubType};
use sp_core::storage::{ChildInfo, StateVersion};
use sp_externalities::{set_and_run_with_externalities, Externalities};
use sp_io::KillStorageResult;
use sp_runtime::traits::{Block as BlockT, Extrinsic, HashFor, Header as HeaderT};
use sp_std::{mem, prelude::*};
use sp_std::prelude::*;
use sp_trie::MemoryDB;

type TrieBackend<B> = sp_state_machine::TrieBackend<MemoryDB<HashFor<B>>, HashFor<B>>;
Expand Down Expand Up @@ -187,9 +187,13 @@ where
E::execute_block(block);

let new_validation_code = crate::NewValidationCode::<PSC>::get();
let upward_messages = crate::UpwardMessages::<PSC>::get();
let upward_messages = crate::UpwardMessages::<PSC>::get().try_into().expect(
"Number of upward messages should not be greater than `MAX_UPWARD_MESSAGE_NUM`",
);
let processed_downward_messages = crate::ProcessedDownwardMessages::<PSC>::get();
let horizontal_messages = crate::HrmpOutboundMessages::<PSC>::get();
let horizontal_messages = crate::HrmpOutboundMessages::<PSC>::get().try_into().expect(
"Number of horizontal messages should not be greater than `MAX_HORIZONTAL_MESSAGE_NUM`",
);
let hrmp_watermark = crate::HrmpWatermark::<PSC>::get();

let head_data =
Expand Down