mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
collation-generation: Support compressed PoVs directly (#4825)
This adds support for returning a compressed PoV directly to the collation generation. This is mainly to not requiring to compress a PoV twice.
This commit is contained in:
@@ -309,9 +309,7 @@ async fn handle_new_activations<Context: SubsystemContext>(
|
||||
|
||||
// Apply compression to the block data.
|
||||
let pov = {
|
||||
let pov = polkadot_node_primitives::maybe_compress_pov(
|
||||
collation.proof_of_validity,
|
||||
);
|
||||
let pov = collation.proof_of_validity.into_compressed();
|
||||
let encoded_size = pov.encoded_size();
|
||||
|
||||
// As long as `POV_BOMB_LIMIT` is at least `max_pov_size`, this ensures
|
||||
|
||||
@@ -22,7 +22,9 @@ mod handle_new_activations {
|
||||
task::{Context as FuturesContext, Poll},
|
||||
Future,
|
||||
};
|
||||
use polkadot_node_primitives::{BlockData, Collation, CollationResult, PoV, POV_BOMB_LIMIT};
|
||||
use polkadot_node_primitives::{
|
||||
BlockData, Collation, CollationResult, MaybeCompressedPoV, PoV,
|
||||
};
|
||||
use polkadot_node_subsystem::{
|
||||
errors::RuntimeApiError,
|
||||
messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest},
|
||||
@@ -41,7 +43,7 @@ mod handle_new_activations {
|
||||
horizontal_messages: vec![],
|
||||
new_validation_code: None,
|
||||
head_data: dummy_head_data(),
|
||||
proof_of_validity: PoV { block_data: BlockData(Vec::new()) },
|
||||
proof_of_validity: MaybeCompressedPoV::Raw(PoV { block_data: BlockData(Vec::new()) }),
|
||||
processed_downward_messages: 0_u32,
|
||||
hrmp_watermark: 0_u32.into(),
|
||||
}
|
||||
@@ -49,16 +51,8 @@ mod handle_new_activations {
|
||||
|
||||
fn test_collation_compressed() -> Collation {
|
||||
let mut collation = test_collation();
|
||||
let compressed = PoV {
|
||||
block_data: BlockData(
|
||||
sp_maybe_compressed_blob::compress(
|
||||
&collation.proof_of_validity.block_data.0,
|
||||
POV_BOMB_LIMIT,
|
||||
)
|
||||
.unwrap(),
|
||||
),
|
||||
};
|
||||
collation.proof_of_validity = compressed;
|
||||
let compressed = collation.proof_of_validity.clone().into_compressed();
|
||||
collation.proof_of_validity = MaybeCompressedPoV::Compressed(compressed);
|
||||
collation
|
||||
}
|
||||
|
||||
@@ -309,7 +303,8 @@ mod handle_new_activations {
|
||||
// we expect a single message to be sent, containing a candidate receipt.
|
||||
// we don't care too much about the `commitments_hash` right now, but let's ensure that we've calculated the
|
||||
// correct descriptor
|
||||
let expect_pov_hash = test_collation_compressed().proof_of_validity.hash();
|
||||
let expect_pov_hash =
|
||||
test_collation_compressed().proof_of_validity.into_compressed().hash();
|
||||
let expect_validation_data_hash = test_validation_data().hash();
|
||||
let expect_relay_parent = Hash::repeat_byte(4);
|
||||
let expect_validation_code_hash = ValidationCode(vec![1, 2, 3]).hash();
|
||||
|
||||
@@ -257,6 +257,29 @@ impl PoV {
|
||||
}
|
||||
}
|
||||
|
||||
/// A type that represents a maybe compressed [`PoV`].
|
||||
#[derive(Clone, Encode, Decode)]
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
pub enum MaybeCompressedPoV {
|
||||
/// A raw [`PoV`], aka not compressed.
|
||||
Raw(PoV),
|
||||
/// The given [`PoV`] is already compressed.
|
||||
Compressed(PoV),
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
impl MaybeCompressedPoV {
|
||||
/// Convert into a compressed [`PoV`].
|
||||
///
|
||||
/// If `self == Raw` it is compressed using [`maybe_compress_pov`].
|
||||
pub fn into_compressed(self) -> PoV {
|
||||
match self {
|
||||
Self::Raw(raw) => maybe_compress_pov(raw),
|
||||
Self::Compressed(compressed) => compressed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The output of a collator.
|
||||
///
|
||||
/// This differs from `CandidateCommitments` in two ways:
|
||||
@@ -264,6 +287,7 @@ impl PoV {
|
||||
/// - does not contain the erasure root; that's computed at the Polkadot level, not at Cumulus
|
||||
/// - contains a proof of validity.
|
||||
#[derive(Clone, Encode, Decode)]
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
pub struct Collation<BlockNumber = polkadot_primitives::v1::BlockNumber> {
|
||||
/// Messages destined to be interpreted by the Relay chain itself.
|
||||
pub upward_messages: Vec<UpwardMessage>,
|
||||
@@ -274,7 +298,7 @@ pub struct Collation<BlockNumber = polkadot_primitives::v1::BlockNumber> {
|
||||
/// The head-data produced as a result of execution.
|
||||
pub head_data: HeadData,
|
||||
/// Proof to verify the state transition of the parachain.
|
||||
pub proof_of_validity: PoV,
|
||||
pub proof_of_validity: MaybeCompressedPoV,
|
||||
/// The number of messages processed from the DMQ.
|
||||
pub processed_downward_messages: u32,
|
||||
/// The mark which specifies the block number up to which all inbound HRMP messages are processed.
|
||||
@@ -283,6 +307,7 @@ pub struct Collation<BlockNumber = polkadot_primitives::v1::BlockNumber> {
|
||||
|
||||
/// Signal that is being returned when a collation was seconded by a validator.
|
||||
#[derive(Debug)]
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
pub struct CollationSecondedSignal {
|
||||
/// The hash of the relay chain block that was used as context to sign [`Self::statement`].
|
||||
pub relay_parent: Hash,
|
||||
@@ -293,6 +318,7 @@ pub struct CollationSecondedSignal {
|
||||
}
|
||||
|
||||
/// Result of the [`CollatorFn`] invocation.
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
pub struct CollationResult {
|
||||
/// The collation that was build.
|
||||
pub collation: Collation,
|
||||
@@ -304,6 +330,7 @@ pub struct CollationResult {
|
||||
pub result_sender: Option<futures::channel::oneshot::Sender<CollationSecondedSignal>>,
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
impl CollationResult {
|
||||
/// Convert into the inner values.
|
||||
pub fn into_inner(
|
||||
@@ -319,6 +346,7 @@ impl CollationResult {
|
||||
/// [`ValidationData`] that provides information about the state of the parachain on the relay chain.
|
||||
///
|
||||
/// Returns an optional [`CollationResult`].
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
pub type CollatorFn = Box<
|
||||
dyn Fn(
|
||||
Hash,
|
||||
@@ -329,6 +357,7 @@ pub type CollatorFn = Box<
|
||||
>;
|
||||
|
||||
/// Configuration for the collation generator
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
pub struct CollationGenerationConfig {
|
||||
/// Collator's authentication key, so it can sign things.
|
||||
pub key: CollatorPair,
|
||||
@@ -338,6 +367,7 @@ pub struct CollationGenerationConfig {
|
||||
pub para_id: ParaId,
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
impl std::fmt::Debug for CollationGenerationConfig {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "CollationGenerationConfig {{ ... }}")
|
||||
@@ -371,8 +401,8 @@ impl Proof {
|
||||
}
|
||||
}
|
||||
|
||||
/// Possible errors when converting from `Vec<Vec<u8>>` into [`Proof`].
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
///
|
||||
pub enum MerkleProofError {
|
||||
#[error("Merkle max proof depth exceeded {0} > {} .", MERKLE_PROOF_MAX_DEPTH)]
|
||||
/// This error signifies that the Proof length exceeds the trie's max depth
|
||||
|
||||
@@ -20,7 +20,8 @@ use futures::channel::oneshot;
|
||||
use futures_timer::Delay;
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use polkadot_node_primitives::{
|
||||
Collation, CollationResult, CollationSecondedSignal, CollatorFn, PoV, Statement,
|
||||
Collation, CollationResult, CollationSecondedSignal, CollatorFn, MaybeCompressedPoV, PoV,
|
||||
Statement,
|
||||
};
|
||||
use polkadot_primitives::v1::{CollatorId, CollatorPair};
|
||||
use sp_core::{traits::SpawnNamed, Pair};
|
||||
@@ -175,7 +176,7 @@ impl Collator {
|
||||
horizontal_messages: Vec::new(),
|
||||
new_validation_code: None,
|
||||
head_data: head_data.encode().into(),
|
||||
proof_of_validity: pov.clone(),
|
||||
proof_of_validity: MaybeCompressedPoV::Raw(pov.clone()),
|
||||
processed_downward_messages: 0,
|
||||
hrmp_watermark: validation_data.relay_parent_number,
|
||||
};
|
||||
@@ -273,11 +274,16 @@ mod tests {
|
||||
fn validate_collation(collator: &Collator, parent_head: HeadData, collation: Collation) {
|
||||
use polkadot_node_core_pvf::testing::validate_candidate;
|
||||
|
||||
let block_data = match collation.proof_of_validity {
|
||||
MaybeCompressedPoV::Raw(pov) => pov.block_data,
|
||||
MaybeCompressedPoV::Compressed(_) => panic!("Only works with uncompressed povs"),
|
||||
};
|
||||
|
||||
let ret_buf = validate_candidate(
|
||||
collator.validation_code(),
|
||||
&ValidationParams {
|
||||
parent_head: parent_head.encode().into(),
|
||||
block_data: collation.proof_of_validity.block_data,
|
||||
block_data,
|
||||
relay_parent_number: 1,
|
||||
relay_parent_storage_root: Default::default(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user