Commit 7807924
fix(l1): don't treat unrelated datadir files as an existing DB (#6786)
## Motivation
Closes #5680.
`Store::new` returns `NotFoundDBVersion` whenever the datadir is merely
**non-empty**, even when there is no actual database in it. This breaks
setups where unrelated files share the datadir — e.g. EthDocker places
the JWT secret in the same directory, so startup fails on a fresh node.
## Description
The intent of that branch is "a pre-metadata DB exists and we can't
migrate it safely." It used *directory non-empty* as a proxy for *a
database exists*, which is too broad.
This PR replaces `dir_is_empty()` with `dir_contains_existing_db()`,
which looks for RocksDB's marker files (`CURRENT`, `IDENTITY`,
`MANIFEST-*`) instead. A datadir that only contains unrelated files (a
JWT, etc.) is now correctly treated as fresh and initialized, while a
real pre-metadata DB still returns `NotFoundDBVersion`.
RocksDB is the only on-disk backend (`crates/storage/backend/` =
`rocksdb` + `in_memory`), so its markers fully cover the persistent
path. Happy to extend the marker set if other backends land.
## Tests
Added unit tests in `datadir_tests`:
- empty dir → not an existing DB
- dir with only unrelated files (JWT, `LOG`) → not an existing DB (the
regression)
- dir with `CURRENT` / `MANIFEST-*` → existing DB
```
cargo test -p ethrex-storage --lib datadir_tests
cargo clippy -p ethrex-storage --lib
```
---------
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>1 parent aa5bd30 commit 7807924
1 file changed
Lines changed: 81 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1649 | 1649 | | |
1650 | 1650 | | |
1651 | 1651 | | |
1652 | | - | |
| 1652 | + | |
1653 | 1653 | | |
1654 | 1654 | | |
1655 | 1655 | | |
1656 | 1656 | | |
1657 | | - | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
1658 | 1662 | | |
1659 | 1663 | | |
1660 | 1664 | | |
| |||
3594 | 3598 | | |
3595 | 3599 | | |
3596 | 3600 | | |
3597 | | - | |
3598 | | - | |
3599 | | - | |
| 3601 | + | |
| 3602 | + | |
| 3603 | + | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
| 3611 | + | |
| 3612 | + | |
| 3613 | + | |
| 3614 | + | |
| 3615 | + | |
| 3616 | + | |
| 3617 | + | |
| 3618 | + | |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
| 3622 | + | |
| 3623 | + | |
| 3624 | + | |
| 3625 | + | |
| 3626 | + | |
| 3627 | + | |
| 3628 | + | |
| 3629 | + | |
| 3630 | + | |
| 3631 | + | |
3600 | 3632 | | |
3601 | 3633 | | |
3602 | 3634 | | |
| |||
3802 | 3834 | | |
3803 | 3835 | | |
3804 | 3836 | | |
| 3837 | + | |
| 3838 | + | |
| 3839 | + | |
| 3840 | + | |
| 3841 | + | |
| 3842 | + | |
| 3843 | + | |
| 3844 | + | |
| 3845 | + | |
| 3846 | + | |
| 3847 | + | |
| 3848 | + | |
| 3849 | + | |
| 3850 | + | |
| 3851 | + | |
| 3852 | + | |
| 3853 | + | |
| 3854 | + | |
| 3855 | + | |
| 3856 | + | |
| 3857 | + | |
| 3858 | + | |
| 3859 | + | |
| 3860 | + | |
| 3861 | + | |
| 3862 | + | |
| 3863 | + | |
| 3864 | + | |
| 3865 | + | |
| 3866 | + | |
| 3867 | + | |
| 3868 | + | |
| 3869 | + | |
| 3870 | + | |
| 3871 | + | |
| 3872 | + | |
| 3873 | + | |
| 3874 | + | |
| 3875 | + | |
| 3876 | + | |
| 3877 | + | |
| 3878 | + | |
| 3879 | + | |
| 3880 | + | |
0 commit comments