Skip to content

Estimate compression ratio at rollupFee for Feynman #1197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: l1data-to-rollupfee
Choose a base branch
from

Conversation

ranchalp
Copy link

@ranchalp ranchalp commented Jun 9, 2025

1. Purpose or design rationale of this PR

See #1196 for more.

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • build: Changes that affect the build system or external dependencies (example scopes: yarn, eslint, typescript)
  • ci: Changes to our CI configuration files and scripts (example scopes: vercel, github, cypress)
  • docs: Documentation-only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that doesn't fix a bug, or add a feature, or improves performance
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

Copy link

coderabbitai bot commented Jun 9, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ranchalp ranchalp force-pushed the rollupfee-estimate-compression branch from 9d4f5bc to 4c1dc4d Compare June 9, 2025 10:31
@ranchalp ranchalp requested review from Thegaram and jonastheis June 9, 2025 13:18
// Default compression ratio is 1.0 (no compression)
compressionRatioInt := big.NewInt(rcfg.Precision.Int64())

if len(data) != 0 {

Choose a reason for hiding this comment

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

Is this zero check needed? This should never happen, plus this error case is covered inside CompressScrollBatchBytes.

Copy link
Author

Choose a reason for hiding this comment

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

True, it is already in CompressScrollBatchBytes. Removed.

compressionRatioInt := big.NewInt(rcfg.Precision.Int64())

if len(data) != 0 {
compressedBytes, err := zstd.CompressScrollBatchBytes(data)

Choose a reason for hiding this comment

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

Fyi this will add 128 byte overhead (compressBufferOverhead).

Copy link
Author

@ranchalp ranchalp Jun 10, 2025

Choose a reason for hiding this comment

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

should we just subtract these 128 bytes from the result then and continue using our own zstd implementation (probably in a wrapper function)?

Choose a reason for hiding this comment

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

That could work, though it leaks implementation details of da-codec.

compressionRatioInt := big.NewInt(rcfg.Precision.Int64())

if len(data) != 0 {
compressedBytes, err := zstd.CompressScrollBatchBytes(data)

Choose a reason for hiding this comment

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

I think we can just use any go zstd lib, don't need to use our da-codec, what do you think? @colinlyguo

Copy link
Author

Choose a reason for hiding this comment

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

What are the motivations to not use our own zstd lib? the 128 bytes overhead?

Choose a reason for hiding this comment

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

Please sync with Colin, this is something we want to do in other codebases too. Circuits can now support the whole zstd spec so we don't need to hardcode using a specific implementation (true with some caveats).

Copy link
Member

@colinlyguo colinlyguo Jun 11, 2025

Choose a reason for hiding this comment

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

Yeah. We can use any Go Zstd lib. And a reminder is that the spec can also be used in Reth, for constructing historical blocks from DA.

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/DataDog/zstd, https://github.com/valyala/gozstd. These libraries look good (listed in https://facebook.github.io/zstd/), the implementation is the official zstd C implementation.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Pure Go implementation, such as https://github.com/klauspost/compress/tree/master/zstd#zstd won't have any issues with C's global symbol conflicts when loading multiple zstd libraries. But I'm afraid Rust cannot have an identical implementation to reproduce the same compression ratio.

Also, pls double-check if a version of zstd running on different operating systems will produce the same results.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Got it and thanks!

Comment on lines 220 to 221
compressionRatioInt.Mul(compressedSize, rcfg.Precision)
compressionRatioInt.Div(compressionRatioInt, txSize)

Choose a reason for hiding this comment

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

While I believe it's always true that compressedSize <= size, I'm not 100% convinced this is the case. I suggest you add a check to cover this

Copy link
Author

@ranchalp ranchalp Jun 10, 2025

Choose a reason for hiding this comment

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

good catch, also not 100% sure. Done

// compression_ratio(tx) = 1 (placeholder, scaled to match scalars precision)
compressionRatio := big.NewInt(rcfg.Precision.Int64())
// Default compression ratio is 1.0 (no compression)
compressionRatioInt := big.NewInt(rcfg.Precision.Int64())

Choose a reason for hiding this comment

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

Why rename to compressionRatioInt?

Copy link
Author

Choose a reason for hiding this comment

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

Fair, removed.

@ranchalp
Copy link
Author

Waiting for a decision on which zstd library to use (I am not sure I understand why not just going with our own?), otherwise comments resolved.

@ranchalp ranchalp marked this pull request as ready for review June 10, 2025 20:27
@ranchalp ranchalp force-pushed the l1data-to-rollupfee branch from d0e730b to ce2498e Compare June 11, 2025 16:00
@ranchalp ranchalp force-pushed the rollupfee-estimate-compression branch from b83f7dc to e3c5bd7 Compare June 12, 2025 13:38
@ranchalp
Copy link
Author

Following the discussion here, I reverted the use of a standard go zstd library in favour for the da-codec's version.

Copy link

@jonastheis jonastheis left a comment

Choose a reason for hiding this comment

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

Please revert all the whitespace changes. Next to being a pain when reviewing it also increases the diff.

Good common practice is to check files and their content before committing to avoid such whitespace changes from eg linter and to make sure what you're committing is actually sensible.

compressionRatio := big.NewInt(rcfg.Precision.Int64())

compressedBytes, err := zstd.CompressScrollBatchBytes(data)
if err != nil {
log.Error("Batch compression failed, using 1.0 compression ratio", "err", err)

Choose a reason for hiding this comment

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

adjust the log message and would be good to also add the tx hash to the log message here to make it more meaningful.

compressionRatio := big.NewInt(rcfg.Precision.Int64())

compressedBytes, err := zstd.CompressScrollBatchBytes(data)
Copy link

@jonastheis jonastheis Jun 19, 2025

Choose a reason for hiding this comment

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

might still be good to use the zstd version that comes with da-codec. maybe we need to introduce a new function there to get rid of the overhead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants