-
Notifications
You must be signed in to change notification settings - Fork 793
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
[Merged by Bors] - Allow libp2p to determine listening addresses #4700
Conversation
804a9a0
to
0c23c86
Compare
Currently failing on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me but I'm lacking context to properly assess the discovery changes. Will wait for Age or João
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in general look fine. Some comments we probably should address tho.
@@ -1036,12 +1038,107 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> { | |||
FromSwarm::DialFailure(DialFailure { peer_id, error, .. }) => { | |||
self.on_dial_failure(peer_id, error) | |||
} | |||
FromSwarm::NewListenAddr(ev) => { | |||
/* TODO(jmcph4): plumb user override status into config somehow */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we handle this before merging?
} | ||
}; | ||
|
||
let mut should_update_ip: bool = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should never update the ENR IP here.
A few reasons:
- The local address we are binding to (i.e the address that libp2p will return) will almost never be a globally routable address. Most computers will be behind a NAT. Unless they are using ipv6 etc. But in any case its better to let discovery handle the IP field of the ENR.
- Discovery sets this field based on how others connect to us. We should not interfere with this I dont think.
We should only really set the TCP or QUIC fields of the ENR based on libp2p's response.
Protocol::Tcp(port) => port, | ||
Protocol::Udp(port) => port, | ||
_ => { | ||
crit!(self.log, "Attempt to update discovery with unsupported transport (this should never occur)"; "transport" => ?transport); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think on every start we now also listen on the QUICv1 protocol.
I would imagine that means running this code would immediately emit this crit.
I usually run an instance of lighthouse locally (with backfill disabled and weak subjectivity sync) to see if it starts up and connects and doesn't emit crits.
It's usually a good self-test to catch bugs like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think on every start we now also listen on the QUICv1 protocol.
As of #4402 this is correct.
I would imagine that means running this code would immediately emit this crit.
When we listen on QUICv1, the multiaddress looks like this: /ip4/127.0.0.1/udp/9001/quic-v1/
. In this handler (for FromSwarm::NewListenAddr
), we parse the multiaddress from left-to-right and only ever two Protocol
s deep -- so we'll never encounter this crit!
log emission during normal operation of the BN. This is still a bug obviously as only ever parsing two Protocol
s deep will completely miss QUICv1 altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right. I saw this line:
https://github.com/jmcph4/lighthouse/blob/10263d3e003218c529f420d7e34ad658ff2f1ca1/beacon_node/lighthouse_network/src/discovery/mod.rs#L1131
match addr.iter().nth(1) {
Some(Protocol::Tcp(port)) => update_enr(ip, Protocol::Tcp(port)),
Some(Protocol::Udp(port)) => update_enr(ip, Protocol::Udp(port)),
Some(Protocol::Quic) => update_enr(ip, Protocol::Quic),
_ => {
debug!(self.log, "Encountered unacceptable multiaddr for listening (invalid transport)"; "addr" => ?addr);
}
};
which explicitly passes the Quic protocol to that function. I guess this case just never occurs because you only look at the nth(1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's somewhat regrettable that the current fix (i.e., 599c706) duplicates the port number itself (as the Protocol::QuicV1
variant doesn't store the port unlike its TCP and UDP counterparts) but is much more explicit about the mapping from multiaddress to ENR update information.
match ip { | ||
IpAddr::V4(_) => { | ||
if transport_is_tcp { | ||
insert_into_enr("tcp4", &port); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also probably should check that the tcp port isn't already set from a previous run. I.e we load it from disk. I can't recall maybe the insert() function already checks. But we probably dont want to be increasing the sequence number if we don't have to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also probably should check that the tcp port isn't already set from a previous run. I.e we load it from disk.
Are you referring to previous instances of us entering this swarm event handler throughout the duration of the BN runtime? Namely, if we receive multiple local addresses to listen on from the swarm (which virtually always happens during normal operation), when we perform the updates serially, we keep thrashing the ENR's sequence number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of the case like, we run Lighthouse on port 9000 as default. It creates an ENR from fresh because its our first ever time running. We set the tcp port on the ENR.
We then shutdown lighthouse and save the ENR to disk.
Then we run lighthouse again. This loads the saved ENR from disk which has the TCP field already set. If we are using the exact same CLI params (i.e all we have done is restart lighthouse), the tcp field in the ENR is set to the one that libp2p would return to us so we probably don't need to reset it.
match addr.iter().nth(1) { | ||
Some(Protocol::Tcp(port)) => update_enr(ip, Protocol::Tcp(port)), | ||
Some(Protocol::Udp(port)) => update_enr(ip, Protocol::Udp(port)), | ||
Some(Protocol::Quic) => update_enr(ip, Protocol::Quic), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might be using QuicV1. Should double check this.
In either case a simple run should show this debug error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might be using QuicV1.
We are; good catch.
In either case a simple run should show this debug error.
This will almost never occur (see above for context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the logic looks good to me. Just a few nitpicks.
Co-authored-by: Age Manning <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets gooo!
bors r+ |
Build failed (retrying...): |
bors r- |
Canceled. |
bors r+ |
bors r- |
Canceled. |
bors r+ |
Build failed (retrying...): |
Build failed: |
bors r+ |
Pull request successfully merged into unstable. Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page.
|
Issue Addressed
#4675
Proposed Changes
SwarmEvent::NewListenAddr
)Additional Info
See Also