dbwrapper: accept optional testing leveldb::Env in DBParams

Allow callers to inject a custom leveldb::Env via DBParams::testing_env,
which takes priority over the memory_only in-memory environment. This
enables fuzz harnesses to supply a deterministic environment.
This commit is contained in:
Andrew Toth
2026-03-21 11:21:10 -04:00
parent 8d390c93fc
commit 32169c3855
2 changed files with 16 additions and 3 deletions

View File

@@ -224,16 +224,22 @@ CDBWrapper::CDBWrapper(const DBParams& params)
DBContext().options = GetOptions(params.cache_bytes);
DBContext().options.create_if_missing = true;
DBContext().options.max_file_size = params.max_file_size;
if (params.memory_only) {
assert(!(params.testing_env && params.memory_only));
if (params.testing_env) {
DBContext().options.env = params.testing_env;
} else if (params.memory_only) {
DBContext().penv = leveldb::NewMemEnv(leveldb::Env::Default());
DBContext().options.env = DBContext().penv;
} else {
}
if (!params.memory_only) {
if (params.wipe_data) {
LogInfo("Wiping LevelDB in %s", fs::PathToString(params.path));
leveldb::Status result = leveldb::DestroyDB(fs::PathToString(params.path), DBContext().options);
HandleError(result);
}
TryCreateDirectories(params.path);
if (!params.testing_env) {
TryCreateDirectories(params.path);
}
LogInfo("Opening LevelDB in %s", fs::PathToString(params.path));
}
// PathToString() return value is safe to pass to leveldb open function,