From ee1e40f58000921e95f08bcb199a452eb5c4d9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Sat, 3 Jan 2026 20:26:04 +0100 Subject: [PATCH] txdb: assert `CCoinsViewDB::GetCoin` only returns unspent coins The chainstate UTXO database only stores unspent outputs; spent entries are removed. Assert after reading a `Coin` so corruption or misuse cannot propagate a spent coin through the `GetCoin()` interface. --- src/txdb.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 5d61388b078..141c31c5d51 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -67,7 +67,10 @@ void CCoinsViewDB::ResizeCache(size_t new_cache_size) std::optional CCoinsViewDB::GetCoin(const COutPoint& outpoint) const { - if (Coin coin; m_db->Read(CoinEntry(&outpoint), coin)) return coin; + if (Coin coin; m_db->Read(CoinEntry(&outpoint), coin)) { + Assert(!coin.IsSpent()); // The UTXO database should never contain spent coins + return coin; + } return std::nullopt; }