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 coordinated zetaclient restart #3252

Merged
merged 8 commits into from
Dec 18, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Dec 6, 2024

Add an OperationalFlags resource to zetacore which will be used for various operational functionality. The initial field will be restart_height which will be used for scheduling a coordinated zetaclient restart (#3248).

The next thing I will add to this resource is a minimum_version field for for the minimum version check.

This PR is just zetacore functionality at the moment. Once I get initial reviews, I will continue to add the zetaclient side, add additional unit test coverage, and generate files.

TODO:

  • zetacore test coverage
  • state import/export
  • basic zetaclient implementation
  • zetaclient unit tests
  • full e2e tests

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced functionality for managing and querying operational flags within the ZetaChain framework.
    • Added command-line interface command for updating operational flags.
    • Expanded end-to-end testing for operational flags functionality.
  • Bug Fixes

    • Enhanced test coverage for authorization management related to operational flags.
  • Documentation

    • Updated message types and RPC methods for operational flags in the API documentation.
  • Chores

    • Added new constants and message types to improve operational flags handling.

@gartnera gartnera added the ADMIN_TESTS Run make start-admin-tests label Dec 6, 2024
@gartnera gartnera requested a review from a team as a code owner December 6, 2024 03:20
Copy link
Contributor

coderabbitai bot commented Dec 6, 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
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces a series of enhancements to the ZetaChain codebase, primarily focusing on operational flags. Key changes include the addition of a new test case for operational flags, the introduction of new Protocol Buffers definitions, and the implementation of methods for querying and updating operational flags. The changes also expand the command-line interface to support operational flags updates and enhance the testing framework for authorization management.

Changes

File Path Change Summary
cmd/zetae2e/local/local.go Added new test case e2etests.TestOperationalFlagsName to adminTestRoutine in localE2ETest.
e2e/e2etests/e2etests.go Introduced constant TestOperationalFlagsName and a new E2E test for operational flags functionality.
e2e/e2etests/test_operational_flags.go Added function TestOperationalFlags to validate operational flags functionality.
proto/zetachain/zetacore/observer/operational.proto Defined new message type OperationalFlags with field restart_height.
proto/zetachain/zetacore/observer/query.proto Added RPC method OperationalFlags and message types QueryOperationalFlagsRequest and QueryOperationalFlagsResponse.
proto/zetachain/zetacore/observer/tx.proto Introduced method UpdateOperationalFlags and message types MsgUpdateOperationalFlags and MsgUpdateOperationalFlagsResponse.
x/authority/types/authorization_list.go Updated OperationPolicyMessages to include "/zetachain.zetacore.observer.MsgUpdateOperationalFlags".
x/authority/types/authorization_list_test.go Enhanced test coverage for AuthorizationList methods.
x/observer/client/cli/tx.go Added command CmdUpdateOperationalFlags() to transaction commands.
x/observer/client/cli/tx_update_operational_flags.go Introduced CLI command for updating operational flags with JSON file support.
x/observer/keeper/grpc_query_operational_flags.go Added method OperationalFlags for querying operational flags via gRPC.
x/observer/keeper/msg_server_update_operational_flags.go Introduced function UpdateOperationalFlags for updating operational flags.
x/observer/keeper/operational_flags.go Added methods SetOperationalFlags and GetOperationalFlags for managing operational flags.
x/observer/types/codec.go Registered MsgUpdateOperationalFlags in codec and interface registry.
x/observer/types/keys.go Introduced constant OperationalFlagsKey.
x/observer/types/message_update_operational_flags.go Defined message type MsgUpdateOperationalFlags with necessary methods and validations.

Possibly related issues

Suggested labels

UPGRADE_TESTS, SOLANA_TESTS

Suggested reviewers

  • fbac
  • kingpinXD
  • ws4charlie
  • lumtis
  • skosito
  • swift1337

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.

Copy link

github-actions bot commented Dec 6, 2024

!!!WARNING!!!
nosec detected in the following files: x/observer/client/cli/tx_update_operational_flags.go

Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.

Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.

Pay extra attention to the way #nosec is being used in the files listed above.

@github-actions github-actions bot added the nosec label Dec 6, 2024
@gartnera gartnera force-pushed the zetaclient-cooridinated-restart branch from dcac2fb to ca2cc9f Compare December 6, 2024 03:21
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 82.23684% with 27 lines in your changes missing coverage. Please review.

Project coverage is 61.77%. Comparing base (dbfd3f1) to head (2d5f95c).
Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
zetaclient/maintenance/shutdown_listener.go 73.41% 18 Missing and 3 partials ⚠️
x/observer/keeper/grpc_query_operational_flags.go 70.00% 2 Missing and 1 partial ⚠️
zetaclient/zetacore/client_operationalflags.go 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3252      +/-   ##
===========================================
+ Coverage    61.62%   61.77%   +0.15%     
===========================================
  Files          433      440       +7     
  Lines        31037    31163     +126     
===========================================
+ Hits         19126    19251     +125     
+ Misses       11052    11049       -3     
- Partials       859      863       +4     
Files with missing lines Coverage Δ
x/authority/types/authorization_list.go 100.00% <ø> (ø)
x/observer/genesis.go 100.00% <100.00%> (ø)
...rver/keeper/msg_server_update_operational_flags.go 100.00% <100.00%> (ø)
x/observer/keeper/operational_flags.go 100.00% <100.00%> (ø)
...observer/types/message_update_operational_flags.go 100.00% <100.00%> (ø)
x/observer/types/operational.go 100.00% <100.00%> (ø)
x/observer/keeper/grpc_query_operational_flags.go 70.00% <70.00%> (ø)
zetaclient/zetacore/client_operationalflags.go 0.00% <0.00%> (ø)
zetaclient/maintenance/shutdown_listener.go 73.41% <73.41%> (ø)

... and 3 files with indirect coverage changes

@gartnera gartnera force-pushed the zetaclient-cooridinated-restart branch from ca2cc9f to 56a323b Compare December 6, 2024 03:30
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: 11

🧹 Outside diff range and nitpick comments (8)
proto/zetachain/zetacore/observer/operational.proto (1)

6-10: Enhance message documentation and consider field validation

The message structure looks good, but consider these improvements:

  1. Add comprehensive message documentation:
+// OperationalFlags defines configuration flags for coordinating operational tasks
+// across the network, such as client restarts and version updates.
 message OperationalFlags {
   // Height for a coordinated zetaclient restart.
   // Will be ignored if missed.
   int64 restart_height = 1;
 }
  1. Consider adding field validation using protobuf's built-in constraints:
   // Height for a coordinated zetaclient restart.
   // Will be ignored if missed.
-  int64 restart_height = 1;
+  int64 restart_height = 1 [(gogoproto.moretags) = "validate:\"gte=0\""];
🧰 Tools
🪛 buf (1.47.2)

6-10: Message "OperationalFlags" should have a non-empty comment for documentation.

(COMMENT_MESSAGE)

x/observer/keeper/grpc_query_operational_flags.go (1)

13-26: Add unit tests for the query handler

The test coverage report indicates this code is not covered by tests. Consider adding tests for:

  • Nil request handling
  • Flags not found scenario
  • Valid flags retrieval

Would you like me to help generate comprehensive unit tests for this query handler?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 16-25: x/observer/keeper/grpc_query_operational_flags.go#L16-L25
Added lines #L16 - L25 were not covered by tests

x/observer/keeper/operational_flags.go (2)

9-26: Add comprehensive test coverage

The keeper methods lack test coverage. Consider adding tests for:

  • Setting and retrieving flags
  • Handling empty/nil cases
  • Concurrent access scenarios

Would you like me to help generate a comprehensive test suite for these keeper methods?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 9-13: x/observer/keeper/operational_flags.go#L9-L13
Added lines #L9 - L13 were not covered by tests


[warning] 16-25: x/observer/keeper/operational_flags.go#L16-L25
Added lines #L16 - L25 were not covered by tests


9-14: Consider atomic updates for operational flags

Since this involves coordinated restarts, ensure atomic updates to prevent race conditions:

  1. Consider implementing a version number or timestamp for updates
  2. Add validation to ensure updates are monotonic
  3. Consider implementing optimistic locking for concurrent updates
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 9-13: x/observer/keeper/operational_flags.go#L9-L13
Added lines #L9 - L13 were not covered by tests

e2e/e2etests/test_operational_flags.go (2)

19-20: Enhance comment clarity regarding test safety

The comment about low height could be more explicit about its purpose.

Consider updating the comment:

-	// always set to low height so it's ignored by zetaclient
+	// Set to current height + 1 to ensure the value is valid but too low to trigger
+	// an actual zetaclient restart, preventing unintended side effects during testing

11-38: Enhance test coverage with additional scenarios

The test currently only covers the happy path. Consider adding test cases for:

  1. Initial state validation
  2. Authorization failure
  3. Invalid operational flags values

Consider structuring the test as subtests:

func TestOperationalFlags(r *runner.E2ERunner, _ []string) {
    t := r.T
    t.Run("happy path - successful update", func(t *testing.T) {
        // existing test code
    })
    
    t.Run("should fail with unauthorized account", func(t *testing.T) {
        // test with non-operational policy account
    })
    
    t.Run("should fail with invalid flags", func(t *testing.T) {
        // test with invalid restart height
    })
}
proto/zetachain/zetacore/observer/tx.proto (1)

35-36: Consider adding authorization metadata

The RPC method definition could benefit from additional metadata about authorization requirements.

Consider adding a comment documenting the operational policy requirement:

+  // UpdateOperationalFlags updates the operational flags. Requires operational policy authorization.
   rpc UpdateOperationalFlags(MsgUpdateOperationalFlags)
       returns (MsgUpdateOperationalFlagsResponse);
x/authority/types/authorization_list.go (1)

minimum_version field implementation requires tracking

The codebase search reveals no explicit tracking or implementation plans for the minimum_version field in OperationalFlags. To ensure proper feature implementation:

  • Create a dedicated issue to track the minimum_version field implementation
  • Document the requirements and acceptance criteria for this feature
  • Consider adding a TODO comment in the relevant code section to reference the tracking issue
🔗 Analysis chain

Line range hint 144-147: Verify tracking of minimum_version implementation

The PR objectives mention plans to add a minimum_version field to OperationalFlags, but this isn't reflected in the current implementation.

Let's check if there's a tracking issue:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for issues tracking minimum_version implementation
gh issue list --search "minimum_version in:title,body" --state open

Length of output: 69


Script:

#!/bin/bash
# Let's check for any mentions of minimum_version in the codebase
rg -i "minimum.?version" -A 2 -B 2

# Also check for any TODO/FIXME comments related to version
rg -i "todo.*version|fixme.*version" -A 2 -B 2

# Check commit messages for any mentions
git log --grep="minimum.?version" --oneline

# Look for any related issues in pull request descriptions
gh pr list --search "minimum_version in:title,body" --state open

Length of output: 1128

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 96099ee and 56a323b.

⛔ Files ignored due to path filters (4)
  • x/observer/types/operational.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/observer/types/query.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/observer/types/query.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
  • x/observer/types/tx.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
📒 Files selected for processing (16)
  • cmd/zetae2e/local/local.go (1 hunks)
  • e2e/e2etests/e2etests.go (2 hunks)
  • e2e/e2etests/test_operational_flags.go (1 hunks)
  • proto/zetachain/zetacore/observer/operational.proto (1 hunks)
  • proto/zetachain/zetacore/observer/query.proto (2 hunks)
  • proto/zetachain/zetacore/observer/tx.proto (3 hunks)
  • x/authority/types/authorization_list.go (1 hunks)
  • x/authority/types/authorization_list_test.go (1 hunks)
  • x/observer/client/cli/tx.go (1 hunks)
  • x/observer/client/cli/tx_update_operational_flags.go (1 hunks)
  • x/observer/keeper/grpc_query_operational_flags.go (1 hunks)
  • x/observer/keeper/msg_server_update_operational_flags.go (1 hunks)
  • x/observer/keeper/operational_flags.go (1 hunks)
  • x/observer/types/codec.go (2 hunks)
  • x/observer/types/keys.go (1 hunks)
  • x/observer/types/message_update_operational_flags.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (16)
cmd/zetae2e/local/local.go (1)

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

x/authority/types/authorization_list.go (1)

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

x/observer/client/cli/tx.go (1)

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

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

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

x/observer/keeper/grpc_query_operational_flags.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/codec.go (1)

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

e2e/e2etests/e2etests.go (1)

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

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

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

x/observer/keeper/operational_flags.go (1)

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

e2e/e2etests/test_operational_flags.go (1)

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

x/observer/keeper/msg_server_update_operational_flags.go (1)

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

x/observer/client/cli/tx_update_operational_flags.go (1)

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

x/authority/types/authorization_list_test.go (1)

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

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

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

x/observer/types/message_update_operational_flags.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/keeper/grpc_query_operational_flags.go

[warning] 16-25: x/observer/keeper/grpc_query_operational_flags.go#L16-L25
Added lines #L16 - L25 were not covered by tests

x/observer/keeper/operational_flags.go

[warning] 9-13: x/observer/keeper/operational_flags.go#L9-L13
Added lines #L9 - L13 were not covered by tests


[warning] 16-25: x/observer/keeper/operational_flags.go#L16-L25
Added lines #L16 - L25 were not covered by tests

x/observer/keeper/msg_server_update_operational_flags.go

[warning] 16-23: x/observer/keeper/msg_server_update_operational_flags.go#L16-L23
Added lines #L16 - L23 were not covered by tests


[warning] 25-27: x/observer/keeper/msg_server_update_operational_flags.go#L25-L27
Added lines #L25 - L27 were not covered by tests

x/observer/types/message_update_operational_flags.go

[warning] 15-19: x/observer/types/message_update_operational_flags.go#L15-L19
Added lines #L15 - L19 were not covered by tests


[warning] 22-23: x/observer/types/message_update_operational_flags.go#L22-L23
Added lines #L22 - L23 were not covered by tests


[warning] 26-27: x/observer/types/message_update_operational_flags.go#L26-L27
Added lines #L26 - L27 were not covered by tests


[warning] 30-33: x/observer/types/message_update_operational_flags.go#L30-L33
Added lines #L30 - L33 were not covered by tests


[warning] 35-35: x/observer/types/message_update_operational_flags.go#L35
Added line #L35 was not covered by tests


[warning] 38-40: x/observer/types/message_update_operational_flags.go#L38-L40
Added lines #L38 - L40 were not covered by tests


[warning] 43-47: x/observer/types/message_update_operational_flags.go#L43-L47
Added lines #L43 - L47 were not covered by tests

🪛 buf (1.47.2)
proto/zetachain/zetacore/observer/operational.proto

2-2: Files with package "zetachain.zetacore.observer" must be within a directory "zetachain/zetacore/observer" relative to root but were in directory "proto/zetachain/zetacore/observer".

(PACKAGE_DIRECTORY_MATCH)


6-10: Message "OperationalFlags" should have a non-empty comment for documentation.

(COMMENT_MESSAGE)

🔇 Additional comments (11)
x/observer/keeper/grpc_query_operational_flags.go (1)

21-22: Document the rationale for ignoring 'found' status

While the comment indicates this is intentional, it would be helpful to document why this is acceptable. Consider:

  1. What is returned when flags are not found?
  2. Is this behavior safe for all clients?
✅ Verification successful

Let me check the implementation of GetOperationalFlags to understand the default behavior.


Ignoring 'found' status is acceptable in this context

The current implementation is correct and safe because:

  1. When flags are not found, GetOperationalFlags returns a zero-value OperationalFlags struct containing RestartHeight: 0
  2. The RestartHeight field is documented as "Will be ignored if missed", making the zero-value behavior appropriate
  3. Clients properly handle the response without needing the found status, as evidenced by the e2e tests
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any error checks for missing flags in clients
rg -A 5 "OperationalFlags\(" --type go

Length of output: 12589


Script:

#!/bin/bash
# Check the implementation of GetOperationalFlags and OperationalFlags type
ast-grep --pattern 'func (k Keeper) GetOperationalFlags(ctx $_) (val types.OperationalFlags, found bool) {
  $$$
}'

# Check the OperationalFlags type definition
ast-grep --pattern 'type OperationalFlags struct {
  $$$
}'

Length of output: 1355

x/observer/client/cli/tx.go (1)

35-35: LGTM!

The command registration follows the established pattern and is correctly placed in the command list.

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

23-23: LGTM: Codec registration follows standard pattern

The registration of MsgUpdateOperationalFlags in both the amino codec and interface registry follows the established Cosmos SDK patterns.

Also applies to: 40-40

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

144-149: LGTM: Message definitions follow proto best practices

The message definitions are well-structured:

  • Non-nullable constraint on operationalFlags ensures required field validation
  • Empty response message follows the pattern used by other similar operations
x/authority/types/authorization_list.go (1)

23-23: LGTM: Appropriate authorization level

The message URL is correctly added to OperationPolicyMessages, which aligns with the operational nature of coordinated zetaclient restarts.

proto/zetachain/zetacore/observer/query.proto (2)

17-17: LGTM!

The import statement is correctly placed and follows the alphabetical ordering convention.


176-179: LGTM!

The message definitions follow protobuf best practices:

  • Empty request message for simple queries
  • Response message with non-nullable field
  • Clear and consistent naming
x/authority/types/authorization_list_test.go (1)

402-402: LGTM!

The addition of MsgUpdateOperationalFlags to the operational policy message list is consistent with the feature's authorization requirements.

cmd/zetae2e/local/local.go (1)

411-411: LGTM!

The addition of TestOperationalFlagsName to the admin test suite ensures proper end-to-end testing of the operational flags feature.

e2e/e2etests/e2etests.go (2)

143-143: LGTM: Constant declaration follows conventions.

The constant TestOperationalFlagsName is well-placed in the admin tests section and follows the established naming pattern.


859-864: Enhance test description and verify test function.

While the test registration follows the correct pattern, consider:

  1. Expanding the description to be more specific about what aspects of operational flags are being tested.
  2. Consider adding relevant arguments if the test needs to be parameterized.

Let's verify the test function implementation:

✅ Verification successful

Enhance test description to reflect operational flags restart height functionality

The test function implementation shows that this E2E test specifically verifies:

  • Querying operational flags
  • Updating the restart height through operational policy
  • Verifying the updated restart height

Consider updating the test description to: "verifies operational flags functionality for updating and querying restart height via operational policy"

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the TestOperationalFlags function exists and its implementation

# Search for the TestOperationalFlags function implementation
ast-grep --pattern 'func TestOperationalFlags($$$) {
  $$$
}'

Length of output: 2126

x/observer/keeper/operational_flags.go Show resolved Hide resolved
x/observer/keeper/operational_flags.go Show resolved Hide resolved
x/observer/types/message_update_operational_flags.go Outdated Show resolved Hide resolved
x/observer/types/message_update_operational_flags.go Outdated Show resolved Hide resolved
x/observer/client/cli/tx_update_operational_flags.go Outdated Show resolved Hide resolved
x/observer/types/keys.go Outdated Show resolved Hide resolved
proto/zetachain/zetacore/observer/query.proto 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: 11

🧹 Outside diff range and nitpick comments (6)
proto/zetachain/zetacore/observer/operational.proto (1)

6-10: Enhance message documentation for better API clarity

The OperationalFlags message would benefit from comprehensive documentation explaining its purpose and usage in the context of coordinated zetaclient restarts.

Consider adding this documentation:

+// OperationalFlags defines configuration flags for coordinating operational tasks
+// across the network, such as zetaclient restarts and version management.
 message OperationalFlags {
   // Height for a coordinated zetaclient restart.
   // Will be ignored if missed.
   int64 restart_height = 1;
 }
🧰 Tools
🪛 buf (1.47.2)

6-10: Message "OperationalFlags" should have a non-empty comment for documentation.

(COMMENT_MESSAGE)

x/observer/keeper/grpc_query_operational_flags.go (1)

13-26: Add test coverage for the query handler

The query handler lacks test coverage. Consider adding tests for:

  • Nil request handling
  • Not found scenario
  • Successful retrieval

Would you like me to help generate comprehensive test cases for this query handler?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 16-25: x/observer/keeper/grpc_query_operational_flags.go#L16-L25
Added lines #L16 - L25 were not covered by tests

x/observer/keeper/operational_flags.go (1)

1-26: Add comprehensive test coverage

Both keeper methods lack test coverage. Consider adding tests for:

  • Setting and retrieving flags
  • Validation scenarios
  • Error handling cases
  • Event emission verification

Would you like me to help generate a comprehensive test suite for these keeper methods?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 9-13: x/observer/keeper/operational_flags.go#L9-L13
Added lines #L9 - L13 were not covered by tests


[warning] 16-25: x/observer/keeper/operational_flags.go#L16-L25
Added lines #L16 - L25 were not covered by tests

e2e/e2etests/test_operational_flags.go (2)

11-38: Enhance test coverage with additional test cases

While the happy path is well tested, consider adding the following test cases:

  1. Attempt to update flags with unauthorized account
  2. Validate behavior with invalid restart height
  3. Test concurrent updates
  4. Verify persistence across chain restarts

Here's a suggested test case for unauthorized access:

func TestOperationalFlagsUnauthorized(r *runner.E2ERunner, _ []string) {
    // Attempt update with non-policy account
    updateMsg := observertypes.NewMsgUpdateOperationalFlags(
        r.ZetaTxServer.MustGetAccountAddressFromName("regular_user"),
        observertypes.OperationalFlags{
            RestartHeight: 100,
        },
    )
    
    _, err := r.ZetaTxServer.BroadcastTx("regular_user", updateMsg)
    require.Error(r, err)
    require.Contains(r, err.Error(), "unauthorized")
}

19-20: Document the purpose of low restart height

The comment about setting a low height could be more explicit about why this is necessary for the test.

-	// always set to low height so it's ignored by zetaclient
+	// Set restart height to current height + 1 to ensure it's in the past
+	// relative to the chain's current height, preventing actual client restarts
proto/zetachain/zetacore/observer/query.proto (1)

176-176: Consider adding pagination to request message

The empty request message could benefit from pagination support for future extensibility when the number of operational flags grows.

-message QueryOperationalFlagsRequest {}
+message QueryOperationalFlagsRequest {
+    cosmos.base.query.v1beta1.PageRequest pagination = 1;
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 96099ee and 56a323b.

⛔ Files ignored due to path filters (4)
  • x/observer/types/operational.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/observer/types/query.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/observer/types/query.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
  • x/observer/types/tx.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
📒 Files selected for processing (16)
  • cmd/zetae2e/local/local.go (1 hunks)
  • e2e/e2etests/e2etests.go (2 hunks)
  • e2e/e2etests/test_operational_flags.go (1 hunks)
  • proto/zetachain/zetacore/observer/operational.proto (1 hunks)
  • proto/zetachain/zetacore/observer/query.proto (2 hunks)
  • proto/zetachain/zetacore/observer/tx.proto (3 hunks)
  • x/authority/types/authorization_list.go (1 hunks)
  • x/authority/types/authorization_list_test.go (1 hunks)
  • x/observer/client/cli/tx.go (1 hunks)
  • x/observer/client/cli/tx_update_operational_flags.go (1 hunks)
  • x/observer/keeper/grpc_query_operational_flags.go (1 hunks)
  • x/observer/keeper/msg_server_update_operational_flags.go (1 hunks)
  • x/observer/keeper/operational_flags.go (1 hunks)
  • x/observer/types/codec.go (2 hunks)
  • x/observer/types/keys.go (1 hunks)
  • x/observer/types/message_update_operational_flags.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (16)
x/observer/client/cli/tx.go (1)

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

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

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

x/authority/types/authorization_list.go (1)

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

cmd/zetae2e/local/local.go (1)

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

e2e/e2etests/e2etests.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/keeper/grpc_query_operational_flags.go (1)

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

x/observer/keeper/msg_server_update_operational_flags.go (1)

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

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

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

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

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

x/observer/client/cli/tx_update_operational_flags.go (1)

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

x/authority/types/authorization_list_test.go (1)

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

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

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

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

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

e2e/e2etests/test_operational_flags.go (1)

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

x/observer/keeper/operational_flags.go (1)

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

🪛 buf (1.47.2)
proto/zetachain/zetacore/observer/operational.proto

2-2: Files with package "zetachain.zetacore.observer" must be within a directory "zetachain/zetacore/observer" relative to root but were in directory "proto/zetachain/zetacore/observer".

(PACKAGE_DIRECTORY_MATCH)


6-10: Message "OperationalFlags" should have a non-empty comment for documentation.

(COMMENT_MESSAGE)

🪛 GitHub Check: codecov/patch
x/observer/keeper/grpc_query_operational_flags.go

[warning] 16-25: x/observer/keeper/grpc_query_operational_flags.go#L16-L25
Added lines #L16 - L25 were not covered by tests

x/observer/keeper/msg_server_update_operational_flags.go

[warning] 16-23: x/observer/keeper/msg_server_update_operational_flags.go#L16-L23
Added lines #L16 - L23 were not covered by tests


[warning] 25-27: x/observer/keeper/msg_server_update_operational_flags.go#L25-L27
Added lines #L25 - L27 were not covered by tests

x/observer/types/message_update_operational_flags.go

[warning] 15-19: x/observer/types/message_update_operational_flags.go#L15-L19
Added lines #L15 - L19 were not covered by tests


[warning] 22-23: x/observer/types/message_update_operational_flags.go#L22-L23
Added lines #L22 - L23 were not covered by tests


[warning] 26-27: x/observer/types/message_update_operational_flags.go#L26-L27
Added lines #L26 - L27 were not covered by tests


[warning] 30-33: x/observer/types/message_update_operational_flags.go#L30-L33
Added lines #L30 - L33 were not covered by tests


[warning] 35-35: x/observer/types/message_update_operational_flags.go#L35
Added line #L35 was not covered by tests


[warning] 38-40: x/observer/types/message_update_operational_flags.go#L38-L40
Added lines #L38 - L40 were not covered by tests


[warning] 43-47: x/observer/types/message_update_operational_flags.go#L43-L47
Added lines #L43 - L47 were not covered by tests

x/observer/keeper/operational_flags.go

[warning] 9-13: x/observer/keeper/operational_flags.go#L9-L13
Added lines #L9 - L13 were not covered by tests


[warning] 16-25: x/observer/keeper/operational_flags.go#L16-L25
Added lines #L16 - L25 were not covered by tests

🔇 Additional comments (9)
proto/zetachain/zetacore/observer/operational.proto (1)

7-9: Clarify restart coordination behavior

The comment "Will be ignored if missed" needs elaboration on the coordination mechanism to prevent race conditions or inconsistent states across nodes.

Could you clarify:

  1. What happens if some nodes see the height and others miss it?
  2. Is there a cleanup mechanism after the restart height passes?

Consider adding a status field to track whether the restart was successfully executed.

x/observer/client/cli/tx.go (1)

35-35: LGTM!

The new command is properly integrated into the existing command structure.

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

23-23: LGTM: Codec registration follows established pattern

The registration of MsgUpdateOperationalFlags in both RegisterCodec and RegisterInterfaces follows the consistent pattern used for other message types.

Also applies to: 40-40

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

35-36: LGTM: Well-structured Protobuf definitions

The new message types and RPC method are well-defined, following Protobuf best practices and existing patterns in the codebase.

Also applies to: 144-149

x/authority/types/authorization_list.go (1)

23-23: Verify authorization scope

The message URL is correctly added to OperationPolicyMessages. Let's verify that no other files grant different authorization levels for this message.

✅ Verification successful

Authorization scope verified

The message handler properly enforces authorization through the authority keeper's CheckAuthorization method. The message URL is correctly placed in OperationPolicyMessages and the handler implementation confirms that authorization is checked before executing the operation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent authorization level for MsgUpdateOperationalFlags

# Search for any other authorization definitions for this message
rg -l "MsgUpdateOperationalFlags.*Policy" --type go

# Search for any policy checks in the message handler
ast-grep --pattern 'func $_(MsgUpdateOperationalFlags) {
  $$$
}'

Length of output: 121


Script:

#!/bin/bash
# Let's try a broader search to find all references to this message type and authorization

# Search for the message type definition and usage
rg "MsgUpdateOperationalFlags" --type go -A 5

# Search for any policy-related files that might contain authorization rules
fd -e go -E 'vendor/*' -E 'testutil/*' . | grep -i 'policy\|auth' | xargs cat

# Search specifically in the observer module for handler implementation
fd -e go . | grep -i 'observer.*handler' | xargs cat

Length of output: 103531


Script:

#!/bin/bash
# Let's check the message handler implementation and authorization checks

# Search for the message handler implementation
rg -A 10 "func.*MsgUpdateOperationalFlags" x/observer/keeper/

# Search for authorization checks in the handler
rg -A 5 "CheckAuthorization.*MsgUpdateOperationalFlags" x/observer/keeper/

Length of output: 140


Script:

#!/bin/bash
# Let's try a different approach to find the message handler and authorization checks

# Search for the message handler file and its contents
fd -t f msg_server_update_operational_flags.go . | xargs cat

# Search for authorization checks in keeper files
fd -t f -e go . | grep -i 'keeper' | xargs rg -l "CheckAuthorization"

Length of output: 5195

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

178-180: LGTM: Response message structure

The response message is well-structured with proper use of gogoproto.nullable = false.

x/authority/types/authorization_list_test.go (1)

402-402: LGTM: Well-structured test addition

The addition of MsgUpdateOperationalFlags to the OperationalPolicyMessageList is appropriate and maintains consistency with the existing test structure.

cmd/zetae2e/local/local.go (1)

411-411: LGTM: Clean test integration

The addition of TestOperationalFlagsName to the admin test routine is well-integrated and maintains the existing concurrent execution pattern.

e2e/e2etests/e2etests.go (1)

859-864: Verify the test function implementation.

The test definition looks good and follows the established pattern for admin tests. However, let's verify the implementation of TestOperationalFlags.

✅ Verification successful

Test implementation is complete and follows best practices

The test function implementation in e2e/e2etests/test_operational_flags.go is well-structured and comprehensive:

  • Verifies the initial operational flags state
  • Updates the restart height using the operational policy account
  • Confirms the update was successful through a follow-up query
  • Properly handles error cases with appropriate assertions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the test function implementation.

# Test: Search for the test function implementation.
ast-grep --pattern $'func TestOperationalFlags(r *runner.E2ERunner, _ []string) {
  $$$
}'

Length of output: 2154

x/observer/keeper/operational_flags.go Show resolved Hide resolved
x/observer/keeper/operational_flags.go Show resolved Hide resolved
x/observer/types/message_update_operational_flags.go Outdated Show resolved Hide resolved
x/observer/types/message_update_operational_flags.go Outdated Show resolved Hide resolved
x/observer/client/cli/tx_update_operational_flags.go Outdated Show resolved Hide resolved
x/observer/client/cli/tx_update_operational_flags.go Outdated Show resolved Hide resolved
x/observer/types/keys.go Outdated Show resolved Hide resolved
proto/zetachain/zetacore/observer/query.proto Outdated Show resolved Hide resolved
ws4charlie
ws4charlie previously approved these changes Dec 9, 2024
Copy link
Contributor

@ws4charlie ws4charlie left a comment

Choose a reason for hiding this comment

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

the idea looks clear

Copy link
Contributor

@kingpinXD kingpinXD left a comment

Choose a reason for hiding this comment

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

  • Unit tests need to be added , ideally one for every new file .

  • Cosider adding operational Flags to the genesis state ,and implementing import export .

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

The structure and the idea look good to me.
For new state variable, we also need to add a field in the genesis and update export/import

@gartnera gartnera force-pushed the zetaclient-cooridinated-restart branch from 8afffab to 5c1e821 Compare December 11, 2024 18:44
@gartnera gartnera requested a review from kingpinXD December 11, 2024 19:52
@gartnera gartnera force-pushed the zetaclient-cooridinated-restart branch 3 times, most recently from baa2beb to 864154c Compare December 16, 2024 18:35
@gartnera gartnera force-pushed the zetaclient-cooridinated-restart branch from 864154c to 4654698 Compare December 16, 2024 18:51
@gartnera gartnera requested review from lumtis, ws4charlie and a team December 16, 2024 21:48
@gartnera gartnera force-pushed the zetaclient-cooridinated-restart branch from eba17df to bb11313 Compare December 17, 2024 00:50
Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

LGTM

x/authority/types/authorization_list_test.go Show resolved Hide resolved
e2e/e2etests/e2etests.go Outdated Show resolved Hide resolved
@swift1337 swift1337 self-requested a review December 17, 2024 12:20
@gartnera gartnera requested a review from kingpinXD December 17, 2024 17:27
@gartnera gartnera added this pull request to the merge queue Dec 17, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 17, 2024
@gartnera gartnera added the CONSENSUS_BREAKING_ACK Acknowledge a consensus breaking change label Dec 17, 2024
@gartnera gartnera added this pull request to the merge queue Dec 17, 2024
Merged via the queue into develop with commit 8d25c74 Dec 18, 2024
49 checks passed
@gartnera gartnera deleted the zetaclient-cooridinated-restart branch December 18, 2024 00:13
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 nosec
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants