-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Several mining-related improvements #5957
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
sipa
commented
Apr 1, 2015
- Get rid of the optimized hashing code (which wasn't even been used for regtest, which is the only thing for which it matters...).
- Introduce a separate 'generate' RPC call for the regtest-specific 'setgenerate' behaviour.
- Make regtest mining faster by using the mining loops from miner.cpp.
- Avoid the 1000s of errors when mining long regtest chains.
- Abstract out some of the mining code.
- Fix a bug where chainActive.Tip() was accessed outside of cs_main.
Nice.. I've wanted something like 'generate' Passes quick-glance review. Will test. |
Travis failure
|
1f5872d
to
6f25142
Compare
@fanquake Fixed. |
mapArgs ["-genproclimit"] = itostr(nGenProcLimit); | ||
GenerateBitcoins(fGenerate, pwalletMain, nGenProcLimit); | ||
} | ||
mapArgs["-gen"] = (fGenerate ? "1" : "0"); |
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.
We should probably change this at some point too to not update the mapArgs. Throughout the program we assume that mapArgs is read-only after initialization. This kind of r/w access would need proper locking around everything. No change needed for this pull but I'm just reminded of it.
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.
Agree.
This is obviously the right way to go, utACK Edit: tested ACK |
// the double-SHA256 state, and compute the result. | ||
CHash256(hasher).Write((unsigned char*)&nNonce, 4).Finalize((unsigned char*)phash); | ||
pblock->nNonce++; | ||
*phash = pblock->GetHash(); | ||
|
||
// Return the nonce if the hash has at least some zero bits, | ||
// caller will check if it has enough to reach the target | ||
if (((uint16_t*)phash)[15] == 0) | ||
return true; |
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.
Can't we directly return CheckProofOfWork() here instead of true and remove the later UintToArith256(hash) <= hashTarget
check in ScanLoop() [which means you can also remove the uint256 *phash param in ScanHash()] ?
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.
Even without CheckProofOfWork, that check belongs inside ScanHash so you can save the hash parameter and the hash parameter and you can reuse the arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
instead of repeating the conversion every time ((uint16_t*)phash)[15] == 0
. At that point, I'm not sure it's worth it to remove the optimization but I'm still not opposed to removing it.
And of course it can be && in the condition rather than returning.
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.
Yeah, just CheckProofOfWork would be fine, if we removed its error reporting (which imho we should in any case...), as now regtest mining beyond the first 2016 blocks prints 1000s of error messages to the log for each miner block as a result.
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.
Can you at least move the check in ScanLoop inside ScanHash for now?
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.
I'm not doing that as long as it produces this much debug output - that makes it effectively unusable for mining a >2016 long block chain. That error output should probably be discussed elsewhere.
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.
Wait, I misunderstood. Yes, that seems fine.
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.
Yes, as said in the other PR I plan to solve the warning problem soon as part of the consensus work for blockheader.
At that point that check can be directly replaced by CheckProofOfWork, I'm not proposing to do it now.
This makes -regtest block generation MUCH slower. Before: After: --> 2 minutes 10 seconds. |
New wallet tests have been added in the meantime and need to be updated to use `generate` instead of `setgenerate`.
Apparently I merged this too soon, sorry. @sdaftuar noticed that this was giving problems with travis due to the slowdown @gavinandresen remarks on. I've thus reverted the changes to the mining code for now (but not the |
Reopened #4793, which also does some code simplifications in miner.cpp. |
While it's sort of easy to mitigate, changing the API of Bitcoin Core ( |
@dexX7 I agree for any production usage of the RPC system, but this is
regtest specific. Do you have any evidence of the regtest-specific
setgenerate being used elsewhere? If so, we can of course temporarily
maintain compatibility.
|
I see your point, and I don't have specific use-cases, but there are a few references to This change may be announced on the mailing list, to enquire additional feedback from actual users, which may, or may not be out there. |
Thanks for pointing that out. I was not aware that the dev guide mentioned
this.
|
Here's the line in If we are the only external use-case we can handle this change when it happens, but we may not be the only case. |
Ever since bitcoin#5957 there has been the problem that older RPC test cases (as can be found plenty in open pulls) use setgenerate() on regtest, assuming a different interpretation of the arguments. Directly generating a number of blocks has been split off into a new method `generate` - however using `setgenerate` with the previous arguments will result in spawning an unreasonable number of threads, and well, simply not work as expected without clear indication of the error. Add an error to point the user at the right method.
Do not translate -help-debug options, Many technical terms, and only a very small audience, so is unnecessary stress to translators. Brings the code up to date with translation string policy in `doc/translation_strings_policy.md`. Also remove no-longer-relevant "In this mode -genproclimit controls how many blocks are generated immediately." (as of bitcoin#5957) from regtest help.
No longer relevant after bitcoin#5957. This hack existed because of another hack where the numthreads parameter, on regtest, doubled as how many blocks to generate.
No longer relevant after #5957. This hack existed because of another hack where the numthreads parameter, on regtest, doubled as how many blocks to generate. Conflicts: src/miner.cpp