move sync state to the chains KV (#1940)
## Issue Addressed we have a log saying we add a peer to a chain, and an another one in case the chain is not syncing. To avoid needing to peer there two (and reduce log entries) simply log the chain's syncing state in the chain's KV
This commit is contained in:
parent
426b3001e0
commit
d0cbf3111a
@ -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,
|
||||
@ -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,
|
||||
@ -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
|
||||
@ -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("state", &format_args!("{:?}", self.state))?;
|
||||
slog::Result::Ok(())
|
||||
}
|
||||
}
|
||||
@ -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!(
|
||||
|
Loading…
Reference in New Issue
Block a user