Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update event scanners #434

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sentry-sdk = "==1.32.0"
py-ecc = "==6.0.0"
gql = {extras = ["aiohttp"], version = "==3.5.0"}
multiproof = { git = "https://github.com/stakewise/multiproof.git", rev = "v0.1.8" }
sw-utils = {git = "https://github.com/stakewise/sw-utils.git", rev = "v0.6.27"}
sw-utils = {git = "https://github.com/stakewise/sw-utils.git", rev = "v0.6.31"}
staking-deposit = { git = "https://github.com/ethereum/staking-deposit-cli.git", rev = "v2.4.0" }
pycryptodomex = "3.19.1"
click = "==8.1.7"
Expand Down
12 changes: 11 additions & 1 deletion src/common/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ class ExecutionClient:
client: AsyncWeb3
is_set_up = False

def __init__(self, use_retries: bool = True) -> None:
self.use_retries = use_retries

async def setup(self) -> None:
if not any(settings.execution_endpoints):
return

retry_timeout = 0
if self.use_retries:
retry_timeout = settings.execution_retry_timeout

w3 = get_execution_client(
settings.execution_endpoints,
timeout=settings.execution_timeout,
retry_timeout=settings.execution_retry_timeout,
retry_timeout=retry_timeout,
jwt_secret=settings.execution_jwt_secret,
)
# Account is required when emitting transactions.
Expand Down Expand Up @@ -89,9 +97,11 @@ async def fetch_json(self, ipfs_hash: str) -> dict | list:

db_client = Database()
execution_client = cast(AsyncWeb3, ExecutionClient())
execution_non_retry_client = cast(AsyncWeb3, ExecutionClient(use_retries=False))
consensus_client = cast(ExtendedAsyncBeacon, ConsensusClient())
ipfs_fetch_client = IpfsLazyFetchClient()


async def setup_clients() -> None:
await execution_client.setup() # type: ignore
await execution_non_retry_client.setup() # type: ignore
15 changes: 9 additions & 6 deletions src/common/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from eth_typing import HexStr
from sw_utils.typings import Bytes32
from web3 import Web3
from web3 import AsyncWeb3, Web3
from web3.contract import AsyncContract
from web3.contract.async_contract import (
AsyncContractEvent,
Expand All @@ -15,7 +15,7 @@
)
from web3.types import BlockNumber, ChecksumAddress, EventData

from src.common.clients import execution_client
from src.common.clients import execution_client as default_execution_client
from src.common.typings import HarvestParams, RewardVoteInfo
from src.config.settings import settings

Expand All @@ -26,6 +26,9 @@ class ContractWrapper:
abi_path: str = ''
settings_key: str = ''

def __init__(self, execution_client: AsyncWeb3 | None = None):
self.execution_client = execution_client or default_execution_client

@property
def contract_address(self) -> ChecksumAddress:
return getattr(settings.network_config, self.settings_key)
Expand All @@ -35,7 +38,7 @@ def contract(self) -> AsyncContract:
current_dir = os.path.dirname(__file__)
with open(os.path.join(current_dir, self.abi_path), encoding='utf-8') as f:
abi = json.load(f)
return execution_client.eth.contract(abi=abi, address=self.contract_address)
return self.execution_client.eth.contract(abi=abi, address=self.contract_address)

@property
def address(self) -> ChecksumAddress:
Expand Down Expand Up @@ -208,15 +211,15 @@ async def get_config_updated_event(
return await self._get_last_event(
self.events.ConfigUpdated, # type: ignore
from_block=from_block or settings.network_config.KEEPER_GENESIS_BLOCK,
to_block=to_block or await execution_client.eth.get_block_number(),
to_block=to_block or await self.execution_client.eth.get_block_number(),
)

async def get_last_rewards_update(self) -> RewardVoteInfo | None:
"""Fetches the last rewards update."""
last_event = await self._get_last_event(
self.events.RewardsUpdated, # type: ignore
from_block=settings.network_config.KEEPER_GENESIS_BLOCK,
to_block=await execution_client.eth.get_block_number(),
to_block=await self.execution_client.eth.get_block_number(),
)
if not last_event:
return None
Expand All @@ -234,7 +237,7 @@ async def get_exit_signatures_updated_event(
to_block: BlockNumber | None = None,
) -> EventData | None:
from_block = from_block or settings.network_config.KEEPER_GENESIS_BLOCK
to_block = to_block or await execution_client.eth.get_block_number()
to_block = to_block or await self.execution_client.eth.get_block_number()

last_event = await self._get_last_event(
self.events.ExitSignaturesUpdated, # type: ignore
Expand Down
9 changes: 6 additions & 3 deletions src/validators/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from web3 import Web3
from web3.types import EventData, Wei

from src.common.clients import execution_non_retry_client
from src.common.contracts import (
ValidatorsRegistryContract,
multicall_contract,
validators_registry_contract,
vault_contract,
Expand All @@ -28,9 +30,10 @@
class NetworkValidatorsProcessor(EventProcessor):
contract_event = 'DepositEvent'

@property
def contract(self): # type: ignore
return validators_registry_contract
def __init__(self) -> None:
self.contract = ValidatorsRegistryContract(
execution_client=execution_non_retry_client
).contract

@staticmethod
async def get_from_block() -> BlockNumber:
Expand Down
Loading