Skip to content

Commit

Permalink
move sync state to the chains KV
Browse files Browse the repository at this point in the history
  • Loading branch information
divagant-martian committed Nov 20, 2020
1 parent 3b405f1 commit b4980aa
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions beacon_node/network/src/sync/range_sync/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const BATCH_BUFFER_SIZE: u8 = 5;
pub type ProcessingResult = Result<KeepChain, RemoveChain>;

/// Reasons for removing a chain
#[derive(Debug)]
pub enum RemoveChain {
EmptyPeerPool,
ChainCompleted,
Expand Down Expand Up @@ -101,7 +102,7 @@ pub struct SyncingChain<T: BeaconChainTypes> {
log: slog::Logger,
}

#[derive(PartialEq)]
#[derive(PartialEq, Debug)]
pub enum ChainSyncingState {
/// The chain is not being synced.
Stopped,
Expand Down Expand Up @@ -764,9 +765,6 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
network: &mut SyncNetworkContext<T::EthSpec>,
peer_id: PeerId,
) -> ProcessingResult {
if let ChainSyncingState::Stopped = self.state {
debug!(self.log, "Peer added to non-syncing chain"; "peer" => %peer_id)
}
// add the peer without overwriting its active requests
if self.peers.entry(peer_id).or_default().is_empty() {
// Either new or not, this peer is idle, try to request more batches
Expand Down Expand Up @@ -1041,6 +1039,7 @@ impl<T: BeaconChainTypes> slog::KV for SyncingChain<T> {
serializer.emit_usize("batches", self.batches.len())?;
serializer.emit_usize("peers", self.peers.len())?;
serializer.emit_u8("validated_batches", self.validated_batches)?;
serializer.emit_arguments(format_args!("{:?}", self.state))?;
slog::Result::Ok(())
}
}
Expand All @@ -1052,19 +1051,6 @@ impl From<WrongBatchState> for RemoveChain {
}
}

impl std::fmt::Debug for RemoveChain {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// needed to avoid Debugging Strings
match self {
RemoveChain::ChainCompleted => f.write_str("ChainCompleted"),
RemoveChain::EmptyPeerPool => f.write_str("EmptyPeerPool"),
RemoveChain::ChainFailed(batch) => write!(f, "ChainFailed(batch: {} )", batch),
RemoveChain::WrongBatchState(reason) => write!(f, "WrongBatchState: {}", reason),
RemoveChain::WrongChainState(reason) => write!(f, "WrongChainState: {}", reason),
}
}
}

impl RemoveChain {
pub fn is_critical(&self) -> bool {
matches!(
Expand Down

0 comments on commit b4980aa

Please sign in to comment.