[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)
This commit is contained in:
parent
2bcc31928e
commit
3231454bb1
@ -131,9 +131,6 @@ struct PingRequest {
|
|||||||
node: NodeEntry,
|
node: NodeEntry,
|
||||||
// The hash sent in the Ping request
|
// The hash sent in the Ping request
|
||||||
echo_hash: H256,
|
echo_hash: H256,
|
||||||
// The hash Parity used to respond with (until rev 01f825b0e1f1c4c420197b51fc801cbe89284b29)
|
|
||||||
#[deprecated()]
|
|
||||||
deprecated_echo_hash: H256,
|
|
||||||
reason: PingReason
|
reason: PingReason
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,23 +252,17 @@ impl Discovery {
|
|||||||
}.and_then(|(node_entry, bucket_distance)| {
|
}.and_then(|(node_entry, bucket_distance)| {
|
||||||
trace!(target: "discovery", "Adding a new node {:?} into our bucket {}", &node_entry, bucket_distance);
|
trace!(target: "discovery", "Adding a new node {:?} into our bucket {}", &node_entry, bucket_distance);
|
||||||
|
|
||||||
let mut added = HashMap::with_capacity(1);
|
|
||||||
added.insert(node_entry.id, node_entry.clone());
|
|
||||||
|
|
||||||
let node_to_ping = {
|
|
||||||
let bucket = &mut self.node_buckets[bucket_distance];
|
let bucket = &mut self.node_buckets[bucket_distance];
|
||||||
bucket.nodes.push_front(BucketEntry::new(node_entry.clone()));
|
bucket.nodes.push_front(BucketEntry::new(node_entry.clone()));
|
||||||
if bucket.nodes.len() > BUCKET_SIZE {
|
if bucket.nodes.len() > BUCKET_SIZE {
|
||||||
select_bucket_ping(bucket.nodes.iter())
|
if let Some(node) = select_bucket_ping(bucket.nodes.iter()) {
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if let Some(node) = node_to_ping {
|
|
||||||
self.try_ping(node, PingReason::Default);
|
self.try_ping(node, PingReason::Default);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if node_entry.endpoint.is_valid_sync_node() {
|
if node_entry.endpoint.is_valid_sync_node() {
|
||||||
|
let mut added = HashMap::with_capacity(1);
|
||||||
|
added.insert(node_entry.id, node_entry);
|
||||||
Some(TableUpdates { added, removed: HashSet::new() })
|
Some(TableUpdates { added, removed: HashSet::new() })
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -381,14 +372,12 @@ impl Discovery {
|
|||||||
self.public_endpoint.to_rlp_list(&mut rlp);
|
self.public_endpoint.to_rlp_list(&mut rlp);
|
||||||
node.endpoint.to_rlp_list(&mut rlp);
|
node.endpoint.to_rlp_list(&mut rlp);
|
||||||
append_expiration(&mut rlp);
|
append_expiration(&mut rlp);
|
||||||
let old_parity_hash = keccak(rlp.as_raw());
|
|
||||||
let hash = self.send_packet(PACKET_PING, node.endpoint.udp_address(), rlp.drain())?;
|
let hash = self.send_packet(PACKET_PING, node.endpoint.udp_address(), rlp.drain())?;
|
||||||
|
|
||||||
self.in_flight_pings.insert(node.id, PingRequest {
|
self.in_flight_pings.insert(node.id, PingRequest {
|
||||||
sent_at: Instant::now(),
|
sent_at: Instant::now(),
|
||||||
node: node.clone(),
|
node: node.clone(),
|
||||||
echo_hash: hash,
|
echo_hash: hash,
|
||||||
deprecated_echo_hash: old_parity_hash,
|
|
||||||
reason,
|
reason,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -569,28 +558,15 @@ impl Discovery {
|
|||||||
self.check_timestamp(timestamp)?;
|
self.check_timestamp(timestamp)?;
|
||||||
|
|
||||||
let expected_node = match self.in_flight_pings.entry(node_id) {
|
let expected_node = match self.in_flight_pings.entry(node_id) {
|
||||||
|
Entry::Occupied(entry) if entry.get().echo_hash != echo_hash => {
|
||||||
|
debug!(target: "discovery", "Got unexpected Pong from {:?} ; packet_hash={:#x} ; expected_hash={:#x}", &from, entry.get().echo_hash, echo_hash);
|
||||||
|
None
|
||||||
|
},
|
||||||
Entry::Occupied(entry) => {
|
Entry::Occupied(entry) => {
|
||||||
let expected_node = {
|
let request = entry.remove();
|
||||||
let request = entry.get();
|
Some((request.node, request.reason))
|
||||||
if request.echo_hash != echo_hash && request.deprecated_echo_hash != echo_hash {
|
|
||||||
debug!(target: "discovery", "Got unexpected Pong from {:?} ; packet_hash={:#x} ; expected_hash={:#x}", &from, request.echo_hash, echo_hash);
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
if request.deprecated_echo_hash == echo_hash {
|
|
||||||
trace!(target: "discovery", "Got Pong from an old open-ethereum version.");
|
|
||||||
}
|
|
||||||
Some((request.node.clone(), request.reason))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if expected_node.is_some() {
|
|
||||||
entry.remove();
|
|
||||||
}
|
|
||||||
expected_node
|
|
||||||
},
|
|
||||||
Entry::Vacant(_) => {
|
|
||||||
None
|
|
||||||
},
|
},
|
||||||
|
Entry::Vacant(_) => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some((node, ping_reason)) = expected_node {
|
if let Some((node, ping_reason)) = expected_node {
|
||||||
|
Loading…
Reference in New Issue
Block a user