Search in sources :

Example 1 with SszBitlist

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

the class BitlistBenchmark method setAllBits.

@Benchmark
@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
public void setAllBits(Blackhole bh) {
    final SszBitlist target = createBitlist().or(MANY_BITS_SET);
    bh.consume(target);
}
Also used : SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) Measurement(org.openjdk.jmh.annotations.Measurement) Warmup(org.openjdk.jmh.annotations.Warmup) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 2 with SszBitlist

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

the class DataStructureUtil method randomBitlist.

public SszBitlist randomBitlist(int n) {
    Random random = new Random(nextSeed());
    int[] bits = IntStream.range(0, n).sequential().filter(__ -> random.nextBoolean()).toArray();
    return SszBitlistSchema.create(n).ofBits(n, bits);
}
Also used : SszPrimitive(tech.pegasys.teku.infrastructure.ssz.SszPrimitive) IndexedAttestation(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation) SszList(tech.pegasys.teku.infrastructure.ssz.SszList) MinGenesisTimeBlockEvent(tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SchemaDefinitionsAltair(tech.pegasys.teku.spec.schemas.SchemaDefinitionsAltair) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) PendingAttestation(tech.pegasys.teku.spec.datastructures.state.PendingAttestation) SszData(tech.pegasys.teku.infrastructure.ssz.SszData) BeaconBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState) EnrForkId(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId) Eth1Address(tech.pegasys.teku.spec.datastructures.eth1.Eth1Address) BeaconBlockBody(tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody) Stream(java.util.stream.Stream) BeaconStateSchemaPhase0(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStateSchemaPhase0) SszBytes32Vector(tech.pegasys.teku.infrastructure.ssz.collections.SszBytes32Vector) VoteTracker(tech.pegasys.teku.spec.datastructures.forkchoice.VoteTracker) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) SszPublicKey(tech.pegasys.teku.spec.datastructures.type.SszPublicKey) Bytes(org.apache.tuweni.bytes.Bytes) Supplier(java.util.function.Supplier) BeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockHeader) ContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof) ArrayList(java.util.ArrayList) ExecutionPayloadHeader(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader) SszListSchema(tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema) SszPrimitiveVectorSchema(tech.pegasys.teku.infrastructure.ssz.schema.collections.SszPrimitiveVectorSchema) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) SszPrimitiveListSchema(tech.pegasys.teku.infrastructure.ssz.schema.collections.SszPrimitiveListSchema) Domain(tech.pegasys.teku.spec.constants.Domain) Bytes8(tech.pegasys.teku.infrastructure.bytes.Bytes8) Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) BeaconStateSchema(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema) SyncCommitteeMessage(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) BLSTestUtil(tech.pegasys.teku.bls.BLSTestUtil) VoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.VoluntaryExit) SszBitlistSchema(tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitlistSchema) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) SyncAggregate(tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregate) SpecConfigBellatrix(tech.pegasys.teku.spec.config.SpecConfigBellatrix) SszBitvectorSchema(tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema) Random(java.util.Random) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) AttesterSlashing(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing) IndexedAttestationSchema(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) Eth1Data(tech.pegasys.teku.spec.datastructures.blocks.Eth1Data) BeaconBlockBodySchema(tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBodySchema) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) ExecutionPayload(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) UInt256(org.apache.tuweni.units.bigints.UInt256) Bytes32(org.apache.tuweni.bytes.Bytes32) SyncAggregateSchema(tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair.SyncAggregateSchema) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) BLS(tech.pegasys.teku.bls.BLS) BLSSignature(tech.pegasys.teku.bls.BLSSignature) SszUInt64List(tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List) SchemaDefinitions(tech.pegasys.teku.spec.schemas.SchemaDefinitions) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SszBytes32VectorSchema(tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBytes32VectorSchema) FAR_FUTURE_EPOCH(tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH) List(java.util.List) SszVectorSchema(tech.pegasys.teku.infrastructure.ssz.schema.SszVectorSchema) SszPrimitiveVector(tech.pegasys.teku.infrastructure.ssz.collections.SszPrimitiveVector) SszByte(tech.pegasys.teku.infrastructure.ssz.primitive.SszByte) Optional(java.util.Optional) SszVector(tech.pegasys.teku.infrastructure.ssz.SszVector) Bytes48(org.apache.tuweni.bytes.Bytes48) DepositMessage(tech.pegasys.teku.spec.datastructures.operations.DepositMessage) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) IntStream(java.util.stream.IntStream) AggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof) SignedBeaconBlockHeader(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader) Fork(tech.pegasys.teku.spec.datastructures.state.Fork) Function(java.util.function.Function) SYNC_COMMITTEE_SUBNET_COUNT(tech.pegasys.teku.spec.constants.NetworkConstants.SYNC_COMMITTEE_SUBNET_COUNT) SpecVersion(tech.pegasys.teku.spec.SpecVersion) SyncCommitteeSchema(tech.pegasys.teku.spec.datastructures.state.SyncCommittee.SyncCommitteeSchema) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) ProposerSlashing(tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing) Bytes20(tech.pegasys.teku.infrastructure.bytes.Bytes20) SchemaDefinitionsBellatrix(tech.pegasys.teku.spec.schemas.SchemaDefinitionsBellatrix) DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent) Spec(tech.pegasys.teku.spec.Spec) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Validator(tech.pegasys.teku.spec.datastructures.state.Validator) ForkChoiceState(tech.pegasys.teku.spec.executionengine.ForkChoiceState) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) SszPrimitiveList(tech.pegasys.teku.infrastructure.ssz.collections.SszPrimitiveList) SszUInt64ListSchema(tech.pegasys.teku.infrastructure.ssz.schema.collections.SszUInt64ListSchema) BeaconBlockSchema(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSchema) PendingAttestationSchema(tech.pegasys.teku.spec.datastructures.state.PendingAttestation.PendingAttestationSchema) SyncCommittee(tech.pegasys.teku.spec.datastructures.state.SyncCommittee) Collectors.toList(java.util.stream.Collectors.toList) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint) BeaconStateSchemaAltair(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateSchemaAltair) DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Random(java.util.Random)

Example 3 with SszBitlist

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

the class AggregatorUtil method aggregateAttestations.

public static Attestation aggregateAttestations(final Attestation firstAttestation, final Attestation... attestations) {
    SszBitlist aggregateBits = firstAttestation.getAggregationBits();
    final List<BLSSignature> signatures = new ArrayList<>();
    signatures.add(firstAttestation.getAggregateSignature());
    for (Attestation attestation : attestations) {
        aggregateBits = aggregateBits.or(attestation.getAggregationBits());
        signatures.add(attestation.getAggregateSignature());
    }
    return firstAttestation.getSchema().create(aggregateBits, firstAttestation.getData(), BLS.aggregate(signatures));
}
Also used : ArrayList(java.util.ArrayList) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Example 4 with SszBitlist

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

the class AttestationProductionDutyTest method createExpectedAttestation.

public Attestation createExpectedAttestation(final AttestationData attestationData, final int committeePosition, final int committeeSize, final BLSSignature signature) {
    final AttestationSchema attestationSchema = spec.atSlot(attestationData.getSlot()).getSchemaDefinitions().getAttestationSchema();
    final SszBitlist expectedAggregationBits = attestationSchema.getAggregationBitsSchema().ofBits(committeeSize, committeePosition);
    return attestationSchema.create(expectedAggregationBits, attestationData, signature);
}
Also used : AttestationSchema(tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema) SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist)

Example 5 with SszBitlist

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

the class AttestationValidatorTest method shouldRejectAttestationWithIncorrectAggregateBitsSize.

@Test
public void shouldRejectAttestationWithIncorrectAggregateBitsSize() {
    final Attestation attestation = attestationGenerator.validAttestation(storageSystem.getChainHead());
    final SszBitlist validAggregationBits = attestation.getAggregationBits();
    SszBitlist invalidAggregationBits = validAggregationBits.getSchema().ofBits(validAggregationBits.size() + 1).or(validAggregationBits);
    final Attestation invalidAttestation = attestationSchema.create(invalidAggregationBits, attestation.getData(), attestation.getAggregateSignature());
    assertThat(validate(invalidAttestation).code()).isEqualTo(REJECT);
}
Also used : SszBitlist(tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Test(org.junit.jupiter.api.Test)

Aggregations

SszBitlist (tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist)25 Test (org.junit.jupiter.api.Test)15 PendingAttestation (tech.pegasys.teku.spec.datastructures.state.PendingAttestation)8 ArrayList (java.util.ArrayList)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)6 BLSSignature (tech.pegasys.teku.bls.BLSSignature)5 AttestationSchema (tech.pegasys.teku.spec.datastructures.operations.Attestation.AttestationSchema)4 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)4 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)3 IntList (it.unimi.dsi.fastutil.ints.IntList)2 List (java.util.List)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 Measurement (org.openjdk.jmh.annotations.Measurement)2 Warmup (org.openjdk.jmh.annotations.Warmup)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1