There is plenty of test code that exercises the code path for FRESH-but-not-DIRTY coins in CCoinsViewCache. However, we can see there is only one place in production code where we call SetFresh
that is not preceded by SetDirty
. This is in CCoinsViewCache::FetchCoin
and we can see that this is called if the coin retrieved from base->GetCoin
is spent. The base
in this case can be another CCoinsViewCache
or a CCoinsViewDB
. In CCoinsViewCache::GetCoin
we can see that we do not return spent coins, and in CCoinsViewDB
we don’t ever store spent coins so there are none to return.
Thus, we can safely remove this dead code, and now we can see that there are never any calls to SetFresh
not preceded by SetDirty
. This PR removes this dead code and replaces SetFresh
by passing a fresh
boolean flag to SetDirty
. This simplifies the logic of CCoinsViewCache
and lets us remove test cases checking for FRESH-but-not-DIRTY coins. It removes the possibility of FRESH-but-not-DIRTY coins being called from any code path, so we can eliminate this state entirely and reduce the cognitive load of having to consider it.
This is pulled out from #30673 to make the change simpler.