Skip to content

Commit

Permalink
fix: cosmovisor logs
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler committed Nov 21, 2024
1 parent 1ba6fb3 commit 3359a0d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
8 changes: 8 additions & 0 deletions engines/tendermint-v34/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,14 @@ func (engine *Engine) BootstrapState(value []byte) error {
return fmt.Errorf("failed to unmarshal tendermint-ssync bundle: %w", err)
}

// if TimeIotaMs is zero we set it to 1 else the app would panic.
// in rare circumstances this can be zero if the snapshot got
// created with the engine cometbft-v0.37 or cometbft-v0.38 but the
// height is still for tendermint-v0.34
if bundle[0].Value.State.ConsensusParams.Block.TimeIotaMs == 0 {
bundle[0].Value.State.ConsensusParams.Block.TimeIotaMs = 1
}

err := engine.stateStore.Bootstrap(*bundle[0].Value.State)
if err != nil {
return fmt.Errorf("failed to bootstrap state: %s\"", err)
Expand Down
14 changes: 7 additions & 7 deletions sources/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func SelectCosmovisorVersion(binaryPath, homePath, registryUrl, source string, c
}

func IsBinaryRecommendedVersion(binaryPath, registryUrl, source string, continuationHeight int64, userInput bool) error {
if source == "" || !userInput {
if binaryPath == "" || source == "" || !userInput {
return nil
}

Expand All @@ -69,16 +69,17 @@ func IsBinaryRecommendedVersion(binaryPath, registryUrl, source string, continua
return fmt.Errorf("failed to lookup binary path: %w", err)
}

startArgs := make([]string, 0)
cmd := exec.Command(cmdPath)

// if we run with cosmovisor we start with the cosmovisor run command
if strings.HasSuffix(binaryPath, "cosmovisor") {
startArgs = append(startArgs, "run")
cmd.Args = append(cmd.Args, "run")
cmd.Env = append(os.Environ(), "COSMOVISOR_DISABLE_LOGS=true")
}

startArgs = append(startArgs, "version")
cmd.Args = append(cmd.Args, "version")

out, err := exec.Command(cmdPath, startArgs...).Output()
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to get output of binary: %w", err)
}
Expand Down Expand Up @@ -118,8 +119,7 @@ func IsBinaryRecommendedVersion(binaryPath, registryUrl, source string, continua
}

if strings.ToLower(answer) != "y" {
logger.Error().Msg("abort")
return nil
return fmt.Errorf("abort")
}

return nil
Expand Down
40 changes: 21 additions & 19 deletions utils/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ func GetHomePathFromBinary(binaryPath string) string {
os.Exit(1)
}

startArgs := make([]string, 0)
cmd := exec.Command(cmdPath)

// if we run with cosmovisor we start with the cosmovisor run command
if strings.HasSuffix(binaryPath, "cosmovisor") {
startArgs = append(startArgs, "run")
cmd.Args = append(cmd.Args, "run")
cmd.Env = append(os.Environ(), "COSMOVISOR_DISABLE_LOGS=true")
}

out, err := exec.Command(cmdPath, startArgs...).Output()
out, err := cmd.CombinedOutput()
if err != nil {
logger.Error().Msg("failed to get output of binary")
os.Exit(1)
Expand Down Expand Up @@ -55,16 +56,17 @@ func GetEnginePathFromBinary(binaryPath string) string {
os.Exit(1)
}

startArgs := make([]string, 0)
cmd := exec.Command(cmdPath)

// if we run with cosmovisor we start with the cosmovisor run command
if strings.HasSuffix(binaryPath, "cosmovisor") {
startArgs = append(startArgs, "run")
cmd.Args = append(cmd.Args, "run")
cmd.Env = append(os.Environ(), "COSMOVISOR_DISABLE_LOGS=true")
}

startArgs = append(startArgs, "version", "--long")
cmd.Args = append(cmd.Args, "version", "--long")

out, err := exec.Command(cmdPath, startArgs...).CombinedOutput()
out, err := cmd.CombinedOutput()
if err != nil {
logger.Error().Msg("failed to get output of binary")
os.Exit(1)
Expand Down Expand Up @@ -103,27 +105,27 @@ func StartBinaryProcessForDB(engine types.Engine, binaryPath string, debug bool,
return processId, fmt.Errorf("failed to lookup binary path: %w", err)
}

startArgs := make([]string, 0)
cmd := exec.Command(cmdPath)

// if we run with cosmovisor we start with the cosmovisor run command
if strings.HasSuffix(binaryPath, "cosmovisor") {
startArgs = append(startArgs, "run")
cmd.Args = append(cmd.Args, "run")
cmd.Env = append(os.Environ(), "COSMOVISOR_DISABLE_LOGS=true")
}

if err := engine.LoadConfig(); err != nil {
return processId, fmt.Errorf("failed to load engine config: %w", err)
}

baseArgs := append([]string{
"start",
cmd.Args = append(cmd.Args, "start",
"--home",
engine.GetHomePath(),
"--with-tendermint=false",
"--address",
engine.GetProxyAppAddress(),
}, args...)
)

cmd := exec.Command(cmdPath, append(startArgs, baseArgs...)...)
cmd.Args = append(cmd.Args, args...)

if debug {
cmd.Stdout = os.Stdout
Expand All @@ -148,15 +150,15 @@ func StartBinaryProcessForP2P(engine types.Engine, binaryPath string, debug bool
return processId, fmt.Errorf("failed to lookup binary path: %w", err)
}

startArgs := make([]string, 0)
cmd := exec.Command(cmdPath)

// if we run with cosmovisor we start with the cosmovisor run command
if strings.HasSuffix(binaryPath, "cosmovisor") {
startArgs = append(startArgs, "run")
cmd.Args = append(cmd.Args, "run")
cmd.Env = append(os.Environ(), "COSMOVISOR_DISABLE_LOGS=true")
}

baseArgs := append([]string{
"start",
cmd.Args = append(cmd.Args, "start",
"--home",
engine.GetHomePath(),
"--p2p.pex=false",
Expand All @@ -166,9 +168,9 @@ func StartBinaryProcessForP2P(engine types.Engine, binaryPath string, debug bool
"",
"--p2p.unconditional_peer_ids",
"",
}, args...)
)

cmd := exec.Command(cmdPath, append(startArgs, baseArgs...)...)
cmd.Args = append(cmd.Args, args...)

if debug {
cmd.Stdout = os.Stdout
Expand Down

0 comments on commit 3359a0d

Please sign in to comment.