qt: Remove redundant locks #11733

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:redundant-locks changing 1 files +3 −9
  1. practicalswift commented at 12:52 PM on November 20, 2017: contributor

    Remove redundant locks:

    • FindNode(...) is locking cs_vNodes internally
    • SetAddressBook(...) is locking cs_wallet internally
    • DelAddressBook(...) is locking cs_wallet internally

    Note to reviewers: From what I can tell these locks are redundantly held from a data integrity perspective (guarding specific variables), and they do not appear to be needed from a data consistency perspective (ensuring a consistent state at the right points). Review thoroughly and please let me know if I'm mistaken :-)

  2. fanquake added the label Refactoring on Nov 20, 2017
  3. fanquake commented at 1:28 PM on November 20, 2017: member

    The changes to net.cpp remove 2/3 LOCKs introduced in 3c37dc40d39e1a1e56b6b0d3e660626a78656d4f, part of #9626.

    "This also ensures that if we return a CNode* from FindNode, we are still holding cs_vNodes if we use it for anything aside from existance-checking, fixing a stupid-unlikely race where it might be deleted out from under us."

  4. practicalswift commented at 1:52 PM on November 20, 2017: contributor

    @fanquake Thanks for reviewing. Good point. Would it be possible to state that locking requirement more explicitly using annotations (see #11226)? Perhaps one way to do it would be if the two uses were separated: CNode* FindNode(…) would require holding cs_vNodes (which would be clearly stated using EXCLUSIVE_LOCKS_REQUIRED(cs_vNodes)) whereas say bool NodeExists(…) wouldn't? Worth doing?

  5. in src/net.cpp:402 in cf6c726644 outdated
     398 | @@ -399,7 +399,6 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
     399 |              // In that case, drop the connection that was just created, and return the existing CNode instead.
     400 |              // Also store the name we used to connect in that CNode, so that future FindNode() calls to that
     401 |              // name catch this early.
     402 | -            LOCK(cs_vNodes);
    


    promag commented at 3:35 PM on November 20, 2017:

    I think this is necessary. cc @theuni


    practicalswift commented at 3:48 PM on November 20, 2017:

    Yes, see @fanquake's comment above regarding 3c37dc4 :-)


    promag commented at 3:52 PM on November 20, 2017:

    Alright 😄

  6. in src/net.cpp:2555 in cf6c726644 outdated
    2550 | @@ -2552,7 +2551,6 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats)
    2551 |  
    2552 |  bool CConnman::DisconnectNode(const std::string& strNode)
    2553 |  {
    2554 | -    LOCK(cs_vNodes);
    


    promag commented at 3:36 PM on November 20, 2017:

    Same as above.

  7. Remove redundant locks
    * SetAddressBook(...) is locking cs_wallet internally
    * DelAddressBook(...) is locking cs_wallet internally
    d6f3a73736
  8. practicalswift force-pushed on Nov 21, 2017
  9. practicalswift commented at 9:18 AM on November 21, 2017: contributor

    @fanquake @promag Please re-review :-)

  10. MarcoFalke renamed this:
    Remove redundant locks
    qt: Remove redundant locks
    on Nov 21, 2017
  11. practicalswift commented at 12:55 PM on January 31, 2018: contributor

    Anyone willing to review? :-)

  12. MarcoFalke commented at 2:45 PM on January 31, 2018: member

    Any measurable speedup by removing those? Just asking.

  13. practicalswift commented at 3:06 PM on January 31, 2018: contributor

    @MarcoFalke I would assume no. My goal with this PR was to achieve correct locking, so any measurable speed-up would be an unintended bonus :-)

  14. ryanofsky commented at 5:49 PM on January 31, 2018: member

    utACK d6f3a737361d8fb562f08763f613a6529b870d1e. This could help performance since it releases the lock while writing to disk. Anyway it's an obvious improvement for code simplicity & consistency.

  15. laanwj commented at 4:26 PM on February 14, 2018: member

    utACK d6f3a73, indeed makes no sense to do this locking internally as well as externally, and having the locking contained internally is better.

  16. laanwj merged this on Feb 14, 2018
  17. laanwj closed this on Feb 14, 2018

  18. laanwj referenced this in commit e782099a15 on Feb 14, 2018
  19. jasonbcox referenced this in commit bf97bcfb82 on Mar 26, 2019
  20. jonspock referenced this in commit 2d9196a9e0 on Apr 6, 2019
  21. jonspock referenced this in commit b658bcd4b1 on Apr 8, 2019
  22. jonspock referenced this in commit 251d8051e1 on Apr 8, 2019
  23. PastaPastaPasta referenced this in commit 063a9265b2 on Jun 10, 2020
  24. PastaPastaPasta referenced this in commit 2065d47494 on Jun 12, 2020
  25. PastaPastaPasta referenced this in commit ef57921fc7 on Jun 13, 2020
  26. PastaPastaPasta referenced this in commit 05b043d26f on Jun 14, 2020
  27. PastaPastaPasta referenced this in commit 82f04481f1 on Jun 14, 2020
  28. practicalswift deleted the branch on Apr 10, 2021
  29. gades referenced this in commit 3198bb43d3 on Mar 8, 2022
  30. DrahtBot locked this on Aug 16, 2022

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 21:15 UTC

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