Skip to content

Commit

Permalink
Add approvals interval
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise committed Dec 1, 2023
1 parent 8fe024c commit 7d525ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/exits/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import logging
import time
from random import shuffle

from eth_typing import BlockNumber, BLSPubkey
Expand Down Expand Up @@ -118,7 +119,11 @@ async def _update_exit_signatures(
# pylint: disable=duplicate-code
validators = await get_validator_public_keys(outdated_indexes)
deadline = None
approvals_min_interval = 1

while True:
approval_start_time = time.time()

current_timestamp = get_current_timestamp()
if not deadline or deadline <= current_timestamp:
deadline = current_timestamp + oracles.signature_validity_period
Expand All @@ -145,6 +150,8 @@ async def _update_exit_signatures(
e.threshold,
', '.join(e.failed_endpoints),
)
approvals_time = time.time() - approval_start_time
await asyncio.sleep(approvals_min_interval - approvals_time)

tx_hash = await submit_exit_signatures(oracles_approval)
if not tx_hash:
Expand Down
9 changes: 9 additions & 0 deletions src/validators/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
import logging
import time

from eth_typing import BLSPubkey
from multiproof.standard import MultiProof
Expand Down Expand Up @@ -102,7 +104,11 @@ async def register_validators(
registry_root = None
oracles_request = None
deadline = get_current_timestamp() + oracles.signature_validity_period
approvals_min_interval = 1

while True:
approval_start_time = time.time()

latest_registry_root = await validators_registry_contract.get_registry_root()
current_timestamp = get_current_timestamp()
if (
Expand Down Expand Up @@ -140,6 +146,9 @@ async def register_validators(
e.threshold,
', '.join(e.failed_endpoints),
)
approvals_time = time.time() - approval_start_time
await asyncio.sleep(approvals_min_interval - approvals_time)

# compare validators root just before transaction to reduce reverted calls
if registry_root != await validators_registry_contract.get_registry_root():
logger.info(
Expand Down

0 comments on commit 7d525ac

Please sign in to comment.