Skip to content

Commit

Permalink
Add participant addresses to ChannelSettled event
Browse files Browse the repository at this point in the history
The `participant1_*` and `participant2_*` arguments were useless,
because it was not able to determine what partner corresponds
to the arguments. By adding the addresses this problem is solved.
  • Loading branch information
ezdac committed Jul 29, 2021
1 parent 9a1563c commit 8291b19
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 42 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ Documents changes that result in:
- API changes in the package (externally used constants, externally used utilities and scripts)
- important bug fixes between releases

- [#1494](https://github.com/raiden-network/raiden-contracts/pull/1494) Add both participants addresses to the `TokenNetwork.ChannelSettled` event
- [#1436](https://github.com/raiden-network/raiden-contracts/issues/1436) Add `TokenNetwork.openChannelWithDeposit`, which combines opening and depositing to a channel
- [#1482](https://github.com/raiden-network/raiden-contracts/issues/1482) Add `UserDeposit.withdrawToBeneficiary`, which allows withdrawing to a beneficiary
- [#1383](https://github.com/raiden-network/raiden-contracts/issues/1383) Add `TokenNetwork.cooperativeSettle`, which settles the channel in a single transaction when the participants cooperate


## [0.38.0]
- [#1462](https://github.com/raiden-network/raiden-contracts/pull/1462) TokenNetwork: allow updating channel state anytime before a channel is settled
- [#1464](https://github.com/raiden-network/raiden-contracts/pull/1464) Use RDN as default token for service payments
Expand Down
94 changes: 71 additions & 23 deletions raiden_contracts/data/contracts.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions raiden_contracts/data/gas.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{
"CustomToken.approve": 46080,
"CustomToken.mint": 50646,
"CustomToken.transfer": 36412,
"CustomToken.transferFrom": 28922,
"CustomToken.transfer": 36388,
"CustomToken.transferFrom": 28910,
"MonitoringService.claimReward": 45932,
"MonitoringService.monitor": 230910,
"OneToN.bulkClaim 1 ious": 106352,
"OneToN.bulkClaim 6 ious": 161946,
"MonitoringService.monitor": 230868,
"OneToN.bulkClaim 1 ious": 106369,
"OneToN.bulkClaim 6 ious": 161958,
"OneToN.claim": 103666,
"SecretRegistry.registerSecret": 46297,
"SecretRegistry.registerSecretBatch1": 46759,
"SecretRegistry.registerSecretBatch2": 71519,
"SecretRegistry.registerSecretBatch3": 96279,
"ServiceRegistry.deposit": 570886,
"ServiceRegistry.setURL": 47223,
"TokenNetwork DEPLOYMENT": 4266574,
"TokenNetwork.closeChannel": 122795,
"TokenNetwork.cooperativeSettle": 122309,
"TokenNetwork DEPLOYMENT": 4288115,
"TokenNetwork.closeChannel": 122802,
"TokenNetwork.cooperativeSettle": 123080,
"TokenNetwork.openChannel": 115046,
"TokenNetwork.openChannelWithDeposit": 153235,
"TokenNetwork.setTotalDeposit": 58441,
"TokenNetwork.setTotalWithdraw": 120351,
"TokenNetwork.settleChannel": 115054,
"TokenNetwork.settleChannel": 115432,
"TokenNetwork.unlock 1 locks": 45079,
"TokenNetwork.unlock 6 locks": 61780,
"TokenNetwork.updateNonClosingBalanceProof": 94597,
"TokenNetworkRegistry DEPLOYMENT": 4850894,
"TokenNetworkRegistry createERC20TokenNetwork": 4024953,
"TokenNetwork.unlock 6 locks": 61756,
"TokenNetwork.updateNonClosingBalanceProof": 94609,
"TokenNetworkRegistry DEPLOYMENT": 4872448,
"TokenNetworkRegistry createERC20TokenNetwork": 4045003,
"TokenNetworkUtils DEPLOYMENT": 307459,
"UserDeposit.deposit": 98239,
"UserDeposit.deposit (increase balance)": 34039,
Expand Down
6 changes: 5 additions & 1 deletion raiden_contracts/data/source/raiden/TokenNetwork.sol
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ contract TokenNetwork is Utils {

event ChannelSettled(
uint256 indexed channel_identifier,
address participant1,
uint256 participant1_amount,
bytes32 participant1_locksroot,
address participant2,
uint256 participant2_amount,
bytes32 participant2_locksroot
);
Expand Down Expand Up @@ -559,7 +561,7 @@ contract TokenNetwork is Utils {
}
removeChannelData(channel, channel_identifier, data1.participant, data2.participant);

emit ChannelSettled(channel_identifier, data1.total_withdraw, 0, data2.total_withdraw, 0);
emit ChannelSettled(channel_identifier, data1.participant, data1.total_withdraw, 0, data2.participant, data2.total_withdraw, 0);
}

/// @notice Close the channel defined by the two participant addresses.
Expand Down Expand Up @@ -873,8 +875,10 @@ contract TokenNetwork is Utils {

emit ChannelSettled(
channel_identifier,
participant1,
participant1_settlement.transferred_amount,
participant1_settlement.locksroot,
participant2,
participant2_settlement.transferred_amount,
participant2_settlement.locksroot
);
Expand Down
12 changes: 10 additions & 2 deletions raiden_contracts/tests/test_channel_cooperative_settle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from web3.exceptions import ValidationError

from raiden_contracts.constants import EMPTY_ADDRESS, ChannelEvent
from raiden_contracts.tests.utils import call_and_transact
from raiden_contracts.tests.utils import EMPTY_LOCKSROOT, call_and_transact
from raiden_contracts.utils.events import check_channel_settled, check_withdraw_2
from raiden_contracts.utils.type_aliases import BlockExpiration

Expand Down Expand Up @@ -611,6 +611,14 @@ def test_cooperative_settle_channel_event(
ev_handler.add(
txn_hash,
ChannelEvent.SETTLED,
check_channel_settled(channel_identifier, balance_B, balance_A),
check_channel_settled(
channel_identifier,
B,
balance_B,
EMPTY_LOCKSROOT,
A,
balance_A,
EMPTY_LOCKSROOT,
),
)
ev_handler.check()
8 changes: 7 additions & 1 deletion raiden_contracts/tests/test_channel_settle.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,5 +733,11 @@ def test_settle_channel_event(
{"from": A},
)

ev_handler.add(txn_hash, ChannelEvent.SETTLED, check_channel_settled(channel_identifier, 5, 5))
ev_handler.add(
txn_hash,
ChannelEvent.SETTLED,
check_channel_settled(
channel_identifier, B, 5, LOCKSROOT_OF_NO_LOCKS, A, 5, LOCKSROOT_OF_NO_LOCKS
),
)
ev_handler.check()
9 changes: 8 additions & 1 deletion raiden_contracts/tests/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@
from eth_utils.units import units

from raiden_contracts.utils.signature import private_key_to_address
from raiden_contracts.utils.type_aliases import AdditionalHash, BalanceHash, PrivateKey, Signature
from raiden_contracts.utils.type_aliases import (
AdditionalHash,
BalanceHash,
Locksroot,
PrivateKey,
Signature,
)

UINT256_MAX = 2 ** 256 - 1
NOT_ADDRESS = "0xaaa"
FAKE_ADDRESS = HexAddress(HexStr("0x00112233445566778899aabbccddeeff00112233"))
EMPTY_HEXADDRESS = "0x0000000000000000000000000000000000000000"
EMPTY_BALANCE_HASH = BalanceHash(b"\x00" * 32)
EMPTY_ADDITIONAL_HASH = AdditionalHash(b"\x00" * 32)
EMPTY_LOCKSROOT = Locksroot(b"\x00" * 32)
EMPTY_SIGNATURE = Signature(b"\x00" * 65)
passphrase = "0"
FAUCET_PRIVATE_KEY = PrivateKey(
Expand Down
12 changes: 11 additions & 1 deletion raiden_contracts/utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,21 @@ def get(event: Dict[str, Any]) -> None:


def check_channel_settled(
channel_identifier: int, participant1_amount: int, participant2_amount: int
channel_identifier: int,
participant1: HexAddress,
participant1_amount: int,
participant1_locksroot: bytes,
participant2: HexAddress,
participant2_amount: int,
participant2_locksroot: bytes,
) -> Callable[[Dict[str, Any]], None]:
def get(event: Dict[str, Any]) -> None:
assert event["args"]["channel_identifier"] == channel_identifier
assert event["args"]["participant1"] == participant1
assert event["args"]["participant1_amount"] == participant1_amount
assert event["args"]["participant1_locksroot"] == participant1_locksroot
assert event["args"]["participant2"] == participant2
assert event["args"]["participant2_amount"] == participant2_amount
assert event["args"]["participant2_locksroot"] == participant2_locksroot

return get

0 comments on commit 8291b19

Please sign in to comment.