Skip to content

Commit

Permalink
Make deposit limits configurable at TokenNetowk
Browse files Browse the repository at this point in the history
deployment time.

After some trial and error I believe that the best approach to
accomodate the different use cases of TokenNetwork is to make it
configurable at the deployment time, as opposed to providing multiple
flavors or versions of the source code.
  • Loading branch information
pirapira committed Mar 2, 2019
1 parent 7f5a218 commit e300a3e
Show file tree
Hide file tree
Showing 19 changed files with 290 additions and 98 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Documents changes that result in:

## Unreleased

- Deployment script's `register` command takes two additional options --channel-participant-deposit-limit and --token-network-deposit-limit
- TokenNetwork's constructor takes two additional arguments `_channel_participant_deposit_limit` and `_token_network_deposit_limit`
- TokenNetworkRegistry's constructor takes an additional argument `max_number_of_token_networks`
- Removed flavors

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Deploying a token for testing purposes (please DO NOT use this for production pu

Registering a token with the ``TokenNetworkRegistry`` contract, so it can be used by the Raiden Network, with the ``register`` command::

python -m raiden_contracts.deploy register --rpc-provider http://127.0.0.1:8545 --private-key /path/to/your/private_key/file --gas-price 10 --token-address TOKEN_TO_BE_REGISTERED_ADDRESS --registry-address TOKEN_NETWORK_REGISTRY_ADDRESS
python -m raiden_contracts.deploy register --rpc-provider http://127.0.0.1:8545 --private-key /path/to/your/private_key/file --gas-price 10 --token-address TOKEN_TO_BE_REGISTERED_ADDRESS --registry-address TOKEN_NETWORK_REGISTRY_ADDRESS --channel-participant-deposit-limit 115792089237316195423570985008687907853269984665640564039457584007913129639935 --token-network-deposit-limit 115792089237316195423570985008687907853269984665640564039457584007913129639935

.. Note::
Registering a token only works once. All subsequent transactions will fail.
Expand Down
20 changes: 12 additions & 8 deletions raiden_contracts/contracts/raiden/TokenNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ contract TokenNetwork is Utils {
115792089237316195423570985008687907853269984665640564039457584007913129639935
);

// Red Eyes release deposit limits
// The combined deposit of one channel is limited to 0.15 ETH.
// So 0.075 ETH per participant.
uint256 constant public channel_participant_deposit_limit = 75000000000000000 wei;
// The total combined deposit of all channels across the whole network is
// limited to 250 ETH.
uint256 constant public token_network_deposit_limit = 250000000000000000000 wei;
// The deposit limit per channel per participant.
uint256 public channel_participant_deposit_limit;
// The total combined deposit of all channels across the whole network
uint256 public token_network_deposit_limit;

// Global, monotonically increasing counter that keeps track of all the
// opened channels in this contract
Expand Down Expand Up @@ -214,7 +211,9 @@ contract TokenNetwork is Utils {
uint256 _chain_id,
uint256 _settlement_timeout_min,
uint256 _settlement_timeout_max,
address _deprecation_executor
address _deprecation_executor,
uint256 _channel_participant_deposit_limit,
uint256 _token_network_deposit_limit
)
public
{
Expand All @@ -226,6 +225,9 @@ contract TokenNetwork is Utils {
require(_settlement_timeout_max > _settlement_timeout_min);
require(contractExists(_token_address));
require(contractExists(_secret_registry));
require(_channel_participant_deposit_limit > 0);
require(_token_network_deposit_limit > 0);
require(_token_network_deposit_limit >= _channel_participant_deposit_limit);

token = Token(_token_address);

Expand All @@ -238,6 +240,8 @@ contract TokenNetwork is Utils {
require(token.totalSupply() > 0);

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

function deprecate() isSafe onlyDeprecationExecutor public {
Expand Down
10 changes: 8 additions & 2 deletions raiden_contracts/contracts/raiden/TokenNetworkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ contract TokenNetworkRegistry is Utils {
/// `_token_address`.
/// @param _token_address Ethereum address of an already deployed token, to
/// be used in the new TokenNetwork contract.
function createERC20TokenNetwork(address _token_address)
function createERC20TokenNetwork(
address _token_address,
uint256 _channel_participant_deposit_limit,
uint256 _token_network_deposit_limit
)
canCreateTokenNetwork
external
returns (address token_network_address)
Expand All @@ -79,7 +83,9 @@ contract TokenNetworkRegistry is Utils {
chain_id,
settlement_timeout_min,
settlement_timeout_max,
deprecation_executor
deprecation_executor,
_channel_participant_deposit_limit,
_token_network_deposit_limit
);

token_network_address = address(token_network);
Expand Down
12 changes: 9 additions & 3 deletions raiden_contracts/contracts/test/TokenNetworkInternalsTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ contract TokenNetworkInternalStorageTest is TokenNetwork {
_chain_id,
_settlement_timeout_min,
_settlement_timeout_max,
msg.sender
msg.sender,
MAX_SAFE_UINT256,
MAX_SAFE_UINT256
)
public
{
Expand Down Expand Up @@ -152,7 +154,9 @@ contract TokenNetworkSignatureTest is TokenNetwork {
_chain_id,
_settlement_timeout_min,
_settlement_timeout_max,
msg.sender
msg.sender,
MAX_SAFE_UINT256,
MAX_SAFE_UINT256
)
public
{
Expand Down Expand Up @@ -256,7 +260,9 @@ contract TokenNetworkUtilsTest is TokenNetwork {
_chain_id,
_settlement_timeout_min,
_settlement_timeout_max,
msg.sender
msg.sender,
MAX_SAFE_UINT256,
MAX_SAFE_UINT256
)
public
{
Expand Down
104 changes: 60 additions & 44 deletions raiden_contracts/data/contracts.json

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions raiden_contracts/data/gas.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
{
"EndpointRegistry.registerEndpoint": 48408,
"MonitoringService.claimReward": 42679,
"MonitoringService.monitor": 203858,
"OneToN.claim": 90847,
"SecretRegistry.registerSecret": 45757,
"TokenNetwork.closeChannel": 111155,
"TokenNetwork.openChannel": 97555,
"TokenNetwork.setTotalDeposit": 44509,
"TokenNetwork.settleChannel": 123370,
"TokenNetwork.unlock 1 locks": 32192,
"TokenNetwork.unlock 6 locks": 66009,
"TokenNetwork.updateNonClosingBalanceProof": 93786
"TokenNetwork DEPLOYMENT": 4031224,
"TokenNetwork.closeChannel": 111162,
"TokenNetwork.openChannel": 97745,
"TokenNetwork.setTotalDeposit": 44919,
"TokenNetwork.settleChannel": 123380,
"TokenNetwork.unlock 1 locks": 32118,
"TokenNetwork.unlock 6 locks": 66029,
"TokenNetwork.updateNonClosingBalanceProof": 93759,
"TokenNetworkRegistry DEPLOYMENT": 4753616,
"TokenNetworkRegistry createERC20TokenNetwork": 3110454,
"UserDeposit.deposit": 101311,
"UserDeposit.deposit (increase balance)": 28156,
"UserDeposit.planWithdraw": 64021,
"UserDeposit.withdraw": 40079
}
20 changes: 12 additions & 8 deletions raiden_contracts/data/source/raiden/TokenNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ contract TokenNetwork is Utils {
115792089237316195423570985008687907853269984665640564039457584007913129639935
);

// Red Eyes release deposit limits
// The combined deposit of one channel is limited to 0.15 ETH.
// So 0.075 ETH per participant.
uint256 constant public channel_participant_deposit_limit = 75000000000000000 wei;
// The total combined deposit of all channels across the whole network is
// limited to 250 ETH.
uint256 constant public token_network_deposit_limit = 250000000000000000000 wei;
// The deposit limit per channel per participant.
uint256 public channel_participant_deposit_limit;
// The total combined deposit of all channels across the whole network
uint256 public token_network_deposit_limit;

// Global, monotonically increasing counter that keeps track of all the
// opened channels in this contract
Expand Down Expand Up @@ -214,7 +211,9 @@ contract TokenNetwork is Utils {
uint256 _chain_id,
uint256 _settlement_timeout_min,
uint256 _settlement_timeout_max,
address _deprecation_executor
address _deprecation_executor,
uint256 _channel_participant_deposit_limit,
uint256 _token_network_deposit_limit
)
public
{
Expand All @@ -226,6 +225,9 @@ contract TokenNetwork is Utils {
require(_settlement_timeout_max > _settlement_timeout_min);
require(contractExists(_token_address));
require(contractExists(_secret_registry));
require(_channel_participant_deposit_limit > 0);
require(_token_network_deposit_limit > 0);
require(_token_network_deposit_limit >= _channel_participant_deposit_limit);

token = Token(_token_address);

Expand All @@ -238,6 +240,8 @@ contract TokenNetwork is Utils {
require(token.totalSupply() > 0);

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

function deprecate() isSafe onlyDeprecationExecutor public {
Expand Down
10 changes: 8 additions & 2 deletions raiden_contracts/data/source/raiden/TokenNetworkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ contract TokenNetworkRegistry is Utils {
/// `_token_address`.
/// @param _token_address Ethereum address of an already deployed token, to
/// be used in the new TokenNetwork contract.
function createERC20TokenNetwork(address _token_address)
function createERC20TokenNetwork(
address _token_address,
uint256 _channel_participant_deposit_limit,
uint256 _token_network_deposit_limit
)
canCreateTokenNetwork
external
returns (address token_network_address)
Expand All @@ -79,7 +83,9 @@ contract TokenNetworkRegistry is Utils {
chain_id,
settlement_timeout_min,
settlement_timeout_max,
deprecation_executor
deprecation_executor,
_channel_participant_deposit_limit,
_token_network_deposit_limit
);

token_network_address = address(token_network);
Expand Down
12 changes: 9 additions & 3 deletions raiden_contracts/data/source/test/TokenNetworkInternalsTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ contract TokenNetworkInternalStorageTest is TokenNetwork {
_chain_id,
_settlement_timeout_min,
_settlement_timeout_max,
msg.sender
msg.sender,
MAX_SAFE_UINT256,
MAX_SAFE_UINT256
)
public
{
Expand Down Expand Up @@ -152,7 +154,9 @@ contract TokenNetworkSignatureTest is TokenNetwork {
_chain_id,
_settlement_timeout_min,
_settlement_timeout_max,
msg.sender
msg.sender,
MAX_SAFE_UINT256,
MAX_SAFE_UINT256
)
public
{
Expand Down Expand Up @@ -256,7 +260,9 @@ contract TokenNetworkUtilsTest is TokenNetwork {
_chain_id,
_settlement_timeout_min,
_settlement_timeout_max,
msg.sender
msg.sender,
MAX_SAFE_UINT256,
MAX_SAFE_UINT256
)
public
{
Expand Down
20 changes: 20 additions & 0 deletions raiden_contracts/deploy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,18 @@ def token(
callback=validate_address,
help='Address of token network registry',
)
@click.option(
'--channel-participant-deposit-limit',
required=True,
type=int,
help='Address of token network registry',
)
@click.option(
'--token-network-deposit-limit',
required=True,
type=int,
help='Address of token network registry',
)
@click.pass_context
def register(
ctx,
Expand All @@ -451,6 +463,8 @@ def register(
contracts_version,
token_address,
registry_address,
channel_participant_deposit_limit,
token_network_deposit_limit,
):
setup_ctx(
ctx,
Expand Down Expand Up @@ -479,6 +493,8 @@ def register(
token_registry_abi=abi,
token_registry_address=ctx.obj['deployed_contracts'][CONTRACT_TOKEN_NETWORK_REGISTRY],
token_address=ctx.obj['deployed_contracts'][token_type],
channel_participant_deposit_limit=channel_participant_deposit_limit,
token_network_deposit_limit=token_network_deposit_limit,
wait=ctx.obj['wait'],
gas_price=gas_price,
token_registry_version=expected_version,
Expand Down Expand Up @@ -637,6 +653,8 @@ def register_token_network(
token_registry_address: str,
token_registry_version: str,
token_address: str,
channel_participant_deposit_limit: int,
token_network_deposit_limit: int,
wait=10,
gas_limit=4000000,
gas_price=10,
Expand All @@ -653,6 +671,8 @@ def register_token_network(

txhash = token_network_registry.functions.createERC20TokenNetwork(
token_address,
channel_participant_deposit_limit,
token_network_deposit_limit,
).transact(
{
'from': caller,
Expand Down
19 changes: 17 additions & 2 deletions raiden_contracts/tests/deprecation_switch_testnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CONTRACT_TOKEN_NETWORK_REGISTRY,
CONTRACT_TOKEN_NETWORK,
MAX_ETH_CHANNEL_PARTICIPANT,
MAX_ETH_TOKEN_NETWORK,
DEPLOY_SETTLE_TIMEOUT_MIN,
)

Expand Down Expand Up @@ -62,11 +63,18 @@ def deprecation_test(

# We deploy the Raiden Network contracts and register a token network
token_amount = MAX_ETH_CHANNEL_PARTICIPANT * 6
channel_participant_deposit_limit = MAX_ETH_CHANNEL_PARTICIPANT
token_network_deposit_limit = MAX_ETH_TOKEN_NETWORK
(
token_network_registry,
token_network,
token_contract,
) = deprecation_test_setup(deployer, token_amount)
) = deprecation_test_setup(
deployer,
token_amount,
channel_participant_deposit_limit,
token_network_deposit_limit,
)

log.info('Checking that channels can be opened and deposits can be made.')

Expand Down Expand Up @@ -96,7 +104,12 @@ def deprecation_test(
log.info('Deprecation switch test OK.')


def deprecation_test_setup(deployer, token_amount):
def deprecation_test_setup(
deployer,
token_amount,
channel_participant_deposit_limit: int,
token_network_deposit_limit: int,
):
deployed_contracts = deploy_raiden_contracts(
deployer=deployer,
max_num_of_token_networks=1,
Expand Down Expand Up @@ -146,6 +159,8 @@ def deprecation_test_setup(deployer, token_amount):
token_registry_abi=abi,
token_registry_address=deployed_contracts[CONTRACT_TOKEN_NETWORK_REGISTRY]['address'],
token_address=token_address,
channel_participant_deposit_limit=channel_participant_deposit_limit,
token_network_deposit_limit=token_network_deposit_limit,
token_registry_version=deployer.contract_manager.version_string(),
wait=deployer.wait,
)
Expand Down
Loading

0 comments on commit e300a3e

Please sign in to comment.