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

Enable starting monomer apps in verifier mode #320

Merged
merged 3 commits into from
Dec 17, 2024
Merged

Conversation

natebeauregard
Copy link
Collaborator

@natebeauregard natebeauregard commented Dec 16, 2024

Introduces the --monomer.sequencer-mode flag to start the Monomer application in sequencer mode. Otherwise, the Monomer application will be started in verifier mode.

Summary by CodeRabbit

  • Documentation

    • Updated instructions for creating a Monomer application, clarifying command-line options for running in sequencer and verifier modes.
    • Revised documentation for interacting with Monomer Rollup Devnet to reflect changes in the startup command.
  • New Features

    • Introduced a new command-line flag to enable sequencer mode for the Monomer node.
    • Enhanced testing capabilities by adding functionality for setting up and running a verifier node alongside the sequencer node.

Introduces the --monomer.sequencer-mode flag to start the Monomer
application in sequencer mode. Otherwise, the Monomer application will
be started in verifier mode.
Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces a new --monomer.sequencer flag across multiple components of the Monomer application, enabling users to explicitly control the node's operational mode. The changes include updates to documentation, integration code, and test configurations, allowing developers to run nodes in either sequencer or verifier mode. The modifications provide clearer instructions for application startup and enhance the flexibility of node configuration.

Changes

File Change Summary
docs/docs/build/create-an-app-with-monomer.md Updated documentation to clarify Monomer application configuration and execution steps, including new sequencer mode flag.
docs/docs/build/interact.md Modified command syntax to use --monomer.sequencer flag for devnet startup.
e2e/e2e.go Added --monomer.sequencer argument to application startup command.
integrations/integrations.go Introduced flagSequencerMode flag, enabling sequencer mode configuration for Monomer node.
opdevnet/op.go Added conditional check to control batcher and proposer service initialization based on SequencerEnabled flag.
opdevnet/opdevnet_test.go Enhanced test to include verifier node setup and synchronization validation.

Possibly related PRs

Suggested reviewers

  • joshklop

Poem

🐰 Hop, hop, through the code we go,
Sequencer mode, a flag to show
Verifier's path, now crystal clear
Monomer's magic, drawing near!
A rabbit's dance of bits and bytes 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 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 73f5f8d and 031c712.

📒 Files selected for processing (1)
  • opdevnet/opdevnet_test.go (3 hunks)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
Contributor

@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: 1

🧹 Nitpick comments (2)
opdevnet/opdevnet_test.go (1)

178-188: Enhance the Synchronization Loop for Robustness

The loop waiting for the verifier node to sync to block 10 could be improved by adding a timeout context or by checking for context cancellation to make it more robust and responsive to test interruptions.

Consider refactoring the loop as follows:

for {
	select {
	case <-ctx.Done():
		t.Fatalf("Context cancelled before verifier synced to block 10")
	default:
		verifierBlockNum := verifierL2Backend.BlockChain().CurrentHeader().Number
		if verifierBlockNum.Uint64() >= 10 {
			break
		}
		time.Sleep(time.Second)
	}
}
integrations/integrations.go (1)

57-57: Enhance flag documentation for clarity.

While the flag implementation is correct, consider enhancing the description to be more explicit about the implications of each mode:

-cmd.Flags().Bool(flagSequencerMode, false, "enable sequencer mode for the Monomer node")
+cmd.Flags().Bool(flagSequencerMode, false, "enable sequencer mode for the Monomer node (default: verifier mode). In sequencer mode, the node runs batcher and proposer services")

Also applies to: 82-82

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 780a117 and 9ede6c1.

📒 Files selected for processing (6)
  • docs/docs/build/create-an-app-with-monomer.md (1 hunks)
  • docs/docs/build/interact.md (1 hunks)
  • e2e/e2e.go (1 hunks)
  • integrations/integrations.go (3 hunks)
  • opdevnet/op.go (1 hunks)
  • opdevnet/opdevnet_test.go (1 hunks)
🔇 Additional comments (5)
docs/docs/build/create-an-app-with-monomer.md (1)

48-59: Clarify Instructions for Running in Sequencer and Verifier Modes

The documentation correctly specifies how to start the application in sequencer and verifier modes. Ensure that users are aware that the --monomer.sequencer-mode flag explicitly sets the application to sequencer mode, and omitting it defaults to verifier mode.

docs/docs/build/interact.md (1)

13-13: Update Command to Reflect New Sequencer Mode Flag

The command now includes the --monomer.sequencer-mode flag, which is necessary to start the devnet in sequencer mode. This update aligns with the recent changes and provides clear instructions.

e2e/e2e.go (1)

74-76: Include Sequencer Mode Flag in E2E Test Setup

Adding the --monomer.sequencer-mode flag ensures that the application starts in sequencer mode during end-to-end testing, which is essential for the test scenarios.

opdevnet/op.go (1)

147-151: LGTM: Clean implementation of verifier mode.

The conditional block effectively implements verifier mode by skipping batcher and proposer services when SequencerEnabled is false. This ensures clean separation of concerns and prevents unnecessary resource usage.

Let's verify the mode separation:

✅ Verification successful

Based on the results, I can generate the final response as the verification is complete. The search results show:

Verified: Mode separation is properly implemented

The codebase shows clean separation between sequencer and verifier modes:

  • Configuration is properly handled via SequencerEnabled flag
  • Test files demonstrate correct verifier mode setup (opdevnet_test.go)
  • Documentation clearly explains both modes and their usage
  • No unexpected coupling between verifier operations and sequencer services found
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that batcher and proposer services are properly isolated
# Test: Search for any direct dependencies between verifier mode and sequencer services
# Expect: No direct coupling between verifier operations and sequencer services

# Check for proper separation of verifier/sequencer concerns
rg -A 5 "SequencerEnabled|sequencer.*mode|verifier.*mode"

# Check for proper initialization of services
ast-grep --pattern 'if $cond {
  $$$
  return nil
}'

Length of output: 4393

integrations/integrations.go (1)

307-307: LGTM: Proper flag value propagation.

The flag value is correctly propagated to the OP configuration's SequencerEnabled field.

opdevnet/opdevnet_test.go Outdated Show resolved Hide resolved
integrations/integrations.go Outdated Show resolved Hide resolved
opdevnet/opdevnet_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@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 (2)
opdevnet/opdevnet_test.go (2)

162-174: Consider removing unnecessary secrets for verifier

The verifier configuration includes batcher and proposer secrets (lines 164-165) which aren't needed since the verifier doesn't perform batching or proposing operations.

Consider passing empty or dummy secrets for the verifier:

 verifierOpConfig, err := opdevnet.BuildOPConfig(
   deployConfig,
-  secrets.Batcher,
-  secrets.Proposer,
+  eth.SignerEmpty{}, // dummy signer for batcher
+  eth.SignerEmpty{}, // dummy signer for proposer
   l1GenesisBlock,
   l1Deployments.L2OutputOracleProxy,

179-190: Enhance sync verification robustness and readability

Consider the following improvements to the sync verification logic:

  1. Use descriptive constants for magic numbers
  2. Implement exponential backoff for more efficient waiting
  3. Provide more descriptive error messages
+  const (
+    targetSyncBlock = 10 // Block number to verify state root
+    maxWaitIterations = 30 // Maximum number of iterations to wait for sync
+    baseWaitTime = time.Second
+  )
-  const waitBlocks = 30
-  for i := 0; i < waitBlocks; i++ {
-    if verifierL2Backend.BlockChain().CurrentHeader().Number.Uint64() >= 10 {
+  for i := 0; i < maxWaitIterations; i++ {
+    currentBlock := verifierL2Backend.BlockChain().CurrentHeader().Number.Uint64()
+    if currentBlock >= targetSyncBlock {
       // Assert that the verifier and sequencer state roots at block 10 are equal
-      require.Equal(t, verifierL2Backend.BlockChain().GetHeaderByNumber(10).Root, l2Backend.BlockChain().GetHeaderByNumber(10).Root)
+      require.Equal(t, 
+        verifierL2Backend.BlockChain().GetHeaderByNumber(targetSyncBlock).Root,
+        l2Backend.BlockChain().GetHeaderByNumber(targetSyncBlock).Root,
+        "State root mismatch at block %d", targetSyncBlock,
+      )
       break
-    } else if i == waitBlocks-1 {
-      t.Fatalf("verifier only synced to block %v", verifierL2Backend.BlockChain().CurrentHeader().Number)
+    } else if i == maxWaitIterations-1 {
+      t.Fatalf("Verifier sync timeout: reached block %d, expected >= %d after %d iterations",
+        currentBlock, targetSyncBlock, maxWaitIterations)
     }
-    time.Sleep(time.Second * time.Duration(l1Config.BlockTime))
+    // Exponential backoff with base wait time
+    waitTime := baseWaitTime * time.Duration(1<<uint(i))
+    if waitTime > time.Duration(l1Config.BlockTime)*time.Second {
+      waitTime = time.Duration(l1Config.BlockTime)*time.Second
+    }
+    time.Sleep(waitTime)
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9ede6c1 and 73f5f8d.

📒 Files selected for processing (5)
  • docs/docs/build/create-an-app-with-monomer.md (1 hunks)
  • docs/docs/build/interact.md (1 hunks)
  • e2e/e2e.go (1 hunks)
  • integrations/integrations.go (3 hunks)
  • opdevnet/opdevnet_test.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • e2e/e2e.go
  • docs/docs/build/create-an-app-with-monomer.md
  • docs/docs/build/interact.md
  • integrations/integrations.go
🔇 Additional comments (3)
opdevnet/opdevnet_test.go (3)

81-81: LGTM: URL reachability check is well-placed

The L1 URL reachability check is appropriately placed after the L1 node setup and uses the correct assertion method.


Line range hint 89-102: LGTM: Sequencer node setup is properly configured

The sequencer node setup follows best practices with:

  • Proper L2 node initialization
  • Correct JWT configuration
  • Appropriate URL configurations
  • Well-placed reachability check

140-177: LGTM: Verifier node setup is well-structured

The verifier node setup is properly implemented with:

  • Distinct ports for each service
  • Correct reuse of JWT secret
  • Explicit disabling of sequencer mode

@natebeauregard natebeauregard merged commit 7aa7d97 into main Dec 17, 2024
16 checks passed
@natebeauregard natebeauregard deleted the nkb.verifier-flag branch December 17, 2024 20:23
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.

2 participants