Skip to content

fix(tools/cosmovisor): decode TOML-quoted db_backend before opening the blockstore - #26856

Open
2xburnt wants to merge 1 commit into
cosmos:mainfrom
2xburnt:fix/cosmovisor-db-backend-quoted
Open

2xburnt wants to merge 1 commit into
cosmos:mainfrom
2xburnt:fix/cosmovisor-db-backend-quoted

Conversation

@2xburnt

@2xburnt 2xburnt commented Oct 2, 2026

Copy link
Copy Markdown

Description

When the daemon has already exited, fileWatcher.checkHeight reads the current height from the CometBFT blockstore itself. It gets the backend name from <daemon> config get config db_backend and passes the raw output to dbm.NewDB. Current SDK versions print that value TOML-encoded, as "goleveldb" with quotes and a trailing newline. dbm.NewDB rejects it, checkHeight returns an error, and CheckUpdate returns false. The upgrade is then missed: cosmovisor restarts the old binary instead of switching.

This PR adds parseDBBackend, which strictly decodes the command output:

  • It accepts a bare value, a TOML basic string ("...") or a TOML literal string ('...'), on a single line, with surrounding whitespace allowed.
  • It rejects empty output, multi-line output (for example a warning printed after the value), unterminated quotes and characters outside [a-z0-9_].
  • It does not check whether the backend is known or compiled in. dbm.NewDB still decides that.

The fallback to goleveldb when the config command fails is unchanged.

Files to review: tools/cosmovisor/dbbackend.go (the parser), and the checkHeight call site in tools/cosmovisor/scanner.go.

Testing

  • TestParseDBBackend in tools/cosmovisor/dbbackend_test.go covers the quoted, literal, bare and whitespace forms, plus each rejection case.
  • go test ./... in tools/cosmovisor passes, and so does golangci-lint with the repository config.
  • Reproduced on a real chain's node home with a daemon that exits before cosmovisor polls upgrade-info.json. cosmovisor v1.7.3 stays on the genesis binary. With this change it switches to the upgrade binary, and the upgraded node produces blocks.

…he blockstore

When the daemon has exited, checkHeight reads the height from the
blockstore itself and takes the backend from
`<daemon> config get config db_backend`. That command prints the value
TOML-encoded ("goleveldb" with quotes and a trailing newline), and the
raw output was passed to dbm.NewDB, which rejects it. The height check
then fails and the upgrade is not taken.

Decode the value strictly (bare, basic or literal TOML string, one line)
and leave backend validation to dbm.NewDB.
@greptile-apps

greptile-apps Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant