diff --git a/eth_validator_watcher/beacon.py b/eth_validator_watcher/beacon.py index 5f9524c..8dec50f 100644 --- a/eth_validator_watcher/beacon.py +++ b/eth_validator_watcher/beacon.py @@ -240,7 +240,7 @@ def get_rewards( self, beacon_type: BeaconType, epoch: int, - validators_index: Optional[set[int]] = None, + validators_index: set[int] | None = None, ) -> Rewards: """Get rewards. @@ -333,7 +333,7 @@ def get_validators_liveness( return {item.index: item.is_live for item in validators_liveness.data} - def get_potential_block(self, slot) -> Optional[Block]: + def get_potential_block(self, slot) -> Block | None: """Get a block if it exists, otherwise return None. Parameters: diff --git a/eth_validator_watcher/entrypoint.py b/eth_validator_watcher/entrypoint.py index 1b740b4..ddeb684 100644 --- a/eth_validator_watcher/entrypoint.py +++ b/eth_validator_watcher/entrypoint.py @@ -78,7 +78,8 @@ def handler( beacon_url: str = Option(..., help="URL of beacon node", show_default=False), execution_url: str = Option(None, help="URL of execution node", show_default=False), - pubkeys_file_path: Optional[Path] = Option( + pubkeys_file_path: Path + | None = Option( None, help="File containing the list of public keys to watch", exists=True, @@ -86,15 +87,18 @@ def handler( dir_okay=False, show_default=False, ), - web3signer_url: Optional[str] = Option( + web3signer_url: str + | None = Option( None, help="URL to web3signer managing keys to watch", show_default=False ), - fee_recipient: Optional[str] = Option( + fee_recipient: str + | None = Option( None, help="Fee recipient address - --execution-url must be set", show_default=False, ), - slack_channel: Optional[str] = Option( + slack_channel: str + | None = Option( None, help="Slack channel to send alerts - SLACK_TOKEN env var must be set", show_default=False, @@ -116,9 +120,7 @@ def handler( relay_url: List[str] = Option( [], help="URL of allow listed relay", show_default=False ), - liveness_file: Optional[Path] = Option( - None, help="Liveness file", show_default=False - ), + liveness_file: Path | None = Option(None, help="Liveness file", show_default=False), ) -> None: """ 🚨 Ethereum Validator Watcher 🚨 @@ -188,14 +190,14 @@ def handler( def _handler( beacon_url: str, - execution_url: Optional[str], - pubkeys_file_path: Optional[Path], - web3signer_url: Optional[str], - fee_recipient: Optional[str], - slack_channel: Optional[str], + execution_url: str | None, + pubkeys_file_path: Path | None, + web3signer_url: str | None, + fee_recipient: str | None, + slack_channel: str | None, beacon_type: BeaconType, relays_url: List[str], - liveness_file: Optional[Path], + liveness_file: Path | None, ) -> None: """Just a wrapper to be able to test the handler function""" slack_token = environ.get("SLACK_TOKEN") @@ -240,11 +242,11 @@ def _handler( exited_validators = ExitedValidators(slack) slashed_validators = SlashedValidators(slack) - last_missed_attestations_process_epoch: Optional[int] = None - last_rewards_process_epoch: Optional[int] = None + last_missed_attestations_process_epoch: int | None = None + last_rewards_process_epoch: int | None = None - previous_epoch: Optional[int] = None - last_processed_finalized_slot: Optional[int] = None + previous_epoch: int | None = None + last_processed_finalized_slot: int | None = None genesis = beacon.get_genesis() diff --git a/eth_validator_watcher/exited_validators.py b/eth_validator_watcher/exited_validators.py index 5911e63..f568034 100644 --- a/eth_validator_watcher/exited_validators.py +++ b/eth_validator_watcher/exited_validators.py @@ -1,7 +1,6 @@ """Contains the ExitedValidators class, which is responsible for managing the exited validators.""" -from typing import Optional from prometheus_client import Gauge @@ -17,13 +16,13 @@ class ExitedValidators: """Exited validators abstraction.""" - def __init__(self, slack: Optional[Slack]) -> None: + def __init__(self, slack: Slack | None) -> None: """Exited validators Parameters: slack: Optional slack client """ - self.__our_exited_unslashed_indexes: Optional[set[int]] = None + self.__our_exited_unslashed_indexes: set[int] | None = None self.__slack = slack def process( diff --git a/eth_validator_watcher/fee_recipient.py b/eth_validator_watcher/fee_recipient.py index 636ceea..d3b3b40 100644 --- a/eth_validator_watcher/fee_recipient.py +++ b/eth_validator_watcher/fee_recipient.py @@ -1,6 +1,5 @@ """Contains the logic to check if the fee recipient is the one expected.""" -from typing import Optional from prometheus_client import Counter @@ -17,9 +16,9 @@ def process_fee_recipient( block: Block, index_to_validator: dict[int, Validators.DataItem.Validator], - execution: Optional[Execution], - expected_fee_recipient: Optional[str], - slack: Optional[Slack], + execution: Execution | None, + expected_fee_recipient: str | None, + slack: Slack | None, ) -> None: """Check if the fee recipient is the one expected. diff --git a/eth_validator_watcher/missed_attestations.py b/eth_validator_watcher/missed_attestations.py index a84208d..d2b8e76 100644 --- a/eth_validator_watcher/missed_attestations.py +++ b/eth_validator_watcher/missed_attestations.py @@ -1,7 +1,6 @@ """Contains the logic to check if the validators missed attestations.""" import functools -from typing import Optional, Set from prometheus_client import Gauge @@ -87,8 +86,8 @@ def process_double_missed_attestations( previous_dead_indexes: set[int], epoch_to_index_to_validator_index: LimitedDict, epoch: int, - slack: Optional[Slack], -) -> Set[int]: + slack: Slack | None, +) -> set[int]: """Process double missed attestations. Parameters: diff --git a/eth_validator_watcher/missed_blocks.py b/eth_validator_watcher/missed_blocks.py index 7303124..7c5aec6 100644 --- a/eth_validator_watcher/missed_blocks.py +++ b/eth_validator_watcher/missed_blocks.py @@ -1,7 +1,6 @@ """Contains functions to handle missed block proposals detection on head""" import functools -from typing import Optional from prometheus_client import Counter @@ -36,10 +35,10 @@ def process_missed_blocks_head( beacon: Beacon, - potential_block: Optional[Block], + potential_block: Block | None, slot: int, our_pubkeys: set[str], - slack: Optional[Slack], + slack: Slack | None, ) -> bool: """Process missed block proposals detection at head @@ -111,7 +110,7 @@ def process_missed_blocks_finalized( last_processed_finalized_slot: int, slot: int, our_pubkeys: set[str], - slack: Optional[Slack], + slack: Slack | None, ) -> int: """Process missed block proposals detection at finalized diff --git a/eth_validator_watcher/models.py b/eth_validator_watcher/models.py index 8be76f6..7e72d64 100644 --- a/eth_validator_watcher/models.py +++ b/eth_validator_watcher/models.py @@ -1,7 +1,6 @@ """Contains the models for the validator watcher.""" from enum import StrEnum -from typing import Optional from pydantic import BaseModel @@ -153,7 +152,7 @@ class EthGetBlockByHashRequest(BaseModel): class ExecutionBlock(BaseModel): class Result(BaseModel): class Transaction(BaseModel): - to: Optional[str] + to: str | None transactions: list[Transaction] diff --git a/eth_validator_watcher/slashed_validators.py b/eth_validator_watcher/slashed_validators.py index 2f3fdf0..f189629 100644 --- a/eth_validator_watcher/slashed_validators.py +++ b/eth_validator_watcher/slashed_validators.py @@ -1,8 +1,5 @@ """Contains the SlashedValidators class, which is responsible for managing the slashed validators.""" - -from typing import Optional - from prometheus_client import Gauge from .models import Validators @@ -22,14 +19,14 @@ class SlashedValidators: """Slashed validators abstraction.""" - def __init__(self, slack: Optional[Slack]) -> None: + def __init__(self, slack: Slack | None) -> None: """Slashed validators Parameters: slack: Optional slack client """ - self.__total_exited_slashed_indexes: Optional[set[int]] = None - self.__our_exited_slashed_indexes: Optional[set[int]] = None + self.__total_exited_slashed_indexes: set[int] | None = None + self.__our_exited_slashed_indexes: set[int] | None = None self.__slack = slack def process( diff --git a/eth_validator_watcher/utils.py b/eth_validator_watcher/utils.py index f8af7c3..f1ecff5 100644 --- a/eth_validator_watcher/utils.py +++ b/eth_validator_watcher/utils.py @@ -184,8 +184,8 @@ def load_pubkeys_from_file(path: Path) -> set[str]: def get_our_pubkeys( - pubkeys_file_path: Optional[Path], - web3signer: Optional[Web3Signer], + pubkeys_file_path: Path | None, + web3signer: Web3Signer | None, ) -> set[str]: """Get our pubkeys diff --git a/tests/entrypoint/test__handler.py b/tests/entrypoint/test__handler.py index ea708c5..d960d47 100644 --- a/tests/entrypoint/test__handler.py +++ b/tests/entrypoint/test__handler.py @@ -2,15 +2,14 @@ from pathlib import Path from typing import Iterator, Optional, Tuple -from freezegun import freeze_time -from pytest import raises -from typer import BadParameter - from eth_validator_watcher import entrypoint from eth_validator_watcher.entrypoint import _handler from eth_validator_watcher.models import BeaconType, Genesis, Validators from eth_validator_watcher.utils import LimitedDict, Slack from eth_validator_watcher.web3signer import Web3Signer +from freezegun import freeze_time +from pytest import raises +from typer import BadParameter StatusEnum = Validators.DataItem.StatusEnum Validator = Validators.DataItem.Validator @@ -199,7 +198,7 @@ def get_status_to_index_to_validator( }, } - def get_potential_block(self, slot: int) -> Optional[str]: + def get_potential_block(self, slot: int) -> str | None: assert slot in {63, 64} return "A BLOCK" @@ -291,7 +290,7 @@ def process_missed_blocks_finalized( def process_suboptimal_attestations( beacon: Beacon, - potential_block: Optional[str], + potential_block: str | None, slot: int, index_to_validator: dict[int, Validator], ) -> set[int]: @@ -308,7 +307,7 @@ def process_suboptimal_attestations( def process_missed_blocks( beacon: Beacon, - potential_block: Optional[str], + potential_block: str | None, slot: int, pubkeys: set[str], slack: Slack, diff --git a/tests/rewards/test_process_rewards_net.py b/tests/rewards/test_process_rewards_net.py index 43019ca..bf823cb 100644 --- a/tests/rewards/test_process_rewards_net.py +++ b/tests/rewards/test_process_rewards_net.py @@ -1,5 +1,4 @@ from math import isclose -from typing import Optional from eth_validator_watcher.models import BeaconType, Rewards, Validators from eth_validator_watcher.rewards import ( @@ -53,7 +52,7 @@ def get_rewards( self, beacon_type: BeaconType, epoch: int, - validators_index: Optional[set[int]] = None, + validators_index: set[int] | None = None, ) -> Rewards: assert isinstance(beacon_type, BeaconType) assert epoch == 40 @@ -184,7 +183,7 @@ def get_rewards( self, beacon_type: BeaconType, epoch: int, - validators_index: Optional[set[int]] = None, + validators_index: set[int] | None = None, ) -> Rewards: assert isinstance(beacon_type, BeaconType) assert epoch == 40 @@ -375,7 +374,7 @@ def get_rewards( self, beacon_type: BeaconType, epoch: int, - validators_index: Optional[set[int]] = None, + validators_index: set[int] | None = None, ) -> Rewards: assert isinstance(beacon_type, BeaconType) assert epoch == 40 diff --git a/tests/rewards/test_process_rewards_our.py b/tests/rewards/test_process_rewards_our.py index b096967..0af2e26 100644 --- a/tests/rewards/test_process_rewards_our.py +++ b/tests/rewards/test_process_rewards_our.py @@ -1,5 +1,4 @@ from math import isclose -from typing import Optional from eth_validator_watcher.models import BeaconType, Rewards, Validators from eth_validator_watcher.rewards import ( @@ -27,7 +26,7 @@ def get_rewards( self, beacon_type: BeaconType, epoch: int, - validators_index: Optional[set[int]] = None, + validators_index: set[int] | None = None, ) -> Rewards: assert isinstance(beacon_type, BeaconType) assert epoch == 40 @@ -158,7 +157,7 @@ def get_rewards( self, beacon_type: BeaconType, epoch: int, - validators_index: Optional[set[int]] = None, + validators_index: set[int] | None = None, ) -> Rewards: assert isinstance(beacon_type, BeaconType) assert epoch == 40 @@ -349,7 +348,7 @@ def get_rewards( self, beacon_type: BeaconType, epoch: int, - validators_index: Optional[set[int]] = None, + validators_index: set[int] | None = None, ) -> Rewards: assert isinstance(beacon_type, BeaconType) assert epoch == 40