Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Updating host ENR #5593

Merged
merged 13 commits into from
May 28, 2019
Merged

Updating host ENR #5593

merged 13 commits into from
May 28, 2019

Conversation

gumb0
Copy link
Member

@gumb0 gumb0 commented May 7, 2019

Implements part 3 of #5551

New host ENR is generated:

  • when network config given to Host contains new public address / listen port
  • when EndpointTracker in NodeTable detects new public UDP endpoint

libp2p/ENR.cpp Outdated

return ENR{0 /* sequence number */, keyValuePairs, signFunction};
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be better to start the sequence number at 1.

@gumb0 gumb0 force-pushed the enr-update branch 2 times, most recently from 8771c9a to b49f1fc Compare May 9, 2019 10:23
@codecov-io
Copy link

codecov-io commented May 9, 2019

Codecov Report

Merging #5593 into master will increase coverage by 0.08%.
The diff coverage is 87.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5593      +/-   ##
==========================================
+ Coverage   62.33%   62.42%   +0.08%     
==========================================
  Files         350      350              
  Lines       29428    29531     +103     
  Branches     3322     3327       +5     
==========================================
+ Hits        18344    18434      +90     
- Misses       9886     9893       +7     
- Partials     1198     1204       +6

@gumb0
Copy link
Member Author

gumb0 commented May 9, 2019

Currently ENR is updated too often - every time we receive Pong with different destination port (this is how we always updated our knowledge of UDP external port).

I'll try to investigate geth code for a better approach, like updating it only when certain number of packets with specific port is received, it seems it shouldn't be too difficult to implement something like this.

@gumb0
Copy link
Member Author

gumb0 commented May 15, 2019

I plan to rebase this after #5602 is merged

@halfalicious
Copy link
Contributor

Currently ENR is updated too often - every time we receive Pong with different destination port (this is how we always updated our knowledge of UDP external port).

I'll try to investigate geth code for a better approach, like updating it only when certain number of packets with specific port is received, it seems it shouldn't be too difficult to implement something like this.

For context what is the downside of updating a node’s ENR this frequently?

@gumb0
Copy link
Member Author

gumb0 commented May 16, 2019

@halfalicious Well discv5 nodes should keep ENRs of their peers up-to-date, so changing it all the time would make it necessary to re-request it from us all the time.

(I suspect putting different endpoint values into our Pings all the time might negatively affect simple v4 discovery, too, somehow)

Also I think signing ENR is pretty costly operation (now it happens sometimes several times a second)

@@ -825,10 +842,12 @@ void Host::startedWorking()
else
m_listenPort = m_netConfig.listenPort;

determinePublic();
m_tcpPublic = determinePublic();
Copy link
Member Author

@gumb0 gumb0 May 22, 2019

Choose a reason for hiding this comment

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

I made determinePublic return tcp::endpoint as result, instead of assigning it inside, to make more explicit that it's the only result of this function.

@gumb0 gumb0 removed the in progress label May 22, 2019
@gumb0 gumb0 requested review from halfalicious and chfast May 22, 2019 16:45
@gumb0
Copy link
Member Author

gumb0 commented May 23, 2019

I tried it with geth, and it look to be working, geth doesn't complain about our ENR.

The logs look like this:

DEBUG 05-23 17:21:54 p2p  discov Ping from ##6f611751…@127.0.0.1:30303
DEBUG 05-23 17:21:54 p2p  discov Adding node ##6f611751…@127.0.0.1:30303
DEBUG 05-23 17:21:54 p2p  discov Pong to ##6f611751…@127.0.0.1:30303
DEBUG 05-23 17:21:54 p2p  discov Active node ##6f611751…@127.0.0.1:30303
DEBUG 05-23 17:21:54 p2p  discov ENRRequest from ##6f611751…@127.0.0.1:30303
DEBUG 05-23 17:21:54 p2p  discov ENRResponse to ##6f611751…@127.0.0.1:30303
DEBUG 05-23 17:21:54 p2p  discov Active node ##6f611751…@127.0.0.1:30303
TRACE[05-23|17:21:53.797] New dial task                            task="discovery lookup"
TRACE[05-23|17:21:54.570] >> PING/v4                               id=651d77d331e7d70c addr=127.0.0.1:30305     err=nil
TRACE[05-23|17:21:54.572] << PONG/v4                               id=651d77d331e7d70c addr=127.0.0.1:30305     err=nil
TRACE[05-23|17:21:54.573] >> ENRREQUEST/v4                         id=651d77d331e7d70c addr=127.0.0.1:30305     err=nil
TRACE[05-23|17:21:54.575] << ENRRESPONSE/v4                        id=651d77d331e7d70c addr=127.0.0.1:30305     err=nil
DEBUG[05-23|17:21:54.576] Revalidated node                         b=13 id=651d77d331e7d70c checks=1

libp2p/ENR.cpp Outdated
std::array<byte, N> bytesToAddress(bytesConstRef _bytes)
{
std::array<byte, N> address;
std::copy(_bytes.begin(), _bytes.begin() + N, address.begin());
Copy link
Member

Choose a reason for hiding this comment

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

Use std::copy_n()

libp2p/ENR.cpp Outdated
// The resulting 64-byte signature is encoded as the concatenation of the r and s signature values.
return bytes(&s[0], &s[64]);
};
return ENR(m_seq + 1, _keyValuePairs, _signFunction);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return ENR(m_seq + 1, _keyValuePairs, _signFunction);
return ENR{m_seq + 1, _keyValuePairs, _signFunction};

or

Suggested change
return ENR(m_seq + 1, _keyValuePairs, _signFunction);
return {m_seq + 1, _keyValuePairs, _signFunction};

libp2p/ENR.cpp Outdated
{
_out << keyValue.first << "=";
_out << toHexPrefixed(RLP{keyValue.second}.toBytes()) << " ";
_out << "key=" << IdentitySchemeV4::publicKey(_enr).abridged() << " ip=" << _enr.ip()
Copy link
Member

Choose a reason for hiding this comment

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

This can partly output something.

Also fix operator<< to handle incorrect tcp and udp.
@gumb0 gumb0 merged commit 312fff8 into master May 28, 2019
@gumb0 gumb0 deleted the enr-update branch May 28, 2019 13:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants