Skip to content

Commit

Permalink
chore: improve engine detection (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler authored Jan 20, 2025
1 parent 8e67d8f commit 6259cd0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ func (app *CosmosApp) LoadConsensusEngine() error {
}
}

// we first try to detect the engine by checking the build dependencies
// in the "version --long" command. If we don't find anything there we check
// the "tendermint version" command. We prefer to detect it with the build
// dependencies because only there we can distinguish between tendermint-v34
// and the celestia-core engine fork
cmd := exec.Command(app.binaryPath)

if app.isCosmovisor {
Expand Down Expand Up @@ -479,6 +484,38 @@ func (app *CosmosApp) LoadConsensusEngine() error {
}
}

cmd = exec.Command(app.binaryPath)

if app.isCosmovisor {
cmd.Args = append(cmd.Args, "run")
cmd.Env = append(os.Environ(), "COSMOVISOR_DISABLE_LOGS=true")
}

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

out, err = cmd.CombinedOutput()
if err != nil {
return nil, fmt.Errorf("failed to get output of binary: %w", err)
}

for _, engine := range []string{"tendermint", "Tendermint", "CometBFT"} {
for _, line := range strings.Split(string(out), "\n") {
if strings.Contains(line, engine) {
version := strings.Split(line, ": ")[1]

if strings.Contains(version, "0.34.") {
return tendermint_v34.NewEngine(app.homePath)
} else if strings.Contains(version, "0.37.") {
return cometbft_v37.NewEngine(app.homePath)
} else if strings.Contains(version, "0.38.") {
return cometbft_v38.NewEngine(app.homePath)
} else {
return nil, fmt.Errorf("failed to find engine in binary dependencies")
}
}
}
}

return nil, fmt.Errorf("failed to find engine in binary dependencies")
}()

Expand Down

0 comments on commit 6259cd0

Please sign in to comment.