Search in sources :

Example 6 with StoreConfig

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();
    }
}
Also used : StoreConfig(tech.pegasys.teku.storage.store.StoreConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 7 with StoreConfig

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();
        }
    }
}
Also used : StoreConfig(tech.pegasys.teku.storage.store.StoreConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 8 with StoreConfig

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);
}
Also used : Optional(java.util.Optional) StoreBuilder(tech.pegasys.teku.storage.store.StoreBuilder) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) StoreConfig(tech.pegasys.teku.storage.store.StoreConfig) Test(org.junit.jupiter.api.Test)

Example 9 with StoreConfig

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);
}
Also used : Optional(java.util.Optional) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) StoreConfig(tech.pegasys.teku.storage.store.StoreConfig) Test(org.junit.jupiter.api.Test)

Aggregations

StoreConfig (tech.pegasys.teku.storage.store.StoreConfig)9 Test (org.junit.jupiter.api.Test)8 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)5 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)5 Optional (java.util.Optional)3 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)3 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)3 AbstractBeaconNodeCommandTest (tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)2 StubMetricsSystem (tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem)2 UpdatableStore (tech.pegasys.teku.storage.store.UpdatableStore)2 Throwables (com.google.common.base.Throwables)1 BindException (java.net.BindException)1 Path (java.nio.file.Path)1 Duration (java.time.Duration)1 Comparator (java.util.Comparator)1 Random (java.util.Random)1 Function (java.util.function.Function)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Bytes (org.apache.tuweni.bytes.Bytes)1