3434//! search for the block and subsequently search for parents if needed.
3535
3636use super :: backfill_sync:: { BackFillSync , ProcessResult , SyncStart } ;
37+ use super :: block_lookups:: common:: LookupType ;
3738use super :: block_lookups:: BlockLookups ;
3839use super :: network_context:: { BlockOrBlob , SyncNetworkContext } ;
3940use super :: peer_sync_info:: { remote_sync_type, PeerSyncType } ;
@@ -80,6 +81,7 @@ pub type Id = u32;
8081pub struct SingleLookupReqId {
8182 pub id : Id ,
8283 pub req_counter : Id ,
84+ pub lookup_type : LookupType ,
8385}
8486
8587/// Id of rpc requests sent by sync to the network.
@@ -89,12 +91,6 @@ pub enum RequestId {
8991 SingleBlock { id : SingleLookupReqId } ,
9092 /// Request searching for a set of blobs given a hash.
9193 SingleBlob { id : SingleLookupReqId } ,
92- /// Request searching for a block's parent. The id is the chain, share with the corresponding
93- /// blob id.
94- ParentLookup { id : SingleLookupReqId } ,
95- /// Request searching for a block's parent blobs. The id is the chain, shared with the corresponding
96- /// block id.
97- ParentLookupBlob { id : SingleLookupReqId } ,
9894 /// Request was from the backfill sync algorithm.
9995 BackFillBlocks { id : Id } ,
10096 /// Backfill request that is composed by both a block range request and a blob range request.
@@ -331,42 +327,42 @@ impl<T: BeaconChainTypes> SyncManager<T> {
331327 fn inject_error ( & mut self , peer_id : PeerId , request_id : RequestId , error : RPCError ) {
332328 trace ! ( self . log, "Sync manager received a failed RPC" ) ;
333329 match request_id {
334- RequestId :: SingleBlock { id } => {
335- self . block_lookups
330+ RequestId :: SingleBlock { id } => match id. lookup_type {
331+ LookupType :: Current => self
332+ . block_lookups
336333 . single_block_lookup_failed :: < BlockRequestState < Current > > (
337334 id,
338335 & peer_id,
339336 & self . network ,
340337 error,
341- ) ;
342- }
343- RequestId :: SingleBlob { id } => {
344- self . block_lookups
345- . single_block_lookup_failed :: < BlobRequestState < Current , T :: EthSpec > > (
338+ ) ,
339+ LookupType :: Parent => self
340+ . block_lookups
341+ . parent_lookup_failed :: < BlockRequestState < Parent > > (
346342 id,
347343 & peer_id,
348344 & self . network ,
349345 error,
350- ) ;
351- }
352- RequestId :: ParentLookup { id } => {
353- self . block_lookups
354- . parent_lookup_failed :: < BlockRequestState < Parent > > (
346+ ) ,
347+ } ,
348+ RequestId :: SingleBlob { id } => match id. lookup_type {
349+ LookupType :: Current => self
350+ . block_lookups
351+ . single_block_lookup_failed :: < BlobRequestState < Current , T :: EthSpec > > (
355352 id,
356- peer_id,
353+ & peer_id,
357354 & self . network ,
358355 error,
359- ) ;
360- }
361- RequestId :: ParentLookupBlob { id } => {
362- self . block_lookups
356+ ) ,
357+ LookupType :: Parent => self
358+ . block_lookups
363359 . parent_lookup_failed :: < BlobRequestState < Parent , T :: EthSpec > > (
364360 id,
365- peer_id,
361+ & peer_id,
366362 & self . network ,
367363 error,
368- ) ;
369- }
364+ ) ,
365+ } ,
370366 RequestId :: BackFillBlocks { id } => {
371367 if let Some ( batch_id) = self
372368 . network
@@ -882,30 +878,29 @@ impl<T: BeaconChainTypes> SyncManager<T> {
882878 seen_timestamp : Duration ,
883879 ) {
884880 match request_id {
885- RequestId :: SingleBlock { id } => self
886- . block_lookups
887- . single_lookup_response :: < BlockRequestState < Current > > (
888- id,
889- peer_id,
890- block,
891- seen_timestamp,
892- & self . network ,
893- ) ,
881+ RequestId :: SingleBlock { id } => match id. lookup_type {
882+ LookupType :: Current => self
883+ . block_lookups
884+ . single_lookup_response :: < BlockRequestState < Current > > (
885+ id,
886+ peer_id,
887+ block,
888+ seen_timestamp,
889+ & self . network ,
890+ ) ,
891+ LookupType :: Parent => self
892+ . block_lookups
893+ . parent_lookup_response :: < BlockRequestState < Parent > > (
894+ id,
895+ peer_id,
896+ block,
897+ seen_timestamp,
898+ & self . network ,
899+ ) ,
900+ } ,
894901 RequestId :: SingleBlob { .. } => {
895902 crit ! ( self . log, "Block received during blob request" ; "peer_id" => %peer_id ) ;
896903 }
897- RequestId :: ParentLookup { id } => self
898- . block_lookups
899- . parent_lookup_response :: < BlockRequestState < Parent > > (
900- id,
901- peer_id,
902- block,
903- seen_timestamp,
904- & self . network ,
905- ) ,
906- RequestId :: ParentLookupBlob { id : _ } => {
907- crit ! ( self . log, "Block received during parent blob request" ; "peer_id" => %peer_id ) ;
908- }
909904 RequestId :: BackFillBlocks { id } => {
910905 let is_stream_terminator = block. is_none ( ) ;
911906 if let Some ( batch_id) = self
@@ -966,28 +961,26 @@ impl<T: BeaconChainTypes> SyncManager<T> {
966961 RequestId :: SingleBlock { .. } => {
967962 crit ! ( self . log, "Single blob received during block request" ; "peer_id" => %peer_id ) ;
968963 }
969- RequestId :: SingleBlob { id } => self
970- . block_lookups
971- . single_lookup_response :: < BlobRequestState < Current , T :: EthSpec > > (
972- id,
973- peer_id,
974- blob,
975- seen_timestamp,
976- & self . network ,
977- ) ,
978-
979- RequestId :: ParentLookup { id : _ } => {
980- crit ! ( self . log, "Single blob received during parent block request" ; "peer_id" => %peer_id ) ;
981- }
982- RequestId :: ParentLookupBlob { id } => self
983- . block_lookups
984- . parent_lookup_response :: < BlobRequestState < Parent , T :: EthSpec > > (
985- id,
986- peer_id,
987- blob,
988- seen_timestamp,
989- & self . network ,
990- ) ,
964+ RequestId :: SingleBlob { id } => match id. lookup_type {
965+ LookupType :: Current => self
966+ . block_lookups
967+ . single_lookup_response :: < BlobRequestState < Current , T :: EthSpec > > (
968+ id,
969+ peer_id,
970+ blob,
971+ seen_timestamp,
972+ & self . network ,
973+ ) ,
974+ LookupType :: Parent => self
975+ . block_lookups
976+ . parent_lookup_response :: < BlobRequestState < Parent , T :: EthSpec > > (
977+ id,
978+ peer_id,
979+ blob,
980+ seen_timestamp,
981+ & self . network ,
982+ ) ,
983+ } ,
991984 RequestId :: BackFillBlocks { id : _ } => {
992985 crit ! ( self . log, "Blob received during backfill block request" ; "peer_id" => %peer_id ) ;
993986 }
0 commit comments