Repository: rotki/rotki

Issue:
DAI in DSR multiplies every time I refresh blockchain balances
## Problem Definition

As described above, my 10 DAI in Oasis Saving turn into 20 DAI, then 30 DAI, and so on every time I hit refresh on blockchain balance.

### System Description

Running Appimage Rotki on Fedora 32.


Discussion:
Could you provide a little more information?
* Does the balance revert to the "correct" balance if you browse away from the dashboard and back to the dashboard, or does it stay incorrect?
* Does the balance revert to the "correct" balance if you restart the application?
* If you go to the "Accounts & Balances" page and then scroll to the "Blockchain Balances per Asset" balances, is the DAI balance matching what you see in the dashboard or is it "correct"?
* If you go to the "Accounts & Balances" page and then scroll down to your "ETH per account balances" balances, is the account that that DAI is in also being inflated?
Of course! My bad!

It only reverts to the correct amount after I quit the application then restart it/log in. Browsing away or to Dashboard and Account & Balances still shows the incorrect, multiplied amount of DAI. And my ETH and every other Token balance stays as the correct amount throughout the process.

TL;DR  1. Stays incorrect  2.Yes  3. Matches what I see in the dashboard (incorrect amount) 4. Yes, also incorrect amount.
No need to apologize! Thanks for the quick follow-up, it really helps.

It looks like the issue is in the frontend which means that your saved balances are not incorrect -- which is great!. We will try to reproduce and fix ASAP.
We checked a bit and it may also be in the backend. Since the amount also seems to get appended again in the network tab. Will take a deeper look and hopefully solve it today.

Resolving patch:
diff --git a/rotkehlchen/chain/manager.py b/rotkehlchen/chain/manager.py
--- a/rotkehlchen/chain/manager.py
+++ b/rotkehlchen/chain/manager.py
@@ -876,6 +876,14 @@ def query_ethereum_tokens(
         - EthSyncError if querying the token balances through a provided ethereum
         client and the chain is not synced
         """
+        # Clear out all previous token balances. If token is "tracked" via the owned
+        # tokens just zero out its balance
+        for token in [x for x, _ in self.totals.items() if isinstance(x, EthereumToken)]:
+            if token not in self.owned_eth_tokens:
+                del self.totals[token]
+            else:
+                self.totals[token] = Balance()
+
         try:
             self._query_ethereum_tokens_alethio(action=AccountAction.QUERY)
         except RemoteError as e:


Test patch:
diff --git a/rotkehlchen/tests/api/test_assets.py b/rotkehlchen/tests/api/test_assets.py
--- a/rotkehlchen/tests/api/test_assets.py
+++ b/rotkehlchen/tests/api/test_assets.py
@@ -25,7 +25,11 @@ def test_query_owned_assets(
     # Disable caching of query results
     rotki = rotkehlchen_api_server_with_exchanges.rest_api.rotkehlchen
     rotki.chain_manager.cache_ttl_secs = 0
-    setup = setup_balances(rotki, ethereum_accounts, btc_accounts)
+    setup = setup_balances(
+        rotki=rotki,
+        ethereum_accounts=ethereum_accounts,
+        btc_accounts=btc_accounts,
+    )
 
     # Get all our mocked balances and save them in the DB
     with ExitStack() as stack: