diff --git a/cmd/ksync/commands/blocksync.go b/cmd/ksync/commands/blocksync.go index 2ff4ae9..95bdc14 100644 --- a/cmd/ksync/commands/blocksync.go +++ b/cmd/ksync/commands/blocksync.go @@ -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") @@ -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) diff --git a/cmd/ksync/commands/heightsync.go b/cmd/ksync/commands/heightsync.go index 3825e74..bc8a368 100644 --- a/cmd/ksync/commands/heightsync.go +++ b/cmd/ksync/commands/heightsync.go @@ -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") @@ -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) } diff --git a/cmd/ksync/commands/serveblocks.go b/cmd/ksync/commands/serveblocks.go index 8d9e668..7eb4acf 100644 --- a/cmd/ksync/commands/serveblocks.go +++ b/cmd/ksync/commands/serveblocks.go @@ -39,6 +39,7 @@ func init() { serveBlocksCmd.Flags().StringVarP(&source, "source", "s", "", "chain-id of the source") serveBlocksCmd.Flags().StringVar(®istryUrl, "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") @@ -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) } diff --git a/cmd/ksync/commands/servesnapshots.go b/cmd/ksync/commands/servesnapshots.go index 2078a7f..b8c1b44 100644 --- a/cmd/ksync/commands/servesnapshots.go +++ b/cmd/ksync/commands/servesnapshots.go @@ -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") @@ -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) } diff --git a/cmd/ksync/commands/statesync.go b/cmd/ksync/commands/statesync.go index b796c04..56a526c 100644 --- a/cmd/ksync/commands/statesync.go +++ b/cmd/ksync/commands/statesync.go @@ -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") @@ -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) } diff --git a/sources/version.go b/sources/version.go index a04f53e..d7678de 100644 --- a/sources/version.go +++ b/sources/version.go @@ -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 {