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

discv5 support #5576

Closed
wants to merge 17 commits into from
Closed

discv5 support #5576

wants to merge 17 commits into from

Conversation

supernovahs
Copy link
Contributor

#1383

TODO
Add relevant traits in https://github.com/sigp/discv5 through a PR

@mattsse
Copy link
Collaborator

mattsse commented Nov 26, 2023

Add relevant traits in https://github.com/sigp/discv5 through a PR

this should not be required, everything we need on top of discv5 should go into the reth-discv5 crate

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

okay after looking at an example:

https://github.com/sigp/discv5/blob/aa12e384c52cc706a570b24260fef09f41c0181b/examples/find_nodes.rs#L159

I think all of this should be easier than expected, we perhaps don't even need the additional crate since the start function spawns the services.

what we should do here is

  1. Configure discv5
  2. call start
  3. get an event stream
  4. Store Arc<Discv5> internally as field and the eventstream as field

crates/net/network/src/discovery.rs Outdated Show resolved Hide resolved
@supernovahs
Copy link
Contributor Author

@rkrasiuk let me know what additional changes need to be done.
Thanks

@supernovahs supernovahs marked this pull request as ready for review December 5, 2023 10:07
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

great!

what's missing now is polling the discv5 event stream in the poll function

crates/net/network/src/discovery.rs Outdated Show resolved Hide resolved
@@ -31,7 +32,7 @@ reth-rpc-types.workspace = true
reth-tokio-util.workspace = true

alloy-rlp.workspace = true

k256 = "0.13.2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

crates/net/discv5/src/lib.rs Show resolved Hide resolved
@rkrasiuk rkrasiuk added C-enhancement New feature or request A-discv5 Related to discv5 discovery labels Dec 5, 2023
crates/net/discv5/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 66 to 67
// Use a placeholder for `discv5` since it doesn't implement Debug
.field("discv5", &format_args!("<Discv5>"))
Copy link
Member

Choose a reason for hiding this comment

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

let's make our own wrapper around discv5 that implements Debug and export that from the crate? @mattsse thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sg!

then we can keep reth-discv5 and have that type there @supernovahs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool

crates/net/discv5/src/lib.rs Show resolved Hide resolved
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

pretty close

crates/net/network/src/discovery.rs Outdated Show resolved Hide resolved
Comment on lines 235 to 237
Event::Discovered(enr) => {}
Event::EnrAdded { enr, replaced } => {}
Event::NodeInserted { node_id, replaced } => {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

here we need to handle the discovered entries

see

fn on_discv4_update(&mut self, update: DiscoveryUpdate) {

crates/net/discv5/src/lib.rs Outdated Show resolved Hide resolved
crates/net/discv5/src/lib.rs Outdated Show resolved Hide resolved
crates/net/discv5/src/lib.rs Outdated Show resolved Hide resolved
let discv5 = Discv5Handle::convert_to_discv5(discv5);
let discv5_guard = discv5.lock();
let mut local_enr = discv5_guard.local_enr();
// local_enr.set_ip(socket_address.ip(),); #5576 figure out how to get signing
Copy link
Contributor Author

Choose a reason for hiding this comment

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

trying to figure out how to get the signing key to update the ip

@supernovahs
Copy link
Contributor Author

supernovahs commented Dec 13, 2023

Some errors need to be handled apart from open comments.
Also, I am reviewing the implementation again to check for any bugs
And the failing test too

@supernovahs
Copy link
Contributor Author

@mattsse any inputs on how to fix the test error. It occurred after using parking lot mutex .
I tried debugging it.
thanks

@mattsse mattsse requested a review from emhane January 5, 2024 16:22
// Wrapper struct for Discv5
#[derive(Clone)]
pub struct Discv5Handle {
inner: Arc<Mutex<Discv5>>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we need a mutex here?

self.inner.clone()
}

pub async fn start_service(&self) -> Result<(), Discv5Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can this not call start directly on the wrapped discv5?

crates/net/network/src/discovery.rs Outdated Show resolved Hide resolved
Comment on lines 276 to 284
if let Some(discv5) = &self.discv5 {
let discv5 = Discv5Handle::convert_to_discv5(discv5);
let discv5_guard = discv5.lock();
let node_id = talk_request.node_id();
let enr = discv5_guard.find_enr(&node_id);
let protocol = talk_request.protocol();
let request = talk_request.body();
let _ =
discv5_guard.talk_req(enr.unwrap(), protocol.to_vec(), request.to_vec());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need this

@gakonst
Copy link
Member

gakonst commented Jan 9, 2024

@supernovahs anything else you'd like to add? else @mattsse bump

@supernovahs
Copy link
Contributor Author

closing since #6151 is now the main PR for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-discv5 Related to discv5 discovery C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants