diff --git a/src/metrics/metrics.py b/src/metrics/metrics.py index 5324cdf9..6c7c8272 100644 --- a/src/metrics/metrics.py +++ b/src/metrics/metrics.py @@ -119,6 +119,13 @@ namespace=PROMETHEUS_PREFIX, ) +GUARDIAN_BALANCE = Gauge( + 'guardian_balance', + 'Balance of the guardian', + ['address', 'chain_id'], + namespace=PROMETHEUS_PREFIX, +) + MODULES = Gauge('modules', 'Modules gauge', ['module_id'], namespace=PROMETHEUS_PREFIX) for module_id in DEPOSIT_MODULES_WHITELIST: diff --git a/src/transport/msg_providers/onchain_transport.py b/src/transport/msg_providers/onchain_transport.py index ee6750b6..5f1ec982 100644 --- a/src/transport/msg_providers/onchain_transport.py +++ b/src/transport/msg_providers/onchain_transport.py @@ -4,6 +4,7 @@ from eth_typing import ChecksumAddress from eth_utils import to_bytes +from metrics.metrics import GUARDIAN_BALANCE from schema import Schema from transport.msg_providers.common import BaseMessageProvider from transport.msg_providers.rabbit import MessageType @@ -269,13 +270,17 @@ def _fetch_messages(self) -> list: if from_block == latest_block_number: return [] event_ids = [self._w3.keccak(text=parser.message_abi) for parser in self._parsers] - addresses_with_padding = [_32padding_address(address) for address in self._allowed_guardians_provider()] + guardians = self._allowed_guardians_provider() + addresses_with_padding = [_32padding_address(address) for address in guardians] filter_params = FilterParams( fromBlock=from_block, toBlock=latest_block_number, address=self._onchain_address, topics=[event_ids, addresses_with_padding], ) + for guard in guardians: + balance = self._w3.eth.get_balance(guard) + GUARDIAN_BALANCE.labels(address=guard, chain_id=self._chain_id).set(balance) try: logs = self._w3.eth.get_logs(filter_params) if logs: diff --git a/tests/fixtures/provider.py b/tests/fixtures/provider.py index 3a26e27e..bb453c79 100644 --- a/tests/fixtures/provider.py +++ b/tests/fixtures/provider.py @@ -34,7 +34,9 @@ def web3_provider_integration(request) -> Web3: variables.WEB3_RPC_ENDPOINTS[0], block_num, ): - yield Web3(HTTPProvider('http://127.0.0.1:8545', request_kwargs={'timeout': 3600})) + web3 = Web3(HTTPProvider('http://127.0.0.1:8545', request_kwargs={'timeout': 3600})) + assert web3.is_connected() + yield web3 @pytest.fixture diff --git a/tests/transport/test_data_bus.py b/tests/transport/test_data_bus.py index 2e110e3e..5f504a95 100644 --- a/tests/transport/test_data_bus.py +++ b/tests/transport/test_data_bus.py @@ -33,19 +33,14 @@ # DATA_BUS_ADDRESS: '0x5FbDB2315678afecb367f032d93F642f64180aa3' # } @pytest.mark.integration_chiado -@pytest.mark.parametrize( - 'web3_provider_integration', - [12217621], - indirect=['web3_provider_integration'], -) def test_data_bus_provider( - web3_provider_integration, web3_transaction_integration, ): """ Utilise this function for an adhoc testing of data bus transport """ variables.ONCHAIN_TRANSPORT_ADDRESS = ChecksumAddress(HexAddress(HexStr('0x37De961D6bb5865867aDd416be07189D2Dd960e6'))) + web3_transaction_integration.eth.get_balance = Mock(return_value=1) provider = OnchainTransportProvider( w3=web3_transaction_integration, onchain_address=variables.ONCHAIN_TRANSPORT_ADDRESS, @@ -63,17 +58,11 @@ def test_data_bus_provider( allowed_guardians_provider=lambda: [Web3.to_checksum_address(_DEFAULT_GUARDIAN)], ) messages = provider.get_messages() - assert len(messages) == 75 + assert messages @pytest.mark.integration_chiado -@pytest.mark.parametrize( - 'web3_provider_integration', - [12217621], - indirect=['web3_provider_integration'], -) def test_data_bus_provider_unvet( - web3_provider_integration, web3_transaction_integration, ): """ @@ -123,13 +112,7 @@ def test_data_bus_provider_unvet( @pytest.mark.integration_chiado -@pytest.mark.parametrize( - 'web3_provider_integration', - [12217621], - indirect=['web3_provider_integration'], -) def test_data_bus_provider_pause_v2( - web3_provider_integration, web3_transaction_integration, ): """ @@ -175,13 +158,7 @@ def test_data_bus_provider_pause_v2( @pytest.mark.integration_chiado -@pytest.mark.parametrize( - 'web3_provider_integration', - [12217621], - indirect=['web3_provider_integration'], -) def test_data_bus_provider_pause_v3( - web3_provider_integration, web3_transaction_integration, ): """ @@ -224,6 +201,7 @@ def test_data_bus_mock_responses(web3_lido_unit): receipts = mock_receipts(web3_lido_unit) web3_lido_unit.eth.get_logs = Mock(side_effect=[receipts, None]) web3_lido_unit.is_connected = Mock(return_value=True) + web3_lido_unit.eth.get_balance = Mock(return_value=1) web3_lido_unit.eth.get_block_number = Mock(return_value=1) provider = OnchainTransportProvider( w3=web3_lido_unit,