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: add zetaclient minimum version check #3320

Merged
merged 3 commits into from
Jan 8, 2025

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Dec 19, 2024

Closes #3248

Should probably check the major version before start too. I don't think there's anything that actually disconnects zetaclient from TSS p2p when the upgrade happens either.

Summary by CodeRabbit

  • New Features

    • Added minimum version validation for zetaclient
    • Introduced version check mechanism before client startup
  • Bug Fixes

    • Enhanced error handling for version compatibility checks
  • Documentation

    • Updated OpenAPI specification with minimum version property
  • Tests

    • Added test cases for version validation and pre-start checks

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request introduces a minimum version check mechanism for the ZetaClient. The changes span multiple files to implement version validation during client startup. The primary objective is to ensure that the ZetaClient meets a specified minimum version requirement, potentially preventing incompatible client versions from running and triggering automatic shutdown if version requirements are not met.

Changes

File Change Summary
cmd/zetaclientd/start.go Restructured TSS service setup with pre-start checks
docs/openapi/openapi.swagger.yaml Added minimum_version property to OpenAPI specification
proto/zetachain/zetacore/observer/operational.proto Introduced minimum_version field in OperationalFlags
x/observer/types/errors.go Added new error variable for invalid minimum version
x/observer/types/operational.go Added semantic version validation for MinimumVersion
zetaclient/maintenance/shutdown_listener.go Implemented version check logic and pre-start checks

Assessment against linked issues

Objective Addressed Explanation
Automatically shut down if version does not match [#3248]
Check minimum version against configured requirement [#3248]

Possibly related PRs

Suggested labels

UPGRADE_LIGHT_TESTS

Suggested reviewers

  • kingpinXD
  • lumtis
  • fbac
  • ws4charlie
  • brewmaster012

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.

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.

@gartnera gartnera added ADMIN_TESTS Run make start-admin-tests CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change labels Dec 19, 2024
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 82.50000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 61.88%. Comparing base (148935c) to head (0c6d0b4).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
zetaclient/maintenance/shutdown_listener.go 81.08% 6 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3320      +/-   ##
===========================================
+ Coverage    61.86%   61.88%   +0.02%     
===========================================
  Files          444      444              
  Lines        31457    31492      +35     
===========================================
+ Hits         19461    19490      +29     
- Misses       11124    11129       +5     
- Partials       872      873       +1     
Files with missing lines Coverage Δ
x/observer/types/operational.go 100.00% <100.00%> (ø)
zetaclient/maintenance/shutdown_listener.go 75.67% <81.08%> (+2.25%) ⬆️

@gartnera gartnera changed the title feat: add minimum version check feat: add zetaclient minimum version check Dec 19, 2024
@gartnera gartnera force-pushed the zetaclient-signer-latency-correction branch from d5d0c22 to d80e97d Compare December 31, 2024 00:27
Base automatically changed from zetaclient-signer-latency-correction to develop December 31, 2024 00:57
@gartnera gartnera force-pushed the zetaclient-version-check branch 3 times, most recently from abbdba6 to ae0816e Compare January 2, 2025 17:23
@gartnera gartnera marked this pull request as ready for review January 2, 2025 17:38
@gartnera gartnera requested a review from a team as a code owner January 2, 2025 17:38
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: 2

🧹 Nitpick comments (7)
zetaclient/maintenance/shutdown_listener.go (2)

169-171: Default version retrieval might benefit from testing.
getVersionDefault references constant.Version. Static analysis indicates these lines are not covered by tests. Adding a brief test ensures code stability if future changes are introduced.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 169-170: zetaclient/maintenance/shutdown_listener.go#L169-L170
Added lines #L169 - L170 were not covered by tests


173-178: Prefix helper is straightforward.
ensurePrefix is concise and clear. Including a small test for edge cases (e.g., empty prefix) might further improve confidence.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 177-177: zetaclient/maintenance/shutdown_listener.go#L177
Added line #L177 was not covered by tests

x/observer/types/operational.go (1)

27-29: Validation for minimum_version is correct, but test coverage for invalid semver is recommended.
This logic properly returns an error if f.MinimumVersion is an invalid semver. However, static analysis indicates no direct test coverage for this path.

Do you want to add or generate a test case verifying the behavior when MinimumVersion is not valid semver?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 28-29: x/observer/types/operational.go#L28-L29
Added lines #L28 - L29 were not covered by tests

x/observer/types/operational_test.go (1)

55-66: Valid version scenarios are tested; consider adding an invalid version test.
The test checks a valid semver. A counterpart test catching invalid semver strings would solidify coverage and confidence in the new logic.

cmd/zetaclientd/start.go (1)

125-129: Confirm TSS setup order and context cancellation.

Initializing TSS after the preflight checks ensures the system only proceeds if validations pass. As an added safeguard, confirm that the TSS setup respects context cancellation (e.g., if the pre-check fails or a shutdown signal is triggered during setup) to avoid partial or corrupted initialization.

docs/openapi/openapi.swagger.yaml (1)

58118-58122: Implementation looks good but could be enhanced.

The property definition and description are clear and well-placed within the operational flags section.

Consider enhancing the schema definition with:

  1. A pattern regex to validate semver format
  2. Example values for better documentation
   minimum_version:
     type: string
+    pattern: '^v\d+\.\d+\.\d+$|^$'
     description: |-
       Minimum version of zetaclient that is allowed to run. This must be either
       a valid semver string (v23.0.1) or empty.
+    example: "v23.0.1"
zetaclient/maintenance/shutdown_listener_test.go (1)

105-131: Enhance version string handling and test coverage

The test case effectively verifies the basic version check functionality, but could be improved in the following areas:

  1. Version strings should consistently follow semantic versioning format (with 'v' prefix)
  2. Consider using constants for version strings to maintain consistency
  3. Add edge cases for version comparison

Consider applying these improvements:

+const (
+    testVersionOk = "v1.1.2"
+    testVersionMin = "v1.1.1"
+)

 t.Run("minimum version ok", func(t *testing.T) {
     client := mocks.NewZetacoreClient(t)
     listener := NewShutdownListener(client, logger)
     listener.getVersion = func() string {
-        return "1.1.2"
+        return testVersionOk
     }

     client.Mock.On("GetOperationalFlags", ctx).Return(observertypes.OperationalFlags{
-        MinimumVersion: "v1.1.1",
+        MinimumVersion: testVersionMin,
     }, nil)

Consider adding test cases for:

  • Equal versions
  • Version with different number of components (e.g., "v1.1" vs "v1.1.0")
  • Invalid version strings
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0c4267 and ae0816e.

⛔ Files ignored due to path filters (2)
  • typescript/zetachain/zetacore/observer/operational_pb.d.ts is excluded by !**/*_pb.d.ts
  • x/observer/types/operational.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
📒 Files selected for processing (8)
  • cmd/zetaclientd/start.go (1 hunks)
  • docs/openapi/openapi.swagger.yaml (1 hunks)
  • proto/zetachain/zetacore/observer/operational.proto (1 hunks)
  • x/observer/types/errors.go (1 hunks)
  • x/observer/types/operational.go (2 hunks)
  • x/observer/types/operational_test.go (2 hunks)
  • zetaclient/maintenance/shutdown_listener.go (5 hunks)
  • zetaclient/maintenance/shutdown_listener_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
x/observer/types/errors.go (1)

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

x/observer/types/operational.go (1)

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

proto/zetachain/zetacore/observer/operational.proto (1)

Pattern **/*.proto: Review the Protobuf definitions, point out issues relative to compatibility, and expressiveness.

x/observer/types/operational_test.go (1)

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

zetaclient/maintenance/shutdown_listener_test.go (1)

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

cmd/zetaclientd/start.go (1)

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

zetaclient/maintenance/shutdown_listener.go (1)

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

🪛 GitHub Check: codecov/patch
x/observer/types/operational.go

[warning] 28-29: x/observer/types/operational.go#L28-L29
Added lines #L28 - L29 were not covered by tests

zetaclient/maintenance/shutdown_listener.go

[warning] 47-48: zetaclient/maintenance/shutdown_listener.go#L47-L48
Added lines #L47 - L48 were not covered by tests


[warning] 67-67: zetaclient/maintenance/shutdown_listener.go#L67
Added line #L67 was not covered by tests


[warning] 169-170: zetaclient/maintenance/shutdown_listener.go#L169-L170
Added lines #L169 - L170 were not covered by tests


[warning] 177-177: zetaclient/maintenance/shutdown_listener.go#L177
Added line #L177 was not covered by tests

🔇 Additional comments (15)
zetaclient/maintenance/shutdown_listener.go (10)

5-6: Imports look appropriate for added functionality.
No immediate issues are detected with adding "fmt" and "strings", as they serve error structuring and prefix handling in this file.


11-11: Semantic version comparison import is appropriate.
Using golang.org/x/mod/semver is a good choice for implementing robust semver checks.


14-14: Constant import is well-scoped.
No concerns regarding the import of github.com/zeta-chain/node/pkg/constant for version retrieval.


29-29: Injecting version retrieval enhances testability.
Declaring getVersion as a function field is a clean approach, allowing you to inject and mock version retrieval for testing.


36-38: Constructor assigns default implementation correctly.
Storing the default version retrieval function in the constructor is neat. This design fosters better modularity and potential overrides.


42-53: Pre-start checks implemented correctly, but lines 47-48 lack test coverage.
The RunPreStartCheck method gracefully retrieves flags and checks versions before P2P starts. However, static analysis warns that lines 47-48 are not covered by tests. Consider adding a failing retrieval scenario test to improve coverage.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 47-48: zetaclient/maintenance/shutdown_listener.go#L47-L48
Added lines #L47 - L48 were not covered by tests


65-67: Comprehensive retry approach for operational flags.
Line 67 returns the wrapped error if retrieval fails after retries. To ensure reliability, consider testing retry-failure scenarios around these lines, as static analysis indicates line 67 lacks coverage.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 67-67: zetaclient/maintenance/shutdown_listener.go#L67
Added line #L67 was not covered by tests


93-98: Typed backoff and retry logic looks sound.
The usage of retry.DoTypedWithBackoffAndRetry is consistent with resilient design. Ensure that potential repeated failures are logged or handled appropriately.


102-105: Immediate return on version check failure ensures timely shutdown.
When checkMinimumVersion fails, returning true promptly signals shutdown. This behavior appears correct. If possible, add integration tests to confirm that a mismatch triggers the intended shutdown logic.


153-167: Version comparison is correct for semver compliance.
The call to ensure a 'v' prefix and subsequent semver.Compare is straightforward and correct. No concurrency, correctness, or security issues detected.

x/observer/types/operational.go (1)

7-7: Importing semver for enhanced validation.
Leveraging golang.org/x/mod/semver aligns with the addition of MinimumVersion checks.

proto/zetachain/zetacore/observer/operational.proto (1)

20-22: New field for minimum version is clearly documented.
The added minimum_version field, along with descriptive comments, is consistent with semver-based validation elsewhere.

x/observer/types/operational_test.go (1)

18-21: Empty OperationalFlags test is appropriate.
Confirming that an empty instance passes validation ensures default behavior remains intact.

x/observer/types/errors.go (1)

74-78: New semantic version error is clearly defined.
ErrOperationalFlagsInvalidMinimumVersion adds clarity and maintains consistency with existing error-handling patterns.

cmd/zetaclientd/start.go (1)

113-118: Ensure pre-start checks handle all required validations gracefully.

The flow introduced here correctly invokes RunPreStartCheck before continuing the startup process. Consider verifying that any additional operational checks (e.g., version compatibility or environment preconditions) are included within this method to avoid unexpected failures later. Otherwise, it appears consistent and aligns well with graceful shutdown handling.

cmd/zetaclientd/start.go Outdated Show resolved Hide resolved
proto/zetachain/zetacore/observer/operational.proto Outdated Show resolved Hide resolved
x/observer/types/operational_test.go Show resolved Hide resolved
@gartnera gartnera requested review from lumtis and a team January 6, 2025 17:32
cmd/zetaclientd/start.go Outdated Show resolved Hide resolved
zetaclient/maintenance/shutdown_listener.go Outdated Show resolved Hide resolved
zetaclient/maintenance/shutdown_listener.go Outdated Show resolved Hide resolved
zetaclient/maintenance/shutdown_listener.go Outdated Show resolved Hide resolved
@gartnera gartnera force-pushed the zetaclient-version-check branch from f2cd32a to bc77fe1 Compare January 7, 2025 16:46
@gartnera gartnera requested a review from swift1337 January 7, 2025 16:46
@gartnera gartnera force-pushed the zetaclient-version-check branch from bc77fe1 to ae373be Compare January 7, 2025 19:48
@gartnera gartnera force-pushed the zetaclient-version-check branch from ae373be to 0c6d0b4 Compare January 8, 2025 17:32
@gartnera gartnera enabled auto-merge January 8, 2025 17:34
@gartnera gartnera added this pull request to the merge queue Jan 8, 2025
Merged via the queue into develop with commit 47c9444 Jan 8, 2025
35 checks passed
@gartnera gartnera deleted the zetaclient-version-check branch January 8, 2025 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADMIN_TESTS Run make start-admin-tests breaking:cli breaking:proto CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zetaclient: add minimum version check
3 participants