Skip to content

Commit

Permalink
Use unstable contract env for development env
Browse files Browse the repository at this point in the history
  • Loading branch information
karlb committed Apr 1, 2021
1 parent 0303c79 commit d693760
Show file tree
Hide file tree
Showing 9 changed files with 471 additions and 456 deletions.
860 changes: 414 additions & 446 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions scenario_player/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def __init__(
self.token = TokenConfig(self._loaded, self.scenario_dir.joinpath("token.info"))
deploy_token = self.token.address is None
self.nodes = NodesConfig(self._loaded, environment="development" if deploy_token else None)
self.nodes.dict["default_options"][
"development-environment"
] = environment.development_environment.value
self.scenario = ScenarioConfig(self._loaded)

# If the environment sets a list of matrix servers, the nodes must not
Expand Down
1 change: 1 addition & 0 deletions scenario_player/environment/development.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"environment_type": "development",
"development_environment": "unstable",
"pfs_with_fee": "https://pfs.transport01.raiden.network",
"eth_rpc_endpoints": [
"http://parity.goerli.ethnodes.brainbot.com:8545"
Expand Down
2 changes: 2 additions & 0 deletions scenario_player/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ def reclaim_eth(
contract_manager=contract_manager,
web3=web3,
account=account,
development_environment=environment.development_environment,
)

for token_address in reclaim_tokens:
Expand All @@ -479,6 +480,7 @@ def reclaim_eth(
contract_manager=contract_manager,
web3=web3,
account=account,
development_environment=environment.development_environment,
)
scenario_player.utils.reclaim.reclaim_erc20(
reclamation_candidates=reclamation_candidates,
Expand Down
25 changes: 21 additions & 4 deletions scenario_player/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
CONTRACT_CUSTOM_TOKEN,
CONTRACT_TOKEN_NETWORK_REGISTRY,
)
from raiden_contracts.contract_manager import DeployedContracts, get_contracts_deployment_info
from raiden_contracts.contract_manager import (
ContractDevEnvironment,
DeployedContracts,
get_contracts_deployment_info,
)
from raiden_contracts.utils.type_aliases import TokenAmount
from requests import HTTPError, Session
from web3 import HTTPProvider, Web3
Expand Down Expand Up @@ -106,6 +110,7 @@ def wait_for_nodes_to_be_ready(node_runners: List[NodeRunner], session: Session)
def get_token_network_registry_from_dependencies(
settings: SettingsConfig,
proxy_manager: ProxyManager,
development_environment: ContractDevEnvironment,
smoketest_deployment_data: DeployedContracts = None,
) -> TokenNetworkRegistry:
"""Return contract proxies for the UserDepositContract and associated token.
Expand All @@ -117,7 +122,11 @@ def get_token_network_registry_from_dependencies(
assert chain_id, "Missing configuration, either set udc_address or the chain_id"

if chain_id != CHAINNAME_TO_ID["smoketest"]:
contracts = get_contracts_deployment_info(chain_id, version=RAIDEN_CONTRACT_VERSION)
contracts = get_contracts_deployment_info(
chain_id,
version=RAIDEN_CONTRACT_VERSION,
development_environment=development_environment,
)
else:
contracts = smoketest_deployment_data

Expand Down Expand Up @@ -403,7 +412,11 @@ def setup_environment_and_run_main_task(self, node_addresses: Set[ChecksumAddres

smoketesting = False
if self.chain_id != CHAINNAME_TO_ID["smoketest"]:
deploy = get_contracts_deployment_info(self.chain_id, RAIDEN_CONTRACT_VERSION)
deploy = get_contracts_deployment_info(
self.chain_id,
RAIDEN_CONTRACT_VERSION,
development_environment=self.environment.development_environment,
)
else:
smoketesting = True
deploy = self.smoketest_deployment_data
Expand All @@ -427,6 +440,7 @@ def setup_environment_and_run_main_task(self, node_addresses: Set[ChecksumAddres
udc_address=udc_settings.address,
chain_id=settings.chain_id,
proxy_manager=proxy_manager,
development_environment=self.environment.development_environment,
)

log.debug("Minting utility tokens and /scheduling/ transfers to the nodes")
Expand All @@ -446,10 +460,13 @@ def setup_environment_and_run_main_task(self, node_addresses: Set[ChecksumAddres
settings=settings,
proxy_manager=proxy_manager,
smoketest_deployment_data=deploy,
development_environment=self.environment.development_environment,
)
else:
token_network_registry_proxy = get_token_network_registry_from_dependencies(
settings=settings, proxy_manager=proxy_manager
settings=settings,
proxy_manager=proxy_manager,
development_environment=self.environment.development_environment,
)

self.setup_raiden_token_balances(pool, token_proxy, node_addresses)
Expand Down
2 changes: 2 additions & 0 deletions scenario_player/tasks/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def _run(self, *args, **kwargs) -> Dict[str, Any]: # pylint: disable=unused-arg
contract_data = get_contracts_deployment_info(
chain_id=self._runner.definition.settings.chain_id,
version=RAIDEN_CONTRACT_VERSION,
development_environment=self._runner.environment.development_environment,
)
if self.contract_name == CONTRACT_TOKEN_NETWORK:
self.contract_address = self._runner.token_network_address
Expand Down Expand Up @@ -212,6 +213,7 @@ def __init__(
contract_data = get_contracts_deployment_info(
chain_id=self._runner.definition.settings.chain_id,
version=RAIDEN_CONTRACT_VERSION,
development_environment=self._runner.environment.development_environment,
)
assert contract_data
try:
Expand Down
3 changes: 3 additions & 0 deletions scenario_player/utils/configuration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import structlog
from eth_typing import URI
from raiden_contracts.contract_manager import ContractDevEnvironment
from typing_extensions import Literal

from raiden.utils.typing import (
Expand Down Expand Up @@ -40,9 +41,11 @@ class EnvironmentConfig:
raiden_client: str
wait_short: int
wait_long: int
development_environment: ContractDevEnvironment = ContractDevEnvironment.DEMO

def __post_init__(self):
self.eth_rpc_endpoint_iterator = itertools.cycle(self.eth_rpc_endpoints)
self.development_environment = ContractDevEnvironment(self.development_environment)


class PFSSettingsConfig:
Expand Down
12 changes: 10 additions & 2 deletions scenario_player/utils/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from eth_utils import to_canonical_address
from raiden_contracts.constants import CONTRACT_TOKEN_NETWORK_REGISTRY, CONTRACT_USER_DEPOSIT
from raiden_contracts.contract_manager import (
ContractDevEnvironment,
ContractManager,
DeployedContracts,
contracts_precompiled_path,
Expand Down Expand Up @@ -37,7 +38,10 @@ def get_proxy_manager(client: JSONRPCClient, deploy: DeployedContracts) -> Proxy


def get_udc_and_corresponding_token_from_dependencies(
chain_id: ChainID, proxy_manager: ProxyManager, udc_address: ChecksumAddress = None
chain_id: ChainID,
proxy_manager: ProxyManager,
development_environment: ContractDevEnvironment,
udc_address: ChecksumAddress = None,
) -> Tuple[UserDeposit, CustomToken]:
"""Return contract proxies for the UserDepositContract and associated token.
Expand All @@ -46,7 +50,11 @@ def get_udc_and_corresponding_token_from_dependencies(
"""
if udc_address is None:

contracts = get_contracts_deployment_info(chain_id, version=RAIDEN_CONTRACT_VERSION)
contracts = get_contracts_deployment_info(
chain_id,
version=RAIDEN_CONTRACT_VERSION,
development_environment=development_environment,
)

msg = (
f"invalid chain_id, {chain_id} is not available "
Expand Down
19 changes: 15 additions & 4 deletions scenario_player/utils/reclaim.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from gevent.pool import Pool
from raiden_contracts.constants import CONTRACT_TOKEN_NETWORK_REGISTRY, ChannelEvent
from raiden_contracts.contract_manager import (
ContractDevEnvironment,
ContractManager,
DeployedContracts,
get_contracts_deployment_info,
Expand Down Expand Up @@ -151,17 +152,22 @@ def withdraw_from_udc(
contract_manager: ContractManager,
account: Account,
web3: Web3,
development_environment: ContractDevEnvironment,
):
chain_id = ChainID(web3.eth.chainId)
deploy = get_contracts_deployment_info(chain_id, RAIDEN_CONTRACT_VERSION)
deploy = get_contracts_deployment_info(
chain_id, RAIDEN_CONTRACT_VERSION, development_environment=development_environment
)
assert deploy

planned_withdraws: Dict[ChecksumAddress, Tuple[BlockNumber, TokenAmount]] = {}

log.info("Checking chain for deposits in UserDeposit contact")
for node in reclamation_candidates:
(userdeposit_proxy, _) = get_udc_and_corresponding_token_from_dependencies(
chain_id=chain_id, proxy_manager=node.get_proxy_manager(web3, deploy)
chain_id=chain_id,
proxy_manager=node.get_proxy_manager(web3, deploy),
development_environment=development_environment,
)

balance = userdeposit_proxy.get_total_deposit(to_canonical_address(node.address), "latest")
Expand Down Expand Up @@ -207,7 +213,9 @@ def withdraw_from_udc(
candidate = [c for c in reclamation_candidates if c.address == address][0]
proxy_manager = candidate.get_proxy_manager(web3, deploy)
(userdeposit_proxy, _) = get_udc_and_corresponding_token_from_dependencies(
chain_id=chain_id, proxy_manager=proxy_manager
chain_id=chain_id,
proxy_manager=proxy_manager,
development_environment=development_environment,
)
# FIXME: Something is off with the block numbers, adding 20 to work around.
# See https://github.com/raiden-network/raiden/pull/6091/files#r412234516
Expand Down Expand Up @@ -442,6 +450,7 @@ def withdraw_all(
web3: Web3,
contract_manager: ContractManager,
token_address: TokenAddress,
development_environment: ContractDevEnvironment,
) -> None:
"""Withdraws all tokens from all channels
Expand All @@ -452,7 +461,9 @@ def withdraw_all(
wait times.
"""
chain_id = ChainID(web3.eth.chainId)
deploy = get_contracts_deployment_info(chain_id, RAIDEN_CONTRACT_VERSION)
deploy = get_contracts_deployment_info(
chain_id, RAIDEN_CONTRACT_VERSION, development_environment=development_environment
)
assert deploy
assert account.privkey
token_network_address = _get_token_network_address(
Expand Down

0 comments on commit d693760

Please sign in to comment.