Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible places where named args for integral literals may be used (e.g.
2026-11-03 06:18:20 |
d5cf460 to
bf14474
Compare
|
Rebased on master to resolve conflicts with #35621. |
|
Hmm, it could make sense to be more type-safe here, but looking at the code, there are places that flatten this back down to a boolean, so I wonder what the overall benefit is? I think it could make sense to think whether any places that flatten this down again to a boolean need a different handling? If yes, fixing that handling should probably be done early in a pull request changing the behavior. Moreover, I presume all of the runtime-errors are fatal, so I presume they must all call the fatal error function. Maybe this can be enforced at compile-time, so that all those fatal errors ensure that the fatal error function is called exactly once? |
optout21
left a comment
There was a problem hiding this comment.
Concept ACK
The advantages of this change are:
- enforcement of returned errors -- some methods can return only runtime errors;
- reduced risk of accidental mix-up of validation and runtime errors.
At first it looked a bit strange that some errors (runtime errors) are treated as exceptional cases, while validation errors are treated as return values, as previously both were treated the same. However, this makes sense; validation status can be regarded as the non-exceptional output of the checker algotihms, while runtime errors are proper exceptional errors.
Some minor observations:
- Maybe the big change could be broken up (e.g. in two, first the
voidreturn value changes, then theBlockValidationStatechanges) CheckBlock,CheckBlockHeadercould be also be changed to the return-state pattern[[nodiscard]]could be added touched signatures, to reduce risk of ignored errors.- In some places where a local
statevariable is used, its scope could be reduced, or omitted entirely. Preferably error from a call should be handled right away, there is no need for method-wide state/error variable (left comments in a few places).
| @@ -2307,6 +2305,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, | |||
| uint256 block_hash{block.GetHash()}; | |||
| assert(*pindex->phashBlock == block_hash); | |||
|
|
|||
| BlockValidationState state; | |||
There was a problem hiding this comment.
7d0ed51 validation: route fatal errors through util::Expected:
Could get rid of this local variable if CheckBlock signature is also changed (to return state).
There was a problem hiding this comment.
I think this could be done in a follow-up to reduce the review burden here? #35570
You're right that the top-level callers collapses the result back to yes/no, wouldn't that be the right place for it to collapse? e.g.
I've checked, every fatal error already fires at the origin(
This is mostly true, except for Details |
Yeah, I am mostly wondering aloud. Because currently, your patch will map both to That doesn't seem consistent or worthwhile. I'd say:
|
bf14474 to
1811b21
Compare
Co-authored-by: Hodlinator <[email protected]>
Co-authored-by: Hodlinator <[email protected]>
Read fatal errors directly from ProcessNewBlock in submission callers. Test block-write, undo-write, and post-validation flush failures, including the absence of BlockChecked signals for fatal validation failures. Fatal AcceptBlock and ConnectBlock failures no longer emit BlockChecked, since callers now receive the error from ProcessNewBlock. Clean up the submitted block source in peer processing when ProcessNewBlock returns a fatal error. For block submission over the mining interface, a fatal error is reported with reason "inconclusive" and the error message in debug, so that reason keeps its existing set of values. Co-authored-by: Hodlinator <[email protected]> Co-authored-by: optout <[email protected]>
Runtime failures are now returned separately through `util::Expected`, so `ValidationState` only needs to represent valid and invalid validation outcomes. Remove `M_ERROR`, `Error()`, and `IsError()`.
Validation state no longer represents runtime failures, so remove INTERNAL_ERROR from the kernel C API and C++ wrapper.
7a6ced0 to
ebe01e1
Compare
|
Rebased onto master (ddea919) and addressed review comments from @optout21.
|
| if (auto res{chainman.ProcessNewBlock(block_out, /*force_processing=*/true, /*min_pow_checked=*/true, nullptr)}; !res || !*res) { | ||
| throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); | ||
| } |
There was a problem hiding this comment.
cea4ccb refactor: Make ProcessNewBlock() use FatalError type:
In case of error, res.error().message() could be included in the error message.
| state.Error(strprintf("%s: Failed to find position to write new block to disk: %s", __func__, res.error().message())); | ||
| return false; | ||
| } | ||
| assert(!res->IsNull()); |
There was a problem hiding this comment.
65d1929 refactor: Make BlockManager use FatalError type:
Even though currently this assert is guaranteed to not be hit, an Assume() instead of assert would be more appropriate.
|
🐙 This pull request conflicts with the target branch and needs rebase. |

BlockValidationStatecurrently carries two unrelated kinds of failure: consensus/policy invalidity which is the actual purpose and runtime errors via aM_ERRORmode inModeStateenum insideValidationStateclass. This PR removesM_ERRORand routes runtime errors throughutil::Expected<T, std::string>instead, making the two failure modes distinct.Motivation
BlockValidationStateexists to describe why a block or transaction is invalid. It holds a consensus/policy reject reason. A disk write or system runtime error is not that, yet it was folded into the same object as a third state i.e.M_ERROR.This conflation has two costs:
Wrong abstraction for non-validating functions.
FlushStateToDisk,DisconnectTip,ActivateBestChain,PreciousBlock, andInvalidateBlockdo no block validation, but each takes aBlockValidationStateout-param to report any runtime error.Three outcomes in one object. Functions that can both validate and hit a runtime error (
ConnectBlock,AcceptBlock,ProcessNewBlock) holds valid, invalid, and fatal into a singleBlockValidationState, forcing every caller to unwrap.As noted in the original discussion here:
And also discussion here to remove
M_ERRORvalue.BlockValidationStatefrom validation methods instead of boolean value.util::Expectedis a good option for this reason, it keeps the error handling in the same return value style (system/runtime errors andValidationStatefor consensus correctness) and separates-out runtime errors fromValidationState.Runtime errors could be signaled either by a return value or by throwing. This PR keeps them as return values as it's a minimal change.
M_ERRORwas already a return-value mechanism included inValidationStatewith consensus verdict. This PR doesn't open the exceptions vs returns question, it keeps the existing return-value style and just moves the fatal error into a proper Expected channel.