Search in sources :

Example 1 with StateSyncCommittees

use of tech.pegasys.teku.api.response.v1.beacon.StateSyncCommittees in project teku by ConsenSys.

the class ChainDataProvider method getSyncCommitteesFromState.

private StateSyncCommittees getSyncCommitteesFromState(final tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState state, final Optional<UInt64> epochQueryParam) {
    final UInt64 epoch = epochQueryParam.orElse(spec.computeEpochAtSlot(state.getSlot()));
    final UInt64 slot = spec.computeStartSlotAtEpoch(epoch);
    final Optional<SyncCommittee> maybeCommittee = spec.getSyncCommitteeUtil(slot).map(util -> util.getSyncCommittee(state, epoch));
    // returned
    if (maybeCommittee.isEmpty()) {
        return new StateSyncCommittees(List.of(), List.of());
    }
    final SyncCommittee committee = maybeCommittee.get();
    final List<UInt64> committeeIndices = committee.getPubkeys().stream().flatMap(pubkey -> spec.getValidatorIndex(state, pubkey.getBLSPublicKey()).stream()).map(UInt64::valueOf).collect(toList());
    return new StateSyncCommittees(committeeIndices, Lists.partition(committeeIndices, spec.atEpoch(epoch).getConfig().getTargetCommitteeSize()));
}
Also used : UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SyncCommittee(tech.pegasys.teku.spec.datastructures.state.SyncCommittee) StateSyncCommittees(tech.pegasys.teku.api.response.v1.beacon.StateSyncCommittees)

Aggregations

StateSyncCommittees (tech.pegasys.teku.api.response.v1.beacon.StateSyncCommittees)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 SyncCommittee (tech.pegasys.teku.spec.datastructures.state.SyncCommittee)1