Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make eth protocol handler stateful in network #13955

Open
mattsse opened this issue Jan 23, 2025 · 1 comment
Open

Make eth protocol handler stateful in network #13955

mattsse opened this issue Jan 23, 2025 · 1 comment
Labels
A-devp2p Related to the Ethereum P2P protocol A-networking Related to networking in general A-sdk Related to reth's use as a library C-enhancement New feature or request D-complex Quite challenging from either a design or technical perspective Ask for help!

Comments

@mattsse
Copy link
Collaborator

mattsse commented Jan 23, 2025

Describe the feature

rn the eth handler used by peer connections are fixed to the default eth protocol spec:

pub enum EthMessage<N: NetworkPrimitives = EthNetworkPrimitives> {

this means that, while the types are configurable, the actual message variants are not.

the network impl itself is only concerned with bodies,headers,transaction messages

/// All Bi-directional eth-message variants that can be sent to a session or received from a
/// session.
#[derive(Debug)]
pub enum PeerMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
/// Announce new block hashes
NewBlockHashes(NewBlockHashes),
/// Broadcast new block.
NewBlock(NewBlockMessage<N::Block>),
/// Received transactions _from_ the peer
ReceivedTransaction(Transactions<N::BroadcastedTransaction>),
/// Broadcast transactions _from_ local _to_ a peer.
SendTransactions(SharedTransactions<N::BroadcastedTransaction>),
/// Send new pooled transactions
PooledTransactions(NewPooledTransactionHashes),
/// 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),
}

we assume this will still be the case, but we'd like to make connection handling configurable:

let stream = match get_ecies_stream(stream, secret_key, direction).await {
Ok(stream) => stream,
Err(error) => {
let _ = events
.send(PendingSessionEvent::EciesAuthError {
remote_addr,
session_id,
error,
direction,
})
.await;
return
}
};
let unauthed = UnauthedP2PStream::new(stream);
let auth = authenticate_stream(
unauthed,
session_id,
remote_addr,
local_addr,
direction,
hello,
status,
fork_filter,
extra_handlers,
)
.boxed();

meaning we'd like to support a custom p2pstream type:

// conduct the p2p handshake and return the authenticated stream
let (p2p_stream, their_hello) = match stream.handshake(hello).await {

this can be implemented similarly to what we already do with additional rlpx protocol handlers:

/// Additional `RLPx` sub-protocols to be used by the session manager.
extra_protocols: RlpxSubProtocols,

so some type that knows:

This is a significant change and should be done in multiple steps
First we should introduce a stateful authenticator style type that knows how to establish incoming and outgoing connections (still restricted to the default eth types)
Afterwards we can slow relax the EthMessage locking and make it possible to configure a modified eth protocol for example.

Additional context

No response

@mattsse mattsse added A-devp2p Related to the Ethereum P2P protocol A-networking Related to networking in general A-sdk Related to reth's use as a library C-enhancement New feature or request D-complex Quite challenging from either a design or technical perspective Ask for help! labels Jan 23, 2025
@nadtech-hub
Copy link
Contributor

I would like to work on this one too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-devp2p Related to the Ethereum P2P protocol A-networking Related to networking in general A-sdk Related to reth's use as a library C-enhancement New feature or request D-complex Quite challenging from either a design or technical perspective Ask for help!
Projects
Status: Todo
Development

No branches or pull requests

2 participants