public async Task <IList <ValidatorDuty> > ValidatorDutiesAsync(IEnumerable <BlsPublicKey> validatorPublicKeys, Epoch epoch) { // TODO: Rather than check one by one (each of which loops through potentially all slots for the epoch), optimise by either checking multiple, or better possibly caching or pre-calculating List <ValidatorDuty> validatorDuties = new List <ValidatorDuty>(); foreach (BlsPublicKey validatorPublicKey in validatorPublicKeys) { ValidatorDuty validatorDuty = await _validatorAssignments.GetValidatorDutyAsync(validatorPublicKey, epoch); validatorDuties.Add(validatorDuty); } return(validatorDuties); }
public async Task <ApiResponse <IList <ValidatorDuty> > > ValidatorDutiesAsync( IList <BlsPublicKey> validatorPublicKeys, Epoch?epoch, CancellationToken cancellationToken) { if (validatorPublicKeys.Count < 1) { return(ApiResponse.Create <IList <ValidatorDuty> >(StatusCode.InvalidRequest)); } if (!_store.IsInitialized) { // Beacon chain is currently syncing or waiting for genesis. return(ApiResponse.Create <IList <ValidatorDuty> >(StatusCode.CurrentlySyncing)); } // TODO: Rather than check one by one (each of which loops through potentially all slots for the epoch), optimise by either checking multiple, or better possibly caching or pre-calculating IList <ValidatorDuty> validatorDuties = new List <ValidatorDuty>(); foreach (BlsPublicKey validatorPublicKey in validatorPublicKeys) { ValidatorDuty validatorDuty; try { validatorDuty = await _validatorAssignments.GetValidatorDutyAsync(validatorPublicKey, epoch ?? Epoch.None) .ConfigureAwait(false); } catch (ArgumentOutOfRangeException outOfRangeException) when(outOfRangeException.ParamName == "epoch") { return(ApiResponse.Create <IList <ValidatorDuty> >(StatusCode.DutiesNotAvailableForRequestedEpoch)); } catch (Exception ex) { if (_logger.IsWarn()) { Log.ApiErrorValidatorDuties(_logger, ex); } throw; } validatorDuties.Add(validatorDuty); } ApiResponse <IList <ValidatorDuty> > response = ApiResponse.Create(StatusCode.Success, validatorDuties); return(response); }
public async IAsyncEnumerable <ValidatorDuty> ValidatorDutiesAsync(IEnumerable <BlsPublicKey> validatorPublicKeys, Epoch epoch, [EnumeratorCancellation] CancellationToken cancellationToken) { // TODO: Rather than check one by one (each of which loops through potentially all slots for the epoch), optimise by either checking multiple, or better possibly caching or pre-calculating foreach (BlsPublicKey validatorPublicKey in validatorPublicKeys) { ValidatorDuty validatorDuty; try { validatorDuty = await _validatorAssignments.GetValidatorDutyAsync(validatorPublicKey, epoch) .ConfigureAwait(false); } catch (Exception ex) { if (_logger.IsWarn()) { Log.ApiErrorValidatorDuties(_logger, ex); } throw; } yield return(validatorDuty); } }