Search in sources :

Example 1 with SignedBlock

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);
}
Also used : SignedBeaconBlockAltair(tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair) Arrays(java.util.Arrays) SszBitvectorSchema(tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema) ValidatorKeystores(tech.pegasys.teku.test.acceptance.dsl.tools.deposits.ValidatorKeystores) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) PostValidatorLivenessResponse(tech.pegasys.teku.api.response.v1.validator.PostValidatorLivenessResponse) Network(org.testcontainers.containers.Network) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) GetStateResponseV2(tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2) SpecFactory(tech.pegasys.teku.spec.SpecFactory) Duration(java.time.Duration) Map(java.util.Map) FinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.FinalityCheckpointsResponse) KEY_TYPE(io.libp2p.core.crypto.KEY_TYPE) URI(java.net.URI) SignedBlock(tech.pegasys.teku.api.schema.interfaces.SignedBlock) Bytes32(org.apache.tuweni.bytes.Bytes32) Collectors.toSet(java.util.stream.Collectors.toSet) HttpWaitStrategy(org.testcontainers.containers.wait.strategy.HttpWaitStrategy) PrivKey(io.libp2p.core.crypto.PrivKey) EventType(tech.pegasys.teku.api.response.v1.EventType) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) ValidatorLivenessRequest(tech.pegasys.teku.api.request.v1.validator.ValidatorLivenessRequest) Logger(org.apache.logging.log4j.Logger) SignedBeaconBlock(tech.pegasys.teku.api.schema.SignedBeaconBlock) MountableFile(org.testcontainers.utility.MountableFile) Optional(java.util.Optional) IntStream(java.util.stream.IntStream) IOUtils(org.testcontainers.shaded.org.apache.commons.io.IOUtils) GenesisStateConfig(tech.pegasys.teku.test.acceptance.dsl.tools.GenesisStateConfig) GetGenesisResponse(tech.pegasys.teku.api.response.v1.beacon.GetGenesisResponse) MINUTES(java.util.concurrent.TimeUnit.MINUTES) HashMap(java.util.HashMap) Bytes(org.apache.tuweni.bytes.Bytes) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) GetBlockResponseV2(tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2) SignedContributionAndProof(tech.pegasys.teku.api.schema.altair.SignedContributionAndProof) PeerId(io.libp2p.core.PeerId) ValidatorLivenessAtEpoch(tech.pegasys.teku.api.response.v1.validator.ValidatorLivenessAtEpoch) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) KeyKt(io.libp2p.core.crypto.KeyKt) Spec(tech.pegasys.teku.spec.Spec) GetStateFinalityCheckpointsResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateFinalityCheckpointsResponse) GenesisStateGenerator(tech.pegasys.teku.test.acceptance.dsl.tools.GenesisStateGenerator) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) HeadEvent(tech.pegasys.teku.api.response.v1.HeadEvent) FileOutputStream(java.io.FileOutputStream) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) File(java.io.File) BeaconState(tech.pegasys.teku.api.schema.BeaconState) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) GetBlockRootResponse(tech.pegasys.teku.api.response.v1.beacon.GetBlockRootResponse) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) SignedBeaconBlock(tech.pegasys.teku.api.schema.SignedBeaconBlock) SignedBlock(tech.pegasys.teku.api.schema.interfaces.SignedBlock) BeaconState(tech.pegasys.teku.api.schema.BeaconState) Collection(java.util.Collection) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Example 2 with SignedBlock

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);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) SignedBeaconBlockAltair(tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) SignedBlock(tech.pegasys.teku.api.schema.interfaces.SignedBlock)

Aggregations

Bytes (org.apache.tuweni.bytes.Bytes)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 PeerId (io.libp2p.core.PeerId)1 KEY_TYPE (io.libp2p.core.crypto.KEY_TYPE)1 KeyKt (io.libp2p.core.crypto.KeyKt)1 PrivKey (io.libp2p.core.crypto.PrivKey)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Files (java.nio.file.Files)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1