vasild
commented at 12:04 pm on May 1, 2025:
contributor
The only case of a recursive lock was a nested ForNode() call to trim
the size of lNodesAnnouncingHeaderAndIDs to <= 3. This need not be
nested, so take it out.
Before:
0// we know we will push one new element at the back
1if (size >= 3) pop from front
2push at the back
After:
0// maybe push at the back
1if (size > 3) pop from the front
lNodesAnnouncingHeaderAndIDs is protected by cs_main which is locked
during the entire operation.
This PR includes #32326 (first 3 commits in this PR). If that PR gets merged first, then the size of this will be reduced. If this gets merged first then that can be closed (will be fully merged via this one).
net: merge AlreadyConnectedToAddress() and FindNode(CNetAddr)
`CConnman::AlreadyConnectedToAddress()` is the only caller of
`CConnman::FindNode(CNetAddr)`, so merge the two in one function and
rename it to `IsConnectedToAddr()` to show that it compares just the
address and not the port.
The unit test that checked whether `AlreadyConnectedToAddress()` ignores
the port is now unnecessary because now the function takes a `CNetAddr`
argument. It has no access to the port.
f8201774b5
net: avoid recursive m_nodes_mutex lock in DisconnectNode()
Have `CConnman::DisconnectNode()` iterate `m_nodes` itself instead of
using `FindNode()`. This avoids recursive mutex lock and drops the only
caller of `FindNode()` which used the return value for something else
than a boolean found/notfound.
78e0345867
net: change FindNode() to not return a node and rename it
All callers of `CConnman::FindNode()` use its return value `CNode*` only
as a boolean null/notnull. So change that method to return `bool`.
This removes the dangerous pattern of handling a `CNode` object (the
return value of `FindNode()`) without holding `CConnman::m_nodes_mutex`
and without having that object's reference count incremented for the
duration of the usage.
Also rename the method to better describe what it does.
4f635d100d
net: make m_nodes_mutex non-recursive
The only case of a recursive lock was a nested `ForNode()` call to trim
the size of `lNodesAnnouncingHeaderAndIDs` to `<= 3`. This need not be
nested, so take it out.
Before:
```
// we know we will push one new element at the back
if (size >= 3) pop from front
push at the back
```
After:
```
// maybe push at the back
if (size > 3) pop from the front
```
`lNodesAnnouncingHeaderAndIDs` is protected by `cs_main` which is locked
during the entire operation.
Partially resolves: https://github.com/bitcoin/bitcoin/issues/19303
98bba932bf
DrahtBot
commented at 12:04 pm on May 1, 2025:
contributor
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
#29641 (scripted-diff: Use LogInfo over LogPrintf [WIP, NOMERGE, DRAFT] by maflcko)
#28463 (p2p: Increase inbound capacity for block-relay only connections by mzumsande)
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.
DrahtBot added the label
P2P
on May 1, 2025
Bonobirho99
commented at 1:21 pm on May 1, 2025:
none
.
hebasto
commented at 2:18 pm on May 1, 2025:
member
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2025-05-05 12:12 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me