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

fix(rollup-relayer): wrong l1 messages popped num #1550

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

colinlyguo
Copy link
Member

@colinlyguo colinlyguo commented Oct 23, 2024

Purpose or design rationale of this PR

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:

  • fix: A bug fix

Deployment tag versioning

Has tag in common/version.go been updated or have you added bump-version label to this PR?

  • Yes

Breaking change label

Does this PR have the breaking-change label?

  • No, this PR is not a breaking change

Summary by CodeRabbit

  • New Features

    • Updated versioning information to version 4.4.70.
  • Bug Fixes

    • Improved error logging by converting ParentBatchHash to hexadecimal format in multiple locations, enhancing clarity in logs.
  • Chores

    • Simplified variable initialization in the GetBatchMetadata function for better code readability.

Copy link

coderabbitai bot commented Oct 23, 2024

Walkthrough

The changes in this pull request primarily involve an update to the version number in common/version/version.go, changing it from "v4.4.69" to "v4.4.70". Additionally, modifications are made to enhance error logging in the InsertBatch methods across multiple files, ensuring that the ParentBatchHash is logged in hexadecimal format. A minor adjustment is also made in rollup/internal/utils/utils.go to initialize a variable directly. Overall, the core functionality and structure of the methods remain unchanged.

Changes

File Path Change Summary
common/version/version.go Updated variable tag from "v4.4.69" to "v4.4.70".
coordinator/internal/orm/batch.go Updated InsertBatch method to log ParentBatchHash in hexadecimal format in multiple error scenarios.
rollup/internal/orm/batch.go Updated InsertBatch and GetVerifiedProofByHash methods to log ParentBatchHash and batch.Hash in hexadecimal format.
rollup/internal/utils/utils.go Initialized totalL1MessagePoppedBeforeEndDAChunk directly with batch.TotalL1MessagePoppedBefore.
tests/integration-test/orm/batch.go Updated InsertBatch method to log ParentBatchHash in hexadecimal format in multiple error scenarios.

Possibly related PRs

  • refactor: use new codec interfaces #1530: The changes in this PR involve an update to the versioning information in common/version/version.go, which aligns with the version updates mentioned in the main PR.

Suggested labels

bump-version

Suggested reviewers

  • NazariiDenha
  • georgehao
  • jonastheis

Poem

🐇 In the meadow where the code does play,
A version hops to greet the day.
From v4.4.69 to v4.4.70 it leaps,
With logs in hex, the rabbit keeps.
Error messages clear as can be,
Hooray for changes, oh so merry! 🎉


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.

@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2024

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.

Project coverage is 52.84%. Comparing base (cc2441d) to head (1bcdaa0).

Files with missing lines Patch % Lines
coordinator/internal/orm/batch.go 0.00% 6 Missing ⚠️
rollup/internal/orm/batch.go 0.00% 3 Missing ⚠️
rollup/internal/utils/utils.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1550   +/-   ##
========================================
  Coverage    52.84%   52.84%           
========================================
  Files          157      157           
  Lines        12641    12641           
========================================
  Hits          6680     6680           
  Misses        5382     5382           
  Partials       579      579           
Flag Coverage Δ
coordinator 17.13% <0.00%> (ø)
rollup 59.11% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

🧹 Outside diff range and nitpick comments (4)
tests/integration-test/orm/batch.go (1)

Line range hint 183-193: Consider improving transaction handling.

The current transaction handling could be enhanced for better consistency and error recovery:

  1. Consider using a transaction by default instead of making it optional
  2. Add transaction rollback on error
 db := o.db
 if len(dbTX) > 0 && dbTX[0] != nil {
     db = dbTX[0]
 }
 db = db.WithContext(ctx)
 db = db.Model(&Batch{})
 
+tx := db.Begin()
+defer func() {
+    if r := recover(); r != nil {
+        tx.Rollback()
+    }
+}()
+
+if err := tx.Create(&newBatch).Error; err != nil {
+    tx.Rollback()
     log.Error("failed to insert batch", "batch", newBatch, "err", err)
     return nil, fmt.Errorf("Batch.InsertBatch error: %w", err)
 }
+if err := tx.Commit().Error; err != nil {
+    tx.Rollback()
+    log.Error("failed to commit batch transaction", "batch", newBatch, "err", err)
+    return nil, fmt.Errorf("Batch.InsertBatch commit error: %w", err)
+}
coordinator/internal/orm/batch.go (1)

Line range hint 331-332: Remove misleading comments about unit test usage.

These comments suggest the code is only used in unit tests:

BlobDataProof:     nil, // using mock value because this piece of codes is only used in unit tests
BlobSize:          0,   // using mock value because this piece of codes is only used in unit tests

However, InsertBatch appears to be a core ORM method. Consider either:

  1. Removing these comments if the method is used in production.
  2. Documenting the actual reason for using mock values.
rollup/internal/orm/batch.go (2)

268-268: Improved error logging with hex formatting and L1 message context.

The enhanced error logging provides better debugging context by:

  1. Converting ParentBatchHash to hex format
  2. Including TotalL1MessagePoppedBefore in the logs

This improvement aligns with the PR objective of fixing L1 messages popped num issues.

Consider applying similar logging improvements to other error scenarios in the InsertBatch method for consistency. For example:

 if err := db.Create(&newBatch).Error; err != nil {
-    log.Error("failed to insert batch", "batch", newBatch, "err", err)
+    log.Error("failed to insert batch", "index", batch.Index, "total l1 message popped before", batch.TotalL1MessagePoppedBefore,
+        "parent hash", batch.ParentBatchHash.Hex(), "number of chunks", numChunks, "err", err)
     return nil, fmt.Errorf("Batch.InsertBatch error: %w", err)
 }

Also applies to: 277-277, 284-284


Line range hint 268-285: Consider implementing structured logging for batch processing.

Given the critical nature of batch processing and L1 message tracking in the rollup system, consider implementing a more structured logging approach:

  1. Define standard log fields for batch operations
  2. Create logging middleware or helper functions
  3. Consider adding metrics for tracking L1 message processing

This would provide:

  • Consistent error context across all batch operations
  • Better observability for debugging L1 message issues
  • Easier log aggregation and analysis

Example helper function:

func logBatchError(logger log.Logger, msg string, batch *encoding.Batch, numChunks uint64, err error) {
    logger.Error(msg,
        "index", batch.Index,
        "total_l1_message_popped_before", batch.TotalL1MessagePoppedBefore,
        "parent_hash", batch.ParentBatchHash.Hex(),
        "number_of_chunks", numChunks,
        "err", err,
    )
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cc2441d and 1bcdaa0.

📒 Files selected for processing (5)
  • common/version/version.go (1 hunks)
  • coordinator/internal/orm/batch.go (3 hunks)
  • rollup/internal/orm/batch.go (2 hunks)
  • rollup/internal/utils/utils.go (1 hunks)
  • tests/integration-test/orm/batch.go (3 hunks)
🧰 Additional context used
🔇 Additional comments (11)
common/version/version.go (2)

8-8: LGTM! Version bump follows semantic versioning.

The patch version increment (v4.4.69 → v4.4.70) is appropriate for a bug fix change.


8-8: Verify version consistency across the codebase.

Let's ensure this version is consistently referenced across the codebase.

✅ Verification successful

Let me gather more specific information about version references in the codebase.

This will help us verify if the version update is properly reflected in critical files and if there are any version dependencies we need to consider.


Based on the gathered information, I can now provide the final response:

Version update appears to be isolated and safe

The version update from the old version to v4.4.70 is contained within common/version/version.go and doesn't require synchronization with other components because:

  • No references to the old version (v4.4.69) were found in the codebase
  • The version tag in version.go is used independently of the prover version checking mechanism
  • The minimum prover versions specified in coordinator config (v4.4.43 and v4.4.45) are well below the new version
  • The prover version checking logic in prover_version.go uses semantic version comparison and doesn't hardcode specific versions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any other version references that might need updating

# Test 1: Search for the old version string
echo "Checking for old version (v4.4.69) references:"
rg "v4\.4\.69"

# Test 2: Search for version-related files
echo -e "\nChecking other version-related files:"
fd -t f "version|VERSION"

# Test 3: Check for version strings in configuration files
echo -e "\nChecking configuration files:"
fd -e yaml -e json -e toml | xargs rg "version|Version"

Length of output: 1883


Script:

#!/bin/bash
# Check for any references to v4.4.70 and surrounding context
echo "Checking for new version references:"
rg -A 2 -B 2 "v4\.4\.70"

# Check prover version related code
echo -e "\nChecking prover version related code:"
cat common/version/prover_version.go

# Check version-related configuration
echo -e "\nChecking coordinator config:"
cat coordinator/conf/config.json | jq '.circuits'

Length of output: 1741

rollup/internal/utils/utils.go (1)

Line range hint 202-208: LGTM: Correct initialization of L1 message counter.

The change properly initializes totalL1MessagePoppedBeforeEndDAChunk with the batch's total popped messages and correctly accumulates L1 messages from each chunk. This fixes the bug where the wrong number of L1 messages was being counted.

Let's verify the fix by checking for any related test cases:

✅ Verification successful

Let me gather more information about the test cases by correcting the search path:


Let me check the actual implementation and test cases to verify the L1 message counting logic:


Let me try one final search to understand the NumL1Messages implementation:


Based on the code inspection results, I can now provide a final response:

The L1 message counting fix is correctly implemented

The code change properly initializes and accumulates L1 messages by:

  1. Starting with batch.TotalL1MessagePoppedBefore as the base count
  2. Incrementally adding each chunk's L1 messages through the loop
  3. Using the accumulated total for the final DA chunk creation

The Chunk struct in rollup/internal/orm/chunk.go confirms the presence of both TotalL1MessagesPoppedBefore and TotalL1MessagesPoppedInChunk fields, which aligns with the fix's approach to message counting.

Note: While we couldn't locate specific test cases, the structural evidence from the codebase supports that the fix correctly handles L1 message counting by properly tracking both the total messages popped before a chunk and the messages within each chunk.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for test cases that verify L1 message counting in chunks/batches
rg -l "TotalL1MessagePoppedBefore|NumL1Messages" --type go "test"

# Look for any related issues or PRs that might provide more context
gh issue list --search "l1 messages popped"
gh pr list --search "l1 messages popped"

Length of output: 328


Script:

#!/bin/bash
# Search for test cases that verify L1 message counting in chunks/batches
rg -l "TotalL1MessagePoppedBefore|NumL1Messages" --type go

# Look for the implementation of NumL1Messages to understand the logic
ast-grep --pattern 'func ($x *$_) NumL1Messages($_) $_'

Length of output: 778


Script:

#!/bin/bash
# Check the implementation of NumL1Messages in chunk.go
rg -A 10 "NumL1Messages" rollup/internal/orm/chunk.go

# Look at the test cases to verify the fix
rg -A 10 "TotalL1MessagePoppedBefore" rollup/internal/orm/orm_test.go

Length of output: 740


Script:

#!/bin/bash
# Search for the Chunk struct and NumL1Messages method implementation
rg -A 15 "type Chunk struct" rollup/internal/orm/chunk.go

# Look for test cases specifically testing the L1 message counting
rg -B 5 -A 10 "func.*Test.*L1Message" rollup/internal/orm/orm_test.go rollup/internal/controller/relayer/l2_relayer_test.go

Length of output: 1390

tests/integration-test/orm/batch.go (2)

109-109: LGTM: Improved error logging with hex formatting.

The consistent use of .Hex() for ParentBatchHash across all error logs improves debugging by making hash values human-readable.

Also applies to: 117-117, 131-131, 138-138, 149-149, 156-156


Line range hint 142-147: Verify L1 message calculation logic.

The code calculates total L1 messages by accumulating messages across chunks. Given the PR's objective to fix wrong L1 messages popped num, please verify:

  1. The initial TotalL1MessagePoppedBefore value is correctly set before this function.
  2. The accumulation logic handles all edge cases (empty messages, overflow).
✅ Verification successful

Let me gather more context about the L1 message calculation logic by examining the related code.


Let me check the implementation in the identified files to understand the L1 message calculation logic better.


Let me check the implementation of NumL1Messages method since it's a crucial part of the L1 message calculation.


Based on the analysis of the code and search results, I can now provide the final response:

L1 message calculation logic is correctly implemented

The L1 message calculation logic in the code is correct and consistent across the codebase:

  • The initial value is properly set from batch.TotalL1MessagePoppedBefore
  • The accumulation logic correctly uses a running total by passing the accumulated value to NumL1Messages() for each chunk
  • The same pattern is used consistently across different packages (coordinator, rollup, tests)
  • Edge cases are handled by the loop structure which correctly processes n-1 chunks before the final chunk
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all places where TotalL1MessagePoppedBefore is set
rg -A 5 "TotalL1MessagePoppedBefore.*=" 

Length of output: 620


Script:

#!/bin/bash
# Search for the implementation of NumL1Messages method
ast-grep --pattern 'func ($_ *$_) NumL1Messages($_) $_'

# Search for CalculateBatchMetrics implementation
ast-grep --pattern 'func CalculateBatchMetrics($_) $_'

# Look for tests related to L1 message calculation
rg -l "TestL1Message|test.*L1Message"

Length of output: 224


Script:

#!/bin/bash
# Check the implementation in both files
cat tests/integration-test/orm/batch.go coordinator/internal/orm/batch.go

# Search for any related test cases
rg -A 10 "func.*Test.*L1Message" tests/integration-test/orm/batch.go coordinator/internal/orm/batch.go

Length of output: 26173


Script:

#!/bin/bash
# Search for NumL1Messages implementation in the codebase
rg -A 5 "func.*NumL1Messages"

# Look for the implementation in the da-codec repository
rg "NumL1Messages" --type go

Length of output: 1059

coordinator/internal/orm/batch.go (6)

263-263: LGTM! Improved error logging readability.

Converting ParentBatchHash to hex format in logs makes debugging easier.


271-271: LGTM! Consistent error logging format.

The hex format for ParentBatchHash maintains consistency with other error logs.


285-285: LGTM! Consistent error logging enhancement.

Hex format for ParentBatchHash aligns with the logging improvements.


292-292: LGTM! Consistent logging format.

Hex format maintains consistency across error logs.


303-303: LGTM! Consistent error logging.

Hex format for ParentBatchHash follows the established pattern.


310-310: LGTM! Consistent logging enhancement.

Hex format maintains consistency in error logging.

@colinlyguo colinlyguo merged commit bc8f9db into develop Oct 23, 2024
9 checks passed
@colinlyguo colinlyguo deleted the fix-rollup-relayer-wrong-l1-messages-popped-num branch October 23, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants