@Test void getAncestors_shouldGetSimpleSequenceOfAncestors() { chainBuilder.generateBlocksUpToSlot(10).forEach(this::addBlock); final NavigableMap<UInt64, Bytes32> rootsBySlot = ForkChoiceUtil.getAncestors( forkChoiceStrategy, chainBuilder.getLatestBlockAndState().getRoot(), UInt64.ONE, UInt64.ONE, UInt64.valueOf(8)); assertThat(rootsBySlot).containsExactlyEntriesOf(getRootsForBlocks(1, 2, 3, 4, 5, 6, 7, 8)); }
public static NavigableMap<UInt64, Bytes32> getAncestors( ForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 startSlot, UInt64 step, UInt64 count) { final NavigableMap<UInt64, Bytes32> roots = new TreeMap<>(); final UInt64 endSlot = startSlot.plus(step.times(count)).minus(UInt64.ONE); Bytes32 parentRoot = root; Optional<UInt64> parentSlot = forkChoiceStrategy.blockSlot(parentRoot); while (parentSlot.isPresent() && parentSlot.get().compareTo(startSlot) > 0) { maybeAddRoot(startSlot, step, roots, endSlot, parentRoot, parentSlot); parentRoot = forkChoiceStrategy.blockParentRoot(parentRoot).orElseThrow(); parentSlot = forkChoiceStrategy.blockSlot(parentRoot); } maybeAddRoot(startSlot, step, roots, endSlot, parentRoot, parentSlot); return roots; }
ForkChoiceUtil { public static NavigableMap<UInt64, Bytes32> getAncestors( ForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 startSlot, UInt64 step, UInt64 count) { final NavigableMap<UInt64, Bytes32> roots = new TreeMap<>(); final UInt64 endSlot = startSlot.plus(step.times(count)).minus(UInt64.ONE); Bytes32 parentRoot = root; Optional<UInt64> parentSlot = forkChoiceStrategy.blockSlot(parentRoot); while (parentSlot.isPresent() && parentSlot.get().compareTo(startSlot) > 0) { maybeAddRoot(startSlot, step, roots, endSlot, parentRoot, parentSlot); parentRoot = forkChoiceStrategy.blockParentRoot(parentRoot).orElseThrow(); parentSlot = forkChoiceStrategy.blockSlot(parentRoot); } maybeAddRoot(startSlot, step, roots, endSlot, parentRoot, parentSlot); return roots; } }
ForkChoiceUtil { public static NavigableMap<UInt64, Bytes32> getAncestors( ForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 startSlot, UInt64 step, UInt64 count) { final NavigableMap<UInt64, Bytes32> roots = new TreeMap<>(); final UInt64 endSlot = startSlot.plus(step.times(count)).minus(UInt64.ONE); Bytes32 parentRoot = root; Optional<UInt64> parentSlot = forkChoiceStrategy.blockSlot(parentRoot); while (parentSlot.isPresent() && parentSlot.get().compareTo(startSlot) > 0) { maybeAddRoot(startSlot, step, roots, endSlot, parentRoot, parentSlot); parentRoot = forkChoiceStrategy.blockParentRoot(parentRoot).orElseThrow(); parentSlot = forkChoiceStrategy.blockSlot(parentRoot); } maybeAddRoot(startSlot, step, roots, endSlot, parentRoot, parentSlot); return roots; }  }
ForkChoiceUtil { public static NavigableMap<UInt64, Bytes32> getAncestors( ForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 startSlot, UInt64 step, UInt64 count) { final NavigableMap<UInt64, Bytes32> roots = new TreeMap<>(); final UInt64 endSlot = startSlot.plus(step.times(count)).minus(UInt64.ONE); Bytes32 parentRoot = root; Optional<UInt64> parentSlot = forkChoiceStrategy.blockSlot(parentRoot); while (parentSlot.isPresent() && parentSlot.get().compareTo(startSlot) > 0) { maybeAddRoot(startSlot, step, roots, endSlot, parentRoot, parentSlot); parentRoot = forkChoiceStrategy.blockParentRoot(parentRoot).orElseThrow(); parentSlot = forkChoiceStrategy.blockSlot(parentRoot); } maybeAddRoot(startSlot, step, roots, endSlot, parentRoot, parentSlot); return roots; }  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 NavigableMap<UInt64, Bytes32> getAncestors( ForkChoiceStrategy forkChoiceStrategy, Bytes32 root, UInt64 startSlot, UInt64 step, UInt64 count) { final NavigableMap<UInt64, Bytes32> roots = new TreeMap<>(); final UInt64 endSlot = startSlot.plus(step.times(count)).minus(UInt64.ONE); Bytes32 parentRoot = root; Optional<UInt64> parentSlot = forkChoiceStrategy.blockSlot(parentRoot); while (parentSlot.isPresent() && parentSlot.get().compareTo(startSlot) > 0) { maybeAddRoot(startSlot, step, roots, endSlot, parentRoot, parentSlot); parentRoot = forkChoiceStrategy.blockParentRoot(parentRoot).orElseThrow(); parentSlot = forkChoiceStrategy.blockSlot(parentRoot); } maybeAddRoot(startSlot, step, roots, endSlot, parentRoot, parentSlot); return roots; }  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);  }