Skip to content
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

net: Add Clang thread safety annotations for guarded variables in the networking code #13123

Merged
merged 2 commits into from
Nov 28, 2018

Conversation

practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Apr 30, 2018

Add Clang thread safety annotations for variables guarded by:

  • cs_addrLocal
  • cs_addrName
  • cs_feeFilter
  • cs_filter
  • cs_hSocket
  • cs_inventory
  • cs_mapLocalHost
  • cs_most_recent_block
  • cs_proxyInfos
  • cs_sendProcessing
  • cs_setBanned
  • cs_SubVer
  • cs_vOneShots
  • cs_vProcessMsg
  • cs_vRecv
  • cs_vSend

Changed files:

  • src/net.{cpp,h}
  • src/netbase.cpp

@practicalswift practicalswift changed the title Add Clang thread safety annotations for guarded variables in the networking code net: Add Clang thread safety annotations for guarded variables in the networking code Apr 30, 2018
@practicalswift
Copy link
Contributor Author

Rebased!

@maflcko
Copy link
Member

maflcko commented Aug 12, 2018

Imo could squash everything, since most of the commits only touch 2 lines.

@practicalswift
Copy link
Contributor Author

@MarcoFalke Rebased and squashed! Please re-review :-)

@practicalswift
Copy link
Contributor Author

Rebased and added missing lock:

diff --git a/src/net.cpp b/src/net.cpp
index 529a2f82f..7fcf6a3ef 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -715,7 +715,10 @@ void CNode::copyStats(CNodeStats &stats)
         X(nRecvBytes);
     }
     X(fWhitelisted);
-    X(minFeeFilter);
+    {
+        LOCK(cs_feeFilter);
+        X(minFeeFilter);
+    }

     // It is common for nodes with good ping times to suddenly become lagged,
     // due to a new block arriving or other large transfer.

src/net.h Show resolved Hide resolved
src/net.h Show resolved Hide resolved
src/net.h Outdated Show resolved Hide resolved
@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 20, 2018

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #14605 (Return of the Banman by dongcarl)
  • #14046 (net: Refactor message parsing (CNetMessage), adds flexibility by jonasschnelli)

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.

@practicalswift
Copy link
Contributor Author

@MarcoFalke @Empact Updated. Please re-review :-)

@practicalswift practicalswift force-pushed the net-guarded-by branch 5 times, most recently from 09d46b5 to d4dd3f9 Compare October 8, 2018 13:55
@practicalswift
Copy link
Contributor Author

@jnewbery I agree that sure looks like an error! Good catch!

@jnewbery
Copy link
Contributor

Thanks for the quick reply. I have a PR moving some of those fields around, so I'll get rid of the lock annotations there.

@practicalswift
Copy link
Contributor Author

@jnewbery Thanks a lot for fixing (and finding)! Much appreciated!

@jnewbery
Copy link
Contributor

@practicalswift sorry I meant to say that I have a branch that moves the fields around that I haven't PR'ed yet. I'll ping you when the PR is open.

naumenkogs added a commit to naumenkogs/bitcoin that referenced this pull request Oct 6, 2020
naumenkogs added a commit to naumenkogs/bitcoin that referenced this pull request Oct 6, 2020
naumenkogs added a commit to naumenkogs/bitcoin that referenced this pull request Oct 7, 2020
naumenkogs added a commit to naumenkogs/bitcoin that referenced this pull request Oct 13, 2020
This locking was mistakenly introduced in PR bitcoin#13123.
Related conversation:
bitcoin#13123 (comment)

Making these fields atomic would ensure safety
if multiple RPC accesses them.
jnewbery pushed a commit to jnewbery/bitcoin that referenced this pull request Oct 13, 2020
…_local_addr_send

This locking was mistakenly introduced in PR bitcoin#13123.
Related conversation:
bitcoin#13123 (comment)

Making these fields atomic would ensure safety
if multiple RPC accesses them.
naumenkogs added a commit to naumenkogs/bitcoin that referenced this pull request Dec 9, 2020
…_local_addr_send

This locking was mistakenly introduced in PR bitcoin#13123.
Related conversation:
bitcoin#13123 (comment)

Making these fields atomic would ensure safety
if multiple RPC accesses them.
naumenkogs added a commit to naumenkogs/bitcoin that referenced this pull request Dec 9, 2020
…_local_addr_send

This locking was mistakenly introduced in PR bitcoin#13123.
Related conversation:
bitcoin#13123 (comment)

Making these fields atomic would ensure safety
if multiple RPC accesses them.
naumenkogs added a commit to naumenkogs/bitcoin that referenced this pull request Dec 10, 2020
…_local_addr_send

This locking was mistakenly introduced in PR bitcoin#13123.
Related conversation:
bitcoin#13123 (comment)

Making these fields atomic would ensure safety
if multiple RPC accesses them.
naumenkogs added a commit to naumenkogs/bitcoin that referenced this pull request Dec 18, 2020
…_local_addr_send

This locking was mistakenly introduced in PR bitcoin#13123.
Related conversation:
bitcoin#13123 (comment)

Making these fields atomic would ensure safety
if multiple RPC accesses them.
jnewbery added a commit to jnewbery/bitcoin that referenced this pull request Feb 28, 2021
m_next_addr_send and m_next_local_addr_send do not need to be guarded by
cs_sendProcessing. These fields are only read/writen by the message
handling thread and the annotation was added unnecessarily in commit
b312cd7. See discussion at
bitcoin#13123 (comment).

Therefore remove this unnecessary lock annotation.
@jnewbery
Copy link
Contributor

@practicalswift sorry I meant to say that I have a branch that moves the fields around that I haven't PR'ed yet. I'll ping you when the PR is open.

PR is open here: #21236. It's a pure refactor and should be easy to review.

jnewbery added a commit to jnewbery/bitcoin that referenced this pull request Mar 1, 2021
m_next_addr_send and m_next_local_addr_send are currently guarded by
cs_sendProcessing. These fields are only read/writen by the message
handling thread and the annotation was added unnecessarily in commit
b312cd7. See discussion at
bitcoin#13123 (comment).

We add a new m_addr_mutex to guard these fields. Once all the addr relay
fields have been moved to the Peer object in net_processing, they will
be protected by the same mutex.
@practicalswift practicalswift deleted the net-guarded-by branch April 10, 2021 19:36
LarryRuane pushed a commit to LarryRuane/zcash that referenced this pull request Apr 29, 2021
zcash: note: more work will be needed to the overall code base in order
zcash: for annotations to compile successfully.
zcash: cherry picked from commit b312cd7
zcash: bitcoin/bitcoin#13123
LarryRuane pushed a commit to LarryRuane/zcash that referenced this pull request Apr 29, 2021
LarryRuane pushed a commit to LarryRuane/zcash that referenced this pull request Jun 1, 2021
zcash: note: more work will be needed to the overall code base in order
zcash: for annotations to compile successfully.
zcash: cherry picked from commit b312cd7
zcash: bitcoin/bitcoin#13123
LarryRuane pushed a commit to LarryRuane/zcash that referenced this pull request Jun 1, 2021
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Jun 25, 2021
…rded variables in the networking code

4894133 Add missing lock in CNode::copyStats(...) (practicalswift)
b312cd7 Add missing locking annotations (practicalswift)

Pull request description:

  Add Clang thread safety annotations for variables guarded by:
  * `cs_addrLocal`
  * `cs_addrName`
  * `cs_feeFilter`
  * `cs_filter`
  * `cs_hSocket`
  * `cs_inventory`
  * `cs_mapLocalHost`
  * `cs_most_recent_block`
  * `cs_proxyInfos`
  * `cs_sendProcessing`
  * `cs_setBanned`
  * `cs_SubVer`
  * `cs_vOneShots`
  * `cs_vProcessMsg`
  * `cs_vRecv`
  * `cs_vSend`

  Changed files:
  * `src/net.{cpp,h}`
  * `src/netbase.cpp`

Tree-SHA512: 319a1574a07d766e81fab19b9cfdcf8b5f0b175034ebef220cd406f1672b4ef2c57f5c456c623456ca7a1f96308de69c73535792e9e4c34b848b55fd4f35fc95
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Feb 8, 2022
…rded variables in the networking code

4894133 Add missing lock in CNode::copyStats(...) (practicalswift)
b312cd7 Add missing locking annotations (practicalswift)

Pull request description:

  Add Clang thread safety annotations for variables guarded by:
  * `cs_addrLocal`
  * `cs_addrName`
  * `cs_feeFilter`
  * `cs_filter`
  * `cs_hSocket`
  * `cs_inventory`
  * `cs_mapLocalHost`
  * `cs_most_recent_block`
  * `cs_proxyInfos`
  * `cs_sendProcessing`
  * `cs_setBanned`
  * `cs_SubVer`
  * `cs_vOneShots`
  * `cs_vProcessMsg`
  * `cs_vRecv`
  * `cs_vSend`

  Changed files:
  * `src/net.{cpp,h}`
  * `src/netbase.cpp`

Tree-SHA512: 319a1574a07d766e81fab19b9cfdcf8b5f0b175034ebef220cd406f1672b4ef2c57f5c456c623456ca7a1f96308de69c73535792e9e4c34b848b55fd4f35fc95
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
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.

6 participants