@@ -131,9 +131,6 @@ struct PingRequest {
131
131
node : NodeEntry ,
132
132
// The hash sent in the Ping request
133
133
echo_hash : H256 ,
134
- // The hash Parity used to respond with (until rev 01f825b0e1f1c4c420197b51fc801cbe89284b29)
135
- #[ deprecated( ) ]
136
- deprecated_echo_hash : H256 ,
137
134
reason : PingReason
138
135
}
139
136
@@ -255,23 +252,17 @@ impl Discovery {
255
252
} . and_then ( |( node_entry, bucket_distance) | {
256
253
trace ! ( target: "discovery" , "Adding a new node {:?} into our bucket {}" , & node_entry, bucket_distance) ;
257
254
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 ) ;
268
260
}
269
- } ;
270
- if let Some ( node) = node_to_ping {
271
- self . try_ping ( node, PingReason :: Default ) ;
272
- } ;
261
+ }
273
262
274
263
if node_entry. endpoint . is_valid_sync_node ( ) {
264
+ let mut added = HashMap :: with_capacity ( 1 ) ;
265
+ added. insert ( node_entry. id , node_entry) ;
275
266
Some ( TableUpdates { added, removed : HashSet :: new ( ) } )
276
267
} else {
277
268
None
@@ -381,14 +372,12 @@ impl Discovery {
381
372
self . public_endpoint . to_rlp_list ( & mut rlp) ;
382
373
node. endpoint . to_rlp_list ( & mut rlp) ;
383
374
append_expiration ( & mut rlp) ;
384
- let old_parity_hash = keccak ( rlp. as_raw ( ) ) ;
385
375
let hash = self . send_packet ( PACKET_PING , node. endpoint . udp_address ( ) , rlp. drain ( ) ) ?;
386
376
387
377
self . in_flight_pings . insert ( node. id , PingRequest {
388
378
sent_at : Instant :: now ( ) ,
389
379
node : node. clone ( ) ,
390
380
echo_hash : hash,
391
- deprecated_echo_hash : old_parity_hash,
392
381
reason,
393
382
} ) ;
394
383
@@ -569,28 +558,15 @@ impl Discovery {
569
558
self . check_timestamp ( timestamp) ?;
570
559
571
560
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) ;
592
563
None
593
564
} ,
565
+ Entry :: Occupied ( entry) => {
566
+ let request = entry. remove ( ) ;
567
+ Some ( ( request. node , request. reason ) )
568
+ } ,
569
+ Entry :: Vacant ( _) => None ,
594
570
} ;
595
571
596
572
if let Some ( ( node, ping_reason) ) = expected_node {
@@ -606,7 +582,7 @@ impl Discovery {
606
582
debug ! ( target: "discovery" , "Error occured when processing ping from a bucket node: {:?}" , & error) ;
607
583
} ) ;
608
584
} ,
609
- NodeValidity :: UnknownNode | NodeValidity :: ExpiredNode ( NodeCategory :: Observed ) | NodeValidity :: ValidNode ( NodeCategory :: Observed ) => {
585
+ NodeValidity :: UnknownNode | NodeValidity :: ExpiredNode ( NodeCategory :: Observed ) | NodeValidity :: ValidNode ( NodeCategory :: Observed ) => {
610
586
trace ! ( target: "discovery" , "Updating node {:?} in the list of other_observed_nodes" , & node) ;
611
587
self . other_observed_nodes . insert ( node. id , ( node. endpoint , Instant :: now ( ) ) ) ;
612
588
} ,
0 commit comments