Skip to content

Commit

Permalink
chore: added autoselect to every sync command
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler committed Nov 20, 2024
1 parent b7c3aba commit e6892de
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
10 changes: 5 additions & 5 deletions cmd/ksync/commands/blocksync.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func init() {

blockSyncCmd.Flags().StringVarP(&appFlags, "app-flags", "f", "", "custom flags which are applied to the app binary start command. Example: --app-flags=\"--x-crisis-skip-assert-invariants,--iavl-disable-fastnode\"")

blockSyncCmd.Flags().BoolVarP(&reset, "autoselect-binary-version", "a", false, "if provided binary is cosmovisor KSYNC will automatically change the \"current\" symlink to the correct upgrade version")
blockSyncCmd.Flags().BoolVarP(&autoselectBinaryVersion, "autoselect-binary-version", "a", false, "if provided binary is cosmovisor KSYNC will automatically change the \"current\" symlink to the correct upgrade version")
blockSyncCmd.Flags().BoolVarP(&reset, "reset-all", "r", false, "reset this node's validator to genesis state")
blockSyncCmd.Flags().BoolVar(&optOut, "opt-out", false, "disable the collection of anonymous usage data")
blockSyncCmd.Flags().BoolVarP(&debug, "debug", "d", false, "show logs from tendermint app")
Expand Down Expand Up @@ -121,16 +121,16 @@ var blockSyncCmd = &cobra.Command{
return fmt.Errorf("failed to close dbs in engine: %w", err)
}

if err := sources.IsBinaryRecommendedVersion(binaryPath, registryUrl, source, continuationHeight, !y); err != nil {
return fmt.Errorf("failed to check if binary has the recommended version: %w", err)
}

if autoselectBinaryVersion {
if err := sources.SelectCosmovisorVersion(binaryPath, homePath, registryUrl, source, continuationHeight); err != nil {
return fmt.Errorf("failed to autoselect binary version: %w", err)
}
}

if err := sources.IsBinaryRecommendedVersion(binaryPath, registryUrl, source, continuationHeight, !y); err != nil {
return fmt.Errorf("failed to check if binary has the recommended version: %w", err)
}

consensusEngine, err := engines.EngineSourceFactory(engine, homePath, registryUrl, source, rpcServerPort, continuationHeight)
if err != nil {
return fmt.Errorf("failed to create consensus engine for source: %w", err)
Expand Down
7 changes: 7 additions & 0 deletions cmd/ksync/commands/heightsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func init() {

heightSyncCmd.Flags().Int64VarP(&targetHeight, "target-height", "t", 0, "target height (including), if not specified it will sync to the latest available block height")

heightSyncCmd.Flags().BoolVarP(&autoselectBinaryVersion, "autoselect-binary-version", "a", false, "if provided binary is cosmovisor KSYNC will automatically change the \"current\" symlink to the correct upgrade version")
heightSyncCmd.Flags().BoolVarP(&reset, "reset-all", "r", false, "reset this node's validator to genesis state")
heightSyncCmd.Flags().BoolVar(&optOut, "opt-out", false, "disable the collection of anonymous usage data")
heightSyncCmd.Flags().BoolVarP(&debug, "debug", "d", false, "show logs from tendermint app")
Expand Down Expand Up @@ -129,6 +130,12 @@ var heightSyncCmd = &cobra.Command{
return fmt.Errorf("failed to close dbs in engine: %w", err)
}

if autoselectBinaryVersion {
if err := sources.SelectCosmovisorVersion(binaryPath, homePath, registryUrl, source, continuationHeight); err != nil {
return fmt.Errorf("failed to autoselect binary version: %w", err)
}
}

if err := sources.IsBinaryRecommendedVersion(binaryPath, registryUrl, source, continuationHeight, !y); err != nil {
return fmt.Errorf("failed to check if binary has the recommended version: %w", err)
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/ksync/commands/serveblocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func init() {
serveBlocksCmd.Flags().StringVarP(&source, "source", "s", "", "chain-id of the source")
serveBlocksCmd.Flags().StringVar(&registryUrl, "registry-url", utils.DefaultRegistryURL, "URL to fetch latest KYVE Source-Registry")

serveBlocksCmd.Flags().BoolVarP(&autoselectBinaryVersion, "autoselect-binary-version", "a", false, "if provided binary is cosmovisor KSYNC will automatically change the \"current\" symlink to the correct upgrade version")
serveBlocksCmd.Flags().BoolVarP(&reset, "reset-all", "r", false, "reset this node's validator to genesis state")
serveBlocksCmd.Flags().BoolVar(&optOut, "opt-out", false, "disable the collection of anonymous usage data")
serveBlocksCmd.Flags().BoolVarP(&debug, "debug", "d", false, "show logs from tendermint app")
Expand Down Expand Up @@ -109,6 +110,12 @@ var serveBlocksCmd = &cobra.Command{
return fmt.Errorf("failed to close dbs in engine: %w", err)
}

if autoselectBinaryVersion {
if err := sources.SelectCosmovisorVersion(binaryPath, homePath, registryUrl, source, continuationHeight); err != nil {
return fmt.Errorf("failed to autoselect binary version: %w", err)
}
}

if err := sources.IsBinaryRecommendedVersion(binaryPath, registryUrl, source, continuationHeight, !y); err != nil {
return fmt.Errorf("failed to check if binary has the recommended version: %w", err)
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/ksync/commands/servesnapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func init() {

servesnapshotsCmd.Flags().StringVarP(&appFlags, "app-flags", "f", "", "custom flags which are applied to the app binary start command. Example: --app-flags=\"--x-crisis-skip-assert-invariants,--iavl-disable-fastnode\"")

servesnapshotsCmd.Flags().BoolVarP(&autoselectBinaryVersion, "autoselect-binary-version", "a", false, "if provided binary is cosmovisor KSYNC will automatically change the \"current\" symlink to the correct upgrade version")
servesnapshotsCmd.Flags().BoolVarP(&reset, "reset-all", "r", false, "reset this node's validator to genesis state")
servesnapshotsCmd.Flags().BoolVar(&optOut, "opt-out", false, "disable the collection of anonymous usage data")
servesnapshotsCmd.Flags().BoolVarP(&debug, "debug", "d", false, "show logs from tendermint app")
Expand Down Expand Up @@ -122,6 +123,12 @@ var servesnapshotsCmd = &cobra.Command{
return fmt.Errorf("failed to close dbs in engine: %w", err)
}

if autoselectBinaryVersion {
if err := sources.SelectCosmovisorVersion(binaryPath, homePath, registryUrl, source, snapshotHeight); err != nil {
return fmt.Errorf("failed to autoselect binary version: %w", err)
}
}

if err := sources.IsBinaryRecommendedVersion(binaryPath, registryUrl, source, continuationHeight, !y); err != nil {
return fmt.Errorf("failed to check if binary has the recommended version: %w", err)
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/ksync/commands/statesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func init() {

stateSyncCmd.Flags().Int64VarP(&targetHeight, "target-height", "t", 0, "snapshot height, if not specified it will use the latest available snapshot height")

stateSyncCmd.Flags().BoolVarP(&autoselectBinaryVersion, "autoselect-binary-version", "a", false, "if provided binary is cosmovisor KSYNC will automatically change the \"current\" symlink to the correct upgrade version")
stateSyncCmd.Flags().BoolVarP(&reset, "reset-all", "r", false, "reset this node's validator to genesis state")
stateSyncCmd.Flags().BoolVar(&optOut, "opt-out", false, "disable the collection of anonymous usage data")
stateSyncCmd.Flags().BoolVarP(&debug, "debug", "d", false, "show logs from tendermint app")
Expand Down Expand Up @@ -94,6 +95,12 @@ var stateSyncCmd = &cobra.Command{
return fmt.Errorf("state-sync validation checks failed: %w", err)
}

if autoselectBinaryVersion {
if err := sources.SelectCosmovisorVersion(binaryPath, homePath, registryUrl, source, snapshotHeight); err != nil {
return fmt.Errorf("failed to autoselect binary version: %w", err)
}
}

if err := sources.IsBinaryRecommendedVersion(binaryPath, registryUrl, source, snapshotHeight, !y); err != nil {
return fmt.Errorf("failed to check if binary has the recommended version: %w", err)
}
Expand Down
7 changes: 6 additions & 1 deletion sources/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ func SelectCosmovisorVersion(binaryPath, homePath, registryUrl, source string, c
}
}

return os.Symlink(fmt.Sprintf("%s/cosmovisor/upgrades/%s", homePath, upgradeName), symlinkPath)
if err := os.Symlink(fmt.Sprintf("%s/cosmovisor/upgrades/%s", homePath, upgradeName), symlinkPath); err != nil {
return fmt.Errorf("failed to create symlink: %w", err)
}

logger.Info().Msgf("selected binary version \"%s\" for cosmovisor", upgradeName)
return nil
}

func IsBinaryRecommendedVersion(binaryPath, registryUrl, source string, continuationHeight int64, userInput bool) error {
Expand Down

0 comments on commit e6892de

Please sign in to comment.