-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add a fn listen_addresses()
to NetworkService
#6409
Conversation
Forked at: d735e4d No parent branch.
For testing, note that the network can be put into a "memory-only" mode: substrate/client/network/src/config.rs Line 535 in d5336db
The idea is to generate Example usage: substrate/client/network/src/protocol/generic_proto/tests.rs Lines 35 to 112 in adb5acb
Beyond the fact that it solves the problem that you're having, it also solves the problem that using TCP sockets might also lead to running out of ports if you have several heavy tests running at the same time. |
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 PR looks good, but as explained I suggest your use the "memory-mode".
@@ -747,6 +747,15 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H> { | |||
.unbounded_send(ServiceToWorkerMsg::UpdateChain); | |||
} | |||
|
|||
/// Returns a stream containing the listen addresses |
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.
/// Returns a stream containing the listen addresses | |
/// Returns the list of addresses we are currently listening on. | |
/// | |
/// Please be aware that this list might change over time. |
This is AWESOME!! Thanks! ... 🤔 this is strange. Now my function listen_addresses return an empty Vec. Shouldn't it have the memory address? (I understand I might not need this function anymore but I'm curious) |
Oh, this might be a bug in rust-libp2p. The list of listened addresses is reported by the low-level transport code (such as the TCP code), and I think we don't do that for the memory transport. |
Nevermind, we do it: https://github.com/libp2p/rust-libp2p/blob/168b00ed3e8999904e075469eb867d692e04487f/core/src/transport/memory.rs#L179-L182 Another possibility is that because opening listeners is actually asynchronous in libp2p, you're processing the nodes in such a way that you get the list of listened addresses before the first listener has opened. |
I did some experiment but I have a new issue: it seems my nodes are not connected for some reason (it says "0 peers")... I haven't investigated yet
Also: after tweaking with all of this I have the feeling that |
Thanks for the help @tomaka I had to set the TransportConfig of the I'm closing this PR for now as it would be unnecessary code to maintain and I will post my solution soon when it is merged. |
Use case
I'm writing a test crate for polkadot and a simple test that ensures blocks are being built. For that I need to start a few nodes on random ports. To do that I pass the port 0 to get a random port but I need to know what port has been assigned for each node.
Proposed solution
The only way I found would be to call
listen_addresses
on the NetworkWorker but since I only have a NetworkService, I added a functionlisten_addresses
to NetworkService which passes the message to the NetworkWorker.Related PR and alternative solution chosen: paritytech/polkadot#1258