use of tech.pegasys.teku.api.schema.interfaces.SignedBlock in project teku by ConsenSys.
the class TekuNode method waitForAttestationBeingGossiped.
public void waitForAttestationBeingGossiped(int validatorSeparationIndex, int totalValidatorCount) {
List<UInt64> node1Validators = IntStream.range(0, validatorSeparationIndex).mapToObj(UInt64::valueOf).collect(toList());
List<UInt64> node2Validators = IntStream.range(validatorSeparationIndex, totalValidatorCount).mapToObj(UInt64::valueOf).collect(toList());
waitFor(() -> {
final Optional<SignedBlock> maybeBlock = fetchHeadBlock();
final Optional<BeaconState> maybeState = fetchHeadState();
assertThat(maybeBlock).isPresent();
assertThat(maybeState).isPresent();
SignedBeaconBlock block = (SignedBeaconBlock) maybeBlock.get();
BeaconState state = maybeState.get();
// Check that the fetched block and state are in sync
assertThat(state.latest_block_header.parent_root).isEqualTo(block.getMessage().parent_root);
tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState internalBeaconState = state.asInternalBeaconState(spec);
UInt64 proposerIndex = block.getMessage().proposer_index;
Set<UInt64> attesterIndicesInAttestations = block.getMessage().getBody().attestations.stream().map(a -> spec.getAttestingIndices(internalBeaconState, a.asInternalAttestation(spec).getData(), a.asInternalAttestation(spec).getAggregationBits())).flatMap(Collection::stream).map(UInt64::valueOf).collect(toSet());
if (node1Validators.contains(proposerIndex)) {
assertThat(attesterIndicesInAttestations.stream().anyMatch(node2Validators::contains)).isTrue();
} else if (node2Validators.contains(proposerIndex)) {
assertThat(attesterIndicesInAttestations.stream().anyMatch(node1Validators::contains)).isTrue();
} else {
throw new IllegalStateException("Proposer index greater than total validator count");
}
}, 2, MINUTES);
}
use of tech.pegasys.teku.api.schema.interfaces.SignedBlock in project teku by ConsenSys.
the class TekuNode method waitForFullSyncCommitteeAggregate.
public void waitForFullSyncCommitteeAggregate() {
LOG.debug("Wait for full sync committee aggregates");
waitFor(() -> {
final Optional<SignedBlock> block = fetchHeadBlock();
assertThat(block).isPresent();
assertThat(block.get()).isInstanceOf(SignedBeaconBlockAltair.class);
final SignedBeaconBlockAltair altairBlock = (SignedBeaconBlockAltair) block.get();
final int syncCommitteeSize = spec.getSyncCommitteeSize(altairBlock.getMessage().slot);
final SszBitvectorSchema<SszBitvector> syncCommitteeSchema = SszBitvectorSchema.create(syncCommitteeSize);
final Bytes syncCommitteeBits = altairBlock.getMessage().getBody().syncAggregate.syncCommitteeBits;
final int actualSyncBitCount = syncCommitteeSchema.sszDeserialize(syncCommitteeBits).getBitCount();
final double percentageOfBitsSet = actualSyncBitCount == syncCommitteeSize ? 1.0 : actualSyncBitCount / (double) syncCommitteeSize;
if (percentageOfBitsSet < 1.0) {
LOG.debug(String.format("Sync committee bits are only %s%% full, expecting %s%%: %s", percentageOfBitsSet * 100, 100, syncCommitteeBits));
}
assertThat(percentageOfBitsSet >= 1.0).isTrue();
}, 5, MINUTES);
}
Aggregations