Libp2p takes a TaskExecutor

This commit is contained in:
pawan
2020-05-22 20:47:54 +05:30
parent d3f73a354d
commit b84f8b91d6
3 changed files with 9 additions and 7 deletions

8
Cargo.lock generated
View File

@@ -1076,9 +1076,9 @@ dependencies = [
[[package]] [[package]]
name = "enr" name = "enr"
version = "0.1.0-alpha.7" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "266c26f4eec6f07787274ddb813bb91355eeea7c094113d2d81ddd6330af1334" checksum = "ca3cd1bccf1bd78eee44d89c0f81b60008b40153db2b99c0fc01abf353781e13"
dependencies = [ dependencies = [
"base64 0.12.1", "base64 0.12.1",
"bs58", "bs58",
@@ -1189,10 +1189,12 @@ dependencies = [
"base64 0.12.1", "base64 0.12.1",
"dirs", "dirs",
"discv5", "discv5",
"environment",
"error-chain", "error-chain",
"eth2_ssz", "eth2_ssz",
"eth2_ssz_derive", "eth2_ssz_derive",
"eth2_ssz_types", "eth2_ssz_types",
"exit-future",
"fnv", "fnv",
"futures 0.3.5", "futures 0.3.5",
"hashset_delay", "hashset_delay",
@@ -1323,7 +1325,7 @@ dependencies = [
name = "eth2_testnet_config" name = "eth2_testnet_config"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"eth2-libp2p", "enr",
"eth2_ssz", "eth2_ssz",
"reqwest", "reqwest",
"serde", "serde",

View File

@@ -84,7 +84,7 @@ pub struct Service<TSpec: EthSpec> {
impl<TSpec: EthSpec> Service<TSpec> { impl<TSpec: EthSpec> Service<TSpec> {
pub fn new( pub fn new(
handle: tokio::runtime::Handle, handle: environment::TaskExecutor,
config: &NetworkConfig, config: &NetworkConfig,
enr_fork_id: EnrForkId, enr_fork_id: EnrForkId,
log: &slog::Logger, log: &slog::Logger,
@@ -123,10 +123,10 @@ impl<TSpec: EthSpec> Service<TSpec> {
let behaviour = Behaviour::new(&local_keypair, config, network_globals.clone(), &log)?; let behaviour = Behaviour::new(&local_keypair, config, network_globals.clone(), &log)?;
// use the executor for libp2p // use the executor for libp2p
struct Executor(tokio::runtime::Handle); struct Executor(environment::TaskExecutor);
impl libp2p::core::Executor for Executor { impl libp2p::core::Executor for Executor {
fn exec(&self, f: Pin<Box<dyn Future<Output = ()> + Send>>) { fn exec(&self, f: Pin<Box<dyn Future<Output = ()> + Send>>) {
self.0.spawn(f); self.0.spawn(f, "libp2p");
} }
} }
SwarmBuilder::new(transport, behaviour, local_peer_id.clone()) SwarmBuilder::new(transport, behaviour, local_peer_id.clone())

View File

@@ -73,7 +73,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {
// launch libp2p service // launch libp2p service
let (network_globals, mut libp2p) = let (network_globals, mut libp2p) =
LibP2PService::new(executor.runtime_handle(), config, enr_fork_id, &network_log)?; LibP2PService::new(executor.clone(), config, enr_fork_id, &network_log)?;
for enr in load_dht::<T::Store, T::EthSpec>(store.clone()) { for enr in load_dht::<T::Store, T::EthSpec>(store.clone()) {
libp2p.swarm.add_enr(enr); libp2p.swarm.add_enr(enr);