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

Backport Bitcoin PR#8113: Rework addnode behaviour #1525

Merged
merged 3 commits into from
Jul 14, 2017

Conversation

OlegGirko
Copy link

This is backport of Bitcoin PR bitcoin#8113.

This change is needed because it changes code that will be changed by further PRs.

The original PR description follows.

This is an alternative to bitcoin#8097 that:

  • Maintains consistency between ThreadOpenAddedNodeConnections and getaddednodeinfo, without any DNS resolving from RPC.
  • Deals with the use case of added names whose IP mapping changes over time (switching over to the new IP only when the connection to the old one closes, though).
  • Gets rid of the fDns argument to getaddednodeinfo (turning it into a dummy)
  • Simplifies the code significantly by introducing a shared GetAddedNodeInfo in net.cpp.
  • The existing addnode logic that tries all resolved addresses for a name is pushed down into ConnectSocketByName (picking at random).
  • The existing addnode logic to prevent multiple connections to the same IP is pushed down into ConnectNode (by storing colliding names into the CNode's addrName field).

Untested.

src/net.cpp Outdated
CNode* pnode = FindNode((CService)addrConnect);
if (pnode)
{
pnode->AddRef();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pnode->AddRef(); should be replaced with the same logic as in 396-401 i.e.

            // we have existing connection to this node but it was not a connection to masternode,
            // change flag and add reference so that we can correctly clear it later
            if(fConnectToMasternode && !pnode->fMasternode) {
                pnode->AddRef();
                pnode->fMasternode = true;
            }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking about backporting bitcoin#9626 that in both cases replaces

pnode->AddRef();
return pnode;

with

LogPrintf("Failed to open new connection, already connected\n");
return NULL;

So, looks to me that after this backport, upgrading node's status to masternode can be done with one line, like

pnode->fMasternode = pnode->fMasternode || fConnectToMasternode;

BTW, what was the reason to do pnode->AddRef(); in this place only when upgrading node's status to masternode, not always (like in bitcoin).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddRef for ("normal") existing connection in bitcoin was a bug #924 bitcoin#8372. Using AddRef in situations where we select node with existing connection as a masternode to connect to, allowed us to track some related bugs iirc. These AddRefs and corresponding Release in ThreadSocketHandler for fMasternode flag are probably not needed anymore, so I guess they can be safely removed (in both places simultaniously ofc).

Also, I think triggering fMasternode flag can be simplified even further:

pnode->fMasternode |= fConnectToMasternode;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll use AddRef() for now for uniformity, and then will remove it later when backporting bitcoin#9626.

src/net.cpp Outdated
{
pnode->AddRef();
{
LOCK(cs_vNodes);
Copy link

@UdjinM6 UdjinM6 Jul 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cs_vNodes should be locked before FindNode on line 428

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue was fixed in bitcoin#9626 as well.

@OlegGirko
Copy link
Author

OK, I've pushed branch with updated changes. Upgrading node status to masternode added, but I'd rather leave locking issues to be fixed when I backport bitcoin#9626.

@OlegGirko
Copy link
Author

One check failed because it just got stuck. Can somebody please restart that failed test?

@UdjinM6
Copy link

UdjinM6 commented Jul 14, 2017

Travis is probably having some issues... "An error occurred. The job could not be restarted."... Even though https://www.traviscistatus.com/ says "All Systems Operational" 🤔 I'll try restarting it a bit later.

@UdjinM6
Copy link

UdjinM6 commented Jul 14, 2017

Hmmm... I was able to restart some random build in my own repo, but can't restart jobs in dashpay anymore... @schinzelh any idea?

@OlegGirko meanwhile you can probably do commit --amend and push -f to trigger the build again

@schinzelh
Copy link

@UdjinM6 same here, can't restart the builds, must be a Travis issue.

@schinzelh
Copy link

@UdjinM6 This may be the root cause

image

Seems like they have updated the image recently and now "old" builds can't be restarted anymore...

@UdjinM6
Copy link

UdjinM6 commented Jul 14, 2017

Pls rebase (no conflicts, just to make sure that travis workaround works as expected + to trigger new build and make sure that all tests pass)

sipa added 3 commits July 14, 2017 15:40
* Use CNode::addeName to track whether a connection to a name is already open
  * A new connection to a previously-connected by-name addednode is only opened when
    the previous one closes (even if the name starts resolving to something else)
  * At most one connection is opened per addednode (even if the name resolves to multiple)
* Unify the code between ThreadOpenAddedNodeConnections and getaddednodeinfo
  * Information about open connections is always returned, and the dns argument becomes a dummy
  * An IP address and inbound/outbound is only reported for the (at most 1) open connection
@OlegGirko
Copy link
Author

I've pushed rebased branch, let's see test results now.

@OlegGirko
Copy link
Author

All Travis tests were successful.

@tgflynn
Copy link

tgflynn commented Jul 14, 2017

utACK

@UdjinM6
Copy link

UdjinM6 commented Jul 14, 2017

utACK (assuming future fix of LOCK issue)

@UdjinM6 UdjinM6 added this to the 12.2 milestone Jul 14, 2017
@UdjinM6 UdjinM6 merged commit 9ce2b96 into dashpay:v0.12.2.x Jul 14, 2017
@OlegGirko OlegGirko deleted the bc-pr-8113 branch July 14, 2017 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants