Beispiel #1
0
        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);
        }
Beispiel #2
0
        public bool IsValidGenesisState(BeaconState state)
        {
            var miscellaneousParameters = _miscellaneousParameterOptions.CurrentValue;
            var 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);
        }