-
Notifications
You must be signed in to change notification settings - Fork 376
-
Notifications
You must be signed in to change notification settings - Fork 376
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
ChannelStateSchema.get_balance returns distributable #4348
Comments
This function is used to calculate the value for a field Gives this this is plain wrong and should be fixed. The remaining question for me is whether or not we should return the distributable in the API as well? |
I remember seeing a PR by @hackaugusto recently touching on this subject. Perhaps he is the best person to weigh in here. I see 3 terms here. Let's simply define them in the spec and make sure the code reflects them. I don't think we should expose more in the API since it's already confusing enough. So in the spec I only see capacity defined in the terminology as
Interestingly enough there is more info on the glossary of the docs of this repo ...
First of all let's perhaps clear up the spec/specs and keep it all in one place well defined. Secondly what should be exposed in the API? I suppose what I care about is how much I have available to send. So that would be the balance only? @palango The distributable you propose is what? The capacity? Aka sum of balances? |
@LefterisJP The code defines it as follows: """Return the amount of tokens that can be used by the `sender`.
The returned value is limited to a UINT256, since that is the representation
used in the smart contracts and we cannot use a larger value. The limit is
enforced on transferred_amount + locked_amount to avoid overflows. This is
an additional security check.
"""
...
distributable = get_balance(sender, receiver) - get_amount_locked(sender) So |
I see. Hmmm then we should add it to the spec by the way. I guess this is not what I would be most interested in. How much I have available to send on this channel is not something that can be consumed nicely, what you need to know is your balance first and foremost right? I suppose the problem is that there is always the incoming + outgoing channel. If you have locked transfers due to just being a node in the network and mediating:
And now that I am mentioning that ... looking at the linked code it seems that the API calls it balance, but returns the distributable. So this should change anyway. |
In the mediation scenario balance would change as well, just later than distributable: return Balance(
sender.contract_balance
- max(sender.offchain_total_withdraw, sender.onchain_total_withdraw)
- sender_transferred_amount
+ receiver_transferred_amount
)
That's exactly what the issue is about ;) |
Hmm you are right. Then we should maybe see balance as that of the incoming + outgoing channel? I guess as a user what do I expect the term balance to mean? Something that changes only when I perform an action and not something that changes depending on payments being mediated through me.
I am slow :) |
True, but that info here is the per-channel info, so I guess we cannot work around it like that. I guess it would make sense to return distributable as well, because it's a better upper bound. |
According to the glossary, the capacity does not care about locks:
while the term "distributable" does:
distributable = get_balance(sender, receiver) - get_amount_locked(sender)
Since these two terms mean different things, the following code is wrong or at least highly misleading:
The text was updated successfully, but these errors were encountered: