Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Perf

### 2025-10-27

- Reusing FindNode message per lookup loop instead of randomizing the key for each message. [#5047](https://github.com/lambdaclass/ethrex/pull/5047)

### 2025-10-21

- Instead of lazy computation of blocklist, do greedy computation of allowlist and store the result, fetch it with the DB. [#4961](https://github.com/lambdaclass/ethrex/pull/4961)
Expand Down
26 changes: 11 additions & 15 deletions crates/networking/p2p/discv4/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,18 @@ impl DiscoveryServer {
}

async fn lookup(&mut self) -> Result<(), DiscoveryServerError> {
// Sending the same FindNode message to all contacts to optimize message creation and encoding
let expiration: u64 = get_msg_expiration_from_seconds(EXPIRATION_SECONDS);
let random_priv_key = SecretKey::new(&mut OsRng);
let random_pub_key = public_key_from_signing_key(&random_priv_key);
let msg = Message::FindNode(FindNodeMessage::new(random_pub_key, expiration));
let mut buf = BytesMut::new();
msg.encode_with_header(&mut buf, &self.signer);

for contact in self.peer_table.get_contacts_for_lookup().await? {
if self.send_find_node(&contact.node).await.is_err() {
if self.udp_socket.send_to(&buf, &contact.node.udp_addr()).await.inspect_err(
|e| error!(sending = ?msg, addr = ?&contact.node.udp_addr(), err=?e, "Error sending message"),
).is_err() {
self.peer_table
.set_disposable(&contact.node.node_id())
.await?;
Expand Down Expand Up @@ -309,20 +319,6 @@ impl DiscoveryServer {
Ok(())
}

async fn send_find_node(&self, node: &Node) -> Result<(), DiscoveryServerError> {
let expiration: u64 = get_msg_expiration_from_seconds(EXPIRATION_SECONDS);

let random_priv_key = SecretKey::new(&mut OsRng);
let random_pub_key = public_key_from_signing_key(&random_priv_key);

let msg = Message::FindNode(FindNodeMessage::new(random_pub_key, expiration));
self.send(msg, node.udp_addr()).await?;

debug!(sent = "FindNode", to = %format!("{:#x}", node.public_key));

Ok(())
}

async fn send_neighbors(
&self,
neighbors: Vec<Node>,
Expand Down