Repository: rotki/rotki

Issue:
"Could not read blocknumber from etherscan getblocknobytime result Error! No closest block found"
## Problem Definition

I updated this morning to the latest rotki version `1.31.1` and it looks like the Etherscan API is unstable. Not sure you can do much (maybe a fallback option?), but just wanted to let you know.

## Logs

![image](https://github.com/rotki/rotki/assets/25297591/703480af-3ca1-47f0-b38b-42cf1dcae933)


### System Description

Operating system: Win
Rotki version: `1.31.1`

> PS: Just tried on my Ubuntu machine, and faced the same issue


Discussion:
This is not an actionble issue. This is just a warning. If you read the entire error, you will see that etherscan, which is where we get the timestamp -> blocknumber had a problem on their side. We should probably downgrade those errors. To not appear to the user like this.
> This is not an actionble issue. This is just a warning. If you read the entire error, you will see that etherscan, which is where we get the timestamp -> blocknumber had a problem on their side. We should probably downgrade those errors. To not appear to the user like this.

Yeah, I was not sure if there is anything to do here, but figured such feedback could maybe still help wrt UX.
> This is not an actionble issue. This is just a warning. If you read the entire error, you will see that etherscan, which is where we get the timestamp -> blocknumber had a problem on their side. We should probably downgrade those errors. To not appear to the user like this.

If it is a `warning` maybe it makes sense to change it from `error` to `warning` so that it does not spam the user. By default `warning` will not popup but `error` will.

Resolving patch:
diff --git a/rotkehlchen/chain/evm/transactions.py b/rotkehlchen/chain/evm/transactions.py
--- a/rotkehlchen/chain/evm/transactions.py
+++ b/rotkehlchen/chain/evm/transactions.py
@@ -224,13 +224,18 @@ def _get_transactions_for_range(
                 )
 
             except RemoteError as e:
-                self.msg_aggregator.add_error(
+                log.error(
                     f'Got error "{e!s}" while querying {self.evm_inquirer.chain_name} '
                     f'transactions from Etherscan. Some transactions not added to the DB '
                     f'address: {address} '
                     f'from_ts: {query_start_ts} '
                     f'to_ts: {query_end_ts} ',
                 )
+                self.msg_aggregator.add_warning(
+                    f'Failed to query some transactions for {address} '
+                    f'on {self.evm_inquirer.chain_name}. '
+                    f'Please check the logs.',
+                )
                 return
 
         log.debug(f'{self.evm_inquirer.chain_name} transactions done for {address}. Update range {start_ts} - {end_ts}')  # noqa: E501
@@ -330,13 +335,18 @@ def _get_internal_transactions_for_ranges(
                     location_string=location_string,
                 )
             except RemoteError as e:
-                self.msg_aggregator.add_error(
+                log.error(
                     f'Got error "{e!s}" while querying internal {self.evm_inquirer.chain_name} '
                     f'transactions from Etherscan. Transactions not added to the DB '
                     f'address: {address} '
                     f'from_ts: {query_start_ts} '
                     f'to_ts: {query_end_ts} ',
                 )
+                self.msg_aggregator.add_warning(
+                    f'Failed to query some internal transactions for {address} '
+                    f'on {self.evm_inquirer.chain_name}. '
+                    f'Please check the logs.',
+                )
                 return
 
         log.debug(f'Internal {self.evm_inquirer.chain_name} transactions for address {address} done. Update range {start_ts} - {end_ts}')  # noqa: E501
@@ -401,13 +411,18 @@ def _get_erc20_transfers_for_ranges(
                             },
                         )
             except RemoteError as e:
-                self.msg_aggregator.add_error(
+                log.error(
                     f'Got error "{e!s}" while querying {self.evm_inquirer.chain_name} '
                     f'token transactions from Etherscan. Transactions not added to the DB '
                     f'address: {address} '
                     f'from_ts: {query_start_ts} '
                     f'to_ts: {query_end_ts} ',
                 )
+                self.msg_aggregator.add_warning(
+                    f'Failed to query some token transactions for {address} '
+                    f'on {self.evm_inquirer.chain_name}. '
+                    f'Please check the logs.',
+                )
 
         log.debug(f'{self.evm_inquirer.chain_name} ERC20 Transfers done for address {address}. Update range {start_ts} - {end_ts}')  # noqa: E501
         with self.database.user_write() as write_cursor:
@@ -480,10 +495,15 @@ def address_has_been_spammed(self, address: ChecksumEvmAddress) -> bool:
 
                     log.debug(f'Address detection: queried {self.evm_inquirer.chain_name} ERC20 Transfers for {address} -> range {start_ts} - {end_ts}')  # noqa: E501
         except RemoteError as e:
-            self.msg_aggregator.add_error(
+            log.error(
                 f'Got error "{e!s}" while querying {self.evm_inquirer.chain_name} '
                 f'token transactions from Etherscan. address: {address} spam detection failed',
             )
+            self.msg_aggregator.add_warning(
+                f'Failed to check if {address} has been spammed '
+                f'with any tokens on {self.evm_inquirer.chain_name}. '
+                f'Please check the logs.',
+            )
             return False
 
         return True


Test patch:
diff --git a/rotkehlchen/tests/api/test_balances.py b/rotkehlchen/tests/api/test_balances.py
--- a/rotkehlchen/tests/api/test_balances.py
+++ b/rotkehlchen/tests/api/test_balances.py
@@ -950,7 +950,7 @@ def mock_query_tokens(addresses):
 
     query_tokens_patch = patch('rotkehlchen.chain.evm.tokens.EvmTokens.query_tokens_for_addresses', side_effect=mock_query_tokens)  # noqa: E501
     price_inquirer_patch = patch('rotkehlchen.inquirer.Inquirer.find_usd_price', side_effect=lambda _: Price(ZERO))  # noqa: E501
-    proxies_inquirer_patch = patch('rotkehlchen.chain.evm.proxies_inquirer.EvmProxiesInquirer.get_accounts_having_proxy', side_effect=lambda: {})  # noqa: E501
+    proxies_inquirer_patch = patch('rotkehlchen.chain.evm.proxies_inquirer.EvmProxiesInquirer.get_accounts_having_proxy', side_effect=dict)  # noqa: E501
     defi_query_patch = patch('rotkehlchen.chain.ethereum.defi.zerionsdk.ZerionSDK._query_chain_for_all_balances', side_effect=lambda account: [])  # noqa: E501
     multieth_balance_patch = patch.object(chains_aggregator.ethereum.node_inquirer, 'get_multi_balance', lambda accounts: {ethereum_accounts[0]: ZERO})  # noqa: E501
     protocols_patch = patch('rotkehlchen.chain.aggregator.CHAIN_TO_BALANCE_PROTOCOLS', side_effect={ChainID.ETHEREUM: ()})  # noqa: E501
diff --git a/rotkehlchen/tests/api/test_history.py b/rotkehlchen/tests/api/test_history.py
--- a/rotkehlchen/tests/api/test_history.py
+++ b/rotkehlchen/tests/api/test_history.py
@@ -195,11 +195,11 @@ def test_query_history_remote_errors(rotkehlchen_api_server_with_exchanges):
         ],
     )
     warnings = rotki.msg_aggregator.consume_warnings()
-    assert len(warnings) == 0
+    assert len(warnings) == 9
     errors = rotki.msg_aggregator.consume_errors()
-    assert len(errors) == 11
-    assert all('kraken' in e for e in errors[:2])
-    assert 'Etherscan API request http://someurl.com returned invalid JSON response: [{' in errors[2]  # noqa: E501
+    assert len(errors) == 2
+    assert all('kraken' in e for e in errors)
+    assert 'Failed to query some token transactions for' in warnings[2]
     # The history processing is completely mocked away and omitted in this test.
     # because it is only for the history creation not its processing.
     # For history processing tests look at test_accounting.py and