Partially backport Bitcoin PR#9626: Clean up a few CConnman cs_vNodes/CNode things #1591
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is partial backport of Bitcoin PR bitcoin#9626.
The main purpose of this backport is to fix locking issues introduced by earlier backported PR.
This backport includes only 2 of 3 original commits. Last commit is omitted because it moves important code from
CConnman::ConnectNode()
method toCConnman::OpenNetworkConnection()
. This code adds newly createdCNode
toCConnman::vNodes
vector and emitsInitializeNode
signal. Moving this code is OK for Bitcoin becauseCConnman::ConnectNode()
is private there and the only caller of this method isCConnman::OpenNetworkConnection()
. Unfortunately, this is not the case in Dash:CConnman::ConnectNode()
is called in some places of Dash-specific code, so moving important functionality out if this method will break that code.Hence, the last commit is not included in this backport. It can be backported separately later after we decide how to refactor Dash-specific code that uses
CConnman::ConnectNode()
.The original PR description follows.
This should fix the long-standing (read: satoshi-era) bug where we may not delete a node if we try to connect to it (via RPC) after its already connected as we'll have duplicate refs.
This also removes some unused functions (some of which miss a lock, some of which should otherwise be cleaned up for bitcoin#9609).
This also ensures that if we return a CNode* from FindNode, we are still holding cs_vNodes if we use it for anything aside from existance-checking, fixing a stupid-unlikely race where it might be deleted out from under us.