/// <summary> /// Initiate the exit of the validator with index ``index``. /// </summary> public void InitiateValidatorExit(BeaconState state, ValidatorIndex index) { // Return if validator already initiated exit var validator = state.Validators[(int)(ulong)index]; if (validator.ExitEpoch != _chainConstants.FarFutureEpoch) { return; } // Compute exit queue epoch var exitEpochs = state.Validators .Where(x => x.ExitEpoch != _chainConstants.FarFutureEpoch) .Select(x => x.ExitEpoch); var maxExitEpoch = exitEpochs.DefaultIfEmpty().Max(); var currentEpoch = _beaconStateAccessor.GetCurrentEpoch(state); var activationExitEpoch = _beaconChainUtility.ComputeActivationExitEpoch(currentEpoch); var exitQueueEpoch = Epoch.Max(maxExitEpoch, activationExitEpoch); var exitQueueChurn = state.Validators.Where(x => x.ExitEpoch == exitQueueEpoch).Count(); var validatorChurnLimit = _beaconStateAccessor.GetValidatorChurnLimit(state); if ((ulong)exitQueueChurn >= validatorChurnLimit) { exitQueueEpoch += new Epoch(1); } // Set validator exit epoch and withdrawable epoch validator.SetExitEpoch(exitQueueEpoch); var withdrawableEpoch = validator.ExitEpoch + _timeParameterOptions.CurrentValue.MinimumValidatorWithdrawabilityDelay; validator.SetWithdrawableEpoch(withdrawableEpoch); }
public Gwei GetLatestAttestingBalance(IStore store, Hash32 root) { if (!store.TryGetCheckpointState(store.JustifiedCheckpoint, out var state)) { throw new Exception(); } var currentEpoch = _beaconStateAccessor.GetCurrentEpoch(state); var activeIndexes = _beaconStateAccessor.GetActiveValidatorIndices(state, currentEpoch); if (!store.TryGetBlock(root, out var rootBlock)) { throw new Exception(); } var rootSlot = rootBlock.Slot; var balance = new Gwei(0); foreach (var index in activeIndexes) { if (store.TryGetLatestMessage(index, out var latestMessage)) { var ancestor = GetAncestor(store, latestMessage.Root, rootSlot); if (ancestor == root) { var validator = state.Validators[(int)(ulong)index]; balance += validator.EffectiveBalance; } } } return(balance); }
public IEnumerable <PendingAttestation> GetMatchingSourceAttestations(BeaconState state, Epoch epoch) { var currentEpoch = _beaconStateAccessor.GetCurrentEpoch(state); var previousEpoch = _beaconStateAccessor.GetPreviousEpoch(state); if (epoch != currentEpoch && epoch != previousEpoch) { throw new ArgumentOutOfRangeException(nameof(epoch), epoch, $"The epoch for attestions must be either the current epoch {currentEpoch} or previous epoch {previousEpoch}."); } if (epoch == currentEpoch) { return(state.CurrentEpochAttestations); } return(state.PreviousEpochAttestations); }