-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Separate CValidationState from main #5669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm not a fan of adding more try/catch to consensus code, but that's (mostly) a matter of personal taste. Any reason for not simply returning a (differently named) ConsensusException object? Also, as another matter of personal preference, reusing the name CheckTransaction() makes it hard to read/grep. I suppose if we started using the Consensus namespace as a convention I wouldn't mind that though. grumble..bikeshed...consensus.cpp... Concept ACK. |
if (tx.vout[i].nValue > MAX_MONEY) | ||
throw ConsensusException(100, __func__, "txout.nValue too high", "bad-txns-vout-toolarge"); | ||
nValueOut += tx.vout[i].nValue; | ||
if (!MoneyRange(nValueOut)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question, MoneyRange()
does return (nValue >= 0 && nValue <= MAX_MONEY)
, why not reuse MoneyRange()
also for the check before accumulating the amounts and just give another error message? This would de-duplicate the above code.
@Diapolo 1) Will fix the #ifndef 2) Good catch on @theuni Yes, the point of the namespace was to avoid naming these functions ConsensusCheckTransaction(), etc. But I'm fine also changing the name. What about Consensus::CheckTx() ? @both of you, I agree that ConsensusException is not the most elegant thing in the world as it is now. @Diapolo proposes to unify functionIn and strErrorIn into maybe descriptionIn. That makes sense. I would prefer not putting there anything at all. Remember that this is only for the log. Would it be much worse if instead of using |
@jtimon IMHO it makes absolutely sense to create an additional commit, which picks up my suggestion and perhaps also your optimisation ideas. It makes things easy to review if the last commit would be that. About my suggestion for the input strings, I just meant changing them to Thanks for also picking up the other things! |
Since it is still very new, I took the liberty of directly editing the commits instead of adding new ones to later rebase and squash.
Oh, and bikeshed from CheckTransaction() to CheckTx(). |
Also, I replaced a couple of |
Hmm, looking at this again.. What's the reason for not dropping state.Abort() (it makes no sense for a state object to be aborting the node anyway imo), creating something like "abortNodeBadState(CValidationState& state, std::string reason)" to take its place, and moving CValidationState into consensus.o ? That way we could share much more code with the current implementation. |
I was curious to see what it'd look like, so I tried out the above suggested change in one big nasty commit: theuni@fd19dd4 It seems quite advantageous to have CValidationState in consensus.o. |
Yesterday I realized that the result object should be more generic to be used by other consensus functions. Also it would be useful for some policy methods. But your approach is definitely simpler. The only disadvantage being the lack of an error string to be passed and thus changing a little bit the logging. So I think I'm going to redo this on top of an edited version of your commit. |
Rebased with CValidationState in consensus/validation.h.
Feel free to bikeshed the file names. |
Mm, this is now hard to review because it's such a moving target. I was ready to ACK the changes after another quick review based on your comment above, but lots of other things have been touched since then. Could you try to keep this to a somewhat narrow scope for the sake of review? Also, since a fresh review is needed, please go ahead and rebase to remove the squashme's. |
a69e9c9
to
88d9145
Compare
Rebased on top of #5681, added some "SQUASHME" notes since some small commits like those flagged with "MOVEONLY", are only useful for the initial review (for example I separated theuni/bitcoin@fd19dd4 into jtimon@72e5068 and jtimon@8a6590c). |
Ok. Concept ACK here. I'll re-review and verify the MOVEONLY's after #5681. |
ce58172
to
5683d47
Compare
Needed rebase. Also I thought more about it and it's good to separate the class from main as soon as possible not only for consensus encapsulation but also for policy encapsulation (maybe wallet too? ), and include organization. So I put the moveonly commit back in. |
ACK. I think this is merge-ready. My only nit would be validation.h -> validationstate.h, but not a big deal either way. I'd like to see the DoS functionality moved out, but that can be discussed after this goes in. |
I could rename it but I would prefer not to do so to avoid rebasing some branches based on this if it's not a big deal. |
ACK, needs rebase though. Longer term (but not for this PR), handling of system errors (the ERROR) state should be handled completely separately from CValidationState (yes, my fault that I introduced it there). There are several functions that only use a CValidationState to pass on possible system failure (and not actually failed validation). |
rebased |
Needed rebase |
ACK. |
reACK. Untested after rebase, but still looks sane. |
Rebased |
utACK |
ut ACK |
First decouple CValidationState from main::AbortNode(), Then move it to consensus/validation.h
This is part of the effort to create libconsensus.
It's also useful for policy encapsulation.