Repository: rotki/rotki

Issue:
Make node management and status dynamic
## Abstract

At the moment it is evm or ksm/polkadot so we can make it dynamic in a way that when a new evm chain is added this automatically adds a new tab.

We also need to update the status which might require changes in the periodic.

```json
{
 "connected_eth_nodes": [],
 "connected_optimism_nodes": []
}
```
Should change to make it dynamic and easier to retrieve using the chain id:
```json
{
  "connected_nodes": { 
    "eth": [],
    "optimism": []
  }
}
```
## Motivation

Make dynamic so that new chains automatically get added without too much of frontend work.

## Specification

Decide how to handle the first part, maybe just add a tab for every txChain?



Discussion:

Resolving patch:
diff --git a/rotkehlchen/chain/aggregator.py b/rotkehlchen/chain/aggregator.py
--- a/rotkehlchen/chain/aggregator.py
+++ b/rotkehlchen/chain/aggregator.py
@@ -4,7 +4,17 @@
 from collections.abc import Iterator, Sequence
 from importlib import import_module
 from pathlib import Path
-from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, TypeVar, cast, overload
+from typing import (
+    TYPE_CHECKING,
+    Any,
+    Callable,
+    Literal,
+    Optional,
+    TypeVar,
+    cast,
+    get_args,
+    overload,
+)
 
 from gevent.lock import Semaphore
 from web3.exceptions import BadFunctionCallOutput
@@ -1486,6 +1496,11 @@ def detect_evm_accounts(
 
         return added_accounts
 
+    def iterate_evm_chain_managers(self) -> Iterator['EvmManager']:
+        """Iterate the supported evm chain managers"""
+        for chain_id in get_args(SUPPORTED_CHAIN_IDS):
+            yield self.get_evm_manager(chain_id)
+
     def flush_eth2_cache(self) -> None:
         self.flush_cache('get_eth2_staking_details')
         self.flush_cache('get_eth2_history_events')
diff --git a/rotkehlchen/rotkehlchen.py b/rotkehlchen/rotkehlchen.py
--- a/rotkehlchen/rotkehlchen.py
+++ b/rotkehlchen/rotkehlchen.py
@@ -1085,16 +1085,17 @@ def setup_exchange(
             )
         return is_success, msg
 
-    def query_periodic_data(self) -> dict[str, Union[bool, list[str], Timestamp]]:
+    def query_periodic_data(self) -> dict[str, Union[bool, dict[str, list[str]], Timestamp]]:
         """Query for frequently changing data"""
-        result: dict[str, Union[bool, list[str], Timestamp]] = {}
+        result: dict[str, Union[bool, dict[str, list[str]], Timestamp]] = {}
 
         if self.user_is_logged_in:
             with self.data.db.conn.read_ctx() as cursor:
                 result['last_balance_save'] = self.data.db.get_last_balance_save_time(cursor)
-                result['connected_eth_nodes'] = [node.name for node in self.chains_aggregator.ethereum.node_inquirer.get_connected_nodes()]  # noqa: E501
-                result['connected_optimism_nodes'] = [node.name for node in self.chains_aggregator.optimism.node_inquirer.get_connected_nodes()]  # noqa: E501
-                result['connected_polygon_pos_nodes'] = [node.name for node in self.chains_aggregator.polygon_pos.node_inquirer.get_connected_nodes()]  # noqa: E501
+                connected_nodes = {}
+                for evm_manager in self.chains_aggregator.iterate_evm_chain_managers():
+                    connected_nodes[evm_manager.node_inquirer.chain_name] = [node.name for node in evm_manager.node_inquirer.get_connected_nodes()]  # noqa: E501
+                result['connected_nodes'] = connected_nodes
                 result['last_data_upload_ts'] = Timestamp(self.premium_sync_manager.last_data_upload_ts)  # noqa: E501
         return result
 


Test patch:
diff --git a/rotkehlchen/tests/api/test_periodic.py b/rotkehlchen/tests/api/test_periodic.py
--- a/rotkehlchen/tests/api/test_periodic.py
+++ b/rotkehlchen/tests/api/test_periodic.py
@@ -33,10 +33,11 @@ def test_query_periodic(rotkehlchen_api_server_with_exchanges):
         api_url_for(rotkehlchen_api_server_with_exchanges, 'periodicdataresource'),
     )
     result = assert_proper_response_with_result(response)
-    assert len(result) == 5
+    assert len(result) == 3
     assert result['last_balance_save'] >= start_ts
-    assert result['connected_eth_nodes'] == []
-    assert result['connected_optimism_nodes'] == []
-    assert result['connected_polygon_pos_nodes'] == []
+    connected_nodes = result['connected_nodes']
+    assert len(connected_nodes) == len(list(rotki.chains_aggregator.iterate_evm_chain_managers()))
+    for evm_manager in rotki.chains_aggregator.iterate_evm_chain_managers():
+        assert connected_nodes[evm_manager.node_inquirer.chain_name] == []
     # Non -1 value tests for these exist in test_history.py::test_query_history_timerange
     assert result['last_data_upload_ts'] == 0