Skip to content

Commit ad949ba

Browse files
committed
txdb: don't reset during in-memory cache resize
We can't support a reset of the dbwrapper object when in-memory configuration is used because it results in the permanent loss of coins. This only affects unittest configurations (since that's the only place we use in-memory CCoinsViewDB instances).
1 parent f6e2da5 commit ad949ba

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/txdb.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ CCoinsViewDB::CCoinsViewDB(fs::path ldb_path, size_t nCacheSize, bool fMemory, b
4747

4848
void CCoinsViewDB::ResizeCache(size_t new_cache_size)
4949
{
50-
// Have to do a reset first to get the original `m_db` state to release its
51-
// filesystem lock.
52-
m_db.reset();
53-
m_db = MakeUnique<CDBWrapper>(
54-
m_ldb_path, new_cache_size, m_is_memory, /*fWipe*/ false, /*obfuscate*/ true);
50+
// We can't do this operation with an in-memory DB since we'll lose all the coins upon
51+
// reset.
52+
if (!m_is_memory) {
53+
// Have to do a reset first to get the original `m_db` state to release its
54+
// filesystem lock.
55+
m_db.reset();
56+
m_db = MakeUnique<CDBWrapper>(
57+
m_ldb_path, new_cache_size, m_is_memory, /*fWipe*/ false, /*obfuscate*/ true);
58+
}
5559
}
5660

5761
bool CCoinsViewDB::GetCoin(const COutPoint &outpoint, Coin &coin) const {

0 commit comments

Comments
 (0)