mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 11:41:51 +00:00
Libp2p Connection Limit (#2455)
* Get libp2p to handle connection limits * fmt
This commit is contained in:
@@ -42,8 +42,10 @@ regex = "1.3.9"
|
||||
strum = { version = "0.20", features = ["derive"] }
|
||||
|
||||
[dependencies.libp2p]
|
||||
version = "0.39.1"
|
||||
default-features = false
|
||||
#version = "0.39.1"
|
||||
#default-features = false
|
||||
git = "https://github.com/sigp/rust-libp2p"
|
||||
rev = "323cae1d08112052740834aa1fb262ae43e6f783"
|
||||
features = ["websocket", "identify", "mplex", "yamux", "noise", "gossipsub", "dns-tokio", "tcp-tokio"]
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -54,15 +54,14 @@ const HEARTBEAT_INTERVAL: u64 = 30;
|
||||
/// A fraction of `PeerManager::target_peers` that we allow to connect to us in excess of
|
||||
/// `PeerManager::target_peers`. For clarity, if `PeerManager::target_peers` is 50 and
|
||||
/// PEER_EXCESS_FACTOR = 0.1 we allow 10% more nodes, i.e 55.
|
||||
const PEER_EXCESS_FACTOR: f32 = 0.1;
|
||||
pub const PEER_EXCESS_FACTOR: f32 = 0.1;
|
||||
/// A fraction of `PeerManager::target_peers` that need to be outbound-only connections.
|
||||
pub const MIN_OUTBOUND_ONLY_FACTOR: f32 = 0.1;
|
||||
|
||||
/// Relative factor of peers that are allowed to have a negative gossipsub score without penalizing
|
||||
/// them in lighthouse.
|
||||
const ALLOWED_NEGATIVE_GOSSIPSUB_FACTOR: f32 = 0.1;
|
||||
|
||||
/// A fraction of `PeerManager::target_peers` that need to be outbound-only connections.
|
||||
const MIN_OUTBOUND_ONLY_FACTOR: f32 = 0.1;
|
||||
|
||||
/// The main struct that handles peer's reputation and connection status.
|
||||
pub struct PeerManager<TSpec: EthSpec> {
|
||||
/// Storage of network globals to access the `PeerDB`.
|
||||
|
||||
@@ -27,6 +27,8 @@ use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use types::{ChainSpec, EnrForkId, EthSpec};
|
||||
|
||||
use crate::peer_manager::{MIN_OUTBOUND_ONLY_FACTOR, PEER_EXCESS_FACTOR};
|
||||
|
||||
pub const NETWORK_KEY_FILENAME: &str = "key";
|
||||
/// The maximum simultaneous libp2p connections per peer.
|
||||
const MAX_CONNECTIONS_PER_PEER: u32 = 1;
|
||||
@@ -129,8 +131,17 @@ impl<TSpec: EthSpec> Service<TSpec> {
|
||||
let limits = ConnectionLimits::default()
|
||||
.with_max_pending_incoming(Some(5))
|
||||
.with_max_pending_outgoing(Some(16))
|
||||
.with_max_established_incoming(Some((config.target_peers as f64 * 1.2) as u32))
|
||||
.with_max_established_outgoing(Some((config.target_peers as f64 * 1.2) as u32))
|
||||
.with_max_established_incoming(Some(
|
||||
(config.target_peers as f32
|
||||
* (1.0 + PEER_EXCESS_FACTOR - MIN_OUTBOUND_ONLY_FACTOR))
|
||||
as u32,
|
||||
))
|
||||
.with_max_established_outgoing(Some(
|
||||
(config.target_peers as f32 * (1.0 + PEER_EXCESS_FACTOR)) as u32,
|
||||
))
|
||||
.with_max_established_total(Some(
|
||||
(config.target_peers as f32 * (1.0 + PEER_EXCESS_FACTOR)) as u32,
|
||||
))
|
||||
.with_max_established_per_peer(Some(MAX_CONNECTIONS_PER_PEER));
|
||||
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user