Skip to content

Commit

Permalink
chore: rm unused capabilities code (#13935)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jan 22, 2025
1 parent 3e181ab commit 6937578
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 83 deletions.
24 changes: 3 additions & 21 deletions crates/net/eth-wire/src/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ use crate::{
};
use alloy_primitives::bytes::Bytes;
use derive_more::{Deref, DerefMut};
use reth_eth_wire_types::{EthMessage, EthNetworkPrimitives, NetworkPrimitives};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::{
borrow::Cow,
collections::{BTreeSet, HashMap},
};

/// A Capability message consisting of the message-id and the payload
/// A Capability message consisting of the message-id and the payload.
#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RawCapabilityMessage {
/// Identifier of the message.
pub id: usize,
Expand All @@ -37,27 +34,12 @@ impl RawCapabilityMessage {
///
/// Caller must ensure that the rlp encoded `payload` matches the given `id`.
///
/// See also [`EthMessage`]
/// See also [`EthMessage`](crate::EthMessage)
pub const fn eth(id: EthMessageID, payload: Bytes) -> Self {
Self::new(id as usize, payload)
}
}

/// Various protocol related event types bubbled up from a session that need to be handled by the
/// network.
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum CapabilityMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
/// Eth sub-protocol message.
#[cfg_attr(
feature = "serde",
serde(bound = "EthMessage<N>: Serialize + serde::de::DeserializeOwned")
)]
Eth(EthMessage<N>),
/// Any other or manually crafted eth message.
Other(RawCapabilityMessage),
}

/// This represents a shared capability, its version, and its message id offset.
///
/// The [offset](SharedCapability::message_id_offset) is the message ID offset for this shared
Expand Down
23 changes: 1 addition & 22 deletions crates/net/network/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ use crate::{
};
use futures::{Future, StreamExt};
use parking_lot::Mutex;
use reth_eth_wire::{
capability::CapabilityMessage, Capabilities, DisconnectReason, EthNetworkPrimitives,
NetworkPrimitives,
};
use reth_eth_wire::{DisconnectReason, EthNetworkPrimitives, NetworkPrimitives};
use reth_fs_util::{self as fs, FsPathError};
use reth_metrics::common::mpsc::UnboundedMeteredSender;
use reth_network_api::{
Expand Down Expand Up @@ -441,20 +438,6 @@ impl<N: NetworkPrimitives> NetworkManager<N> {
}
}

/// Event hook for an unexpected message from the peer.
fn on_invalid_message(
&mut self,
peer_id: PeerId,
_capabilities: Arc<Capabilities>,
_message: CapabilityMessage<N>,
) {
trace!(target: "net", ?peer_id, "received unexpected message");
self.swarm
.state_mut()
.peers_mut()
.apply_reputation_change(&peer_id, ReputationChangeKind::BadProtocol);
}

/// Sends an event to the [`TransactionsManager`](crate::transactions::TransactionsManager) if
/// configured.
fn notify_tx_manager(&self, event: NetworkTransactionEvent<N>) {
Expand Down Expand Up @@ -702,10 +685,6 @@ impl<N: NetworkPrimitives> NetworkManager<N> {
// handle event
match event {
SwarmEvent::ValidMessage { peer_id, message } => self.on_peer_message(peer_id, message),
SwarmEvent::InvalidCapabilityMessage { peer_id, capabilities, message } => {
self.on_invalid_message(peer_id, capabilities, message);
self.metrics.invalid_messages_received.increment(1);
}
SwarmEvent::TcpListenerClosed { remote_addr } => {
trace!(target: "net", ?remote_addr, "TCP listener closed.");
}
Expand Down
2 changes: 2 additions & 0 deletions crates/net/network/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub enum PeerMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
/// All `eth` request variants.
EthRequest(PeerRequest<N>),
/// Any other or manually crafted eth message.
///
/// Caution: It is expected that this is a valid `eth_` capability message.
Other(RawCapabilityMessage),
}

Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ pub(crate) enum NetworkHandleMessage<N: NetworkPrimitives = EthNetworkPrimitives
EthMessage {
/// The peer to send the message to.
peer_id: PeerId,
/// The message to send to the peer's sessions.
/// The `eth` protocol message to send to the peer's session.
message: PeerMessage<N>,
},
/// Applies a reputation change to the given peer.
Expand Down
12 changes: 1 addition & 11 deletions crates/net/network/src/session/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crate::{
};
use reth_ecies::ECIESError;
use reth_eth_wire::{
capability::CapabilityMessage, errors::EthStreamError, Capabilities, DisconnectReason,
EthVersion, NetworkPrimitives, Status,
errors::EthStreamError, Capabilities, DisconnectReason, EthVersion, NetworkPrimitives, Status,
};
use reth_network_api::PeerInfo;
use reth_network_peers::{NodeRecord, PeerId};
Expand Down Expand Up @@ -257,15 +256,6 @@ pub enum ActiveSessionMessage<N: NetworkPrimitives> {
/// Message received from the peer.
message: PeerMessage<N>,
},
/// Received a message that does not match the announced capabilities of the peer.
InvalidMessage {
/// Identifier of the remote peer.
peer_id: PeerId,
/// Announced capabilities of the remote peer.
capabilities: Arc<Capabilities>,
/// Message received from the peer.
message: CapabilityMessage<N>,
},
/// Received a bad message from the peer.
BadMessage {
/// Identifier of the remote peer.
Expand Down
18 changes: 3 additions & 15 deletions crates/net/network/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ use counter::SessionCounter;
use futures::{future::Either, io, FutureExt, StreamExt};
use reth_ecies::{stream::ECIESStream, ECIESError};
use reth_eth_wire::{
capability::CapabilityMessage, errors::EthStreamError, multiplex::RlpxProtocolMultiplexer,
Capabilities, DisconnectReason, EthVersion, HelloMessageWithProtocols, NetworkPrimitives,
Status, UnauthedEthStream, UnauthedP2PStream,
errors::EthStreamError, multiplex::RlpxProtocolMultiplexer, Capabilities, DisconnectReason,
EthVersion, HelloMessageWithProtocols, NetworkPrimitives, Status, UnauthedEthStream,
UnauthedP2PStream,
};
use reth_ethereum_forks::{ForkFilter, ForkId, ForkTransition, Head};
use reth_metrics::common::mpsc::MeteredPollSender;
Expand Down Expand Up @@ -444,9 +444,6 @@ impl<N: NetworkPrimitives> SessionManager<N> {
ActiveSessionMessage::ValidMessage { peer_id, message } => {
Poll::Ready(SessionEvent::ValidMessage { peer_id, message })
}
ActiveSessionMessage::InvalidMessage { peer_id, capabilities, message } => {
Poll::Ready(SessionEvent::InvalidMessage { peer_id, message, capabilities })
}
ActiveSessionMessage::BadMessage { peer_id } => {
Poll::Ready(SessionEvent::BadMessage { peer_id })
}
Expand Down Expand Up @@ -703,15 +700,6 @@ pub enum SessionEvent<N: NetworkPrimitives> {
/// Message received from the peer.
message: PeerMessage<N>,
},
/// Received a message that does not match the announced capabilities of the peer.
InvalidMessage {
/// The remote node's public key
peer_id: PeerId,
/// Announced capabilities of the remote peer.
capabilities: Arc<Capabilities>,
/// Message received from the peer.
message: CapabilityMessage<N>,
},
/// Received a bad message from the peer.
BadMessage {
/// Identifier of the remote peer.
Expand Down
15 changes: 2 additions & 13 deletions crates/net/network/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
};
use futures::Stream;
use reth_eth_wire::{
capability::CapabilityMessage, errors::EthStreamError, Capabilities, DisconnectReason,
EthNetworkPrimitives, EthVersion, NetworkPrimitives, Status,
errors::EthStreamError, Capabilities, DisconnectReason, EthNetworkPrimitives, EthVersion,
NetworkPrimitives, Status,
};
use reth_network_api::{PeerRequest, PeerRequestSender};
use reth_network_peers::PeerId;
Expand Down Expand Up @@ -149,9 +149,6 @@ impl<N: NetworkPrimitives> Swarm<N> {
SessionEvent::ValidMessage { peer_id, message } => {
Some(SwarmEvent::ValidMessage { peer_id, message })
}
SessionEvent::InvalidMessage { peer_id, capabilities, message } => {
Some(SwarmEvent::InvalidCapabilityMessage { peer_id, capabilities, message })
}
SessionEvent::IncomingPendingSessionClosed { remote_addr, error } => {
Some(SwarmEvent::IncomingPendingSessionClosed { remote_addr, error })
}
Expand Down Expand Up @@ -344,14 +341,6 @@ pub(crate) enum SwarmEvent<N: NetworkPrimitives = EthNetworkPrimitives> {
/// Message received from the peer
message: PeerMessage<N>,
},
/// Received a message that does not match the announced capabilities of the peer.
InvalidCapabilityMessage {
peer_id: PeerId,
/// Announced capabilities of the remote peer.
capabilities: Arc<Capabilities>,
/// Message received from the peer.
message: CapabilityMessage<N>,
},
/// Received a bad message from the peer.
BadMessage {
/// Identifier of the remote peer.
Expand Down

0 comments on commit 6937578

Please sign in to comment.