mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 03:12:41 +00:00
Misc Peer sync info adjustments (#1896)
## Issue Addressed #1856 ## Proposed Changes - For clarity, the router's processor now only decides if a peer is compatible and it disconnects it or sends it to sync accordingly. No logic here regarding how useful is the peer. - Update peer_sync_info's rules - Add an `IrrelevantPeer` sync status to account for incompatible peers (maybe this should be "IncompatiblePeer" now that I think about it?) this state is update upon receiving an internal goodbye in the peer manager - Misc code cleanups - Reduce the need to create `StatusMessage`s (and thus, `Arc` accesses ) - Add missing calls to update the global sync state The overall effect should be: - More peers recognized as Behind, and less as Unknown - Peers identified as incompatible
This commit is contained in:
@@ -7,9 +7,9 @@ use super::chain::{ChainId, ProcessingResult, RemoveChain, SyncingChain};
|
||||
use super::sync_type::RangeSyncType;
|
||||
use crate::beacon_processor::WorkEvent as BeaconWorkEvent;
|
||||
use crate::sync::network_context::SyncNetworkContext;
|
||||
use crate::sync::PeerSyncInfo;
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use eth2_libp2p::PeerId;
|
||||
use eth2_libp2p::SyncInfo;
|
||||
use fnv::FnvHashMap;
|
||||
use slog::{crit, debug, error};
|
||||
use smallvec::SmallVec;
|
||||
@@ -185,35 +185,22 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
|
||||
pub fn update(
|
||||
&mut self,
|
||||
network: &mut SyncNetworkContext<T::EthSpec>,
|
||||
awaiting_head_peers: &mut HashMap<PeerId, PeerSyncInfo>,
|
||||
local: &SyncInfo,
|
||||
awaiting_head_peers: &mut HashMap<PeerId, SyncInfo>,
|
||||
beacon_processor_send: &mpsc::Sender<BeaconWorkEvent<T::EthSpec>>,
|
||||
) {
|
||||
let (local_finalized_epoch, local_head_epoch) =
|
||||
match PeerSyncInfo::from_chain(&self.beacon_chain) {
|
||||
None => {
|
||||
return error!(
|
||||
self.log,
|
||||
"Failed to get peer sync info";
|
||||
"msg" => "likely due to head lock contention"
|
||||
)
|
||||
}
|
||||
Some(local) => (
|
||||
local.finalized_epoch,
|
||||
local.head_slot.epoch(T::EthSpec::slots_per_epoch()),
|
||||
),
|
||||
};
|
||||
|
||||
// Remove any outdated finalized/head chains
|
||||
self.purge_outdated_chains(awaiting_head_peers);
|
||||
self.purge_outdated_chains(local, awaiting_head_peers);
|
||||
|
||||
let local_head_epoch = local.head_slot.epoch(T::EthSpec::slots_per_epoch());
|
||||
// Choose the best finalized chain if one needs to be selected.
|
||||
self.update_finalized_chains(network, local_finalized_epoch, local_head_epoch);
|
||||
self.update_finalized_chains(network, local.finalized_epoch, local_head_epoch);
|
||||
|
||||
if !matches!(self.state, RangeSyncState::Finalized(_)) {
|
||||
// Handle head syncing chains if there are no finalized chains left.
|
||||
self.update_head_chains(
|
||||
network,
|
||||
local_finalized_epoch,
|
||||
local.finalized_epoch,
|
||||
local_head_epoch,
|
||||
awaiting_head_peers,
|
||||
beacon_processor_send,
|
||||
@@ -329,7 +316,7 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
|
||||
network: &mut SyncNetworkContext<T::EthSpec>,
|
||||
local_epoch: Epoch,
|
||||
local_head_epoch: Epoch,
|
||||
awaiting_head_peers: &mut HashMap<PeerId, PeerSyncInfo>,
|
||||
awaiting_head_peers: &mut HashMap<PeerId, SyncInfo>,
|
||||
beacon_processor_send: &mpsc::Sender<BeaconWorkEvent<T::EthSpec>>,
|
||||
) {
|
||||
// Include the awaiting head peers
|
||||
@@ -404,19 +391,9 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
|
||||
/// finalized block slot. Peers that would create outdated chains are removed too.
|
||||
pub fn purge_outdated_chains(
|
||||
&mut self,
|
||||
awaiting_head_peers: &mut HashMap<PeerId, PeerSyncInfo>,
|
||||
local_info: &SyncInfo,
|
||||
awaiting_head_peers: &mut HashMap<PeerId, SyncInfo>,
|
||||
) {
|
||||
let local_info = match PeerSyncInfo::from_chain(&self.beacon_chain) {
|
||||
Some(local) => local,
|
||||
None => {
|
||||
return error!(
|
||||
self.log,
|
||||
"Failed to get peer sync info";
|
||||
"msg" => "likely due to head lock contention"
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
let local_finalized_slot = local_info
|
||||
.finalized_epoch
|
||||
.start_slot(T::EthSpec::slots_per_epoch());
|
||||
|
||||
@@ -43,12 +43,13 @@ use super::chain::{ChainId, RemoveChain, SyncingChain};
|
||||
use super::chain_collection::ChainCollection;
|
||||
use super::sync_type::RangeSyncType;
|
||||
use crate::beacon_processor::WorkEvent as BeaconWorkEvent;
|
||||
use crate::router::processor::status_message;
|
||||
use crate::sync::network_context::SyncNetworkContext;
|
||||
use crate::sync::BatchProcessResult;
|
||||
use crate::sync::PeerSyncInfo;
|
||||
use crate::sync::RequestId;
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use eth2_libp2p::PeerId;
|
||||
use eth2_libp2p::SyncInfo;
|
||||
use slog::{crit, debug, error, trace};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -63,7 +64,7 @@ pub struct RangeSync<T: BeaconChainTypes> {
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
/// Last known sync info of our useful connected peers. We use this information to create Head
|
||||
/// chains after all finalized chains have ended.
|
||||
awaiting_head_peers: HashMap<PeerId, PeerSyncInfo>,
|
||||
awaiting_head_peers: HashMap<PeerId, SyncInfo>,
|
||||
/// A collection of chains that need to be downloaded. This stores any head or finalized chains
|
||||
/// that need to be downloaded.
|
||||
chains: ChainCollection<T>,
|
||||
@@ -100,22 +101,15 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
pub fn add_peer(
|
||||
&mut self,
|
||||
network: &mut SyncNetworkContext<T::EthSpec>,
|
||||
local_info: SyncInfo,
|
||||
peer_id: PeerId,
|
||||
remote_info: PeerSyncInfo,
|
||||
remote_info: SyncInfo,
|
||||
) {
|
||||
// evaluate which chain to sync from
|
||||
|
||||
// determine if we need to run a sync to the nearest finalized state or simply sync to
|
||||
// its current head
|
||||
|
||||
let local_info = match PeerSyncInfo::from_chain(&self.beacon_chain) {
|
||||
Some(local) => local,
|
||||
None => {
|
||||
return error!(self.log, "Failed to get peer sync info";
|
||||
"msg" => "likely due to head lock contention")
|
||||
}
|
||||
};
|
||||
|
||||
// convenience variable
|
||||
let remote_finalized_slot = remote_info
|
||||
.finalized_epoch
|
||||
@@ -146,6 +140,7 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
|
||||
self.chains.update(
|
||||
network,
|
||||
&local_info,
|
||||
&mut self.awaiting_head_peers,
|
||||
&self.beacon_processor_send,
|
||||
);
|
||||
@@ -182,6 +177,7 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
);
|
||||
self.chains.update(
|
||||
network,
|
||||
&local_info,
|
||||
&mut self.awaiting_head_peers,
|
||||
&self.beacon_processor_send,
|
||||
);
|
||||
@@ -345,9 +341,23 @@ impl<T: BeaconChainTypes> RangeSync<T> {
|
||||
|
||||
network.status_peers(self.beacon_chain.clone(), chain.peers());
|
||||
|
||||
let local = match status_message(&self.beacon_chain) {
|
||||
Ok(status) => SyncInfo {
|
||||
head_slot: status.head_slot,
|
||||
head_root: status.head_root,
|
||||
finalized_epoch: status.finalized_epoch,
|
||||
finalized_root: status.finalized_root,
|
||||
},
|
||||
Err(e) => {
|
||||
return error!(self.log, "Failed to get peer sync info";
|
||||
"msg" => "likely due to head lock contention", "err" => ?e)
|
||||
}
|
||||
};
|
||||
|
||||
// update the state of the collection
|
||||
self.chains.update(
|
||||
network,
|
||||
&local,
|
||||
&mut self.awaiting_head_peers,
|
||||
&self.beacon_processor_send,
|
||||
);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Contains logic about identifying which Sync to perform given PeerSyncInfo of ourselves and
|
||||
//! of a remote.
|
||||
|
||||
use crate::sync::PeerSyncInfo;
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use eth2_libp2p::SyncInfo;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// The type of Range sync that should be done relative to our current state.
|
||||
@@ -19,8 +19,8 @@ impl RangeSyncType {
|
||||
/// `PeerSyncInfo`.
|
||||
pub fn new<T: BeaconChainTypes>(
|
||||
chain: &Arc<BeaconChain<T>>,
|
||||
local_info: &PeerSyncInfo,
|
||||
remote_info: &PeerSyncInfo,
|
||||
local_info: &SyncInfo,
|
||||
remote_info: &SyncInfo,
|
||||
) -> RangeSyncType {
|
||||
// Check for finalized chain sync
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user