Search in sources :

Example 1 with StubStorageUpdateChannel

use of tech.pegasys.teku.storage.api.StubStorageUpdateChannel in project teku by ConsenSys.

the class StoreTransactionTest method retrieveFinalizedCheckpointAndState_finalizedCheckpointPruned.

@Test
public void retrieveFinalizedCheckpointAndState_finalizedCheckpointPruned() {
    final UpdatableStore store = createGenesisStore();
    final SignedBlockAndState finalizedBlockAndState = chainBuilder.generateBlockAtSlot(spec.slotsPerEpoch(ZERO) - 1);
    final Checkpoint finalizedCheckpoint = new Checkpoint(UInt64.ONE, finalizedBlockAndState.getRoot());
    final SignedBlockAndState newerFinalizedBlockAndState = chainBuilder.generateBlockAtSlot(spec.slotsPerEpoch(ZERO) * 2);
    final Checkpoint newerFinalizedCheckpoint = new Checkpoint(UInt64.valueOf(2), newerFinalizedBlockAndState.getRoot());
    // Save blocks
    final StoreTransaction blockTx = store.startTransaction(new StubStorageUpdateChannel());
    blockTx.putBlockAndState(finalizedBlockAndState);
    blockTx.putBlockAndState(newerFinalizedBlockAndState);
    assertThat(blockTx.commit()).isCompleted();
    // Start tx finalizing epoch 1
    final StoreTransaction tx = store.startTransaction(new StubStorageUpdateChannel());
    tx.setFinalizedCheckpoint(finalizedCheckpoint);
    // Finalize epoch 2
    final StoreTransaction otherTx = store.startTransaction(new StubStorageUpdateChannel());
    otherTx.putBlockAndState(newerFinalizedBlockAndState);
    otherTx.setFinalizedCheckpoint(newerFinalizedCheckpoint);
    assertThat(otherTx.commit()).isCompleted();
    // Check response from tx1 for finalized value
    final SafeFuture<CheckpointState> result = tx.retrieveFinalizedCheckpointAndState();
    assertThat(result).isCompleted();
    assertThat(result.join().getCheckpoint()).isEqualTo(newerFinalizedCheckpoint);
    assertThat(result.join().getRoot()).isEqualTo(newerFinalizedBlockAndState.getRoot());
    assertThat(result.join().getState()).isEqualTo(newerFinalizedBlockAndState.getState());
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) StubStorageUpdateChannel(tech.pegasys.teku.storage.api.StubStorageUpdateChannel) CheckpointState(tech.pegasys.teku.spec.datastructures.state.CheckpointState) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test)

Example 2 with StubStorageUpdateChannel

use of tech.pegasys.teku.storage.api.StubStorageUpdateChannel in project teku by ConsenSys.

the class StoreTest method retrieveCheckpointState_shouldThrowInvalidCheckpointExceptionWhenEpochBeforeBlockRoot.

@Test
public void retrieveCheckpointState_shouldThrowInvalidCheckpointExceptionWhenEpochBeforeBlockRoot() {
    final UpdatableStore store = createGenesisStore();
    final UInt64 epoch = UInt64.valueOf(2);
    final UInt64 startSlot = spec.computeStartSlotAtEpoch(epoch);
    final Bytes32 futureRoot = chainBuilder.generateBlockAtSlot(startSlot).getRoot();
    // Add blocks
    final StoreTransaction tx = store.startTransaction(new StubStorageUpdateChannel());
    chainBuilder.streamBlocksAndStates().forEach(tx::putBlockAndState);
    tx.commit().join();
    final Checkpoint checkpoint = new Checkpoint(UInt64.ONE, futureRoot);
    final SafeFuture<Optional<BeaconState>> result = store.retrieveCheckpointState(checkpoint);
    assertThat(result).isCompletedExceptionally();
    assertThatThrownBy(result::get).hasCauseInstanceOf(InvalidCheckpointException.class);
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) Optional(java.util.Optional) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) StubStorageUpdateChannel(tech.pegasys.teku.storage.api.StubStorageUpdateChannel) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) Test(org.junit.jupiter.api.Test)

Example 3 with StubStorageUpdateChannel

use of tech.pegasys.teku.storage.api.StubStorageUpdateChannel in project teku by ConsenSys.

the class StoreTest method retrieveFinalizedCheckpointAndState.

@Test
public void retrieveFinalizedCheckpointAndState() {
    final UpdatableStore store = createGenesisStore();
    final SignedBlockAndState finalizedBlockAndState = chainBuilder.generateBlockAtSlot(spec.slotsPerEpoch(UInt64.ZERO) - 1);
    final Checkpoint finalizedCheckpoint = new Checkpoint(UInt64.ONE, finalizedBlockAndState.getRoot());
    final StoreTransaction tx = store.startTransaction(new StubStorageUpdateChannel());
    tx.putBlockAndState(finalizedBlockAndState);
    tx.setFinalizedCheckpoint(finalizedCheckpoint);
    assertThat(tx.commit()).isCompleted();
    final SafeFuture<CheckpointState> result = store.retrieveFinalizedCheckpointAndState();
    assertThat(result).isCompleted();
    assertThat(result.join().getCheckpoint()).isEqualTo(finalizedCheckpoint);
    assertThat(result.join().getRoot()).isEqualTo(finalizedBlockAndState.getRoot());
    assertThat(result.join().getState()).isNotEqualTo(finalizedBlockAndState.getState());
    assertThat(result.join().getState().getSlot()).isEqualTo(finalizedBlockAndState.getSlot().plus(1));
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) StubStorageUpdateChannel(tech.pegasys.teku.storage.api.StubStorageUpdateChannel) CheckpointState(tech.pegasys.teku.spec.datastructures.state.CheckpointState) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test)

Example 4 with StubStorageUpdateChannel

use of tech.pegasys.teku.storage.api.StubStorageUpdateChannel in project teku by ConsenSys.

the class StoreTransactionTest method retrieveFinalizedCheckpointAndState_finalizedBlockInMemory.

@Test
public void retrieveFinalizedCheckpointAndState_finalizedBlockInMemory() {
    final UpdatableStore store = createGenesisStore();
    final SignedBlockAndState finalizedBlockAndState = chainBuilder.generateBlockAtSlot(spec.slotsPerEpoch(ZERO) - 1);
    final Checkpoint finalizedCheckpoint = new Checkpoint(UInt64.ONE, finalizedBlockAndState.getRoot());
    final StoreTransaction tx = store.startTransaction(new StubStorageUpdateChannel());
    tx.putBlockAndState(finalizedBlockAndState);
    tx.setFinalizedCheckpoint(finalizedCheckpoint);
    final SafeFuture<CheckpointState> result = tx.retrieveFinalizedCheckpointAndState();
    assertThat(result).isCompleted();
    assertThat(result.join().getCheckpoint()).isEqualTo(finalizedCheckpoint);
    assertThat(result.join().getRoot()).isEqualTo(finalizedBlockAndState.getRoot());
    assertThat(result.join().getState()).isNotEqualTo(finalizedBlockAndState.getState());
    assertThat(result.join().getState().getSlot()).isEqualTo(finalizedBlockAndState.getSlot().plus(1));
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) StubStorageUpdateChannel(tech.pegasys.teku.storage.api.StubStorageUpdateChannel) CheckpointState(tech.pegasys.teku.spec.datastructures.state.CheckpointState) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test)

Example 5 with StubStorageUpdateChannel

use of tech.pegasys.teku.storage.api.StubStorageUpdateChannel in project teku by ConsenSys.

the class StoreTransactionTest method retrieveFinalizedCheckpointAndState_pullFromStore.

@Test
public void retrieveFinalizedCheckpointAndState_pullFromStore() {
    final UpdatableStore store = createGenesisStore();
    final SignedBlockAndState finalizedBlockAndState = chainBuilder.generateBlockAtSlot(spec.slotsPerEpoch(ZERO) - 1);
    final Checkpoint finalizedCheckpoint = new Checkpoint(UInt64.ONE, finalizedBlockAndState.getRoot());
    final StoreTransaction finalizingTx = store.startTransaction(new StubStorageUpdateChannel());
    finalizingTx.setFinalizedCheckpoint(finalizedCheckpoint);
    finalizingTx.putBlockAndState(finalizedBlockAndState);
    assertThat(finalizingTx.commit()).isCompleted();
    final StoreTransaction tx = store.startTransaction(new StubStorageUpdateChannel());
    final SafeFuture<CheckpointState> result = tx.retrieveFinalizedCheckpointAndState();
    assertThat(result).isCompleted();
    assertThat(result.join().getCheckpoint()).isEqualTo(finalizedCheckpoint);
    assertThat(result.join().getRoot()).isEqualTo(finalizedBlockAndState.getRoot());
    assertThat(result.join().getState()).isNotEqualTo(finalizedBlockAndState.getState());
    assertThat(result.join().getState().getSlot()).isEqualTo(finalizedBlockAndState.getSlot().plus(1));
}
Also used : Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) StoreTransaction(tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction) StubStorageUpdateChannel(tech.pegasys.teku.storage.api.StubStorageUpdateChannel) CheckpointState(tech.pegasys.teku.spec.datastructures.state.CheckpointState) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)6 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)6 StubStorageUpdateChannel (tech.pegasys.teku.storage.api.StubStorageUpdateChannel)6 StoreTransaction (tech.pegasys.teku.storage.store.UpdatableStore.StoreTransaction)6 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)5 CheckpointState (tech.pegasys.teku.spec.datastructures.state.CheckpointState)5 Optional (java.util.Optional)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1