Skip to content

Commit afc534d

Browse files
committed
refactor: Wrap DestroyDB in dbwrapper helper
Wrap leveldb::DestroyDB in a helper function without exposing leveldb-specifics. Also, add missing optional include. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
1 parent 42a9110 commit afc534d

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/dbwrapper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#include <memory>
2828
#include <optional>
2929

30+
bool DestroyDB(const std::string& path_str)
31+
{
32+
return leveldb::DestroyDB(path_str, {}).ok();
33+
}
34+
3035
class CBitcoinLevelDBLogger : public leveldb::Logger {
3136
public:
3237
// This code is adapted from posix_logger.h, which is why it is using vsprintf.

src/dbwrapper.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <leveldb/slice.h>
2222
#include <leveldb/status.h>
2323
#include <leveldb/write_batch.h>
24+
#include <optional>
2425
#include <stdexcept>
2526
#include <string>
2627
#include <vector>
@@ -64,10 +65,6 @@ class dbwrapper_error : public std::runtime_error
6465

6566
class CDBWrapper;
6667

67-
namespace dbwrapper {
68-
using leveldb::DestroyDB;
69-
}
70-
7168
/** These should be considered an implementation detail of the specific database.
7269
*/
7370
namespace dbwrapper_private {
@@ -82,7 +79,9 @@ void HandleError(const leveldb::Status& status);
8279
*/
8380
const std::vector<unsigned char>& GetObfuscateKey(const CDBWrapper &w);
8481

85-
};
82+
}; // namespace dbwrapper_private
83+
84+
bool DestroyDB(const std::string& path_str);
8685

8786
/** Batch of changes queued to be written to a CDBWrapper */
8887
class CDBBatch

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5027,7 +5027,7 @@ static bool DeleteCoinsDBFromDisk(const fs::path db_path, bool is_snapshot)
50275027

50285028
// We have to destruct before this call leveldb::DB in order to release the db
50295029
// lock, otherwise `DestroyDB` will fail. See `leveldb::~DBImpl()`.
5030-
const bool destroyed = dbwrapper::DestroyDB(path_str, {}).ok();
5030+
const bool destroyed = DestroyDB(path_str);
50315031

50325032
if (!destroyed) {
50335033
LogPrintf("error: leveldb DestroyDB call failed on %s\n", path_str);

0 commit comments

Comments
 (0)