Skip to content

Commit 67eac5c

Browse files
authored
fix(state): make read_only_open_with_ephemeral_config_returns_error more robust (#11146)
2 parents 5cd42d5 + 2bbefc2 commit 67eac5c

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

zebra-state/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- `init_read_only()` now returns `StateInitError::ReadOnlyEphemeralConflict` for a config with
13+
`ephemeral = true`, even when the configured `cache_dir` is missing or unreadable. Previously the
14+
cache directory was checked first, so this configuration error surfaced as
15+
`StateInitError::ReadOnlyCacheDirUnreadable`.
16+
1017
## [12.0.1] - 2026-07-27
1118

1219
### Changed

zebra-state/src/service/finalized_state/zebra_db.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ impl ZebraDb {
107107
// checked for readability first, so a missing or unreadable directory returns a typed
108108
// `ReadOnlyCacheDirUnreadable` error here instead of panicking on the version-file read.
109109
let disk_version = if read_only {
110+
// While this check is also done in `DiskDB::new()` below, we must
111+
// repeat it here because the `check_cache_dir_readable()` call just
112+
// after this will look into `cache_dir` but that should be ignored
113+
// when `ephemeral` is true.
114+
if config.ephemeral {
115+
return Err(StateInitError::ReadOnlyEphemeralConflict);
116+
}
117+
110118
DiskDb::check_cache_dir_readable(&config.cache_dir)?;
111119

112120
database_format_version_on_disk(config, &db_kind, format_version_in_code.major, network)

zebra-state/src/service/tests.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,14 @@ fn read_only_open_with_unreadable_cache_dir_returns_error() {
667667
fn read_only_open_with_ephemeral_config_returns_error() {
668668
let network = Network::Mainnet;
669669

670+
// While `ephemeral: true` should make `cache_dir` irrelevant, we had
671+
// instances where a bug would try to read the `cache_dir` before checking
672+
// `ephemeral`, so we use a missing directory to ensure that `ephemeral` is
673+
// checked first.
674+
let parent = tempfile::tempdir().expect("creating a temporary directory should succeed");
670675
let config = Config {
671676
ephemeral: true,
677+
cache_dir: parent.path().join("missing"),
672678
..Config::default()
673679
};
674680

0 commit comments

Comments
 (0)