async def _handle_hello(self, stream: INetStream) -> None:
    peer_id = stream.mplex_conn.peer_id
    self.logger.debug('Waiting for hello from the other side')
    try:
        hello_other_side = (await read_req(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))
            return
    self.logger.debug('Received the hello message %s', hello_other_side)
    try:
        (await self._validate_hello_req(hello_other_side))
    except ValidationError as error:
        self.logger.info('Handshake failed: hello message %s is invalid: %s', hello_other_side, str(error))
        (await stream.reset())
        (await self.say_goodbye(peer_id, GoodbyeReasonCode.IRRELEVANT_NETWORK))
        (await self.disconnect_peer(peer_id))
        return
    hello_mine = self._make_hello_packet()
    self.logger.debug('Sending our hello message %s', hello_mine)
    try:
        (await write_resp(stream, hello_mine, ResponseCode.SUCCESS))
        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:
            self.logger.info('Handshake failed: failed to write message %s', hello_mine)
            (await self.disconnect_peer(peer_id))
            return
    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 from %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 _handle_hello(self, stream: INetStream) -> None:
    peer_id = stream.mplex_conn.peer_id
    self.logger.debug('Waiting for hello from the other side')
    try:
        hello_other_side = (await read_req(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))
            return
    self.logger.debug('Received the hello message %s', hello_other_side)
    try:
        (await self._validate_hello_req(hello_other_side))
    except ValidationError as error:
        self.logger.info('Handshake failed: hello message %s is invalid: %s', hello_other_side, str(error))
        (await stream.reset())
        (await self.say_goodbye(peer_id, GoodbyeReasonCode.IRRELEVANT_NETWORK))
        (await self.disconnect_peer(peer_id))
        return
    hello_mine = self._make_hello_packet()
    self.logger.debug('Sending our hello message %s', hello_mine)
    try:
        (await write_resp(stream, hello_mine, ResponseCode.SUCCESS))
        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:
            self.logger.info('Handshake failed: failed to write message %s', hello_mine)
            (await self.disconnect_peer(peer_id))
            return
    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 from %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())