Search in sources :

Example 1 with GenesisData

use of tech.pegasys.teku.spec.datastructures.genesis.GenesisData in project teku by ConsenSys.

the class RecentChainData method setStore.

boolean setStore(UpdatableStore store) {
    if (!storeInitialized.compareAndSet(false, true)) {
        return false;
    }
    this.store = store;
    this.store.startMetrics();
    // Set data that depends on the genesis state
    this.genesisTime = this.store.getGenesisTime();
    final BeaconState anchorState = store.getLatestFinalized().getState();
    final Bytes32 genesisValidatorsRoot = anchorState.getGenesis_validators_root();
    this.genesisData = Optional.of(new GenesisData(anchorState.getGenesis_time(), genesisValidatorsRoot));
    spec.getForkSchedule().getActiveMilestones().forEach(forkAndMilestone -> {
        final Fork fork = forkAndMilestone.getFork();
        final ForkInfo forkInfo = new ForkInfo(fork, genesisValidatorsRoot);
        final Bytes4 forkDigest = forkInfo.getForkDigest(spec);
        this.forkDigestToMilestone.put(forkDigest, forkAndMilestone.getSpecMilestone());
        this.milestoneToForkDigest.put(forkAndMilestone.getSpecMilestone(), forkDigest);
    });
    storeInitializedFuture.complete(null);
    return true;
}
Also used : Fork(tech.pegasys.teku.spec.datastructures.state.Fork) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) GenesisData(tech.pegasys.teku.spec.datastructures.genesis.GenesisData) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) Bytes32(org.apache.tuweni.bytes.Bytes32) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 2 with GenesisData

use of tech.pegasys.teku.spec.datastructures.genesis.GenesisData in project teku by ConsenSys.

the class GenesisDataProviderTest method shouldRetryWhenGenesisTimeIsNotYetKnown.

@Test
void shouldRetryWhenGenesisTimeIsNotYetKnown() {
    when(validatorApiChannel.getGenesisData()).thenReturn(completedFuture(Optional.empty())).thenReturn(completedFuture(Optional.of(new GenesisData(GENESIS_TIME, GENESIS_VALIDATORS_ROOT))));
    // First request fails
    final SafeFuture<UInt64> result = genesisDataProvider.getGenesisTime();
    verify(validatorApiChannel).getGenesisData();
    assertThat(result).isNotDone();
    Assertions.assertThat(asyncRunner.hasDelayedActions()).isTrue();
    // Retry is scheduled.
    asyncRunner.executeQueuedActions();
    verify(validatorApiChannel, times(2)).getGenesisData();
    assertThat(result).isCompletedWithValue(GENESIS_TIME);
}
Also used : GenesisData(tech.pegasys.teku.spec.datastructures.genesis.GenesisData) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 3 with GenesisData

use of tech.pegasys.teku.spec.datastructures.genesis.GenesisData in project teku by ConsenSys.

the class MetricRecordingValidatorApiChannelTest method getDataRequestArguments.

public static Stream<Arguments> getDataRequestArguments() {
    final DataStructureUtil dataStructureUtil = new DataStructureUtil(TestSpecFactory.createMinimalAltair());
    final UInt64 slot = dataStructureUtil.randomUInt64();
    final BLSSignature signature = dataStructureUtil.randomSignature();
    final AttestationData attestationData = dataStructureUtil.randomAttestationData();
    final int subcommitteeIndex = dataStructureUtil.randomPositiveInt();
    final Bytes32 beaconBlockRoot = dataStructureUtil.randomBytes32();
    return Stream.of(requestDataTest("getGenesisData", ValidatorApiChannel::getGenesisData, MetricRecordingValidatorApiChannel.GENESIS_TIME_REQUESTS_COUNTER_NAME, new GenesisData(dataStructureUtil.randomUInt64(), Bytes32.random())), requestDataTest("createUnsignedBlock", channel -> channel.createUnsignedBlock(slot, signature, Optional.empty()), MetricRecordingValidatorApiChannel.UNSIGNED_BLOCK_REQUESTS_COUNTER_NAME, dataStructureUtil.randomBeaconBlock(slot)), requestDataTest("createAttestationData", channel -> channel.createAttestationData(slot, 4), MetricRecordingValidatorApiChannel.ATTESTATION_DATA_REQUEST_COUNTER_NAME, dataStructureUtil.randomAttestationData()), requestDataTest("createAggregate", channel -> channel.createAggregate(attestationData.getSlot(), attestationData.hashTreeRoot()), MetricRecordingValidatorApiChannel.AGGREGATE_REQUESTS_COUNTER_NAME, dataStructureUtil.randomAttestation()), requestDataTest("createSyncCommitteeContribution", channel -> channel.createSyncCommitteeContribution(slot, subcommitteeIndex, beaconBlockRoot), MetricRecordingValidatorApiChannel.CREATE_SYNC_COMMITTEE_CONTRIBUTION_REQUESTS_COUNTER_NAME, dataStructureUtil.randomSyncCommitteeContribution(slot)));
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Function(java.util.function.Function) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Assertions(org.assertj.core.api.Assertions) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) RequestOutcome(tech.pegasys.teku.validator.beaconnode.metrics.BeaconChainRequestCounter.RequestOutcome) Bytes32(org.apache.tuweni.bytes.Bytes32) GenesisData(tech.pegasys.teku.spec.datastructures.genesis.GenesisData) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) MethodSource(org.junit.jupiter.params.provider.MethodSource) Collections.emptySet(java.util.Collections.emptySet) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Collections.emptyList(java.util.Collections.emptyList) Mockito.when(org.mockito.Mockito.when) Arguments(org.junit.jupiter.params.provider.Arguments) Consumer(java.util.function.Consumer) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) ValidatorApiChannel(tech.pegasys.teku.validator.api.ValidatorApiChannel) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) SubmitDataError(tech.pegasys.teku.validator.api.SubmitDataError) Mockito.mock(org.mockito.Mockito.mock) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) GenesisData(tech.pegasys.teku.spec.datastructures.genesis.GenesisData) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSSignature(tech.pegasys.teku.bls.BLSSignature) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil)

Example 4 with GenesisData

use of tech.pegasys.teku.spec.datastructures.genesis.GenesisData in project teku by ConsenSys.

the class GenesisDataProviderTest method shouldRetryWhenGenesisTimeFailsToLoad.

@Test
void shouldRetryWhenGenesisTimeFailsToLoad() {
    when(validatorApiChannel.getGenesisData()).thenReturn(failedFuture(new RuntimeException("Nope"))).thenReturn(completedFuture(Optional.of(new GenesisData(GENESIS_TIME, GENESIS_VALIDATORS_ROOT))));
    // First request fails
    final SafeFuture<UInt64> result = genesisDataProvider.getGenesisTime();
    verify(validatorApiChannel).getGenesisData();
    assertThat(result).isNotDone();
    Assertions.assertThat(asyncRunner.hasDelayedActions()).isTrue();
    // Retry is scheduled.
    asyncRunner.executeQueuedActions();
    verify(validatorApiChannel, times(2)).getGenesisData();
    assertThat(result).isCompletedWithValue(GENESIS_TIME);
}
Also used : GenesisData(tech.pegasys.teku.spec.datastructures.genesis.GenesisData) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 5 with GenesisData

use of tech.pegasys.teku.spec.datastructures.genesis.GenesisData in project teku by ConsenSys.

the class GenesisDataProviderTest method shouldReturnCachedGenesisTimeWhenPreviouslyLoaded.

@Test
void shouldReturnCachedGenesisTimeWhenPreviouslyLoaded() {
    when(validatorApiChannel.getGenesisData()).thenReturn(SafeFuture.completedFuture(Optional.of(new GenesisData(GENESIS_TIME, GENESIS_VALIDATORS_ROOT))));
    assertThat(genesisDataProvider.getGenesisData()).isCompletedWithValue(new GenesisData(GENESIS_TIME, GENESIS_VALIDATORS_ROOT));
    verify(validatorApiChannel).getGenesisData();
    // Subsequent requests just return the cached version
    assertThat(genesisDataProvider.getGenesisData()).isCompletedWithValue(new GenesisData(GENESIS_TIME, GENESIS_VALIDATORS_ROOT));
    verifyNoMoreInteractions(validatorApiChannel);
}
Also used : GenesisData(tech.pegasys.teku.spec.datastructures.genesis.GenesisData) Test(org.junit.jupiter.api.Test)

Aggregations

GenesisData (tech.pegasys.teku.spec.datastructures.genesis.GenesisData)5 Test (org.junit.jupiter.api.Test)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptySet (java.util.Collections.emptySet)1 List (java.util.List)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Stream (java.util.stream.Stream)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Arguments (org.junit.jupiter.params.provider.Arguments)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 BLSSignature (tech.pegasys.teku.bls.BLSSignature)1