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

feat(net): network scaffolding #110

Merged
merged 30 commits into from
Nov 7, 2022
Merged

feat(net): network scaffolding #110

merged 30 commits into from
Nov 7, 2022

Conversation

mattsse
Copy link
Collaborator

@mattsse mattsse commented Oct 20, 2022

sketch out Network type, incoming tcp listener and udp discovery.

Blocked by #113

@onbjerg onbjerg added C-enhancement New feature or request A-devp2p Related to the Ethereum P2P protocol labels Oct 21, 2022
@codecov
Copy link

codecov bot commented Oct 28, 2022

Codecov Report

Merging #110 (5427fb5) into main (9c40f82) will decrease coverage by 3.96%.
The diff coverage is 13.49%.

@@            Coverage Diff             @@
##             main     #110      +/-   ##
==========================================
- Coverage   74.84%   70.88%   -3.97%     
==========================================
  Files         171      186      +15     
  Lines       14093    15130    +1037     
==========================================
+ Hits        10548    10725     +177     
- Misses       3545     4405     +860     
Impacted Files Coverage Δ
crates/net/eth-wire/src/ethstream.rs 88.01% <0.00%> (-0.92%) ⬇️
crates/net/eth-wire/src/lib.rs 100.00% <ø> (ø)
crates/net/eth-wire/src/types/blocks.rs 95.50% <ø> (ø)
crates/net/network/src/config.rs 0.00% <0.00%> (ø)
crates/net/network/src/error.rs 0.00% <0.00%> (ø)
crates/net/network/src/fetch.rs 0.00% <0.00%> (ø)
crates/net/network/src/manager.rs 0.00% <0.00%> (ø)
crates/net/network/src/message.rs 0.00% <0.00%> (ø)
crates/net/network/src/network.rs 0.00% <0.00%> (ø)
crates/net/network/src/peers.rs 0.00% <0.00%> (ø)
... and 16 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@onbjerg
Copy link
Member

onbjerg commented Nov 3, 2022

wip?

@mattsse
Copy link
Collaborator Author

mattsse commented Nov 3, 2022

currently integrating the p2p stream, then this is a ready mvp

@Rjected Rjected mentioned this pull request Nov 3, 2022
23 tasks
@mattsse mattsse requested a review from Rjected November 4, 2022 11:23
Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool stuff, yeah lets try to merge this and do smaller iterations

Comment on lines +85 to +90
pub struct Capability {
/// Name of the Capability
pub name: SmolStr,
/// The version of the capability
pub version: u64,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be unified with what we have in eth-wire/ CapabilityMessage, maybe good for a follow up

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely. will be first follow up.

Comment on lines +120 to +125
pub enum CapabilityMessage {
/// Eth sub-protocol message.
Eth(EthMessage),
/// Any other capability message.
Other(RawCapabilityMessage),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need an implementation of Stream/Sink which outputs / takes as input this type?

The current implementation is nice because EthStream can be layered on top of a Stream<Item = Result<Bytes>> but having a way to get this typed CapabilityMessage from a P2PStream would be useful as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally deserialization will be handled by the session task, so we don't need to do the work in the main network loop and can instead deal directly with the message variants.

Comment on lines +459 to +471
direction: Direction,
) {
let stream = match direction {
Direction::Incoming => match ECIESStream::incoming(stream, secret_key).await {
Ok(stream) => stream,
Err(error) => {
let _ = events
.send(PendingSessionEvent::EciesAuthError { remote_addr, session_id, error })
.await;
return
}
},
Direction::Outgoing(remote_node_id) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direction is very cool here

Comment on lines +141 to +149
Poll::Ready(Err(_)) => {
trace!(
?id,
target = "net",
"Request canceled, response channel closed."
);
disconnect_sessions.push(*id);
}
Poll::Pending => continue,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should peer sessions return an error when a remote peer sends a Disconnect message? Or should there be an event type / listener for disconnect notifications instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is handled in the session manager, which should listen for the disconnect message from the spawned session.

Comment on lines +85 to +91
/// Propagates Block to peers.
pub(crate) fn announce_block(&mut self, _hash: H256, _block: ()) {
// TODO propagate the newblock messages to all connected peers that haven't seen the block
// yet

todo!()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block gossip is removed in EIP-3675 but other chains that use the devp2p stack may still use this. So we may need to implement this in a configurable way.

Other chains sometimes modify the networking layer in subtle ways, for example BSC's eth/67 is different than ETH's eth/67 (and there are more subprotocols / sync strategies), so we may need to revisit things if we decide to support other chains.

@mattsse mattsse merged commit b7cdfbf into main Nov 7, 2022
@mattsse mattsse deleted the matt/network-scaffolding branch November 7, 2022 08:27
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 C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants