@@ -50,7 +50,7 @@ use codec::{Decode, Encode};
5050use futures:: sync:: oneshot;
5151use polkadot_primitives:: { Block , SessionKey , Hash , Header } ;
5252use polkadot_primitives:: parachain:: { Id as ParaId , CollatorId , BlockData , CandidateReceipt , Collation } ;
53- use substrate_network:: { NodeIndex , RequestId , Context , Severity } ;
53+ use substrate_network:: { PeerId , RequestId , Context , Severity } ;
5454use substrate_network:: { message, generic_message} ;
5555use substrate_network:: specialization:: NetworkSpecialization as Specialization ;
5656use substrate_network:: StatusMessage as GenericFullStatus ;
@@ -150,21 +150,21 @@ pub enum Message {
150150 Collation ( Hash , Collation ) ,
151151}
152152
153- fn send_polkadot_message ( ctx : & mut Context < Block > , to : NodeIndex , message : Message ) {
153+ fn send_polkadot_message ( ctx : & mut Context < Block > , to : PeerId , message : Message ) {
154154 trace ! ( target: "p_net" , "Sending polkadot message to {}: {:?}" , to, message) ;
155155 let encoded = message. encode ( ) ;
156156 ctx. send_message ( to, generic_message:: Message :: ChainSpecific ( encoded) )
157157}
158158
159159/// Polkadot protocol attachment for substrate.
160160pub struct PolkadotProtocol {
161- peers : HashMap < NodeIndex , PeerInfo > ,
161+ peers : HashMap < PeerId , PeerInfo > ,
162162 collating_for : Option < ( CollatorId , ParaId ) > ,
163163 collators : CollatorPool ,
164- validators : HashMap < SessionKey , NodeIndex > ,
164+ validators : HashMap < SessionKey , PeerId > ,
165165 local_collations : LocalCollations < Collation > ,
166166 live_consensus : LiveConsensusInstances ,
167- in_flight : HashMap < ( RequestId , NodeIndex ) , BlockDataRequest > ,
167+ in_flight : HashMap < ( RequestId , PeerId ) , BlockDataRequest > ,
168168 pending : Vec < BlockDataRequest > ,
169169 extrinsic_store : Option < :: av_store:: Store > ,
170170 next_req_id : u64 ,
@@ -216,7 +216,7 @@ impl PolkadotProtocol {
216216 {
217217 peer_data. collator_state . send_key ( new_local. clone ( ) , |msg| send_polkadot_message (
218218 ctx,
219- * id ,
219+ id . clone ( ) ,
220220 msg
221221 ) ) ;
222222 }
@@ -245,7 +245,7 @@ impl PolkadotProtocol {
245245 }
246246 Err ( Some ( known_keys) ) => {
247247 let next_peer = known_keys. iter ( )
248- . filter_map ( |x| validator_keys. get ( x) . map ( |id| ( x. clone ( ) , * id ) ) )
248+ . filter_map ( |x| validator_keys. get ( x) . map ( |id| ( x. clone ( ) , id . clone ( ) ) ) )
249249 . find ( |& ( ref key, _) | pending. attempted_peers . insert ( key. clone ( ) ) )
250250 . map ( |( _, id) | id) ;
251251
@@ -256,7 +256,7 @@ impl PolkadotProtocol {
256256
257257 send_polkadot_message (
258258 ctx,
259- who,
259+ who. clone ( ) ,
260260 Message :: RequestBlockData ( req_id, parent, c_hash)
261261 ) ;
262262
@@ -278,7 +278,7 @@ impl PolkadotProtocol {
278278 self . pending = new_pending;
279279 }
280280
281- fn on_polkadot_message ( & mut self , ctx : & mut Context < Block > , who : NodeIndex , msg : Message ) {
281+ fn on_polkadot_message ( & mut self , ctx : & mut Context < Block > , who : PeerId , msg : Message ) {
282282 trace ! ( target: "p_net" , "Polkadot message from {}: {:?}" , who, msg) ;
283283 match msg {
284284 Message :: SessionKey ( key) => self . on_session_key ( ctx, who, key) ,
@@ -301,7 +301,7 @@ impl PolkadotProtocol {
301301 }
302302 }
303303
304- fn on_session_key ( & mut self , ctx : & mut Context < Block > , who : NodeIndex , key : SessionKey ) {
304+ fn on_session_key ( & mut self , ctx : & mut Context < Block > , who : PeerId , key : SessionKey ) {
305305 {
306306 let info = match self . peers . get_mut ( & who) {
307307 Some ( peer) => peer,
@@ -331,7 +331,7 @@ impl PolkadotProtocol {
331331 for ( relay_parent, collation) in new_collations {
332332 send_polkadot_message (
333333 ctx,
334- who,
334+ who. clone ( ) ,
335335 Message :: Collation ( relay_parent, collation) ,
336336 )
337337 }
@@ -342,8 +342,8 @@ impl PolkadotProtocol {
342342 self . dispatch_pending_requests ( ctx) ;
343343 }
344344
345- fn on_block_data ( & mut self , ctx : & mut Context < Block > , who : NodeIndex , req_id : RequestId , data : Option < BlockData > ) {
346- match self . in_flight . remove ( & ( req_id, who) ) {
345+ fn on_block_data ( & mut self , ctx : & mut Context < Block > , who : PeerId , req_id : RequestId , data : Option < BlockData > ) {
346+ match self . in_flight . remove ( & ( req_id, who. clone ( ) ) ) {
347347 Some ( req) => {
348348 if let Some ( data) = data {
349349 if data. hash ( ) == req. block_data_hash {
@@ -360,7 +360,7 @@ impl PolkadotProtocol {
360360 }
361361
362362 // when a validator sends us (a collator) a new role.
363- fn on_new_role ( & mut self , ctx : & mut Context < Block > , who : NodeIndex , role : Role ) {
363+ fn on_new_role ( & mut self , ctx : & mut Context < Block > , who : PeerId , role : Role ) {
364364 let info = match self . peers . get_mut ( & who) {
365365 Some ( peer) => peer,
366366 None => {
@@ -388,7 +388,7 @@ impl PolkadotProtocol {
388388 debug ! ( target: "p_net" , "Broadcasting collation on relay parent {:?}" , relay_parent) ;
389389 send_polkadot_message (
390390 ctx,
391- who,
391+ who. clone ( ) ,
392392 Message :: Collation ( relay_parent, collation) ,
393393 )
394394 }
@@ -401,7 +401,7 @@ impl Specialization<Block> for PolkadotProtocol {
401401 Status { collating_for : self . collating_for . clone ( ) } . encode ( )
402402 }
403403
404- fn on_connect ( & mut self , ctx : & mut Context < Block > , who : NodeIndex , status : FullStatus ) {
404+ fn on_connect ( & mut self , ctx : & mut Context < Block > , who : PeerId , status : FullStatus ) {
405405 let local_status = match Status :: decode ( & mut & status. chain_status [ ..] ) {
406406 Some ( status) => status,
407407 None => {
@@ -428,7 +428,7 @@ impl Specialization<Block> for PolkadotProtocol {
428428
429429 peer_info. collator_state . set_role ( collator_role, |msg| send_polkadot_message (
430430 ctx,
431- who,
431+ who. clone ( ) ,
432432 msg,
433433 ) ) ;
434434 }
@@ -438,7 +438,7 @@ impl Specialization<Block> for PolkadotProtocol {
438438 for local_session_key in self . live_consensus . recent_keys ( ) {
439439 peer_info. collator_state . send_key ( local_session_key. clone ( ) , |msg| send_polkadot_message (
440440 ctx,
441- who,
441+ who. clone ( ) ,
442442 msg,
443443 ) ) ;
444444 }
@@ -448,7 +448,7 @@ impl Specialization<Block> for PolkadotProtocol {
448448 self . dispatch_pending_requests ( ctx) ;
449449 }
450450
451- fn on_disconnect ( & mut self , ctx : & mut Context < Block > , who : NodeIndex ) {
451+ fn on_disconnect ( & mut self , ctx : & mut Context < Block > , who : PeerId ) {
452452 if let Some ( info) = self . peers . remove ( & who) {
453453 if let Some ( ( acc_id, _) ) = info. collating_for {
454454 let new_primary = self . collators . on_disconnect ( acc_id)
@@ -457,7 +457,7 @@ impl Specialization<Block> for PolkadotProtocol {
457457 if let Some ( ( new_primary, primary_info) ) = new_primary {
458458 primary_info. collator_state . set_role ( Role :: Primary , |msg| send_polkadot_message (
459459 ctx,
460- new_primary,
460+ new_primary. clone ( ) ,
461461 msg,
462462 ) ) ;
463463 }
@@ -490,7 +490,7 @@ impl Specialization<Block> for PolkadotProtocol {
490490 }
491491 }
492492
493- fn on_message ( & mut self , ctx : & mut Context < Block > , who : NodeIndex , message : & mut Option < message:: Message < Block > > ) {
493+ fn on_message ( & mut self , ctx : & mut Context < Block > , who : PeerId , message : & mut Option < message:: Message < Block > > ) {
494494 match message. take ( ) {
495495 Some ( generic_message:: Message :: ChainSpecific ( raw) ) => {
496496 match Message :: decode ( & mut raw. as_slice ( ) ) {
@@ -520,7 +520,7 @@ impl Specialization<Block> for PolkadotProtocol {
520520 Action :: NewRole ( account_id, role) => if let Some ( ( collator, info) ) = self . collator_peer ( account_id) {
521521 info. collator_state . set_role ( role, |msg| send_polkadot_message (
522522 ctx,
523- collator,
523+ collator. clone ( ) ,
524524 msg,
525525 ) )
526526 } ,
@@ -536,7 +536,7 @@ impl Specialization<Block> for PolkadotProtocol {
536536
537537impl PolkadotProtocol {
538538 // we received a collation from a peer
539- fn on_collation ( & mut self , ctx : & mut Context < Block > , from : NodeIndex , relay_parent : Hash , collation : Collation ) {
539+ fn on_collation ( & mut self , ctx : & mut Context < Block > , from : PeerId , relay_parent : Hash , collation : Collation ) {
540540 let collation_para = collation. receipt . parachain_index ;
541541 let collated_acc = collation. receipt . collator . clone ( ) ;
542542
@@ -565,7 +565,7 @@ impl PolkadotProtocol {
565565 }
566566
567567 // get connected peer with given account ID for collation.
568- fn collator_peer ( & mut self , account_id : CollatorId ) -> Option < ( NodeIndex , & mut PeerInfo ) > {
568+ fn collator_peer ( & mut self , account_id : CollatorId ) -> Option < ( PeerId , & mut PeerInfo ) > {
569569 let check_info = |info : & PeerInfo | info
570570 . collating_for
571571 . as_ref ( )
@@ -574,7 +574,7 @@ impl PolkadotProtocol {
574574 self . peers
575575 . iter_mut ( )
576576 . filter ( |& ( _, ref info) | check_info ( & * * info) )
577- . map ( |( who, info) | ( * who, info) )
577+ . map ( |( who, info) | ( who. clone ( ) , info) )
578578 . next ( )
579579 }
580580
@@ -604,7 +604,7 @@ impl PolkadotProtocol {
604604 debug ! ( target: "p_net" , "Sending local collation to {:?}" , primary) ;
605605 send_polkadot_message (
606606 ctx,
607- * who,
607+ who. clone ( ) ,
608608 Message :: Collation ( relay_parent, cloned_collation) ,
609609 )
610610 } ,
0 commit comments