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