mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 20:02:43 +00:00
Add multiaddr support in bootnodes (#1481)
## Issue Addressed #1384 Only catch, as currently implemented, when dialing the multiaddr nodes, there is no way to ask the peer manager if they are already connected or dialing
This commit is contained in:
@@ -15,7 +15,7 @@ use futures::prelude::*;
|
||||
use futures::stream::FuturesUnordered;
|
||||
use libp2p::core::PeerId;
|
||||
use lru::LruCache;
|
||||
use slog::{crit, debug, info, warn};
|
||||
use slog::{crit, debug, error, info, warn};
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_types::BitVector;
|
||||
use std::{
|
||||
@@ -163,7 +163,7 @@ pub struct Discovery<TSpec: EthSpec> {
|
||||
|
||||
impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
/// NOTE: Creating discovery requires running within a tokio execution environment.
|
||||
pub fn new(
|
||||
pub async fn new(
|
||||
local_key: &Keypair,
|
||||
config: &NetworkConfig,
|
||||
network_globals: Arc<NetworkGlobals<TSpec>>,
|
||||
@@ -189,21 +189,23 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
.map_err(|e| format!("Discv5 service failed. Error: {:?}", e))?;
|
||||
|
||||
// Add bootnodes to routing table
|
||||
for bootnode_enr in config.boot_nodes.clone() {
|
||||
for bootnode_enr in config.boot_nodes_enr.clone() {
|
||||
debug!(
|
||||
log,
|
||||
"Adding node to routing table";
|
||||
"node_id" => format!("{}", bootnode_enr.node_id()),
|
||||
"peer_id" => format!("{}", bootnode_enr.peer_id()),
|
||||
"node_id" => bootnode_enr.node_id().to_string(),
|
||||
"peer_id" => bootnode_enr.peer_id().to_string(),
|
||||
"ip" => format!("{:?}", bootnode_enr.ip()),
|
||||
"udp" => format!("{:?}", bootnode_enr.udp()),
|
||||
"tcp" => format!("{:?}", bootnode_enr.tcp())
|
||||
);
|
||||
let repr = bootnode_enr.to_string();
|
||||
let _ = discv5.add_enr(bootnode_enr).map_err(|e| {
|
||||
debug!(
|
||||
error!(
|
||||
log,
|
||||
"Could not add peer to the local routing table";
|
||||
"error" => e.to_string()
|
||||
"addr" => repr,
|
||||
"error" => e.to_string(),
|
||||
)
|
||||
});
|
||||
}
|
||||
@@ -217,7 +219,54 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
EventStream::InActive
|
||||
};
|
||||
|
||||
// Obtain the event stream
|
||||
if !config.boot_nodes_multiaddr.is_empty() {
|
||||
info!(log, "Contacting Multiaddr boot-nodes for their ENR");
|
||||
}
|
||||
|
||||
// get futures for requesting the Enrs associated to these multiaddr and wait for their
|
||||
// completion
|
||||
let mut fut_coll = config
|
||||
.boot_nodes_multiaddr
|
||||
.iter()
|
||||
.map(|addr| addr.to_string())
|
||||
// request the ENR for this multiaddr and keep the original for logging
|
||||
.map(|addr| {
|
||||
futures::future::join(
|
||||
discv5.request_enr(addr.clone()),
|
||||
futures::future::ready(addr),
|
||||
)
|
||||
})
|
||||
.collect::<FuturesUnordered<_>>();
|
||||
|
||||
while let Some((result, original_addr)) = fut_coll.next().await {
|
||||
match result {
|
||||
Ok(Some(enr)) => {
|
||||
debug!(
|
||||
log,
|
||||
"Adding node to routing table";
|
||||
"node_id" => enr.node_id().to_string(),
|
||||
"peer_id" => enr.peer_id().to_string(),
|
||||
"ip" => format!("{:?}", enr.ip()),
|
||||
"udp" => format!("{:?}", enr.udp()),
|
||||
"tcp" => format!("{:?}", enr.tcp())
|
||||
);
|
||||
let _ = discv5.add_enr(enr).map_err(|e| {
|
||||
error!(
|
||||
log,
|
||||
"Could not add peer to the local routing table";
|
||||
"addr" => original_addr.to_string(),
|
||||
"error" => e.to_string(),
|
||||
)
|
||||
});
|
||||
}
|
||||
Ok(None) => {
|
||||
error!(log, "No ENR found for MultiAddr"; "addr" => original_addr.to_string())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(log, "Error getting mapping to ENR"; "multiaddr" => original_addr.to_string(), "error" => e.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
cached_enrs: LruCache::new(50),
|
||||
@@ -733,8 +782,8 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
|
||||
if enr.eth2() == self.local_enr().eth2() {
|
||||
trace!(self.log, "Peer found in process of query"; "peer_id" => format!("{}", enr.peer_id()), "tcp_socket" => enr.tcp_socket());
|
||||
} else {
|
||||
// this is temporary warning for debugging the DHT
|
||||
warn!(self.log, "Found peer during discovery not on correct fork"; "peer_id" => format!("{}", enr.peer_id()), "tcp_socket" => enr.tcp_socket());
|
||||
// this is temporary warning for debugging the DHT
|
||||
warn!(self.log, "Found peer during discovery not on correct fork"; "peer_id" => format!("{}", enr.peer_id()), "tcp_socket" => enr.tcp_socket());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user