Skip to content

Commit

Permalink
Decrease logging in oracles approval
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise committed Oct 16, 2023
1 parent c4d83ec commit d548200
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 23 deletions.
7 changes: 6 additions & 1 deletion src/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ def __init__(self, *args, **kwargs):


class NotEnoughOracleApprovalsError(ValueError):
def __init__(self, *args, **kwargs):
def __init__(
self, num_votes: int, threshold: int, failed_endpoints: list[str], *args, **kwargs
):
super().__init__(NOT_ENOUGH_ORACLE_APPROVALS, *args, **kwargs)
self.num_votes = num_votes
self.threshold = threshold
self.failed_endpoints = failed_endpoints
3 changes: 2 additions & 1 deletion src/common/startup_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ async def collect_healthy_oracles() -> list:
healthy_oracles = []
for result, endpoint in zip(results, endpoints):
if isinstance(result, Exception):
logger.warning('%s for endpoint %s', format_error(result), endpoint)
if settings.verbose:
logger.warning('%s for endpoint %s', format_error(result), endpoint)
continue

if result:
Expand Down
3 changes: 2 additions & 1 deletion src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ def process_oracles_approvals(
votes = candidates[winner]
if len(votes) < votes_threshold:
# not enough oracles have approved the request
# Fill `failed_endpoints` later
raise NotEnoughOracleApprovalsError(
f'Received {len(votes)} approvals, but {votes_threshold} is required'
num_votes=len(votes), threshold=votes_threshold, failed_endpoints=[]
)

signatures = b''
Expand Down
4 changes: 2 additions & 2 deletions src/exits/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from src.common.execution import get_oracles
from src.common.metrics import metrics
from src.common.typings import Oracles
from src.common.utils import get_current_timestamp, is_block_finalized
from src.common.utils import get_current_timestamp, is_block_finalized, log_verbose
from src.config.settings import settings
from src.exits.consensus import get_validator_public_keys
from src.exits.execution import submit_exit_signatures
Expand Down Expand Up @@ -102,7 +102,7 @@ async def _update_exit_signatures(
logger.info('Fetched updated signature for validators: count=%d', len(validators))
break
except Exception as e:
logger.exception(e)
log_verbose(e)

tx_hash = await submit_exit_signatures(oracles_approval)
logger.info(
Expand Down
16 changes: 9 additions & 7 deletions src/exits/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ async def send_signature_rotation_requests(
session=session, replicas=replicas, payload=payload
)
except Exception as e:
logger.error(
'All endpoints for oracle %s failed to sign signature rotation request. '
'Last error: %s',
address,
format_error(e),
)
if settings.verbose:
logger.warning(
'All endpoints for oracle %s failed to sign signature rotation request. '
'Last error: %s',
address,
format_error(e),
)
continue
approvals[address] = response

Expand All @@ -65,7 +66,8 @@ async def send_signature_rotation_request_to_replicas(
try:
return await send_signature_rotation_request(session, endpoint, payload)
except (ClientError, asyncio.TimeoutError) as e:
logger.warning('%s for endpoint %s', format_error(e), endpoint)
if settings.verbose:
logger.warning('%s for endpoint %s', format_error(e), endpoint)
last_error = e

if last_error:
Expand Down
11 changes: 9 additions & 2 deletions src/validators/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from src.common.clients import consensus_client, ipfs_fetch_client
from src.common.contracts import validators_registry_contract
from src.common.exceptions import NotEnoughOracleApprovalsError
from src.common.execution import check_gas_price, get_oracles
from src.common.metrics import metrics
from src.common.typings import Oracles
Expand Down Expand Up @@ -122,8 +123,14 @@ async def register_validators(
oracles_request.validator_index,
)
break
except Exception as e:
logger.exception(e)
except NotEnoughOracleApprovalsError as e:
logger.error(
'Failed to fetch oracle approvals. Received %d out of %d, '
'the oracles with endpoints %s have failed to respond.',
e.num_votes,
e.threshold,
', '.join(e.failed_endpoints),
)

if len(validators) == 1:
validator = validators[0]
Expand Down
28 changes: 19 additions & 9 deletions src/validators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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
from src.config.settings import DEFAULT_RETRY_TIME, ORACLES_VALIDATORS_TIMEOUT, settings
Expand Down Expand Up @@ -59,19 +60,27 @@ async def send_approval_requests(oracles: Oracles, request: ApprovalRequest) ->
)

approvals: dict[ChecksumAddress, OracleApproval] = {}
for address, result in zip(oracles.addresses, results):
failed_endpoints: list[str] = []

for address, replicas, result in zip(oracles.addresses, oracles.endpoints, results):
if isinstance(result, Exception):
logger.error(
'All endpoints for oracle %s failed to sign validators approval request. '
'Last error: %s',
address,
format_error(result),
)
if settings.verbose:
logger.warning(
'All endpoints for oracle %s failed to sign validators approval request. '
'Last error: %s',
address,
format_error(result),
)
failed_endpoints.extend(replicas)
continue

approvals[address] = result

return process_oracles_approvals(approvals, oracles.validators_threshold)
try:
return process_oracles_approvals(approvals, oracles.validators_threshold)
except NotEnoughOracleApprovalsError as e:
e.failed_endpoints = failed_endpoints
raise


# pylint: disable=duplicate-code
Expand All @@ -88,7 +97,8 @@ async def send_approval_request_to_replicas(
try:
return await send_approval_request(session, endpoint, payload)
except (ClientError, asyncio.TimeoutError) as e:
logger.warning('%s for endpoint %s', format_error(e), endpoint)
if settings.verbose:
logger.warning('%s for endpoint %s', format_error(e), endpoint)
last_error = e

if last_error:
Expand Down

0 comments on commit d548200

Please sign in to comment.