Skip to content

Commit

Permalink
Rename deprecation_executor to controller
Browse files Browse the repository at this point in the history
This user can now also remove limits. It is renamed to make this clear.
  • Loading branch information
karlb authored and palango committed Jul 29, 2021
1 parent 5346cf6 commit a825c62
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 60 deletions.
20 changes: 10 additions & 10 deletions raiden_contracts/data/source/raiden/TokenNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract TokenNetwork is Utils {
uint256 public channel_counter;

// Only for the limited Red Eyes release
address public deprecation_executor;
address public controller;
bool public safety_deprecation_switch = false;

// channel_identifier => Channel
Expand Down Expand Up @@ -202,8 +202,8 @@ contract TokenNetwork is Utils {
bytes32 participant2_locksroot
);

modifier onlyDeprecationExecutor() {
require(msg.sender == deprecation_executor, "Can only be called by deprecation_executor");
modifier onlyController() {
require(msg.sender == controller, "Can only be called by controller");
_;
}

Expand All @@ -230,7 +230,7 @@ contract TokenNetwork is Utils {
/// that can be chosen at the channel opening
/// @param _settlement_timeout_max The longest settlement period (in number of blocks)
/// that can be chosen at the channel opening
/// @param _deprecation_executor The Ethereum address that can disable new deposits and channel creation
/// @param _controller The Ethereum address that can disable new deposits and channel creation
/// @param _channel_participant_deposit_limit The maximum amount of tokens that can be deposited by each
/// participant of each channel. MAX_SAFE_UINT256 means no limits
/// @param _token_network_deposit_limit The maximum amount of tokens that this contract can hold
Expand All @@ -241,13 +241,13 @@ contract TokenNetwork is Utils {
uint256 _chain_id,
uint256 _settlement_timeout_min,
uint256 _settlement_timeout_max,
address _deprecation_executor,
address _controller,
uint256 _channel_participant_deposit_limit,
uint256 _token_network_deposit_limit
) {
require(_token_address != address(0x0));
require(_secret_registry != address(0x0));
require(_deprecation_executor != address(0x0));
require(_controller != address(0x0));
require(_chain_id > 0);
require(_settlement_timeout_min > 0);
require(_settlement_timeout_max > _settlement_timeout_min);
Expand All @@ -267,12 +267,12 @@ contract TokenNetwork is Utils {
// Make sure the contract is indeed a token contract
require(token.totalSupply() > 0);

deprecation_executor = _deprecation_executor;
controller = _controller;
channel_participant_deposit_limit = _channel_participant_deposit_limit;
token_network_deposit_limit = _token_network_deposit_limit;
}

function deprecate() public isSafe onlyDeprecationExecutor {
function deprecate() public isSafe onlyController {
safety_deprecation_switch = true;
emit DeprecationSwitch(safety_deprecation_switch);
}
Expand Down Expand Up @@ -1557,10 +1557,10 @@ contract TokenNetwork is Utils {
}

/// @notice Removes the balance limits.
/// Can only be called by the deprecation_executor.
/// Can only be called by the controller.
function removeLimits()
external
onlyDeprecationExecutor
onlyController
{
channel_participant_deposit_limit = MAX_INT;
token_network_deposit_limit = MAX_INT;
Expand Down
10 changes: 5 additions & 5 deletions raiden_contracts/data/source/raiden/TokenNetworkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract TokenNetworkRegistry is Utils {
uint256 public max_token_networks;

// Only for the limited Red Eyes release
address public deprecation_executor;
address public controller;
uint256 public token_network_created = 0;

// Token address => TokenNetwork address
Expand Down Expand Up @@ -59,7 +59,7 @@ contract TokenNetworkRegistry is Utils {
settlement_timeout_max = _settlement_timeout_max;
max_token_networks = _max_token_networks;

deprecation_executor = msg.sender;
controller = msg.sender;
}

/// @notice Deploy a new TokenNetwork contract for the Token deployed at
Expand Down Expand Up @@ -89,7 +89,7 @@ contract TokenNetworkRegistry is Utils {
chain_id,
settlement_timeout_min,
settlement_timeout_max,
deprecation_executor,
controller,
_channel_participant_deposit_limit,
_token_network_deposit_limit
);
Expand All @@ -112,11 +112,11 @@ contract TokenNetworkRegistry is Utils {
}

/// @notice Removes the limit on the number of token networks.
/// Can only be called by the deprecation_executor.
/// Can only be called by the controller.
function removeLimits()
external
{
require(msg.sender == deprecation_executor, "Can only be called by deprecation_executor");
require(msg.sender == controller, "Can only be called by controller");
max_token_networks = MAX_INT;
}
}
Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/deploy/contract_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def register_token_network(
_chain_id=chain_id,
_settlement_timeout_min=settle_timeout_min,
_settlement_timeout_max=settle_timeout_max,
_deprecation_executor=self.owner,
_controller=self.owner,
_channel_participant_deposit_limit=channel_participant_deposit_limit,
_token_network_deposit_limit=token_network_deposit_limit,
)
Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/tests/fixtures/token_network_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def token_network_external(
_chain_id=web3.eth.chain_id,
_settlement_timeout_min=TEST_SETTLE_TIMEOUT_MIN,
_settlement_timeout_max=TEST_SETTLE_TIMEOUT_MAX,
_deprecation_executor=DEPLOYER_ADDRESS,
_controller=DEPLOYER_ADDRESS,
_channel_participant_deposit_limit=channel_participant_deposit_limit,
_token_network_deposit_limit=token_network_deposit_limit,
)
26 changes: 13 additions & 13 deletions raiden_contracts/tests/test_deprecation_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)


def test_deprecation_executor(
def test_controller(
web3: Web3,
contracts_manager: ContractManager,
deploy_tester_contract: Callable,
Expand All @@ -41,21 +41,21 @@ def test_deprecation_executor(
original account as the deprecation executor. During these, this test also
tries to register more than one TokenNetworks and see a failure.
"""
(deprecation_executor, B) = get_accounts(2)
(controller, B) = get_accounts(2)

token_network_registry = deploy_tester_contract(
CONTRACT_TOKEN_NETWORK_REGISTRY,
token_network_libs,
deprecation_executor,
controller,
_secret_registry_address=secret_registry_contract.address,
_chain_id=web3.eth.chain_id,
_settlement_timeout_min=TEST_SETTLE_TIMEOUT_MIN,
_settlement_timeout_max=TEST_SETTLE_TIMEOUT_MAX,
_max_token_networks=1,
)

# Make sure deployer is deprecation_executor
assert token_network_registry.functions.deprecation_executor().call() == deprecation_executor
# Make sure deployer is controller
assert token_network_registry.functions.controller().call() == controller
assert token_network_registry.functions.token_network_created().call() == 0

# We can only deploy one TokenNetwork contract
Expand All @@ -82,7 +82,7 @@ def test_deprecation_executor(
custom_token.address,
channel_participant_deposit_limit,
token_network_deposit_limit,
).call({"from": deprecation_executor})
).call({"from": controller})

tx_receipt = web3.eth.get_transaction_receipt(tx_hash)
event_abi = contracts_manager.get_event_abi(
Expand All @@ -95,7 +95,7 @@ def test_deprecation_executor(
address=token_network_address,
)

assert token_network.functions.deprecation_executor().call() == deprecation_executor
assert token_network.functions.controller().call() == controller


def test_set_deprecation_switch(
Expand All @@ -106,14 +106,14 @@ def test_set_deprecation_switch(
) -> None:
"""The deprecation executor deprecates a TokenNetwork contract"""
(A) = get_accounts(1)[0]
deprecation_executor = token_network.functions.deprecation_executor().call()
controller = token_network.functions.controller().call()

assert token_network.functions.safety_deprecation_switch().call() is False

with pytest.raises(TransactionFailed):
token_network.functions.deprecate().call({"from": A})

tx = call_and_transact(token_network.functions.deprecate(), {"from": deprecation_executor})
tx = call_and_transact(token_network.functions.deprecate(), {"from": controller})
assert token_network.functions.safety_deprecation_switch().call() is True
tx_receipt = web3.eth.get_transaction_receipt(tx)
event_abi = contracts_manager.get_event_abi(CONTRACT_TOKEN_NETWORK, EVENT_DEPRECATION_SWITCH)
Expand All @@ -133,7 +133,7 @@ def test_deprecation_switch(
) -> None:
"""Test the effects of the deprecation switch on deposits and channel opening"""

deprecation_executor = token_network.functions.deprecation_executor().call()
controller = token_network.functions.controller().call()
(A, B, C, D) = get_accounts(4)
deposit = 100
bigger_deposit = 200
Expand All @@ -142,7 +142,7 @@ def test_deprecation_switch(
channel_deposit(channel_identifier, A, deposit, B)
channel_deposit(channel_identifier, B, deposit, A)

call_and_transact(token_network.functions.deprecate(), {"from": deprecation_executor})
call_and_transact(token_network.functions.deprecate(), {"from": controller})
assert token_network.functions.safety_deprecation_switch().call() is True

# Now we cannot deposit in existent channels
Expand All @@ -167,7 +167,7 @@ def test_deprecation_switch_settle(
close_and_update_channel: Callable,
) -> None:
"""Channel close and settlement still work after the depracation switch is turned on"""
deprecation_executor = token_network.functions.deprecation_executor().call()
controller = token_network.functions.controller().call()
(A, B) = get_accounts(2)
deposit = 100

Expand Down Expand Up @@ -215,7 +215,7 @@ def test_deprecation_switch_settle(
reveal_secrets(B, pending_transfers_tree_B.unlockable)

# Set the deprecation switch to true
call_and_transact(token_network.functions.deprecate(), {"from": deprecation_executor})
call_and_transact(token_network.functions.deprecate(), {"from": controller})
assert token_network.functions.safety_deprecation_switch().call() is True

# We need to make sure we can still close, settle & unlock the channels
Expand Down
4 changes: 2 additions & 2 deletions raiden_contracts/tests/test_print_gas.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def print_gas_token_network_deployment(
token_network_deposit_limit: int,
) -> None:
"""Abusing pytest to print the deployment gas cost of TokenNetwork"""
deprecation_executor = get_accounts(1)[0]
controller = get_accounts(1)[0]
txhash = deploy_tester_contract_txhash(
CONTRACT_TOKEN_NETWORK,
libs=token_network_libs,
Expand All @@ -121,7 +121,7 @@ def print_gas_token_network_deployment(
_chain_id=web3.eth.chain_id,
_settlement_timeout_min=TEST_SETTLE_TIMEOUT_MIN,
_settlement_timeout_max=TEST_SETTLE_TIMEOUT_MAX,
_deprecation_executor=deprecation_executor,
_controller=controller,
_channel_participant_deposit_limit=channel_participant_deposit_limit,
_token_network_deposit_limit=token_network_deposit_limit,
)
Expand Down
Loading

0 comments on commit a825c62

Please sign in to comment.