diff --git a/sn_networking/src/cmd.rs b/sn_networking/src/cmd.rs index e7c0686e4d..cdd7345ab2 100644 --- a/sn_networking/src/cmd.rs +++ b/sn_networking/src/cmd.rs @@ -181,6 +181,39 @@ pub enum SwarmCmd { FetchCompleted(RecordKey), } +impl SwarmCmd { + /// Check if the command can be dropped safely in times of high load. + pub(crate) fn can_be_dropped_safely(&self) -> bool { + match self { + SwarmCmd::Dial { .. } => true, + SwarmCmd::DialWithOpts { .. } => true, + SwarmCmd::GetAllLocalPeers { .. } => false, + SwarmCmd::GetKBuckets { .. } => true, + SwarmCmd::GetClosestKLocalPeers { .. } => false, + SwarmCmd::GetClosestPeersToAddressFromNetwork { .. } => true, + SwarmCmd::GetCloseGroupLocalPeers { .. } => false, + SwarmCmd::GetSwarmLocalState { .. } => false, + SwarmCmd::SendRequest { .. } => true, + SwarmCmd::SendResponse { .. } => true, + SwarmCmd::RecordStoreHasKey { .. } => true, + SwarmCmd::GetAllLocalRecordAddresses { .. } => true, + SwarmCmd::GetNetworkRecord { .. } => true, + SwarmCmd::GetLocalStoreCost { .. } => true, + SwarmCmd::PaymentReceived => false, + SwarmCmd::GetLocalRecord { .. } => true, + SwarmCmd::PutRecord { .. } => false, + SwarmCmd::PutRecordTo { .. } => false, + SwarmCmd::PutLocalRecord { .. } => false, + SwarmCmd::RemoveFailedLocalRecord { .. } => false, + SwarmCmd::AddLocalRecordAsStored { .. } => false, + SwarmCmd::TriggerIntervalReplication => true, + SwarmCmd::RecordNodeIssue { .. } => false, + SwarmCmd::IsPeerShunned { .. } => true, + SwarmCmd::QuoteVerification { .. } => false, + SwarmCmd::FetchCompleted { .. } => false, + } + } +} /// Debug impl for SwarmCmd to avoid printing full Record, instead only RecodKey /// and RecordKind are printed. impl Debug for SwarmCmd { diff --git a/sn_networking/src/lib.rs b/sn_networking/src/lib.rs index df13d6cdaf..e0d787aa06 100644 --- a/sn_networking/src/lib.rs +++ b/sn_networking/src/lib.rs @@ -965,6 +965,11 @@ pub(crate) fn send_swarm_cmd(swarm_cmd_sender: Sender, cmd: SwarmCmd) let capacity = swarm_cmd_sender.capacity(); if capacity == 0 { + if cmd.can_be_dropped_safely() { + warn!("Dropping {cmd:?} as we're at max capacity"); + return; + } + error!( "SwarmCmd channel is full. Await capacity to send: {:?}", cmd