Skip to content

Commit c5f6b1d

Browse files
committed
fuzz: coins_view: correct an incorrect assertion
It is incorrect to assert that `cache.HaveCoin()` will always be `true` if `backend.HaveCoin()` is. The coin could well have been marked as spent in the cache but not yet flushed, in which case `cache.HaveCoin()` would return `false`. Note this was never hit because `exists_using_have_coin_in_backend` is currently never `true` (it's the default implementation of `CCoinsView`. However this might change if we were to add a target where the backend is a `CCoinsViewDB`.
1 parent a4ca497 commit c5f6b1d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/test/fuzz/coins_view.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ FUZZ_TARGET(coins_view, .init = initialize_coins_view)
155155
}
156156
assert((exists_using_access_coin && exists_using_have_coin_in_cache && exists_using_have_coin && exists_using_get_coin) ||
157157
(!exists_using_access_coin && !exists_using_have_coin_in_cache && !exists_using_have_coin && !exists_using_get_coin));
158+
// If HaveCoin on the backend is true, it must also be on the cache if the coin wasn't spent.
158159
const bool exists_using_have_coin_in_backend = backend_coins_view.HaveCoin(random_out_point);
159-
if (exists_using_have_coin_in_backend) {
160+
if (!coin_using_access_coin.IsSpent() && exists_using_have_coin_in_backend) {
160161
assert(exists_using_have_coin);
161162
}
162163
Coin coin_using_backend_get_coin;

0 commit comments

Comments
 (0)