-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Fix RandAddSeedPerfMon and move large stack objects to heap #4392
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
Fix RandAddSeedPerfMon and move large stack objects to heap #4392
Conversation
Tried testing on wine, but the |
|
Testing on Windows 8 64bit with @laanwj's binary, my log shows
I'm not sure how to further debug this. My regular Bitcoin 0.9.1 GUI does not seem to show any randomness-related debug messages (started with |
@leofidus Thanks for testing! The regular client doesn't show any messages if the call fails, only if it succeeds. In the second commit of this pull I added that warning. So - it's failing in 0.9.1 as well. But the error is different than mine on wine. Error 234 is
|
My official 0.9.1 client shows, that it's working here |
@Diapolo Thanks for testing, although at this point I doubt that it depends on this patch. So at least it works in some cases. Do you perhaps know if HKEY_PERFORMANCE_DATA returns a variable number of bytes that may be >250000? Ah, got it:
So we need a loop. |
@laanwj We had a debate about that part of the code in 09. 2012, see https://bitcointalk.org/index.php?topic=113496.msg1225880#msg1225880 |
@laanwj What do you think about removing that source of entropy and use the debug.log with |
Wut? It is known since 2012? I'm extremely disappointed and surprised here. Why did no one ever fix that or escalate it beyond a silly forum topic? Getting the performance data properly is simple, an example is even given in the MSDN documentation that I link above. I don't think debug.log is a good source of entropy as it is - up to a point - controllable by the outside world through the network. But I'm not an expert on that. If you implement an extra entropy source for that be sure to just use part of the file, not all of it, or it could slow down start-up. |
@laanwj I proposed a change (https://bitcointalk.org/index.php?topic=113496.msg1228012#msg1228012) and if I remember correctly also had a pull open for this. It was decided to leave as is. |
That makes no sense. I can only find one issue with |
Are you going to rework this to include a loop? I tend to just remove it, but have no strong enough feeling yet. |
Yes, I'm going to turn it into a loop. We have a dearth of entropy sources on windows so removing any sounds extremely unwise. |
Ok, it should always collect now unless there is >10MB of performance data. A bitcoind.exe to test with is available here: https://download.visucore.com/bitcoin/bitcoin-win-v0.9.99.0-g3b8c1da.zip (gpg sigs https://download.visucore.com/bitcoin/bitcoin-win-v0.9.99.0-g3b8c1da.zip.sig) |
Again, can someone with windows test the above bitcoin-win-v0.9.99.0-g3b8c1da.zip and start with -debug=rand and look for the RandAddSeedPerfmon() XXX bytes message in debug.log? |
static bool warned = false; // Warn only once | ||
if (!warned) | ||
{ | ||
LogPrintf("%s: Warning: RegQueryValueExA(HKEY_PERFORMANCE_DATA) failed with code %i\n", __func__, ret); |
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.
Nit: Can we define to add a space before the function name :)? Also should this be part of the "rand" category or not? Which is a thing I need to consider with my OpenSSL related pulls also...
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 don't understand, the function name is at the beginning of the line, adding a space there makes no sense.
And this is not in the rand category on purpose because people need to see it. It is not just for debugging. And it only emits the warning once anyway.
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 talking about this changed to this anyway:
LogPrintf("%s : Warning: RegQueryValueExA(HKEY_PERFORMANCE_DATA) failed with code %i\n", __func__, ret);
We seem to use that syntax more often.
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 inconsistent too. The second :
has no space before it. Also looks strange to me. In English you write like this: there is never a space before a (semi)colon. Anyhow, I'm not going to waste time discussing the formatting of log messages, sorry.
I'm currently testing this... |
Currently we use a fixed buffer of 250000 bytes to request HKEY_PERFORMANCE_DATA. In many cases this is not enough, causing the entropy collection to be skipped. Use a loop that grows the buffer as specified in the RegQueryValueEx documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724911%28v=vs.85%29.aspx (as the size of the performance data can differ for every call, the normal solution of requesting the size then allocating that can't work)
2014-06-26 13:16:33 RandAddSeedPerfmon : 215208 bytes 2014-06-26 13:26:33 RandAddSeedPerfmon : 205416 bytes Seems to work :). ACK |
Thanks for testing. I added the 0 initializations. Ready for merge now. |
Automatic sanity-testing: FAILED BUILD/TEST, see http://jenkins.bluematt.me/pull-tester/p4392_8ae973c00cfb02161bb2c2a6c839e510cd409278/ for binaries and test log. This could happen for one of several reasons:
If you believe this to be in error, please ping BlueMatt on freenode or TheBlueMatt here. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ |
Rebased version of #4236 by @arowser, changed to use begin_ptr from #4293. Also use vXXXX variable name syntax for the vectors...
Testing: I'm a bit wary to merge as it affects entropy collection for randomness. I'd like someone with windows to verify that this does the right thing (so, start with
-debug=rand
and look for theRandAddSeed() XXX bytes
message).