mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 21:52:53 +02:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user