Summary. Refactor validation result to be a return value instead of an output parameter in several validation.cpp methods.
Motivation. The benefits of the change are:
- Exclude the potentially inconsistent case when the bool return value and the returned
stateare inconsistent - Exclude the ambiguity whether the passed in value of state is used or not (not obvious in chained calls)
- Remove the possibility of unintuitive interaction between subsequent calls with the same state. In case of a validation error, a failure reason is set if the state was valid, but not if it was already invalid.
- Slightly simpler: It's more evident which is the result; one less parameters.
This has grown out from #33856, mentioned in comment here and here.
Details. Many methods follow the scheme where the validation state is returned in an output parameter (BlockValidationState& state), and and additional bool return value indicating success. In success case the convention is that state.IsValid() and the return value are both true. After the change there is only a BlockValidationState return value, which is either success (state.IsValid() == true), or an invalid/error case.
This change is a highly localized refactor, but touching a sensitive file.
Relevant methods called by ProcessNewBlockHeaders and AcceptBlock (directly and indirectly) are touched.
Changes are separated into commits by touched methods, ordered by bottom-to-top in the call hierarchy.