|
7 | 7 | from grpc import insecure_channel, RpcError, StatusCode |
8 | 8 | from tenacity import retry, Retrying |
9 | 9 | from tenacity.before_sleep import before_sleep_log |
10 | | -from typing import Set, Dict, Tuple |
| 10 | +from typing import Set, Dict, Tuple, Callable |
11 | 11 | from web3 import Web3 |
12 | | -from web3.contract import Contract |
| 12 | +from web3.contract import Contract, ContractFunction |
13 | 13 | from web3.exceptions import ContractLogicError |
14 | 14 | from web3.types import Wei, BlockNumber, Timestamp, BlockIdentifier |
15 | 15 |
|
@@ -242,6 +242,25 @@ def get_validators_total_balance( |
242 | 242 | return total_balance |
243 | 243 |
|
244 | 244 |
|
| 245 | +def wait_contracts_ready( |
| 246 | + test_query: ContractFunction, |
| 247 | + interrupt_handler: InterruptHandler, |
| 248 | + process_interval: int, |
| 249 | +) -> None: |
| 250 | + """ |
| 251 | + Wait that smart contracts are ready to for interactions. |
| 252 | + """ |
| 253 | + while not interrupt_handler.exit: |
| 254 | + try: |
| 255 | + # This will bomb with ContractLogicError if contract are not ready |
| 256 | + test_query.call() |
| 257 | + break |
| 258 | + except ContractLogicError: |
| 259 | + logger.warning("Waiting for contracts to be upgraded...") |
| 260 | + |
| 261 | + time.sleep(process_interval) |
| 262 | + |
| 263 | + |
245 | 264 | def wait_prysm_ready( |
246 | 265 | interrupt_handler: InterruptHandler, |
247 | 266 | endpoint: str, |
|
0 commit comments