async def say_hello(self, peer_id: ID) -> None:
    hello_mine = self._make_hello_packet()
    self.logger.debug('Opening new stream to peer=%s with protocols=%s', peer_id, [REQ_RESP_HELLO_SSZ])
    stream = (await self.host.new_stream(peer_id, [REQ_RESP_HELLO_SSZ]))
    self.logger.debug('Sending our hello message %s', hello_mine)
    try:
        (await write_req(stream, hello_mine))
        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:
            (await self.disconnect_peer(peer_id))
            error_msg = f'fail to write request={hello_mine}'
            self.logger.info('Handshake failed: %s', error_msg)
            raise HandshakeFailure(error_msg)
    self.logger.debug('Waiting for hello from the other side')
    try:
        (resp_code, hello_other_side) = (await read_resp(stream, HelloRequest))
        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:
            (await self.disconnect_peer(peer_id))
            self.logger.info('Handshake failed: fail to read the response')
            raise HandshakeFailure('fail to read the response')
    self.logger.debug('Received the hello message %s, resp_code=%s', hello_other_side, resp_code)
    if (resp_code != ResponseCode.SUCCESS):
        error_msg = f'resp_code != ResponseCode.SUCCESS, resp_code={resp_code}, error_msg={hello_other_side}'
        self.logger.info('Handshake failed: %s', error_msg)
        (await stream.reset())
        (await self.disconnect_peer(peer_id))
        raise HandshakeFailure(error_msg)
    hello_other_side = cast(HelloRequest, hello_other_side)
    try:
        (await self._validate_hello_req(hello_other_side))
    except ValidationError as error:
        error_msg = f'hello message {hello_other_side} is invalid: {str(error)}'
        self.logger.info('Handshake failed: %s. Disconnecting %s', error_msg, peer_id)
        (await stream.reset())
        (await self.say_goodbye(peer_id, GoodbyeReasonCode.IRRELEVANT_NETWORK))
        (await self.disconnect_peer(peer_id))
        raise HandshakeFailure(error_msg) from error
    if (peer_id not in self.handshaked_peers):
        peer = Peer.from_hello_request(self, peer_id, hello_other_side)
        self.handshaked_peers.add(peer)
        self.logger.debug('Handshake to peer=%s is finished. Added to the `handshake_peers`', peer_id)
    self._compare_chain_tip_and_finalized_epoch(hello_other_side.finalized_epoch, hello_other_side.head_slot)
    (await stream.close())
async def say_hello(self, peer_id: ID) -> None:
    hello_mine = self._make_hello_packet()
    self.logger.debug('Opening new stream to peer=%s with protocols=%s', peer_id, [REQ_RESP_HELLO_SSZ])
    stream = (await self.host.new_stream(peer_id, [REQ_RESP_HELLO_SSZ]))
    self.logger.debug('Sending our hello message %s', hello_mine)
    try:
        (await write_req(stream, hello_mine))
        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:
            (await self.disconnect_peer(peer_id))
            error_msg = f'fail to write request={hello_mine}'
            self.logger.info('Handshake failed: %s', error_msg)
            raise HandshakeFailure(error_msg)
    self.logger.debug('Waiting for hello from the other side')
    try:
        (resp_code, hello_other_side) = (await read_resp(stream, HelloRequest))
        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:
            (await self.disconnect_peer(peer_id))
            self.logger.info('Handshake failed: fail to read the response')
            raise HandshakeFailure('fail to read the response')
    self.logger.debug('Received the hello message %s, resp_code=%s', hello_other_side, resp_code)
    if (resp_code != ResponseCode.SUCCESS):
        error_msg = f'resp_code != ResponseCode.SUCCESS, resp_code={resp_code}, error_msg={hello_other_side}'
        self.logger.info('Handshake failed: %s', error_msg)
        (await stream.reset())
        (await self.disconnect_peer(peer_id))
        raise HandshakeFailure(error_msg)
    hello_other_side = cast(HelloRequest, hello_other_side)
    try:
        (await self._validate_hello_req(hello_other_side))
    except ValidationError as error:
        error_msg = f'hello message {hello_other_side} is invalid: {str(error)}'
        self.logger.info('Handshake failed: %s. Disconnecting %s', error_msg, peer_id)
        (await stream.reset())
        (await self.say_goodbye(peer_id, GoodbyeReasonCode.IRRELEVANT_NETWORK))
        (await self.disconnect_peer(peer_id))
        raise HandshakeFailure(error_msg) from error
    if (peer_id not in self.handshaked_peers):
        peer = Peer.from_hello_request(self, peer_id, hello_other_side)
        self.handshaked_peers.add(peer)
        self.logger.debug('Handshake to peer=%s is finished. Added to the `handshake_peers`', peer_id)
    self._compare_chain_tip_and_finalized_epoch(hello_other_side.finalized_epoch, hello_other_side.head_slot)
    (await stream.close())