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 races in AppInitMain and others with lock and atomic bools #11107
Conversation
src/init.cpp
Outdated
@@ -1632,8 +1632,12 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) | |||
// ********************************************************* Step 11: start node | |||
|
|||
//// debug print | |||
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size()); | |||
LogPrintf("nBestHeight = %d\n", chainActive.Height()); | |||
{ |
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 guess it would make sense to also cover mapBlockIndex
and chainActive
to make this move-safe.
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.
chainActive.Height() is also accessed on line 1652, you want to bring it in too?
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.
If chainActive is added then update descriptions accordingly.
Did you search for other cases?
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.
No haven't modified the pull yet, it still just fixes the issue linked
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.
Indeed, ight as well pull chainActive.Height() into the cs_main here.
Travis error looks unrelated, timeout in sendheaders.py - |
While you're at it, want to make fReindex atomic so that the ThreadImport write doesn't "race" with net_processing reads? |
Ping @TheBlueMatt if you have a bit of time :) |
src/init.cpp
Outdated
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size()); | ||
} | ||
LogPrintf("nBestHeight = %d\n", chainActive.Height()); | ||
|
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: EOL whitespace here.
src/validation.cpp
Outdated
@@ -3523,7 +3523,7 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) | |||
// Check whether we need to continue reindexing | |||
bool fReindexing = false; | |||
pblocktree->ReadReindexing(fReindexing); | |||
fReindex |= fReindexing; | |||
fReindex = fReindex | fReindexing; |
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.
Might as well use the atomic or here since we're making it atomic, no?
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.
|=
? It is only defined on atomic integral types I believe, not bool
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.
Err, indeed, quivalent is to do an if(fReindexing) fReindex = 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.
Yeah true that's cleaner, will do
src/init.cpp
Outdated
@@ -1632,8 +1632,12 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) | |||
// ********************************************************* Step 11: start node | |||
|
|||
//// debug print | |||
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size()); | |||
LogPrintf("nBestHeight = %d\n", chainActive.Height()); | |||
{ |
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.
Indeed, ight as well pull chainActive.Height() into the cs_main here.
utACK 731065b |
@@ -3523,7 +3523,7 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) | |||
// Check whether we need to continue reindexing | |||
bool fReindexing = false; | |||
pblocktree->ReadReindexing(fReindexing); | |||
fReindex |= fReindexing; |
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.
What's wrong with |= ?
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.
See my reply to @TheBlueMatt's comment above, it's not implemented for atomic bool :)
utACK 731065b |
Added a new commit to make fUseCrypto atomic as well, see #10916 (comment) @TheBlueMatt @jonasschnelli |
Friendly ping @jonasschnelli and/or @TheBlueMatt if you have time, the last commit is only a 2 line change so shouldn't be too time consuming to review ;) |
utACK c626dcb |
…c bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes #11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
…d atomic bools c626dcb Make fUseCrypto atomic (MeshCollider) 731065b Consistent parameter names in txdb.h (MeshCollider) 35aeabe Make fReindex atomic to avoid race (MeshCollider) 58d91af Fix race for mapBlockIndex in AppInitMain (MeshCollider) Pull request description: Fixes bitcoin#11106 Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916 bitcoin@d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex Tree-SHA512: b378aa7289fd505b76565cd4d48dcdc04ac5540283ea1c80442170b0f13cb6df771b1a94dd54b7fec3478a7b4668c224ec9d795f16937782724c5d020edd3a42
Fix races in AppInitMain and others with lock and atomic bools (Bitcoin backport) Backport bitcoin bitcoin/bitcoin#11107 (excluding the last commit, it was fixed in Zcash before). This functionality is required for #4368 (details #4368 (comment)) as part of the issue #3813 resolution.
zcash: cherry picked from commit c626dcb zcash: bitcoin/bitcoin#11107
Bitcoin 0.16 locking PRs These are locking changes from upstream (bitcoin core) release 0.16 (Aug 14, 2017, to Feb 16, 2018), oldest to newest (when merged to the master branch). Each commit also includes a reference both to the PR and the upstream commit. - bitcoin/bitcoin#11126 - Excludes changes to wallet tests that we don't have. - bitcoin/bitcoin#10916 - first commit only; second commit already merged by d9fcc2b - bitcoin/bitcoin#11107 - Only the last commit. - bitcoin/bitcoin#11593 - bitcoin/bitcoin#11585 - bitcoin/bitcoin#11618 - bitcoin/bitcoin#10286 - Only the third and last commits. - bitcoin/bitcoin#11870 - bitcoin/bitcoin#12330 - bitcoin/bitcoin#12366 - bitcoin/bitcoin#12368 - bitcoin/bitcoin#12333 - Only the first commit.
7a5d181 Use the character based overload for std::string::find. (Alin Rus) c19401b Don't use pass by reference to const for cheaply-copied types (bool, char, etc.). (practicalswift) 4c5fe36 [Refactor] Remove unused fQuit var from checkqueue.h (donaloconnor) fda7a5f Cleanup: remove unneeded header includes (random-zebra) ac2476c Add test cases covering the relevant key length boundaries: 64 bytes +/- 1 byte for HMAC-SHA256 and 128 bytes +/- 1 byte for HMAC-SHA512 (practicalswift) a346262 Fix code constness in CBlockIndex::GetAncestor() overloads (Dan Raviv) 65e3f4e Refactor: More range-based for loops (random-zebra) dd3d3c4 Use range-based for loops (C++11) when looping over map elements (practicalswift) 5a7750a Move RPC registration out of AppInitParameterInteraction (Russell Yanofsky) 402b4c4 Use compile-time constants instead of unnamed enumerations (practicalswift) bbac2d0 [Trivial] Fix indentation in coins.cpp (random-zebra) e539c62 Small refactor of CCoinsViewCache::BatchWrite() (Dan Raviv) ec91759 Use MakeUnique<T>(...) instead of std::unique_ptr<T>(new T(...)) (random-zebra) 93487b1 Use unique_ptr for pcoinscatcher/pcoinsdbview/pcoinsTip/pblocktree (random-zebra) ff43d69 Use unique_ptr for pdbCopy (Db) and fix potential memory leak (practicalswift) b4d9641 Use unique_ptr for dbenv (DbEnv) (practicalswift) 36108b9 Use unique_ptr for pfilter (CBloomFilter) (practicalswift) ff1c454 Use unique_ptr for sem{Addnode,Outbound} (CSemaphore) (practicalswift) 93daf17 Use unique_ptr for httpRPCTimerInterface (HTTPRPCTimerInterface) (practicalswift) 020ac16 Init: Remove redundant exit(EXIT_FAILURE) instances and replace with (random-zebra) b9f5d1f Remove duplicate uriParts.size() > 0 check (practicalswift) 440d961 Remove redundant check (!ecc is always true) (practicalswift) bfd295b Remove redundant NULL checks after new (practicalswift) 97aad32 Make fUseCrypto atomic (MeshCollider) 2711f78 Consistent parameter names in txdb.h (MeshCollider) d40df3a Fix race for mapBlockIndex in AppInitMain (random-zebra) 03b7766 Cleanup: remove unused functions to Hash the concat of 4 or more objects (random-zebra) c520e0f Remove some unused functions and methods (Pieter Wuille) 508f1a1 range-based loops and const qualifications in net.cpp (Marko Bencun) 79b1e50 Refactor: implement CPubKey::data() (random-zebra) 614d26c Refactor: more &vec[0] to vec.data() (random-zebra) 02b6337 Changing &vec[0] to vec.data(), what 9804 missed (MeshCollider) c1c8b05 Ensure that data types are consistent (jjz) 732bb9d Fix potential null dereferences (MeshCollider) 80f35f9 Remove unreachable code (practicalswift) Pull request description: This is a collection of simple refactorings coming from upstream Bitcoin v0.16 (adapting/extending to PIVX-specific code where needed). Pull requests backported: - bitcoin#10845 (practicalswift) - bitcoin#11238 (MeshCollider) - bitcoin#11232 (jjz) - bitcoin#10793 (MeshCollider) - bitcoin#10888 (benma) - ~~bitcoin#11351 (danra)~~ [edit: removed - included in #2423] - bitcoin#11385 (sipa) - bitcoin#11107 (MeshCollider) - bitcoin#10898 (practicalswift) - bitcoin#11511 (donaloconnor) - bitcoin#11043 (practicalswift) - bitcoin#11353 (danra) - bitcoin#10749 (practicalswift) - bitcoin#11603 (ryanofsky) - bitcoin#10493 (practicalswift) - bitcoin#11337 (danra) - bitcoin#11516 (practicalswift) - bitcoin#10574 (practicalswift) - bitcoin#12108 (donaloconnor) - bitcoin#10839 (practicalswift) - bitcoin#12159 (kekimusmaximus) ACKs for top commit: Fuzzbawls: ACK 7a5d181 furszy: re-ACK 7a5d181 after rebase, no code changes. Merging.. Tree-SHA512: d92f5df47f443391a6531274a2efb9a4882c62d32eff628f795b3abce703f108c8b40ec80ac841cde6c5fdd5c9ff2b6056a31546ac2edda279f5f18fccc99c32
Fixes #11106
Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916
d291e76 just renames the parameters in the txdb header file to make them consistent with those used in the cpp file, noticed it when looking for uses of fReindex