Skip to content

Commit e38c225

Browse files
committed
Merge bitcoin/bitcoin#28215: fuzz: fix a couple incorrect assertions in the coins_view target
e417c98 fuzz: coins_view: remove an incorrect assertion (Antoine Poinsot) c5f6b1d fuzz: coins_view: correct an incorrect assertion (Antoine Poinsot) Pull request description: The `coins_view` fuzz target would assert in two places that the cache is consistent with the backend. But it's never the case (that's the whole point of using a cache). The only reason this didn't result in a crash was that we would never actually hit these assertions. I ran into this while introducing a new target with an in-memory `CCoinsViewDB` as the backend view (see bitcoin/bitcoin#28216) which made the code paths with those assertions actually reachable. ACKs for top commit: dergoegge: Code review ACK e417c98 Tree-SHA512: 5847bb2744a2f2831dace62d32b79cc491bf54e2af4ce425411d245d566622d9aff816d9be5ec8e830d10851c13f2500bf4f0c004d88b4d7cca1d483ef8960a6
2 parents aadaa56 + e417c98 commit e38c225

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/test/fuzz/coins_view.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,16 @@ 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;
163164
if (backend_coins_view.GetCoin(random_out_point, coin_using_backend_get_coin)) {
164165
assert(exists_using_have_coin_in_backend);
165-
assert(coin_using_get_coin == coin_using_backend_get_coin);
166+
// Note we can't assert that `coin_using_get_coin == coin_using_backend_get_coin` because the coin in
167+
// the cache may have been modified but not yet flushed.
166168
} else {
167169
assert(!exists_using_have_coin_in_backend);
168170
}

0 commit comments

Comments
 (0)