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;
}
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);
}
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)));
}
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);
}
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);
}
Aggregations