mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 11:41:51 +00:00
Upgrade to latest libp2p (#2605)
This is a pre-cursor to the next libp2p upgrade. It is currently being used for staging a number of PR upgrades which are contingent on the latest libp2p.
This commit is contained in:
@@ -4,7 +4,8 @@ use crate::behaviour::gossipsub_scoring_parameters::{
|
||||
use crate::config::gossipsub_config;
|
||||
use crate::discovery::{subnet_predicate, Discovery, DiscoveryEvent, TARGET_SUBNET_PEERS};
|
||||
use crate::peer_manager::{
|
||||
peerdb::score::ReportSource, ConnectionDirection, PeerManager, PeerManagerEvent,
|
||||
peerdb::score::PeerAction, peerdb::score::ReportSource, ConnectionDirection, PeerManager,
|
||||
PeerManagerEvent,
|
||||
};
|
||||
use crate::rpc::*;
|
||||
use crate::service::METADATA_FILENAME;
|
||||
@@ -26,7 +27,7 @@ use libp2p::{
|
||||
},
|
||||
identify::{Identify, IdentifyConfig, IdentifyEvent},
|
||||
swarm::{
|
||||
AddressScore, DialPeerCondition, NetworkBehaviourAction as NBAction,
|
||||
AddressScore, DialPeerCondition, NetworkBehaviour, NetworkBehaviourAction as NBAction,
|
||||
NetworkBehaviourEventProcess, PollParameters,
|
||||
},
|
||||
NetworkBehaviour, PeerId,
|
||||
@@ -121,7 +122,11 @@ enum InternalBehaviourMessage {
|
||||
/// This core behaviour is managed by `Behaviour` which adds peer management to all core
|
||||
/// behaviours.
|
||||
#[derive(NetworkBehaviour)]
|
||||
#[behaviour(out_event = "BehaviourEvent<TSpec>", poll_method = "poll")]
|
||||
#[behaviour(
|
||||
out_event = "BehaviourEvent<TSpec>",
|
||||
poll_method = "poll",
|
||||
event_process = true
|
||||
)]
|
||||
pub struct Behaviour<TSpec: EthSpec> {
|
||||
/* Sub-Behaviours */
|
||||
/// The routing pub-sub mechanism for eth2.
|
||||
@@ -192,9 +197,11 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
|
||||
"".into(),
|
||||
local_key.public(), // Still send legitimate public key
|
||||
)
|
||||
.with_cache_size(0)
|
||||
} else {
|
||||
IdentifyConfig::new("eth2/1.0.0".into(), local_key.public())
|
||||
.with_agent_version(lighthouse_version::version_with_platform())
|
||||
.with_cache_size(0)
|
||||
};
|
||||
|
||||
// Build and start the discovery sub-behaviour
|
||||
@@ -848,6 +855,15 @@ impl<TSpec: EthSpec> NetworkBehaviourEventProcess<GossipsubEvent> for Behaviour<
|
||||
.remove_subscription(&peer_id, &subnet_id);
|
||||
}
|
||||
}
|
||||
GossipsubEvent::GossipsubNotSupported { peer_id } => {
|
||||
debug!(self.log, "Peer does not support gossipsub"; "peer_id" => %peer_id);
|
||||
self.peer_manager.report_peer(
|
||||
&peer_id,
|
||||
PeerAction::LowToleranceError,
|
||||
ReportSource::Gossipsub,
|
||||
Some(GoodbyeReason::Unknown),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1031,11 +1047,13 @@ impl<TSpec: EthSpec> NetworkBehaviourEventProcess<IdentifyEvent> for Behaviour<T
|
||||
|
||||
impl<TSpec: EthSpec> Behaviour<TSpec> {
|
||||
/// Consumes the events list and drives the Lighthouse global NetworkBehaviour.
|
||||
fn poll<THandlerIn>(
|
||||
fn poll(
|
||||
&mut self,
|
||||
cx: &mut Context,
|
||||
_: &mut impl PollParameters,
|
||||
) -> Poll<NBAction<THandlerIn, BehaviourEvent<TSpec>>> {
|
||||
) -> Poll<
|
||||
NBAction<BehaviourEvent<TSpec>, <Behaviour<TSpec> as NetworkBehaviour>::ProtocolsHandler>,
|
||||
> {
|
||||
if let Some(waker) = &self.waker {
|
||||
if waker.will_wake(cx.waker()) {
|
||||
self.waker = Some(cx.waker().clone());
|
||||
@@ -1048,9 +1066,11 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
|
||||
if let Some(event) = self.internal_events.pop_front() {
|
||||
match event {
|
||||
InternalBehaviourMessage::DialPeer(peer_id) => {
|
||||
let handler = self.new_handler();
|
||||
return Poll::Ready(NBAction::DialPeer {
|
||||
peer_id,
|
||||
condition: DialPeerCondition::Disconnected,
|
||||
handler,
|
||||
});
|
||||
}
|
||||
InternalBehaviourMessage::SocketUpdated(address) => {
|
||||
|
||||
Reference in New Issue
Block a user