MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / CDBWrapper

Method CDBWrapper

src/dbwrapper.cpp:117–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool obfuscate)
118 : m_name(fs::basename(path))
119{
120 penv = nullptr;
121 readoptions.verify_checksums = true;
122 iteroptions.verify_checksums = true;
123 iteroptions.fill_cache = false;
124 syncoptions.sync = true;
125 options = GetOptions(nCacheSize);
126 options.create_if_missing = true;
127 if (fMemory) {
128 penv = leveldb::NewMemEnv(leveldb::Env::Default());
129 options.env = penv;
130 } else {
131 if (fWipe) {
132 LogPrintf("Wiping LevelDB in %s\n", path.string());
133 leveldb::Status result = leveldb::DestroyDB(path.string(), options);
134 dbwrapper_private::HandleError(result);
135 }
136 TryCreateDirectories(path);
137 LogPrintf("Opening LevelDB in %s\n", path.string());
138 }
139 leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
140 dbwrapper_private::HandleError(status);
141 LogPrintf("Opened LevelDB successfully\n");
142
143 if (gArgs.GetBoolArg("-forcecompactdb", false)) {
144 LogPrintf("Starting database compaction of %s\n", path.string());
145 pdb->CompactRange(nullptr, nullptr);
146 LogPrintf("Finished database compaction of %s\n", path.string());
147 }
148
149 // The base-case obfuscation key, which is a noop.
150 obfuscate_key = std::vector<unsigned char>(OBFUSCATE_KEY_NUM_BYTES, '\000');
151
152 bool key_exists = Read(OBFUSCATE_KEY_KEY, obfuscate_key);
153
154 if (!key_exists && obfuscate && IsEmpty()) {
155 // Initialize non-degenerate obfuscation if it won't upset
156 // existing, non-obfuscated data.
157 std::vector<unsigned char> new_key = CreateObfuscateKey();
158
159 // Write `new_key` so we don't obfuscate the key with itself
160 Write(OBFUSCATE_KEY_KEY, new_key);
161 obfuscate_key = new_key;
162
163 LogPrintf("Wrote new obfuscate key for %s: %s\n", path.string(), HexStr(obfuscate_key));
164 }
165
166 LogPrintf("Using obfuscation key for %s: %s\n", path.string(), HexStr(obfuscate_key));
167}
168
169CDBWrapper::~CDBWrapper()
170{

Callers

nothing calls this directly

Calls 8

GetOptionsFunction · 0.85
NewMemEnvFunction · 0.85
DestroyDBFunction · 0.85
HandleErrorFunction · 0.85
TryCreateDirectoriesFunction · 0.85
HexStrFunction · 0.85
GetBoolArgMethod · 0.80
CompactRangeMethod · 0.45

Tested by

no test coverage detected