-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: compress state witness (#10715)
This PR adds state witness compression as well as metrics around it. See #10780 for the big picture analysis. We explicitly limit the size of the decompressed state witness to 64MB to handle [Zip bomb](https://en.wikipedia.org/wiki/Zip_bomb) attack. This is implemented by using `BufMut` and `Limit` along with `zstd::stream::copy_decode`, so it fails when attempting to write data beyond the limit. Compression reduces state witness size particularly well for large state witnesses (containing many `ContractCode` values), which makes it worthwhile. For cases when compression doesn't yield much improvements the latency overhead is not significant. In practice shadow validation was used to verify the statements above with the current mainnet traffic: * overall traffic reduction ([dashboard](https://nearinc.grafana.net/d/a41c3c5e-4c1b-41fc-919c-11040e9cfc13/shadow-chunk-validation?orgId=1&from=now-6h&to=now&viewPanel=32)) is about 16% which is not great. That makes sense considering that after resharding to 6 shards the size of state witnesses per shard dropped significantly which makes compression less effective. * max state witness size ([uncompressed](https://nearinc.grafana.net/d/a41c3c5e-4c1b-41fc-919c-11040e9cfc13/shadow-chunk-validation?orgId=1&from=now-12h&to=now&viewPanel=33) and [compressed](https://nearinc.grafana.net/d/a41c3c5e-4c1b-41fc-919c-11040e9cfc13/shadow-chunk-validation?orgId=1&from=now-12h&to=now&viewPanel=1) dashboards) reduced a lot for large state witnesses. We didn't observe any witnesses larger than 2.5MB in compressed state while uncompressed ones were as big as 6.6MB. * additional latency ([avg](https://nearinc.grafana.net/d/a41c3c5e-4c1b-41fc-919c-11040e9cfc13/shadow-chunk-validation?orgId=1&from=now-6h&to=now&viewPanel=34) and [distribution](https://nearinc.grafana.net/d/a41c3c5e-4c1b-41fc-919c-11040e9cfc13/shadow-chunk-validation?orgId=1&from=now-6h&to=now&viewPanel=11) dashboards) is mostly comes from encoding and is in a 10-20ms range for the most busy shard 2. This PR also includes the following changes: - reduce state witness size histogram step - bump `actix-http` version to avoid bringing multiple version of `zstd` dependency ([zulip thread](https://near.zulipchat.com/#narrow/stream/300659-Rust-.F0.9F.A6.80/topic/Transitive.20dependency.20conflict))
- Loading branch information
Showing
12 changed files
with
203 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.