refactor: Avoid locking cs_main in ProcessNewBlockHeaders #16793

pull promag wants to merge 1 commits into bitcoin:master from promag:2019-09-csmain-headers changing 1 files +0 −1
  1. promag commented at 2:23 PM on September 3, 2019: member

    Builds on #16774, this change avoids locking cs_main in ProcessNewBlockHeaders when the tip has changed - in this case the removed lock was necessary to just log a message.

  2. MarcoFalke commented at 2:35 PM on September 3, 2019: member

    Tend to NACK, as this seems like a layer violation

  3. DrahtBot added the label Refactoring on Sep 3, 2019
  4. DrahtBot added the label Validation on Sep 3, 2019
  5. promag commented at 2:48 PM on September 3, 2019: member

    @MarcoFalke I don't understand why, this change makes NotifyHeaderTip return whether it's IBD. Note that NotifyHeaderTip already sends it in the notification.

  6. TheBlueMatt commented at 3:10 PM on September 3, 2019: member

    NACK as-is, but IsInitialBlockDownload() doesn't need cs_main anyway (it takes it itself if it needs it, and has an atomic cache first), so it looks like you should be able to just drop the cs_mains here wholesale with no other changes.

  7. MarcoFalke commented at 3:11 PM on September 3, 2019: member

    the lock is needed for g_chainstate

  8. TheBlueMatt commented at 8:31 PM on September 3, 2019: member

    Huh? g_chainstate is set during init (pre-threading) and never edited after. No reason it would need cs_main, either?

  9. MarcoFalke commented at 8:38 PM on September 3, 2019: member

    I figured that would change with assumeutxo? Maybe @jamesob knows

  10. jamesob commented at 8:42 PM on September 3, 2019: member

    Later on g_chainstate (or ChainstateActive()) will be covered by some lock (since it may be swapped out during runtime), but probably not cs_main. I think for now we should be able to do as @TheBlueMatt and just drop the lock acquisition.

  11. jamesob commented at 8:44 PM on September 3, 2019: member

    ...though don't we need cs_main to safely use ppindex?

  12. MarcoFalke commented at 8:45 PM on September 3, 2019: member

    Not for the members that are read (nHeight et al)

  13. MarcoFalke commented at 8:47 PM on September 3, 2019: member
  14. promag commented at 12:12 PM on September 5, 2019: member

    @MarcoFalke why are you linking that comment?

  15. MarcoFalke commented at 5:31 PM on September 5, 2019: member

    cs_main might be needed for pindexBestHeader, but that is no longer in the current code. So, indeed, you can just remove cs_main here.

  16. refactor: Avoid locking cs_main in ProcessNewBlockHeaders 3109a1f948
  17. promag commented at 11:40 PM on September 5, 2019: member

    Done.

  18. promag force-pushed on Sep 5, 2019
  19. MarcoFalke referenced this in commit ae3e3bd151 on Sep 6, 2019
  20. MarcoFalke merged this on Sep 6, 2019
  21. MarcoFalke closed this on Sep 6, 2019

  22. promag deleted the branch on Sep 6, 2019
  23. jasonbcox referenced this in commit 8a397ebe78 on Sep 30, 2020
  24. humbleDasher referenced this in commit 4bf53b1931 on Nov 13, 2021
  25. pravblockc referenced this in commit c6ea021589 on Nov 18, 2021
  26. DrahtBot locked this on Dec 16, 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 18:14 UTC

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