Skip to content

Commit 1983300

Browse files
authored
Update event scanners (#434)
* Update event scanners Signed-off-by: cyc60 <avsysoev60@gmail.com> * Review fix Signed-off-by: cyc60 <avsysoev60@gmail.com> * Review fix Signed-off-by: cyc60 <avsysoev60@gmail.com> --------- Signed-off-by: cyc60 <avsysoev60@gmail.com>
1 parent 748793a commit 1983300

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sentry-sdk = "==1.32.0"
1212
py-ecc = "==6.0.0"
1313
gql = {extras = ["aiohttp"], version = "==3.5.0"}
1414
multiproof = { git = "https://github.com/stakewise/multiproof.git", rev = "v0.1.8" }
15-
sw-utils = {git = "https://github.com/stakewise/sw-utils.git", rev = "v0.6.27"}
15+
sw-utils = {git = "https://github.com/stakewise/sw-utils.git", rev = "v0.6.31"}
1616
staking-deposit = { git = "https://github.com/ethereum/staking-deposit-cli.git", rev = "v2.4.0" }
1717
pycryptodomex = "3.19.1"
1818
click = "==8.1.7"

src/common/clients.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,21 @@ class ExecutionClient:
3131
client: AsyncWeb3
3232
is_set_up = False
3333

34+
def __init__(self, use_retries: bool = True) -> None:
35+
self.use_retries = use_retries
36+
3437
async def setup(self) -> None:
3538
if not any(settings.execution_endpoints):
3639
return
40+
41+
retry_timeout = 0
42+
if self.use_retries:
43+
retry_timeout = settings.execution_retry_timeout
44+
3745
w3 = get_execution_client(
3846
settings.execution_endpoints,
3947
timeout=settings.execution_timeout,
40-
retry_timeout=settings.execution_retry_timeout,
48+
retry_timeout=retry_timeout,
4149
jwt_secret=settings.execution_jwt_secret,
4250
)
4351
# Account is required when emitting transactions.
@@ -89,9 +97,11 @@ async def fetch_json(self, ipfs_hash: str) -> dict | list:
8997

9098
db_client = Database()
9199
execution_client = cast(AsyncWeb3, ExecutionClient())
100+
execution_non_retry_client = cast(AsyncWeb3, ExecutionClient(use_retries=False))
92101
consensus_client = cast(ExtendedAsyncBeacon, ConsensusClient())
93102
ipfs_fetch_client = IpfsLazyFetchClient()
94103

95104

96105
async def setup_clients() -> None:
97106
await execution_client.setup() # type: ignore
107+
await execution_non_retry_client.setup() # type: ignore

src/common/contracts.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from eth_typing import HexStr
88
from sw_utils.typings import Bytes32
9-
from web3 import Web3
9+
from web3 import AsyncWeb3, Web3
1010
from web3.contract import AsyncContract
1111
from web3.contract.async_contract import (
1212
AsyncContractEvent,
@@ -15,7 +15,7 @@
1515
)
1616
from web3.types import BlockNumber, ChecksumAddress, EventData
1717

18-
from src.common.clients import execution_client
18+
from src.common.clients import execution_client as default_execution_client
1919
from src.common.typings import HarvestParams, RewardVoteInfo
2020
from src.config.settings import settings
2121

@@ -26,6 +26,9 @@ class ContractWrapper:
2626
abi_path: str = ''
2727
settings_key: str = ''
2828

29+
def __init__(self, execution_client: AsyncWeb3 | None = None):
30+
self.execution_client = execution_client or default_execution_client
31+
2932
@property
3033
def contract_address(self) -> ChecksumAddress:
3134
return getattr(settings.network_config, self.settings_key)
@@ -35,7 +38,7 @@ def contract(self) -> AsyncContract:
3538
current_dir = os.path.dirname(__file__)
3639
with open(os.path.join(current_dir, self.abi_path), encoding='utf-8') as f:
3740
abi = json.load(f)
38-
return execution_client.eth.contract(abi=abi, address=self.contract_address)
41+
return self.execution_client.eth.contract(abi=abi, address=self.contract_address)
3942

4043
@property
4144
def address(self) -> ChecksumAddress:
@@ -208,15 +211,15 @@ async def get_config_updated_event(
208211
return await self._get_last_event(
209212
self.events.ConfigUpdated, # type: ignore
210213
from_block=from_block or settings.network_config.KEEPER_GENESIS_BLOCK,
211-
to_block=to_block or await execution_client.eth.get_block_number(),
214+
to_block=to_block or await self.execution_client.eth.get_block_number(),
212215
)
213216

214217
async def get_last_rewards_update(self) -> RewardVoteInfo | None:
215218
"""Fetches the last rewards update."""
216219
last_event = await self._get_last_event(
217220
self.events.RewardsUpdated, # type: ignore
218221
from_block=settings.network_config.KEEPER_GENESIS_BLOCK,
219-
to_block=await execution_client.eth.get_block_number(),
222+
to_block=await self.execution_client.eth.get_block_number(),
220223
)
221224
if not last_event:
222225
return None
@@ -234,7 +237,7 @@ async def get_exit_signatures_updated_event(
234237
to_block: BlockNumber | None = None,
235238
) -> EventData | None:
236239
from_block = from_block or settings.network_config.KEEPER_GENESIS_BLOCK
237-
to_block = to_block or await execution_client.eth.get_block_number()
240+
to_block = to_block or await self.execution_client.eth.get_block_number()
238241

239242
last_event = await self._get_last_event(
240243
self.events.ExitSignaturesUpdated, # type: ignore

src/validators/execution.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from web3 import Web3
99
from web3.types import EventData, Wei
1010

11+
from src.common.clients import execution_non_retry_client
1112
from src.common.contracts import (
13+
ValidatorsRegistryContract,
1214
multicall_contract,
1315
validators_registry_contract,
1416
vault_contract,
@@ -28,9 +30,10 @@
2830
class NetworkValidatorsProcessor(EventProcessor):
2931
contract_event = 'DepositEvent'
3032

31-
@property
32-
def contract(self): # type: ignore
33-
return validators_registry_contract
33+
def __init__(self) -> None:
34+
self.contract = ValidatorsRegistryContract(
35+
execution_client=execution_non_retry_client
36+
).contract
3437

3538
@staticmethod
3639
async def get_from_block() -> BlockNumber:

0 commit comments

Comments
 (0)