Allow discovery to be more lenient in enr eth2 fields (#1201)

* Allow discovery to be more lenient in enr eth2 fields

* Correct web3 dep

* Discovery bug fixes
This commit is contained in:
Age Manning
2020-05-27 06:34:15 +10:00
committed by GitHub
parent 8bc82c573d
commit 5122b2c13a
8 changed files with 171 additions and 151 deletions

View File

@@ -15,18 +15,18 @@ eth2_ssz = "0.1.2"
eth2_ssz_derive = "0.1.0"
slog = { version = "2.5.2", features = ["max_level_trace"] }
version = { path = "../version" }
tokio = { version = "0.2.20", features = ["time"] }
tokio = { version = "0.2.21", features = ["time"] }
futures = "0.3.5"
error-chain = "0.12.2"
dirs = "2.0.2"
fnv = "1.0.6"
fnv = "1.0.7"
unsigned-varint = { git = "https://github.com/sigp/unsigned-varint", branch = "latest-codecs", features = ["codec"] }
lazy_static = "1.4.0"
lighthouse_metrics = { path = "../../common/lighthouse_metrics" }
smallvec = "1.4.0"
lru = "0.4.3"
lru = "0.4.5"
parking_lot = "0.10.2"
sha2 = "0.8.1"
sha2 = "0.8.2"
base64 = "0.12.1"
snap = "1.0.0"
void = "1.0.2"
@@ -35,16 +35,16 @@ tokio-util = { version = "0.3.1", features = ["codec", "compat"] }
# Patched for quick updates
discv5 = { git = "https://github.com/sigp/discv5", rev = "7b3bd40591b62b8c002ffdb85de008aa9f82e2e5" }
tiny-keccak = "2.0.2"
libp2p-tcp = { version = "0.18.0", default-features = false, features = ["tokio"] }
libp2p-tcp = { version = "0.19.1", default-features = false, features = ["tokio"] }
[dependencies.libp2p]
version = "0.18.1"
version = "0.19.1"
default-features = false
features = ["websocket", "identify", "mplex", "yamux", "noise", "secio", "gossipsub", "dns"]
[dev-dependencies]
tokio = { version = "0.2.20", features = ["full"] }
tokio = { version = "0.2.21", features = ["full"] }
slog-stdlog = "4.0.0"
slog-term = "2.5.0"
slog-async = "2.5.0"

View File

@@ -36,6 +36,8 @@ use types::{EnrForkId, EthSpec, SubnetId};
const MAX_TIME_BETWEEN_PEER_SEARCHES: u64 = 120;
/// Initial delay between peer searches.
const INITIAL_SEARCH_DELAY: u64 = 5;
/// The number of peers we must be connected to before increasing the discovery delay.
const MINIMUM_PEERS_BEFORE_DELAY_INCREASE: usize = 5;
/// Local ENR storage filename.
pub const ENR_FILENAME: &str = "enr.dat";
/// Number of peers we'd like to have connected to a given long-lived subnet.
@@ -361,7 +363,9 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
}
};
// predicate for finding nodes with a matching fork
let eth2_fork_predicate = move |enr: &Enr| enr.eth2() == Ok(enr_fork_id.clone());
let eth2_fork_predicate = move |enr: &Enr| {
enr.eth2().map(|enr| enr.fork_digest) == Ok(enr_fork_id.fork_digest.clone())
};
let predicate = move |enr: &Enr| eth2_fork_predicate(enr) && enr_predicate(enr);
// general predicate
@@ -476,10 +480,13 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> {
Discv5Event::FindNodeResult { closer_peers, .. } => {
debug!(self.log, "Discovery query completed"; "peers_found" => closer_peers.len());
// update the time to the next query
if self.past_discovery_delay < MAX_TIME_BETWEEN_PEER_SEARCHES {
if self.past_discovery_delay < MAX_TIME_BETWEEN_PEER_SEARCHES
&& self.network_globals.connected_or_dialing_peers()
> MINIMUM_PEERS_BEFORE_DELAY_INCREASE
{
self.past_discovery_delay *= 2;
}
let delay = std::cmp::max(
let delay = std::cmp::min(
self.past_discovery_delay,
MAX_TIME_BETWEEN_PEER_SEARCHES,
);