@Test void shouldRegenerateFromMoreRecentCachedState() throws Exception { final UInt64 databaseSlot = UInt64.valueOf(1); final UInt64 cachedSlot = UInt64.valueOf(2); final UInt64 requestedSlot = UInt64.valueOf(3); chainBuilder.generateBlocksUpToSlot(requestedSlot); when(database.getLatestAvailableFinalizedState(any())) .thenReturn(Optional.of(chainBuilder.getStateAtSlot(databaseSlot))); allowStreamingBlocks(); assertThat(cache.getFinalizedState(cachedSlot)) .contains(chainBuilder.getStateAtSlot(cachedSlot)); verify(database).streamFinalizedBlocks(databaseSlot.plus(ONE), cachedSlot); assertThat(cache.getFinalizedState(requestedSlot)) .contains(chainBuilder.getStateAtSlot(requestedSlot)); verify(database).streamFinalizedBlocks(cachedSlot.plus(ONE), requestedSlot); }
public Optional<BeaconState> getFinalizedState(final UInt64 slot) { try { return Optional.of(stateCache.getUnchecked(slot)); } catch (final UncheckedExecutionException e) { if (Throwables.getRootCause(e) instanceof StateUnavailableException) { return Optional.empty(); } throw new RuntimeException("Error while regenerating state", e); } }
FinalizedStateCache { public Optional<BeaconState> getFinalizedState(final UInt64 slot) { try { return Optional.of(stateCache.getUnchecked(slot)); } catch (final UncheckedExecutionException e) { if (Throwables.getRootCause(e) instanceof StateUnavailableException) { return Optional.empty(); } throw new RuntimeException("Error while regenerating state", e); } } }
FinalizedStateCache { public Optional<BeaconState> getFinalizedState(final UInt64 slot) { try { return Optional.of(stateCache.getUnchecked(slot)); } catch (final UncheckedExecutionException e) { if (Throwables.getRootCause(e) instanceof StateUnavailableException) { return Optional.empty(); } throw new RuntimeException("Error while regenerating state", e); } } FinalizedStateCache(
      final Database database, final int maximumCacheSize, final boolean useSoftReferences); }
FinalizedStateCache { public Optional<BeaconState> getFinalizedState(final UInt64 slot) { try { return Optional.of(stateCache.getUnchecked(slot)); } catch (final UncheckedExecutionException e) { if (Throwables.getRootCause(e) instanceof StateUnavailableException) { return Optional.empty(); } throw new RuntimeException("Error while regenerating state", e); } } FinalizedStateCache(
      final Database database, final int maximumCacheSize, final boolean useSoftReferences); Optional<BeaconState> getFinalizedState(final UInt64 slot); }
FinalizedStateCache { public Optional<BeaconState> getFinalizedState(final UInt64 slot) { try { return Optional.of(stateCache.getUnchecked(slot)); } catch (final UncheckedExecutionException e) { if (Throwables.getRootCause(e) instanceof StateUnavailableException) { return Optional.empty(); } throw new RuntimeException("Error while regenerating state", e); } } FinalizedStateCache(
      final Database database, final int maximumCacheSize, final boolean useSoftReferences); Optional<BeaconState> getFinalizedState(final UInt64 slot);  }