Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Validator client doesn't crash due to unresponsive beacon node.
Browse files Browse the repository at this point in the history
Cleaner exception handling.

removed extra space

removed extra space

lint
  • Loading branch information
g-r-a-n-t committed May 25, 2020
1 parent 32f5231 commit c0068c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
56 changes: 34 additions & 22 deletions eth2/validator_client/duty_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ async def resolve_duty(
) -> None:
if duty.duty_type == DutyType.Attestation:
duty = cast(AttestationDuty, duty)
attestation = await beacon_node.fetch_attestation(
duty.validator_public_key,
duty.tick_for_execution.slot,
duty.committee_index,
)
if attestation:
await resolved_duties.send((duty, attestation))

try:
attestation = await beacon_node.fetch_attestation(
duty.validator_public_key,
duty.tick_for_execution.slot,
duty.committee_index,
)
except OSError as err:
logger.warning("could not fetch attestation from beacon node: %s", err)
else:
if attestation:
await resolved_duties.send((duty, attestation))

elif duty.duty_type == DutyType.BlockProposal:
randao_reveal = randao_provider(
duty.validator_public_key, duty.tick_for_execution.epoch
Expand Down Expand Up @@ -67,23 +73,29 @@ async def _fetch_latest_duties(
current_epoch = tick.epoch
next_epoch = Epoch(current_epoch + 1)

current_duties = await beacon_node.fetch_duties(
tick, validator_public_keys, current_epoch
)
upcoming_duties = await beacon_node.fetch_duties(
tick, validator_public_keys, next_epoch
)
latest_duties = cast(Tuple[Duty, ...], current_duties) + cast(
Tuple[Duty, ...], upcoming_duties
)
if not latest_duties:
return
try:
current_duties = await beacon_node.fetch_duties(
tick, validator_public_keys, current_epoch
)
upcoming_duties = await beacon_node.fetch_duties(
tick, validator_public_keys, next_epoch
)
except OSError as err:
logger.warning(
"could not fetch latest duties from beacon node at %s: %s", tick, err
)
else:
latest_duties = cast(Tuple[Duty, ...], current_duties) + cast(
Tuple[Duty, ...], upcoming_duties
)
if not latest_duties:
return

logger.debug("%s: found %d duties", tick, len(latest_duties))
logger.debug("%s: found %d duties", tick, len(latest_duties))

# TODO manage duties correctly, accounting for re-orgs, etc.
# NOTE: the naive strategy is likely "last write wins"
await duty_store.add_duties(*latest_duties)
# TODO manage duties correctly, accounting for re-orgs, etc.
# NOTE: the naive strategy is likely "last write wins"
await duty_store.add_duties(*latest_duties)


async def schedule_and_dispatch_duties_at_tick(
Expand Down
5 changes: 4 additions & 1 deletion eth2/validator_client/signatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@ async def sign_and_broadcast_operation_if_valid(
duty,
humanize_bytes(operation_with_signature.hash_tree_root),
)
await beacon_node.publish(duty, operation_with_signature)
try:
await beacon_node.publish(duty, operation_with_signature)
except OSError as err:
logger.warning("could not publish opperation to beacon node: %s", err)

0 comments on commit c0068c8

Please sign in to comment.