-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Proof of work related refactor #4377
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
|
Maybe I should have just put #4393 into this one... |
|
@Drak As it changes how verifying POW works, this looks kind of risky and needs extensive testing and review. It's not an easy merge like the code move. |
|
I think both commits are straight-forward to merge, specially the first one. |
|
I'm including more commits. All commits are refactors that don't change functionality but if there's some of them that are more controversial I can separate them in different PRs. |
|
Also, to understand the motivation of this PR you may want to take a look to this unfinished branch that completely encapsulates the Proof of Work, making it easier to experiment with other Proofs: Probably Params().AllowMinDifficultyBlocks() can be removed with an specialized Proof. Well, not probably, for sure, what remains to be seen if it that will simplify the code or not. |
|
Agree on overall changes, haven't checked the code moves or tested yet. |
|
Ping @sipa - This looks good to me, was wondering around this part of code and now happy to find this PR. It is not invasive and makes the whole POW more readable and maintainable. But I advise against going forward into #4506 mainly because class polymorphism will affect runtime performance signicantly and can introduce problems using templates. #4508 looks like a very good move to follow up with this. |
|
I simplified the last two commits and unified them into one after completing #4506 |
src/pow.h
Outdated
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.
That's a confusing name. How about GetProofIncrement()?
|
Changed GetLengthIncrement to GetProofIncrement as suggested by @sipa |
|
Tested ACK |
|
I'm not entirely happy that part of the internal miner is moved to pow.cpp (the ugly loop GenerateProof , as well as global variable dHashesPerSec and nHPSTimerStart). Most of this clearly belongs in miner.cpp. I understand why, but I would prefer if pow.cpp only contained the consensus-critical code that verifies proof of work. I'd suggest to keep the outer loop in miner.cpp but move an inner pow-dependent part (ScanHash) to pow.cpp. |
|
I'm not entirely happy with the GenerateProof function either. My initial approach was to simply remove the optimizations, but #4423 was rejected. Maybe we could just remove the hashrate counter to simplify things... |
|
Thank you for the feedback. I thought it was good to rebase on top of the latest head often, but yes, that kind of invalidates earlier testing. |
|
Added the additional conversion to CheckMinWork as suggested by @laanwj |
|
Ping. |
|
Tested ACK |
src/pow.cpp
Outdated
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.
Deleting this conversion won't hurt. GetCompact + SetCompact will only round the (absolute value of a) uint256 down, so the check becomes stricter. As it's only a heuristic, loosening it is never a problem. Given that all it does is divide by a power of 4, I expect it to be no-op apart from the last 2 bits anyway.
In short: the test is probably immeasurably stronger by having the conversion.
|
I don't like keeping TODO's like the one you mentioned in master code. A comment about why it's there (if you don't delete it) or where it used to be (if you do) is fine of course. I'd keep the conversion. |
|
Mildly-tested ACK. |
|
Additional conversion and TODO removed. |
|
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4377_654871d43677947d124673c9e0dd2984f0d3ca61/ for binaries and test log. |
|
Sorry, in the comment to the commit you said it would be safe to remove the redundant conversion but later you say you would keep the conversion. I missed that and I removed it again. |
|
@jtimon It's fine. Both are safe; the extra conversion makes the test up to 0.000036% stronger (3 / 2^23). Then again, it's easy to do too. |
|
ACK |
Continues #3839