-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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: cosmovisor batch upgrades #21790
base: main
Are you sure you want to change the base?
Changes from 9 commits
9fd017f
61a09d1
7b34213
60a7362
acaab9f
342723f
6009d24
3fe1cff
7e1bf65
2fb3b68
66c7be2
ba5462f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewBatchAddUpgradeCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "add-batch-upgrade <upgrade1-name>:<path-to-exec1>:<upgrade1-height> .. <upgradeN-name>:<path-to-execN>:<upgradeN-height>", | ||
Short: "Add APP upgrades binary to cosmovisor", | ||
SilenceUsage: true, | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: AddBatchUpgrade, | ||
} | ||
} | ||
|
||
// AddBatchUpgrade takes in multiple specified upgrades and creates a single | ||
// batch upgrade file out of them | ||
func AddBatchUpgrade(cmd *cobra.Command, args []string) error { | ||
cfg, err := GetConfig(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
upgradeInfoPaths := []string{} | ||
for i, as := range args { | ||
a := strings.Split(as, ":") | ||
if len(a) != 3 { | ||
return fmt.Errorf("argument at position %d (%s) is invalid", i, as) | ||
} | ||
upgradeName := filepath.Base(a[0]) | ||
upgradePath := a[1] | ||
upgradeHeight, err := strconv.ParseInt(a[2], 10, 64) | ||
if err != nil { | ||
return fmt.Errorf("upgrade height at position %d (%s) is invalid", i, a[2]) | ||
} | ||
upgradeInfoPath := filepath.Join(cfg.UpgradeInfoFilePath(), upgradeName) | ||
upgradeInfoPaths = append(upgradeInfoPaths, upgradeInfoPath) | ||
if err := AddUpgrade(cfg, true, upgradeHeight, upgradeName, upgradePath, upgradeInfoPath); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
var allData []json.RawMessage | ||
for _, uip := range upgradeInfoPaths { | ||
fileData, err := os.ReadFile(uip) | ||
if err != nil { | ||
return fmt.Errorf("error reading file %s: %w", uip, err) | ||
} | ||
|
||
// Verify it's valid JSON | ||
var jsonData json.RawMessage | ||
if err := json.Unmarshal(fileData, &jsonData); err != nil { | ||
return fmt.Errorf("error parsing JSON from file %s: %w", uip, err) | ||
} | ||
|
||
// Add to our slice | ||
allData = append(allData, jsonData) | ||
} | ||
|
||
// Marshal the combined data | ||
batchData, err := json.MarshalIndent(allData, "", " ") | ||
if err != nil { | ||
return fmt.Errorf("error marshaling combined JSON: %w", err) | ||
} | ||
|
||
// Write to output file | ||
err = os.WriteFile(cfg.UpgradeInfoBatchFilePath(), batchData, 0o600) | ||
if err != nil { | ||
return fmt.Errorf("error writing combined JSON to file: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
Comment on lines
+50
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Action Required: Add Unit Tests for Batch Upgrade Functions The
🔗 Analysis chainLGTM: Batch upgrade processing logic looks good. Consider adding unit tests. The logic for reading, parsing, and combining upgrade info files is well-implemented with proper error handling. The use of However, as mentioned in a previous review, it would be beneficial to add unit tests for the To help with creating unit tests, you can use the following script to identify existing test files and patterns: This will help you understand the current testing structure and conventions used in the project. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Find existing test files and patterns in the cosmovisor directory
# Search for test files
echo "Existing test files:"
fd -e go -e _test.go . tools/cosmovisor
# Search for common test function patterns
echo "\nCommon test function patterns:"
rg -t go '(?m)^func Test\w+\(t \*testing\.T\)' tools/cosmovisor
Length of output: 2291 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't make cosmovisor cometbft specific