@Test void shouldUseCachedStateWhenAvailable() throws Exception { final BeaconState state = chainBuilder.generateBlockAtSlot(ONE).getState(); when(database.getLatestAvailableFinalizedState(state.getSlot())).thenReturn(Optional.of(state)); final Optional<BeaconState> initialResult = cache.getFinalizedState(state.getSlot()); assertThat(initialResult).contains(state); assertThat(cache.getFinalizedState(state.getSlot())).contains(state); verify(database, times(1)).getLatestAvailableFinalizedState(state.getSlot()); verifyNoMoreInteractions(database); }
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);  }