mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
upgrade to libp2p 0.52 (#4431)
## Issue Addressed Upgrade libp2p to v0.52 ## Proposed Changes - **Workflows**: remove installation of `protoc` - **Book**: remove installation of `protoc` - **`Dockerfile`s and `cross`**: remove custom base `Dockerfile` for cross since it's no longer needed. Remove `protoc` from remaining `Dockerfiles`s - **Upgrade `discv5` to `v0.3.1`:** we have some cool stuff in there: no longer needs `protoc` and faster ip updates on cold start - **Upgrade `prometheus` to `0.21.0`**, now it no longer needs encoding checks - **things that look like refactors:** bunch of api types were renamed and need to be accessed in a different (clearer) way - **Lighthouse network** - connection limits is now a behaviour - banned peers no longer exist on the swarm level, but at the behaviour level - `connection_event_buffer_size` now is handled per connection with a buffer size of 4 - `mplex` is deprecated and was removed - rpc handler now logs the peer to which it belongs ## Additional Info Tried to keep as much behaviour unchanged as possible. However, there is a great deal of improvements we can do _after_ this upgrade: - Smart connection limits: Connection limits have been checked only based on numbers, we can now use information about the incoming peer to decide if we want it - More powerful peer management: Dial attempts from other behaviours can be rejected early - Incoming connections can be rejected early - Banning can be returned exclusively to the peer management: We should not get connections to banned peers anymore making use of this - TCP Nat updates: We might be able to take advantage of confirmed external addresses to check out tcp ports/ips Co-authored-by: Age Manning <Age@AgeManning.com> Co-authored-by: Akihito Nakano <sora.akatsuki@gmail.com>
This commit is contained in:
@@ -6,10 +6,7 @@ use directory::{
|
||||
DEFAULT_BEACON_NODE_DIR, DEFAULT_HARDCODED_NETWORK, DEFAULT_NETWORK_DIR, DEFAULT_ROOT_DIR,
|
||||
};
|
||||
use discv5::{Discv5Config, Discv5ConfigBuilder};
|
||||
use libp2p::gossipsub::{
|
||||
FastMessageId, GossipsubConfig, GossipsubConfigBuilder, GossipsubMessage, MessageId,
|
||||
RawGossipsubMessage, ValidationMode,
|
||||
};
|
||||
use libp2p::gossipsub;
|
||||
use libp2p::Multiaddr;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use sha2::{Digest, Sha256};
|
||||
@@ -83,7 +80,7 @@ pub struct Config {
|
||||
|
||||
/// Gossipsub configuration parameters.
|
||||
#[serde(skip)]
|
||||
pub gs_config: GossipsubConfig,
|
||||
pub gs_config: gossipsub::Config,
|
||||
|
||||
/// Discv5 configuration parameters.
|
||||
#[serde(skip)]
|
||||
@@ -265,7 +262,7 @@ impl Default for Config {
|
||||
|
||||
// Note: Using the default config here. Use `gossipsub_config` function for getting
|
||||
// Lighthouse specific configuration for gossipsub.
|
||||
let gs_config = GossipsubConfigBuilder::default()
|
||||
let gs_config = gossipsub::ConfigBuilder::default()
|
||||
.build()
|
||||
.expect("valid gossipsub configuration");
|
||||
|
||||
@@ -416,16 +413,16 @@ impl From<u8> for NetworkLoad {
|
||||
}
|
||||
|
||||
/// Return a Lighthouse specific `GossipsubConfig` where the `message_id_fn` depends on the current fork.
|
||||
pub fn gossipsub_config(network_load: u8, fork_context: Arc<ForkContext>) -> GossipsubConfig {
|
||||
pub fn gossipsub_config(network_load: u8, fork_context: Arc<ForkContext>) -> gossipsub::Config {
|
||||
// The function used to generate a gossipsub message id
|
||||
// We use the first 8 bytes of SHA256(topic, data) for content addressing
|
||||
let fast_gossip_message_id = |message: &RawGossipsubMessage| {
|
||||
let fast_gossip_message_id = |message: &gossipsub::RawMessage| {
|
||||
let data = [message.topic.as_str().as_bytes(), &message.data].concat();
|
||||
FastMessageId::from(&Sha256::digest(data)[..8])
|
||||
gossipsub::FastMessageId::from(&Sha256::digest(data)[..8])
|
||||
};
|
||||
fn prefix(
|
||||
prefix: [u8; 4],
|
||||
message: &GossipsubMessage,
|
||||
message: &gossipsub::Message,
|
||||
fork_context: Arc<ForkContext>,
|
||||
) -> Vec<u8> {
|
||||
let topic_bytes = message.topic.as_str().as_bytes();
|
||||
@@ -451,8 +448,8 @@ pub fn gossipsub_config(network_load: u8, fork_context: Arc<ForkContext>) -> Gos
|
||||
}
|
||||
|
||||
let is_merge_enabled = fork_context.fork_exists(ForkName::Merge);
|
||||
let gossip_message_id = move |message: &GossipsubMessage| {
|
||||
MessageId::from(
|
||||
let gossip_message_id = move |message: &gossipsub::Message| {
|
||||
gossipsub::MessageId::from(
|
||||
&Sha256::digest(
|
||||
prefix(MESSAGE_DOMAIN_VALID_SNAPPY, message, fork_context.clone()).as_slice(),
|
||||
)[..20],
|
||||
@@ -461,7 +458,7 @@ pub fn gossipsub_config(network_load: u8, fork_context: Arc<ForkContext>) -> Gos
|
||||
|
||||
let load = NetworkLoad::from(network_load);
|
||||
|
||||
GossipsubConfigBuilder::default()
|
||||
gossipsub::ConfigBuilder::default()
|
||||
.max_transmit_size(gossip_max_size(is_merge_enabled))
|
||||
.heartbeat_interval(load.heartbeat_interval)
|
||||
.mesh_n(load.mesh_n)
|
||||
@@ -474,7 +471,7 @@ pub fn gossipsub_config(network_load: u8, fork_context: Arc<ForkContext>) -> Gos
|
||||
.max_messages_per_rpc(Some(500)) // Responses to IWANT can be quite large
|
||||
.history_gossip(load.history_gossip)
|
||||
.validate_messages() // require validation before propagation
|
||||
.validation_mode(ValidationMode::Anonymous)
|
||||
.validation_mode(gossipsub::ValidationMode::Anonymous)
|
||||
.duplicate_cache_time(DUPLICATE_CACHE_TIME)
|
||||
.message_id_fn(gossip_message_id)
|
||||
.fast_message_id_fn(fast_gossip_message_id)
|
||||
|
||||
Reference in New Issue
Block a user