public void InvalidSignature()
        {
            // Arrange
            IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider();
            BeaconState      state = TestState.PrepareTestState(testServiceProvider);

            TimeParameters      timeParameters      = testServiceProvider.GetService <IOptions <TimeParameters> >().Value;
            BeaconStateAccessor beaconStateAccessor = testServiceProvider.GetService <BeaconStateAccessor>();

            // move state forward PERSISTENT_COMMITTEE_PERIOD epochs to allow for exit
            ulong move    = timeParameters.SlotsPerEpoch * (ulong)timeParameters.PersistentCommitteePeriod;
            ulong newSlot = state.Slot + move;

            state.SetSlot((Slot)newSlot);

            Epoch          currentEpoch   = beaconStateAccessor.GetCurrentEpoch(state);
            ValidatorIndex validatorIndex = beaconStateAccessor.GetActiveValidatorIndices(state, currentEpoch)[0];
            Validator      validator      = state.Validators[(int)(ulong)validatorIndex];

            byte[] privateKey = TestKeys.PublicKeyToPrivateKey(validator.PublicKey, timeParameters);

            VoluntaryExit       voluntaryExit       = TestVoluntaryExit.BuildVoluntaryExit(testServiceProvider, currentEpoch, validatorIndex);
            SignedVoluntaryExit signedVoluntaryExit = new SignedVoluntaryExit(voluntaryExit, BlsSignature.Zero);

            RunVoluntaryExitProcessing(testServiceProvider, state, signedVoluntaryExit, expectValid: false);
        }
Esempio n. 2
0
        public async Task <Gwei> GetLatestAttestingBalanceAsync(IStore store, Root root)
        {
            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);
            SignedBeaconBlock      rootBlock     = await store.GetSignedBlockAsync(root).ConfigureAwait(false);

            Slot rootSlot = rootBlock !.Message.Slot;
            Gwei balance  = Gwei.Zero;

            foreach (ValidatorIndex index in activeIndexes)
            {
                LatestMessage?latestMessage = await store.GetLatestMessageAsync(index, false);

                if (latestMessage != null)
                {
                    Root ancestor = await store.GetAncestorAsync(latestMessage.Root, rootSlot);

                    if (ancestor == root)
                    {
                        Validator validator = state.Validators[(int)index];
                        balance += validator.EffectiveBalance;
                    }
                }
            }

            return(balance);
        }