Skip to content

Commit 314bf12

Browse files
committed
Add function for checking whether contracts ready
1 parent 021bd07 commit 314bf12

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import time
55

6+
from contracts import get_reward_eth_contract
67
from src.merkle_distributor.distributor import Distributor
78
from src.settings import (
89
WEB3_WS_ENDPOINT,
@@ -25,7 +26,7 @@
2526
ETHERSCAN_ADDRESS_BASE_URL,
2627
)
2728
from src.staking_rewards.rewards import Rewards
28-
from src.staking_rewards.utils import wait_prysm_ready
29+
from src.staking_rewards.utils import wait_prysm_ready, wait_contracts_ready
2930
from src.utils import (
3031
get_web3_client,
3132
configure_default_account,
@@ -73,6 +74,14 @@ def main() -> None:
7374
disable_web_page_preview=True,
7475
)
7576

77+
# wait for contracts to be upgraded to the oracles supported version
78+
reward_eth = get_reward_eth_contract(web3_client)
79+
wait_contracts_ready(
80+
test_query=reward_eth.functions.lastUpdateBlockNumber(),
81+
interrupt_handler=interrupt_handler,
82+
process_interval=PROCESS_INTERVAL,
83+
)
84+
7685
# wait that node is synced before trying to do anything
7786
wait_prysm_ready(
7887
interrupt_handler=interrupt_handler,

src/staking_rewards/utils.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from grpc import insecure_channel, RpcError, StatusCode
88
from tenacity import retry, Retrying
99
from tenacity.before_sleep import before_sleep_log
10-
from typing import Set, Dict, Tuple
10+
from typing import Set, Dict, Tuple, Callable
1111
from web3 import Web3
12-
from web3.contract import Contract
12+
from web3.contract import Contract, ContractFunction
1313
from web3.exceptions import ContractLogicError
1414
from web3.types import Wei, BlockNumber, Timestamp, BlockIdentifier
1515

@@ -242,6 +242,25 @@ def get_validators_total_balance(
242242
return total_balance
243243

244244

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+
245264
def wait_prysm_ready(
246265
interrupt_handler: InterruptHandler,
247266
endpoint: str,

0 commit comments

Comments
 (0)