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.
This commit is contained in:
1 file changed
+4
-1
+4
-1
@@ -67,7 +67,10 @@ void CCoinsViewDB::ResizeCache(size_t new_cache_size)
|
|||||||
|
|
||||||
std::optional<Coin> CCoinsViewDB::GetCoin(const COutPoint& outpoint) const
|
std::optional<Coin> 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;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user