@@ -341,28 +341,10 @@ async fn send_submit_block_full(
341341 return Ok ( None ) ;
342342 }
343343
344- // Decode the payload based on content type.
345- // The v1 guard above ensures `content_type` is Some
346- let content_type = block_response. content_type . ok_or_else ( || PbsError :: RelayResponse {
347- error_msg : "v1 submit_block response missing Content-Type" . to_string ( ) ,
348- code : block_response. code . as_u16 ( ) ,
349- } ) ?;
350- let decoded_response = match content_type {
351- EncodingType :: Json => decode_json_payload ( & block_response. response_bytes ) ?,
352- EncodingType :: Ssz => {
353- let fork = match block_response. fork {
354- Some ( fork) => fork,
355- None => {
356- return Err ( PbsError :: RelayResponse {
357- error_msg : "missing fork version header in SSZ submit_block response"
358- . to_string ( ) ,
359- code : block_response. code . as_u16 ( ) ,
360- } ) ;
361- }
362- } ;
363- decode_ssz_payload ( & block_response. response_bytes , fork) ?
364- }
365- } ;
344+ // Decode the payload based on content type. The v1 guard above ensures
345+ // `content_type` is Some.
346+ let decoded_response =
347+ decode_by_encoding ( & block_response, decode_json_payload, decode_ssz_payload) ?;
366348
367349 // Log and return
368350 debug ! (
@@ -407,24 +389,13 @@ async fn send_submit_block_light(
407389 }
408390
409391 // Decode the payload based on content type. The v1 guard above ensures
410- // `content_type` is Some (v2 paths return None and early-exit).
411- let content_type = block_response. content_type . ok_or_else ( || PbsError :: RelayResponse {
412- error_msg : "v1 submit_block response missing Content-Type" . to_string ( ) ,
413- code : block_response. code . as_u16 ( ) ,
414- } ) ?;
415- let fork = match content_type {
416- EncodingType :: Json => get_light_info_from_json ( & block_response. response_bytes ) ?,
417- EncodingType :: Ssz => match block_response. fork {
418- Some ( fork) => fork,
419- None => {
420- return Err ( PbsError :: RelayResponse {
421- error_msg : "missing fork version header in SSZ submit_block response"
422- . to_string ( ) ,
423- code : block_response. code . as_u16 ( ) ,
424- } ) ;
425- }
426- } ,
427- } ;
392+ // `content_type` is Some.
393+ let fork =
394+ decode_by_encoding ( & block_response, get_light_info_from_json, |_bytes, fork| Ok ( fork) ) ?;
395+ // `content_type` is guaranteed Some on v1 per decode_by_encoding.
396+ let encoding_type = block_response. content_type . expect (
397+ "v1 submit_block response carries Content-Type; decode_by_encoding already enforced this" ,
398+ ) ;
428399
429400 // Log and return
430401 debug ! (
@@ -437,11 +408,36 @@ async fn send_submit_block_light(
437408
438409 Ok ( Some ( LightSubmitBlockResponse {
439410 version : fork,
440- encoding_type : content_type ,
411+ encoding_type,
441412 raw_bytes : block_response. response_bytes ,
442413 } ) )
443414}
444415
416+ /// Dispatch a v1 submit_block response to the appropriate decoder based on the
417+ /// negotiated content-type. Caller guarantees `content_type` is Some (v2
418+ /// paths early-exit before reaching decode); an absent Content-Type on v1 is
419+ /// treated as a protocol violation. SSZ additionally requires a fork header.
420+ fn decode_by_encoding < T > (
421+ info : & SubmitBlockResponseInfo ,
422+ on_json : impl FnOnce ( & [ u8 ] ) -> Result < T , PbsError > ,
423+ on_ssz : impl FnOnce ( & [ u8 ] , ForkName ) -> Result < T , PbsError > ,
424+ ) -> Result < T , PbsError > {
425+ let content_type = info. content_type . ok_or_else ( || PbsError :: RelayResponse {
426+ error_msg : "v1 submit_block response missing Content-Type" . to_string ( ) ,
427+ code : info. code . as_u16 ( ) ,
428+ } ) ?;
429+ match content_type {
430+ EncodingType :: Json => on_json ( & info. response_bytes ) ,
431+ EncodingType :: Ssz => {
432+ let fork = info. fork . ok_or_else ( || PbsError :: RelayResponse {
433+ error_msg : "missing fork version header in SSZ submit_block response" . to_string ( ) ,
434+ code : info. code . as_u16 ( ) ,
435+ } ) ?;
436+ on_ssz ( & info. response_bytes , fork)
437+ }
438+ }
439+ }
440+
445441/// Sends the actual HTTP request to the relay's submit_block endpoint,
446442/// returning the response (if applicable), the round-trip time, and the
447443/// encoding type used for the body (if any). Used by send_submit_block.
0 commit comments