Search in sources :

Example 1 with SszBitvector

use of tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector in project teku by ConsenSys.

the class SubnetScorer method scoreExistingPeer.

@Override
public int scoreExistingPeer(final NodeId peerId) {
    final SszBitvector attSubscriptions = peerSubnetSubscriptions.getAttestationSubnetSubscriptions(peerId);
    final SszBitvector syncCommitteeSubscriptions = peerSubnetSubscriptions.getSyncCommitteeSubscriptions(peerId);
    return score(attSubscriptions, syncCommitteeSubscriptions, this::scoreSubnetForExistingPeer);
}
Also used : SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector)

Example 2 with SszBitvector

use of tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector in project teku by ConsenSys.

the class NodeRecordConverterTest method shouldConvertAttnets.

@Test
public void shouldConvertAttnets() {
    SszBitvector persistentSubnets = ATT_SUBNET_SCHEMA.ofBits(1, 8, 14, 32);
    Bytes encodedPersistentSubnets = persistentSubnets.sszSerialize();
    final Optional<DiscoveryPeer> result = convertNodeRecordWithFields(new EnrField(EnrField.IP_V6, IPV6_LOCALHOST), new EnrField(EnrField.TCP_V6, 1234), new EnrField(ATTESTATION_SUBNET_ENR_FIELD, encodedPersistentSubnets));
    assertThat(result).contains(new DiscoveryPeer(PUB_KEY, new InetSocketAddress("::1", 1234), ENR_FORK_ID, persistentSubnets, SYNCNETS));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) DiscoveryPeer(tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer) EnrField(org.ethereum.beacon.discovery.schema.EnrField) InetSocketAddress(java.net.InetSocketAddress) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) Test(org.junit.jupiter.api.Test)

Example 3 with SszBitvector

use of tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector in project teku by ConsenSys.

the class NodeRecordConverterTest method shouldUseEmptyAttnetsWhenFieldValueIsInvalid.

@Test
public void shouldUseEmptyAttnetsWhenFieldValueIsInvalid() {
    // Incorrect length
    SszBitvector persistentSubnets = SszBitvectorSchema.create(4).ofBits(1, 2);
    Bytes encodedPersistentSubnets = persistentSubnets.sszSerialize();
    final Optional<DiscoveryPeer> result = convertNodeRecordWithFields(new EnrField(EnrField.IP_V6, IPV6_LOCALHOST), new EnrField(EnrField.TCP_V6, 1234), new EnrField(ATTESTATION_SUBNET_ENR_FIELD, encodedPersistentSubnets));
    assertThat(result).contains(new DiscoveryPeer(PUB_KEY, new InetSocketAddress("::1", 1234), ENR_FORK_ID, ATT_SUBNET_SCHEMA.getDefault(), SYNCNETS));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) DiscoveryPeer(tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer) EnrField(org.ethereum.beacon.discovery.schema.EnrField) InetSocketAddress(java.net.InetSocketAddress) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) Test(org.junit.jupiter.api.Test)

Example 4 with SszBitvector

use of tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector in project teku by ConsenSys.

the class ValidatorDataProvider method getAggregationBits.

private IntIterable getAggregationBits(final Bytes aggregationBits, final UInt64 slot) {
    final SchemaDefinitionsAltair altairDefinitions = SchemaDefinitionsAltair.required(spec.atSlot(slot).getSchemaDefinitions());
    final SyncCommitteeContributionSchema syncCommitteeContributionSchema = altairDefinitions.getSyncCommitteeContributionSchema();
    final SszBitvector aggregationBitsVector = syncCommitteeContributionSchema.getAggregationBitsSchema().fromBytes(aggregationBits);
    return aggregationBitsVector.getAllSetBits();
}
Also used : SchemaDefinitionsAltair(tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair) SyncCommitteeContributionSchema(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContributionSchema) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector)

Example 5 with SszBitvector

use of tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector in project teku by ConsenSys.

the class SyncCommitteeContribution method asInternalSyncCommitteeContribution.

public static tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution asInternalSyncCommitteeContribution(final Spec spec, final SyncCommitteeContribution syncCommitteeContribution) {
    final SchemaDefinitionsAltair altairDefinitions = SchemaDefinitionsAltair.required(spec.atSlot(syncCommitteeContribution.slot).getSchemaDefinitions());
    final SyncCommitteeContributionSchema syncCommitteeContributionSchema = altairDefinitions.getSyncCommitteeContributionSchema();
    final SszBitvector aggregationBitsVector = syncCommitteeContributionSchema.getAggregationBitsSchema().fromBytes(syncCommitteeContribution.aggregationBits);
    return spec.getSyncCommitteeUtilRequired(syncCommitteeContribution.slot).createSyncCommitteeContribution(syncCommitteeContribution.slot, syncCommitteeContribution.beaconBlockRoot, syncCommitteeContribution.subcommitteeIndex, aggregationBitsVector.getAllSetBits(), syncCommitteeContribution.signature.asInternalBLSSignature());
}
Also used : SchemaDefinitionsAltair(tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair) SyncCommitteeContributionSchema(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContributionSchema) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector)

Aggregations

SszBitvector (tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector)18 Test (org.junit.jupiter.api.Test)9 Bytes (org.apache.tuweni.bytes.Bytes)7 DiscoveryPeer (tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer)5 InetSocketAddress (java.net.InetSocketAddress)4 EnrField (org.ethereum.beacon.discovery.schema.EnrField)4 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)4 EnrForkId (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId)2 SyncCommitteeContributionSchema (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContributionSchema)2 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)2 SchemaDefinitionsAltair (tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 IntSet (it.unimi.dsi.fastutil.ints.IntSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Collectors.toList (java.util.stream.Collectors.toList)1