Skip to content
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

refactor: use new da-codec interfaces #1068

Merged
merged 14 commits into from
Oct 21, 2024

Conversation

colinlyguo
Copy link
Member

@colinlyguo colinlyguo commented Oct 11, 2024

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:

  • refactor: A code change that doesn't fix a bug, or add a feature, or improves performance

3. Deployment tag versioning

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

  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new key for tracking the last synced L1 block number for rollup events.
    • Enhanced handling of commit batch data with codec versioning in the CalldataBlobSource.
  • Bug Fixes

    • Simplified the getCommittedBatchMeta method to improve clarity and reduce complexity.
  • Refactor

    • Streamlined batch type handling in the BatchQueue.
    • Consolidated codec handling in the RollupSyncService, removing unnecessary complexity.
  • Chores

    • Updated module dependencies to the latest versions.

jonastheis
jonastheis previously approved these changes Oct 16, 2024
colinlyguo and others added 4 commits October 18, 2024 15:01
…eum into refactor/use-new-da-codec-interfaces
* use new da-codec interface in syncing from l1

* delete unused

* nit

* uncomment

* typo

---------

Co-authored-by: colinlyguo <[email protected]>
jonastheis
jonastheis previously approved these changes Oct 21, 2024
@georgehao
Copy link
Member

@coderabbitai review

Copy link

coderabbitai bot commented Oct 21, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Oct 21, 2024

Walkthrough

The changes in this pull request involve significant modifications to the handling of batch data within the codebase. Key functions related to batch chunk range management have been removed, including writing, reading, and deleting batch chunk ranges. Corresponding test functions have also been eliminated. The schema has been updated to reflect the removal of batch chunk range keys and the addition of a new key for tracking synced L1 block numbers. Furthermore, several methods in the RollupSyncService and CalldataBlobSource classes have been altered to streamline batch processing and codec handling.

Changes

File Path Change Summary
core/rawdb/accessors_rollup_event.go Removed functions: WriteBatchChunkRanges, DeleteBatchChunkRanges, ReadBatchChunkRanges.
core/rawdb/accessors_rollup_event_test.go Removed test function: TestBatchChunkRanges.
core/rawdb/schema.go Removed function: batchChunkRangesKey; added key: rollupEventSyncedL1BlockNumberKey.
go.mod Updated dependency versions for github.com/VictoriaMetrics/fastcache and github.com/scroll-tech/da-codec.
rollup/da_syncer/batch_queue.go Updated NextBatch method to handle da.CommitBatchWithBlobType.
rollup/da_syncer/da/calldata_blob_source.go Enhanced getCommitBatchDA method with codec versioning and error handling for unsupported versions.
rollup/da_syncer/da/commitV0.go Updated type references from codecv0.DAChunkRawTx to encoding.DAChunkRawTx.
rollup/da_syncer/da/commitV1.go Renamed function from NewCommitBatchDAV1 to NewCommitBatchDAWithBlob; updated its signature.
rollup/da_syncer/da/commitV2.go Removed type CommitBatchDAV2 and its associated methods.
rollup/da_syncer/da/commitV4.go Removed type CommitBatchDAV4 and its associated methods.
rollup/da_syncer/da/da.go Removed constants: CommitBatchV1Type, CommitBatchV2Type, CommitBatchV4Type; added: CommitBatchWithBlobType.
rollup/rollup_sync_service/rollup_sync_service.go Simplified getCommittedBatchMeta and getLocalChunksForBatch methods; removed codec-specific imports.
rollup/rollup_sync_service/rollup_sync_service_test.go Updated tests to reflect changes in getCommittedBatchMeta and new metadata structure.

Poem

In the fields where data flows,
A rabbit hops, where change bestows.
With chunks and batches, now streamlined,
The code is neat, the paths aligned.
Hooray for updates, swift and bright,
In the coding burrow, all feels right! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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 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.

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: 10

🧹 Outside diff range and nitpick comments (5)
rollup/da_syncer/batch_queue.go (1)

Line range hint 1-95: Overall assessment: Code change aligns with refactoring objectives.

The modification to the NextBatch method reflects a broader shift in batch type handling across the system. While the change itself is straightforward and localized, it's crucial to ensure that this refactoring is consistently applied throughout the codebase.

Consider the following recommendations:

  1. Update documentation: Ensure that any documentation referring to batch types is updated to reflect this change.
  2. Review tests: Verify that all relevant test cases have been updated to use the new CommitBatchWithBlobType where appropriate.
  3. Performance impact: Assess whether this consolidation of batch types has any performance implications, particularly in terms of data processing and storage.
  4. Migration plan: If this change affects existing data or APIs, ensure there's a clear migration plan for transitioning from the old batch types to the new one.

These considerations will help maintain consistency and prevent potential issues as the refactoring is rolled out across the system.

rollup/da_syncer/da/commitV0.go (1)

27-27: LGTM: New codec parameter enhances flexibility.

The addition of the codec encoding.Codec parameter aligns with the PR's refactoring objective and allows for more flexible handling of different encoding schemes.

Consider adding a nil check for the codec parameter to improve error handling:

if codec == nil {
    return nil, fmt.Errorf("codec cannot be nil")
}
rollup/da_syncer/da/commitV1.go (3)

Line range hint 23-33: Add Nil Check for the codec Parameter

The function NewCommitBatchDAWithBlob uses the codec parameter without checking if it is nil. This could lead to a nil pointer dereference if codec is nil.

Consider adding a nil check at the beginning of the function:

if codec == nil {
    return nil, fmt.Errorf("codec is nil")
}

Line range hint 49-52: Fix Logical Error in Blob Null Check

The condition blob == nil && err != nil in the error check is logically incorrect. If err != nil, it should have already returned earlier. The unexpected case is when blob == nil && err == nil.

Update the condition and error message as follows:

- if blob == nil {
-     return nil, fmt.Errorf("unexpected, blob == nil and err != nil, batch index: %d, versionedHash: %s, blobClient: %T", batchIndex, versionedHash.String(), blobClient)
+ if err == nil && blob == nil {
+     return nil, fmt.Errorf("unexpected nil blob with no error, batch index: %d, versionedHash: %s, blobClient: %T", batchIndex, versionedHash.String(), blobClient)
}

77-77: Update Type() Method Documentation

The return value of the Type() method has changed to CommitBatchWithBlobType. Ensure that any documentation or comments reflecting the return type are updated accordingly.

Consider updating any relevant comments to match the new return type.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8454491 and bbd7b73.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (13)
  • core/rawdb/accessors_rollup_event.go (0 hunks)
  • core/rawdb/accessors_rollup_event_test.go (0 hunks)
  • core/rawdb/schema.go (0 hunks)
  • go.mod (2 hunks)
  • rollup/da_syncer/batch_queue.go (1 hunks)
  • rollup/da_syncer/da/calldata_blob_source.go (3 hunks)
  • rollup/da_syncer/da/commitV0.go (4 hunks)
  • rollup/da_syncer/da/commitV1.go (5 hunks)
  • rollup/da_syncer/da/commitV2.go (0 hunks)
  • rollup/da_syncer/da/commitV4.go (0 hunks)
  • rollup/da_syncer/da/da.go (1 hunks)
  • rollup/rollup_sync_service/rollup_sync_service.go (11 hunks)
  • rollup/rollup_sync_service/rollup_sync_service_test.go (13 hunks)
💤 Files with no reviewable changes (5)
  • core/rawdb/accessors_rollup_event.go
  • core/rawdb/accessors_rollup_event_test.go
  • core/rawdb/schema.go
  • rollup/da_syncer/da/commitV2.go
  • rollup/da_syncer/da/commitV4.go
✅ Files skipped from review due to trivial changes (1)
  • go.mod
🧰 Additional context used
🔇 Additional comments (16)
rollup/da_syncer/da/da.go (1)

14-15: LGTM! Consider verifying impact and updating documentation.

The consolidation of multiple commit batch types into a single CommitBatchWithBlobType simplifies the enum and makes it more flexible for future versions. This change looks good.

To ensure this change doesn't introduce any issues, please run the following script to check for any remaining references to the old types:

Consider updating any relevant documentation or comments in other files to reflect this change in batch type representation.

✅ Verification successful

Verified: All old CommitBatchV1Type to CommitBatchV4Type references have been successfully removed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to old CommitBatch types

# Test: Search for old CommitBatch type references
echo "Searching for old CommitBatch type references:"
rg -i "CommitBatchV[1-4]Type" --type go

# Test: Search for uses of the new CommitBatchWithBlobType
echo "Searching for uses of the new CommitBatchWithBlobType:"
rg "CommitBatchWithBlobType" --type go

Length of output: 627

rollup/da_syncer/batch_queue.go (1)

44-44: LGTM. Verify impact on other components.

The consolidation of batch types to include da.CommitBatchWithBlobType aligns with the broader changes in the system. This simplification is a positive step.

To ensure this change doesn't introduce compatibility issues, please run the following verification:

Ensure that all references to the removed batch types have been updated and that the new CommitBatchWithBlobType is consistently used across the codebase.

✅ Verification successful

Verified. All references to removed batch types have been successfully eliminated, and the new CommitBatchWithBlobType is consistently utilized across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to removed batch types and verify the introduction of the new type.

# Test 1: Search for any remaining references to removed batch types
echo "Searching for references to removed batch types..."
rg -i "CommitBatchV1Type|CommitBatchV2Type"

# Test 2: Verify the introduction and usage of the new batch type
echo "Verifying usage of new CommitBatchWithBlobType..."
rg -i "CommitBatchWithBlobType"

# Test 3: Check for any TODO comments or FIXME related to batch types
echo "Checking for TODO or FIXME comments related to batch types..."
rg -i "TODO|FIXME" | rg -i "batch.*type|type.*batch"

Length of output: 810

rollup/da_syncer/da/commitV0.go (7)

20-20: LGTM: Type change aligns with refactoring objective.

The change from []*codecv0.DAChunkRawTx to []*encoding.DAChunkRawTx is consistent with the PR's objective of refactoring to use new da-codec interfaces. This update likely improves the code's flexibility by using a more generic encoding package.


35-35: LGTM: Decoding logic updated to use new codec.

The change to use codec.DecodeDAChunksRawTx(chunks) for decoding is consistent with the new codec parameter and the overall refactoring objective. The error handling remains appropriate.


47-47: LGTM: Parameter type updated consistently.

The change of decodedChunks parameter type from []*codecv0.DAChunkRawTx to []*encoding.DAChunkRawTx is consistent with the earlier changes and the overall refactoring objective.


103-105: LGTM: Improved encapsulation in daBlock usage.

The changes to use method calls (e.g., daBlock.NumTransactions(), daBlock.NumL1Messages()) instead of direct field access improve encapsulation. This is a good practice and is consistently applied across all usages of daBlock.

Also applies to: 110-110, 117-120


132-132: LGTM: Function signature updated consistently.

The change of the decodedChunks parameter type from []*codecv0.DAChunkRawTx to []*encoding.DAChunkRawTx in the getTotalMessagesPoppedFromChunks function is consistent with earlier changes and the overall refactoring objective.


136-136: LGTM: Consistent method call update.

The change to use block.NumL1Messages() instead of direct field access is consistent with earlier changes and improves encapsulation.


Line range hint 1-172: Overall assessment: Well-executed refactoring with improved design.

The changes in this file consistently implement the refactoring to use new da-codec interfaces. Key improvements include:

  1. Transition from codecv0 to a more generic encoding package.
  2. Introduction of a codec parameter for flexible encoding handling.
  3. Enhanced encapsulation through the use of method calls instead of direct field access.

These changes align well with the PR objectives and contribute to a more flexible and maintainable codebase. The refactoring has been applied consistently throughout the file, maintaining the existing functionality while improving the overall design.

rollup/da_syncer/da/commitV1.go (1)

Line range hint 23-33: Verify All Callers of Renamed Function Are Updated

The function NewCommitBatchDAV1 has been renamed to NewCommitBatchDAWithBlob. Ensure that all references to NewCommitBatchDAV1 in the codebase are updated to prevent undefined function errors.

Run the following script to find any remaining references to the old function name:

rollup/da_syncer/da/calldata_blob_source.go (1)

8-8: Addition of 'encoding' package import is appropriate

The import of the encoding package is necessary for the codec functionality introduced in the code.

rollup/rollup_sync_service/rollup_sync_service.go (3)

218-221: Code logic for handling committed batch metadata looks good

The error handling and writing of committedBatchMeta are correctly implemented.


Line range hint 355-407: Validation and error handling in getCommittedBatchMeta are appropriate

The function correctly handles potential errors and provides informative messages.


583-604: Proper error handling when decoding block ranges from encoded chunks

The function correctly handles errors and validates input data.

rollup/rollup_sync_service/rollup_sync_service_test.go (2)

568-571: Consistent initialization of committedBatchMeta

Ensure that the committedBatchMeta initialization is consistent across different codec versions. Currently, BlobVersionedHashes is set to nil. If this is intentional for CodecV0, please confirm that downstream code can handle a nil value without errors.


739-751: Ensure correct handling of BlobVersionedHashes for CodecV3

In the committedBatchMeta1 initialization for CodecV3, verify that the BlobVersionedHashes slice contains the correct hash values corresponding to the blobs used. Incorrect hashes may lead to validation failures.

@colinlyguo colinlyguo merged commit 3d92f68 into syncUpstream/active Oct 21, 2024
4 of 5 checks passed
@colinlyguo colinlyguo deleted the refactor/use-new-da-codec-interfaces branch October 21, 2024 14:24
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