Search in sources :

Example 1 with UpdatableStore

use of tech.pegasys.teku.storage.store.UpdatableStore in project teku by ConsenSys.

the class ForkChoiceTestExecutor method applyChecks.

private void applyChecks(final RecentChainData recentChainData, final ForkChoice forkChoice, final Map<String, Object> step) {
    assertThat(forkChoice.processHead()).isCompleted();
    final UpdatableStore store = recentChainData.getStore();
    final Map<String, Object> checks = get(step, "checks");
    for (String checkType : checks.keySet()) {
        switch(checkType) {
            case "genesis_time":
                assertThat(recentChainData.getGenesisTime()).isEqualTo(getUInt64(checks, checkType));
                break;
            case "head":
                final Map<String, Object> expectedHead = get(checks, checkType);
                final UInt64 expectedSlot = UInt64.valueOf(expectedHead.get("slot").toString());
                final Bytes32 expectedRoot = Bytes32.fromHexString(expectedHead.get("root").toString());
                assertThat(recentChainData.getHeadSlot()).isEqualTo(expectedSlot);
                assertThat(recentChainData.getBestBlockRoot()).contains(expectedRoot);
                break;
            case "time":
                final UInt64 expectedTime = getUInt64(checks, checkType);
                assertThat(store.getTime()).isEqualTo(expectedTime);
                break;
            case "justified_checkpoint_root":
                final Bytes32 expectedJustifiedRoot = getBytes32(checks, checkType);
                assertThat(store.getJustifiedCheckpoint().getRoot()).describedAs("justified checkpoint").isEqualTo(expectedJustifiedRoot);
                break;
            case "justified_checkpoint":
                assertCheckpoint("justified checkpoint", store.getJustifiedCheckpoint(), get(checks, checkType));
                break;
            case "best_justified_checkpoint":
                assertCheckpoint("best justified checkpoint", store.getBestJustifiedCheckpoint(), get(checks, checkType));
                break;
            case "finalized_checkpoint_root":
                final Bytes32 expectedFinalizedRoot = getBytes32(checks, checkType);
                assertThat(store.getFinalizedCheckpoint().getRoot()).describedAs("finalized checkpoint").isEqualTo(expectedFinalizedRoot);
                break;
            case "finalized_checkpoint":
                assertCheckpoint("finalized checkpoint", store.getFinalizedCheckpoint(), get(checks, checkType));
                break;
            case "proposer_boost_root":
                final Optional<Bytes32> boostedRoot = store.getProposerBoostRoot();
                final Bytes32 expectedBoostedRoot = getBytes32(checks, checkType);
                if (expectedBoostedRoot.isZero()) {
                    assertThat(boostedRoot).describedAs("proposer_boost_root").isEmpty();
                } else {
                    assertThat(boostedRoot).describedAs("proposer_boost_root").contains(expectedBoostedRoot);
                }
                break;
            default:
                throw new UnsupportedOperationException("Unsupported check type: " + checkType);
        }
    }
}
Also used : UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32)

Example 2 with UpdatableStore

use of tech.pegasys.teku.storage.store.UpdatableStore in project teku by ConsenSys.

the class AbstractDatabaseTest method shouldStoreSingleValue_genesisTime.

@Test
public void shouldStoreSingleValue_genesisTime() {
    final UInt64 newGenesisTime = UInt64.valueOf(3);
    // Sanity check
    assertThat(store.getGenesisTime()).isNotEqualTo(newGenesisTime);
    final StoreTransaction transaction = recentChainData.startStoreTransaction();
    transaction.setGenesisTime(newGenesisTime);
    commit(transaction);
    final UpdatableStore result = recreateStore();
    assertThat(result.getGenesisTime()).isEqualTo(transaction.getGenesisTime());
}
Also used : UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 3 with UpdatableStore

use of tech.pegasys.teku.storage.store.UpdatableStore in project teku by ConsenSys.

the class AbstractDatabaseTest method testStartupFromNonGenesisState.

public void testStartupFromNonGenesisState(final StateStorageMode storageMode) {
    createStorage(storageMode);
    // Set up database from an anchor point
    final UInt64 anchorEpoch = UInt64.valueOf(10);
    final SignedBlockAndState anchorBlockAndState = chainBuilder.generateBlockAtSlot(spec.computeStartSlotAtEpoch(anchorEpoch));
    final AnchorPoint anchor = AnchorPoint.create(spec, new Checkpoint(anchorEpoch, anchorBlockAndState.getRoot()), anchorBlockAndState.getState(), Optional.empty());
    createStorage(storageMode);
    initFromAnchor(anchor);
    // Add some blocks
    addBlocks(chainBuilder.generateNextBlock(), chainBuilder.generateNextBlock());
    // Restart and check data is what we expect
    final UpdatableStore originalStore = recentChainData.getStore();
    restartStorage();
    StoreAssertions.assertStoresMatch(recentChainData.getStore(), originalStore);
    assertThat(recentChainData.getFinalizedCheckpoint()).contains(anchor.getCheckpoint());
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)

Example 4 with UpdatableStore

use of tech.pegasys.teku.storage.store.UpdatableStore in project teku by ConsenSys.

the class AbstractDatabaseTest method assertHotBlocksAndStates.

protected void assertHotBlocksAndStates(final UpdatableStore store, final Collection<SignedBlockAndState> blocksAndStates) {
    final List<UpdatableStore> storesToCheck = List.of(store, recreateStore());
    for (UpdatableStore currentStore : storesToCheck) {
        assertThat(currentStore.getOrderedBlockRoots()).hasSameElementsAs(blocksAndStates.stream().map(SignedBlockAndState::getRoot).collect(toList()));
        final List<BeaconState> hotStates = currentStore.getOrderedBlockRoots().stream().map(currentStore::retrieveBlockState).map(f -> {
            assertThat(f).isCompleted();
            return f.join();
        }).flatMap(Optional::stream).collect(toList());
        assertThat(hotStates).hasSameElementsAs(blocksAndStates.stream().map(SignedBlockAndState::getState).collect(toList()));
    }
}
Also used : UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 5 with UpdatableStore

use of tech.pegasys.teku.storage.store.UpdatableStore in project teku by ConsenSys.

the class AbstractDatabaseTest method shouldStoreSingleValue_singleBlockAndState.

@Test
public void shouldStoreSingleValue_singleBlockAndState() {
    final SignedBlockAndState newBlock = chainBuilder.generateNextBlock();
    // Sanity check
    assertThatSafeFuture(store.retrieveBlock(newBlock.getRoot())).isCompletedWithEmptyOptional();
    final StoreTransaction transaction = recentChainData.startStoreTransaction();
    transaction.putBlockAndState(newBlock);
    commit(transaction);
    final UpdatableStore result = recreateStore();
    assertThat(result.retrieveSignedBlock(newBlock.getRoot())).isCompletedWithValue(Optional.of(newBlock.getBlock()));
    assertThat(result.retrieveBlockState(newBlock.getRoot())).isCompletedWithValue(Optional.of(newBlock.getState()));
}
Also used : UpdatableStore(tech.pegasys.teku.storage.store.UpdatableStore) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test)

Aggregations

UpdatableStore (tech.pegasys.teku.storage.store.UpdatableStore)24 Test (org.junit.jupiter.api.Test)13 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)11 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)8 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)8 StoreTransaction (tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction)8 Optional (java.util.Optional)4 Bytes32 (org.apache.tuweni.bytes.Bytes32)4 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)4 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)4 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)3 BlockProvider (tech.pegasys.teku.dataproviders.lookup.BlockProvider)2 StubMetricsSystem (tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem)2 Spec (tech.pegasys.teku.spec.Spec)2 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)2 StoreBuilder (tech.pegasys.teku.storage.store.StoreBuilder)2 StoreConfig (tech.pegasys.teku.storage.store.StoreConfig)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Throwables (com.google.common.base.Throwables)1 IOException (java.io.IOException)1