mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Subnet discovery fixes (#2095)
## Issue Addressed N/A ## Proposed Changes Fixes multiple issues related to discovering of subnet peers. 1. Subnet discovery retries after yielding no results 2. Metadata updates if peer send older metadata 3. peerdb stores the peer subscriptions from gossipsub
This commit is contained in:
@@ -5,7 +5,10 @@ use crate::peer_manager::{
|
||||
};
|
||||
use crate::rpc::*;
|
||||
use crate::service::METADATA_FILENAME;
|
||||
use crate::types::{GossipEncoding, GossipKind, GossipTopic, MessageData, SubnetDiscovery};
|
||||
use crate::types::{
|
||||
subnet_id_from_topic_hash, GossipEncoding, GossipKind, GossipTopic, MessageData,
|
||||
SubnetDiscovery,
|
||||
};
|
||||
use crate::Eth2Enr;
|
||||
use crate::{error, metrics, Enr, NetworkConfig, NetworkGlobals, PubsubMessage, TopicHash};
|
||||
use futures::prelude::*;
|
||||
@@ -100,8 +103,6 @@ pub enum BehaviourEvent<TSpec: EthSpec> {
|
||||
/// The message itself.
|
||||
message: PubsubMessage<TSpec>,
|
||||
},
|
||||
/// Subscribed to peer for given topic
|
||||
PeerSubscribed(PeerId, TopicHash),
|
||||
/// Inform the network to send a Status to this peer.
|
||||
StatusPeer(PeerId),
|
||||
}
|
||||
@@ -665,9 +666,15 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
|
||||
}
|
||||
}
|
||||
GossipsubEvent::Subscribed { peer_id, topic } => {
|
||||
self.add_event(BehaviourEvent::PeerSubscribed(peer_id, topic));
|
||||
if let Some(subnet_id) = subnet_id_from_topic_hash(&topic) {
|
||||
self.peer_manager.add_subscription(&peer_id, subnet_id);
|
||||
}
|
||||
}
|
||||
GossipsubEvent::Unsubscribed { peer_id, topic } => {
|
||||
if let Some(subnet_id) = subnet_id_from_topic_hash(&topic) {
|
||||
self.peer_manager.remove_subscription(&peer_id, subnet_id);
|
||||
}
|
||||
}
|
||||
GossipsubEvent::Unsubscribed { .. } => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1102,6 +1109,9 @@ impl<TSpec: EthSpec> NetworkBehaviour for Behaviour<TSpec> {
|
||||
fn inject_disconnected(&mut self, peer_id: &PeerId) {
|
||||
// If the application/behaviour layers thinks this peer has connected inform it of the disconnect.
|
||||
|
||||
// Remove all subnet subscriptions from peerdb for the disconnected peer.
|
||||
self.peer_manager().remove_all_subscriptions(&peer_id);
|
||||
|
||||
if self
|
||||
.network_globals
|
||||
.peers
|
||||
|
||||
Reference in New Issue
Block a user