Search in sources :

Example 1 with IndexedAttestationSchema

use of tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema in project teku by ConsenSys.

the class AttestationUtil method getIndexedAttestation.

/**
 * Return the indexed attestation corresponding to ``attestation``.
 *
 * @param state
 * @param attestation
 * @return
 * @see
 *     <a>https://github.com/ethereum/eth2.0-specs/blob/v0.8.0/specs/core/0_beacon-chain.md#get_indexed_attestation</a>
 */
public IndexedAttestation getIndexedAttestation(BeaconState state, Attestation attestation) {
    List<Integer> attesting_indices = getAttestingIndices(state, attestation.getData(), attestation.getAggregationBits());
    final IndexedAttestationSchema indexedAttestationSchema = schemaDefinitions.getIndexedAttestationSchema();
    return indexedAttestationSchema.create(attesting_indices.stream().sorted().map(UInt64::valueOf).collect(indexedAttestationSchema.getAttestingIndicesSchema().collectorUnboxed()), attestation.getData(), attestation.getAggregateSignature());
}
Also used : IndexedAttestationSchema(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Example 2 with IndexedAttestationSchema

use of tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema in project teku by ConsenSys.

the class DataStructureUtil method randomIndexedAttestation.

public IndexedAttestation randomIndexedAttestation(final UInt64... attestingIndices) {
    final IndexedAttestationSchema indexedAttestationSchema = spec.getGenesisSchemaDefinitions().getIndexedAttestationSchema();
    SszUInt64List attesting_indices = indexedAttestationSchema.getAttestingIndicesSchema().of(attestingIndices);
    return indexedAttestationSchema.create(attesting_indices, randomAttestationData(), randomSignature());
}
Also used : IndexedAttestationSchema(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema) SszUInt64List(tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List)

Example 3 with IndexedAttestationSchema

use of tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema in project teku by ConsenSys.

the class ForkChoiceTest method applyAttestationFromValidator.

private UInt64 applyAttestationFromValidator(final UInt64 validatorIndex, final SignedBlockAndState targetBlock) {
    // Note this attestation is wildly invalid but we're going to shove it straight into fork choice
    // as pre-validated.
    final UInt64 updatedAttestationSlot = UInt64.valueOf(20);
    final ValidateableAttestation updatedVote = ValidateableAttestation.from(spec, attestationSchema.create(attestationSchema.getAggregationBitsSchema().ofBits(16), new AttestationData(updatedAttestationSlot, UInt64.ONE, targetBlock.getRoot(), recentChainData.getStore().getJustifiedCheckpoint(), new Checkpoint(spec.computeEpochAtSlot(updatedAttestationSlot), targetBlock.getRoot())), dataStructureUtil.randomSignature()));
    final IndexedAttestationSchema indexedAttestationSchema = spec.atSlot(updatedAttestationSlot).getSchemaDefinitions().getIndexedAttestationSchema();
    updatedVote.setIndexedAttestation(indexedAttestationSchema.create(indexedAttestationSchema.getAttestingIndicesSchema().of(validatorIndex), updatedVote.getData(), updatedVote.getAttestation().getAggregateSignature()));
    forkChoice.applyIndexedAttestations(List.of(updatedVote));
    return updatedAttestationSlot;
}
Also used : IndexedAttestationSchema(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema) AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)

Example 4 with IndexedAttestationSchema

use of tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema in project teku by ConsenSys.

the class BeaconBlockBodySchemaPhase0Test method create_mainnet.

@Test
public void create_mainnet() {
    final Spec spec = TestSpecFactory.createMainnetPhase0();
    final SpecConfig specConfig = spec.getGenesisSpecConfig();
    final BeaconBlockBodySchemaPhase0 specA = BeaconBlockBodySchemaPhase0.create(specConfig, new AttesterSlashingSchema(new IndexedAttestationSchema(specConfig)));
    final BeaconBlockBodySchemaPhase0 specB = BeaconBlockBodySchemaPhase0.create(specConfig, new AttesterSlashingSchema(new IndexedAttestationSchema(specConfig)));
    assertThat(specA).isEqualTo(specB);
}
Also used : IndexedAttestationSchema(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema) AttesterSlashingSchema(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing.AttesterSlashingSchema) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Spec(tech.pegasys.teku.spec.Spec) Test(org.junit.jupiter.api.Test)

Example 5 with IndexedAttestationSchema

use of tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema in project teku by ConsenSys.

the class BeaconBlockBodySchemaPhase0Test method create_minimal.

@Test
public void create_minimal() {
    final Spec spec = TestSpecFactory.createMinimalPhase0();
    final SpecConfig specConfig = spec.getGenesisSpecConfig();
    final BeaconBlockBodySchemaPhase0 specA = BeaconBlockBodySchemaPhase0.create(specConfig, new AttesterSlashingSchema(new IndexedAttestationSchema(specConfig)));
    final BeaconBlockBodySchemaPhase0 specB = BeaconBlockBodySchemaPhase0.create(specConfig, new AttesterSlashingSchema(new IndexedAttestationSchema(specConfig)));
    assertThat(specA).isEqualTo(specB);
}
Also used : IndexedAttestationSchema(tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema) AttesterSlashingSchema(tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing.AttesterSlashingSchema) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Spec(tech.pegasys.teku.spec.Spec) Test(org.junit.jupiter.api.Test)

Aggregations

IndexedAttestationSchema (tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation.IndexedAttestationSchema)5 Test (org.junit.jupiter.api.Test)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 Spec (tech.pegasys.teku.spec.Spec)2 SpecConfig (tech.pegasys.teku.spec.config.SpecConfig)2 AttesterSlashingSchema (tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing.AttesterSlashingSchema)2 SszUInt64List (tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List)1 ValidateableAttestation (tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation)1 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)1 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)1