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

Feat/start height #8

Merged
merged 25 commits into from
Aug 15, 2024
Merged

Feat/start height #8

merged 25 commits into from
Aug 15, 2024

Conversation

sh-cha
Copy link
Collaborator

@sh-cha sh-cha commented Aug 8, 2024

Added a config to start from a specific height. If you enter l2 height, it starts from the l2 block number +1 of the last output smaller than that.

A batch can also start from a specific height or from an initialized l2 height.

Summary by CodeRabbit

  • New Features

    • Introduced context-aware method signatures across various components, enabling better management of cancellations and timeouts.
    • Added a command in the documentation for querying the status of the bot via curl.
  • Bug Fixes

    • Improved error handling mechanisms to enhance the reliability of transaction processing.
  • Documentation

    • Enhanced clarity in documentation regarding new configuration options for transaction management.
  • Refactor

    • Streamlined method signatures and control flows across the Node, Broadcaster, and Executor components for better readability and maintainability.
  • Chores

    • Updated the version of the github.com/initia-labs/OPinit dependency from v0.4.1 to v0.4.2.

@sh-cha sh-cha self-assigned this Aug 8, 2024
@sh-cha sh-cha requested a review from a team as a code owner August 8, 2024 09:16
executor/executor.go Outdated Show resolved Hide resolved
executor/host/query.go Outdated Show resolved Hide resolved
node/node.go Show resolved Hide resolved
Copy link

coderabbitai bot commented Aug 14, 2024

Walkthrough

This update significantly enhances the system's robustness and adaptability through improved context management, error handling, and configuration flexibility. By integrating context.Context into multiple function signatures, the changes enable better cancellation and timeout handling. Modifications to transaction parameters and logging levels refine performance and clarity, collectively strengthening the application's operational flow. Additionally, new status reporting structures improve monitoring capabilities across components.

Changes

Files Change Summary
node/broadcaster/process.go, executor/child/child.go Enhanced methods with improved error handling, context management, and configurable parameters for transaction processing and output queries.
README.md Added command for querying bot status using curl for enhanced user documentation.
go.mod Updated github.com/initia-labs/OPinit dependency version from v0.4.1 to v0.4.2.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Broadcaster
    participant Node
    participant Context

    User->>Broadcaster: Initiate transaction
    Broadcaster->>Context: Create context
    Context-->>Broadcaster: Return context
    Broadcaster->>Node: Process new block with context
    Node-->>Broadcaster: Handle event with context
    Broadcaster-->>User: Transaction completed
Loading

🐰 In fields of code, I hop and play,
Enhancements sprout like blooms in May.
Contexts added, errors tamed,
Robust and swift, our work proclaimed.
With each new line, we leap with glee,
A brighter future, come code with me! 🌼


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

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

executor/child/withdraw.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

Do we also have feature to prevent feeding old oracle prices??

like when the op bot started in past start block (not latest block), then we have to wait until we are reaching to latest l1 height before feeding oracle price to l2.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 048b675 and 0e2e4b7.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (48)
  • README.md (1 hunks)
  • bot/types/bot.go (1 hunks)
  • cmd/opinitd/reset.go (1 hunks)
  • cmd/opinitd/start.go (2 hunks)
  • executor/README.md (2 hunks)
  • executor/batch/batch.go (4 hunks)
  • executor/batch/handler.go (9 hunks)
  • executor/batch/status.go (1 hunks)
  • executor/batch/utils.go (1 hunks)
  • executor/celestia/celestia.go (2 hunks)
  • executor/celestia/handler.go (1 hunks)
  • executor/celestia/status.go (1 hunks)
  • executor/child/child.go (6 hunks)
  • executor/child/deposit.go (2 hunks)
  • executor/child/handler.go (2 hunks)
  • executor/child/msgs.go (1 hunks)
  • executor/child/oracle.go (3 hunks)
  • executor/child/query.go (4 hunks)
  • executor/child/status.go (1 hunks)
  • executor/child/withdraw.go (6 hunks)
  • executor/executor.go (7 hunks)
  • executor/host/batch.go (2 hunks)
  • executor/host/deposit.go (2 hunks)
  • executor/host/handler.go (4 hunks)
  • executor/host/host.go (3 hunks)
  • executor/host/msgs.go (1 hunks)
  • executor/host/query.go (3 hunks)
  • executor/host/status.go (1 hunks)
  • executor/host/withdraw.go (4 hunks)
  • executor/status.go (1 hunks)
  • executor/types/batch.go (2 hunks)
  • executor/types/config.go (6 hunks)
  • go.mod (1 hunks)
  • keys/codec.go (1 hunks)
  • keys/keyring.go (1 hunks)
  • merkle/merkle.go (1 hunks)
  • node/broadcaster/broadcaster.go (3 hunks)
  • node/broadcaster/process.go (6 hunks)
  • node/broadcaster/tx.go (3 hunks)
  • node/broadcaster/types/config.go (3 hunks)
  • node/broadcaster/types/db.go (3 hunks)
  • node/db.go (1 hunks)
  • node/node.go (4 hunks)
  • node/process.go (14 hunks)
  • node/rpcclient/client.go (2 hunks)
  • node/types/handler.go (3 hunks)
  • node/types/status.go (1 hunks)
  • types/context.go (1 hunks)
Files skipped from review due to trivial changes (6)
  • README.md
  • executor/batch/utils.go
  • executor/child/msgs.go
  • executor/host/status.go
  • keys/codec.go
  • keys/keyring.go
Files skipped from review as they are similar to previous changes (31)
  • bot/types/bot.go
  • cmd/opinitd/reset.go
  • executor/batch/handler.go
  • executor/batch/status.go
  • executor/celestia/handler.go
  • executor/celestia/status.go
  • executor/child/deposit.go
  • executor/child/handler.go
  • executor/child/oracle.go
  • executor/child/status.go
  • executor/child/withdraw.go
  • executor/host/batch.go
  • executor/host/deposit.go
  • executor/host/msgs.go
  • executor/host/query.go
  • executor/host/withdraw.go
  • executor/status.go
  • executor/types/batch.go
  • go.mod
  • merkle/merkle.go
  • node/broadcaster/broadcaster.go
  • node/broadcaster/process.go
  • node/broadcaster/tx.go
  • node/broadcaster/types/config.go
  • node/broadcaster/types/db.go
  • node/db.go
  • node/node.go
  • node/process.go
  • node/rpcclient/client.go
  • node/types/status.go
  • types/context.go
Additional context used
golangci-lint
executor/child/query.go

24-24: copylocks: QueryBridgeInfo passes lock by value: github.com/initia-labs/opinit-bots-go/executor/child.Child contains sync.Once contains sync/atomic.Uint32 contains sync/atomic.noCopy

(govet)

Markdownlint
executor/README.md

76-76: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


228-228: Column: 1
Hard tabs

(MD010, no-hard-tabs)


229-229: Column: 1
Hard tabs

(MD010, no-hard-tabs)


230-230: Column: 1
Hard tabs

(MD010, no-hard-tabs)


231-231: Column: 1
Hard tabs

(MD010, no-hard-tabs)


232-232: Column: 1
Hard tabs

(MD010, no-hard-tabs)

Additional comments not posted (35)
node/types/handler.go (5)

18-18: Contextual enhancement approved for EventHandlerFn.

The addition of context.Context improves the function's ability to handle context-related operations.


27-27: Contextual enhancement approved for TxHandlerFn.

The inclusion of context.Context is a beneficial change for managing context in concurrent operations.


35-35: Contextual enhancement approved for BeginBlockHandlerFn.

Adding context.Context enhances the function's ability to manage context effectively.


43-43: Contextual enhancement approved for EndBlockHandlerFn.

The addition of context.Context is a positive change for context management.


50-50: Contextual enhancement approved for RawBlockHandlerFn.

Including context.Context improves the function's context management capabilities.

cmd/opinitd/start.go (2)

19-20: Addition of flagPollingInterval approved.

The new constant enhances the configurability of the command by allowing users to specify the polling interval.


47-58: Enhancements in startCmd function approved.

The use of an error group and retrieval of the polling interval improve the command's robustness and configurability.

Ensure that WithErrGrp and WithPollingInterval are correctly implemented and used throughout the codebase.

Verification successful

Verify consistent usage of WithErrGrp and WithPollingInterval across the codebase.

Both functions are implemented in types/context.go and used in cmd/opinitd/start.go. Ensure they are used consistently and appropriately in other parts of the codebase if applicable.

  • WithErrGrp is implemented in types/context.go and used in cmd/opinitd/start.go.
  • WithPollingInterval is implemented in types/context.go and used in cmd/opinitd/start.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and usage of `WithErrGrp` and `WithPollingInterval`.

# Test: Search for the implementation and usage of `WithErrGrp`.
rg --type go 'WithErrGrp'

# Test: Search for the implementation and usage of `WithPollingInterval`.
rg --type go 'WithPollingInterval'

Length of output: 392

executor/host/handler.go (3)

Line range hint 15-19:
Contextual enhancement approved for beginBlockHandler.

The addition of context.Context prepares the function for improved context management.


Line range hint 24-64:
Contextual enhancement approved for endBlockHandler.

Including context.Context enhances the function's capability for context-aware operations.


Line range hint 65-74:
Contextual enhancement approved for txHandler.

The addition of context.Context aligns with best practices for managing context in asynchronous operations.

executor/child/query.go (3)

Line range hint 24-31:
Ensure proper context usage in QueryBridgeInfo.

The addition of context.Context improves the function's ability to handle cancellation and timeouts. Ensure that the context is correctly propagated in all call sites.

Tools
golangci-lint

24-24: copylocks: QueryBridgeInfo passes lock by value: github.com/initia-labs/opinit-bots-go/executor/child.Child contains sync.Once contains sync/atomic.Uint32 contains sync/atomic.noCopy

(govet)


Line range hint 36-43:
Ensure proper context usage in QueryNextL1Sequence.

The context parameter enhances the function's cancellation and timeout capabilities. Verify that all invocations of this method correctly pass the context.


Line range hint 48-55:
Ensure proper context usage in QueryNextL2Sequence.

The context parameter, along with the height, supports better management of long-running operations. Confirm that all call sites handle the context appropriately.

executor/batch/batch.go (3)

26-26: Ensure context propagation in QueryBatchInfos.

The hostNode interface method now takes a context.Context, allowing for better cancellation and timeout handling. Ensure that implementations of this interface correctly utilize the context.


Line range hint 110-147:
Verify context and startHeight handling in BatchSubmitter.Initialize.

The addition of context.Context and startHeight parameters improves initialization flexibility. Ensure that all calls to this method correctly provide these parameters.


133-137: Review file handling logic.

The conditional logic for setting file flags based on node initialization state is clear and improves flexibility. Ensure that this logic aligns with your intended file handling strategy.

executor/celestia/celestia.go (1)

97-101: Improve error handling in Celestia.Initialize.

The addition of node initialization with error handling ensures that subsequent operations only proceed if the node is successfully initialized. This change enhances robustness.

executor/host/host.go (2)

29-29: Enhancement: Added context to QueryNextL1Sequence.

The addition of context.Context to the QueryNextL1Sequence method improves the interface's ability to handle cancellations and timeouts.


118-127: Improvement: Context and start height added to Initialize.

The Initialize method now supports context management and allows specifying a starting height, enhancing flexibility and control.

Ensure that all calls to Initialize are updated to use the new signature.

Verification successful

Let's refine the search to capture all instances of Initialize calls and ensure they match the new signature.


Update Confirmed: Host.Initialize uses new signature in executor/executor.go.

The Initialize method in executor/host/host.go is correctly called with the new signature in executor/executor.go. Ensure that all other instances across the codebase are similarly updated.

  • executor/executor.go: ex.host.Initialize(ctx, hostStartHeight, ex.child, ex.batch, int64(bridgeInfo.BridgeId))
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `Host.Initialize` use the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'Initialize(context.Context, uint64, childNode, batchNode, int64)'

Length of output: 86


Script:

#!/bin/bash
# Description: Search for all calls to `Initialize` in the codebase to verify they match the new signature.

# Test: Search for the function usage with a broader pattern to capture all calls.
rg --type go 'Initialize\(' -A 3

Length of output: 2759

executor/child/child.go (3)

33-34: Enhancement: Added context to QueryLastOutput and QueryOutput.

The addition of context.Context to these methods improves their ability to handle cancellations and timeouts.


56-57: Enhancement: Added initializeTree and initializeTreeFn to Child.

These fields improve the initialization logic and state management of the Child struct.


124-138: Improvement: Enhanced initialization in Child.Initialize.

The method now supports additional parameters for improved configurability and sets up an initialization function.

Ensure that all calls to Initialize are updated to use the new signature.

Verification successful

Verification Complete: Child.Initialize Signature Updated Correctly

The Child.Initialize method is called with the correct new signature in the codebase, ensuring proper initialization with the additional parameters.

  • executor/executor.go: Correct usage of Child.Initialize with the new parameters.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to `Child.Initialize` use the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'Initialize(uint64, uint64, hostNode, opchildtypes.BridgeInfo)'

Length of output: 83


Script:

#!/bin/bash
# Description: Verify all calls to `Child.Initialize` use the new signature.

# Test: Search for the function usage with a more flexible pattern.
rg --type go 'Initialize\(' -A 5

Length of output: 3483

executor/types/config.go (5)

11-18: Enhancement: Introduced NodeConfig type.

The NodeConfig type consolidates node-specific settings, improving configuration management and maintainability.


20-30: Enhancement: Added validation for NodeConfig.

The Validate method ensures essential fields are populated, enhancing robustness and preventing misconfiguration.


40-45: Refactor: Updated Config to use NodeConfig.

The Config structure now includes NodeConfig instances for L1, L2, and DA nodes, simplifying configuration management.


84-109: Improvement: Updated DefaultConfig to use NodeConfig.

The function now initializes L1Node, L2Node, and DANode with NodeConfig, providing default values for each node type.


134-144: Enhancement: Added NodeConfig validation in Config.Validate.

The method now ensures that all NodeConfig instances are validated, enhancing robustness and preventing misconfiguration.

executor/executor.go (5)

49-64: Configuration access improvements are approved.

The changes enhance clarity by using nested configuration properties. This is consistent with the new configuration structure.


76-119: Error handling improvements are approved.

Replacing panics with error returns enhances robustness. The encapsulation of start height logic into getStartHeights improves readability.


Line range hint 122-137:
Concurrency management is well-implemented.

The use of types.ErrGrp for managing concurrent operations is appropriate and ensures clean shutdowns.


Line range hint 166-201:
DA node creation logic is sound.

The method correctly handles different chain types and initializes DA nodes with appropriate error handling.


203-236: Start heights retrieval logic is well-structured.

The method encapsulates start height logic effectively, enhancing readability and maintainability.

executor/README.md (3)

19-69: Configuration restructuring is well-executed.

The use of nested objects improves clarity and maintainability. New parameters like gas_adjustment and tx_timeout enhance transaction control.


73-135: Start height configuration examples are clear and informative.

The examples effectively demonstrate how different configurations affect start heights, providing valuable guidance.

Tools
Markdownlint

76-76: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


Line range hint 136-232:
Comprehensive documentation enhances understanding.

The detailed explanations and code snippets improve understanding of the Executor's operations, covering handler rules, deposit, withdrawal, oracle, and batch processes.

Tools
Markdownlint

228-228: Column: 1
Hard tabs

(MD010, no-hard-tabs)


229-229: Column: 1
Hard tabs

(MD010, no-hard-tabs)


230-230: Column: 1
Hard tabs

(MD010, no-hard-tabs)


231-231: Column: 1
Hard tabs

(MD010, no-hard-tabs)


232-232: Column: 1
Hard tabs

(MD010, no-hard-tabs)

executor/child/query.go Show resolved Hide resolved
@sh-cha
Copy link
Collaborator Author

sh-cha commented Aug 15, 2024

Do we also have feature to prevent feeding old oracle prices??

like when the op bot started in past start block (not latest block), then we have to wait until we are reaching to latest l1 height before feeding oracle price to l2.

It only sends when the current block is equal to the latest height, but basically the user has to look at the oracle height and decide whether to use the price or not. Also, if it submits a price for an older height than the one already submitted, the simulation will fail with the old height, and this error will be ignored and the Tx will not be submitted.

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, codebase verification and nitpick comments (1)
README.md (1)

67-70: LGTM! Consider adding more context for clarity.

The new section for querying the bot's status is a valuable addition. It might be helpful to provide a brief explanation of what users can expect from the status endpoint, such as the type of information returned or any prerequisites needed to access it.

### Query status

+ This command retrieves the current operational status of the bot. Ensure the bot is running and accessible at the specified address.
```bash
curl localhost:3000/status

</blockquote></details>

</blockquote></details>

<details>
<summary>Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**

<details>
<summary>Commits</summary>

Files that changed from the base of the PR and between 0e2e4b769c6d108d9a4d7c8ded4c329631a4c087 and 6de57c889b065dff106e4dac90465a23daec3a2d.

</details>


<details>
<summary>Files selected for processing (3)</summary>

* README.md (2 hunks)
* executor/child/child.go (6 hunks)
* node/broadcaster/process.go (6 hunks)

</details>








<details>
<summary>Files skipped from review as they are similar to previous changes (2)</summary>

* executor/child/child.go
* node/broadcaster/process.go

</details>




</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@sh-cha sh-cha merged commit f8acae3 into main Aug 15, 2024
3 checks passed
@sh-cha sh-cha deleted the feat/start-height branch August 15, 2024 06:59
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