public Gwei GetLatestAttestingBalance(IStore store, Hash32 root) { if (!store.TryGetCheckpointState(store.JustifiedCheckpoint, out var storedState)) { throw new Exception($"Not able to get checkpoint state {store.JustifiedCheckpoint}"); } var state = storedState !; var currentEpoch = _beaconStateAccessor.GetCurrentEpoch(state); var activeIndexes = _beaconStateAccessor.GetActiveValidatorIndices(state, currentEpoch); if (!store.TryGetBlock(root, out var rootBlock)) { throw new Exception($"Not ble to find block {root}"); } Slot rootSlot = rootBlock !.Slot; Gwei balance = Gwei.Zero; foreach (ValidatorIndex 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)index]; balance += validator.EffectiveBalance; } } } return(balance); }
public async Task <Gwei> GetLatestAttestingBalanceAsync(IStore store, Hash32 root) { // NOTE: This method should probably live in IStore, for various efficient implementations. Checkpoint justifiedCheckpoint = store.JustifiedCheckpoint; BeaconState state = (await store.GetCheckpointStateAsync(justifiedCheckpoint, true).ConfigureAwait(false)) !; Epoch currentEpoch = _beaconStateAccessor.GetCurrentEpoch(state); IList <ValidatorIndex> activeIndexes = _beaconStateAccessor.GetActiveValidatorIndices(state, currentEpoch); BeaconBlock rootBlock = await store.GetBlockAsync(root).ConfigureAwait(false); Slot rootSlot = rootBlock !.Slot; Gwei balance = Gwei.Zero; foreach (ValidatorIndex index in activeIndexes) { LatestMessage?latestMessage = await store.GetLatestMessageAsync(index, false); if (latestMessage != null) { Hash32 ancestor = await GetAncestorAsync(store, latestMessage.Root, rootSlot); if (ancestor == root) { Validator validator = state.Validators[(int)index]; balance += validator.EffectiveBalance; } } } return(balance); }
public bool IsValidGenesisState(BeaconState state) { MiscellaneousParameters miscellaneousParameters = _miscellaneousParameterOptions.CurrentValue; InitialValues initialValues = _initialValueOptions.CurrentValue; if (state.GenesisTime < miscellaneousParameters.MinimumGenesisTime) { return(false); } var activeValidatorIndices = _beaconStateAccessor.GetActiveValidatorIndices(state, initialValues.GenesisEpoch); if (activeValidatorIndices.Count < miscellaneousParameters.MinimumGenesisActiveValidatorCount) { return(false); } return(true); }