Skip to content

Commit

Permalink
Rework
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise committed Dec 1, 2023
1 parent e09d69f commit a5d3629
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 38 deletions.
5 changes: 1 addition & 4 deletions src/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ def __init__(self, *args, **kwargs): # type: ignore


class NotEnoughOracleApprovalsError(ValueError):
def __init__( # type: ignore
self, num_votes: int, threshold: int, failed_endpoints: list[str], *args, **kwargs
):
def __init__(self, num_votes: int, threshold: int, *args, **kwargs): # type: ignore
super().__init__(NOT_ENOUGH_ORACLE_APPROVALS, *args, **kwargs)
self.num_votes = num_votes
self.threshold = threshold
self.failed_endpoints = failed_endpoints
14 changes: 5 additions & 9 deletions src/exits/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,13 @@ async def _update_exit_signatures(
try:
# send approval request to oracles
oracles_approval = await send_signature_rotation_requests(oracles, oracles_request)
logger.info('Fetched updated signature for validators: count=%d', len(validators))
break
except NotEnoughOracleApprovalsError as e:
log_msg = 'Failed to fetch oracle approvals. Received %d out of %d.'
log_args: list = [e.num_votes, e.threshold]

if e.failed_endpoints:
log_msg += ' The oracles with endpoints %s have failed to respond.'
log_args.append(', '.join(e.failed_endpoints))

logger.error(log_msg, *log_args)
logger.error(
'Not enough votes for exit signature update: %d. Threshold is %d',
e.num_votes,
e.threshold,
)

tx_hash = await submit_exit_signatures(oracles_approval)
if not tx_hash:
Expand Down
21 changes: 15 additions & 6 deletions src/exits/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from sw_utils.decorators import retry_aiohttp_errors
from web3 import Web3

from src.common.exceptions import NotEnoughOracleApprovalsError
from src.common.typings import OracleApproval, Oracles, OraclesApproval
from src.common.utils import format_error, process_oracles_approvals, warning_verbose
from src.config.settings import (
Expand Down Expand Up @@ -50,11 +49,21 @@ async def send_signature_rotation_requests(
failed_endpoints.extend(replicas)
continue
approvals[address] = response
try:
return process_oracles_approvals(approvals, oracles.validators_threshold)
except NotEnoughOracleApprovalsError as e:
e.failed_endpoints = failed_endpoints
raise

logger.info(
'Fetched oracle approvals for signature update: validators count = %d. '
'Received: %d out of %d.',
len(request.public_keys),
len(approvals),
len(oracles.endpoints),
)

if failed_endpoints:
logger.error(
'The oracles with endpoints %s have failed to respond.', ', '.join(failed_endpoints)
)

return process_oracles_approvals(approvals, oracles.validators_threshold)


# pylint: disable=duplicate-code
Expand Down
18 changes: 5 additions & 13 deletions src/validators/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,13 @@ async def register_validators(

try:
oracles_approval = await send_approval_requests(oracles, oracles_request)
logger.info(
'Fetched oracles approval for validators: deadline=%d, start index=%d',
oracles_request.deadline,
oracles_request.validator_index,
)
break
except NotEnoughOracleApprovalsError as e:
log_msg = 'Failed to fetch oracle approvals. Received %d out of %d.'
log_args: list = [e.num_votes, e.threshold]

if e.failed_endpoints:
log_msg += ' The oracles with endpoints %s have failed to respond.'
log_args.append(', '.join(e.failed_endpoints))

logger.error(log_msg, *log_args)
logger.error(
'Not enough votes for validator registration: %d. Threshold is %d',
e.num_votes,
e.threshold,
)

# compare validators root just before transaction to reduce reverted calls
if registry_root != await validators_registry_contract.get_registry_root():
Expand Down
21 changes: 15 additions & 6 deletions src/validators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from web3 import Web3

from src.common.contracts import validators_registry_contract
from src.common.exceptions import NotEnoughOracleApprovalsError
from src.common.typings import OracleApproval, Oracles, OraclesApproval
from src.common.utils import format_error, process_oracles_approvals, warning_verbose
from src.config.settings import DEFAULT_RETRY_TIME, ORACLES_VALIDATORS_TIMEOUT, settings
Expand Down Expand Up @@ -75,11 +74,21 @@ async def send_approval_requests(oracles: Oracles, request: ApprovalRequest) ->

approvals[address] = result

try:
return process_oracles_approvals(approvals, oracles.validators_threshold)
except NotEnoughOracleApprovalsError as e:
e.failed_endpoints = failed_endpoints
raise
logger.info(
'Fetched oracle approvals for validator registration: '
'deadline=%d, start index=%d. Received %d out of %d.',
request.deadline,
request.validator_index,
len(approvals),
len(oracles.endpoints),
)

if failed_endpoints:
logger.error(
'The oracles with endpoints %s have failed to respond.', ', '.join(failed_endpoints)
)

return process_oracles_approvals(approvals, oracles.validators_threshold)


# pylint: disable=duplicate-code
Expand Down

0 comments on commit a5d3629

Please sign in to comment.