aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@pm.me>2020-08-25 13:48:21 -0400
committerJames O'Beirne <james.obeirne@pm.me>2021-02-12 07:53:32 -0600
commitad949ba449ff2115e3d22c71f5b6509f11112098 (patch)
treee389510ed6ca780532c322c378c8049adde0e7c9
parentf6e2da5fb7c6406c37612c838c998078ea8d2252 (diff)
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).
-rw-r--r--src/txdb.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/txdb.cpp b/src/txdb.cpp
index 72460e7c69..4b4766e1ba 100644
--- a/src/txdb.cpp
+++ b/src/txdb.cpp
@@ -47,11 +47,15 @@ CCoinsViewDB::CCoinsViewDB(fs::path ldb_path, size_t nCacheSize, bool fMemory, b
void CCoinsViewDB::ResizeCache(size_t new_cache_size)
{
- // Have to do a reset first to get the original `m_db` state to release its
- // filesystem lock.
- m_db.reset();
- m_db = MakeUnique<CDBWrapper>(
- m_ldb_path, new_cache_size, m_is_memory, /*fWipe*/ false, /*obfuscate*/ true);
+ // We can't do this operation with an in-memory DB since we'll lose all the coins upon
+ // reset.
+ if (!m_is_memory) {
+ // Have to do a reset first to get the original `m_db` state to release its
+ // filesystem lock.
+ m_db.reset();
+ m_db = MakeUnique<CDBWrapper>(
+ m_ldb_path, new_cache_size, m_is_memory, /*fWipe*/ false, /*obfuscate*/ true);
+ }
}
bool CCoinsViewDB::GetCoin(const COutPoint &outpoint, Coin &coin) const {