While reviewing the removal of the unreachable combinations from the Coin cache logic, we’ve noticed that the related tests often reflect impossible states.
Browsing the Coin cache refactoring history revealed that migrating bool GetCoin
to optional<Coin> GetCoin
was already proposed a few times before.
This refactor makes certain invalid states impossible, reducing the possibility of errors and making the code easier to understand. This will let us remove test code that exercises the impossible states as well.
The PR is done in multiple small steps, first swapping the new optional
return value, slowly strangling out the usages of the return parameter, followed by the removal of the parameter.
Most of the invalid test states were still kept, except for https://github.com/bitcoin/bitcoin/pull/30673/files#r1748087322, where the new design prohibits invalid usage and https://github.com/bitcoin/bitcoin/pull/30673/files#r1749350258 was just marked with a TODO, will be removed in a follow-up PR.