Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 3231454

Browse files
authored
[devp2p discovery]: remove deprecated_echo_hash (#11564)
Removes support for `deprecated_echo_hash` ping/pong in devp2p-discovery. It will not work with nodes prior to `stable 2.0.5` (#9526)
1 parent 2bcc319 commit 3231454

File tree

1 file changed

+16
-40
lines changed

1 file changed

+16
-40
lines changed

util/network-devp2p/src/discovery.rs

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ struct PingRequest {
131131
node: NodeEntry,
132132
// The hash sent in the Ping request
133133
echo_hash: H256,
134-
// The hash Parity used to respond with (until rev 01f825b0e1f1c4c420197b51fc801cbe89284b29)
135-
#[deprecated()]
136-
deprecated_echo_hash: H256,
137134
reason: PingReason
138135
}
139136

@@ -255,23 +252,17 @@ impl Discovery {
255252
}.and_then(|(node_entry, bucket_distance)| {
256253
trace!(target: "discovery", "Adding a new node {:?} into our bucket {}", &node_entry, bucket_distance);
257254

258-
let mut added = HashMap::with_capacity(1);
259-
added.insert(node_entry.id, node_entry.clone());
260-
261-
let node_to_ping = {
262-
let bucket = &mut self.node_buckets[bucket_distance];
263-
bucket.nodes.push_front(BucketEntry::new(node_entry.clone()));
264-
if bucket.nodes.len() > BUCKET_SIZE {
265-
select_bucket_ping(bucket.nodes.iter())
266-
} else {
267-
None
255+
let bucket = &mut self.node_buckets[bucket_distance];
256+
bucket.nodes.push_front(BucketEntry::new(node_entry.clone()));
257+
if bucket.nodes.len() > BUCKET_SIZE {
258+
if let Some(node) = select_bucket_ping(bucket.nodes.iter()) {
259+
self.try_ping(node, PingReason::Default);
268260
}
269-
};
270-
if let Some(node) = node_to_ping {
271-
self.try_ping(node, PingReason::Default);
272-
};
261+
}
273262

274263
if node_entry.endpoint.is_valid_sync_node() {
264+
let mut added = HashMap::with_capacity(1);
265+
added.insert(node_entry.id, node_entry);
275266
Some(TableUpdates { added, removed: HashSet::new() })
276267
} else {
277268
None
@@ -381,14 +372,12 @@ impl Discovery {
381372
self.public_endpoint.to_rlp_list(&mut rlp);
382373
node.endpoint.to_rlp_list(&mut rlp);
383374
append_expiration(&mut rlp);
384-
let old_parity_hash = keccak(rlp.as_raw());
385375
let hash = self.send_packet(PACKET_PING, node.endpoint.udp_address(), rlp.drain())?;
386376

387377
self.in_flight_pings.insert(node.id, PingRequest {
388378
sent_at: Instant::now(),
389379
node: node.clone(),
390380
echo_hash: hash,
391-
deprecated_echo_hash: old_parity_hash,
392381
reason,
393382
});
394383

@@ -569,28 +558,15 @@ impl Discovery {
569558
self.check_timestamp(timestamp)?;
570559

571560
let expected_node = match self.in_flight_pings.entry(node_id) {
572-
Entry::Occupied(entry) => {
573-
let expected_node = {
574-
let request = entry.get();
575-
if request.echo_hash != echo_hash && request.deprecated_echo_hash != echo_hash {
576-
debug!(target: "discovery", "Got unexpected Pong from {:?} ; packet_hash={:#x} ; expected_hash={:#x}", &from, request.echo_hash, echo_hash);
577-
None
578-
} else {
579-
if request.deprecated_echo_hash == echo_hash {
580-
trace!(target: "discovery", "Got Pong from an old open-ethereum version.");
581-
}
582-
Some((request.node.clone(), request.reason))
583-
}
584-
};
585-
586-
if expected_node.is_some() {
587-
entry.remove();
588-
}
589-
expected_node
590-
},
591-
Entry::Vacant(_) => {
561+
Entry::Occupied(entry) if entry.get().echo_hash != echo_hash => {
562+
debug!(target: "discovery", "Got unexpected Pong from {:?} ; packet_hash={:#x} ; expected_hash={:#x}", &from, entry.get().echo_hash, echo_hash);
592563
None
593564
},
565+
Entry::Occupied(entry) => {
566+
let request = entry.remove();
567+
Some((request.node, request.reason))
568+
},
569+
Entry::Vacant(_) => None,
594570
};
595571

596572
if let Some((node, ping_reason)) = expected_node {
@@ -606,7 +582,7 @@ impl Discovery {
606582
debug!(target: "discovery", "Error occured when processing ping from a bucket node: {:?}", &error);
607583
});
608584
},
609-
NodeValidity::UnknownNode | NodeValidity::ExpiredNode(NodeCategory::Observed) | NodeValidity::ValidNode(NodeCategory::Observed)=> {
585+
NodeValidity::UnknownNode | NodeValidity::ExpiredNode(NodeCategory::Observed) | NodeValidity::ValidNode(NodeCategory::Observed) => {
610586
trace!(target: "discovery", "Updating node {:?} in the list of other_observed_nodes", &node);
611587
self.other_observed_nodes.insert(node.id, (node.endpoint, Instant::now()));
612588
},

0 commit comments

Comments
 (0)