Skip to content

Commit a6887b9

Browse files
authored
Bleeding edge discovery (#2435)
* Update discovery banning logic and tokio * Update to latest discovery * Shift to latest discovery * Fmt
1 parent 8d6cf0b commit a6887b9

File tree

29 files changed

+52
-35
lines changed

29 files changed

+52
-35
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

account_manager/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ eth2_wallet = { path = "../crypto/eth2_wallet" }
2727
eth2_wallet_manager = { path = "../common/eth2_wallet_manager" }
2828
rand = "0.7.3"
2929
validator_dir = { path = "../common/validator_dir" }
30-
tokio = { version = "1.1.0", features = ["full"] }
30+
tokio = { version = "1.7.1", features = ["full"] }
3131
eth2_keystore = { path = "../crypto/eth2_keystore" }
3232
account_utils = { path = "../common/account_utils" }
3333
slashing_protection = { path = "../validator_client/slashing_protection" }

beacon_node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ slog = { version = "2.5.2", features = ["max_level_trace", "release_max_level_tr
2626
slog-term = "2.6.0"
2727
slog-async = "2.5.0"
2828
ctrlc = { version = "3.1.6", features = ["termination"] }
29-
tokio = { version = "1.1.0", features = ["time"] }
29+
tokio = { version = "1.7.1", features = ["time"] }
3030
exit-future = "0.2.0"
3131
dirs = "3.0.1"
3232
logging = { path = "../common/logging" }

beacon_node/beacon_chain/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ eth2_ssz_derive = "0.1.0"
4040
state_processing = { path = "../../consensus/state_processing" }
4141
tree_hash = "0.1.1"
4242
types = { path = "../../consensus/types" }
43-
tokio = "1.1.0"
43+
tokio = "1.7.1"
4444
eth1 = { path = "../eth1" }
4545
futures = "0.3.7"
4646
genesis = { path = "../genesis" }

beacon_node/client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ error-chain = "0.12.4"
2626
serde_yaml = "0.8.13"
2727
slog = { version = "2.5.2", features = ["max_level_trace"] }
2828
slog-async = "2.5.0"
29-
tokio = "1.1.0"
29+
tokio = "1.7.1"
3030
dirs = "3.0.1"
3131
futures = "0.3.7"
3232
reqwest = { version = "0.11.0", features = ["native-tls-vendored"] }

beacon_node/eth1/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tree_hash = "0.1.1"
2626
eth2_hashing = "0.1.0"
2727
parking_lot = "0.11.0"
2828
slog = "2.5.2"
29-
tokio = { version = "1.1.0", features = ["full"] }
29+
tokio = { version = "1.7.1", features = ["full"] }
3030
state_processing = { path = "../../consensus/state_processing" }
3131
libflate = "1.0.2"
3232
lighthouse_metrics = { path = "../../common/lighthouse_metrics"}

beacon_node/eth2_libp2p/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = ["Sigma Prime <[email protected]>"]
55
edition = "2018"
66

77
[dependencies]
8-
discv5 = { version = "0.1.0-beta.5", features = ["libp2p"] }
8+
discv5 = { version = "0.1.0-beta.6", features = ["libp2p"] }
99
unsigned-varint = { version = "0.6.0", features = ["codec"] }
1010
types = { path = "../../consensus/types" }
1111
hashset_delay = { path = "../../common/hashset_delay" }
@@ -16,7 +16,7 @@ eth2_ssz = "0.1.2"
1616
eth2_ssz_derive = "0.1.0"
1717
slog = { version = "2.5.2", features = ["max_level_trace"] }
1818
lighthouse_version = { path = "../../common/lighthouse_version" }
19-
tokio = { version = "1.1.0", features = ["time", "macros"] }
19+
tokio = { version = "1.7.1", features = ["time", "macros"] }
2020
futures = "0.3.7"
2121
futures-io = "0.3.7"
2222
error-chain = "0.12.4"
@@ -47,7 +47,7 @@ default-features = false
4747
features = ["websocket", "identify", "mplex", "yamux", "noise", "gossipsub", "dns-tokio", "tcp-tokio"]
4848

4949
[dev-dependencies]
50-
tokio = { version = "1.1.0", features = ["full"] }
50+
tokio = { version = "1.7.1", features = ["full"] }
5151
slog-term = "2.6.0"
5252
slog-async = "2.5.0"
5353
tempfile = "3.1.0"

beacon_node/eth2_libp2p/src/config.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ impl Default for Config {
151151
.build()
152152
.expect("valid gossipsub configuration");
153153

154+
// Discv5 Unsolicited Packet Rate Limiter
155+
let filter_rate_limiter = Some(
156+
discv5::RateLimiterBuilder::new()
157+
.total_n_every(10, Duration::from_secs(1)) // Allow bursts, average 10 per second
158+
.ip_n_every(9, Duration::from_secs(1)) // Allow bursts, average 9 per second
159+
.node_n_every(8, Duration::from_secs(1)) // Allow bursts, average 8 per second
160+
.build()
161+
.expect("The total rate limit has been specified"),
162+
);
163+
154164
// discv5 configuration
155165
let discv5_config = Discv5ConfigBuilder::new()
156166
.enable_packet_filter()
@@ -164,6 +174,10 @@ impl Default for Config {
164174
.disable_report_discovered_peers()
165175
.ip_limit() // limits /24 IP's in buckets.
166176
.incoming_bucket_limit(8) // half the bucket size
177+
.filter_rate_limiter(filter_rate_limiter)
178+
.filter_max_bans_per_ip(Some(5))
179+
.filter_max_nodes_per_ip(Some(10))
180+
.ban_duration(Some(Duration::from_secs(3600)))
167181
.ping_interval(Duration::from_secs(300))
168182
.build();
169183

beacon_node/eth2_libp2p/src/discovery/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,13 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
497497
// first try and convert the peer_id to a node_id.
498498
if let Ok(node_id) = peer_id_to_node_id(peer_id) {
499499
// If we could convert this peer id, remove it from the DHT and ban it from discovery.
500-
self.discv5.ban_node(&node_id);
500+
self.discv5.ban_node(&node_id, None);
501501
// Remove the node from the routing table.
502502
self.discv5.remove_node(&node_id);
503503
}
504504

505505
for ip_address in ip_addresses {
506-
self.discv5.ban_ip(ip_address);
506+
self.discv5.ban_ip(ip_address, None);
507507
}
508508
}
509509

@@ -512,11 +512,11 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
512512
// first try and convert the peer_id to a node_id.
513513
if let Ok(node_id) = peer_id_to_node_id(peer_id) {
514514
// If we could convert this peer id, remove it from the DHT and ban it from discovery.
515-
self.discv5.permit_node(&node_id);
515+
self.discv5.ban_node_remove(&node_id);
516516
}
517517

518518
for ip_address in ip_addresses {
519-
self.discv5.permit_ip(ip_address);
519+
self.discv5.ban_ip_remove(&ip_address);
520520
}
521521
}
522522

@@ -944,7 +944,9 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
944944
*self.network_globals.local_enr.write() = enr;
945945
return Poll::Ready(DiscoveryEvent::SocketUpdated(socket));
946946
}
947-
_ => {} // Ignore all other discv5 server events
947+
Discv5Event::EnrAdded { .. }
948+
| Discv5Event::TalkRequest(_)
949+
| Discv5Event::NodeInserted { .. } => {} // Ignore all other discv5 server events
948950
}
949951
}
950952
}

beacon_node/genesis/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ merkle_proof = { path = "../../consensus/merkle_proof" }
2020
eth2_ssz = "0.1.2"
2121
eth2_hashing = "0.1.0"
2222
tree_hash = "0.1.1"
23-
tokio = { version = "1.1.0", features = ["full"] }
23+
tokio = { version = "1.7.1", features = ["full"] }
2424
parking_lot = "0.11.0"
2525
slog = "2.5.2"
2626
exit-future = "0.2.0"

0 commit comments

Comments
 (0)