Token network registry preconditions#4936
Conversation
| raise InvalidTokenAddress("The call to register a token at 0x00..00 will fail.") | ||
|
|
||
| token_proxy = self.blockchain_service.token(token_address) | ||
| try: |
There was a problem hiding this comment.
Checklist of the preconditions:
-
canCreateTokenNetworkmodified -
require(token_to_token_networks[_token_address] == address(0x0));, done byalready_registered = self.get_token_network -
require(_token_address != address(0x0));, done above byif token_address == NULL_ADDRESS_BYTES: -
require(_secret_registry != address(0x0));, checked implicitly, if the registry exist this value is not zero. -
require(_deprecation_executor != address(0x0));, checked implicitly, if the registry exist this value is not zero. -
require(_chain_id > 0);, checked implicitly, if the registry exist this value is not zero. -
require(_settlement_timeout_min > 0);, checked implicitly, if the registry exist this value is not zero. -
require(_settlement_timeout_max > _settlement_timeout_min);, checked implicitly, if the registry exist this value is greater than the min. -
require(contractExists(_token_address));, checked implicitly, if the proxy exist the address was checked for code. -
require(contractExists(_secret_registry));, checked implicitly, if the registry exist this value is greater than the min. -
require(_token_network_deposit_limit > 0); -
require(_token_network_deposit_limit >= _channel_participant_deposit_limit); -
require(token.totalSupply() > 0);, done bytoken_supply = token_proxy.total_supply(block_identifier=block_identifier).
There was a problem hiding this comment.
btw, the checks for:
require(_token_network_deposit_limit > 0);
require(_token_network_deposit_limit >= _channel_participant_deposit_limit);
can be done above, together with the check for the NULL_ADDRESS_BYTES.
|
|
||
| token_proxy = self.blockchain_service.token(token_address) | ||
| try: | ||
| token_supply = token_proxy.total_supply(block_identifier=block_identifier) |
There was a problem hiding this comment.
side note, can you try this out and see if the proxy will raise an exception instead of returning ""? The RPC call does return "", and back in the day when we used the JSONRPCClient to do these requests that was the value we got. However, I believe that web3 will actually check if the return type of the called function matches the value returned by the RPC call, and if the types don't match I believe it will raise an exception. In this case the total_supply ABI says the return type is an int, so I think that an exception will be raised here. You can easily check that by instantiating a Token proxy using the TokenNetworkRegistry address and calling the function.
- Follow the token network pruned blocks handling pattern - Added transaction / gas estimation failure checks
| "The chain ID property for the TokenNetworkRegistry is invalid." | ||
| ) | ||
|
|
||
| if chain_id != self.blockchain_service.network_id: |
There was a problem hiding this comment.
I think we should not check this. After a fork, there will be a fork with the original chain_id and another fork with a different chain_id. The choice is on the user.
There was a problem hiding this comment.
That's not something we have to handle. Because when the user runs Raiden, it is ran on a specific chain ID. If there was a fork at some point and the user choose to use that new chain, Raiden has to be restarted to use that chain which will have a new ID.
There was a problem hiding this comment.
- We deploy the contract on
chain_id == 1and storechain_id == 1in the contract - A fork happens into
chain_ids 1 and 231. - A user tries to use the smart contract on chain 231.
In this case, the smart contract still remembers chain_id == 1 (that's the left hand side). But blockchain_service.network_id points to 231 because now the user is trying to use chain_id 231. So the check fails here. If the proxy allows, the transaction would succeed onchain because on-chain we don't check that the chain_id is a particular value.
There was a problem hiding this comment.
I already know that the user runs Raiden on a specific chain ID, but I see the problem ^.
There was a problem hiding this comment.
Isn't it also a problem that we store the chain id in the contract though? If there is a fork and both sides survive (let's say 1 and 231 per your example), the contracts would need to be redeployed in 231 chain.
If they are not then the on-chain chain_id would be wrong and as such all functions using it such as recoverAddressFromBalanceProof() would not work.
There was a problem hiding this comment.
Currently, the onchain chain_id would be wrong. That's why no strict checks should be performed with it.
| "The chain ID property for the TokenNetworkRegistry is invalid." | ||
| ) | ||
|
|
||
| if chain_id != self.blockchain_service.network_id: |
There was a problem hiding this comment.
Here too, this check is nowhere in smart contracts. And I think Raiden should be usable on both chains after a fork.
|
|
||
| # check preconditions | ||
| if token_network_deposit_limit <= 0: | ||
| raise InvalidTokenNetworkDepositLimit( |
There was a problem hiding this comment.
I heard that the proxies should not raise specific errors. This should be BrokenPreconditionError. #4878 (comment)
There was a problem hiding this comment.
@pirapira No... it seems like the definition is still vague. This should not be a precondition error.
There was a problem hiding this comment.
token_network_deposit_limit > 0 is a precondition. Here we're in a proxy and checking a precondition before estimating the gas. So the exception should be BrokenPreconditionError.
Codecov Report
@@ Coverage Diff @@
## develop #4936 +/- ##
===========================================
- Coverage 80.79% 80.39% -0.41%
===========================================
Files 120 120
Lines 14514 14604 +90
Branches 2238 2265 +27
===========================================
+ Hits 11727 11741 +14
- Misses 2134 2193 +59
- Partials 653 670 +17
Continue to review full report at Codecov.
|
| class InvalidTokenNetworkDepositLimit(RaidenError): | ||
| """ Raised when an invalid token network deposit | ||
| limit is passed to the token network registry proxy. | ||
| """ |
There was a problem hiding this comment.
This can happen only when the API didn't check enough conditions. This should crash the node with BrokenPreconditionError.
| class InvalidChannelParticipantDepositLimit(RaidenError): | ||
| """ Raised when an invalid channel participant | ||
| deposit limit is passed to the token network registry proxy. | ||
| """ |
There was a problem hiding this comment.
This can only happen when the API didn't check the condition. This situation should crash the node with BrokenPreconditionError.
Merge after #4876
Fixes: #4889
Fixes: #4888
Fixes: #4886
Fixes: #4884
Fixes #4882
Description
Please, describe what this PR does in detail:
PR review check list
Quality check list that cannot be automatically verified.