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: move the key parameters to env #137

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

abuzaforfagun
Copy link

@abuzaforfagun abuzaforfagun commented Feb 14, 2025

This PR will fix the issue #58

Changes:

  • Move defaultLoopDur to config
  • Move defaultBlocksToSearch to config

Summary by CodeRabbit

  • New Features

    • Introduced configurable operational parameters via new environment variables and command-line options, allowing users to set a custom loop duration (default: 60s) and a maximum block search range (default: 2000) for Ethereum event processing.
  • Documentation

    • Updated user documentation to detail the new configuration options and their default values.

Copy link

coderabbitai bot commented Feb 14, 2025

Walkthrough

The changes add two new configuration parameters to control the loop duration and block search range. New environment variables and corresponding command-line options are introduced, and the configuration structs in both CLI and orchestrator packages are extended to include these parameters. Hardcoded defaults are replaced with dynamic values parsed from the configuration, and related logging and looping logic is updated across several orchestrator components.

Changes

File(s) Change Summary
.env.example, README.md Added new environment variables (PEGGO_LOOP_DURATION, PEGGO_BLOCKS_TO_SEARCH) and corresponding command-line options (--loop_duration, --blocks_to_search) with default values, along with minor formatting adjustments.
cmd/peggo/options.go, orchestrator/orchestrator.go Extended configuration structs with new fields (loopDuration, numberOfBlocksToSearch / LoopDuration, NumberOfBlocksToSearch) and initialized them from environment variables.
cmd/peggo/orchestrator.go, orchestrator/batch_creator.go, orchestrator/oracle.go, orchestrator/signer.go Updated loop and block search logic by replacing hardcoded defaults with values from configuration; enhanced error handling and logging to reflect dynamic parameters.

Sequence Diagram(s)

sequenceDiagram
    participant U as User/CLI
    participant E as Environment Loader
    participant C as Config Setup
    participant O as Orchestrator
    participant BC as BatchCreator
    participant OR as Oracle
    participant SG as Signer

    U->>E: Read .env and CLI parameters
    E->>C: Provide config values (loopDuration, BlocksToSearch)
    C->>O: Initialize orchestrator configuration
    O->>BC: Start batch creation using LoopDuration
    O->>OR: Run oracle loop with BlocksToSearch and LoopDuration
    O->>SG: Run signer loop using LoopDuration
Loading

Poem

I'm a hopping rabbit, quick on my feet,
With fresh config changes, my journey's complete.
Loop durations now dance to a flexible beat,
And blocks to search, oh so neat!
Commands and options, a bouncy new treat.
Hop along the code, smooth and fleet!
Hoppy days, let every change shine bright!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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

@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

🧹 Nitpick comments (5)
orchestrator/orchestrator.go (1)

33-34: Add documentation for LoopDuration field.

Similar to NumberOfBlocksToSearch, add a comment explaining the purpose and usage of LoopDuration.

+// Duration between each loop iteration for various orchestrator processes
 LoopDuration         time.Duration
cmd/peggo/orchestrator.go (1)

142-145: Improve error handling for loop duration parsing.

Consider:

  1. Define the default duration as a constant
  2. Log a warning when falling back to default
+const defaultLoopDuration = 60 * time.Second

 loopDur, err = time.ParseDuration(*cfg.loopDuration)
 if err != nil {
-    loopDur = 60 * time.Second
+    log.WithError(err).Warnf("invalid loop duration %q, using default %v", *cfg.loopDuration, defaultLoopDuration)
+    loopDur = defaultLoopDuration
 }
orchestrator/oracle.go (1)

90-93: Update the comment to reflect the new configuration.

The comment still references the old constant name defaultBlocksToSearch.

-// ensure the block range is within defaultBlocksToSearch
+// ensure the block range is within configured NumberOfBlocksToSearch
cmd/peggo/options.go (1)

489-490: Fix typo in comment.

The comment has a typo in "serach".

-/** Default block to serach **/
+/** Default blocks to search **/
README.md (1)

92-93: Use consistent naming convention for command-line options.

The new options use underscores (--loop_duration, --blocks_to_search) while other options use hyphens (e.g., --eth-chain-id, --cosmos-chain-id). Consider using hyphens for consistency.

-      --loop_duration                    Specify the main the loop duration (env $PEGGO_LOOP_DURATION) (default "60s")
-      --blocks_to_search                 Specify maximum block range for Ethereum event query (env $PEGGO_BLOCKS_TO_SEARCH) (default 2000)
+      --loop-duration                    Specify the main the loop duration (env $PEGGO_LOOP_DURATION) (default "60s")
+      --blocks-to-search                 Specify maximum block range for Ethereum event query (env $PEGGO_BLOCKS_TO_SEARCH) (default 2000)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5317d5c and d3c600f.

📒 Files selected for processing (8)
  • .env.example (1 hunks)
  • README.md (3 hunks)
  • cmd/peggo/options.go (3 hunks)
  • cmd/peggo/orchestrator.go (2 hunks)
  • orchestrator/batch_creator.go (1 hunks)
  • orchestrator/oracle.go (2 hunks)
  • orchestrator/orchestrator.go (1 hunks)
  • orchestrator/signer.go (1 hunks)
🔇 Additional comments (4)
orchestrator/signer.go (1)

23-25: LGTM! Good use of configured loop duration.

The changes correctly use the configured loop duration for both logging and execution.

orchestrator/batch_creator.go (1)

17-19: LGTM! Good use of configured loop duration.

The changes correctly use the configured loop duration for both logging and execution.

orchestrator/oracle.go (1)

31-33: LGTM! Good addition of debug logging.

The changes improve observability by logging the loop duration and make the duration configurable.

cmd/peggo/options.go (1)

276-277: LGTM! Good addition of configuration fields.

The new fields follow the project's conventions and are properly typed.

Comment on lines +35 to 39
// Maximum block range for Ethereum event query. If the orchestrator has been offline for a long time,
// the oracle loop can potentially run longer than defaultLoopDur due to a surge of events. This usually happens
// when there are more than ~50 events to claim in a single run.
NumberOfBlocksToSearch uint64
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider using uint64 consistently.

The NumberOfBlocksToSearch field uses uint64, which is appropriate for block numbers. However, ensure this type is used consistently across the codebase for block-related values.


🏁 Script executed:

#!/bin/bash
# Check for inconsistent block number types
rg -A 1 "block.*uint|block.*int" --type go

Length of output: 301


Ensure Consistent Block Number Types Across Files

Please update block number types for consistency. While the organizer/orchestrator.go file correctly uses uint64 for NumberOfBlocksToSearch, our search revealed that in orchestrator/relayer.go block numbers are converted to int64 (e.g., using int64(vs.Height) and int64(batch.Block)). Aligning these types across the codebase would reduce potential confusion or type-mismatch issues, unless using int64 is required by external API constraints. Please either refactor the relayer code to use uint64 where applicable or add documentation explaining the need for the current discrepancy.

Comment on lines +4 to +5
PEGGO_LOOP_DURATION=60s
PEGGO_BLOCKS_TO_SEARCH=2000
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for the new configuration values.

The code should validate:

  1. PEGGO_LOOP_DURATION is a valid duration string (e.g., "60s", "1m").
  2. PEGGO_BLOCKS_TO_SEARCH is a positive number.

Would you like me to generate the validation code for these configuration values?

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