async def request_beacon_blocks(self, peer_id: ID, head_block_root: HashTreeRoot, start_slot: Slot, count: int, step: int) -> Tuple[(BaseBeaconBlock, ...)]:
    if (peer_id not in self.handshaked_peers):
        error_msg = f'not handshaked with peer={peer_id} yet'
        self.logger.info('Request beacon block failed: %s', error_msg)
        raise RequestFailure(error_msg)
    beacon_blocks_request = BeaconBlocksRequest(head_block_root=head_block_root, start_slot=start_slot, count=count, step=step)
    self.logger.debug('Opening new stream to peer=%s with protocols=%s', peer_id, [REQ_RESP_BEACON_BLOCKS_SSZ])
    stream = (await self.host.new_stream(peer_id, [REQ_RESP_BEACON_BLOCKS_SSZ]))
    self.logger.debug('Sending beacon blocks request %s', beacon_blocks_request)
    try:
        (await write_req(stream, beacon_blocks_request))
        has_error = False
    except (WriteMessageFailure, MplexStreamEOF, MplexStreamReset) as error:
        has_error = True
        if isinstance(error, WriteMessageFailure):
            (await stream.reset())
        elif isinstance(error, MplexStreamEOF):
            (await stream.close())
    finally:
        if has_error:
            error_msg = f'fail to write request={beacon_blocks_request}'
            self.logger.info('Request beacon blocks failed: %s', error_msg)
            raise RequestFailure(error_msg)
    self.logger.debug('Waiting for beacon blocks response')
    try:
        (resp_code, beacon_blocks_response) = (await read_resp(stream, BeaconBlocksResponse))
        has_error = False
    except (ReadMessageFailure, MplexStreamEOF, MplexStreamReset) as error:
        has_error = True
        if isinstance(error, ReadMessageFailure):
            (await stream.reset())
        elif isinstance(error, MplexStreamEOF):
            (await stream.close())
    finally:
        if has_error:
            self.logger.info('Request beacon blocks failed: fail to read the response')
            raise RequestFailure('fail to read the response')
    self.logger.debug('Received beacon blocks response %s, resp_code=%s', beacon_blocks_response, resp_code)
    if (resp_code != ResponseCode.SUCCESS):
        error_msg = f'resp_code != ResponseCode.SUCCESS, resp_code={resp_code}, error_msg={beacon_blocks_response}'
        self.logger.info('Request beacon blocks failed: %s', error_msg)
        (await stream.reset())
        raise RequestFailure(error_msg)
    (await stream.close())
    beacon_blocks_response = cast(BeaconBlocksResponse, beacon_blocks_response)
    return beacon_blocks_response.blocks
async def request_beacon_blocks(self, peer_id: ID, head_block_root: HashTreeRoot, start_slot: Slot, count: int, step: int) -> Tuple[(BaseBeaconBlock, ...)]:
    if (peer_id not in self.handshaked_peers):
        error_msg = f'not handshaked with peer={peer_id} yet'
        self.logger.info('Request beacon block failed: %s', error_msg)
        raise RequestFailure(error_msg)
    beacon_blocks_request = BeaconBlocksRequest(head_block_root=head_block_root, start_slot=start_slot, count=count, step=step)
    self.logger.debug('Opening new stream to peer=%s with protocols=%s', peer_id, [REQ_RESP_BEACON_BLOCKS_SSZ])
    stream = (await self.host.new_stream(peer_id, [REQ_RESP_BEACON_BLOCKS_SSZ]))
    self.logger.debug('Sending beacon blocks request %s', beacon_blocks_request)
    try:
        (await write_req(stream, beacon_blocks_request))
        has_error = False
    except (WriteMessageFailure, MplexStreamEOF, MplexStreamReset) as error:
        has_error = True
        if isinstance(error, WriteMessageFailure):
            (await stream.reset())
        elif isinstance(error, MplexStreamEOF):
            (await stream.close())
    finally:
        if has_error:
            error_msg = f'fail to write request={beacon_blocks_request}'
            self.logger.info('Request beacon blocks failed: %s', error_msg)
            raise RequestFailure(error_msg)
    self.logger.debug('Waiting for beacon blocks response')
    try:
        (resp_code, beacon_blocks_response) = (await read_resp(stream, BeaconBlocksResponse))
        has_error = False
    except (ReadMessageFailure, MplexStreamEOF, MplexStreamReset) as error:
        has_error = True
        if isinstance(error, ReadMessageFailure):
            (await stream.reset())
        elif isinstance(error, MplexStreamEOF):
            (await stream.close())
    finally:
        if has_error:
            self.logger.info('Request beacon blocks failed: fail to read the response')
            raise RequestFailure('fail to read the response')
    self.logger.debug('Received beacon blocks response %s, resp_code=%s', beacon_blocks_response, resp_code)
    if (resp_code != ResponseCode.SUCCESS):
        error_msg = f'resp_code != ResponseCode.SUCCESS, resp_code={resp_code}, error_msg={beacon_blocks_response}'
        self.logger.info('Request beacon blocks failed: %s', error_msg)
        (await stream.reset())
        raise RequestFailure(error_msg)
    (await stream.close())
    beacon_blocks_response = cast(BeaconBlocksResponse, beacon_blocks_response)
    return beacon_blocks_response.blocks