How to use the raiden.exceptions.RaidenRecoverableError function in raiden

To help you get started, we’ve selected a few raiden examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github raiden-network / raiden / raiden / exceptions.py View on Github external
Actually, this exception can also be used in the proxies for insane values
    that are not valid regardless of the chain state.
    If a value is not acceptable because of the chain state, BrokenPreconditionError
    must be used instead.
    Also, if a value indicates a bug in our codebase, RaidenValidationError
    is not the right error because RaidenValidationError is considered as a
    recoverable error.

    We prefer this exception over ValueError because libraries (e.g. web3.py)
    raise ValueError sometimes, and we want to differentiate our own exceptions
    from those.
    """


class PaymentConflict(RaidenRecoverableError):
    """ Raised when there is another payment with the same identifier but the
    attributes of the payment don't match.
    """


class InsufficientFunds(RaidenError):
    """ Raised when provided account doesn't have token funds to complete the
    requested deposit.

    Used when a *user* tries to deposit a given amount of token in a channel,
    but his account doesn't have enough funds to pay for the deposit.
    """


class DepositOverLimit(RaidenError):
    """ Raised when the requested deposit is over the limit
github raiden-network / raiden / raiden / network / proxies / user_deposit.py View on Github external
)
                if existing_monitoring_service_address != EMPTY_ADDRESS:
                    msg = (
                        f"MonitoringService contract address was set to "
                        f"{to_checksum_address(existing_monitoring_service_address)}"
                    )
                    raise RaidenRecoverableError(msg)

                if existing_one_to_n_address != EMPTY_ADDRESS:
                    msg = (
                        f"OneToN contract address was set to "
                        f"{to_checksum_address(existing_one_to_n_address)}"
                    )
                    raise RaidenRecoverableError(msg)

                raise RaidenRecoverableError("Deposit failed of unknown reason")
github raiden-network / raiden / raiden / network / proxies / token_network.py View on Github external
f"and {to_checksum_address(partner)} are not participants of "
                    f"that channel. The correct id is {queried_channel_identifier}."
                )
                raise RaidenUnrecoverableError(msg)  # This error is considered a bug

            if channel_data.state == ChannelState.CLOSED:
                msg = "Deposit was prohibited because the channel is closed"
                raise RaidenRecoverableError(msg)

            if channel_data.state == ChannelState.SETTLED:
                msg = "Deposit was prohibited because the channel is settled"
                raise RaidenRecoverableError(msg)

            if channel_data.state == ChannelState.REMOVED:
                msg = "Deposit was prohibited because the channel is settled and unlocked"
                raise RaidenRecoverableError(msg)

            if our_details.deposit >= total_deposit:
                msg = "Attempted deposit has already been done"
                raise RaidenRecoverableError(msg)

            # Check if deposit is being made on a nonexistent channel
            if channel_data.state == ChannelState.NONEXISTENT:
                msg = (
                    f"Channel between participant {to_checksum_address(self.node_address)} "
                    f"and {to_checksum_address(partner)} does not exist"
                )
                raise RaidenUnrecoverableError(msg)

            if total_channel_deposit >= UINT256_MAX:
                raise RaidenRecoverableError("Deposit overflow")
github raiden-network / raiden / raiden / network / proxies / secret_registry.py View on Github external
msg = f"Unexpected exception {e} at sending registerSecretBatch transaction."

        # Clear `open_secret_transactions` regardless of the transaction being
        # successfully executed or not.
        with self._open_secret_transactions_lock:
            for secret in secrets_to_register:
                self.open_secret_transactions.pop(secret)

        # As of version `0.4.0` of the contract has *no* asserts or requires.
        # Therefore the only reason for the transaction to fail is if there is
        # a bug.
        unrecoverable_error = (
            gas_limit is None or receipt is None or receipt["status"] == RECEIPT_FAILURE_CODE
        )

        exception: Union[RaidenRecoverableError, RaidenUnrecoverableError]
        if unrecoverable_error:
            # If the transaction was sent it must not fail. If this happened
            # some of our assumptions is broken therefore the error is
            # unrecoverable
            if receipt is not None:
                if receipt["gasUsed"] == gas_limit:
                    # The transaction failed and all gas was used. This can
                    # happen because of:
                    #
                    # - A compiler bug if an invalid opcode was executed.
                    # - A configuration bug if an assert was executed,
                    # because version 0.4.0 of the secret registry does not have an
                    # assert.
                    # - An ethereum client bug if the gas_limit was
                    # underestimated.
                    #
github raiden-network / raiden / raiden / network / proxies / token_network.py View on Github external
"""
        raise_if_invalid_address_pair(participant1, participant2)

        channel_identifier = self.proxy.contract.functions.getChannelIdentifier(
            participant=to_checksum_address(participant1),
            partner=to_checksum_address(participant2),
        ).call(block_identifier=block_identifier)

        if channel_identifier == 0:
            msg = (
                f"getChannelIdentifier returned 0, meaning "
                f"no channel currently exists between "
                f"{to_checksum_address(participant1)} and "
                f"{to_checksum_address(participant2)}"
            )
            raise RaidenRecoverableError(msg)

        return channel_identifier
github raiden-network / raiden / raiden / network / proxies / token_network.py View on Github external
if allowance < amount_to_deposit:
                    msg = (
                        f"The allowance of the {amount_to_deposit} deposit changed. "
                        f"Check concurrent deposits "
                        f"for the same token network but different proxies."
                    )
                    raise RaidenRecoverableError(msg)

                latest_deposit = self._detail_participant(
                    channel_identifier=channel_identifier,
                    detail_for=self.node_address,
                    partner=partner,
                    block_identifier=failed_at_blockhash,
                ).deposit
                if latest_deposit < total_deposit:
                    raise RaidenRecoverableError("The tokens were not transferred")

                # Here, we don't know what caused the failure. But because we are
                # dealing with an external token contract, it is assumed that it is
                # malicious and therefore we raise a Recoverable error here.
                raise RaidenRecoverableError("Unlocked failed for an unknown reason")
        else:
            # The latest block can not be used reliably because of reorgs,
            # therefore every call using this block has to handle pruned data.
            failed_at = self.proxy.rpc_client.get_block("latest")
            failed_at_blockhash = encode_hex(failed_at["hash"])
            failed_at_blocknumber = failed_at["number"]

            self.proxy.rpc_client.check_for_insufficient_eth(
                transaction_name="setTotalDeposit",
                transaction_executed=False,
                required_gas=self.metadata.gas_measurements["TokenNetwork.setTotalDeposit"],
github raiden-network / raiden / raiden / network / proxies / token_network.py View on Github external
channel_identifier=channel_identifier,
                detail_for=sender,
                partner=receiver,
                block_identifier=failed_at_blockhash,
            )

            if detail.state < ChannelState.SETTLED:
                msg = (
                    f"cannot call unlock on a channel that has not been settled yet. "
                    f"current_state={detail.state}"
                )
                raise RaidenUnrecoverableError(msg)

            is_unlock_done = sender_details.locksroot == LOCKSROOT_OF_NO_LOCKS
            if is_unlock_done:
                raise RaidenRecoverableError("The locks are already unlocked ")

            raise RaidenUnrecoverableError("unlock failed for an unknown reason")
github raiden-network / raiden / raiden / network / proxies / token_network.py View on Github external
if is_invalid_channel_id:
                msg = (
                    f"There is an open channel with the id {channel_identifier}. "
                    f"However addresses {to_checksum_address(self.node_address)} "
                    f"and {to_checksum_address(partner)} are not participants of "
                    f"that channel. The correct id is {queried_channel_identifier}."
                )
                raise RaidenUnrecoverableError(msg)  # This error is considered a bug

            if channel_data.state == ChannelState.CLOSED:
                msg = "Deposit was prohibited because the channel is closed"
                raise RaidenRecoverableError(msg)

            if channel_data.state == ChannelState.SETTLED:
                msg = "Deposit was prohibited because the channel is settled"
                raise RaidenRecoverableError(msg)

            if channel_data.state == ChannelState.REMOVED:
                msg = "Deposit was prohibited because the channel is settled and unlocked"
                raise RaidenRecoverableError(msg)

            if our_details.deposit >= total_deposit:
                msg = "Attempted deposit has already been done"
                raise RaidenRecoverableError(msg)

            # Check if deposit is being made on a nonexistent channel
            if channel_data.state == ChannelState.NONEXISTENT:
                msg = (
                    f"Channel between participant {to_checksum_address(self.node_address)} "
                    f"and {to_checksum_address(partner)} does not exist"
                )
                raise RaidenUnrecoverableError(msg)
github raiden-network / raiden / raiden / network / proxies / user_deposit.py View on Github external
)
                    raise RaidenRecoverableError(msg)

                if whole_balance + amount_to_deposit > whole_balance_limit:
                    msg = (
                        f"Current whole balance is {whole_balance}. "
                        f"With the new deposit of {amount_to_deposit}, the deposit "
                        f"limit of {whole_balance_limit} was exceeded."
                    )
                    raise RaidenRecoverableError(msg)

                if latest_deposit < total_deposit:
                    msg = "Deposit amount did not increase after deposit transaction"
                    raise RaidenRecoverableError(msg)

                raise RaidenRecoverableError("Deposit failed of unknown reason")
github raiden-network / raiden / raiden / network / proxies / token_network.py View on Github external
channel_identifier=channel_identifier,
            )

            if detail.state < ChannelState.CLOSED:
                msg = (
                    f"cannot call update_transfer channel has not been closed yet. "
                    f"current_state={detail.state}"
                )
                raise RaidenUnrecoverableError(msg)

            if detail.state >= ChannelState.SETTLED:
                msg = (
                    f"cannot call update_transfer channel has been settled already. "
                    f"current_state={detail.state}"
                )
                raise RaidenRecoverableError(msg)

            if detail.settle_block_number < failed_at_blocknumber:
                raise RaidenRecoverableError(
                    "update_transfer transation sent after settlement window"
                )

            # At this point it is known the channel is CLOSED on block
            # `failed_at_blockhash`
            partner_details = self._detail_participant(
                channel_identifier=channel_identifier,
                detail_for=partner,
                partner=self.node_address,
                block_identifier=failed_at_blockhash,
            )

            if not partner_details.is_closer: