optimism
optimism copied to clipboard
fix a few corner cases and revert last batch for `SpanBatch` when error happens
According to this code, parent.Timestamp==current.Timestamp is also invalid.
This PR also fixes checkFull so that it only marks ErrCompressorFull when co.compressed.Len() > co.target instead of co.compressed.Len() >= co.target, because when co.compressed.Len() == co.target, we actually want to include the current block into the channel instead of trying to revert to the compressed previous data.
This PR also added a call to revertLastBatch when error happened downstream.
Walkthrough
Walkthrough
The updates across various components primarily focus on enhancing error handling and rollback mechanisms, refining method parameters, and adjusting logical conditions in timestamp and batch processing. These changes aim to improve the robustness and accuracy of transaction and batch operations within the system.
Changes
| File Path | Change Summary |
|---|---|
.../span_batch.go |
Modified timestamp comparison from > to >=, introduced lastParentCheck and lastL1OriginCheck fields, and added revertLastBatch method. |
.../span_batch_tx.go |
Changed size parameter in setDecoded method to an unnamed parameter _. |
.../span_batch_txs.go |
Added revertLastTxs method to revert changes made by the AddTxs method. |
.../channel_builder_test.go |
Imported sync/atomic, added incrementalBlockTime, updated block time setting, and modified test functions for new conditions and error handling. |
.../span_channel_out.go |
Updated return type of AddSingularBatch to (err error), added error handling with deferred function, and adjusted compressor full check logic. |
Recent Review Details
Configuration used: .coderabbit.yml Review profile: CHILL
Commits
Files that changed from the base of the PR and between b8587bc6a01b03c0a15a55bad2ce9800f7cb4eec and 399ee21f64eb9808e4efcf5e2ed7fb81ac4405b0.Files selected for processing (2)
- op-batcher/batcher/channel_builder_test.go (5 hunks)
- op-node/rollup/derive/span_channel_out.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- op-node/rollup/derive/span_channel_out.go
Additional comments not posted (5)
op-batcher/batcher/channel_builder_test.go (5)
9-9: Added import forsync/atomicto support atomic operations onincrementalBlockTime.
48-49: IntroducedincrementalBlockTimeof typeatomic.Uint64for managing block times atomically.
57-57: ModifiednewMiniL2BlockWithNumberParentto useincrementalBlockTime.Add(2)for setting block time, ensuring sequential block times are correctly spaced.
83-83: UpdatedChannelBuilder_OutputFramesMaxFrameIndextest to includederive.SkipOptimize = true, addressing test scenarios where compression might increase data size.
559-573: > :memo: NOTEThis review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [549-570]
Adjusted
MaxFrameSizeinTestChannelBuilder_FullShadowCompressorto handle the compressor full error more accurately, ensuring the test reflects the intended behavior when the compressor is full.
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?
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>.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
@coderabbitaiin 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
@coderabbitaiin 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 generate interesting stats about this repository and render them as a table.@coderabbitai show all the console.log statements in this repository.@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.
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 as PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger a review. This is useful when automatic reviews are disabled for the repository.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai helpto get help.
Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
CodeRabbit Configration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
@zhiqiangxu op-batcher tests are failing with this change
I added a SkipOptimize which is only set to true for test, as I met a case where the size before compressing(969) is smaller than the size after compressing(985). In this situation there's no way to choose a proper MaxFrameSize to make co.target smaller than 969 but bigger than 985.
I also found a couple other issues, described at the beginning of the post.
Some really cool ideas in this PR, thanks for putting it together! I have some comments around testing and edge-cases, but also wanted to leave a high-level comment:
Span Batch Reverting is a helpful feature, but I think the amount of complexity it brings in does not currently justify its benefit. Seems like the largest benefit is that it prevents Span Batches from being added to during an error in
AddSingularBatch, because presumably on retry the same batch would be added again. To address this with less complexity, the SpanBatch itself could check,
- If the same timestamp as the last batch, and the same content (hash), just ignore it
- If the same timestamp as the last content, and different content, panic
This would cover cases where an error in the Span Channel Out might redrive content into the SpanBatch, and would not require
deferbehavior to mutate the SpanBatch.We could even make it something the Span Channel Out manages, with a new function,
func (sb SpanBatch)AlreadyHas(b Batch) bool, so the SpanChannelOut could avoid redriving batches altogether.Span Batches don't currently need the ability to revert, because the Span Channel Out keeps a double-buffer of RLP encoded Raw Span Batches. If the newly added batch exceeds the threshold, the previous RLP buffer is used. This is like a revert, but at the serialized level.
I think this argument is based on assumptions on what kind of error can actually happen downstream, right?
IMHO we'll achieve cleaner separation of concern if we can get rid of such assumptions.
This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.