@@ -43,7 +43,7 @@ use polkadot_node_subsystem::{
4343 overseer, RecoveryError ,
4444} ;
4545use polkadot_primitives:: { AuthorityDiscoveryId , BlakeTwo256 , ChunkIndex , HashT , ValidatorIndex } ;
46- use sc_network:: { IfDisconnected , OutboundFailure , RequestFailure } ;
46+ use sc_network:: { IfDisconnected , OutboundFailure , ProtocolName , RequestFailure } ;
4747use std:: {
4848 collections:: { BTreeMap , HashMap , VecDeque } ,
4949 time:: Duration ,
@@ -79,7 +79,7 @@ pub const REGULAR_CHUNKS_REQ_RETRY_LIMIT: u32 = 5;
7979type OngoingRequests = FuturesUndead < (
8080 AuthorityDiscoveryId ,
8181 ValidatorIndex ,
82- Result < Option < ErasureChunk > , RequestError > ,
82+ Result < ( Option < ErasureChunk > , ProtocolName ) , RequestError > ,
8383) > ;
8484
8585const fn is_unavailable (
@@ -384,15 +384,14 @@ impl State {
384384 let res = match res. await {
385385 Ok ( ( bytes, protocol) ) =>
386386 if v2_protocol_name == protocol {
387- params. metrics . on_chunk_response_v2 ( ) ;
388387 match req_res:: v2:: ChunkFetchingResponse :: decode ( & mut & bytes[ ..] ) {
389388 Ok ( req_res:: v2:: ChunkFetchingResponse :: Chunk ( chunk) ) =>
390- Ok ( Some ( chunk. into ( ) ) ) ,
391- Ok ( req_res:: v2:: ChunkFetchingResponse :: NoSuchChunk ) => Ok ( None ) ,
389+ Ok ( ( Some ( chunk. into ( ) ) , protocol) ) ,
390+ Ok ( req_res:: v2:: ChunkFetchingResponse :: NoSuchChunk ) =>
391+ Ok ( ( None , protocol) ) ,
392392 Err ( e) => Err ( RequestError :: InvalidResponse ( e) ) ,
393393 }
394394 } else if v1_protocol_name == protocol {
395- params. metrics . on_chunk_response_v1 ( ) ;
396395 // V1 protocol version must not be used when chunk mapping node
397396 // feature is enabled, because we can't know the real index of the
398397 // returned chunk.
@@ -410,9 +409,12 @@ impl State {
410409 }
411410
412411 match req_res:: v1:: ChunkFetchingResponse :: decode ( & mut & bytes[ ..] ) {
413- Ok ( req_res:: v1:: ChunkFetchingResponse :: Chunk ( chunk) ) =>
414- Ok ( Some ( chunk. recombine_into_chunk ( & raw_request_v1) ) ) ,
415- Ok ( req_res:: v1:: ChunkFetchingResponse :: NoSuchChunk ) => Ok ( None ) ,
412+ Ok ( req_res:: v1:: ChunkFetchingResponse :: Chunk ( chunk) ) => Ok ( (
413+ Some ( chunk. recombine_into_chunk ( & raw_request_v1) ) ,
414+ protocol,
415+ ) ) ,
416+ Ok ( req_res:: v1:: ChunkFetchingResponse :: NoSuchChunk ) =>
417+ Ok ( ( None , protocol) ) ,
416418 Err ( e) => Err ( RequestError :: InvalidResponse ( e) ) ,
417419 }
418420 } else {
@@ -480,42 +482,54 @@ impl State {
480482 let mut is_error = false ;
481483
482484 match request_result {
483- Ok ( Some ( chunk) ) =>
484- if is_chunk_valid ( params, & chunk) {
485- metrics. on_chunk_request_succeeded ( strategy_type) ;
486- gum:: trace!(
487- target: LOG_TARGET ,
488- candidate_hash = ?params. candidate_hash,
489- ?authority_id,
490- ?validator_index,
491- "Received valid chunk" ,
492- ) ;
493- self . insert_chunk (
494- chunk. index ,
495- Chunk { chunk : chunk. chunk , validator_index } ,
496- ) ;
497- } else {
498- metrics. on_chunk_request_invalid ( strategy_type) ;
499- error_count += 1 ;
500- // Record that we got an invalid chunk so that subsequent strategies don't
501- // try requesting this again.
502- self . record_error_fatal ( authority_id. clone ( ) , validator_index) ;
503- is_error = true ;
504- } ,
505- Ok ( None ) => {
506- metrics. on_chunk_request_no_such_chunk ( strategy_type) ;
507- gum:: trace!(
508- target: LOG_TARGET ,
509- candidate_hash = ?params. candidate_hash,
510- ?authority_id,
511- ?validator_index,
512- "Validator did not have the chunk" ,
513- ) ;
514- error_count += 1 ;
515- // Record that the validator did not have this chunk so that subsequent
516- // strategies don't try requesting this again.
517- self . record_error_fatal ( authority_id. clone ( ) , validator_index) ;
518- is_error = true ;
485+ Ok ( ( maybe_chunk, protocol) ) => {
486+ match protocol {
487+ name if name == params. req_v1_protocol_name =>
488+ params. metrics . on_chunk_response_v1 ( ) ,
489+ name if name == params. req_v2_protocol_name =>
490+ params. metrics . on_chunk_response_v2 ( ) ,
491+ _ => { } ,
492+ }
493+
494+ match maybe_chunk {
495+ Some ( chunk) =>
496+ if is_chunk_valid ( params, & chunk) {
497+ metrics. on_chunk_request_succeeded ( strategy_type) ;
498+ gum:: trace!(
499+ target: LOG_TARGET ,
500+ candidate_hash = ?params. candidate_hash,
501+ ?authority_id,
502+ ?validator_index,
503+ "Received valid chunk" ,
504+ ) ;
505+ self . insert_chunk (
506+ chunk. index ,
507+ Chunk { chunk : chunk. chunk , validator_index } ,
508+ ) ;
509+ } else {
510+ metrics. on_chunk_request_invalid ( strategy_type) ;
511+ error_count += 1 ;
512+ // Record that we got an invalid chunk so that subsequent strategies
513+ // don't try requesting this again.
514+ self . record_error_fatal ( authority_id. clone ( ) , validator_index) ;
515+ is_error = true ;
516+ } ,
517+ None => {
518+ metrics. on_chunk_request_no_such_chunk ( strategy_type) ;
519+ gum:: trace!(
520+ target: LOG_TARGET ,
521+ candidate_hash = ?params. candidate_hash,
522+ ?authority_id,
523+ ?validator_index,
524+ "Validator did not have the chunk" ,
525+ ) ;
526+ error_count += 1 ;
527+ // Record that the validator did not have this chunk so that subsequent
528+ // strategies don't try requesting this again.
529+ self . record_error_fatal ( authority_id. clone ( ) , validator_index) ;
530+ is_error = true ;
531+ } ,
532+ }
519533 } ,
520534 Err ( err) => {
521535 error_count += 1 ;
@@ -1061,7 +1075,7 @@ mod tests {
10611075 future:: ready ( (
10621076 params. validator_authority_keys [ 0 ] . clone ( ) ,
10631077 0 . into ( ) ,
1064- Ok ( Some ( chunks[ 0 ] . clone ( ) ) ) ,
1078+ Ok ( ( Some ( chunks[ 0 ] . clone ( ) ) , "" . into ( ) ) ) ,
10651079 ) )
10661080 . boxed ( ) ,
10671081 ) ;
@@ -1070,13 +1084,17 @@ mod tests {
10701084 future:: ready ( (
10711085 params. validator_authority_keys [ 1 ] . clone ( ) ,
10721086 1 . into ( ) ,
1073- Ok ( Some ( chunks[ 1 ] . clone ( ) ) ) ,
1087+ Ok ( ( Some ( chunks[ 1 ] . clone ( ) ) , "" . into ( ) ) ) ,
10741088 ) )
10751089 . boxed ( ) ,
10761090 ) ;
10771091 ongoing_reqs. push (
1078- future:: ready ( ( params. validator_authority_keys [ 2 ] . clone ( ) , 2 . into ( ) , Ok ( None ) ) )
1079- . boxed ( ) ,
1092+ future:: ready ( (
1093+ params. validator_authority_keys [ 2 ] . clone ( ) ,
1094+ 2 . into ( ) ,
1095+ Ok ( ( None , "" . into ( ) ) ) ,
1096+ ) )
1097+ . boxed ( ) ,
10801098 ) ;
10811099 ongoing_reqs. push (
10821100 future:: ready ( (
@@ -1201,7 +1219,7 @@ mod tests {
12011219 future:: ready ( (
12021220 params. validator_authority_keys [ 0 ] . clone ( ) ,
12031221 0 . into ( ) ,
1204- Ok ( Some ( chunks[ 0 ] . clone ( ) ) ) ,
1222+ Ok ( ( Some ( chunks[ 0 ] . clone ( ) ) , "" . into ( ) ) ) ,
12051223 ) )
12061224 . boxed ( ) ,
12071225 ) ;
@@ -1210,13 +1228,17 @@ mod tests {
12101228 future:: ready ( (
12111229 params. validator_authority_keys [ 1 ] . clone ( ) ,
12121230 1 . into ( ) ,
1213- Ok ( Some ( chunks[ 1 ] . clone ( ) ) ) ,
1231+ Ok ( ( Some ( chunks[ 1 ] . clone ( ) ) , "" . into ( ) ) ) ,
12141232 ) )
12151233 . boxed ( ) ,
12161234 ) ;
12171235 ongoing_reqs. push (
1218- future:: ready ( ( params. validator_authority_keys [ 2 ] . clone ( ) , 2 . into ( ) , Ok ( None ) ) )
1219- . boxed ( ) ,
1236+ future:: ready ( (
1237+ params. validator_authority_keys [ 2 ] . clone ( ) ,
1238+ 2 . into ( ) ,
1239+ Ok ( ( None , "" . into ( ) ) ) ,
1240+ ) )
1241+ . boxed ( ) ,
12201242 ) ;
12211243 ongoing_reqs. push (
12221244 future:: ready ( (
0 commit comments