Closed LefterisJP closed 5 years ago
Follow up to our discussion: Checking unlock: According to the database i have from @kelsos, i can see that his node tried to unlock:
Event: ContractSendChannelBatchUnlock
{'token_address': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 'token_network_identifier': '0xa5C9ECf54790334B73E5DfA1ff5668eB425dC474', 'channel_identifier': '84', 'participant': '0xB2C94bBaf307C6DfBf70Cc2537385553385a345b'}
Is generated as an event when handling the ContractReceiveChannelSettled
at block 5915982
.
Kelsos will share futher details on what happened to the unlock transaction
After looking at the logs with @rakanalh it seems as he already mentioned that the node tried to unlock but then failed to do so due to the following error:
{
"event": "Failed to find state/event that match current channel locksroots. token:0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 token_network:0xa5C9ECf54790334B73E5DfA1ff5668eB425dC474 channel:84 participant:0xB2C94bBaf307C6DfBf70Cc2537385553385a345b our_locksroot:0xba531c7f2735ceb72a1bd8c4776afcea9ac4390ad2b73050033fdd8863984f81 partner_locksroot:0xba531c7f2 735ceb72a1bd8c4776afcea9ac4390ad2b73050033fdd8863984f81 ",
"logger": "raiden.raiden_service",
"level": "error",
"greenlet_name": "AlarmTask|Greenlet-2",
"timestamp": "2018-12-19 17:01:46.562389"
}
You can find the full log file here
our_locksroot:0xba531c7f2735ceb72a1bd8c4776afcea9ac4390ad2b73050033fdd8863984f81
partner_locksroot:0xba531c7f2735ceb72a1bd8c4776afcea9ac4390ad2b73050033fdd8863984f81
same locksroot on both sides?
@konradkonrad
They got the same locked amount too. Assuming they used the same script to send payments and they are all payments of 1 token the merkle tree and thus the root would be identical I suppose.
Wait that does not sound right ... let me have a look.
Additional note: As you can see from the logs in the backstory above this is same locksroot Kelsos used at closing and Cosmin at updating. And also same with settle.
Even if the locked amount is the same since the merkle tree contains the lockhashes, so also the secrethashes the hash can not be the same. We got a problem here.
Problem Definition
The balance returned from the API for a channel does not take the locked amount into account. The channel schema returns the balance here and it uses
channel.get_balance()
https://github.com/raiden-network/raiden/blob/b757d2c9593116780c0a71fa7127dec1e084d6a2/raiden/transfer/channel.py#L787-L804
That function contains only the finalized balance and completely ignores the locked amount. This is not what a user would expect as his balance -- especially since after settle as per the spec what you get out is minus the locked amount.
S1 = D1 - W1 + T2 - T1 - L1
So settling a channel would give you less than your balance would show in the API which is wrong and creates wrong expectations.
Task
There is already a function that does what we want. It's called
get_distributable()
https://github.com/raiden-network/raiden/blob/b757d2c9593116780c0a71fa7127dec1e084d6a2/raiden/transfer/channel.py#L824-L844
So we can simply use this in the API for returning the expected balance.
Still to be discussed: Does having
channel.get_balance()
with its current implementation make sense? It does not seem to be used anywhere else apart from tests and confuses people as to what a balance is. I think it is semantically wrong.Backstory
We noticed this problem during a settlement scenario where people did not get back as much as their balance was after settle.
Information on that channel follows:
channel: 84 Kelsos (settler + closer): 4d6fa60e64c7e520899a9aedd40cb1e6992027f0 Cosmin: b2c94bbaf307c6dfbf70cc2537385553385a345b
Open channel: https://etherscan.io/tx/0x23935f8b39366cf7af58da73e9418a91ad65bb1f188680cf448b79eb2038d9af#decodetab
Close transaction: https://etherscan.io/tx/0x9f1c2d92e29ede0c19f87456ee3ca341c0b78f97df58b492b243269f5f039c71
0xb2c94bbaf307c6dfbf70cc2537385553385a345b setTotalDeposit 20: https://etherscan.io/tx/0x97195897b702309faa356d43a949b2801fe63782e12e14460c88731bce0a28c0#decodetab
4d6fa60e64c7e520899a9aedd40cb1e6992027f0 setTotalDeposit 50: https://etherscan.io/tx/0x1957ee719cc6ee702ba82a1953839ad97e4d69b231e137c64ced56e7ea4184d0#decodetab
b2c94bbaf307c6dfbf70cc2537385553385a345b setTotalDeposit 30049: https://etherscan.io/tx/0x654270b77a041e344becc8ea380808e5cbce69affd5d00e48f6b1a55ce6e2aa6#decodetab
b2c94bbaf307c6dfbf70cc2537385553385a345b setTotalDeposit 30049: https://etherscan.io/tx/0x654270b77a041e344becc8ea380808e5cbce69affd5d00e48f6b1a55ce6e2aa6#decodetab
b2c94bbaf307c6dfbf70cc2537385553385a345b setTotalDeposit 300000000030050: https://etherscan.io/tx/0x5c7f1f2c50dc1dc552e555e3e925b71732a6d50b6626765bbef6c5f12b39f1e6#decodetab
4d6fa60e64c7e520899a9aedd40cb1e6992027f0 closes channel: https://etherscan.io/tx/0x9f1c2d92e29ede0c19f87456ee3ca341c0b78f97df58b492b243269f5f039c71#decodetab
0xb2c94bbaf307c6dfbf70cc2537385553385a345b updates transfer: https://etherscan.io/tx/0x3ffdf9efca9610ab866e77463a000fe5159364ca5844ab0c61a0d9ce2176da99#decodetab
0x4d6fa60e64c7e520899a9aedd40cb1e6992027f0 settles channel: https://etherscan.io/tx/0x1bfd96784e8610866f65a6619a4601c3441ebb4cb553b242a8f3f6211817bde0
From Logs when kelsos closed
From logs when Cosmin settled
What was further misleading is that the contract code has a link to an issue at whose beginning has a settle spec of a particular git commit. And at that commit the spec shows a wrong amount for
S1
.S1 = D1 - W1 + T2 - T1
But that is fixed in latest master. Suggestion: Change that comment in issue 188 to point to the latest spec.