Search in sources :

Example 1 with BeaconState

use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState in project teku by ConsenSys.

the class Eth1DataCacheTest method smallestDistanceWinsIfNoMajority.

@Test
void smallestDistanceWinsIfNoMajority() {
    Eth1Data eth1Data1 = createEth1Data(STATE_DEPOSIT_COUNT);
    Eth1Data eth1Data2 = createEth1Data(STATE_DEPOSIT_COUNT);
    BeaconState beaconState = createBeaconStateWithVotes(eth1Data1, eth1Data2);
    eth1DataCache.onBlockWithDeposit(IN_RANGE_TIMESTAMP_1, eth1Data1);
    eth1DataCache.onBlockWithDeposit(IN_RANGE_TIMESTAMP_2, eth1Data2);
    assertThat(eth1DataCache.getEth1Vote(beaconState)).isEqualTo(eth1Data1);
}
Also used : Eth1Data(tech.pegasys.teku.spec.datastructures.blocks.Eth1Data) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 2 with BeaconState

use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState in project teku by ConsenSys.

the class ValidatorApiHandlerTest method createAttestationData_shouldFailWhenHeadIsOptimistic.

@Test
public void createAttestationData_shouldFailWhenHeadIsOptimistic() {
    final UInt64 slot = spec.computeStartSlotAtEpoch(EPOCH).plus(ONE);
    when(chainDataClient.getCurrentSlot()).thenReturn(slot);
    final BeaconState state = createStateWithActiveValidators(EPOCH_START_SLOT);
    final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(state.getSlot(), state);
    final SignedBlockAndState blockAndState = new SignedBlockAndState(block, state);
    final SafeFuture<Optional<SignedBlockAndState>> blockAndStateResult = completedFuture(Optional.of(blockAndState));
    when(chainDataClient.getSignedBlockAndStateInEffectAtSlot(slot)).thenReturn(blockAndStateResult);
    when(forkChoiceTrigger.prepareForAttestationProduction(slot)).thenReturn(SafeFuture.COMPLETE);
    when(chainDataClient.isOptimisticBlock(blockAndState.getRoot())).thenReturn(true);
    final int committeeIndex = 0;
    final SafeFuture<Optional<AttestationData>> result = validatorApiHandler.createAttestationData(slot, committeeIndex);
    assertThat(result).isCompletedExceptionally();
    assertThatThrownBy(result::get).hasRootCauseInstanceOf(NodeSyncingException.class);
}
Also used : Optional(java.util.Optional) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 3 with BeaconState

use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState in project teku by ConsenSys.

the class ValidatorApiHandlerTest method getSyncCommitteeDuties_shouldNotUseEpochPriorToFork.

@Test
void getSyncCommitteeDuties_shouldNotUseEpochPriorToFork() {
    final Spec spec = TestSpecFactory.createMinimalWithAltairForkEpoch(EPOCH);
    final ValidatorApiHandler validatorApiHandler = new ValidatorApiHandler(chainDataProvider, chainDataClient, syncStateProvider, blockFactory, blockImportChannel, blockGossipChannel, attestationPool, attestationManager, attestationTopicSubscriptions, activeValidatorTracker, dutyMetrics, performanceTracker, spec, forkChoiceTrigger, forkChoiceNotifier, syncCommitteeMessagePool, syncCommitteeContributionPool, syncCommitteeSubscriptionManager);
    // Best state is still in Phase0
    final BeaconState state = dataStructureUtil.stateBuilderPhase0().slot(PREVIOUS_EPOCH_START_SLOT.minus(1)).build();
    when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH);
    when(chainDataClient.getBestState()).thenReturn(Optional.of(SafeFuture.completedFuture(state)));
    when(chainDataClient.getStateAtSlotExact(any())).thenReturn(new SafeFuture<>());
    final SafeFuture<Optional<SyncCommitteeDuties>> result = validatorApiHandler.getSyncCommitteeDuties(EPOCH, IntList.of(1));
    assertThat(result).isNotDone();
    // The start of the sync committee period is prior to the fork block so we should use the
    // fork block to ensure we actually have sync committees available.
    verify(chainDataClient).getStateAtSlotExact(EPOCH_START_SLOT);
}
Also used : Optional(java.util.Optional) Spec(tech.pegasys.teku.spec.Spec) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 4 with BeaconState

use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState in project teku by ConsenSys.

the class ValidatorApiHandlerTest method createUnsignedBlock_shouldCreateBlock.

@Test
public void createUnsignedBlock_shouldCreateBlock() throws Exception {
    final UInt64 newSlot = UInt64.valueOf(25);
    final BeaconState blockSlotState = dataStructureUtil.randomBeaconState(newSlot);
    final BLSSignature randaoReveal = dataStructureUtil.randomSignature();
    final BeaconBlock createdBlock = dataStructureUtil.randomBeaconBlock(newSlot.longValue());
    when(chainDataClient.getStateAtSlotExact(newSlot)).thenReturn(SafeFuture.completedFuture(Optional.of(blockSlotState)));
    when(blockFactory.createUnsignedBlock(blockSlotState, newSlot, randaoReveal, Optional.empty())).thenReturn(createdBlock);
    final SafeFuture<Optional<BeaconBlock>> result = validatorApiHandler.createUnsignedBlock(newSlot, randaoReveal, Optional.empty());
    verify(blockFactory).createUnsignedBlock(blockSlotState, newSlot, randaoReveal, Optional.empty());
    assertThat(result).isCompletedWithValue(Optional.of(createdBlock));
}
Also used : Optional(java.util.Optional) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BLSSignature(tech.pegasys.teku.bls.BLSSignature) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 5 with BeaconState

use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState in project teku by ConsenSys.

the class ValidatorApiHandlerTest method getAttestationDuties_shouldAllowOneEpochTolerance.

@Test
public void getAttestationDuties_shouldAllowOneEpochTolerance() {
    final BeaconState state = createStateWithActiveValidators();
    final BLSPublicKey validator1Key = BLSPublicKey.fromBytesCompressed(state.getValidators().get(1).getPubkeyBytes());
    when(chainDataClient.getStateAtSlotExact(PREVIOUS_EPOCH_START_SLOT)).thenReturn(completedFuture(Optional.of(state)));
    when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH.minus(2));
    final SafeFuture<Optional<AttesterDuties>> result = validatorApiHandler.getAttestationDuties(EPOCH, IntList.of(1, 32));
    final Optional<AttesterDuties> duties = assertCompletedSuccessfully(result);
    assertThat(duties.orElseThrow().getDuties()).containsExactly(new AttesterDuty(validator1Key, 1, 4, 0, 1, 1, UInt64.valueOf(108)));
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Optional(java.util.Optional) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Aggregations

BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)274 Test (org.junit.jupiter.api.Test)167 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)101 Bytes32 (org.apache.tuweni.bytes.Bytes32)55 Optional (java.util.Optional)37 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)37 Bytes (org.apache.tuweni.bytes.Bytes)35 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)35 Spec (tech.pegasys.teku.spec.Spec)27 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)25 ArrayList (java.util.ArrayList)24 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)24 List (java.util.List)19 ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)16 ForkChoiceState (tech.pegasys.teku.spec.executionengine.ForkChoiceState)16 PayloadAttributes (tech.pegasys.teku.spec.executionengine.PayloadAttributes)16 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)15 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)14 Eth1Data (tech.pegasys.teku.spec.datastructures.blocks.Eth1Data)13 BLSSignature (tech.pegasys.teku.bls.BLSSignature)12