Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Cleanup.
  • Loading branch information
eskimor committed Mar 14, 2021
commit c304e9af85e0cacc3ce9951044659ebc9bd84409
2 changes: 1 addition & 1 deletion node/network/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Network protocol types for parachains.

#![deny(unused_crate_dependencies)]
#![warn(missing_docs, unused_imports)]
#![warn(missing_docs)]

use polkadot_primitives::v1::{Hash, BlockNumber};
use parity_scale_codec::{Encode, Decode};
Expand Down
3 changes: 0 additions & 3 deletions node/network/protocol/src/request_response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ impl Protocol {
let cfg = match self {
Protocol::AvailabilityFetching => RequestResponseConfig {
name: p_name,
// Arbitrary very conservative numbers:
// TODO: Get better numbers, see https://github.com/paritytech/polkadot/issues/2370
max_request_size: 1_000,
max_response_size: 100_000,
// Also just some relative conservative guess:
request_timeout: DEFAULT_REQUEST_TIMEOUT,
inbound_queue: Some(tx),
},
Expand Down
4 changes: 2 additions & 2 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "mast
hex-literal = "0.3.1"
parity-util-mem = { version = "0.9.0", default-features = false, optional = true }
thiserror = "1.0.23"
[target.'cfg(not(target_os = "unknown"))'.dependencies]
zstd = "0.5.0"
zstd = { version = "0.5.0", optional = true }

[dev-dependencies]
sp-serializer = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down Expand Up @@ -57,4 +56,5 @@ std = [
"polkadot-core-primitives/std",
"bitvec/std",
"frame-system/std",
"zstd"
]
15 changes: 7 additions & 8 deletions primitives/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,10 @@ impl PoV {

/// SCALE and Zstd encoded [`PoV`].
#[derive(Clone, Encode, Decode, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct CompressedPoV(Vec<u8>);

#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[cfg(not(target_os = "unknown"))]
#[cfg(feature = "std")]
#[allow(missing_docs)]
pub enum CompressedPoVError {
#[error("Failed to compress a PoV")]
Expand All @@ -473,22 +472,22 @@ pub enum CompressedPoVError {
NotSupported,
}

#[cfg(not(target_os = "unknown"))]
#[cfg(feature = "std")]
impl CompressedPoV {
/// Compress the given [`PoV`] and returns a [`CompressedPoV`].
#[cfg(not(target_os = "unknown"))]
#[cfg(feature = "std")]
pub fn compress(pov: &PoV) -> Result<Self, CompressedPoVError> {
zstd::encode_all(pov.encode().as_slice(), 3).map_err(|_| CompressedPoVError::Compress).map(Self)
}

/// Compress the given [`PoV`] and returns a [`CompressedPoV`].
#[cfg(target_os = "unknown")]
#[cfg(not(feature = "std"))]
pub fn compress(_: &PoV) -> Result<Self, CompressedPoVError> {
Err(CompressedPoVError::NotSupported)
}

/// Decompress `self` and returns the [`PoV`] on success.
#[cfg(not(target_os = "unknown"))]
#[cfg(feature = "std")]
pub fn decompress(&self) -> Result<PoV, CompressedPoVError> {
use std::io::Read;
const MAX_POV_BLOCK_SIZE: usize = 32 * 1024 * 1024;
Expand All @@ -512,13 +511,13 @@ impl CompressedPoV {
}

/// Decompress `self` and returns the [`PoV`] on success.
#[cfg(target_os = "unknown")]
#[cfg(not(feature = "std"))]
pub fn decompress(&self) -> Result<PoV, CompressedPoVError> {
Err(CompressedPoVError::NotSupported)
}
}

#[cfg(not(target_os = "unknown"))]
#[cfg(feature = "std")]
impl std::fmt::Debug for CompressedPoV {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "CompressedPoV({} bytes)", self.0.len())
Expand Down