Fix races in AppInitMain and others with lock and atomic bools #11107

pull meshcollider wants to merge 4 commits into bitcoin:master from meshcollider:fix_mapBlockIndex_race changing 5 files +20 −11
  1. meshcollider commented at 9:05 AM on August 22, 2017: contributor

    Fixes #11106

    Also makes fReindex atomic as suggested in @TheBlueMatt comment below, and makes fUseCrypto atomic as suggested in 10916

    https://github.com/bitcoin/bitcoin/pull/11107/commits/d291e7635b0ef4156c2805c6c4ee1adad91f0307 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

  2. in src/init.cpp:1637 in 79e0b157c7 outdated
    1631 | @@ -1632,8 +1632,12 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
    1632 |      // ********************************************************* Step 11: start node
    1633 |  
    1634 |      //// debug print
    1635 | -    LogPrintf("mapBlockIndex.size() = %u\n",   mapBlockIndex.size());
    1636 | -    LogPrintf("nBestHeight = %d\n",                   chainActive.Height());
    1637 | +    {
    


    jonasschnelli commented at 9:35 AM on August 22, 2017:

    I guess it would make sense to also cover mapBlockIndex and chainActive to make this move-safe.


    meshcollider commented at 9:44 AM on August 22, 2017:

    chainActive.Height() is also accessed on line 1652, you want to bring it in too?


    promag commented at 3:56 AM on August 23, 2017:

    If chainActive is added then update descriptions accordingly.

    Did you search for other cases?


    meshcollider commented at 4:35 AM on August 23, 2017:

    No haven't modified the pull yet, it still just fixes the issue linked


    TheBlueMatt commented at 12:36 AM on September 6, 2017:

    Indeed, ight as well pull chainActive.Height() into the cs_main here.

  3. jonasschnelli added the label Refactoring on Aug 22, 2017
  4. meshcollider commented at 9:45 AM on August 22, 2017: contributor

    Travis error looks unrelated, timeout in sendheaders.py - assert(wait_until(test_function, timeout=60))

  5. TheBlueMatt commented at 7:22 PM on August 23, 2017: member

    While you're at it, want to make fReindex atomic so that the ThreadImport write doesn't "race" with net_processing reads?

  6. meshcollider commented at 1:36 AM on September 5, 2017: contributor

    Ping @TheBlueMatt if you have a bit of time :)

  7. in src/init.cpp:1640 in 8a086767a3 outdated
    1637 | +    {
    1638 | +        LOCK(cs_main);
    1639 | +        LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size());
    1640 | +    }
    1641 | +    LogPrintf("nBestHeight = %d\n", chainActive.Height());
    1642 | +	
    


    TheBlueMatt commented at 12:31 AM on September 6, 2017:

    nit: EOL whitespace here.

  8. in src/validation.cpp:3526 in 8a086767a3 outdated
    3522 | @@ -3523,7 +3523,7 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
    3523 |      // Check whether we need to continue reindexing
    3524 |      bool fReindexing = false;
    3525 |      pblocktree->ReadReindexing(fReindexing);
    3526 | -    fReindex |= fReindexing;
    3527 | +    fReindex = fReindex | fReindexing;
    


    TheBlueMatt commented at 12:35 AM on September 6, 2017:

    Might as well use the atomic or here since we're making it atomic, no?


    meshcollider commented at 1:26 AM on September 6, 2017:

    |=? It is only defined on atomic integral types I believe, not bool


    TheBlueMatt commented at 8:36 PM on September 6, 2017:

    Err, indeed, quivalent is to do an if(fReindexing) fReindex = true


    meshcollider commented at 12:01 AM on September 7, 2017:

    Yeah true that's cleaner, will do

  9. Fix race for mapBlockIndex in AppInitMain 58d91af59e
  10. Make fReindex atomic to avoid race 35aeabec62
  11. Consistent parameter names in txdb.h 731065b114
  12. TheBlueMatt commented at 6:47 PM on September 7, 2017: member

    utACK 731065b114452ff770320d09639448b3c9a74b0a

  13. in src/validation.cpp:3526 in 731065b114 outdated
    3522 | @@ -3523,7 +3523,7 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
    3523 |      // Check whether we need to continue reindexing
    3524 |      bool fReindexing = false;
    3525 |      pblocktree->ReadReindexing(fReindexing);
    3526 | -    fReindex |= fReindexing;
    


    jtimon commented at 7:59 PM on September 7, 2017:

    What's wrong with |= ?


    meshcollider commented at 8:05 PM on September 7, 2017:

    See my reply to @TheBlueMatt's comment above, it's not implemented for atomic bool :)

  14. jtimon commented at 8:00 PM on September 7, 2017: contributor

    utACK 731065b

  15. Make fUseCrypto atomic c626dcb50e
  16. meshcollider commented at 11:30 PM on September 9, 2017: contributor

    Added a new commit to make fUseCrypto atomic as well, see #10916 (comment) @TheBlueMatt @jonasschnelli

  17. meshcollider renamed this:
    Fix race for mapBlockIndex in AppInitMain
    Fix races in AppInitMain and others with lock and atomic bools
    on Sep 9, 2017
  18. meshcollider commented at 1:46 AM on September 24, 2017: contributor

    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 ;)

  19. TheBlueMatt commented at 11:30 PM on October 3, 2017: member

    utACK c626dcb50eed496462fd4ac3e05bf79164749ebe

  20. jonasschnelli commented at 5:36 AM on October 4, 2017: contributor

    utACK https://github.com/bitcoin/bitcoin/commit/c626dcb50eed496462fd4ac3e05bf79164749ebe Generally "unrelated" cleanups (like 731065b114452ff770320d09639448b3c9a74b0a) should be avoided.

  21. MarcoFalke merged this on Oct 5, 2017
  22. MarcoFalke closed this on Oct 5, 2017

  23. MarcoFalke referenced this in commit e93fff1463 on Oct 5, 2017
  24. meshcollider deleted the branch on Oct 9, 2017
  25. PastaPastaPasta referenced this in commit cee77b76d5 on Dec 22, 2019
  26. PastaPastaPasta referenced this in commit 4e4574c95c on Jan 2, 2020
  27. PastaPastaPasta referenced this in commit c0ef6547e8 on Jan 4, 2020
  28. PastaPastaPasta referenced this in commit c6fd593eef on Jan 12, 2020
  29. PastaPastaPasta referenced this in commit 73b3ef974a on Jan 12, 2020
  30. PastaPastaPasta referenced this in commit 88b7c4ec79 on Jan 12, 2020
  31. PastaPastaPasta referenced this in commit e12d711957 on Jan 12, 2020
  32. PastaPastaPasta referenced this in commit f262a8e85e on Jan 12, 2020
  33. PastaPastaPasta referenced this in commit 7da3480fe0 on Jan 12, 2020
  34. PastaPastaPasta referenced this in commit 9498e62c0e on Jan 16, 2020
  35. PastaPastaPasta referenced this in commit 980a053af8 on Jan 22, 2020
  36. PastaPastaPasta referenced this in commit d3bb020851 on Jan 29, 2020
  37. PastaPastaPasta referenced this in commit d44ea694a9 on Jan 29, 2020
  38. zkbot referenced this in commit 8c48786d7d on Mar 9, 2020
  39. LarryRuane referenced this in commit c60419e521 on Mar 3, 2021
  40. ckti referenced this in commit 75076e3c17 on Mar 28, 2021
  41. LarryRuane referenced this in commit ea9bcc4774 on Apr 13, 2021
  42. zkbot referenced this in commit 0e36226271 on Apr 17, 2021
  43. furszy referenced this in commit 60d36292bc on Jul 26, 2021
  44. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me