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

Support code blobs compressed with zstd #8549

Merged
16 commits merged into from
Apr 7, 2021
Merged

Support code blobs compressed with zstd #8549

16 commits merged into from
Apr 7, 2021

Conversation

rphmeier
Copy link
Contributor

@rphmeier rphmeier commented Apr 6, 2021

If the Wasm blob begins with a magic prefix, the code will be decompressed with zstd. This will be useful when sending Wasm blobs over the network or through XCM.

The use-case in particular is Statemint or other system parachains. The relay-chain needs to send a code blob over XCM which the Statemint parachain will then apply.

@rphmeier rphmeier added A3-in_progress Pull request is in progress. No review needed at this stage. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Apr 6, 2021
@rphmeier rphmeier added B5-clientnoteworthy and removed B0-silent Changes should not be mentioned in any release notes labels Apr 6, 2021
@rphmeier rphmeier marked this pull request as ready for review April 6, 2021 20:27
@github-actions github-actions bot added A0-please_review Pull request needs code review. A7-needspolkadotpr and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Apr 6, 2021
@rphmeier
Copy link
Contributor Author

rphmeier commented Apr 6, 2021

Why does it need a Polkadot PR?

@rphmeier
Copy link
Contributor Author

rphmeier commented Apr 6, 2021

Tested upgrade to compressed wasm on a --dev chain

Copy link
Contributor

@seunlanlege seunlanlege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks sane

@seunlanlege
Copy link
Contributor

curious though, how much size reduction can we get with zstd compression on wasm blobs?

use std::io::Write;

if blob.len() > bomb_limit {
return None;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return an error here. Otherwise we could drop bomb_limit directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the semantic of an error is different? The function is documented as returning None if the size exceeds the bomb limit.

.expect("Failed to write WASM binary");
} else {
println!(
"Writing uncompressed wasm. Exceeded maximum size {}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we write this?

If the compression fails, no file will exist, but you continue and assume the file exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would be the best place to log an error?

Comment on lines 286 to 288
const WASM_CODE_BOMB_LIMIT: usize = 50 * 1024 * 1024;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const WASM_CODE_BOMB_LIMIT: usize = 50 * 1024 * 1024;

Please move the constant out of this function and add some docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why do we allow 100MB in the wasm builder and only 50 mb here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should put the constant into the sp_maybe_compressed crate to use every the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to have the constant closer to the usage. Initially I did have it in the crate, but then we started to talk about using the crate for PoVs as well. Those will want different max sizes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we already got two constants with different values, in one pr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a CODE_SIZE_BOMB_LIMIT to the crate, but users will pass it through

@rphmeier
Copy link
Contributor Author

rphmeier commented Apr 7, 2021

@seunlanlege

curious though, how much size reduction can we get with zstd compression on wasm blobs?

It's about 3x for node-runtime. It goes from 2.2MB to 750KB

Co-authored-by: Andronik Ordian <write@reusable.software>
@rphmeier
Copy link
Contributor Author

rphmeier commented Apr 7, 2021

bot merge

@ghost
Copy link

ghost commented Apr 7, 2021

Waiting for commit status.

@ghost ghost merged commit 6c5b63a into master Apr 7, 2021
@ghost ghost deleted the rh-compressed-code branch April 7, 2021 20:44
hirschenberger pushed a commit to hirschenberger/substrate that referenced this pull request Apr 14, 2021
* begin maybe-compressed-blob

* fix build

* implement blob compression / decompression

* add some tests

* decode -> decompress

* decompress code if compressed

* make API of compresseed blob crate take limit as parameter

* use new API in sc-executro

* wasm-builder: compress wasm

* fix typo

* simplify

* address review

* fix wasm_project.rs

* Update primitives/maybe-compressed-blob/Cargo.toml

Co-authored-by: Andronik Ordian <write@reusable.software>

Co-authored-by: Andronik Ordian <write@reusable.software>
@cwerling cwerling added D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited and removed D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels May 11, 2021
jordy25519 pushed a commit to cennznet/substrate that referenced this pull request Sep 20, 2021
* begin maybe-compressed-blob

* fix build

* implement blob compression / decompression

* add some tests

* decode -> decompress

* decompress code if compressed

* make API of compresseed blob crate take limit as parameter

* use new API in sc-executro

* wasm-builder: compress wasm

* fix typo

* simplify

* address review

* fix wasm_project.rs

* Update primitives/maybe-compressed-blob/Cargo.toml

Co-authored-by: Andronik Ordian <write@reusable.software>

Co-authored-by: Andronik Ordian <write@reusable.software>
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants