use of tech.pegasys.teku.storage.store.StoreConfig in project teku by ConsenSys.
the class BeaconChainController method initialize.
protected SafeFuture<?> initialize() {
final StoreConfig storeConfig = beaconConfig.storeConfig();
coalescingChainHeadChannel = new CoalescingChainHeadChannel(eventChannels.getPublisher(ChainHeadChannel.class), EVENT_LOG);
StorageQueryChannel storageQueryChannel = eventChannels.getPublisher(StorageQueryChannel.class, beaconAsyncRunner);
StorageUpdateChannel storageUpdateChannel = eventChannels.getPublisher(StorageUpdateChannel.class, beaconAsyncRunner);
final VoteUpdateChannel voteUpdateChannel = eventChannels.getPublisher(VoteUpdateChannel.class);
return initWeakSubjectivity(storageQueryChannel, storageUpdateChannel).thenCompose(__ -> StorageBackedRecentChainData.create(metricsSystem, storeConfig, beaconAsyncRunner, storageQueryChannel, storageUpdateChannel, voteUpdateChannel, eventChannels.getPublisher(FinalizedCheckpointChannel.class, beaconAsyncRunner), coalescingChainHeadChannel, spec)).thenCompose(client -> {
// Setup chain storage
this.recentChainData = client;
if (recentChainData.isPreGenesis()) {
setupInitialState(client);
} else if (beaconConfig.eth2NetworkConfig().isUsingCustomInitialState()) {
STATUS_LOG.warnInitialStateIgnored();
}
return SafeFuture.completedFuture(client);
}).thenAccept(client -> {
// Init other services
this.initAll();
eventChannels.subscribe(TimeTickChannel.class, this);
recentChainData.subscribeStoreInitialized(this::onStoreInitialized);
recentChainData.subscribeBestBlockInitialized(this::startServices);
});
}
use of tech.pegasys.teku.storage.store.StoreConfig in project teku by ConsenSys.
the class AbstractKvStoreDatabaseWithHotStatesTest method shouldPersistHotStates_everyThirdEpoch.
@Test
public void shouldPersistHotStates_everyThirdEpoch() {
final int storageFrequency = 3;
StoreConfig storeConfig = StoreConfig.builder().hotStatePersistenceFrequencyInEpochs(storageFrequency).build();
createStorage(StateStorageMode.ARCHIVE, storeConfig, false);
initGenesis();
final UInt64 latestEpoch = UInt64.valueOf(3 * storageFrequency);
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());
final UInt64 currentSlot = UInt64.valueOf(i);
final UInt64 currentEpoch = spec.computeEpochAtSlot(currentSlot);
final boolean shouldPersistThisEpoch = currentEpoch.mod(storageFrequency).equals(UInt64.ZERO);
if (epochBoundarySlots.contains(currentSlot) && shouldPersistThisEpoch) {
assertThat(actual).contains(blockAndState.getState());
} else {
assertThat(actual).isEmpty();
}
}
}
use of tech.pegasys.teku.storage.store.StoreConfig in project teku by ConsenSys.
the class StoreOptionsTest method hotStatePersistenceFrequency_shouldSetDefaultValue.
@Test
public void hotStatePersistenceFrequency_shouldSetDefaultValue() {
final StoreConfig globalConfiguration = getTekuConfigurationFromArguments().beaconChain().storeConfig();
assertThat(globalConfiguration.getHotStatePersistenceFrequencyInEpochs()).isEqualTo(2);
}
use of tech.pegasys.teku.storage.store.StoreConfig in project teku by ConsenSys.
the class StoreOptionsTest method hotStatePersistenceFrequency_shouldRespectCLIArg.
@Test
public void hotStatePersistenceFrequency_shouldRespectCLIArg() {
final String[] args = { "--Xhot-state-persistence-frequency", "99" };
TekuConfiguration tekuConfiguration = getTekuConfigurationFromArguments(args);
final StoreConfig globalConfiguration = tekuConfiguration.beaconChain().storeConfig();
assertThat(globalConfiguration.getHotStatePersistenceFrequencyInEpochs()).isEqualTo(99);
assertThat(createConfigBuilder().store(b -> b.hotStatePersistenceFrequencyInEpochs(99)).build()).usingRecursiveComparison().isEqualTo(tekuConfiguration);
}
use of tech.pegasys.teku.storage.store.StoreConfig in project teku by ConsenSys.
the class AbstractKvStoreDatabaseWithHotStatesTest method shouldClearStaleHotStates.
@Test
public void shouldClearStaleHotStates() {
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()));
justifyAndFinalizeEpoch(latestEpoch, chainBuilder.getLatestBlockAndState());
// Hot states should be cleared out
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();
}
}
Aggregations