mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-09 02:59:31 +08:00
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:
@@ -67,7 +67,10 @@ void CCoinsViewDB::ResizeCache(size_t new_cache_size)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user