Sync update (#1412)

## Issue Addressed

Recurring sync loop and invalid batch downloading

## Proposed Changes

Shifts the batches to include the first slot of each epoch. This ensures the finalized is always downloaded once a chain has completed syncing. 

Also add in logic to prevent re-dialing disconnected peers. Non-performant peers get disconnected during sync, this prevents re-connection to these during sync. 

## Additional Info

N/A
This commit is contained in:
Age Manning
2020-07-29 05:25:10 +00:00
parent f53dedb27d
commit 395d99ce03
5 changed files with 84 additions and 45 deletions

View File

@@ -159,7 +159,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
info.score.apply_peer_action(action);
if previous_state != info.score.state() {
match info.score.state() {
ScoreState::Ban => {
ScoreState::Banned => {
debug!(self.log, "Peer has been banned"; "peer_id" => peer_id.to_string(), "score" => info.score.to_string());
ban_peer = Some(peer_id.clone());
if info.connection_status.is_connected_or_dialing() {
@@ -169,7 +169,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
));
}
}
ScoreState::Disconnect => {
ScoreState::Disconnected => {
debug!(self.log, "Peer transitioned to disconnect state"; "peer_id" => peer_id.to_string(), "score" => info.score.to_string(), "past_state" => previous_state.to_string());
// disconnect the peer if it's currently connected or dialing
unban_peer = Some(peer_id.clone());
@@ -501,7 +501,11 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
.peers
.read()
.is_connected_or_dialing(&peer_id)
&& !self.network_globals.peers.read().is_banned(&peer_id)
&& !self
.network_globals
.peers
.read()
.is_banned_or_disconnected(&peer_id)
{
// TODO: Update output
// This should be updated with the peer dialing. In fact created once the peer is
@@ -629,7 +633,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
// handle score transitions
if previous_state != info.score.state() {
match info.score.state() {
ScoreState::Ban => {
ScoreState::Banned => {
debug!(self.log, "Peer has been banned"; "peer_id" => peer_id.to_string(), "score" => info.score.to_string());
to_ban_peers.push(peer_id.clone());
if info.connection_status.is_connected_or_dialing() {
@@ -639,7 +643,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
));
}
}
ScoreState::Disconnect => {
ScoreState::Disconnected => {
debug!(self.log, "Peer transitioned to disconnect state"; "peer_id" => peer_id.to_string(), "score" => info.score.to_string(), "past_state" => previous_state.to_string());
// disconnect the peer if it's currently connected or dialing
to_unban_peers.push(peer_id.clone());

View File

@@ -1,6 +1,6 @@
use super::peer_info::{PeerConnectionStatus, PeerInfo};
use super::peer_sync_status::PeerSyncStatus;
use super::score::Score;
use super::score::{Score, ScoreState};
use crate::rpc::methods::MetaData;
use crate::PeerId;
use rand::seq::SliceRandom;
@@ -99,9 +99,17 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
/// Returns true if the Peer is banned.
pub fn is_banned(&self, peer_id: &PeerId) -> bool {
match self.peers.get(peer_id).map(|info| &info.connection_status) {
Some(status) => status.is_banned(),
None => false,
match self.peers.get(peer_id).map(|info| info.score.state()) {
Some(ScoreState::Banned) => true,
_ => false,
}
}
/// Returns true if the Peer is either banned or in the disconnected state.
pub fn is_banned_or_disconnected(&self, peer_id: &PeerId) -> bool {
match self.peers.get(peer_id).map(|info| info.score.state()) {
Some(ScoreState::Banned) | Some(ScoreState::Disconnected) => true,
_ => false,
}
}

View File

@@ -60,10 +60,10 @@ pub(crate) enum ScoreState {
/// We are content with the peers performance. We permit connections and messages.
Healthy,
/// The peer should be disconnected. We allow re-connections if the peer is persistent.
Disconnect,
Disconnected,
/// The peer is banned. We disallow new connections until it's score has decayed into a
/// tolerable threshold.
Ban,
Banned,
}
/// A peer's score (perceived potential usefulness).
@@ -138,8 +138,8 @@ impl std::fmt::Display for ScoreState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ScoreState::Healthy => write!(f, "Healthy"),
ScoreState::Ban => write!(f, "Ban"),
ScoreState::Disconnect => write!(f, "Disconnect"),
ScoreState::Banned => write!(f, "Banned"),
ScoreState::Disconnected => write!(f, "Disconnected"),
}
}
}
@@ -164,8 +164,8 @@ impl Score {
/// Returns the expected state of the peer given it's score.
pub(crate) fn state(&self) -> ScoreState {
match self.score {
x if x <= MIN_SCORE_BEFORE_BAN => ScoreState::Ban,
x if x <= MIN_SCORE_BEFORE_DISCONNECT => ScoreState::Disconnect,
x if x <= MIN_SCORE_BEFORE_BAN => ScoreState::Banned,
x if x <= MIN_SCORE_BEFORE_DISCONNECT => ScoreState::Disconnected,
_ => ScoreState::Healthy,
}
}