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());
}
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);
}
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));
}
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));
}
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));
}
Aggregations