Skip to content

(WIP): Feat/500ms benchmark #1173

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

Closed
wants to merge 5 commits into from
Closed

(WIP): Feat/500ms benchmark #1173

wants to merge 5 commits into from

Conversation

georgehao
Copy link
Member

@georgehao georgehao commented Apr 25, 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

  • Bug Fixes
    • Adjusted block timestamp calculation logic for improved consistency and predictability.
    • Updated mining work deadline calculation to use millisecond precision with alternating offsets for more accurate timing.
    • Replaced dynamic signer address retrieval with a fixed address to ensure stability and prevent potential retrieval errors.

Copy link

coderabbitai bot commented Apr 25, 2025

Walkthrough

This set of changes simplifies the logic for timestamp calculation in the consensus system contract, modifies how the L1 signer address is obtained by hardcoding it, and updates the mining work deadline computation to use a millisecond-based approach with an alternating offset. The previous dynamic and configurable logic for both timestamp and address retrieval is commented out but left in the code, while the new implementations use fixed or simplified rules. No changes were made to the signatures of exported or public entities.

Changes

File(s) Summary
consensus/system_contract/consensus.go Simplified CalcTimestamp logic: timestamp is now parent's timestamp, incremented by 1 if block number is even; previous logic using period and relaxed checks is commented out.
consensus/system_contract/system_contract.go fetchAddressFromL1 now assigns a hardcoded L1 signer address, with all previous dynamic retrieval logic commented out.
miner/scroll_worker.go Mining work deadline calculation now uses millisecond precision with a 500ms alternating offset based on block number parity, replacing the previous second-based addition.

Sequence Diagram(s)

sequenceDiagram
    participant Miner
    participant SystemContract
    participant BlockHeader

    Miner->>SystemContract: CalcTimestamp(parentHeader)
    SystemContract->>SystemContract: Set timestamp = parentHeader.timestamp
    alt parentHeader.number is even
        SystemContract->>SystemContract: Increment timestamp by 1
    end
    SystemContract-->>Miner: Return timestamp

    Miner->>SystemContract: fetchAddressFromL1()
    SystemContract->>SystemContract: Assign hardcoded address
    SystemContract-->>Miner: Return

    Miner->>BlockHeader: Compute mining work deadline
    BlockHeader-->>Miner: Provide header.time and number
    Miner->>Miner: Calculate deadline using ms and 500ms offset
Loading

Possibly related PRs

  • scroll-tech/go-ethereum#1130: Introduced the CalcTimestamp method and timestamp override mechanism in the same file and method, directly relating to the simplification and refactoring done in this PR.

Suggested reviewers

  • zimpha
  • roylou
  • omerfirmak

Poem

In the warren of code, a change hops along,
Timestamps now simpler, no need for a song.
The signer’s address, once fetched with great care,
Is now just a constant, always right there.
Deadlines in milliseconds, with hops that are neat—
This rabbit approves, with a thump of its feet! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5e956fe and 4c5ec01.

📒 Files selected for processing (3)
  • consensus/system_contract/consensus.go (1 hunks)
  • consensus/system_contract/system_contract.go (1 hunks)
  • miner/scroll_worker.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
consensus/system_contract/system_contract.go (1)
common/types.go (1)
  • HexToAddress (218-218)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
miner/scroll_worker.go (1)

563-563:

❓ Verification inconclusive

Updated deadline calculation uses millisecond precision with alternating offset

The deadline calculation is now more precise, using millisecond-level granularity with a 500ms offset that alternates based on block number parity.

This change appears to be coordinated with the timestamp calculation update in consensus/system_contract/consensus.go. Verify that this change works correctly with the new timestamp logic:


🏁 Script executed:

#!/bin/bash
# Description: Check for any tests or comments related to deadline calculation

rg -A 3 -B 3 "deadline.*UnixMilli" --type go
rg -A 3 -B 3 "500.*\%2" --type go

Length of output: 666


Verify deadline calculation alignment with updated consensus timestamp logic

We attempted to confirm the implementation via:

rg -C3 'deadline.*UnixMilli' --type go
rg -C3 '%2' --type go    # regex search errored due to escaping
rg -C3 'UnixMilli' consensus/system_contract/consensus.go

Since the %2 search failed, please manually verify that:

  • miner/scroll_worker.go (line 563) correctly applies the alternating 500 ms offset
  • the timestamp logic in consensus/system_contract/consensus.go now uses millisecond granularity and matches this calculation
  • no other code paths or tests depend on the old second-level deadline calculation

Comment on lines +91 to +119
s.signerAddressL1 = common.HexToAddress("0x756EA06BDEe36de11F22DCca45a31d8a178eF3c6")
//address, err := s.client.StorageAt(s.ctx, s.config.SystemContractAddress, s.config.SystemContractSlot, nil)
//if err != nil {
// return fmt.Errorf("failed to get signer address from L1 System Contract: %w", err)
//}
//bAddress := common.BytesToAddress(address)
//
//s.lock.Lock()
//defer s.lock.Unlock()
//
//// Validate the address is not empty
//if bAddress == (common.Address{}) {
// log.Debug("Retrieved empty signer address from L1 System Contract", "contract", s.config.SystemContractAddress.Hex(), "slot", s.config.SystemContractSlot.Hex())
//
// // Not initialized yet -- we don't consider this an error
// if s.signerAddressL1 == (common.Address{}) {
// log.Warn("System Contract signer address not initialized")
// return nil
// }
//
// return fmt.Errorf("retrieved empty signer address from L1 System Contract")
//}
//
//log.Debug("Read address from system contract", "address", bAddress.Hex())
//
//if s.signerAddressL1 != bAddress {
// s.signerAddressL1 = bAddress
// log.Info("Updated new signer from L1 system contract", "signer", bAddress.Hex())
//}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Hardcoded signer address replaces dynamic L1 retrieval

The implementation now uses a fixed address (0x756EA06BDEe36de11F22DCca45a31d8a178eF3c6) instead of dynamically retrieving the signer address from L1. All validation, error handling, and logging logic has been commented out.

While this simplifies the code, it creates the following concerns:

  1. Removes ability to dynamically update signers via L1
  2. Eliminates error handling for storage retrieval failures
  3. Removes validation that would prevent using an empty address

Consider whether this is intended as a temporary change for testing or if it's a permanent architectural decision. If permanent, add a comment explaining the rationale.

-s.signerAddressL1 = common.HexToAddress("0x756EA06BDEe36de11F22DCca45a31d8a178eF3c6")
+// Hardcoded address for 500ms benchmark testing
+// TODO: Revert to dynamic L1 retrieval after testing is complete
+s.signerAddressL1 = common.HexToAddress("0x756EA06BDEe36de11F22DCca45a31d8a178eF3c6")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
s.signerAddressL1 = common.HexToAddress("0x756EA06BDEe36de11F22DCca45a31d8a178eF3c6")
//address, err := s.client.StorageAt(s.ctx, s.config.SystemContractAddress, s.config.SystemContractSlot, nil)
//if err != nil {
// return fmt.Errorf("failed to get signer address from L1 System Contract: %w", err)
//}
//bAddress := common.BytesToAddress(address)
//
//s.lock.Lock()
//defer s.lock.Unlock()
//
//// Validate the address is not empty
//if bAddress == (common.Address{}) {
// log.Debug("Retrieved empty signer address from L1 System Contract", "contract", s.config.SystemContractAddress.Hex(), "slot", s.config.SystemContractSlot.Hex())
//
// // Not initialized yet -- we don't consider this an error
// if s.signerAddressL1 == (common.Address{}) {
// log.Warn("System Contract signer address not initialized")
// return nil
// }
//
// return fmt.Errorf("retrieved empty signer address from L1 System Contract")
//}
//
//log.Debug("Read address from system contract", "address", bAddress.Hex())
//
//if s.signerAddressL1 != bAddress {
// s.signerAddressL1 = bAddress
// log.Info("Updated new signer from L1 system contract", "signer", bAddress.Hex())
//}
// Hardcoded address for 500ms benchmark testing
// TODO: Revert to dynamic L1 retrieval after testing is complete
s.signerAddressL1 = common.HexToAddress("0x756EA06BDEe36de11F22DCca45a31d8a178eF3c6")

Comment on lines +229 to 246
timestamp := parent.Time

// If RelaxedPeriod is enabled, always set the header timestamp to now (ie the time we start building it) as
// we don't know when it will be sealed
if s.config.RelaxedPeriod || timestamp < uint64(time.Now().Unix()) {
timestamp = uint64(time.Now().Unix())
if parent.Number.Uint64()%2 == 0 {
timestamp += 1
}

return timestamp

//timestamp := parent.Time + s.config.Period
//
//// If RelaxedPeriod is enabled, always set the header timestamp to now (ie the time we start building it) as
//// we don't know when it will be sealed
//if s.config.RelaxedPeriod || timestamp < uint64(time.Now().Unix()) {
// timestamp = uint64(time.Now().Unix())
//}
//
//return timestamp
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplified timestamp calculation using block number parity

The timestamp calculation has been completely revised to use a much simpler rule:

  1. The timestamp starts as the parent block's timestamp
  2. If the parent block number is even, increment timestamp by 1

This replaces the previous approach that used configured periods and current time checks.

While this simplification makes the timestamp calculation more deterministic and predictable, it's lacking documentation to explain the rationale and potential impacts. This change works in conjunction with the deadline calculation update in miner/scroll_worker.go.

 timestamp := parent.Time

 if parent.Number.Uint64()%2 == 0 {
+    // Increment timestamp by 1 on even parent blocks to ensure
+    // a regular, deterministic pattern for block timestamps
+    // This works with the 500ms deadline offset in miner/scroll_worker.go
     timestamp += 1
 }

 return timestamp

@georgehao georgehao closed this Apr 27, 2025
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.

1 participant