-
Notifications
You must be signed in to change notification settings - Fork 784
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
remove nat module and use libp2p upnp #4840
Conversation
can't Making |
ahh yeah good point. When we were discussing this I didn't consider discovery. My opinion is that the code in lh for UPnP isn't great. It was written a while ago and I consider it to always fail (i.e dont rely on it in any way). If libp2p is going to maintain its own version as a dep I think it kind of makes sense to export it there. Perhaps we want to do a similar thing in discovery. I agree that its ugly that we duplicate the dependencies and then attempt UPnP twice this way, but the benefit is that its then logically grouped into each transport that needs it and I guess discovery users independently can benefit from its own internal UPnP functionality. The overhead of running it twice on boot prob isn't that bad. What do you think @divagant-martian? |
Hi Diva, I don't think I also don't think it doesn't make sense to invent a new multiaddress for this.
|
thanks @jxs ot sure what you mean about creating a new multi address? in any case, this is what I discussed and proposed to @AgeManning a couple days ago and what we decided would be best, ty! |
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.
This looks good.
However there is a CLI flag --disable-upnp
. I think we still need to respect that and therefore not use libp2p upnp or discovery upnp when that flag is set.
beacon_node/network/src/nat.rs
Outdated
) | ||
.await | ||
.context("Could not UPnP map port: {port} on the gateway")?; | ||
info!(log, "Discovery UPnP port mapped"; "port" => %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 have a few info logs at the moment.
We have one from creating in libp2p, one from creating discovery and then the results from both.
I think its probably safe to assume if libp2p works, then discovery probably will to. Maybe we make the discovery logs debug
?
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.
yup, makes sense Age. Updated!
reduce logs to debug!
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.
Great to see libp2p-upnp
in action soon.
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.
This looks good to me, but I left some minor comments.
beacon_node/network/src/service.rs
Outdated
"UPnP", | ||
); | ||
} | ||
if let (true, Some(v4)) = (config.upnp_enabled, config.listen_addrs().v4()) { |
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 need to respect config.disable_discovery
too.
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 makes sense, updated!
beacon_node/network/src/nat.rs
Outdated
"Lighthouse Discovery port", | ||
) | ||
.await | ||
.context("Could not UPnP map port: {port} on the gateway")?; |
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.
It seems that the context()
doesn't parse the {port}
placeholder correctly.
Here is a log when I run beacon node with branch:
Nov 04 23:05:30.569 INFO Could not UPnP map Discovery port, error: Could not UPnP map port: {port} on the gateway, module: network::service:240
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.
thanks for trying this and providing feedback, updated!
@@ -1516,6 +1517,47 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> { | |||
} | |||
} | |||
|
|||
fn parse_upnp_event(&mut self, event: libp2p_upnp::Event) { |
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.
Since the existing methods for handling events are named with the prefix inject_
, perhaps we should align with this naming convention? For example, we could name it inject_upnp_event
.
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 makes sense. Updated, thanks!
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.
Thanks for the review Akihito!
@@ -1516,6 +1517,47 @@ impl<AppReqId: ReqId, TSpec: EthSpec> Network<AppReqId, TSpec> { | |||
} | |||
} | |||
|
|||
fn parse_upnp_event(&mut self, event: libp2p_upnp::Event) { |
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 makes sense. Updated, thanks!
beacon_node/network/src/nat.rs
Outdated
"Lighthouse Discovery port", | ||
) | ||
.await | ||
.context("Could not UPnP map port: {port} on the gateway")?; |
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.
thanks for trying this and providing feedback, updated!
beacon_node/network/src/service.rs
Outdated
"UPnP", | ||
); | ||
} | ||
if let (true, Some(v4)) = (config.upnp_enabled, config.listen_addrs().v4()) { |
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 makes sense, updated!
beacon_node/network/src/service.rs
Outdated
) { | ||
let nw = network_log.clone(); | ||
let v4 = v4.clone(); | ||
tokio::spawn(async move { |
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.
Should we use executor.spawn
to spawn a future here, since we were using executor.spawn_blocking
before?
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, thanks for the catch Akihito! Updated
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.
Thanks for the update! Looks good to me.
@Mergifyio queue |
🟠 Waiting for conditions to match
|
@Mergifyio queue |
✅ The pull request has been merged automaticallyThe pull request has been merged automatically at abd9965 |
* remove nat module and use libp2p upnp * update Cargo.lock * remove no longer used dependencies * restore nat module refactored * log successful mapping * only activate upnp if config enabled reduce logs to debug! * Merge branch 'unstable' of https://github.com/sigp/lighthouse into libp2p-nat * Merge branch 'unstable' of https://github.com/sigp/lighthouse into libp2p-nat * Merge branch 'unstable' of https://github.com/sigp/lighthouse into libp2p-nat * address review * Merge branch 'unstable' of https://github.com/sigp/lighthouse into libp2p-nat * Merge branch 'unstable' of https://github.com/sigp/lighthouse into libp2p-nat * Merge branch 'unstable' of https://github.com/sigp/lighthouse into libp2p-nat * address review
Issue Addressed
uses the new libp2p upnp module to map internal ports to the external network instead of the local
nat
module.Additional Info
This is a first move on fulfilling #4816 as we can just use
libp2p
to understand if ports are publicly accessible and it will act accordingly with theFromSwarm::ExternalAdrConfirmed
.There's a downside though, we lose the ability to map the DiscV5 udp port, for that I suggest we implement it as a feature in Discovery itself wdyt? I can submit a PR for that