Skip to content

Commit d14bebf

Browse files
committed
db: add StoragePath to CDBWrapper/CCoinsViewDB
This is used in subsequent commits. It allows us to clean up UTXO snapshot chainstate after background validation completes.
1 parent 29d540b commit d14bebf

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/dbwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static leveldb::Options GetOptions(size_t nCacheSize)
128128
}
129129

130130
CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool obfuscate)
131-
: m_name{fs::PathToString(path.stem())}
131+
: m_name{fs::PathToString(path.stem())}, m_path{path}, m_is_memory{fMemory}
132132
{
133133
penv = nullptr;
134134
readoptions.verify_checksums = true;

src/dbwrapper.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class dbwrapper_error : public std::runtime_error
3939

4040
class CDBWrapper;
4141

42+
namespace dbwrapper {
43+
using leveldb::DestroyDB;
44+
}
45+
4246
/** These should be considered an implementation detail of the specific database.
4347
*/
4448
namespace dbwrapper_private {
@@ -219,6 +223,12 @@ class CDBWrapper
219223

220224
std::vector<unsigned char> CreateObfuscateKey() const;
221225

226+
//! path to filesystem storage
227+
const fs::path m_path;
228+
229+
//! whether or not the database resides in memory
230+
bool m_is_memory;
231+
222232
public:
223233
/**
224234
* @param[in] path Location in the filesystem where leveldb data will be stored.
@@ -268,6 +278,14 @@ class CDBWrapper
268278
return WriteBatch(batch, fSync);
269279
}
270280

281+
//! @returns filesystem path to the on-disk data.
282+
std::optional<fs::path> StoragePath() {
283+
if (m_is_memory) {
284+
return {};
285+
}
286+
return m_path;
287+
}
288+
271289
template <typename K>
272290
bool Exists(const K& key) const
273291
{

src/txdb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <coins.h>
1010
#include <dbwrapper.h>
1111
#include <sync.h>
12+
#include <fs.h>
1213

1314
#include <memory>
1415
#include <optional>
@@ -72,6 +73,9 @@ class CCoinsViewDB final : public CCoinsView
7273

7374
//! Dynamically alter the underlying leveldb cache size.
7475
void ResizeCache(size_t new_cache_size) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
76+
77+
//! @returns filesystem path to on-disk storage or std::nullopt if in memory.
78+
std::optional<fs::path> StoragePath() { return m_db->StoragePath(); }
7579
};
7680

7781
/** Access to the block database (blocks/index/) */

0 commit comments

Comments
 (0)