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: upgrademonitor #2922

Closed
wants to merge 31 commits into from
Closed

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Dec 11, 2023

Closes #2894

Demo on Loom

@rootulp rootulp self-assigned this Dec 11, 2023
@rootulp
Copy link
Collaborator Author

rootulp commented Dec 12, 2023

On second thought, this tool can accept a pre-signed transaction that is generated but not published. When the upgrademonitor detects that the network is upgrade-able, it can publish the pre-signed transaction.

.gitignore Show resolved Hide resolved
@rootulp rootulp requested a review from staheri14 December 12, 2023 20:32
@rootulp rootulp marked this pull request as ready for review December 12, 2023 20:32
Copy link
Contributor

coderabbitai bot commented Dec 12, 2023

Walkthrough

The changes involve the introduction of a new tool called "Upgrade Monitor" for the Celestia network. This tool is designed to monitor upgrades by querying version tallies, publishing transactions, and checking upgrade eligibility through a gRPC interface. The .gitignore file has been updated to ignore specific files and directories related to this tool. New Go source files have been added to handle command-line flags, establish gRPC connections, and execute the monitoring functionality.

Changes

File(s) Change Summary
.gitignore Added entries to ignore the tools/upgrademonitor/upgrademonitor directory and all .json files within the tools/upgrademonitor directory.
tools/upgrademonitor/README.md Added documentation for the "Upgrade Monitor" tool, including build and usage instructions.
tools/upgrademonitor/cmd/flags.go, tools/upgrademonitor/cmd/root.go Introduced new Go source files for handling command-line flags and executing the upgrade monitoring command.
tools/upgrademonitor/internal/grpc.go Added a new Go source file defining gRPC functions for querying version tallies, publishing transactions, and checking upgrade eligibility.

Assessment against linked issues

Objective Addressed Explanation
Tool to monitor network upgrade status and auto submit MsgTryUpgrade The introduced "Upgrade Monitor" tool fulfills the requirement to monitor network upgrade status and auto-submit MsgTryUpgrade transactions.

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

Comment on lines 14 to 48
var rootCmd = &cobra.Command{
Use: "upgrademonitor",
Short: "upgrademonitor monitors that status of upgrades on a Celestia network.",
RunE: func(cmd *cobra.Command, args []string) error {
conn, err := grpc.Dial(grpcEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return fmt.Errorf("could not connect: %v", err)
}
defer conn.Close()

ticker := time.NewTicker(time.Duration(pollFrequency) * time.Second)
defer ticker.Stop()

for {
select {
case <-ticker.C:
resp, err := internal.QueryVersionTally(conn, version)
if err != nil {
return err
}
fmt.Printf("version: %v, voting: %v, threshold: %v, total: %v\n", version, resp.GetVotingPower(), resp.GetThresholdPower(), resp.GetTotalVotingPower())

if internal.IsUpgradeable(resp) {
fmt.Printf("the network is upgradeable so publishing %v\n", pathToTransaction)
resp, err := internal.Publish(conn, pathToTransaction)
if err != nil {
return err
}
fmt.Printf("published transaction: %v\n", resp.TxHash)
return nil // stop the upgrademonitor
}
}
}
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The cobra.Command setup looks correct, and the RunE function is well-structured to establish a gRPC connection, create a ticker for polling, and handle the upgrade monitoring logic. However, there are a few points to consider:

  1. The use of insecure.NewCredentials() in line 18 is potentially concerning from a security perspective. It's important to ensure that this is acceptable for the intended use case and that any risks are mitigated.

  2. The RunE function will exit after publishing a transaction when the network is upgradeable (line 43). This behavior should be clearly documented, and it should be confirmed that this is the desired behavior, as it means the tool will not continue to monitor after an upgrade is detected and handled.

  3. The logging in lines 34 and 42 is directly to stdout. Consider using a logging framework that can be configured for different environments and verbosity levels.

  4. Error handling in lines 19 and 39 is straightforward, but it might be beneficial to log additional context or perform cleanup before returning the error.

  5. The infinite loop starting at line 27 will run indefinitely unless an upgrade is detected. Ensure that there is a way to gracefully shut down the application if needed, such as by handling a termination signal.

tools/upgrademonitor/cmd/root.go Outdated Show resolved Hide resolved
tools/upgrademonitor/internal/grpc.go Show resolved Hide resolved
tools/upgrademonitor/internal/grpc.go Outdated Show resolved Hide resolved
tools/upgrademonitor/internal/grpc.go Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@celestia-bot celestia-bot requested a review from a team December 13, 2023 00:41
Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

Great work. Left a few comments to go over

tools/upgrademonitor/cmd/root.go Outdated Show resolved Hide resolved
@@ -0,0 +1,13 @@
module github.com/celestiaorg/celestia-app/tools/upgrademonitor
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the rationale for this having it's own go.mod?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm upgrademonitor is distinct from celestia-app in that the binary will be used independently of celestia-app. A distinct go.mod allows upgrademonitor to manage its own dependencies.

Your question made me realize that we could even extract upgrademonitor entirely to its own repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we want it in a stand alone repo: celestiaorg/upgrade-monitor#1

tools/upgrademonitor/cmd/root.go Show resolved Hide resolved
tools/upgrademonitor/cmd/root.go Outdated Show resolved Hide resolved
@rootulp rootulp marked this pull request as draft December 13, 2023 16:58
@rootulp
Copy link
Collaborator Author

rootulp commented Dec 13, 2023

Closing in favor of putting this in a stand-alone repo.

@rootulp rootulp closed this Dec 13, 2023
@rootulp rootulp deleted the rp/upgrade-monitor branch December 14, 2023 05:30
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.

Tool to monitor network upgrade status and auto submit MsgTryUpgrade
2 participants