Repository navigation
Conversation
The goal is to ensure that an Invalid `ValidationState` always has a set result. However, there is a violating usage in `TestBlockValidity`. As a preparation to address that, a new value is added to the `BlockValidationResult` enum, `BLOCK_INCONCLUSIVE`, representing a result where validity could not be determined, e.g. due to some missing data (previous block). A corresponding value is added to the kernel C API (btck_BlockValidationResult_INCONCLUSIVE) and its C++ wrapper. In P2P, a `BLOCK_INCONCLUSIVE` result does not lead to punishing the peer. The new value is used in a later commit.
The goal is to ensure that an Invalid ValidationState always has a set result. A violating usage in `TestBlockValidity` is being changed: instead of the default `BLOCK_RESULT_UNSET`, it now uses `BLOCK_INCONCLUSIVE`. The result field from `TestBlockValidity` is currently not inspected by callers, but the constraint "an Invalid state must have a set result" is satisfied this way.
Ensure that an Invalid `ValidationState`, constructed through `Invalid()`, always has a set result field, by using an `Assume`. This increases code robustness/security.
In addition to ensuring a set result, also ensure that `reject_reason` is not empty for an Invalid `ValidationState`. Also remove its empty default value, as it should never be empty. Some test-only usages, where empty reject reason was used, are changed to use a dummy value.
optout21
force-pushed
the
2609-invalid-must-have-reason
branch
from
September 23, 2026 11:41
a3227fb to
22cf9d5
Compare
Owner
Author
|
--> bitcoin#36318 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Block and transaction validation results are represented in
ValidationState, and invalid results in "Invalid" states. Invalid validation results have aresult, an enum value, and areject_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 result was not set, and is being fixed by a new
BLOCK_INCONCLUSIVEresult. PR bitcoin#31981 moved a previous-block check from outside ofTestBlockValidity()to inside it, and introduced a new usage ofBlockValidationStatewith unset result. The result field is not checked outside. This instance is changed now to use the newly-introducedBLOCK_INCONCLUSIVEvalue.The new enum value is added to the kernel C API and its C++ wrapper. In P2P, a
BLOCK_INCONCLUSIVEresult 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 bitcoin#35570, but left untouched there; see bitcoin#35570 (comment) and bitcoin#35570 (comment).