Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MonitoringService update + contracts recompilation #747

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ python:
env:
global:
- TEST_TYPE=raiden_contracts
- SOLC_VERSION='v0.5.4'
- SOLC_VERSION='v0.5.6'
- SOLC_URL="https://github.com/ethereum/solidity/releases/download/$SOLC_VERSION/solc-static-linux"
- CODECOV_TOKEN="52f50270-3657-4f84-9e36-e6c01b2be6da"

Expand Down
1 change: 1 addition & 0 deletions raiden_contracts/contract_source_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def relativise(path):
output_values=PRECOMPILED_DATA_FIELDS + ['ast'],
import_remappings=import_dir_map,
optimize=False,
evm_version='byzantium',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think evm_version should be recorded in contracts.json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • change contract_manager.py to read/write the new field
  • set up a default value for evm_version.

Maybe I should do it later. When I modify contract_manager.py, I can also manually add the field to the existing contracts.jsons with the new solc versions.

)

# Strip `ast` part from result
Expand Down
150 changes: 75 additions & 75 deletions raiden_contracts/data/contracts.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion raiden_contracts/data/source/lib/ECVerify.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

library ECVerify {

Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/raiden/EndpointRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

/// @title Endpoint Registry
/// @notice This contract is a registry which maps an Ethereum address to its
Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/raiden/SecretRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

/// @title SecretRegistry
/// @notice SecretRegistry contract for registering secrets from Raiden Network
Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/raiden/Token.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

interface Token {

Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/raiden/TokenNetwork.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "lib/ECVerify.sol";
import "raiden/Token.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "raiden/Utils.sol";
import "raiden/Token.sol";
Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/raiden/Utils.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

/// @title Utils
/// @notice Utils contract for various helpers used by the Raiden Network smart
Expand Down
11 changes: 5 additions & 6 deletions raiden_contracts/data/source/services/MonitoringService.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "lib/ECVerify.sol";
import "raiden/Token.sol";
Expand Down Expand Up @@ -231,15 +231,14 @@ contract MonitoringService is Utils {
token_network_address
));

// Only allowed to claim, if channel is settled
// Channel is settled if it's data has been deleted
TokenNetwork.ChannelState channel_state;
(, channel_state) = token_network.getChannelInfo(
// Only allowed to claim, if channel is out of the settlement period
uint256 settle_block_number;
(settle_block_number,) = token_network.getChannelInfo(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks tricky. settle_block_number is sometimes 0, and sometimes the length of the settlement period. I think both channel_state and settle_block_number are necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, we should at least check that the channel_state is closed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should work.

channel_identifier,
closing_participant,
non_closing_participant
);
require(channel_state == TokenNetwork.ChannelState.Removed);
require(settle_block_number < block.number);

Reward storage reward = rewards[reward_identifier];

Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/services/OneToN.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "raiden/Utils.sol";
import "services/UserDeposit.sol";
Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/services/ServiceRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "raiden/Token.sol";
import "raiden/Utils.sol";
Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/services/UserDeposit.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "raiden/Token.sol";
import "raiden/Utils.sol";
Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/test/CustomToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

/*
This Token Contract implements the standard token functionality (https://github.com/ethereum/EIPs/issues/20), the ERC223 functionality (https://github.com/ethereum/EIPs/issues/223) as well as the following OPTIONAL extras intended for use by humans.
Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/test/HumanStandardToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "test/StandardToken.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "services/MonitoringService.sol";

Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/test/SignatureVerifyTest.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

/*
* This is a contract used for testing the ECVerify library and ecrecover behaviour.
Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/test/StandardToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "raiden/Token.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "raiden/TokenNetwork.sol";

Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/source/test/UDCTransfer.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.4;
pragma solidity 0.5.6;

import "services/UserDeposit.sol";

Expand Down
64 changes: 62 additions & 2 deletions raiden_contracts/tests/test_monitoring_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def monitor_data(
}


def test_claimReward(
def test_claimReward_with_settle_call(
token_network,
monitoring_service_external,
user_deposit_contract,
Expand All @@ -96,7 +96,7 @@ def test_claimReward(
monitor_data['reward_proof_signature'],
).transact({'from': ms_address})

# claiming before settlement must fail
# claiming before settlement timeout must fail
with pytest.raises(TransactionFailed):
monitoring_service_external.functions.claimReward(
channel_identifier,
Expand Down Expand Up @@ -146,6 +146,66 @@ def test_claimReward(
assert ms_balance_after_reward == REWARD_AMOUNT


def test_claimReward_without_settle_call(
token_network,
monitoring_service_external,
user_deposit_contract,
event_handler,
monitor_data,
ms_address,
):
A, B = monitor_data['participants']
channel_identifier = monitor_data['channel_identifier']

# MS updates closed channel on behalf of B
txn_hash = monitoring_service_external.functions.monitor(
A, B,
*monitor_data['balance_proof_B'],
monitor_data['non_closing_signature'],
REWARD_AMOUNT,
token_network.address,
monitor_data['reward_proof_signature'],
).transact({'from': ms_address})

# claiming before settlement timeout must fail
with pytest.raises(TransactionFailed):
monitoring_service_external.functions.claimReward(
channel_identifier,
token_network.address,
A, B,
).transact({'from': ms_address})

# Wait for settle_timeout to elapse
token_network.web3.testing.mine(8)

# Claim reward for MS
monitoring_service_external.functions.claimReward(
channel_identifier,
token_network.address,
A, B,
).transact({'from': ms_address})

# Check REWARD_CLAIMED event
reward_identifier = Web3.sha3(
encode_single('uint256', channel_identifier) +
Web3.toBytes(hexstr=token_network.address),
)
ms_ev_handler = event_handler(monitoring_service_external)
ms_ev_handler.assert_event(
txn_hash,
MonitoringServiceEvent.REWARD_CLAIMED,
dict(
ms_address=ms_address,
amount=REWARD_AMOUNT,
reward_identifier=reward_identifier,
),
)

# Check that MS balance has increased by claiming the reward
ms_balance_after_reward = user_deposit_contract.functions.balances(ms_address).call()
assert ms_balance_after_reward == REWARD_AMOUNT


def test_monitor(
token_network,
monitoring_service_external,
Expand Down