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:
Bastian Köcher
2022-02-07 20:14:08 +01:00
committed by GitHub
parent 59cddb9f23
commit bb69c82cc5
4 changed files with 50 additions and 21 deletions
+32 -2
View File
@@ -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