Skip to content

Commit

Permalink
Speed up ENR update (#196)
Browse files Browse the repository at this point in the history
* PING immediately if the connection direction is outgoing

* Add a comment

* suggested alternative that reduces cloning

* actually remove the extra clone

* only ping peers that manage to make it into the routing table

to get the added security measures, like bucket and table limits

* Fix borrow of moved value

* Fix E0502: self is already borrowed as immutable

https://github.com/sigp/discv5/actions/runs/5394916671/jobs/9796752728?pr=196#step:5:443

---------

Co-authored-by: Diva M <[email protected]>
  • Loading branch information
ackintosh and divagant-martian authored Jun 27, 2023
1 parent 94e09e1 commit a9ded04
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,11 +1269,23 @@ impl Service {
state: ConnectionState::Connected,
direction,
};
match self.kbuckets.write().insert_or_update(&key, enr, status) {

let insert_result =
self.kbuckets
.write()
.insert_or_update(&key, enr.clone(), status);
match insert_result {
InsertResult::Inserted => {
// We added this peer to the table
debug!("New connected node added to routing table: {}", node_id);
self.peers_to_ping.insert(node_id);

// PING immediately if the direction is outgoing. This allows us to receive
// a PONG without waiting for the ping_interval, making ENR updates faster.
if direction == ConnectionDirection::Outgoing {
self.send_ping(enr, None);
}

let event = Discv5Event::NodeInserted {
node_id,
replaced: None,
Expand Down

0 comments on commit a9ded04

Please sign in to comment.