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.
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-
promag commented at 2:23 PM on September 3, 2019: member
-
MarcoFalke commented at 2:35 PM on September 3, 2019: member
Tend to NACK, as this seems like a layer violation
- DrahtBot added the label Refactoring on Sep 3, 2019
- DrahtBot added the label Validation on Sep 3, 2019
-
promag commented at 2:48 PM on September 3, 2019: member
@MarcoFalke I don't understand why, this change makes
NotifyHeaderTipreturn whether it's IBD. Note thatNotifyHeaderTipalready sends it in the notification. -
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.
-
MarcoFalke commented at 3:11 PM on September 3, 2019: member
the lock is needed for
g_chainstate -
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?
-
MarcoFalke commented at 8:38 PM on September 3, 2019: member
I figured that would change with assumeutxo? Maybe @jamesob knows
-
jamesob commented at 8:42 PM on September 3, 2019: member
Later on
g_chainstate(orChainstateActive()) 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. -
jamesob commented at 8:44 PM on September 3, 2019: member
...though don't we need cs_main to safely use
ppindex? -
MarcoFalke commented at 8:45 PM on September 3, 2019: member
Not for the members that are read (
nHeightet al) -
MarcoFalke commented at 8:47 PM on September 3, 2019: member
-
promag commented at 12:12 PM on September 5, 2019: member
@MarcoFalke why are you linking that comment?
-
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. -
refactor: Avoid locking cs_main in ProcessNewBlockHeaders 3109a1f948
-
promag commented at 11:40 PM on September 5, 2019: member
Done.
- promag force-pushed on Sep 5, 2019
- MarcoFalke referenced this in commit ae3e3bd151 on Sep 6, 2019
- MarcoFalke merged this on Sep 6, 2019
- MarcoFalke closed this on Sep 6, 2019
- promag deleted the branch on Sep 6, 2019
- jasonbcox referenced this in commit 8a397ebe78 on Sep 30, 2020
- humbleDasher referenced this in commit 4bf53b1931 on Nov 13, 2021
- pravblockc referenced this in commit c6ea021589 on Nov 18, 2021
- DrahtBot locked this on Dec 16, 2021