-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: Move CNodeState members guarded by g_msgproc_mutex to Peer #26140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Move CNodeState members guarded by g_msgproc_mutex to Peer #26140
Conversation
Concept ACK |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
8c22a6e
to
ca898b4
Compare
ca898b4
to
cafaa98
Compare
Rebased to avoid the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach ACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cafaa98
to
de97ab2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
light code review ACK de97ab2
de97ab2
to
7aa79e7
Compare
-BEGIN VERIFY SCRIPT- ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); } ren nUnconnectingHeaders m_num_unconnecting_headers_msgs ren fPreferHeaders m_prefers_headers ren MAX_UNCONNECTING_HEADERS MAX_NUM_UNCONNECTING_HEADERS_MSGS -END VERIFY SCRIPT-
37bb332
to
3a060ae
Compare
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code review ACK 3a060ae, as in I am convinced these members shouldn't be guarded by cs_main and belong in Peer/TxRelay. clang checked the annotations for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 3a060ae
FWIW, I have no issues with TSan-instrumented builds locally using both clang-14 and clang-15. Also the "TSan, depends, gui" CI task passed for me locally. |
@@ -2248,7 +2258,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv& | |||
} | |||
} | |||
|
|||
CTransactionRef PeerManagerImpl::FindTxForGetData(const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) | |||
CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to pass in a const TxRelay&
here instead of a const Peer&
?
@@ -2263,7 +2273,7 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const CNode& peer, const GenTx | |||
{ | |||
LOCK(cs_main); | |||
// Otherwise, the transaction must have been announced recently. | |||
if (State(peer.GetId())->m_recently_announced_invs.contains(gtxid.GetHash())) { | |||
if (Assume(peer.GetTxRelay())->m_recently_announced_invs.contains(gtxid.GetHash())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the LOCK(cs_main)
now (and the LOCKS_EXCLUDED(cs_main)
annotation from the function declaration)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, seems like it. Will do this in a follow up (including your other suggestion), thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this doesn't work because mapRelay
is guraded by cs_main
😭😭😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But... mapRelay
is actually only accessed from the msg proc thread, so we can simply mark it as guarded by g_msgproc_mutex
and still do this!
…sgproc mutex to Peer
3fa4c54 [net processing] Pass TxRelay to FindTxForGetData instead of Peer (dergoegge) c85ee76 [net processin] Don't take cs_main in FindTxForGetData (dergoegge) Pull request description: Addresses left over feedback from #26140. * bitcoin/bitcoin#26140 (comment) * bitcoin/bitcoin#26140 (comment) `mapRelay` is only accessed from the message processing thread and does not need to be kept in sync with anything validation specific, it is therfore perfectly fine to have it guarded by `g_msgproc_mutex`. ACKs for top commit: jnewbery: utACK 3fa4c54 hebasto: ACK 3fa4c54, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 3ef84bfe4abfa8d991a7e65d9184221294d80e0df0bbb47f0270ab6ca1593266c98abf83c610f9f86b4d16c7a4b62bcf83f8856c68d3c2e10894bff6ed3e88cd
…cs_main Summary: This is a partial backport of [[bitcoin/bitcoin#26140 | core#26140]] bitcoin/bitcoin@1d87137 Depends on D15287 Test Plan: With Debug: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D15288
…c_mutex and move to Peer Summary: > nUnconnectingHeaders, m_headers_sync_timeout, fPreferHeaders and m_recently_announced_headers are currently all CNodeState members even though they are only ever accessed from the message processing thread (therefore sufficiently guarded exclusively by g_msgproc_mutex). CNodeState exists purely to hold validation-specific state guarded by cs_main that is accessed by multiple threads. This is a partial backport of [[bitcoin/bitcoin#26140 | core#26140]] bitcoin/bitcoin@5f80d8d bitcoin/bitcoin@d8c0d1c Depends on D15288 Test Plan: With Debug: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D15289
…roc_mutex and move to Peer Summary: > nUnconnectingHeaders, m_headers_sync_timeout, fPreferHeaders and m_recently_announced_headers are currently all CNodeState members even though they are only ever accessed from the message processing thread (therefore sufficiently guarded exclusively by g_msgproc_mutex). CNodeState exists purely to hold validation-specific state guarded by cs_main that is accessed by multiple threads. This is a partial backport of [[bitcoin/bitcoin#26140 | core#26140]] bitcoin/bitcoin@4b84e50 bitcoin/bitcoin@4b84e50 Depends on D15289 Test Plan: With Debug: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D15290
…x and move to Peer Summary: > nUnconnectingHeaders, m_headers_sync_timeout, fPreferHeaders and m_recently_announced_headers are currently all CNodeState members even though they are only ever accessed from the message processing thread (therefore sufficiently guarded exclusively by g_msgproc_mutex). CNodeState exists purely to hold validation-specific state guarded by cs_main that is accessed by multiple threads. This is a partial backport of [[bitcoin/bitcoin#26140 | core#26140]] bitcoin/bitcoin@3605011 bitcoin/bitcoin@8a2cb1f Depends on D15290 Test Plan: With Debug: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D15291
…ed by g_msgproc_mutex and move to Peer Summary: This is a partial backport of [[bitcoin/bitcoin#26140 | core#26140]] bitcoin/bitcoin@938a8e2 bitcoin/bitcoin@279c53d Depends on D15291 Test Plan: With Debug `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D15292
Summary: ``` -BEGIN VERIFY SCRIPT- ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); } ren nUnconnectingHeaders m_num_unconnecting_headers_msgs ren fPreferHeaders m_prefers_headers ren MAX_UNCONNECTING_HEADERS MAX_NUM_UNCONNECTING_HEADERS_MSGS -END VERIFY SCRIPT ``` This concludes backport of [[bitcoin/bitcoin#26140 | core#26140]] https://github.com/bitcoin/bitcoin/pull/26140/commits/3a060ae7b67cc28fc60cf28cbc518fa1df24f545- Depends on D15292 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D15293
nUnconnectingHeaders
,m_headers_sync_timeout
,fPreferHeaders
andm_recently_announced_headers
are currently allCNodeState
members even though they are only ever accessed from the message processing thread (therefore sufficiently guarded exclusively byg_msgproc_mutex
).CNodeState
exists purely to hold validation-specific state guarded bycs_main
that is accessed by multiple threads.This PR adds thread-safety annotations for the above mentioned
CNodeState
members and moves them toPeer
.