mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 18:41:05 +00:00
Use a BoundedVec in ValidationResult (#6603)
* Use a `BoundedVec` in `ValidationResult` > Use a `BoundedVec` for `upward_messages` and `horizontal_messages` in order to > limit the number of individual messages/memory allocations right at decoding > time. The reason for this is that the `ValidationResult` may contain a code > upgrade (including a full PVF binary), so the total size limit can't be set > too low and this limit will still allow several millions of upward messages, > which will (due to the memory allocator overhead) already have a > non-negligible memory footprint in decoded form. * List all fields when hashing so we don't miss one * Define types for `BoundedVec`s of messages * Fix test compile errors * Depend on `bounded-collections` 0.1.4 (fixes allocation issue) * Fix compilation issue * Derive `Hash` instead of manual `impl` * Avoid use of unwrap
This commit is contained in:
@@ -39,8 +39,8 @@ mod handle_new_activations {
|
||||
|
||||
fn test_collation() -> Collation {
|
||||
Collation {
|
||||
upward_messages: vec![],
|
||||
horizontal_messages: vec![],
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
new_validation_code: None,
|
||||
head_data: dummy_head_data(),
|
||||
proof_of_validity: MaybeCompressedPoV::Raw(PoV { block_data: BlockData(Vec::new()) }),
|
||||
|
||||
@@ -202,8 +202,8 @@ impl TestCandidateBuilder {
|
||||
},
|
||||
commitments: CandidateCommitments {
|
||||
head_data: self.head_data,
|
||||
upward_messages: vec![],
|
||||
horizontal_messages: vec![],
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
new_validation_code: None,
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 0_u32,
|
||||
@@ -311,8 +311,8 @@ fn backing_second_works() {
|
||||
tx.send(Ok(
|
||||
ValidationResult::Valid(CandidateCommitments {
|
||||
head_data: expected_head_data.clone(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Default::default(),
|
||||
upward_messages: Default::default(),
|
||||
new_validation_code: None,
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 0,
|
||||
@@ -457,8 +457,8 @@ fn backing_works() {
|
||||
tx.send(Ok(
|
||||
ValidationResult::Valid(CandidateCommitments {
|
||||
head_data: expected_head_data.clone(),
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
new_validation_code: None,
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 0,
|
||||
@@ -781,8 +781,8 @@ fn backing_misbehavior_works() {
|
||||
tx.send(Ok(
|
||||
ValidationResult::Valid(CandidateCommitments {
|
||||
head_data: expected_head_data.clone(),
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
new_validation_code: None,
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 0,
|
||||
@@ -954,8 +954,8 @@ fn backing_dont_second_invalid() {
|
||||
tx.send(Ok(
|
||||
ValidationResult::Valid(CandidateCommitments {
|
||||
head_data: expected_head_data.clone(),
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
new_validation_code: None,
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 0,
|
||||
|
||||
@@ -446,8 +446,8 @@ fn candidate_validation_ok_is_ok() {
|
||||
let validation_result = WasmValidationResult {
|
||||
head_data,
|
||||
new_validation_code: Some(vec![2, 2, 2].into()),
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 0,
|
||||
};
|
||||
@@ -573,8 +573,8 @@ fn candidate_validation_one_ambiguous_error_is_valid() {
|
||||
let validation_result = WasmValidationResult {
|
||||
head_data,
|
||||
new_validation_code: Some(vec![2, 2, 2].into()),
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 0,
|
||||
};
|
||||
@@ -751,8 +751,8 @@ fn candidate_validation_commitment_hash_mismatch_is_invalid() {
|
||||
let validation_result = WasmValidationResult {
|
||||
head_data,
|
||||
new_validation_code: None,
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 12345,
|
||||
};
|
||||
@@ -854,8 +854,8 @@ fn compressed_code_works() {
|
||||
let validation_result = WasmValidationResult {
|
||||
head_data,
|
||||
new_validation_code: None,
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 0,
|
||||
};
|
||||
@@ -918,8 +918,8 @@ fn code_decompression_failure_is_error() {
|
||||
let validation_result = WasmValidationResult {
|
||||
head_data,
|
||||
new_validation_code: None,
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 0,
|
||||
};
|
||||
@@ -971,8 +971,8 @@ fn pov_decompression_failure_is_invalid() {
|
||||
let validation_result = WasmValidationResult {
|
||||
head_data,
|
||||
new_validation_code: None,
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: 0,
|
||||
};
|
||||
|
||||
@@ -163,8 +163,8 @@ pub fn create_fake_candidate_commitments(
|
||||
persisted_validation_data: &PersistedValidationData,
|
||||
) -> CandidateCommitments {
|
||||
CandidateCommitments {
|
||||
upward_messages: Vec::new(),
|
||||
horizontal_messages: Vec::new(),
|
||||
upward_messages: Default::default(),
|
||||
horizontal_messages: Default::default(),
|
||||
new_validation_code: None,
|
||||
head_data: persisted_validation_data.parent_head.clone(),
|
||||
processed_downward_messages: 0,
|
||||
|
||||
@@ -16,6 +16,7 @@ sp-consensus-vrf = { git = "https://github.com/paritytech/substrate", branch = "
|
||||
sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-maybe-compressed-blob = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
polkadot-parachain = { path = "../../parachain", default-features = false }
|
||||
schnorrkel = "0.9.1"
|
||||
thiserror = "1.0.31"
|
||||
|
||||
@@ -32,14 +32,14 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use polkadot_primitives::{
|
||||
BlakeTwo256, BlockNumber, CandidateCommitments, CandidateHash, CollatorPair,
|
||||
CommittedCandidateReceipt, CompactStatement, EncodeAs, Hash, HashT, HeadData, Id as ParaId,
|
||||
OutboundHrmpMessage, PersistedValidationData, SessionIndex, Signed, UncheckedSigned,
|
||||
UpwardMessage, ValidationCode, ValidatorIndex, MAX_CODE_SIZE, MAX_POV_SIZE,
|
||||
PersistedValidationData, SessionIndex, Signed, UncheckedSigned, ValidationCode, ValidatorIndex,
|
||||
MAX_CODE_SIZE, MAX_POV_SIZE,
|
||||
};
|
||||
pub use sp_consensus_babe::{
|
||||
AllowedSlots as BabeAllowedSlots, BabeEpochConfiguration, Epoch as BabeEpoch,
|
||||
};
|
||||
|
||||
pub use polkadot_parachain::primitives::BlockData;
|
||||
pub use polkadot_parachain::primitives::{BlockData, HorizontalMessages, UpwardMessages};
|
||||
|
||||
pub mod approval;
|
||||
|
||||
@@ -312,9 +312,9 @@ impl MaybeCompressedPoV {
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
pub struct Collation<BlockNumber = polkadot_primitives::BlockNumber> {
|
||||
/// Messages destined to be interpreted by the Relay chain itself.
|
||||
pub upward_messages: Vec<UpwardMessage>,
|
||||
pub upward_messages: UpwardMessages,
|
||||
/// The horizontal messages sent by the parachain.
|
||||
pub horizontal_messages: Vec<OutboundHrmpMessage<ParaId>>,
|
||||
pub horizontal_messages: HorizontalMessages,
|
||||
/// New validation code.
|
||||
pub new_validation_code: Option<ValidationCode>,
|
||||
/// The head-data produced as a result of execution.
|
||||
|
||||
Reference in New Issue
Block a user