Locking fix for AlreadyHave() #1094

pull jgarzik wants to merge 1 commits into bitcoin:master from jgarzik:already-have-locking changing 1 files +11 −2
  1. jgarzik commented at 10:26 PM on April 13, 2012: contributor

    Access to mapTransactions[] must be guarded by cs_mapTransactions lock.

    Also, reformat long lines to make the switch statement more readable.

  2. Locking fix for AlreadyHave()
    Access to mapTransactions[] must be guarded by cs_mapTransactions lock.
    
    Also, reformat long lines to make the switch statement more readable.
    8deb9822e4
  3. jgarzik commented at 12:14 AM on April 14, 2012: contributor

    It is unfortunate that AlreadyHave() is called in a loop, implying a lot of lock/release in a row (even if it is likely cached and uncontended).

    If LOCK() is moved outside AlreadyHave() and above its callers' loops, that reduces lock/release to one, but holds the lock for MSG_BLOCK in addition to MSG_TX.

  4. laanwj commented at 5:53 AM on April 14, 2012: member

    How long do the loops run on average/worst-case? Is the runtime of the loops that enclose AlreadyHave dependent on I/O such as network/database?

    It looks like AlreadyHave runs very fast (just some hash lookups), however the enclosing loops contains network calls such as PushMessage. I suppose it is undesirable to hold the lock during those?

    In that case the current solution is best. It is also the best encapsulation.

  5. sipa commented at 4:17 PM on April 17, 2012: member

    ACK. If there is a performance problem arises for the processing of "inv" messages, we can always move the lock to a pre-processing step that filters the received inv list before further processing.

  6. laanwj commented at 4:19 PM on April 17, 2012: member

    ACK, agreed, safety comes first

    Edit: Btw, what's the reason that mapBlockIndex / mapOrphanBlocks don't require a mutex? Are they only ever accessed from one thread?

  7. sipa commented at 4:23 PM on April 17, 2012: member

    Actually, I'd prefer the txdb.ContainsTx() call to be outside of the lock, as the db lookup could be slow.

  8. jgarzik referenced this in commit dd21ce5f1b on Apr 17, 2012
  9. jgarzik merged this on Apr 17, 2012
  10. jgarzik closed this on Apr 17, 2012

  11. jgarzik commented at 4:32 PM on April 17, 2012: contributor

    updated

  12. coblee referenced this in commit 0ccb3f5293 on Jul 17, 2012
  13. jgarzik deleted the branch on Aug 24, 2014
  14. suprnurd referenced this in commit e30f8bf6a0 on Dec 5, 2017
  15. lateminer referenced this in commit 24c460fecb on Jan 22, 2019
  16. DrahtBot locked this on Sep 8, 2021
Contributors
Labels

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-20 00:16 UTC

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