diff --git a/raiden/exceptions.py b/raiden/exceptions.py index 1392688af0a..20d46f4a307 100644 --- a/raiden/exceptions.py +++ b/raiden/exceptions.py @@ -200,8 +200,8 @@ class DuplicatedChannelError(RaidenRecoverableError): """Raised if someone tries to create a channel that already exists.""" -class ContractVersionMismatch(RaidenError): - """Raised if deployed version of the contract differs.""" +class ContractCodeMismatch(RaidenError): + """Raised if the onchain code of the contract differs.""" class TransactionThrew(RaidenError): diff --git a/raiden/network/proxies/secret_registry.py b/raiden/network/proxies/secret_registry.py index e6e5c905dd5..920ad53caa4 100644 --- a/raiden/network/proxies/secret_registry.py +++ b/raiden/network/proxies/secret_registry.py @@ -24,7 +24,7 @@ RaidenRecoverableError, RaidenUnrecoverableError, ) -from raiden.network.proxies.utils import compare_contract_versions, log_transaction +from raiden.network.proxies.utils import log_transaction from raiden.network.rpc.client import StatelessFilter, check_address_has_code from raiden.utils import safe_gas_limit from raiden.utils.typing import ( @@ -58,12 +58,8 @@ def __init__(self, jsonrpc_client, secret_registry_address, contract_manager: Co # There should be only one smart contract deployed, to avoid race # conditions for on-chain unlocks. - compare_contract_versions( - proxy=proxy, - expected_version=contract_manager.contracts_version, - contract_name=CONTRACT_SECRET_REGISTRY, - address=secret_registry_address, - ) + + # TODO: check what's onchain self.address = secret_registry_address self.proxy = proxy diff --git a/raiden/network/proxies/service_registry.py b/raiden/network/proxies/service_registry.py index d8f191ebecd..46563e87194 100644 --- a/raiden/network/proxies/service_registry.py +++ b/raiden/network/proxies/service_registry.py @@ -5,7 +5,7 @@ from eth_utils import is_binary_address, to_canonical_address, to_checksum_address from raiden.exceptions import BrokenPreconditionError, InvalidAddress, RaidenUnrecoverableError -from raiden.network.proxies.utils import compare_contract_versions, log_transaction +from raiden.network.proxies.utils import log_transaction from raiden.network.rpc.client import JSONRPCClient, check_address_has_code from raiden.network.rpc.transactions import check_transaction_threw from raiden.utils.typing import Address, AddressHex, BlockSpecification, Optional @@ -33,12 +33,7 @@ def __init__( to_canonical_address(service_registry_address), ) - compare_contract_versions( - proxy=proxy, - expected_version=contract_manager.contracts_version, - contract_name=CONTRACT_SERVICE_REGISTRY, - address=service_registry_address, - ) + # TODO: check what's onchain self.address = service_registry_address self.proxy = proxy diff --git a/raiden/network/proxies/token_network.py b/raiden/network/proxies/token_network.py index d99326a4298..f84cd5d5007 100644 --- a/raiden/network/proxies/token_network.py +++ b/raiden/network/proxies/token_network.py @@ -36,7 +36,7 @@ WithdrawMismatch, ) from raiden.network.proxies.token import Token -from raiden.network.proxies.utils import compare_contract_versions, log_transaction +from raiden.network.proxies.utils import log_transaction from raiden.network.rpc.client import StatelessFilter, check_address_has_code from raiden.network.rpc.transactions import check_transaction_threw from raiden.transfer.channel import compute_locksroot @@ -163,12 +163,7 @@ def __init__( to_normalized_address(token_network_address), ) - compare_contract_versions( - proxy=proxy, - expected_version=contract_manager.contracts_version, - contract_name=CONTRACT_TOKEN_NETWORK, - address=Address(token_network_address), - ) + # TODO: check what's onchain self.gas_measurements = gas_measurements(self.contract_manager.contracts_version) diff --git a/raiden/network/proxies/token_network_registry.py b/raiden/network/proxies/token_network_registry.py index 094a015f35e..43a727aad8d 100644 --- a/raiden/network/proxies/token_network_registry.py +++ b/raiden/network/proxies/token_network_registry.py @@ -18,7 +18,7 @@ RaidenRecoverableError, RaidenUnrecoverableError, ) -from raiden.network.proxies.utils import compare_contract_versions, log_transaction +from raiden.network.proxies.utils import log_transaction from raiden.network.rpc.client import StatelessFilter, check_address_has_code from raiden.network.rpc.transactions import check_transaction_threw from raiden.utils import safe_gas_limit @@ -67,12 +67,7 @@ def __init__( to_normalized_address(registry_address), ) - compare_contract_versions( - proxy=proxy, - expected_version=contract_manager.contracts_version, - contract_name=CONTRACT_TOKEN_NETWORK_REGISTRY, - address=Address(registry_address), - ) + # TODO: check what's onchain self.gas_measurements = gas_measurements(self.contract_manager.contracts_version) diff --git a/raiden/network/proxies/utils.py b/raiden/network/proxies/utils.py index 3fb6c6b71ee..f445490905a 100644 --- a/raiden/network/proxies/utils.py +++ b/raiden/network/proxies/utils.py @@ -1,12 +1,8 @@ from contextlib import contextmanager from typing import TYPE_CHECKING -from eth_utils import to_normalized_address from structlog import BoundLoggerBase -from web3.exceptions import BadFunctionCallOutput -from raiden.exceptions import AddressWrongContract, ContractVersionMismatch -from raiden.network.rpc.smartcontract_proxy import ContractProxy from raiden.transfer.identifiers import CanonicalIdentifier from raiden.utils.typing import Address, Any, BlockSpecification, Dict, Generator, Locksroot, Tuple @@ -15,32 +11,6 @@ from raiden.network.blockchain_service import BlockChainService -def compare_contract_versions( - proxy: ContractProxy, expected_version: str, contract_name: str, address: Address -) -> None: - """Compare version strings of a contract. - - If not matching raise ContractVersionMismatch. Also may raise AddressWrongContract - if the contract contains no code.""" - assert isinstance(expected_version, str) - try: - deployed_version = proxy.contract.functions.contract_version().call() - except BadFunctionCallOutput: - raise AddressWrongContract("") - - deployed_version = deployed_version.replace("_", "0") - expected_version = expected_version.replace("_", "0") - - deployed = [int(x) for x in deployed_version.split(".")] - expected = [int(x) for x in expected_version.split(".")] - - if deployed != expected: - raise ContractVersionMismatch( - f"Provided {contract_name} contract ({to_normalized_address(address)}) " - f"version mismatch. Expected: {expected_version} Got: {deployed_version}" - ) - - def get_onchain_locksroots( chain: "BlockChainService", canonical_identifier: CanonicalIdentifier, diff --git a/raiden/ui/startup.py b/raiden/ui/startup.py index ff7bff35773..17b713c1126 100644 --- a/raiden/ui/startup.py +++ b/raiden/ui/startup.py @@ -5,7 +5,7 @@ from eth_utils import to_canonical_address, to_checksum_address from raiden.constants import Environment, RoutingMode -from raiden.exceptions import AddressWithoutCode, AddressWrongContract, ContractVersionMismatch +from raiden.exceptions import AddressWithoutCode, AddressWrongContract, ContractCodeMismatch from raiden.network.blockchain_service import BlockChainService from raiden.network.pathfinding import PFSConfig, configure_pfs_or_exit from raiden.network.proxies.secret_registry import SecretRegistry @@ -80,7 +80,7 @@ def setup_contracts_or_exit(config: Dict[str, Any], network_id: ChainID) -> Dict return contracts -def handle_contract_version_mismatch(mismatch_exception: ContractVersionMismatch) -> None: +def handle_contract_code_mismatch(mismatch_exception: ContractCodeMismatch) -> None: click.secho(f"{str(mismatch_exception)}. Please update your Raiden installation.", fg="red") sys.exit(1) @@ -147,8 +147,8 @@ def setup_proxies_or_exit( contracts[CONTRACT_TOKEN_NETWORK_REGISTRY]["address"] ) token_network_registry = blockchain_service.token_network_registry(registered_address) - except ContractVersionMismatch as e: - handle_contract_version_mismatch(e) + except ContractCodeMismatch as e: + handle_contract_code_mismatch(e) except AddressWithoutCode: handle_contract_no_code("token network registry", tokennetwork_registry_contract_address) except AddressWrongContract: @@ -161,8 +161,8 @@ def setup_proxies_or_exit( secret_registry_contract_address or to_canonical_address(contracts[CONTRACT_SECRET_REGISTRY]["address"]) ) - except ContractVersionMismatch as e: - handle_contract_version_mismatch(e) + except ContractCodeMismatch as e: + handle_contract_code_mismatch(e) except AddressWithoutCode: handle_contract_no_code("secret registry", secret_registry_contract_address) except AddressWrongContract: @@ -186,8 +186,8 @@ def setup_proxies_or_exit( user_deposit_contract_address or to_canonical_address(contracts[CONTRACT_USER_DEPOSIT]["address"]) ) - except ContractVersionMismatch as e: - handle_contract_version_mismatch(e) + except ContractCodeMismatch as e: + handle_contract_code_mismatch(e) except AddressWithoutCode: handle_contract_no_code("user deposit", user_deposit_contract_address) except AddressWrongContract: @@ -200,8 +200,8 @@ def setup_proxies_or_exit( service_registry_contract_address or to_canonical_address(contracts[CONTRACT_SERVICE_REGISTRY]["address"]) ) - except ContractVersionMismatch as e: - handle_contract_version_mismatch(e) + except ContractCodeMismatch as e: + handle_contract_code_mismatch(e) except AddressWithoutCode: handle_contract_no_code("service registry", service_registry_contract_address) except AddressWrongContract: