Skip to content

Commit a9ded04

Browse files
Speed up ENR update (#196)
* 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]>
1 parent 94e09e1 commit a9ded04

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/service.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,11 +1269,23 @@ impl Service {
12691269
state: ConnectionState::Connected,
12701270
direction,
12711271
};
1272-
match self.kbuckets.write().insert_or_update(&key, enr, status) {
1272+
1273+
let insert_result =
1274+
self.kbuckets
1275+
.write()
1276+
.insert_or_update(&key, enr.clone(), status);
1277+
match insert_result {
12731278
InsertResult::Inserted => {
12741279
// We added this peer to the table
12751280
debug!("New connected node added to routing table: {}", node_id);
12761281
self.peers_to_ping.insert(node_id);
1282+
1283+
// PING immediately if the direction is outgoing. This allows us to receive
1284+
// a PONG without waiting for the ping_interval, making ENR updates faster.
1285+
if direction == ConnectionDirection::Outgoing {
1286+
self.send_ping(enr, None);
1287+
}
1288+
12771289
let event = Discv5Event::NodeInserted {
12781290
node_id,
12791291
replaced: None,

0 commit comments

Comments
 (0)