Search in sources :

Example 1 with SszField

use of tech.pegasys.teku.infrastructure.ssz.sos.SszField in project teku by ConsenSys.

the class BeaconStateSchemaAltair method getUniqueFields.

public static List<SszField> getUniqueFields(final SpecConfig specConfig) {
    final SszField previousEpochAttestationsField = new SszField(PREVIOUS_EPOCH_PARTICIPATION_FIELD_INDEX, BeaconStateFields.PREVIOUS_EPOCH_PARTICIPATION, () -> SszListSchema.create(SszPrimitiveSchemas.BYTE_SCHEMA, specConfig.getValidatorRegistryLimit()));
    final SszField currentEpochAttestationsField = new SszField(CURRENT_EPOCH_PARTICIPATION_FIELD_INDEX, BeaconStateFields.CURRENT_EPOCH_PARTICIPATION, () -> SszListSchema.create(SszPrimitiveSchemas.BYTE_SCHEMA, specConfig.getValidatorRegistryLimit()));
    final SszField inactivityScores = new SszField(INACTIVITY_SCORES_FIELD_INDEX, BeaconStateFields.INACTIVITY_SCORES, SszUInt64ListSchema.create(specConfig.getValidatorRegistryLimit()));
    final SszField currentSyncCommitteeField = new SszField(CURRENT_SYNC_COMMITTEE_FIELD_INDEX, BeaconStateFields.CURRENT_SYNC_COMMITTEE, () -> new SyncCommitteeSchema(SpecConfigAltair.required(specConfig)));
    final SszField nextSyncCommitteeField = new SszField(NEXT_SYNC_COMMITTEE_FIELD_INDEX, BeaconStateFields.NEXT_SYNC_COMMITTEE, () -> new SyncCommitteeSchema(SpecConfigAltair.required(specConfig)));
    return List.of(previousEpochAttestationsField, currentEpochAttestationsField, inactivityScores, currentSyncCommitteeField, nextSyncCommitteeField);
}
Also used : SyncCommitteeSchema(tech.pegasys.teku.spec.datastructures.state.SyncCommittee.SyncCommitteeSchema) SszField(tech.pegasys.teku.infrastructure.ssz.sos.SszField)

Example 2 with SszField

use of tech.pegasys.teku.infrastructure.ssz.sos.SszField in project teku by ConsenSys.

the class AbstractBeaconStateSchemaTest method shouldValidateInvariantFields.

@Test
public void shouldValidateInvariantFields() {
    final SszField randomField = new SszField(2, "random", () -> SszVectorSchema.create(SszPrimitiveSchemas.BYTES32_SCHEMA, 10));
    assertThatThrownBy(() -> createSchema(List.of(GENESIS_TIME_FIELD, GENESIS_VALIDATORS_ROOT_FIELD, randomField))).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Expected invariant field 'slot' at index 2, but got 'random'");
}
Also used : SszField(tech.pegasys.teku.infrastructure.ssz.sos.SszField) Test(org.junit.jupiter.api.Test)

Example 3 with SszField

use of tech.pegasys.teku.infrastructure.ssz.sos.SszField in project teku by ConsenSys.

the class BeaconStateSchemaPhase0 method getUniqueFields.

private static List<SszField> getUniqueFields(final SpecConfig specConfig) {
    final PendingAttestationSchema pendingAttestationSchema = new PendingAttestationSchema(specConfig);
    final SszField previousEpochAttestationsField = new SszField(15, BeaconStateFields.PREVIOUS_EPOCH_ATTESTATIONS, () -> SszListSchema.create(pendingAttestationSchema, (long) specConfig.getMaxAttestations() * specConfig.getSlotsPerEpoch()));
    final SszField currentEpochAttestationsField = new SszField(16, BeaconStateFields.CURRENT_EPOCH_ATTESTATIONS, () -> SszListSchema.create(pendingAttestationSchema, (long) specConfig.getMaxAttestations() * specConfig.getSlotsPerEpoch()));
    return List.of(previousEpochAttestationsField, currentEpochAttestationsField);
}
Also used : SszField(tech.pegasys.teku.infrastructure.ssz.sos.SszField) PendingAttestationSchema(tech.pegasys.teku.spec.datastructures.state.PendingAttestation.PendingAttestationSchema)

Example 4 with SszField

use of tech.pegasys.teku.infrastructure.ssz.sos.SszField in project teku by ConsenSys.

the class AbstractBeaconStateSchema method validateFields.

private void validateFields(final List<SszField> fields) {
    for (int i = 0; i < fields.size(); i++) {
        final int fieldIndex = fields.get(i).getIndex();
        checkArgument(fieldIndex == i, "BeaconStateSchema fields must be ordered and contiguous.  Encountered unexpected index %s at fields element %s", fieldIndex, i);
    }
    final List<SszField> invariantFields = BeaconStateInvariants.getInvariantFields();
    checkArgument(fields.size() >= invariantFields.size(), "Must provide at least %s fields", invariantFields.size());
    for (SszField invariantField : invariantFields) {
        final int invariantIndex = invariantField.getIndex();
        final SszField actualField = fields.get(invariantIndex);
        checkArgument(actualField.equals(invariantField), "Expected invariant field '%s' at index %s, but got '%s'", invariantField.getName(), invariantIndex, actualField.getName());
    }
}
Also used : SszField(tech.pegasys.teku.infrastructure.ssz.sos.SszField)

Aggregations

SszField (tech.pegasys.teku.infrastructure.ssz.sos.SszField)4 Test (org.junit.jupiter.api.Test)1 PendingAttestationSchema (tech.pegasys.teku.spec.datastructures.state.PendingAttestation.PendingAttestationSchema)1 SyncCommitteeSchema (tech.pegasys.teku.spec.datastructures.state.SyncCommittee.SyncCommitteeSchema)1