Repository: rotki/rotki

Issue:
The backend query task died unexpectedly: Token is not ERC20 conformant
## Problem Definition

This happens always after inserting the password to the existent account.

> The backend query task died unexpectedly: Token 0x4f8AD938eBA0CD19155a835f617317a6E788c868 is not ERC20 conformant

## Logs

```
[02/12/2023 17:02:36 CET] ERROR rotkehlchen.chain.evm.node_inquirer Greenlet-0: Failed to query <bound method EvmNodeInquirer._call_contract of <rotkehlchen.chain.ethereum.node_inquirer.EthereumInquirer object at 0x7f49379adbd0>> after trying the following nodes: []
[02/12/2023 17:02:36 CET] ERROR rotkehlchen.api.rest Greenlet with id 139952428041152: Greenlet for task 0 dies with exception: Token 0x4f8AD938eBA0CD19155a835f617317a6E788c868 is not ERC20 conformant.
Exception Name: <class 'rotkehlchen.errors.misc.NotERC20Conformant'>
Exception Info: Token 0x4f8AD938eBA0CD19155a835f617317a6E788c868 is not ERC20 conformant
Traceback:
   File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
  File "rotkehlchen/api/rest.py", line 413, in _do_query_async
  File "rotkehlchen/api/rest.py", line 1126, in user_login
  File "rotkehlchen/rotkehlchen.py", line 365, in unlock_user
  File "rotkehlchen/chain/ethereum/manager.py", line 41, in __init__
  File "rotkehlchen/chain/ethereum/decoding/decoder.py", line 57, in __init__
  File "rotkehlchen/chain/evm/decoding/decoder.py", line 989, in __init__
  File "rotkehlchen/chain/evm/decoding/decoder.py", line 169, in __init__
  File "rotkehlchen/chain/evm/decoding/decoder.py", line 261, in _recursively_initialize_decoders
  File "rotkehlchen/chain/evm/decoding/decoder.py", line 194, in _add_single_decoder
  File "rotkehlchen/chain/ethereum/modules/lockedgno/decoder.py", line 48, in __init__
  File "rotkehlchen/assets/utils.py", line 228, in get_or_create_evm_token
  File "rotkehlchen/assets/utils.py", line 66, in _query_or_get_given_token_info
```

### System Description


Operating system: Linux
Rotki version: 1.31.0



Discussion:
Hey @chfast thank you for the report!

This seems like a network error of some sort which triggers an exception that should have been caught better.

Call to `0x4f8AD938eBA0CD19155a835f617317a6E788c868` decimals/name/symbol has returned error/None, so perhaps there is an eth_call error due to network error above this traceback in the logs?

And then this is not handled well in the protocol decoder for locked gno initialization and it kills the task. And that task is .. the login initialization/unlock so your login is killed? Ouch.

We will fix this but can you give some more logs from above to figure out why the `NotERC20Conformant`is raised? It's probably what I said but need to make sure that it's so. Only thing that makes sense since nobody else has been bitten by this.

Also for faster communication you can join our discord: https://discord.rotki.com/

Resolving patch:
diff --git a/rotkehlchen/chain/evm/decoding/decoder.py b/rotkehlchen/chain/evm/decoding/decoder.py
--- a/rotkehlchen/chain/evm/decoding/decoder.py
+++ b/rotkehlchen/chain/evm/decoding/decoder.py
@@ -32,7 +32,13 @@
 from rotkehlchen.db.filtering import EvmEventFilterQuery
 from rotkehlchen.db.history_events import DBHistoryEvents
 from rotkehlchen.errors.asset import UnknownAsset, WrongAssetType
-from rotkehlchen.errors.misc import InputError, ModuleLoadingError, NotERC20Conformant, RemoteError
+from rotkehlchen.errors.misc import (
+    InputError,
+    ModuleLoadingError,
+    NotERC20Conformant,
+    NotERC721Conformant,
+    RemoteError,
+)
 from rotkehlchen.errors.serialization import ConversionError, DeserializationError
 from rotkehlchen.fval import FVal
 from rotkehlchen.globaldb.handler import GlobalDBHandler
@@ -203,6 +209,12 @@ def _add_single_decoder(
                 f'{class_name} decoder due to asset mismatch: {e!s}',
             )
             return
+        except (NotERC721Conformant, NotERC20Conformant):
+            self.msg_aggregator.add_error(
+                f'Failed at initialization of {self.evm_inquirer.chain_name} '
+                f'{class_name} decoder due to non conformant token',
+            )
+            return
 
         new_input_data_rules = self.decoders[class_name].decoding_by_input_data()
         new_address_to_decoders = self.decoders[class_name].addresses_to_decoders()


Test patch:
diff --git a/rotkehlchen/tests/unit/decoders/test_main.py b/rotkehlchen/tests/unit/decoders/test_main.py
--- a/rotkehlchen/tests/unit/decoders/test_main.py
+++ b/rotkehlchen/tests/unit/decoders/test_main.py
@@ -1,4 +1,3 @@
-from typing import TYPE_CHECKING
 from unittest.mock import patch
 
 import pytest
@@ -11,6 +10,7 @@
     HistoryEventType,
 )
 from rotkehlchen.chain.ethereum.constants import CPT_KRAKEN
+from rotkehlchen.chain.ethereum.decoding.decoder import EthereumTransactionDecoder
 from rotkehlchen.chain.ethereum.transactions import EthereumTransactions
 from rotkehlchen.chain.evm.constants import GENESIS_HASH, ZERO_ADDRESS
 from rotkehlchen.chain.evm.decoding.constants import CPT_GAS
@@ -22,7 +22,7 @@
 from rotkehlchen.constants.assets import A_ETH, A_USDT
 from rotkehlchen.db.evmtx import DBEvmTx
 from rotkehlchen.db.optimismtx import DBOptimismTx
-from rotkehlchen.errors.misc import InputError
+from rotkehlchen.errors.misc import InputError, NotERC20Conformant
 from rotkehlchen.fval import FVal
 from rotkehlchen.tests.utils.constants import A_OPTIMISM_USDT
 from rotkehlchen.tests.utils.ethereum import INFURA_ETH_NODE, get_decoded_events_of_transaction
@@ -40,11 +40,8 @@
 # Have to use a constant instead of make_evm_address() because vcr doesn't work otherwise.
 ADDRESS_WITHOUT_GENESIS_TX = '0x4bBa290826C253BD854121346c370a9886d1bC26'
 
-if TYPE_CHECKING:
-    from rotkehlchen.chain.ethereum.decoding.decoder import EthereumTransactionDecoder
 
-
-def test_decoders_initialization(ethereum_transaction_decoder: 'EthereumTransactionDecoder'):
+def test_decoders_initialization(ethereum_transaction_decoder: EthereumTransactionDecoder):
     """Make sure that all decoders we have created are detected and initialized"""
     assert set(ethereum_transaction_decoder.decoders.keys()) == {
         'Aavev1',
@@ -870,3 +867,20 @@ def test_phising_zero_transfers(database, ethereum_inquirer):
         )
 
     assert ignored_actions == {ActionType.HISTORY_EVENT: {f'{ChainID.ETHEREUM.value}{tx_hex}'}}, 'Transaction with only zero transfers should have been marked as ignored'  # noqa: E501
+
+
+def test_error_at_decoder_initialization(database, ethereum_inquirer, eth_transactions):
+    """Regression test for https://github.com/rotki/rotki/issues/7039"""
+    faulty_get_or_create_evm_token = patch(
+        'rotkehlchen.chain.ethereum.modules.lockedgno.decoder.get_or_create_evm_token',
+        side_effect=NotERC20Conformant,
+    )
+    with faulty_get_or_create_evm_token:
+        decoder = EthereumTransactionDecoder(database=database, ethereum_inquirer=ethereum_inquirer, transactions=eth_transactions)  # noqa: E501
+        assert decoder is not None
+
+    errors = database.msg_aggregator.consume_errors()
+    warnings = database.msg_aggregator.consume_warnings()
+
+    assert len(warnings) == 0
+    assert errors == ['Failed at initialization of ethereum Lockedgno decoder due to non conformant token']  # noqa: E501