@Test public void retrieveBlockState_fromUnderlyingStore_withLimitedCache() { processChainWithLimitedCache( (store, blockAndState) -> { UpdatableStore.StoreTransaction tx = store.startTransaction(storageUpdateChannel); final Bytes32 root = blockAndState.getRoot(); SafeFuture<Optional<BeaconState>> result = tx.retrieveBlockState(root); assertThat(result).isCompleted(); assertThat(result) .withFailMessage("Expected state at %s to be available", blockAndState.getSlot()) .isCompletedWithValue(Optional.of(blockAndState.getState())); }); }
@Override public SafeFuture<Optional<BeaconState>> retrieveBlockState(Bytes32 blockRoot) { if (blockAndStates.containsKey(blockRoot)) { return SafeFuture.completedFuture( Optional.of(blockAndStates.get(blockRoot)).map(SignedBlockAndState::getState)); } return store.retrieveBlockState(blockRoot); }
StoreTransaction implements UpdatableStore.StoreTransaction { @Override public SafeFuture<Optional<BeaconState>> retrieveBlockState(Bytes32 blockRoot) { if (blockAndStates.containsKey(blockRoot)) { return SafeFuture.completedFuture( Optional.of(blockAndStates.get(blockRoot)).map(SignedBlockAndState::getState)); } return store.retrieveBlockState(blockRoot); } }
StoreTransaction implements UpdatableStore.StoreTransaction { @Override public SafeFuture<Optional<BeaconState>> retrieveBlockState(Bytes32 blockRoot) { if (blockAndStates.containsKey(blockRoot)) { return SafeFuture.completedFuture( Optional.of(blockAndStates.get(blockRoot)).map(SignedBlockAndState::getState)); } return store.retrieveBlockState(blockRoot); } StoreTransaction(
      final Store store,
      final ReadWriteLock lock,
      final StorageUpdateChannel storageUpdateChannel,
      final UpdatableStore.StoreUpdateHandler updateHandler); }
StoreTransaction implements UpdatableStore.StoreTransaction { @Override public SafeFuture<Optional<BeaconState>> retrieveBlockState(Bytes32 blockRoot) { if (blockAndStates.containsKey(blockRoot)) { return SafeFuture.completedFuture( Optional.of(blockAndStates.get(blockRoot)).map(SignedBlockAndState::getState)); } return store.retrieveBlockState(blockRoot); } StoreTransaction(
      final Store store,
      final ReadWriteLock lock,
      final StorageUpdateChannel storageUpdateChannel,
      final UpdatableStore.StoreUpdateHandler updateHandler); @Override void putBlockAndState(final SignedBeaconBlock block, final BeaconState state); @Override void putBlockAndState(final SignedBlockAndState blockAndState); @Override void putStateRoot(final Bytes32 stateRoot, final SlotAndBlockRoot slotAndBlockRoot); @Override void setTime(UInt64 time); @Override void setGenesis_time(UInt64 genesis_time); @Override void setJustifiedCheckpoint(Checkpoint justified_checkpoint); @Override void setFinalizedCheckpoint(Checkpoint finalized_checkpoint); @Override void setBestJustifiedCheckpoint(Checkpoint best_justified_checkpoint); @Override VoteTracker getVote(UInt64 validatorIndex); @CheckReturnValue @Override SafeFuture<Void> commit(); @Override void commit(final Runnable onSuccess, final String errorMessage); @Override UInt64 getTime(); @Override UInt64 getGenesisTime(); @Override Checkpoint getJustifiedCheckpoint(); @Override Checkpoint getFinalizedCheckpoint(); @Override SignedBlockAndState getLatestFinalizedBlockAndState(); @Override UInt64 getLatestFinalizedBlockSlot(); @Override Checkpoint getBestJustifiedCheckpoint(); @Override boolean containsBlock(final Bytes32 blockRoot); @Override Set<Bytes32> getBlockRoots(); @Override List<Bytes32> getOrderedBlockRoots(); @Override Optional<BeaconState> getBlockStateIfAvailable(final Bytes32 blockRoot); @Override SafeFuture<Optional<SignedBeaconBlock>> retrieveSignedBlock(Bytes32 blockRoot); @Override SafeFuture<Optional<SignedBlockAndState>> retrieveBlockAndState(Bytes32 blockRoot); @Override SafeFuture<Optional<BeaconState>> retrieveBlockState(Bytes32 blockRoot); @Override SafeFuture<Optional<BeaconState>> retrieveCheckpointState(Checkpoint checkpoint); @Override SafeFuture<CheckpointState> retrieveFinalizedCheckpointAndState(); @Override SafeFuture<Optional<BeaconState>> retrieveCheckpointState(
      final Checkpoint checkpoint, final BeaconState latestStateAtEpoch); @Override Optional<SignedBeaconBlock> getBlockIfAvailable(final Bytes32 blockRoot); @Override Set<UInt64> getVotedValidatorIndices(); }
StoreTransaction implements UpdatableStore.StoreTransaction { @Override public SafeFuture<Optional<BeaconState>> retrieveBlockState(Bytes32 blockRoot) { if (blockAndStates.containsKey(blockRoot)) { return SafeFuture.completedFuture( Optional.of(blockAndStates.get(blockRoot)).map(SignedBlockAndState::getState)); } return store.retrieveBlockState(blockRoot); } StoreTransaction(
      final Store store,
      final ReadWriteLock lock,
      final StorageUpdateChannel storageUpdateChannel,
      final UpdatableStore.StoreUpdateHandler updateHandler); @Override void putBlockAndState(final SignedBeaconBlock block, final BeaconState state); @Override void putBlockAndState(final SignedBlockAndState blockAndState); @Override void putStateRoot(final Bytes32 stateRoot, final SlotAndBlockRoot slotAndBlockRoot); @Override void setTime(UInt64 time); @Override void setGenesis_time(UInt64 genesis_time); @Override void setJustifiedCheckpoint(Checkpoint justified_checkpoint); @Override void setFinalizedCheckpoint(Checkpoint finalized_checkpoint); @Override void setBestJustifiedCheckpoint(Checkpoint best_justified_checkpoint); @Override VoteTracker getVote(UInt64 validatorIndex); @CheckReturnValue @Override SafeFuture<Void> commit(); @Override void commit(final Runnable onSuccess, final String errorMessage); @Override UInt64 getTime(); @Override UInt64 getGenesisTime(); @Override Checkpoint getJustifiedCheckpoint(); @Override Checkpoint getFinalizedCheckpoint(); @Override SignedBlockAndState getLatestFinalizedBlockAndState(); @Override UInt64 getLatestFinalizedBlockSlot(); @Override Checkpoint getBestJustifiedCheckpoint(); @Override boolean containsBlock(final Bytes32 blockRoot); @Override Set<Bytes32> getBlockRoots(); @Override List<Bytes32> getOrderedBlockRoots(); @Override Optional<BeaconState> getBlockStateIfAvailable(final Bytes32 blockRoot); @Override SafeFuture<Optional<SignedBeaconBlock>> retrieveSignedBlock(Bytes32 blockRoot); @Override SafeFuture<Optional<SignedBlockAndState>> retrieveBlockAndState(Bytes32 blockRoot); @Override SafeFuture<Optional<BeaconState>> retrieveBlockState(Bytes32 blockRoot); @Override SafeFuture<Optional<BeaconState>> retrieveCheckpointState(Checkpoint checkpoint); @Override SafeFuture<CheckpointState> retrieveFinalizedCheckpointAndState(); @Override SafeFuture<Optional<BeaconState>> retrieveCheckpointState(
      final Checkpoint checkpoint, final BeaconState latestStateAtEpoch); @Override Optional<SignedBeaconBlock> getBlockIfAvailable(final Bytes32 blockRoot); @Override Set<UInt64> getVotedValidatorIndices();  }