Skip to content

fix: an attempt at making witness generation more stable #1166

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

Merged
merged 4 commits into from
Apr 8, 2025

Conversation

omerfirmak
Copy link

@omerfirmak omerfirmak commented Apr 3, 2025

1. Purpose or design rationale of this PR

...

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

Summary by CodeRabbit

  • New Features

    • Introduced a dedicated option for configuring witness data directly within state management.
  • Bug Fixes

    • Enhanced the clarity of witness generation by simplifying error handling and removing unnecessary complexity.
  • Refactor

    • Streamlined background processing initialization by simplifying argument handling.
    • Updated the integration across blockchain operations and pipeline processes for a more consistent execution flow.
    • Implemented a new sorting mechanism for processing pending storage updates to ensure consistent order.
  • Chores

    • Incremented the patch version to reflect the latest updates.

Copy link

coderabbitai bot commented Apr 3, 2025

Walkthrough

This pull request updates the prefetcher initialization across multiple modules. In the blockchain and rollup pipeline, the second argument of the StartPrefetcher method has been removed. In the state database, a new WithWitness method has been added, and the StartPrefetcher signature is modified to exclude the witness parameter. The generateWitness function now associates the witness with the state via WithWitness, decoupling it from prefetcher initialization. The core blockchain logic and control flow remain consistent.

Changes

Files Change Summary
core/blockchain.go, rollup/pipeline/... Removed the second argument (nil) from the StartPrefetcher method in the insertChain, BuildAndWriteBlock, and traceAndApplyStage functions, simplifying the prefetcher initialization.
core/state/statedb.go, eth/api.go Introduced a new WithWitness method in StateDB for setting the witness. Modified the StartPrefetcher signature to remove the witness parameter, and updated generateWitness to call WithWitness instead of passing witness directly.
core/state/state_object.go Added sorting mechanism for pendingStorage keys in the updateTrie method, ensuring consistent processing order. Import statement for the slices package added.
params/version.go Updated the VersionPatch constant from 35 to 36, reflecting a new patch version.

Sequence Diagram(s)

sequenceDiagram
    participant API as generateWitness
    participant StateDB as StateDB
    participant W as Witness
    API->>StateDB: WithWitness(W)
    API->>StateDB: Process block & validate state
Loading
sequenceDiagram
    participant Caller as Chain/Pipeline Method
    participant StateDB as StateDB
    Caller->>StateDB: StartPrefetcher(namespace)
Loading

Possibly related PRs

  • fix: avoid using snapshots when generating witness #1116: The changes in the main PR are related to the modifications of the StartPrefetcher method, which are also reflected in the retrieved PR's updates to the same method, indicating a direct connection in how the prefetcher is initialized.
  • fix: post-euclid block tracing #1119: The changes in the main PR regarding the StartPrefetcher method in core/blockchain.go are related to the modifications made to the same method in the rollup/pipeline/pipeline.go file of the retrieved PR, as both involve altering the method's parameters.
  • fix(api): eth_getProof crash #1159: The changes in the main PR regarding the StartPrefetcher method in core/blockchain.go and rollup/pipeline/pipeline.go are related to the modifications in the StartPrefetcher method call in the retrieved PR, which also involves changes to the parameters of this method.

Suggested reviewers

  • georgehao
  • colinlyguo
  • Thegaram

Poem

I'm a little rabbit, hopping through the code,
Skipping past nils on a brand-new road.
With witness set aside in a cozy new space,
My prefetcher now moves at a gentler pace.
Code carrots crunch as I joyfully bound—
In this updated garden, magic is found!
🐇💻 Happy hops to all!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5129f60 and 37d2971.

📒 Files selected for processing (1)
  • eth/api.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • eth/api.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: Analyze (go)

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
core/blockchain.go (1)

1839-1841: Update Prefetcher Tag in BuildAndWriteBlock

The call to statedb.StartPrefetcher("l1sync") in the BuildAndWriteBlock function now explicitly uses the "l1sync" label instead of the label used in other contexts (e.g. "chain" in the insertion path). This appears to be part of the effort to decouple witness generation from regular prefetching. Please verify that:

  • The "l1sync" identifier triggers the prefetcher logic appropriate for witness-related operations.
  • This change is consistent with the separate witness-handling mechanism (i.e. using the new WithWitness method in the state database) and does not lead to unintended cache or state inconsistencies.

If this new configuration requires any documentation updates or downstream changes in how prefetcher results are consumed, please address those as well.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d482b2f and 0af50dd.

📒 Files selected for processing (4)
  • core/blockchain.go (2 hunks)
  • core/state/statedb.go (1 hunks)
  • eth/api.go (1 hunks)
  • rollup/pipeline/pipeline.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
core/state/statedb.go (2)
core/vm/interface.go (1)
  • StateDB (28-88)
core/stateless/witness.go (1)
  • Witness (38-47)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build-and-push
  • GitHub Check: test
  • GitHub Check: Analyze (go)
🔇 Additional comments (4)
eth/api.go (1)

357-357: Good refactoring to separate witness association from prefetcher initialization.

This change improves the design by making the witness association with the state DB more explicit through a dedicated method call, rather than coupling it with prefetcher initialization. This separation of concerns helps make witness generation more stable, which aligns with the PR objective.

rollup/pipeline/pipeline.go (1)

231-231: Properly updated to match the new StartPrefetcher signature.

This change correctly removes the second argument (previously nil) from the StartPrefetcher call to align with the updated method signature in the StateDB struct, where witness handling has been decoupled from prefetcher initialization.

core/state/statedb.go (2)

163-166: Good addition of a dedicated method for witness association.

Adding the WithWitness method provides a clear way to associate a witness with the state database. This improves code clarity and follows the principle of separation of concerns by decoupling witness handling from prefetcher initialization.


171-171: Appropriate signature update to remove witness handling from prefetcher initialization.

Removing the witness parameter from the StartPrefetcher method is a good design change that simplifies the prefetcher's responsibilities. This change is consistent with the addition of the dedicated WithWitness method and contributes to making witness generation more stable.

colinlyguo
colinlyguo previously approved these changes Apr 7, 2025
Copy link
Member

@colinlyguo colinlyguo left a comment

Choose a reason for hiding this comment

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

a reminder of version bump.

georgehao
georgehao previously approved these changes Apr 7, 2025
@omerfirmak omerfirmak merged commit ad017f5 into develop Apr 8, 2025
14 checks passed
@omerfirmak omerfirmak deleted the omerfirmak/stable-witness-generation branch April 8, 2025 08:32
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.

3 participants