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(zetaclient): use on-chain chain struct #2834

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Sep 5, 2024

Use the on-chain chain.Chain{} rather than the local on disk config. This ensure that all attributes in chain.Chain{} are consistent across zetaclientd deployments rather than relying on operators to configure things manually.

Also inject the evmJSONRPC client as parameter rather than constructing it in NewObserver to match the style of all the other observers.

We should probably also update the config structure to not use the chain.Chain{} type so people don't accidentally use this type in unexpected places.

Closes #2829

Summary by CodeRabbit

  • New Features

    • Enhanced observer initialization with a more flexible configuration approach.
    • Introduced a new mock JSON RPC client for improved testing capabilities.
  • Bug Fixes

    • Streamlined test setup by removing unnecessary configuration steps for EVM observers.
  • Documentation

    • Updated documentation to reflect changes in observer parameters and configuration.
  • Tests

    • Improved test cases to align with the new observer initialization logic, ensuring accurate validation.

Copy link
Contributor

coderabbitai bot commented Sep 5, 2024

Walkthrough

Walkthrough

The changes involve modifications to the NewObserver function and related components in the observer and signer modules of the ZetaChain project. The updates include parameter adjustments for improved modularity, the introduction of a new JSON RPC client, and enhancements to test cases to ensure compatibility with the new configurations.

Changes

Files Change Summary
zetaclient/chains/evm/observer/observer.go Modified NewObserver function to replace evmCfg with chain and added evmJSONRPC parameter.
zetaclient/chains/evm/observer/observer_test.go Updated MockEVMObserver to include evmJSONRPC, modified test cases to reflect new observer parameters.
zetaclient/chains/evm/signer/signer_test.go Streamlined getNewEvmChainObserver function by removing unnecessary configuration steps and using direct parameters.
zetaclient/orchestrator/bootstrap.go Introduced ethrpc2 dependency and modified syncObserverMap to use evmJSONRPCClient.

Assessment against linked issues

Objective Addressed Explanation
zetaclient_last_scanned_block_number metric emission for EVM chains (#2829) It is unclear if the changes affect metric emission.
Unify chainParams, signer, and observers lifecycle (#2519) The changes do not address lifecycle unification.

Possibly related issues


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

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

codecov bot commented Sep 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.94%. Comparing base (ba3b1c0) to head (44a0cf6).
Report is 10 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #2834   +/-   ##
========================================
  Coverage    66.94%   66.94%           
========================================
  Files          370      370           
  Lines        20965    20967    +2     
========================================
+ Hits         14035    14037    +2     
  Misses        6290     6290           
  Partials       640      640           
Files with missing lines Coverage Δ
zetaclient/chains/evm/observer/observer.go 62.08% <100.00%> (ø)
zetaclient/orchestrator/bootstrap.go 58.40% <100.00%> (+0.37%) ⬆️

Copy link
Contributor

@CryptoFewka CryptoFewka left a comment

Choose a reason for hiding this comment

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

Approved under the expectation that e2e finishes enough that you are comfortable with it @gartnera

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

Outside diff range, codebase verification and nitpick comments (5)
zetaclient/chains/evm/signer/signer_test.go (1)

Line range hint 75-87: Refactor: Simplify the creation of new EVM chain observer in tests.

The changes in the getNewEvmChainObserver function streamline the setup by directly using the chain identifier and a new mock JSON RPC client. This approach reduces the complexity and improves the clarity of the test setup. However, ensure that the new mock setup aligns with the expected behavior in production environments to maintain test reliability.

zetaclient/orchestrator/bootstrap.go (1)

302-309: Enhance modularity by introducing ethrpc2 for Ethereum JSON-RPC client management.

The introduction of ethrpc2 as a dependency and its use in the syncObserverMap function enhances the modularity and configurability of the observer's interaction with Ethereum nodes. This change should improve the maintainability of the code by centralizing the RPC client creation. Ensure that the new client is thoroughly tested in different network conditions to verify its robustness.

zetaclient/chains/evm/observer/observer_test.go (1)

Line range hint 103-141: Refactor: Update MockEVMObserver to include evmJSONRPC parameter.

The addition of the evmJSONRPC parameter to the MockEVMObserver function enhances the flexibility and configurability of the observer setup in tests. This change ensures that the observer can utilize a JSON RPC client during initialization, which is crucial for simulating real-world scenarios in tests. Ensure that the new parameter is properly documented and that existing tests are updated to reflect this change.

zetaclient/chains/evm/observer/observer.go (2)

Line range hint 64-94: Refactor Suggestion: Modular Initialization of Observer

The changes in the NewObserver function are aligned with the PR's objectives to enhance modularity and use on-chain configurations. However, there are several areas where further improvements can be made:

  1. Error Handling: The error from base.NewObserver is wrapped, which is good practice. However, consider adding more context or specific error handling strategies for different types of errors that might be more common in this context.

  2. Dependency Injection: The addition of evmJSONRPC as a parameter is a good move towards dependency injection, which facilitates easier unit testing and modularity. Ensure that all dependencies are similarly managed to maintain consistency across the codebase.

  3. Configuration Validation: Before proceeding with the observer initialization, validate the chain and chainParams to ensure they meet expected criteria. This preemptive check can prevent runtime errors and improve system stability.

  4. Resource Management: Consider how resources are managed within the observer, especially with the new configurations. For instance, if there are resources that need to be closed or cleaned up, ensure that these are handled correctly to avoid resource leaks.

  5. Logging and Metrics: The function initializes various components and logs errors. Ensure that successful initializations are also logged for better traceability. Additionally, consider enhancing the telemetry by adding more granular metrics for the initialization process.

Consider implementing the above suggestions to enhance the robustness, maintainability, and performance of the observer initialization process.


24-24: Architecture Advice: Use of Interfaces and Dependency Injection

The introduction of interfaces.EVMJSONRPCClient and its use in the NewObserver function is a commendable approach to dependency injection, which not only makes the code more testable but also enhances its modularity. This change aligns with modern software design practices and helps in isolating the observer functionality from specific client implementations, which can vary between different blockchain networks or configurations.

Suggestions:

  • Expand Interface Usage: Consider defining more granular interfaces for other components within the observer, such as logging, database access, and metric collection. This would further decouple the implementation details from the observer logic, making the system more adaptable to changes.

  • Configuration Objects: Instead of passing multiple parameters to the NewObserver function, consider using a configuration object. This can encapsulate all necessary parameters and can be validated in a single step, simplifying the function signature and improving code readability.

  • Unit Testing: With the new changes, ensure that unit tests are updated or added to cover the new logic and configurations. Mocking the interfaces can help in testing various scenarios without the need for actual blockchain connections.

Implementing these suggestions can lead to a more robust, scalable, and maintainable system, which is crucial for blockchain-based systems where reliability and performance are paramount.

Also applies to: 64-94

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ba3b1c0 and 44a0cf6.

Files selected for processing (4)
  • zetaclient/chains/evm/observer/observer.go (4 hunks)
  • zetaclient/chains/evm/observer/observer_test.go (8 hunks)
  • zetaclient/chains/evm/signer/signer_test.go (2 hunks)
  • zetaclient/orchestrator/bootstrap.go (2 hunks)
Additional context used
Path-based instructions (4)
zetaclient/chains/evm/signer/signer_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/orchestrator/bootstrap.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/observer/observer_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/observer/observer.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

Learnings (1)
zetaclient/chains/evm/signer/signer_test.go (1)
Learnt from: ws4charlie
PR: zeta-chain/node#2411
File: zetaclient/orchestrator/chain_activate.go:116-181
Timestamp: 2024-07-05T00:02:36.493Z
Learning: The `CreateSignerObserverEVM` function in `zetaclient/orchestrator/chain_activate.go` is covered by unit tests in `zetaclient/orchestrator/chain_activate_test.go`.

zetaclient/chains/evm/observer/observer.go Show resolved Hide resolved
Copy link
Contributor

@swift1337 swift1337 left a comment

Choose a reason for hiding this comment

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

Let's also remove this from yml config. Ideally, we only need an endpoint for RPC per each chain in that conf.

zetaclient/orchestrator/bootstrap.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zetaclient_last_scanned_block_number no longer being emitted for EVM chains
4 participants