trustlines-protocol / contracts

Smart contracts for the Trustlines Protocol
https://trustlines.network/
Other
26 stars 6 forks source link

Setting a debt does not add users #368

Closed cducrest closed 3 years ago

cducrest commented 3 years ago

When setting a debt in between debtor and creditor in the network, we do not add debtor and creditor as users of the currency network.

This makes it impossible to retrieve all the potential debts in a currency network from the state as you do not who the debtors/creditors could be and events have to be used.

compojoom commented 3 years ago

How can a debtor and creditor have a debt in the currency network without being members of the currency network in the first place?

cducrest commented 3 years ago

Here's the function that track users and their friends (ppl they have tl with): https://github.com/trustlines-protocol/contracts/blob/master/contracts/currency-network/CurrencyNetworkBasic.sol#L895-L900

It is called when setting a trustlines (internal function called when opening / updating trustlines) https://github.com/trustlines-protocol/contracts/blob/master/contracts/currency-network/CurrencyNetworkBasic.sol#L1203-L1225

It is not called when updating a debt (which has nothing to do with currency networks). Debts are just a mapping from a pair of address to value. https://github.com/trustlines-protocol/contracts/blob/master/contracts/currency-network/DebtTracking.sol

You can see that DebtTracking does not extend currency networks or have anything to do with them. Eventually, there is one function that allows to withdraw from a user in a CN that has a debt towards you: https://github.com/trustlines-protocol/contracts/blob/master/contracts/currency-network/CurrencyNetwork.sol#L22

The way debt is used is to allow for delegate fees. You would for example delegate for a meta-tx of a user (e.g. the user opens a TL, or do any token transfer or get cryptokitties) and you are rewarded with the user having a debt towards you in the CN that you would eventually settle when (if) there is a path in between you and the user at some point.

The problem in solidity is that for mapping, you have no way to know the keys of the mapping. So you need to store the keys in an array. Here we would need to do the same as for user and friends, have one array of debtorsList: array(address) and one mapping of array debtors: mapping(address => array(address)) so that you can get the debtors of a credtior debtors(creditor): array(address). You'd need to update this array every time a new debt is made, this is very costly gas wise.

The other choice is to simply use userAndFriends also for the debt or not care at all and use the events when we need it.

cducrest commented 3 years ago

done