mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:44:38 +00:00
net: move some CNodeState fields to Peer #35561
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35561
Loading…
Reference in a new issue
No description provided.
Delete branch "06082026/cnodestate"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The first commit moves
m_requested_hb_cmpctblocksandm_provides_cmpctblocksfrom CNodeState to Peer and also makes the two fields atomic.The second commit moves
fPreferredDownloadto Peer and makes it atomic. Sincem_num_preferred_download_peersis a counter based on this field, it can also be atomic. This also lets us dropcs_mainusage in a few places. I found this commit harder to reason about, specifically whether the asserts in FinalizeNode were still safe form_num_preferred_download_peersif another thread could modify the value before/after them_num_preferred_download_peers -= peer->fPreferredDownloadline and trigger the assert. Afaict, these asserts are still safe because ProcessMessage cannot run for the same peer as the peer being cleaned up in FinalizeNode. I am also happy to drop this second commit or explain my reasoning in more detail.For reference:
m_requested_hb_cmpctblockscan be accessed from:NewPoWValidBlock(read) (b-msghand, http, ipc? threads)ProcessMessage(write) (b-msghand)SendMessages(read) (b-msghand)m_provides_cmpctblockscan be accessed from:MaybeSetPeerAsAnnouncingHeaderAndIDs(read) (b-msghand, http, ipc?)HeadersDirectFetchBlocks(read) (b-msghand)ProcessMessage(write) (b-msghand)fPreferredDownloadcan be accessed from:ProcessMessage(read/write) (b-msghand)SendMessages(read) (b-msghand)FinalizeNode(read) (bitcoind, b-net)m_num_preferred_download_peerscan be accessed from:ProcessMessage(write) (b-msghand)SendMessages(read) (b-msghand)FinalizeNode(read/write) (bitcoind, b-net)The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
-addnodeby w0xlt)If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Concept ACK, Reviewed to https://github.com/bitcoin/bitcoin/pull/35561/changes/0954ae669683a3179a362dd47cb6176cda914eb2.
Less
cs_mainis good, locks are scary, and can hurt performance, and are unnecessary for all of these fields. I need to review https://github.com/bitcoin/bitcoin/pull/35561/commits/765f65971aa4fc6c7c0bdf971b4cdc771a5a296e carefully.This scoping can be removed now that the lock is gone, will fix the next time I push up.
Code review ACK 765f65971aa4fc6c7c0bdf971b4cdc771a5a296e
The changes themselves look fine/safe to me but I think it might be useful to provide more motivation for this change.
The
m_num_preferred_download_peerschange also seems correct to me, but I found the previous version with a shared lock (i.e.cs_main) a little easier to reason about wrt "at anytimem_num_preferred_download_peersreflects the number ofCNodeStates withfPreferredDownloadequals true".nit: could scripted diff this to
m_preferred_downloadI started doing this to see how complicated the change would be to remove CNodeState and the cs_main locking it requires, I have more branches that move some of the other fields. I think tracking multiple states (CNodeState & Peer) is more confusing to reason about than just having one state and I think? it's been a goal to reduce the scope of cs_main (i.e. https://github.com/bitcoin/bitcoin/issues/27502). I have a private branch that removes some other fields, though there are some gotchas with locking.
Same. I think in this specific case, it's possible to replace the atomic with a smaller lock than cs_main. However, I don't think this is true of some other fields due to potential deadlock warnings that I haven't figured out how to fix. I think a smaller lock would be clearer than having two atomics here, open to changing it.
Concept ACK
to be fair, we do have the same pattern with
m_wtxid_relay/m_wtxid_relay_peerswhich are also two atomics, so no strong opinion.should
NewPoWValidBlockget a!m_peer_mutexannotation, now that we callGetPeerReffrom it? I think it may be missed by the compiler due to the lambda it is used in.It is indeed missed by the compiler because of the lambda. Should the annotation be added if the compiler silently skips it?
I'd say yes, since it would be incorrect to call the function with
m_peer_mutexheld, and I don't think the compiler would complain about something it may see as a "false positive".🚧 At least one of the CI tasks failed.
Task
Windows native, fuzz, VS: https://github.com/bitcoin/bitcoin/actions/runs/32914333828/job/98014730803LLM reason (✨ experimental): CI failed because the fuzz target
rpccrashed (Windows exit code 3221225477 / access violation).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
765f659 to
3861ab4: rebased since #32606 added another callsite usingm_provides_cmpctblocks. Also added a commit for scripted diff. CI failures are https://github.com/bitcoin/bitcoin/pull/36088.added in
1648713efeadded in
3861ab49ecACK
3861ab49ec🐙 This pull request conflicts with the target branch and needs rebase.
3861ab4..9686707 rebased after new field added to
CNodeState😅I found no actionable issues in this static review.
Reviewed:
4b02684629ce· Review report · Previous reportspermalink
🐙 This pull request conflicts with the target branch and needs rebase.
Seems like there is agreement to do this. Maybe one more rebase to get it over the line? Also cc @instagibbs
ACK once rebased
reACK
4b02684629