Block and transaction validation results are represented in ValidationState, and invalid results in "Invalid" states. Invalid validation results have a result, an enum value, and a reject_reason, a structured string.
The change is to ensure that an invalid result always has a set result and reject reason. This increases code robustness/security.
One instance was identified where the result was not set, and is being fixed by a new BLOCK_INCONCLUSIVE result. PR #31981 moved a previous-block check from outside of TestBlockValidity() to inside it, and introduced a new usage of BlockValidationState with unset result. The result field is not checked outside. This instance is changed now to use the newly-introduced BLOCK_INCONCLUSIVE value.
The new enum value is added to the kernel C API and its C++ wrapper. In P2P, a BLOCK_INCONCLUSIVE result does not lead to punishing the peer.
A few test-only instances with empty reject reason are changed to use a dummy value ("dummy-reason").
History: this was found on the side of #35570, but left untouched there; see #35570 (comment) and #35570 (review).
Alternatives considered:
- Use a new reject reason enum. This is the cleanest solution, but the cost is the extension of a widely-used validation enum.
- Use a different mechanism for returning this specific case from
TestBlockValidity(), e.g. usingutil::Expected, as you discussed. No need to touch theBlockValidationResultenum. However, in the call sites ofTestBlockValidity(), the reject reason and debug strings are handled similarly to other non-valid check results, and they would need a special handling. - Reuse an exisiting reject reason enum value in
TestBlockValidity(), with the comment "only in this spot it means a little different thing". - Create a special
TestBlockValidationResult, "on top of"BlockValidationResult, with the extra value, and a specialTestBlockValidationState(ValidationState<TestBlockValidationResult>). Use this inTestBlockValidity(). As this is used only internally, within this methods and at its call sites, the new value+state doesn't have to be exposed. Therefore the change has lower impact.