Skip to content

Conversation

@promag
Copy link
Contributor

@promag promag commented Sep 3, 2019

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.

@maflcko
Copy link
Member

maflcko commented Sep 3, 2019

Tend to NACK, as this seems like a layer violation

@promag
Copy link
Contributor Author

promag commented Sep 3, 2019

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

@TheBlueMatt
Copy link
Contributor

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.

@maflcko
Copy link
Member

maflcko commented Sep 3, 2019

the lock is needed for g_chainstate

@TheBlueMatt
Copy link
Contributor

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

@maflcko
Copy link
Member

maflcko commented Sep 3, 2019

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

@jamesob
Copy link
Contributor

jamesob commented Sep 3, 2019

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.

@jamesob
Copy link
Contributor

jamesob commented Sep 3, 2019

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

@maflcko
Copy link
Member

maflcko commented Sep 3, 2019

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

@maflcko
Copy link
Member

maflcko commented Sep 3, 2019

#15615 (comment)

@promag
Copy link
Contributor Author

promag commented Sep 5, 2019

@MarcoFalke why are you linking that comment?

@maflcko
Copy link
Member

maflcko commented Sep 5, 2019

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.

@promag
Copy link
Contributor Author

promag commented Sep 5, 2019

Done.

@promag promag force-pushed the 2019-09-csmain-headers branch from e21478b to 3109a1f Compare September 5, 2019 23:40
maflcko pushed a commit that referenced this pull request Sep 6, 2019
3109a1f refactor: Avoid locking cs_main in ProcessNewBlockHeaders (João Barbosa)

Pull request description:

  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.

Top commit has no ACKs.

Tree-SHA512: 31be6d319fa122804f72fa813cec5ed041dd7e4aef3c1921124a1f03016925c43cd4d9a272d80093e77fa7600e3506ef47b7bb821afcbffe01e6be9bceb6dc00
@maflcko maflcko merged commit 3109a1f into bitcoin:master Sep 6, 2019
@promag promag deleted the 2019-09-csmain-headers branch September 6, 2019 12:26
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 30, 2020
…ders

Summary:
The locking was added in a [[bitcoin/bitcoin#15615 (comment) | previous pull request]] during the review phase, but the reason for this lock was later [[bitcoin/bitcoin#15615 (review) | removed during the same review]].

Backport of Core [[bitcoin/bitcoin#16793 | PR16793]]
Depends on D7634

Test Plan:
```
cmake .. -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug
ninja all ckeck-all

```

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, deadalnix

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, deadalnix

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7637
humbleDasher pushed a commit to humbleDasher/dash that referenced this pull request Nov 13, 2021
…ckHeaders

3109a1f refactor: Avoid locking cs_main in ProcessNewBlockHeaders (João Barbosa)

Pull request description:

  Builds on bitcoin#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.

Top commit has no ACKs.

Tree-SHA512: 31be6d319fa122804f72fa813cec5ed041dd7e4aef3c1921124a1f03016925c43cd4d9a272d80093e77fa7600e3506ef47b7bb821afcbffe01e6be9bceb6dc00
pravblockc pushed a commit to pravblockc/dash that referenced this pull request Nov 18, 2021
…ckHeaders

3109a1f refactor: Avoid locking cs_main in ProcessNewBlockHeaders (João Barbosa)

Pull request description:

  Builds on bitcoin#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.

Top commit has no ACKs.

Tree-SHA512: 31be6d319fa122804f72fa813cec5ed041dd7e4aef3c1921124a1f03016925c43cd4d9a272d80093e77fa7600e3506ef47b7bb821afcbffe01e6be9bceb6dc00
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants