Skip to content

Commit

Permalink
Migrate attester slashing and indexed attestation to schema registry (#…
Browse files Browse the repository at this point in the history
…8736)

* migrate-attester-slashing-and-indexed-att

* fix tests
  • Loading branch information
tbenr authored Oct 18, 2024
1 parent aa23460 commit 51f1f37
Show file tree
Hide file tree
Showing 47 changed files with 285 additions and 677 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private IndexedAttestation randomIndexedAttestation(
secretKey,
signingRootUtil.signingRootForSignAttestationData(attestationData, forkInfo));

final IndexedAttestationSchema<?> schema =
final IndexedAttestationSchema schema =
spec.getGenesisSchemaDefinitions().getIndexedAttestationSchema();
return schema.create(
Stream.of(index).collect(schema.getAttestingIndicesSchema().collectorUnboxed()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public void shouldReturnServerErrorWhenUnexpectedErrorHappens() throws Exception
final Response response =
post(
PostAttesterSlashing.ROUTE,
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()));
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()));
assertThat(response.code()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
}

Expand All @@ -78,9 +76,7 @@ public void shouldReturnSuccessWhenRequestBodyIsValid() throws Exception {
final Response response =
post(
PostAttesterSlashing.ROUTE,
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()));
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()));

verify(attesterSlashingPool).addLocal(slashing);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public void shouldReturnServerErrorWhenUnexpectedErrorHappens() throws Exception
final Response response =
post(
PostAttesterSlashingV2.ROUTE,
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()),
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()),
Collections.emptyMap(),
Optional.of(specMilestone.name().toLowerCase(Locale.ROOT)));
assertThat(response.code()).isEqualTo(500);
Expand All @@ -99,9 +97,7 @@ public void shouldReturnSuccessWhenRequestBodyIsValid() throws Exception {
final Response response =
post(
PostAttesterSlashingV2.ROUTE,
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()),
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()),
Collections.emptyMap(),
Optional.of(specMilestone.name().toLowerCase(Locale.ROOT)));

Expand All @@ -117,9 +113,7 @@ void shouldFailWhenMissingConsensusHeader() throws Exception {
final Response response =
post(
PostAttesterSlashingV2.ROUTE,
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()));
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()));

assertThat(response.code()).isEqualTo(SC_BAD_REQUEST);

Expand All @@ -139,9 +133,7 @@ void shouldFailWhenBadConsensusHeaderValue() throws Exception {
final Response response =
post(
PostAttesterSlashingV2.ROUTE,
JsonUtil.serialize(
slashing,
slashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition()),
JsonUtil.serialize(slashing, slashing.getSchema().getJsonTypeDefinition()),
Collections.emptyMap(),
Optional.of(badConsensusHeaderValue));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

public class AttesterSlashingEvent extends Event<AttesterSlashing> {
AttesterSlashingEvent(final AttesterSlashing attesterSlashing) {
super(
attesterSlashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition(),
attesterSlashing);
super(attesterSlashing.getSchema().getJsonTypeDefinition(), attesterSlashing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ private static EndpointMetadata createMetadata(
schemaDefinitionCache
.getSchemaDefinition(SpecMilestone.PHASE0)
.getAttesterSlashingSchema()
.castTypeToAttesterSlashingSchema()
.getJsonTypeDefinition();

final DeserializableTypeDefinition<AttesterSlashing> attesterSlashingElectraSchema =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public AttesterSlashing(

public tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing
asInternalAttesterSlashing(final SpecVersion spec) {
final AttesterSlashingSchema<?> attesterSlashingSchema =
final AttesterSlashingSchema attesterSlashingSchema =
spec.getSchemaDefinitions().getAttesterSlashingSchema();
return attesterSlashingSchema.create(
attestation_1.asInternalIndexedAttestation(spec),
Expand All @@ -58,10 +58,9 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof AttesterSlashing)) {
if (!(o instanceof AttesterSlashing that)) {
return false;
}
AttesterSlashing that = (AttesterSlashing) o;
return Objects.equals(attestation_1, that.attestation_1)
&& Objects.equals(attestation_2, that.attestation_2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public IndexedAttestation(

public tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation
asInternalIndexedAttestation(final SpecVersion spec) {
final IndexedAttestationSchema<?> indexedAttestationSchema =
final IndexedAttestationSchema indexedAttestationSchema =
spec.getSchemaDefinitions().getIndexedAttestationSchema();
return indexedAttestationSchema.create(
indexedAttestationSchema.getAttestingIndicesSchema().of(attesting_indices),
Expand All @@ -74,10 +74,9 @@ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof IndexedAttestation)) {
if (!(o instanceof IndexedAttestation that)) {
return false;
}
IndexedAttestation that = (IndexedAttestation) o;
return Objects.equals(attesting_indices, that.attesting_indices)
&& Objects.equals(data, that.data)
&& Objects.equals(signature, that.signature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.altair;

import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTESTER_SLASHING_SCHEMA;

import it.unimi.dsi.fastutil.longs.LongList;
import java.util.function.Function;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand All @@ -33,10 +35,9 @@
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttesterSlashingPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.IndexedAttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class BeaconBlockBodySchemaAltairImpl
extends ContainerSchema9<
Expand Down Expand Up @@ -79,7 +80,8 @@ private BeaconBlockBodySchemaAltairImpl(
public static BeaconBlockBodySchemaAltairImpl create(
final SpecConfig specConfig,
final long maxValidatorsPerAttestation,
final String containerName) {
final String containerName,
final SchemaRegistry schemaRegistry) {
return new BeaconBlockBodySchemaAltairImpl(
containerName,
namedSchema(BlockBodyFields.RANDAO_REVEAL, SszSignatureSchema.INSTANCE),
Expand All @@ -92,10 +94,7 @@ public static BeaconBlockBodySchemaAltairImpl create(
namedSchema(
BlockBodyFields.ATTESTER_SLASHINGS,
SszListSchema.create(
new AttesterSlashingPhase0Schema(
new IndexedAttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToIndexedAttestationSchema())
.castTypeToAttesterSlashingSchema(),
schemaRegistry.get(ATTESTER_SLASHING_SCHEMA),
specConfig.getMaxAttesterSlashings())),
namedSchema(
BlockBodyFields.ATTESTATIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttesterSlashingPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.IndexedAttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;
import tech.pegasys.teku.spec.schemas.registry.SchemaTypes;

public class BeaconBlockBodySchemaBellatrixImpl
extends ContainerSchema10<
Expand Down Expand Up @@ -88,7 +88,8 @@ private BeaconBlockBodySchemaBellatrixImpl(
public static BeaconBlockBodySchemaBellatrixImpl create(
final SpecConfigBellatrix specConfig,
final long maxValidatorsPerAttestation,
final String containerName) {
final String containerName,
final SchemaRegistry schemaRegistry) {
final ExecutionPayloadSchemaBellatrix executionPayloadSchemaBellatrix =
new ExecutionPayloadSchemaBellatrix(specConfig);
return new BeaconBlockBodySchemaBellatrixImpl(
Expand All @@ -103,10 +104,7 @@ public static BeaconBlockBodySchemaBellatrixImpl create(
namedSchema(
BlockBodyFields.ATTESTER_SLASHINGS,
SszListSchema.create(
new AttesterSlashingPhase0Schema(
new IndexedAttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToIndexedAttestationSchema())
.castTypeToAttesterSlashingSchema(),
schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA),
specConfig.getMaxAttesterSlashings())),
namedSchema(
BlockBodyFields.ATTESTATIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

package tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.bellatrix;

import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTESTER_SLASHING_SCHEMA;

import it.unimi.dsi.fastutil.longs.LongList;
import java.util.function.Function;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
Expand All @@ -38,10 +40,9 @@
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttesterSlashingPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.IndexedAttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;

public class BlindedBeaconBlockBodySchemaBellatrixImpl
extends ContainerSchema10<
Expand Down Expand Up @@ -88,6 +89,7 @@ public static BlindedBeaconBlockBodySchemaBellatrixImpl create(
final SpecConfigBellatrix specConfig,
final long maxValidatorsPerAttestation,
final String containerName,
final SchemaRegistry schemaRegistry,
final ExecutionPayloadHeaderSchemaBellatrix executionPayloadHeaderSchema) {
return new BlindedBeaconBlockBodySchemaBellatrixImpl(
containerName,
Expand All @@ -101,10 +103,7 @@ public static BlindedBeaconBlockBodySchemaBellatrixImpl create(
namedSchema(
BlockBodyFields.ATTESTER_SLASHINGS,
SszListSchema.create(
new AttesterSlashingPhase0Schema(
new IndexedAttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToIndexedAttestationSchema())
.castTypeToAttesterSlashingSchema(),
schemaRegistry.get(ATTESTER_SLASHING_SCHEMA),
specConfig.getMaxAttesterSlashings())),
namedSchema(
BlockBodyFields.ATTESTATIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttesterSlashingPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.IndexedAttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;
import tech.pegasys.teku.spec.schemas.registry.SchemaTypes;

public class BeaconBlockBodySchemaCapellaImpl
extends ContainerSchema11<
Expand Down Expand Up @@ -94,7 +94,8 @@ public static BeaconBlockBodySchemaCapellaImpl create(
final SpecConfigCapella specConfig,
final SignedBlsToExecutionChangeSchema blsToExecutionChangeSchema,
final long maxValidatorsPerAttestation,
final String containerName) {
final String containerName,
final SchemaRegistry schemaRegistry) {
return new BeaconBlockBodySchemaCapellaImpl(
containerName,
namedSchema(BlockBodyFields.RANDAO_REVEAL, SszSignatureSchema.INSTANCE),
Expand All @@ -107,10 +108,7 @@ public static BeaconBlockBodySchemaCapellaImpl create(
namedSchema(
BlockBodyFields.ATTESTER_SLASHINGS,
SszListSchema.create(
new AttesterSlashingPhase0Schema(
new IndexedAttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToIndexedAttestationSchema())
.castTypeToAttesterSlashingSchema(),
schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA),
specConfig.getMaxAttesterSlashings())),
namedSchema(
BlockBodyFields.ATTESTATIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttesterSlashingPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.IndexedAttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;
import tech.pegasys.teku.spec.schemas.registry.SchemaTypes;

public class BlindedBeaconBlockBodySchemaCapellaImpl
extends ContainerSchema11<
Expand Down Expand Up @@ -93,7 +93,8 @@ public static BlindedBeaconBlockBodySchemaCapellaImpl create(
final SpecConfigCapella specConfig,
final SignedBlsToExecutionChangeSchema signedBlsToExecutionChangeSchema,
final long maxValidatorsPerAttestation,
final String containerName) {
final String containerName,
final SchemaRegistry schemaRegistry) {
return new BlindedBeaconBlockBodySchemaCapellaImpl(
containerName,
namedSchema(BlockBodyFields.RANDAO_REVEAL, SszSignatureSchema.INSTANCE),
Expand All @@ -106,10 +107,7 @@ public static BlindedBeaconBlockBodySchemaCapellaImpl create(
namedSchema(
BlockBodyFields.ATTESTER_SLASHINGS,
SszListSchema.create(
new AttesterSlashingPhase0Schema(
new IndexedAttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToIndexedAttestationSchema())
.castTypeToAttesterSlashingSchema(),
schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA),
specConfig.getMaxAttesterSlashings())),
namedSchema(
BlockBodyFields.ATTESTATIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChangeSchema;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttesterSlashingPhase0Schema;
import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.IndexedAttestationPhase0Schema;
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
import tech.pegasys.teku.spec.datastructures.type.SszSignature;
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema;
import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry;
import tech.pegasys.teku.spec.schemas.registry.SchemaTypes;

public class BeaconBlockBodySchemaDenebImpl
extends ContainerSchema12<
Expand Down Expand Up @@ -100,7 +100,8 @@ public static BeaconBlockBodySchemaDenebImpl create(
final SignedBlsToExecutionChangeSchema blsToExecutionChangeSchema,
final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema,
final long maxValidatorsPerAttestation,
final String containerName) {
final String containerName,
final SchemaRegistry schemaRegistry) {
return new BeaconBlockBodySchemaDenebImpl(
containerName,
namedSchema(BlockBodyFields.RANDAO_REVEAL, SszSignatureSchema.INSTANCE),
Expand All @@ -113,10 +114,7 @@ public static BeaconBlockBodySchemaDenebImpl create(
namedSchema(
BlockBodyFields.ATTESTER_SLASHINGS,
SszListSchema.create(
new AttesterSlashingPhase0Schema(
new IndexedAttestationPhase0Schema(maxValidatorsPerAttestation)
.castTypeToIndexedAttestationSchema())
.castTypeToAttesterSlashingSchema(),
schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA),
specConfig.getMaxAttesterSlashings())),
namedSchema(
BlockBodyFields.ATTESTATIONS,
Expand Down
Loading

0 comments on commit 51f1f37

Please sign in to comment.