I am in the process of making the block handler modular (https://github.com/paritytech/substrate/pull/14014 pending now). We have this scenario:
build_network()
expects all the components constructed/passed in before the network is created- If say one of these components needs a handle to the network (for example, to perform request/response), this becomes a problem: as the network is not yet created when the component is created.
We are resorting to some not so nice ways to work around this (e.g) the custom block handler has an Option<NetworkHandle<Block>>
. This starts as None, eventually gets filled in with a valid handle, so on.
The sync layer internally works around this using NetworkServiceHandle, which is a wrapper around a channel send end point. But this doesn't work for external users. One possible solution would be to take Option<NetworkServiceHandle>
(or something equivalent) during the build_network(), so the caller keeps a (cloned) copy of the handle for later use