validation: Tidy up ValidationState interface#15921
Conversation
bca1b5f to
edcbe6c
Compare
promag
left a comment
There was a problem hiding this comment.
Concept ACK, looks like a good refactor and improvement to add ValidationState subclasses.
|
Concept ACK. I'd like to see I also somewhat think that ideally there should be a third state class which handles Corruption cases for 'system state' or something. This covers the notion that the issue is not the fault of the block or the transaction, it is an issue with our local state or implementation. Not sure it's worth the churn though, two is already a huge improvement. |
|
Concept ACK |
The current split is more about "what was being tested" not "what was at fault" -- that's easy to deal with via types, because you know what's being tested at compile time; but you don't know what's going to have been at fault at compile time, so I think dealing with that via the type system (ie as a third state class) wouldn't work. |
edcbe6c to
4a51148
Compare
2b794dc to
4b4d081
Compare
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
4b4d081 to
8d88c86
Compare
|
|
src/consensus/validation.h
Outdated
There was a problem hiding this comment.
Your old answer to to an old comment indicates that at some point you wanted to make the base class ValidationState abstract. However, the class has a (non-pure) virtual destructor and no pure virtual functions, so instantiation of ValidationState should still be possible. Is this working as intended?
fjahr
left a comment
There was a problem hiding this comment.
Code review ACK dcf5003. Also built and ran tests locally.
I agree with @JeremyRubin that Invalid should return void ideally. Also, have you thought about moving the punishment logic into its own class and file? It's not much of a difference in terms of LoC but reducing net_processing.cpp in size would not be a bad thing and it feels like that logic could deserve its own place due to its importance.
src/consensus/tx_check.cpp
Outdated
There was a problem hiding this comment.
nit: the & was moved from the type to the variable name. For consistency I would keep it at end of the type. That's also how it is still declared in the header file.
|
Thanks for the reviews @mzumsande and @fjahr . I've added a couple of fixup commits that address your comments. Let me know if you like them and I'll squash into the appropriate commits. @mzumsande - I had to add a consensus/validation.cpp file to define the |
|
For me, |
Thanks. Much better! |
Looks good to me! |
Split CValidationState into TxValidationState and BlockValidationState to store validation results for transactions and blocks respectively.
Minor style fixups and comment updates. This is purely a style change. There is no change in behavior.
This is in preparation for the next commit, which removes the useless `ret` parameter from ValidationState::Invalid(). error() is simply a convenience wrapper that calls LogPrintf and returns false. Call LogPrintf explicitly and substitute the error() call for a false bool literal.
ValidationState::Invalid() takes a parameter `ret` which is returned to the caller. All call sites set this to false. Remove the `ret` parameter and just return false always.
…ckHeaders() No callers use the returned value in first_invalid. Remove it from the function signature and don't set it in the function.
Handle this failure in the same way as all other failures: call Invalid() with the reasons for the failure.
|
squashed fixup commits. |
|
code review ACK 3004d5a. Also built & ran tests locally. |
|
Code review ACK 3004d5a . Only nit style change and pure virtual destructor added since my last review. |
|
There oughta be a rule about merging review club PRs right before the meeting :) |
|
@jonatack whoops … |
|
Ok, will still mention my code-review ACK for 3004d5a that I was just about to write when this got merged :-) |
Agree. The only downside is that review comments (with the reviewer's name) can not be included in the merge commit. |
|
Could possibly use a |
jonatack
left a comment
There was a problem hiding this comment.
Built at 3004d5a, ran tests, running bitcoind tailing the log.
Code review progress:
- [validation] Add CValidationState subclasses
- [validation] Tidy Up ValidationResult class
- [validation] Remove error() calls from Invalid() calls
- [validation] Remove useless ret parameter from Invalid()
- [validation] Remove unused first_invalid parameter from ProcessNewBlo…
- [validation] Remove fMissingInputs from AcceptToMemoryPool()
Interesting reviewer tip in the PR description; result here (without the right colors).
Done |
Thanks! |
|
Reviewers of this PR are encouraged to review PR #17624 ("net: Fix an uninitialized read in ProcessMessage(…, "tx", …) when receiving a transaction we already have") which fixes a quite serious bug introduced in this PR. Luckily it was caught before being part of any release :) |
Carries out some remaining tidy-ups remaining after PR 15141:
retparameter fromValidationState::Invalid()first_invalidparameter fromProcessNewBlockHeaders()fMissingInputsparameter fromAcceptToMemoryPool(), and deal with missing inputs the same way as other errors by using theTxValidationStateobject.Tip for reviewers (thanks ryanofsky!): The first commit ("[validation] Add CValidationState subclasses" ) is huge and can be easier to start reviewing if you revert the rote, mechanical changes:
Substitute the commit hash of commit "[validation] Add CValidationState subclasses" for in the commands below.
After that it's possible to easily see the mechanical changes with: