@Test void on_tick_shouldExitImmediatelyWhenCurrentTimeIsBeforeGenesisTime() { final MutableStore store = mock(MutableStore.class); when(store.getGenesisTime()).thenReturn(UInt64.valueOf(3000)); when(store.getTime()).thenReturn(UInt64.ZERO); ForkChoiceUtil.on_tick(store, UInt64.valueOf(2000)); verify(store, never()).setTime(any()); }
public static void on_tick(MutableStore store, UInt64 time) { if (store.getTime().isGreaterThan(time) || store.getGenesisTime().isGreaterThan(time)) { return; } UInt64 previous_slot = get_current_slot(store); store.setTime(time); UInt64 current_slot = get_current_slot(store); if (!(current_slot.compareTo(previous_slot) > 0 && compute_slots_since_epoch_start(current_slot).equals(UInt64.ZERO))) { return; } if (store .getBestJustifiedCheckpoint() .getEpoch() .compareTo(store.getJustifiedCheckpoint().getEpoch()) > 0) { store.setJustifiedCheckpoint(store.getBestJustifiedCheckpoint()); } }
ForkChoiceUtil { public static void on_tick(MutableStore store, UInt64 time) { if (store.getTime().isGreaterThan(time) || store.getGenesisTime().isGreaterThan(time)) { return; } UInt64 previous_slot = get_current_slot(store); store.setTime(time); UInt64 current_slot = get_current_slot(store); if (!(current_slot.compareTo(previous_slot) > 0 && compute_slots_since_epoch_start(current_slot).equals(UInt64.ZERO))) { return; } if (store .getBestJustifiedCheckpoint() .getEpoch() .compareTo(store.getJustifiedCheckpoint().getEpoch()) > 0) { store.setJustifiedCheckpoint(store.getBestJustifiedCheckpoint()); } } }
ForkChoiceUtil { public static void on_tick(MutableStore store, UInt64 time) { if (store.getTime().isGreaterThan(time) || store.getGenesisTime().isGreaterThan(time)) { return; } UInt64 previous_slot = get_current_slot(store); store.setTime(time); UInt64 current_slot = get_current_slot(store); if (!(current_slot.compareTo(previous_slot) > 0 && compute_slots_since_epoch_start(current_slot).equals(UInt64.ZERO))) { return; } if (store .getBestJustifiedCheckpoint() .getEpoch() .compareTo(store.getJustifiedCheckpoint().getEpoch()) > 0) { store.setJustifiedCheckpoint(store.getBestJustifiedCheckpoint()); } }  }
ForkChoiceUtil { public static void on_tick(MutableStore store, UInt64 time) { if (store.getTime().isGreaterThan(time) || store.getGenesisTime().isGreaterThan(time)) { return; } UInt64 previous_slot = get_current_slot(store); store.setTime(time); UInt64 current_slot = get_current_slot(store); if (!(current_slot.compareTo(previous_slot) > 0 && compute_slots_since_epoch_start(current_slot).equals(UInt64.ZERO))) { return; } if (store .getBestJustifiedCheckpoint() .getEpoch() .compareTo(store.getJustifiedCheckpoint().getEpoch()) > 0) { store.setJustifiedCheckpoint(store.getBestJustifiedCheckpoint()); } }  static UInt64 get_slots_since_genesis(ReadOnlyStore store, boolean useUnixTime); static UInt64 getCurrentSlot(UInt64 currentTime, UInt64 genesisTime); static UInt64 getSlotStartTime(UInt64 slotNumber, UInt64 genesisTime); static UInt64 get_current_slot(ReadOnlyStore store, boolean useUnixTime); static UInt64 get_current_slot(ReadOnlyStore store); static UInt64 compute_slots_since_epoch_start(UInt64 slot); static Optional<Bytes32> get_ancestor(
      ForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 slot); static NavigableMap<UInt64, Bytes32> getAncestors(
      ForkChoiceStrategy forkChoiceStrategy,
      Bytes32 root,
      UInt64 startSlot,
      UInt64 step,
      UInt64 count); static NavigableMap<UInt64, Bytes32> getAncestorsOnFork(
      ForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 startSlot); static void on_tick(MutableStore store, UInt64 time); @CheckReturnValue static BlockImportResult on_block(
      final MutableStore store,
      final SignedBeaconBlock signed_block,
      Optional<BeaconState> maybePreState,
      final StateTransition st,
      final ForkChoiceStrategy forkChoiceStrategy,
      final Consumer<BeaconState> beaconStateConsumer,
      final IndexedAttestationProvider indexedAttestationProvider); static boolean blockDescendsFromLatestFinalizedBlock(
      final BeaconBlock block,
      final ReadOnlyStore store,
      final ForkChoiceStrategy forkChoiceStrategy); @CheckReturnValue static AttestationProcessingResult on_attestation(
      final MutableStore store,
      final ValidateableAttestation validateableAttestation,
      final Optional<BeaconState> maybeTargetState,
      final ForkChoiceStrategy forkChoiceStrategy); }
ForkChoiceUtil { public static void on_tick(MutableStore store, UInt64 time) { if (store.getTime().isGreaterThan(time) || store.getGenesisTime().isGreaterThan(time)) { return; } UInt64 previous_slot = get_current_slot(store); store.setTime(time); UInt64 current_slot = get_current_slot(store); if (!(current_slot.compareTo(previous_slot) > 0 && compute_slots_since_epoch_start(current_slot).equals(UInt64.ZERO))) { return; } if (store .getBestJustifiedCheckpoint() .getEpoch() .compareTo(store.getJustifiedCheckpoint().getEpoch()) > 0) { store.setJustifiedCheckpoint(store.getBestJustifiedCheckpoint()); } }  static UInt64 get_slots_since_genesis(ReadOnlyStore store, boolean useUnixTime); static UInt64 getCurrentSlot(UInt64 currentTime, UInt64 genesisTime); static UInt64 getSlotStartTime(UInt64 slotNumber, UInt64 genesisTime); static UInt64 get_current_slot(ReadOnlyStore store, boolean useUnixTime); static UInt64 get_current_slot(ReadOnlyStore store); static UInt64 compute_slots_since_epoch_start(UInt64 slot); static Optional<Bytes32> get_ancestor(
      ForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 slot); static NavigableMap<UInt64, Bytes32> getAncestors(
      ForkChoiceStrategy forkChoiceStrategy,
      Bytes32 root,
      UInt64 startSlot,
      UInt64 step,
      UInt64 count); static NavigableMap<UInt64, Bytes32> getAncestorsOnFork(
      ForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 startSlot); static void on_tick(MutableStore store, UInt64 time); @CheckReturnValue static BlockImportResult on_block(
      final MutableStore store,
      final SignedBeaconBlock signed_block,
      Optional<BeaconState> maybePreState,
      final StateTransition st,
      final ForkChoiceStrategy forkChoiceStrategy,
      final Consumer<BeaconState> beaconStateConsumer,
      final IndexedAttestationProvider indexedAttestationProvider); static boolean blockDescendsFromLatestFinalizedBlock(
      final BeaconBlock block,
      final ReadOnlyStore store,
      final ForkChoiceStrategy forkChoiceStrategy); @CheckReturnValue static AttestationProcessingResult on_attestation(
      final MutableStore store,
      final ValidateableAttestation validateableAttestation,
      final Optional<BeaconState> maybeTargetState,
      final ForkChoiceStrategy forkChoiceStrategy);  }