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

Update monitoring service to contract changes #360

Merged
merged 4 commits into from
Dec 10, 2018
Merged
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
1 change: 1 addition & 0 deletions raiden_contracts/contract_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def contracts_source_path():
return {
'raiden': _BASE.joinpath('contracts'),
'test': _BASE.joinpath('contracts', 'test'),
'services': _BASE.joinpath('contracts', 'services'),
}


Expand Down
17 changes: 8 additions & 9 deletions raiden_contracts/contracts/services/MonitoringService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "raiden/Token.sol";
import "raiden/Utils.sol";
import "raiden/lib/ECVerify.sol";
import "raiden/TokenNetwork.sol";
import "raiden/RaidenServiceBundle.sol";
import "services/RaidenServiceBundle.sol";

contract MonitoringService is Utils {
string constant public contract_version = "0.4.0";
Expand Down Expand Up @@ -204,9 +204,11 @@ contract MonitoringService is Utils {
reward_proof_signature
);
TokenNetwork token_network = TokenNetwork(token_network_address);
uint256 channel_identifier = token_network.getChannelIdentifier(closing_participant, non_closing_participant);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding the token_network_address & channel_identifier to the NewBalanceProofReceived event, so you can make a distinction between channels in time (between same participants) and between networks.

You can maybe use the reward_identifier in the event, but then again, you might want to filter all the NewBalanceProofReceived for a specific token network - so this might be over-optimizing.

Can be done in a different PR.


// Call updateTransfer in the corresponding TokenNetwork
token_network.updateNonClosingBalanceProof(
channel_identifier,
closing_participant,
non_closing_participant,
balance_hash,
Expand All @@ -230,6 +232,7 @@ contract MonitoringService is Utils {
/// @param closing_participant Address of the participant of the channel that called close
/// @param non_closing_participant The other participant of the channel
function claimReward(
uint256 channel_identifier,
address token_network_address,
address closing_participant,
address non_closing_participant
Expand All @@ -238,24 +241,20 @@ contract MonitoringService is Utils {
returns (bool)
{
TokenNetwork token_network = TokenNetwork(token_network_address);
uint256 channel_identifier = token_network.getChannelIdentifier(
closing_participant,
non_closing_participant
);
bytes32 reward_identifier = keccak256(abi.encodePacked(
channel_identifier,
token_network_address
));

// Only allowed to claim, if channel is settled
// Channel is settled if it's data has been deleted
uint8 channel_state;
(, , channel_state) = token_network.getChannelInfo(
TokenNetwork.ChannelState channel_state;
(, channel_state) = token_network.getChannelInfo(
channel_identifier,
closing_participant,
non_closing_participant
);
// If channel.state is zero it means it's either non-existing or settled
require(channel_state == 0);
require(channel_state == TokenNetwork.ChannelState.Removed);

Reward storage reward = rewards[reward_identifier];

Expand Down
2 changes: 1 addition & 1 deletion raiden_contracts/data/contracts.json

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions raiden_contracts/tests/test_monitoring_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def get(
return get


@pytest.mark.skip(reason='Monitoring Service implementation delayed to another milestone')
def test_msc_happy_path(
token_network,
monitoring_service_external,
Expand Down Expand Up @@ -69,8 +68,8 @@ def test_msc_happy_path(

# 1) open a channel (c1, c2)
channel_identifier = create_channel(A, B)[0]
txn_hash = channel_deposit(A, 20, B)
txn_hash = channel_deposit(B, 20, A)
txn_hash = channel_deposit(channel_identifier, A, 20, B)
txn_hash = channel_deposit(channel_identifier, B, 20, A)
# 2) create balance proof
balance_proof_A = create_balance_proof(channel_identifier, B, transferred_amount=10, nonce=1)
balance_proof_B = create_balance_proof(channel_identifier, A, transferred_amount=20, nonce=2)
Expand All @@ -88,8 +87,14 @@ def test_msc_happy_path(
nonce=balance_proof_B[1],
)
# 3) c1 closes channel
txn_hash = token_network.functions.closeChannel(B, *balance_proof_A).transact({'from': A})
ev_handler.add(txn_hash, ChannelEvent.CLOSED, check_channel_closed(channel_identifier, A))
txn_hash = token_network.functions.closeChannel(
channel_identifier, B, *balance_proof_A,
).transact({'from': A})
ev_handler.add(
txn_hash,
ChannelEvent.CLOSED,
check_channel_closed(channel_identifier, A, balance_proof_A[1]),
)
ev_handler.check()
# 4) MS calls `MSC::monitor()` using c1's BP and reward proof

Expand All @@ -109,6 +114,7 @@ def test_msc_happy_path(
# 6) channel is settled
token_network.web3.testing.mine(8)
token_network.functions.settleChannel(
channel_identifier,
B, # participant2
10, # participant2_transferred_amount
0, # participant2_locked_amount
Expand All @@ -120,6 +126,7 @@ def test_msc_happy_path(
).transact()
# 7) MS claims the reward
monitoring_service_external.functions.claimReward(
channel_identifier,
token_network.address,
A,
B,
Expand Down