# Buggy code
def on_balance_request(self, payload):
    """
    We received a balance request from a relay or exit node. Respond with the latest block in our chain.
    """
    if not self.bandwidth_wallet:
        self.logger.warning(
            "Bandwidth wallet is not available, not sending balance response!"
        )
        return

    # Get the latest block
    latest_block = self.bandwidth_wallet.trustchain.persistence.get_latest(
        self.my_peer.public_key.key_to_bin(), block_type=b"tribler_bandwidth"
    )
    if not latest_block:
        latest_block = TriblerBandwidthBlock()
    latest_block.public_key = EMPTY_PK  # We hide the public key

    # We either send the response directly or relay the response to the last verified hop
    circuit = self.circuits[payload.circuit_id]
    if not circuit.hops:
        self.increase_bytes_sent(
            circuit,
            self.send_cell(
                circuit.peer,
                "balance-response",
                BalanceResponsePayload.from_half_block(
                    latest_block, circuit.circuit_id
                ),
            ),
        )
    else:
        self.increase_bytes_sent(
            circuit,
            self.send_cell(
                circuit.peer,
                "relay-balance-response",
                BalanceResponsePayload.from_half_block(
                    latest_block, circuit.circuit_id
                ),
            ),
        )


# Traceback (RuntimeError)
Traceback (most recent call last):
File "src\tribler-gui\tribler_gui\event_request_manager.py", line 116, in on_read_data
RuntimeError:
--LONG TEXT--
Traceback (most recent call last):
File "lib\asyncio\events.py", line 81, in _run
File "ipv8\messaging\anonymization\tunnel.py", line 149, in on_ip_address
asyncio.exceptions.CancelledError

--CONTEXT--
{'message': 'Exception in callback TunnelExitSocket.sendto.<locals>.on_ip_address(<Task cancell...unnel.py:171>>) at ipv8\\messaging\\anonymization\\tunnel.py:147', 'exception': CancelledError(), 'handle': <Handle TunnelExitSocket.sendto.<locals>.on_ip_address(<Task cancell...unnel.py:171>>) at ipv8\messaging\anonymization\tunnel.py:147>}

# Fixed code
def on_balance_request(self, payload):
    """
    We received a balance request from a relay or exit node. Respond with the latest block in our chain.
    """
    if not self.bandwidth_wallet:
        self.logger.warning(
            "Bandwidth wallet is not available, not sending balance response!"
        )
        return

    # Get the latest block
    latest_block = self.bandwidth_wallet.trustchain.persistence.get_latest(
        self.my_peer.public_key.key_to_bin(), block_type=b"tribler_bandwidth"
    )
    if not latest_block:
        latest_block = TriblerBandwidthBlock()
    latest_block.public_key = EMPTY_PK  # We hide the public key

    # We either send the response directly or relay the response to the last verified hop
    circuit = self.circuits[payload.circuit_id]
    if not circuit.hops:
        self.send_cell(
            circuit.peer,
            BalanceResponsePayload.from_half_block(latest_block, circuit.circuit_id),
        )
    else:
        self.send_cell(
            circuit.peer,
            RelayBalanceResponsePayload.from_half_block(
                latest_block, circuit.circuit_id
            ),
        )