use of tech.pegasys.teku.storage.store.StoreConfig in project teku by ConsenSys.
the class AbstractKvStoreDatabaseWithHotStatesTest method shouldPersistHotStates_never.
@Test
public void shouldPersistHotStates_never() {
final int storageFrequency = 0;
StoreConfig storeConfig = StoreConfig.builder().hotStatePersistenceFrequencyInEpochs(storageFrequency).build();
createStorage(StateStorageMode.ARCHIVE, storeConfig, false);
initGenesis();
final UInt64 latestEpoch = UInt64.valueOf(3);
final UInt64 targetSlot = spec.computeStartSlotAtEpoch(latestEpoch);
chainBuilder.generateBlocksUpToSlot(targetSlot);
// Add blocks
addBlocks(chainBuilder.streamBlocksAndStates().collect(toList()));
for (int i = 0; i <= targetSlot.intValue(); i++) {
final SignedBlockAndState blockAndState = chainBuilder.getBlockAndStateAtSlot(i);
final Optional<BeaconState> actual = database.getHotState(blockAndState.getRoot());
assertThat(actual).isEmpty();
}
}
use of tech.pegasys.teku.storage.store.StoreConfig in project teku by ConsenSys.
the class AbstractKvStoreDatabaseWithHotStatesTest method shouldPersistHotStates_everyEpoch.
@Test
public void shouldPersistHotStates_everyEpoch() {
final int storageFrequency = 1;
StoreConfig storeConfig = StoreConfig.builder().hotStatePersistenceFrequencyInEpochs(storageFrequency).build();
createStorage(StateStorageMode.ARCHIVE, storeConfig, false);
initGenesis();
final UInt64 latestEpoch = UInt64.valueOf(3);
final UInt64 targetSlot = spec.computeStartSlotAtEpoch(latestEpoch);
chainBuilder.generateBlocksUpToSlot(targetSlot);
// Add blocks
addBlocks(chainBuilder.streamBlocksAndStates().collect(toList()));
// We should only be able to pull states at epoch boundaries
final Set<UInt64> epochBoundarySlots = getEpochBoundarySlots(1, latestEpoch.intValue());
for (int i = 0; i <= targetSlot.intValue(); i++) {
final SignedBlockAndState blockAndState = chainBuilder.getBlockAndStateAtSlot(i);
final Optional<BeaconState> actual = database.getHotState(blockAndState.getRoot());
if (epochBoundarySlots.contains(UInt64.valueOf(i))) {
assertThat(actual).contains(blockAndState.getState());
} else {
assertThat(actual).isEmpty();
}
}
}
use of tech.pegasys.teku.storage.store.StoreConfig in project teku by ConsenSys.
the class StorageBackedRecentChainDataTest method storageBackedClient_storeInitializeViaGetStoreRequest.
@Test
public void storageBackedClient_storeInitializeViaGetStoreRequest() throws ExecutionException, InterruptedException {
SafeFuture<Optional<StoreBuilder>> storeRequestFuture = new SafeFuture<>();
when(storageQueryChannel.onStoreRequest()).thenReturn(storeRequestFuture);
final StoreConfig storeConfig = StoreConfig.builder().hotStatePersistenceFrequencyInEpochs(5).build();
final SafeFuture<RecentChainData> client = StorageBackedRecentChainData.create(new StubMetricsSystem(), storeConfig, asyncRunner, storageQueryChannel, storageUpdateChannel, voteUpdateChannel, finalizedCheckpointChannel, chainHeadChannel, spec);
// We should have posted a request to get the store from storage
verify(storageQueryChannel).onStoreRequest();
// Client shouldn't be initialized yet
assertThat(client).isNotDone();
// Post a store response to complete initialization
final StoreBuilder genesisStoreBuilder = StoreBuilder.forkChoiceStoreBuilder(SYNC_RUNNER, new StubMetricsSystem(), spec, BlockProvider.NOOP, StateAndBlockSummaryProvider.NOOP, AnchorPoint.fromGenesisState(spec, INITIAL_STATE), UInt64.ZERO);
storeRequestFuture.complete(Optional.of(genesisStoreBuilder));
assertThat(client).isCompleted();
assertStoreInitialized(client.get());
assertStoreIsSet(client.get());
final UpdatableStore expectedStore = genesisStoreBuilder.storeConfig(storeConfig).build();
StoreAssertions.assertStoresMatch(client.get().getStore(), expectedStore);
}
use of tech.pegasys.teku.storage.store.StoreConfig in project teku by ConsenSys.
the class StorageBackedRecentChainDataTest method storageBackedClient_storeInitializeViaNewGenesisState.
@Test
public void storageBackedClient_storeInitializeViaNewGenesisState() throws ExecutionException, InterruptedException {
SafeFuture<Optional<StoreBuilder>> storeRequestFuture = new SafeFuture<>();
when(storageQueryChannel.onStoreRequest()).thenReturn(storeRequestFuture);
final StoreConfig storeConfig = StoreConfig.builder().hotStatePersistenceFrequencyInEpochs(5).build();
final SafeFuture<RecentChainData> client = StorageBackedRecentChainData.create(new StubMetricsSystem(), storeConfig, asyncRunner, storageQueryChannel, storageUpdateChannel, voteUpdateChannel, finalizedCheckpointChannel, chainHeadChannel, spec);
// We should have posted a request to get the store from storage
verify(storageQueryChannel).onStoreRequest();
// Client shouldn't be initialized yet
assertThat(client).isNotDone();
// Post a store event to complete initialization
storeRequestFuture.complete(Optional.empty());
assertThat(client).isCompleted();
assertStoreNotInitialized(client.get());
assertThat(client.get().getStore()).isNull();
// Now set the genesis state
final UpdatableStore genesisStore = StoreBuilder.forkChoiceStoreBuilder(SYNC_RUNNER, new StubMetricsSystem(), spec, BlockProvider.NOOP, StateAndBlockSummaryProvider.NOOP, AnchorPoint.fromGenesisState(spec, INITIAL_STATE), UInt64.ZERO).storeConfig(storeConfig).build();
client.get().initializeFromGenesis(INITIAL_STATE, UInt64.ZERO);
assertStoreInitialized(client.get());
assertStoreIsSet(client.get());
StoreAssertions.assertStoresMatch(client.get().getStore(), genesisStore);
}
Aggregations