Repository: rotki/rotki

Issue:
Kusama/polkadot balances no longer queried properly
## Problem Definition

Seems like a substrate-interface problem.

Here is an exception from the logs

```
[12/10/2021 21:14:26 CEST] ERROR rotkehlchen.api.rest Greenlet with id 140372626234448: Greenlet for task 4 dies with exception: 'NoneType' object has no attribute 'metadata'.
Exception Name: <class 'AttributeError'>
Exception Info: 'NoneType' object has no attribute 'metadata'
Traceback:
   File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/api/rest.py", line 280, in _do_query_async
    result = getattr(self, command)(**kwargs)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/api/rest.py", line 435, in _query_all_balances
    ignore_cache=ignore_cache,
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/rotkehlchen.py", line 635, in query_balances
    ignore_cache=ignore_cache,
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/utils/mixins/lockable.py", line 46, in wrapper
    result = f(wrappingobj, *args, **kwargs)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/utils/mixins/cacheable.py", line 97, in wrapper
    result = f(wrappingobj, *args, **kwargs)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/chain/manager.py", line 573, in query_balances
    self.query_kusama_balances(ignore_cache=ignore_cache)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/utils/mixins/lockable.py", line 46, in wrapper
    result = f(wrappingobj, *args, **kwargs)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/utils/mixins/cacheable.py", line 97, in wrapper
    result = f(wrappingobj, *args, **kwargs)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/chain/manager.py", line 631, in query_kusama_balances
    account_amount = self.kusama.get_accounts_balance(self.accounts.ksm)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/chain/substrate/manager.py", line 575, in get_accounts_balance
    balances[account] = self.get_account_balance(account)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/chain/substrate/manager.py", line 89, in wrapper
    result = func(manager, *args_, **kwargs_)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/chain/substrate/manager.py", line 555, in get_account_balance
    return self._get_account_balance(account=account, node_interface=node_interface)
  File "/home/lefteris/w/rotkehlchen/rotkehlchen/chain/substrate/manager.py", line 292, in _get_account_balance
    params=[account],
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/substrateinterface/base.py", line 1387, in query
    metadata_module = self.get_metadata_module(module, block_hash=block_hash)
  File "/home/lefteris/.virtualenvs/rotkipy37/lib/python3.7/site-packages/substrateinterface/base.py", line 2126, in get_metadata_module
    for module in self.metadata_decoder.metadata.modules:

```

## Task

Fix it


Discussion:

Resolving patch:
diff --git a/rotkehlchen/chain/substrate/manager.py b/rotkehlchen/chain/substrate/manager.py
--- a/rotkehlchen/chain/substrate/manager.py
+++ b/rotkehlchen/chain/substrate/manager.py
@@ -314,6 +314,7 @@ def _get_account_balance(
             account=account,
             result=result,
         )
+
         balance = ZERO
         if result is not None:
             account_data = result.value['data']


Test patch:
diff --git a/rotkehlchen/tests/unit/test_substrate_manager.py b/rotkehlchen/tests/unit/test_substrate_manager.py
--- a/rotkehlchen/tests/unit/test_substrate_manager.py
+++ b/rotkehlchen/tests/unit/test_substrate_manager.py
@@ -15,7 +15,6 @@
 from rotkehlchen.errors import RemoteError
 from rotkehlchen.fval import FVal
 from rotkehlchen.tests.utils.substrate import (
-    SUBSTRATE_ACC1_DOT_ADDR,
     SUBSTRATE_ACC1_KSM_ADDR,
     SUBSTRATE_ACC2_KSM_ADDR,
     attempt_connect_test_nodes,
@@ -46,7 +45,7 @@ def test_get_accounts_balance_invalid_account(kusama_manager):
     node. RemoteError is raised by `request_available_nodes()`.
     """
     with pytest.raises(RemoteError) as e:
-        kusama_manager.get_accounts_balance([SUBSTRATE_ACC1_KSM_ADDR, SUBSTRATE_ACC1_DOT_ADDR])
+        kusama_manager.get_accounts_balance([SUBSTRATE_ACC1_KSM_ADDR, '13mB8stSf1vdP7WzbVr82YPgGGF7cBK9N7KxiVEac9UQgYj8'])  # noqa: E501
 
     assert 'Kusama request failed after trying the following nodes' in str(e.value)