Skip to content

Commit

Permalink
Add deadline for exit-sig-update (#144)
Browse files Browse the repository at this point in the history
* Add deadline for exit-sig-update

* Upd IKeeper.json

* Add settings.exit_signature_deadline

* Fix utcnow

---------

Signed-off-by: cyc60 <[email protected]>
Co-authored-by: cyc60 <[email protected]>
  • Loading branch information
evgeny-stakewise and cyc60 authored Aug 24, 2023
1 parent ca2b878 commit 0e7a29e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
11 changes: 5 additions & 6 deletions src/common/abi/IKeeper.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@
"internalType": "string",
"name": "exitSignaturesIpfsHash",
"type": "string"
},
{
"indexed": false,
"internalType": "uint256",
"name": "updateTimestamp",
"type": "uint256"
}
],
"name": "ValidatorsApproval",
Expand Down Expand Up @@ -649,6 +643,11 @@
"name": "vault",
"type": "address"
},
{
"internalType": "uint256",
"name": "deadline",
"type": "uint256"
},
{
"internalType": "string",
"name": "exitSignaturesIpfsHash",
Expand Down
4 changes: 4 additions & 0 deletions src/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Settings(metaclass=Singleton):
ipfs_fetch_endpoints: list[str]
validators_fetch_chunk_size: int
sentry_dsn: str
exit_signature_deadline: int

# pylint: disable-next=too-many-arguments,too-many-locals
def set(
Expand Down Expand Up @@ -121,6 +122,9 @@ def set(
'VALIDATORS_FETCH_CHUNK_SIZE', default=100, cast=int
)
self.sentry_dsn = decouple_config('SENTRY_DSN', default='')
self.exit_signature_deadline = decouple_config(
'EXIT_SIGNATURE_DEADLINE', default=600, cast=int
)

@property
def network_config(self) -> NetworkConfig:
Expand Down
4 changes: 1 addition & 3 deletions src/exits/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,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)
Expand Down
8 changes: 4 additions & 4 deletions src/exits/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import random
import time
from datetime import datetime, timedelta, timezone
from urllib.parse import urljoin

import aiohttp
Expand Down Expand Up @@ -137,13 +138,15 @@ async def get_oracles_approval(
) -> OraclesApproval:
"""Fetches approval from oracles."""
fork = await consensus_client.get_consensus_fork()
deadline = datetime.now(timezone.utc) + timedelta(seconds=settings.exit_signature_deadline)

# 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 @@ -162,10 +165,7 @@ 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)


async def update_exit_signatures_periodically(keystores: Keystores):
Expand Down
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 eth_typing import ChecksumAddress, HexStr

Expand All @@ -7,6 +9,7 @@
class OraclesApproval:
signatures: bytes
ipfs_hash: str
deadline: datetime


@dataclass
Expand All @@ -15,3 +18,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,5 +1,4 @@
import asyncio
import dataclasses
import logging
import random
from urllib.parse import urljoin
Expand All @@ -21,7 +20,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 0e7a29e

Please sign in to comment.