Skip to content

Commit

Permalink
Ignore gossip messages when syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Aug 13, 2020
1 parent 8e59b5d commit 55caf5d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions beacon_node/network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ lazy_static! {
"gossip_processor_work_events_total",
"Count of work events processed by the gossip processor manager."
);
pub static ref GOSSIP_PROCESSOR_WORK_EVENTS_IGNORED_TOTAL: Result<IntCounter> = try_create_int_counter(
"gossip_processor_work_events_ignored_total",
"Count of work events processed by the gossip processor manager."
);
pub static ref GOSSIP_PROCESSOR_IDLE_EVENTS_TOTAL: Result<IntCounter> = try_create_int_counter(
"gossip_processor_idle_events_total",
"Count of idle events processed by the gossip processor manager."
Expand Down
17 changes: 16 additions & 1 deletion beacon_node/network/src/router/gossip_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use beacon_chain::{
ForkChoiceError,
};
use environment::TaskExecutor;
use eth2_libp2p::{MessageId, PeerId};
use eth2_libp2p::{MessageId, NetworkGlobals, PeerId};
use slog::{crit, debug, error, trace, warn, Logger};
use std::collections::VecDeque;
use std::sync::Arc;
Expand Down Expand Up @@ -171,6 +171,7 @@ pub struct GossipProcessor<T: BeaconChainTypes> {
pub beacon_chain: Arc<BeaconChain<T>>,
pub network_tx: mpsc::UnboundedSender<NetworkMessage<T::EthSpec>>,
pub sync_tx: mpsc::UnboundedSender<SyncMessage<T::EthSpec>>,
pub network_globals: Arc<NetworkGlobals<T::EthSpec>>,
pub executor: TaskExecutor,
pub max_workers: usize,
pub current_workers: usize,
Expand Down Expand Up @@ -281,6 +282,20 @@ impl<T: BeaconChainTypes> GossipProcessor<T> {
"msg" => "no new work and cannot spawn worker"
);
}
// There is a new work event, but the chain is syncing. Ignore it.
Some(WorkEvent {
message_id,
peer_id,
work,
}) if self.network_globals.sync_state.read().is_syncing() => {
metrics::inc_counter(&metrics::GOSSIP_PROCESSOR_WORK_EVENTS_IGNORED_TOTAL);
trace!(
self.log,
"Gossip processor skipping work";
"msg" => "chain is syncing"
);
}
// There is a new work event and the chain is not syncing. Process it.
Some(WorkEvent {
message_id,
peer_id,
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/network/src/router/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<T: BeaconChainTypes> Processor<T> {
let sync_send = crate::sync::manager::spawn(
executor.clone(),
beacon_chain.clone(),
network_globals,
network_globals.clone(),
network_send.clone(),
sync_logger,
);
Expand All @@ -65,6 +65,7 @@ impl<T: BeaconChainTypes> Processor<T> {
beacon_chain: beacon_chain.clone(),
network_tx: network_send.clone(),
sync_tx: sync_send.clone(),
network_globals,
executor,
max_workers: num_cpus::get(),
current_workers: 0,
Expand Down

0 comments on commit 55caf5d

Please sign in to comment.