Skip to content

Commit c2e8855

Browse files
Detailed timeout settings (#212)
* Add detailed timeouts * Edit format_error
1 parent 6cecf70 commit c2e8855

File tree

7 files changed

+222
-204
lines changed

7 files changed

+222
-204
lines changed

poetry.lock

Lines changed: 181 additions & 189 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
@@ -10,7 +10,7 @@ python-decouple = "==3.8"
1010
sentry-sdk = "==1.32.0"
1111
py-ecc = "==6.0.0"
1212
multiproof = { git = "https://github.com/stakewise/multiproof.git", rev = "v0.1.5" }
13-
sw-utils = { git = "https://github.com/stakewise/sw-utils.git", rev = "v0.3.29" }
13+
sw-utils = { git = "https://github.com/stakewise/sw-utils.git", rev = "v0.3.30" }
1414
staking-deposit = { git = "https://github.com/ethereum/staking-deposit-cli.git", rev = "v2.4.0" }
1515
pycryptodomex = "==3.19.0"
1616
milagro-bls-binding = "==1.9.0"

src/common/clients.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from web3 import AsyncWeb3
1515

1616
from src.common.wallet import hot_wallet
17-
from src.config.settings import DEFAULT_RETRY_TIME, settings
17+
from src.config.settings import settings
1818

1919
logger = logging.getLogger(__name__)
2020

@@ -30,7 +30,11 @@ def create_db_dir(self):
3030
class ExecutionClient:
3131
@cached_property
3232
def client(self) -> AsyncWeb3:
33-
w3 = get_execution_client(settings.execution_endpoints, retry_timeout=DEFAULT_RETRY_TIME)
33+
w3 = get_execution_client(
34+
settings.execution_endpoints,
35+
timeout=settings.execution_timeout,
36+
retry_timeout=settings.execution_retry_timeout,
37+
)
3438
# Account is required when emitting transactions.
3539
# For read-only queries account may be omitted.
3640
if hot_wallet.can_load():
@@ -48,7 +52,11 @@ def __getattr__(self, item):
4852
class ConsensusClient:
4953
@cached_property
5054
def client(self) -> ExtendedAsyncBeacon:
51-
return get_consensus_client(settings.consensus_endpoints, retry_timeout=DEFAULT_RETRY_TIME)
55+
return get_consensus_client(
56+
settings.consensus_endpoints,
57+
timeout=settings.consensus_timeout,
58+
retry_timeout=settings.consensus_retry_timeout,
59+
)
5260

5361
def __getattr__(self, item):
5462
return getattr(self.client, item)
@@ -57,15 +65,17 @@ def __getattr__(self, item):
5765
class IpfsFetchRetryClient:
5866
@cached_property
5967
def client(self) -> IpfsFetchClient:
60-
return IpfsFetchClient(endpoints=settings.ipfs_fetch_endpoints)
68+
return IpfsFetchClient(
69+
endpoints=settings.ipfs_fetch_endpoints, timeout=settings.ipfs_timeout
70+
)
6171

62-
@retry_ipfs_exception(delay=DEFAULT_RETRY_TIME)
6372
async def fetch_bytes(self, ipfs_hash: str) -> bytes:
64-
return await self.client.fetch_bytes(ipfs_hash)
73+
decorator = retry_ipfs_exception(delay=settings.ipfs_retry_timeout)
74+
return await decorator(self.client.fetch_bytes)(ipfs_hash)
6575

66-
@retry_ipfs_exception(delay=DEFAULT_RETRY_TIME)
6776
async def fetch_json(self, ipfs_hash: str) -> dict | list:
68-
return await self.client.fetch_json(ipfs_hash)
77+
decorator = retry_ipfs_exception(delay=settings.ipfs_retry_timeout)
78+
return await decorator(self.client.fetch_json)(ipfs_hash)
6979

7080

7181
db_client = Database()

src/common/execution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def get_oracles() -> Oracles:
4848

4949
# fetch IPFS record
5050
ipfs_hash = event['args']['configIpfsHash']
51-
config: dict = await ipfs_fetch_client.fetch_json(ipfs_hash)
51+
config: dict = await ipfs_fetch_client.fetch_json(ipfs_hash) # type: ignore
5252
rewards_threshold = await keeper_contract.get_rewards_min_oracles()
5353
validators_threshold = await keeper_contract.get_validators_min_oracles()
5454
endpoints = []

src/common/ipfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async def fetch_harvest_params(
1414
vault_address: ChecksumAddress, ipfs_hash: str, rewards_root: bytes
1515
) -> HarvestParams | None:
1616
ipfs_data = await ipfs_fetch_client.fetch_json(ipfs_hash)
17-
for vault_data in ipfs_data['vaults']:
17+
for vault_data in ipfs_data['vaults']: # type: ignore
1818
if vault_address == Web3.to_checksum_address(vault_data['vault']):
1919
unlocked_mev_reward = Wei(vault_data['unlocked_mev_reward'])
2020
reward = Wei(

src/common/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ def log_verbose(e: Exception):
4343
if settings.verbose:
4444
logger.exception(e)
4545
else:
46-
if isinstance(e, tenacity.RetryError):
47-
# get original error
48-
e = e.last_attempt.exception() # type: ignore
49-
5046
logger.error(format_error(e))
5147

5248

@@ -56,6 +52,10 @@ def warning_verbose(msg: str, *args: Any) -> None:
5652

5753

5854
def format_error(e: Exception) -> str:
55+
if isinstance(e, tenacity.RetryError):
56+
# get original error
57+
e = e.last_attempt.exception() # type: ignore
58+
5959
if isinstance(e, asyncio.TimeoutError):
6060
# str(e) returns empty string
6161
return repr(e)

src/config/settings.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ class Settings(metaclass=Singleton):
2929
vault_dir: Path
3030
network: str
3131
consensus_endpoints: list[str]
32+
consensus_timeout: int
33+
consensus_retry_timeout: int
3234
execution_endpoints: list[str]
35+
execution_timeout: int
36+
execution_retry_timeout: int
3337

3438
harvest_vault: bool
3539
verbose: bool
@@ -51,6 +55,8 @@ class Settings(metaclass=Singleton):
5155
database: Path
5256
log_level: str
5357
ipfs_fetch_endpoints: list[str]
58+
ipfs_timeout: int
59+
ipfs_retry_timeout: int
5460
validators_fetch_chunk_size: int
5561
sentry_dsn: str
5662
pool_size: int | None
@@ -146,13 +152,23 @@ def set(
146152
'http://cloudflare-ipfs.com,'
147153
'https://gateway.pinata.cloud,https://ipfs.io',
148154
)
155+
self.ipfs_timeout = decouple_config('IPFS_TIMEOUT', default=60)
156+
self.ipfs_retry_timeout = decouple_config('IPFS_RETRY_TIMEOUT', default=120)
149157
self.validators_fetch_chunk_size = decouple_config(
150158
'VALIDATORS_FETCH_CHUNK_SIZE', default=100, cast=int
151159
)
152160
self.sentry_dsn = decouple_config('SENTRY_DSN', default='')
153161
self.pool_size = decouple_config(
154162
'POOL_SIZE', default=None, cast=lambda x: int(x) if x else None
155163
)
164+
self.execution_timeout = decouple_config('EXECUTION_TIMEOUT', default=30, cast=int)
165+
self.execution_retry_timeout = decouple_config(
166+
'EXECUTION_RETRY_TIMEOUT', default=60, cast=int
167+
)
168+
self.consensus_timeout = decouple_config('CONSENSUS_TIMEOUT', default=60, cast=int)
169+
self.consensus_retry_timeout = decouple_config(
170+
'CONSENSUS_RETRY_TIMEOUT', default=120, cast=int
171+
)
156172

157173
@property
158174
def network_config(self) -> NetworkConfig:

0 commit comments

Comments
 (0)