Skip to content

Commit

Permalink
Add deadline for exit-sig-update
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise committed Aug 9, 2023
1 parent 277eaa6 commit 6f83529
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/exits/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ async def submit_exit_signatures(

logger.info('Submitting UpdateExitSignatures transaction')
tx = await keeper_contract.functions.updateExitSignatures(
settings.vault,
approval.ipfs_hash,
approval.signatures,
settings.vault, approval.ipfs_hash, approval.signatures, int(approval.deadline.timestamp())
).transact()
logger.info('Waiting for transaction %s confirmation', Web3.to_hex(tx))
await execution_client.eth.wait_for_transaction_receipt(tx, timeout=300)
8 changes: 4 additions & 4 deletions src/exits/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import random
from datetime import datetime, timedelta
from urllib.parse import urljoin

import aiohttp
Expand Down Expand Up @@ -64,13 +65,15 @@ async def get_oracles_approval(
) -> OraclesApproval:
"""Fetches approval from oracles."""
fork = await consensus_client.get_consensus_fork()
deadline = datetime.utcnow() + timedelta(hours=1)

# get exit signature shards
request = SignatureRotationRequest(
vault_address=settings.vault,
public_keys=[],
public_key_shards=[],
exit_signature_shards=[],
deadline=deadline,
)
for validator_index, public_key in validators.items():
shards = get_exit_signature_shards(
Expand All @@ -89,7 +92,4 @@ async def get_oracles_approval(
# send approval request to oracles
signatures, ipfs_hash = await send_signature_rotation_requests(oracles, request)
logger.info('Fetched updated signature for validators: count=%d', len(validators))
return OraclesApproval(
signatures=signatures,
ipfs_hash=ipfs_hash,
)
return OraclesApproval(signatures=signatures, ipfs_hash=ipfs_hash, deadline=deadline)
12 changes: 12 additions & 0 deletions src/exits/typings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import dataclasses
from dataclasses import dataclass
from datetime import datetime
from typing import NewType

from eth_typing import ChecksumAddress, HexStr
Expand All @@ -11,6 +13,7 @@
class OraclesApproval:
signatures: bytes
ipfs_hash: str
deadline: datetime


@dataclass
Expand All @@ -19,3 +22,12 @@ class SignatureRotationRequest:
public_keys: list[HexStr]
public_key_shards: list[list[HexStr]]
exit_signature_shards: list[list[HexStr]]
deadline: datetime

def as_json_dict(self) -> dict:
"""
:return: dict which can be serialized by `json.dumps()`
"""
res = dataclasses.asdict(self)
res['deadline'] = int(self.deadline.timestamp())
return res
3 changes: 1 addition & 2 deletions src/exits/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dataclasses
import logging
import random
from urllib.parse import urljoin
Expand All @@ -19,7 +18,7 @@ async def send_signature_rotation_requests(
oracles: Oracles, request: SignatureRotationRequest
) -> tuple[bytes, str]:
"""Requests exit signature rotation from all oracles."""
payload = dataclasses.asdict(request)
payload = request.as_json_dict()
endpoints = list(zip(oracles.addresses, oracles.endpoints))
random.shuffle(endpoints)

Expand Down

0 comments on commit 6f83529

Please sign in to comment.