diff --git a/acceptance-tests/src/testFixtures/java/tech/pegasys/teku/test/acceptance/dsl/TekuBeaconNode.java b/acceptance-tests/src/testFixtures/java/tech/pegasys/teku/test/acceptance/dsl/TekuBeaconNode.java index 40cc58845aa..ca23f2793ce 100644 --- a/acceptance-tests/src/testFixtures/java/tech/pegasys/teku/test/acceptance/dsl/TekuBeaconNode.java +++ b/acceptance-tests/src/testFixtures/java/tech/pegasys/teku/test/acceptance/dsl/TekuBeaconNode.java @@ -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()), diff --git a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/beacon/PostAttesterSlashingIntegrationTest.java b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/beacon/PostAttesterSlashingIntegrationTest.java index 92d670a017d..142d14ee5b4 100644 --- a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/beacon/PostAttesterSlashingIntegrationTest.java +++ b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/beacon/PostAttesterSlashingIntegrationTest.java @@ -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); } @@ -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); diff --git a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v2/beacon/PostAttesterSlashingV2IntegrationTest.java b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v2/beacon/PostAttesterSlashingV2IntegrationTest.java index a9905fbaec2..ec8a79a9c54 100644 --- a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v2/beacon/PostAttesterSlashingV2IntegrationTest.java +++ b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v2/beacon/PostAttesterSlashingV2IntegrationTest.java @@ -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); @@ -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))); @@ -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); @@ -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)); diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/events/AttesterSlashingEvent.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/events/AttesterSlashingEvent.java index 3b8790695a2..47cd86f5114 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/events/AttesterSlashingEvent.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/events/AttesterSlashingEvent.java @@ -17,8 +17,6 @@ public class AttesterSlashingEvent extends Event { AttesterSlashingEvent(final AttesterSlashing attesterSlashing) { - super( - attesterSlashing.getSchema().castTypeToAttesterSlashingSchema().getJsonTypeDefinition(), - attesterSlashing); + super(attesterSlashing.getSchema().getJsonTypeDefinition(), attesterSlashing); } } diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostAttesterSlashingV2.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostAttesterSlashingV2.java index 776cc7dd343..4217eb91480 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostAttesterSlashingV2.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostAttesterSlashingV2.java @@ -61,7 +61,6 @@ private static EndpointMetadata createMetadata( schemaDefinitionCache .getSchemaDefinition(SpecMilestone.PHASE0) .getAttesterSlashingSchema() - .castTypeToAttesterSlashingSchema() .getJsonTypeDefinition(); final DeserializableTypeDefinition attesterSlashingElectraSchema = diff --git a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/AttesterSlashing.java b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/AttesterSlashing.java index 6ce8c3f3287..77e11250a18 100644 --- a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/AttesterSlashing.java +++ b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/AttesterSlashing.java @@ -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), @@ -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); } diff --git a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/IndexedAttestation.java b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/IndexedAttestation.java index 084c9fd4eec..0adcad6b9c5 100644 --- a/data/serializer/src/main/java/tech/pegasys/teku/api/schema/IndexedAttestation.java +++ b/data/serializer/src/main/java/tech/pegasys/teku/api/schema/IndexedAttestation.java @@ -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), @@ -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); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltairImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltairImpl.java index b3ac966058f..2823300e8f9 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltairImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/altair/BeaconBlockBodySchemaAltairImpl.java @@ -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; @@ -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< @@ -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), @@ -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, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/bellatrix/BeaconBlockBodySchemaBellatrixImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/bellatrix/BeaconBlockBodySchemaBellatrixImpl.java index 176bb09c500..a93f08ce1ac 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/bellatrix/BeaconBlockBodySchemaBellatrixImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/bellatrix/BeaconBlockBodySchemaBellatrixImpl.java @@ -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< @@ -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( @@ -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, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/bellatrix/BlindedBeaconBlockBodySchemaBellatrixImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/bellatrix/BlindedBeaconBlockBodySchemaBellatrixImpl.java index 55da354e6e2..7d0d0aac6e9 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/bellatrix/BlindedBeaconBlockBodySchemaBellatrixImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/bellatrix/BlindedBeaconBlockBodySchemaBellatrixImpl.java @@ -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; @@ -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< @@ -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, @@ -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, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/capella/BeaconBlockBodySchemaCapellaImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/capella/BeaconBlockBodySchemaCapellaImpl.java index 0221fb8e64e..987701b19bc 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/capella/BeaconBlockBodySchemaCapellaImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/capella/BeaconBlockBodySchemaCapellaImpl.java @@ -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< @@ -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), @@ -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, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/capella/BlindedBeaconBlockBodySchemaCapellaImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/capella/BlindedBeaconBlockBodySchemaCapellaImpl.java index 93528343630..7db7b2e100a 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/capella/BlindedBeaconBlockBodySchemaCapellaImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/capella/BlindedBeaconBlockBodySchemaCapellaImpl.java @@ -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< @@ -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), @@ -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, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodySchemaDenebImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodySchemaDenebImpl.java index 4a022890bff..37aa90365a6 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodySchemaDenebImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BeaconBlockBodySchemaDenebImpl.java @@ -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< @@ -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), @@ -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, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BlindedBeaconBlockBodySchemaDenebImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BlindedBeaconBlockBodySchemaDenebImpl.java index 2537eae37c7..15bf7d4f678 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BlindedBeaconBlockBodySchemaDenebImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/deneb/BlindedBeaconBlockBodySchemaDenebImpl.java @@ -41,11 +41,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 BlindedBeaconBlockBodySchemaDenebImpl extends ContainerSchema12< @@ -99,7 +99,8 @@ public static BlindedBeaconBlockBodySchemaDenebImpl create( final SignedBlsToExecutionChangeSchema signedBlsToExecutionChangeSchema, final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema, final long maxValidatorsPerAttestation, - final String containerName) { + final String containerName, + final SchemaRegistry schemaRegistry) { return new BlindedBeaconBlockBodySchemaDenebImpl( containerName, namedSchema(BlockBodyFields.RANDAO_REVEAL, SszSignatureSchema.INSTANCE), @@ -112,10 +113,7 @@ public static BlindedBeaconBlockBodySchemaDenebImpl 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, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/electra/BeaconBlockBodySchemaElectraImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/electra/BeaconBlockBodySchemaElectraImpl.java index e769e2a1884..0aa36cbfc73 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/electra/BeaconBlockBodySchemaElectraImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/electra/BeaconBlockBodySchemaElectraImpl.java @@ -38,7 +38,6 @@ import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsSchema; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; import tech.pegasys.teku.spec.datastructures.operations.Deposit; import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; @@ -48,6 +47,8 @@ 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 BeaconBlockBodySchemaElectraImpl extends ContainerSchema13< @@ -101,12 +102,12 @@ protected BeaconBlockBodySchemaElectraImpl( public static BeaconBlockBodySchemaElectraImpl create( final SpecConfigElectra specConfig, - final AttesterSlashingSchema attesterSlashingSchema, final SignedBlsToExecutionChangeSchema blsToExecutionChangeSchema, final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema, final ExecutionRequestsSchema executionRequestsSchema, final long maxValidatorsPerAttestation, - final String containerName) { + final String containerName, + final SchemaRegistry schemaRegistry) { return new BeaconBlockBodySchemaElectraImpl( containerName, namedSchema(BlockBodyFields.RANDAO_REVEAL, SszSignatureSchema.INSTANCE), @@ -119,7 +120,7 @@ public static BeaconBlockBodySchemaElectraImpl create( namedSchema( BlockBodyFields.ATTESTER_SLASHINGS, SszListSchema.create( - attesterSlashingSchema.castTypeToAttesterSlashingSchema(), + schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA), specConfig.getMaxAttesterSlashingsElectra())), namedSchema( BlockBodyFields.ATTESTATIONS, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/electra/BlindedBeaconBlockBodySchemaElectraImpl.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/electra/BlindedBeaconBlockBodySchemaElectraImpl.java index a213df0b520..76c96f447cc 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/electra/BlindedBeaconBlockBodySchemaElectraImpl.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/electra/BlindedBeaconBlockBodySchemaElectraImpl.java @@ -37,7 +37,6 @@ import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsSchema; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; import tech.pegasys.teku.spec.datastructures.operations.Deposit; import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing; import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange; @@ -47,6 +46,8 @@ 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 BlindedBeaconBlockBodySchemaElectraImpl extends ContainerSchema13< @@ -100,12 +101,12 @@ private BlindedBeaconBlockBodySchemaElectraImpl( public static BlindedBeaconBlockBodySchemaElectraImpl create( final SpecConfigElectra specConfig, - final AttesterSlashingSchema attesterSlashingSchema, final SignedBlsToExecutionChangeSchema signedBlsToExecutionChangeSchema, final BlobKzgCommitmentsSchema blobKzgCommitmentsSchema, final ExecutionRequestsSchema executionRequestsSchema, final long maxValidatorsPerAttestation, - final String containerName) { + final String containerName, + final SchemaRegistry schemaRegistry) { return new BlindedBeaconBlockBodySchemaElectraImpl( containerName, namedSchema(BlockBodyFields.RANDAO_REVEAL, SszSignatureSchema.INSTANCE), @@ -118,7 +119,7 @@ public static BlindedBeaconBlockBodySchemaElectraImpl create( namedSchema( BlockBodyFields.ATTESTER_SLASHINGS, SszListSchema.create( - attesterSlashingSchema.castTypeToAttesterSlashingSchema(), + schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA), specConfig.getMaxAttesterSlashingsElectra())), namedSchema( BlockBodyFields.ATTESTATIONS, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0.java index b65493d80c1..3f9fa086eb6 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0.java @@ -30,13 +30,14 @@ import tech.pegasys.teku.spec.datastructures.blocks.blockbody.common.BlockBodyFields; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; import tech.pegasys.teku.spec.datastructures.operations.Deposit; 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.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 BeaconBlockBodySchemaPhase0 extends ContainerSchema8< @@ -75,9 +76,9 @@ private BeaconBlockBodySchemaPhase0( public static BeaconBlockBodySchemaPhase0 create( final SpecConfig specConfig, - final AttesterSlashingSchema attesterSlashingSchema, final long maxValidatorsPerAttestation, - final String containerName) { + final String containerName, + final SchemaRegistry schemaRegistry) { return new BeaconBlockBodySchemaPhase0( containerName, namedSchema(BlockBodyFields.RANDAO_REVEAL, SszSignatureSchema.INSTANCE), @@ -90,7 +91,7 @@ public static BeaconBlockBodySchemaPhase0 create( namedSchema( BlockBodyFields.ATTESTER_SLASHINGS, SszListSchema.create( - attesterSlashingSchema.castTypeToAttesterSlashingSchema(), + schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA), specConfig.getMaxAttesterSlashings())), namedSchema( BlockBodyFields.ATTESTATIONS, diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashing.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashing.java index 34cde303840..7d8467a8e55 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashing.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashing.java @@ -14,16 +14,41 @@ package tech.pegasys.teku.spec.datastructures.operations; import java.util.Set; -import tech.pegasys.teku.infrastructure.ssz.SszContainer; +import tech.pegasys.teku.infrastructure.ssz.containers.Container2; +import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; import tech.pegasys.teku.infrastructure.unsigned.UInt64; -public interface AttesterSlashing extends SszContainer { +public class AttesterSlashing + extends Container2 { + private final IntersectingIndicesCalculator intersectingIndicesCalculator; + + AttesterSlashing(final AttesterSlashingSchema type, final TreeNode backingNode) { + super(type, backingNode); + this.intersectingIndicesCalculator = new IntersectingIndicesCalculator(this); + } + + AttesterSlashing( + final AttesterSlashingSchema schema, + final IndexedAttestation attestation1, + final IndexedAttestation attestation2) { + super(schema, attestation1, attestation2); + this.intersectingIndicesCalculator = new IntersectingIndicesCalculator(this); + } + @Override - AttesterSlashingSchema getSchema(); + public AttesterSlashingSchema getSchema() { + return (AttesterSlashingSchema) super.getSchema(); + } - Set getIntersectingValidatorIndices(); + public Set getIntersectingValidatorIndices() { + return intersectingIndicesCalculator.getIntersectingValidatorIndices(); + } - IndexedAttestation getAttestation1(); + public IndexedAttestation getAttestation1() { + return getField0(); + } - IndexedAttestation getAttestation2(); + public IndexedAttestation getAttestation2() { + return getField1(); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashingSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashingSchema.java index b75ffc5194f..28f0ad29536 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashingSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashingSchema.java @@ -13,15 +13,29 @@ package tech.pegasys.teku.spec.datastructures.operations; -import tech.pegasys.teku.infrastructure.ssz.schema.SszContainerSchema; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.INDEXED_ATTESTATION_SCHEMA; -public interface AttesterSlashingSchema extends SszContainerSchema { +import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2; +import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; +import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry; - @SuppressWarnings("unchecked") - default AttesterSlashingSchema castTypeToAttesterSlashingSchema() { - return (AttesterSlashingSchema) this; +public class AttesterSlashingSchema + extends ContainerSchema2 { + + public AttesterSlashingSchema(final String containerName, final SchemaRegistry schemaRegistry) { + super( + containerName, + namedSchema("attestation_1", schemaRegistry.get(INDEXED_ATTESTATION_SCHEMA)), + namedSchema("attestation_2", schemaRegistry.get(INDEXED_ATTESTATION_SCHEMA))); + } + + @Override + public AttesterSlashing createFromBackingNode(final TreeNode node) { + return new AttesterSlashing(this, node); } - AttesterSlashing create( - final IndexedAttestation attestation1, final IndexedAttestation attestation2); + public AttesterSlashing create( + final IndexedAttestation attestation1, final IndexedAttestation attestation2) { + return new AttesterSlashing(this, attestation1, attestation2); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/IndexedAttestation.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/IndexedAttestation.java index ca512cc3faa..09b54890150 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/IndexedAttestation.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/IndexedAttestation.java @@ -14,17 +14,40 @@ package tech.pegasys.teku.spec.datastructures.operations; import tech.pegasys.teku.bls.BLSSignature; -import tech.pegasys.teku.infrastructure.ssz.SszContainer; import tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List; +import tech.pegasys.teku.infrastructure.ssz.containers.Container3; +import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; +import tech.pegasys.teku.spec.datastructures.type.SszSignature; -public interface IndexedAttestation extends SszContainer { +public class IndexedAttestation + extends Container3 { + + IndexedAttestation(final IndexedAttestationSchema type, final TreeNode backingNode) { + super(type, backingNode); + } + + IndexedAttestation( + final IndexedAttestationSchema schema, + final SszUInt64List attestingIndices, + final AttestationData data, + final BLSSignature signature) { + super(schema, attestingIndices, data, new SszSignature(signature)); + } @Override - IndexedAttestationSchema getSchema(); + public IndexedAttestationSchema getSchema() { + return (IndexedAttestationSchema) super.getSchema(); + } - SszUInt64List getAttestingIndices(); + public SszUInt64List getAttestingIndices() { + return getField0(); + } - AttestationData getData(); + public AttestationData getData() { + return getField1(); + } - BLSSignature getSignature(); + public BLSSignature getSignature() { + return getField2().getSignature(); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/IndexedAttestationSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/IndexedAttestationSchema.java index 2efb82ebaf0..47f8baf0866 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/IndexedAttestationSchema.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/IndexedAttestationSchema.java @@ -15,19 +15,38 @@ import tech.pegasys.teku.bls.BLSSignature; import tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List; -import tech.pegasys.teku.infrastructure.ssz.schema.SszContainerSchema; +import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3; import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszUInt64ListSchema; +import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; +import tech.pegasys.teku.spec.datastructures.type.SszSignature; +import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema; -public interface IndexedAttestationSchema - extends SszContainerSchema { +public class IndexedAttestationSchema + extends ContainerSchema3 { - @SuppressWarnings("unchecked") - default IndexedAttestationSchema castTypeToIndexedAttestationSchema() { - return (IndexedAttestationSchema) this; + public IndexedAttestationSchema( + final String containerName, final long maxValidatorsPerIndexedAttestation) { + super( + containerName, + namedSchema( + "attesting_indices", SszUInt64ListSchema.create(maxValidatorsPerIndexedAttestation)), + namedSchema("data", AttestationData.SSZ_SCHEMA), + namedSchema("signature", SszSignatureSchema.INSTANCE)); } - SszUInt64ListSchema getAttestingIndicesSchema(); + public SszUInt64ListSchema getAttestingIndicesSchema() { + return (SszUInt64ListSchema) super.getFieldSchema0(); + } + + @Override + public IndexedAttestation createFromBackingNode(final TreeNode node) { + return new IndexedAttestation(this, node); + } - IndexedAttestation create( - SszUInt64List attestingIndices, AttestationData data, BLSSignature signature); + public IndexedAttestation create( + final SszUInt64List attestingIndices, + final AttestationData data, + final BLSSignature signature) { + return new IndexedAttestation(this, attestingIndices, data, signature); + } } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttesterSlashingElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttesterSlashingElectra.java deleted file mode 100644 index f2239f54f78..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttesterSlashingElectra.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.spec.datastructures.operations.versions.electra; - -import java.util.Set; -import tech.pegasys.teku.infrastructure.ssz.containers.Container2; -import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; -import tech.pegasys.teku.infrastructure.unsigned.UInt64; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; -import tech.pegasys.teku.spec.datastructures.operations.IntersectingIndicesCalculator; - -public class AttesterSlashingElectra - extends Container2 - implements AttesterSlashing { - private final IntersectingIndicesCalculator intersectingIndicesCalculator; - - AttesterSlashingElectra(final AttesterSlashingElectraSchema type, final TreeNode backingNode) { - super(type, backingNode); - this.intersectingIndicesCalculator = new IntersectingIndicesCalculator(this); - } - - AttesterSlashingElectra( - final AttesterSlashingElectraSchema schema, - final IndexedAttestation attestation1, - final IndexedAttestation attestation2) { - super(schema, attestation1, attestation2); - this.intersectingIndicesCalculator = new IntersectingIndicesCalculator(this); - } - - @Override - public AttesterSlashingElectraSchema getSchema() { - return (AttesterSlashingElectraSchema) super.getSchema(); - } - - @Override - public Set getIntersectingValidatorIndices() { - return intersectingIndicesCalculator.getIntersectingValidatorIndices(); - } - - @Override - public IndexedAttestation getAttestation1() { - return getField0(); - } - - @Override - public IndexedAttestation getAttestation2() { - return getField1(); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttesterSlashingElectraSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttesterSlashingElectraSchema.java deleted file mode 100644 index 38ccc60a349..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttesterSlashingElectraSchema.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.spec.datastructures.operations.versions.electra; - -import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2; -import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; - -public class AttesterSlashingElectraSchema - extends ContainerSchema2 - implements AttesterSlashingSchema { - public AttesterSlashingElectraSchema( - final IndexedAttestationSchema indexedAttestationSchema) { - super( - "AttesterSlashingElectra", - namedSchema("attestation_1", indexedAttestationSchema), - namedSchema("attestation_2", indexedAttestationSchema)); - } - - @Override - public AttesterSlashingElectra createFromBackingNode(final TreeNode node) { - return new AttesterSlashingElectra(this, node); - } - - @Override - public AttesterSlashing create( - final IndexedAttestation attestation1, final IndexedAttestation attestation2) { - return new AttesterSlashingElectra(this, attestation1, attestation2); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/IndexedAttestationElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/IndexedAttestationElectra.java deleted file mode 100644 index 77800c71ae5..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/IndexedAttestationElectra.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.spec.datastructures.operations.versions.electra; - -import tech.pegasys.teku.bls.BLSSignature; -import tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List; -import tech.pegasys.teku.infrastructure.ssz.containers.Container3; -import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; -import tech.pegasys.teku.spec.datastructures.operations.AttestationData; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; -import tech.pegasys.teku.spec.datastructures.type.SszSignature; - -public class IndexedAttestationElectra - extends Container3 - implements IndexedAttestation { - - IndexedAttestationElectra( - final IndexedAttestationElectraSchema type, final TreeNode backingNode) { - super(type, backingNode); - } - - IndexedAttestationElectra( - final IndexedAttestationElectraSchema schema, - final SszUInt64List attestingIndices, - final AttestationData data, - final BLSSignature signature) { - super(schema, attestingIndices, data, new SszSignature(signature)); - } - - @Override - public IndexedAttestationElectraSchema getSchema() { - return (IndexedAttestationElectraSchema) super.getSchema(); - } - - @Override - public SszUInt64List getAttestingIndices() { - return getField0(); - } - - @Override - public AttestationData getData() { - return getField1(); - } - - @Override - public BLSSignature getSignature() { - return getField2().getSignature(); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/IndexedAttestationElectraSchema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/IndexedAttestationElectraSchema.java deleted file mode 100644 index aaeb9fd039b..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/electra/IndexedAttestationElectraSchema.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.spec.datastructures.operations.versions.electra; - -import tech.pegasys.teku.bls.BLSSignature; -import tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List; -import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3; -import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszUInt64ListSchema; -import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; -import tech.pegasys.teku.spec.datastructures.operations.AttestationData; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; -import tech.pegasys.teku.spec.datastructures.type.SszSignature; -import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema; - -public class IndexedAttestationElectraSchema - extends ContainerSchema3< - IndexedAttestationElectra, SszUInt64List, AttestationData, SszSignature> - implements IndexedAttestationSchema { - - public IndexedAttestationElectraSchema(final long maxValidatorsPerIndexedAttestation) { - super( - "IndexedAttestationElectra", - namedSchema( - "attesting_indices", SszUInt64ListSchema.create(maxValidatorsPerIndexedAttestation)), - namedSchema("data", AttestationData.SSZ_SCHEMA), - namedSchema("signature", SszSignatureSchema.INSTANCE)); - } - - @Override - public SszUInt64ListSchema getAttestingIndicesSchema() { - return (SszUInt64ListSchema) super.getFieldSchema0(); - } - - @Override - public IndexedAttestationElectra createFromBackingNode(final TreeNode node) { - return new IndexedAttestationElectra(this, node); - } - - @Override - public IndexedAttestation create( - final SszUInt64List attestingIndices, - final AttestationData data, - final BLSSignature signature) { - return new IndexedAttestationElectra(this, attestingIndices, data, signature); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttesterSlashingPhase0.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttesterSlashingPhase0.java deleted file mode 100644 index 79d617c51c8..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttesterSlashingPhase0.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.spec.datastructures.operations.versions.phase0; - -import java.util.Set; -import tech.pegasys.teku.infrastructure.ssz.containers.Container2; -import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; -import tech.pegasys.teku.infrastructure.unsigned.UInt64; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; -import tech.pegasys.teku.spec.datastructures.operations.IntersectingIndicesCalculator; - -public class AttesterSlashingPhase0 - extends Container2 - implements AttesterSlashing { - private final IntersectingIndicesCalculator intersectingIndicesCalculator; - - AttesterSlashingPhase0(final AttesterSlashingPhase0Schema type, final TreeNode backingNode) { - super(type, backingNode); - this.intersectingIndicesCalculator = new IntersectingIndicesCalculator(this); - } - - AttesterSlashingPhase0( - final AttesterSlashingPhase0Schema schema, - final IndexedAttestation attestation1, - final IndexedAttestation attestation2) { - super(schema, attestation1, attestation2); - this.intersectingIndicesCalculator = new IntersectingIndicesCalculator(this); - } - - @Override - public AttesterSlashingPhase0Schema getSchema() { - return (AttesterSlashingPhase0Schema) super.getSchema(); - } - - @Override - public Set getIntersectingValidatorIndices() { - return intersectingIndicesCalculator.getIntersectingValidatorIndices(); - } - - @Override - public IndexedAttestation getAttestation1() { - return getField0(); - } - - @Override - public IndexedAttestation getAttestation2() { - return getField1(); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttesterSlashingPhase0Schema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttesterSlashingPhase0Schema.java deleted file mode 100644 index fce3ef2108a..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/AttesterSlashingPhase0Schema.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.spec.datastructures.operations.versions.phase0; - -import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema2; -import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; - -public class AttesterSlashingPhase0Schema - extends ContainerSchema2 - implements AttesterSlashingSchema { - public AttesterSlashingPhase0Schema( - final IndexedAttestationSchema indexedAttestationSchema) { - super( - "AttesterSlashingPhase0", - namedSchema("attestation_1", indexedAttestationSchema), - namedSchema("attestation_2", indexedAttestationSchema)); - } - - @Override - public AttesterSlashingPhase0 createFromBackingNode(final TreeNode node) { - return new AttesterSlashingPhase0(this, node); - } - - @Override - public AttesterSlashing create( - final IndexedAttestation attestation1, final IndexedAttestation attestation2) { - return new AttesterSlashingPhase0(this, attestation1, attestation2); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/IndexedAttestationPhase0.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/IndexedAttestationPhase0.java deleted file mode 100644 index 023876d2d02..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/IndexedAttestationPhase0.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.spec.datastructures.operations.versions.phase0; - -import tech.pegasys.teku.bls.BLSSignature; -import tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List; -import tech.pegasys.teku.infrastructure.ssz.containers.Container3; -import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; -import tech.pegasys.teku.spec.datastructures.operations.AttestationData; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; -import tech.pegasys.teku.spec.datastructures.type.SszSignature; - -public class IndexedAttestationPhase0 - extends Container3 - implements IndexedAttestation { - - IndexedAttestationPhase0(final IndexedAttestationPhase0Schema type, final TreeNode backingNode) { - super(type, backingNode); - } - - IndexedAttestationPhase0( - final IndexedAttestationPhase0Schema schema, - final SszUInt64List attestingIndices, - final AttestationData data, - final BLSSignature signature) { - super(schema, attestingIndices, data, new SszSignature(signature)); - } - - @Override - public IndexedAttestationPhase0Schema getSchema() { - return (IndexedAttestationPhase0Schema) super.getSchema(); - } - - @Override - public SszUInt64List getAttestingIndices() { - return getField0(); - } - - @Override - public AttestationData getData() { - return getField1(); - } - - @Override - public BLSSignature getSignature() { - return getField2().getSignature(); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/IndexedAttestationPhase0Schema.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/IndexedAttestationPhase0Schema.java deleted file mode 100644 index 2b07b235793..00000000000 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/versions/phase0/IndexedAttestationPhase0Schema.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright Consensys Software Inc., 2024 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -package tech.pegasys.teku.spec.datastructures.operations.versions.phase0; - -import tech.pegasys.teku.bls.BLSSignature; -import tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List; -import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema3; -import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszUInt64ListSchema; -import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; -import tech.pegasys.teku.spec.datastructures.operations.AttestationData; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; -import tech.pegasys.teku.spec.datastructures.type.SszSignature; -import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema; - -public class IndexedAttestationPhase0Schema - extends ContainerSchema3 - implements IndexedAttestationSchema { - - public IndexedAttestationPhase0Schema(final long maxValidatorsPerIndexedAttestation) { - super( - "IndexedAttestationPhase0", - namedSchema( - "attesting_indices", SszUInt64ListSchema.create(maxValidatorsPerIndexedAttestation)), - namedSchema("data", AttestationData.SSZ_SCHEMA), - namedSchema("signature", SszSignatureSchema.INSTANCE)); - } - - @Override - public SszUInt64ListSchema getAttestingIndicesSchema() { - return (SszUInt64ListSchema) super.getFieldSchema0(); - } - - @Override - public IndexedAttestationPhase0 createFromBackingNode(final TreeNode node) { - return new IndexedAttestationPhase0(this, node); - } - - @Override - public IndexedAttestation create( - final SszUInt64List attestingIndices, - final AttestationData data, - final BLSSignature signature) { - return new IndexedAttestationPhase0(this, attestingIndices, data, signature); - } -} diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/util/AttestationUtil.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/util/AttestationUtil.java index 36230c1b63d..5da5b45f023 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/util/AttestationUtil.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/util/AttestationUtil.java @@ -100,7 +100,7 @@ public IndexedAttestation getIndexedAttestation( final BeaconState state, final Attestation attestation) { final List attestingIndices = getAttestingIndices(state, attestation); - final IndexedAttestationSchema indexedAttestationSchema = + final IndexedAttestationSchema indexedAttestationSchema = schemaDefinitions.getIndexedAttestationSchema(); return indexedAttestationSchema.create( diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitions.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitions.java index 75ad884784d..58509463de8 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitions.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitions.java @@ -33,9 +33,7 @@ import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema; import tech.pegasys.teku.spec.datastructures.state.HistoricalBatch.HistoricalBatchSchema; @@ -80,9 +78,9 @@ public interface SchemaDefinitions { AttestationSchema getAttestationSchema(); - IndexedAttestationSchema getIndexedAttestationSchema(); + IndexedAttestationSchema getIndexedAttestationSchema(); - AttesterSlashingSchema getAttesterSlashingSchema(); + AttesterSlashingSchema getAttesterSlashingSchema(); BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema getBeaconBlocksByRootRequestMessageSchema(); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java index 99f977c999f..8e932b11a93 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsAltair.java @@ -35,9 +35,7 @@ import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema; import tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProofSchema; @@ -46,17 +44,16 @@ import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContributionSchema; import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessageSchema; 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.state.beaconstate.BeaconStateSchema; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateAltair; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateSchemaAltair; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.MutableBeaconStateAltair; import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry; +import tech.pegasys.teku.spec.schemas.registry.SchemaTypes; public class SchemaDefinitionsAltair extends AbstractSchemaDefinitions { - private final IndexedAttestationSchema indexedAttestationSchema; - private final AttesterSlashingSchema attesterSlashingSchema; + private final IndexedAttestationSchema indexedAttestationSchema; + private final AttesterSlashingSchema attesterSlashingSchema; private final AttestationSchema attestationSchema; private final SignedAggregateAndProofSchema signedAggregateAndProofSchema; private final AggregateAndProofSchema aggregateAndProofSchema; @@ -76,12 +73,8 @@ public class SchemaDefinitionsAltair extends AbstractSchemaDefinitions { public SchemaDefinitionsAltair(final SchemaRegistry schemaRegistry) { super(schemaRegistry); final SpecConfigAltair specConfig = SpecConfigAltair.required(schemaRegistry.getSpecConfig()); - this.indexedAttestationSchema = - new IndexedAttestationPhase0Schema(getMaxValidatorPerAttestation(specConfig)) - .castTypeToIndexedAttestationSchema(); - this.attesterSlashingSchema = - new AttesterSlashingPhase0Schema(indexedAttestationSchema) - .castTypeToAttesterSlashingSchema(); + this.indexedAttestationSchema = schemaRegistry.get(SchemaTypes.INDEXED_ATTESTATION_SCHEMA); + this.attesterSlashingSchema = schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA); this.attestationSchema = new AttestationPhase0Schema(getMaxValidatorPerAttestation(specConfig)) .castTypeToAttestationSchema(); @@ -90,7 +83,10 @@ public SchemaDefinitionsAltair(final SchemaRegistry schemaRegistry) { this.beaconStateSchema = BeaconStateSchemaAltair.create(specConfig); this.beaconBlockBodySchema = BeaconBlockBodySchemaAltairImpl.create( - specConfig, getMaxValidatorPerAttestation(specConfig), "BeaconBlockBodyAltair"); + specConfig, + getMaxValidatorPerAttestation(specConfig), + "BeaconBlockBodyAltair", + schemaRegistry); this.beaconBlockSchema = new BeaconBlockSchema(beaconBlockBodySchema, "BeaconBlockAltair"); this.signedBeaconBlockSchema = new SignedBeaconBlockSchema(beaconBlockSchema, "SignedBeaconBlockAltair"); @@ -131,12 +127,12 @@ public AttestationSchema getAttestationSchema() { } @Override - public IndexedAttestationSchema getIndexedAttestationSchema() { + public IndexedAttestationSchema getIndexedAttestationSchema() { return indexedAttestationSchema; } @Override - public AttesterSlashingSchema getAttesterSlashingSchema() { + public AttesterSlashingSchema getAttesterSlashingSchema() { return attesterSlashingSchema; } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsBellatrix.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsBellatrix.java index ce0e6b8b567..6c843e97e62 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsBellatrix.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsBellatrix.java @@ -62,12 +62,13 @@ public SchemaDefinitionsBellatrix(final SchemaRegistry schemaRegistry) { this.executionPayloadHeaderSchema = beaconStateSchema.getLastExecutionPayloadHeaderSchema(); this.beaconBlockBodySchema = BeaconBlockBodySchemaBellatrixImpl.create( - specConfig, maxValidatorsPerAttestation, "BeaconBlockBodyBellatrix"); + specConfig, maxValidatorsPerAttestation, "BeaconBlockBodyBellatrix", schemaRegistry); this.blindedBeaconBlockBodySchema = BlindedBeaconBlockBodySchemaBellatrixImpl.create( specConfig, maxValidatorsPerAttestation, "BlindedBlockBodyBellatrix", + schemaRegistry, executionPayloadHeaderSchema); this.beaconBlockSchema = new BeaconBlockSchema(beaconBlockBodySchema, "BeaconBlockBellatrix"); this.blindedBeaconBlockSchema = diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java index 61aa76e92af..94b46e09b06 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsCapella.java @@ -87,13 +87,15 @@ public SchemaDefinitionsCapella(final SchemaRegistry schemaRegistry) { specConfig, signedBlsToExecutionChangeSchema, getMaxValidatorPerAttestation(specConfig), - "BeaconBlockBodyCapella"); + "BeaconBlockBodyCapella", + schemaRegistry); this.blindedBeaconBlockBodySchema = BlindedBeaconBlockBodySchemaCapellaImpl.create( specConfig, signedBlsToExecutionChangeSchema, getMaxValidatorPerAttestation(specConfig), - "BlindedBlockBodyCapella"); + "BlindedBlockBodyCapella", + schemaRegistry); this.beaconBlockSchema = new BeaconBlockSchema(beaconBlockBodySchema, "BeaconBlockCapella"); this.blindedBeaconBlockSchema = new BeaconBlockSchema(blindedBeaconBlockBodySchema, "BlindedBlockCapella"); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java index af9dbb4e5b2..c13f6c3a310 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsDeneb.java @@ -98,14 +98,16 @@ public SchemaDefinitionsDeneb(final SchemaRegistry schemaRegistry) { getSignedBlsToExecutionChangeSchema(), blobKzgCommitmentsSchema, getMaxValidatorPerAttestation(specConfig), - "BeaconBlockBodyDeneb"); + "BeaconBlockBodyDeneb", + schemaRegistry); this.blindedBeaconBlockBodySchema = BlindedBeaconBlockBodySchemaDenebImpl.create( specConfig, getSignedBlsToExecutionChangeSchema(), blobKzgCommitmentsSchema, getMaxValidatorPerAttestation(specConfig), - "BlindedBlockBodyDeneb"); + "BlindedBlockBodyDeneb", + schemaRegistry); this.beaconBlockSchema = new BeaconBlockSchema(beaconBlockBodySchema, "BeaconBlockDeneb"); this.blindedBeaconBlockSchema = new BeaconBlockSchema(blindedBeaconBlockBodySchema, "BlindedBlockDeneb"); diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java index 036dcb26cb0..bcd78684b51 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsElectra.java @@ -48,13 +48,7 @@ import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema; -import tech.pegasys.teku.spec.datastructures.operations.versions.electra.AttesterSlashingElectraSchema; -import tech.pegasys.teku.spec.datastructures.operations.versions.electra.IndexedAttestationElectraSchema; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.electra.BeaconStateElectra; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.electra.BeaconStateSchemaElectra; @@ -66,9 +60,6 @@ import tech.pegasys.teku.spec.schemas.registry.SchemaTypes; public class SchemaDefinitionsElectra extends SchemaDefinitionsDeneb { - - private final IndexedAttestationSchema indexedAttestationSchema; - private final AttesterSlashingSchema attesterSlashingSchema; private final AttestationSchema attestationSchema; private final SignedAggregateAndProofSchema signedAggregateAndProofSchema; private final AggregateAndProofSchema aggregateAndProofSchema; @@ -107,12 +98,6 @@ public SchemaDefinitionsElectra(final SchemaRegistry schemaRegistry) { final SpecConfigElectra specConfig = SpecConfigElectra.required(schemaRegistry.getSpecConfig()); final long maxValidatorsPerAttestation = getMaxValidatorPerAttestation(specConfig); - this.indexedAttestationSchema = - new IndexedAttestationElectraSchema(maxValidatorsPerAttestation) - .castTypeToIndexedAttestationSchema(); - this.attesterSlashingSchema = - new AttesterSlashingElectraSchema(indexedAttestationSchema) - .castTypeToAttesterSlashingSchema(); this.attestationSchema = schemaRegistry.get(SchemaTypes.ATTESTATION_SCHEMA); this.aggregateAndProofSchema = new AggregateAndProofSchema(attestationSchema); @@ -123,21 +108,21 @@ public SchemaDefinitionsElectra(final SchemaRegistry schemaRegistry) { this.beaconBlockBodySchema = BeaconBlockBodySchemaElectraImpl.create( specConfig, - getAttesterSlashingSchema(), getSignedBlsToExecutionChangeSchema(), getBlobKzgCommitmentsSchema(), getExecutionRequestsSchema(), maxValidatorsPerAttestation, - "BeaconBlockBodyElectra"); + "BeaconBlockBodyElectra", + schemaRegistry); this.blindedBeaconBlockBodySchema = BlindedBeaconBlockBodySchemaElectraImpl.create( specConfig, - getAttesterSlashingSchema(), getSignedBlsToExecutionChangeSchema(), getBlobKzgCommitmentsSchema(), getExecutionRequestsSchema(), maxValidatorsPerAttestation, - "BlindedBlockBodyElectra"); + "BlindedBlockBodyElectra", + schemaRegistry); this.beaconBlockSchema = new BeaconBlockSchema(beaconBlockBodySchema, "BeaconBlockElectra"); this.blindedBeaconBlockSchema = new BeaconBlockSchema(blindedBeaconBlockBodySchema, "BlindedBlockElectra"); @@ -199,16 +184,6 @@ public AttestationSchema getAttestationSchema() { return attestationSchema; } - @Override - public IndexedAttestationSchema getIndexedAttestationSchema() { - return indexedAttestationSchema; - } - - @Override - public AttesterSlashingSchema getAttesterSlashingSchema() { - return attesterSlashingSchema; - } - @Override public BeaconStateSchema getBeaconStateSchema() { diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsPhase0.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsPhase0.java index 6176c070e32..3352cef3609 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsPhase0.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/SchemaDefinitionsPhase0.java @@ -29,21 +29,17 @@ import tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof.AggregateAndProofSchema; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema; -import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof.SignedAggregateAndProofSchema; -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.state.beaconstate.BeaconStateSchema; import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStateSchemaPhase0; import tech.pegasys.teku.spec.schemas.registry.SchemaRegistry; import tech.pegasys.teku.spec.schemas.registry.SchemaTypes; public class SchemaDefinitionsPhase0 extends AbstractSchemaDefinitions { - private final IndexedAttestationSchema indexedAttestationSchema; - private final AttesterSlashingSchema attesterSlashingSchema; + private final IndexedAttestationSchema indexedAttestationSchema; + private final AttesterSlashingSchema attesterSlashingSchema; private final AttestationSchema attestationSchema; private final SignedAggregateAndProofSchema signedAggregateAndProofSchema; private final AggregateAndProofSchema aggregateAndProofSchema; @@ -56,12 +52,8 @@ public class SchemaDefinitionsPhase0 extends AbstractSchemaDefinitions { public SchemaDefinitionsPhase0(final SchemaRegistry schemaRegistry) { super(schemaRegistry); final SpecConfig specConfig = schemaRegistry.getSpecConfig(); - this.indexedAttestationSchema = - new IndexedAttestationPhase0Schema(getMaxValidatorPerAttestation(specConfig)) - .castTypeToIndexedAttestationSchema(); - this.attesterSlashingSchema = - new AttesterSlashingPhase0Schema(indexedAttestationSchema) - .castTypeToAttesterSlashingSchema(); + this.indexedAttestationSchema = schemaRegistry.get(SchemaTypes.INDEXED_ATTESTATION_SCHEMA); + this.attesterSlashingSchema = schemaRegistry.get(SchemaTypes.ATTESTER_SLASHING_SCHEMA); this.attestationSchema = schemaRegistry.get(SchemaTypes.ATTESTATION_SCHEMA); this.aggregateAndProofSchema = new AggregateAndProofSchema(attestationSchema); @@ -70,9 +62,9 @@ public SchemaDefinitionsPhase0(final SchemaRegistry schemaRegistry) { this.beaconBlockBodySchema = BeaconBlockBodySchemaPhase0.create( specConfig, - getAttesterSlashingSchema(), getMaxValidatorPerAttestation(specConfig), - "BeaconBlockBodyPhase0"); + "BeaconBlockBodyPhase0", + schemaRegistry); this.metadataMessageSchema = new MetadataMessageSchemaPhase0(specConfig.getNetworkingConfig()); beaconBlockSchema = new BeaconBlockSchema(beaconBlockBodySchema, "BeaconBlockPhase0"); signedBeaconBlockSchema = @@ -100,12 +92,12 @@ public AttestationSchema getAttestationSchema() { } @Override - public IndexedAttestationSchema getIndexedAttestationSchema() { + public IndexedAttestationSchema getIndexedAttestationSchema() { return indexedAttestationSchema; } @Override - public AttesterSlashingSchema getAttesterSlashingSchema() { + public AttesterSlashingSchema getAttesterSlashingSchema() { return attesterSlashingSchema; } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaRegistryBuilder.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaRegistryBuilder.java index 833990c1339..6d17881ffe7 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaRegistryBuilder.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaRegistryBuilder.java @@ -13,11 +13,15 @@ package tech.pegasys.teku.spec.schemas.registry; +import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA; +import static tech.pegasys.teku.spec.SpecMilestone.PHASE0; import static tech.pegasys.teku.spec.schemas.registry.BaseSchemaProvider.constantProviderBuilder; import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTESTATION_SCHEMA; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTESTER_SLASHING_SCHEMA; import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.ATTNETS_ENR_FIELD_SCHEMA; import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.BEACON_BLOCKS_BY_ROOT_REQUEST_MESSAGE_SCHEMA; import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.HISTORICAL_BATCH_SCHEMA; +import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.INDEXED_ATTESTATION_SCHEMA; import static tech.pegasys.teku.spec.schemas.registry.SchemaTypes.SYNCNETS_ENR_FIELD_SCHEMA; import com.google.common.annotations.VisibleForTesting; @@ -30,6 +34,8 @@ import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; +import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; import tech.pegasys.teku.spec.datastructures.operations.versions.electra.AttestationElectraSchema; import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttestationPhase0Schema; import tech.pegasys.teku.spec.datastructures.state.HistoricalBatch.HistoricalBatchSchema; @@ -47,13 +53,15 @@ public static SchemaRegistryBuilder create() { .addProvider(createSyncnetsENRFieldSchemaProvider()) .addProvider(createBeaconBlocksByRootRequestMessageSchemaProvider()) .addProvider(createHistoricalBatchSchemaProvider()) + .addProvider(createIndexedAttestationSchemaProvider()) + .addProvider(createAttesterSlashingSchemaProvider()) .addProvider(createAttestationSchemaProvider()); } private static SchemaProvider createAttnetsENRFieldSchemaProvider() { return constantProviderBuilder(ATTNETS_ENR_FIELD_SCHEMA) .withCreator( - SpecMilestone.PHASE0, + PHASE0, (registry, specConfig) -> SszBitvectorSchema.create(specConfig.getAttestationSubnetCount())) .build(); @@ -62,7 +70,7 @@ private static SchemaProvider createAttnetsENRFieldSchemaProvider() { private static SchemaProvider createSyncnetsENRFieldSchemaProvider() { return constantProviderBuilder(SYNCNETS_ENR_FIELD_SCHEMA) .withCreator( - SpecMilestone.PHASE0, + PHASE0, (registry, specConfig) -> SszBitvectorSchema.create(NetworkConstants.SYNC_COMMITTEE_SUBNET_COUNT)) .build(); @@ -71,7 +79,7 @@ private static SchemaProvider createSyncnetsENRFieldSchemaProvider() { private static SchemaProvider createBeaconBlocksByRootRequestMessageSchemaProvider() { return constantProviderBuilder(BEACON_BLOCKS_BY_ROOT_REQUEST_MESSAGE_SCHEMA) .withCreator( - SpecMilestone.PHASE0, + PHASE0, (registry, specConfig) -> new BeaconBlocksByRootRequestMessageSchema(specConfig)) .build(); } @@ -79,30 +87,69 @@ private static SchemaProvider createBeaconBlocksByRootRequestMessageSchemaPro private static SchemaProvider createHistoricalBatchSchemaProvider() { return constantProviderBuilder(HISTORICAL_BATCH_SCHEMA) .withCreator( - SpecMilestone.PHASE0, + PHASE0, (registry, specConfig) -> new HistoricalBatchSchema(specConfig.getSlotsPerHistoricalRoot())) .build(); } + private static SchemaProvider createAttesterSlashingSchemaProvider() { + return constantProviderBuilder(ATTESTER_SLASHING_SCHEMA) + .withCreator( + PHASE0, + (registry, specConfig) -> + new AttesterSlashingSchema( + ATTESTER_SLASHING_SCHEMA.getContainerName(registry.getMilestone()), registry)) + .withCreator( + ELECTRA, + (registry, specConfig) -> + new AttesterSlashingSchema( + ATTESTER_SLASHING_SCHEMA.getContainerName(registry.getMilestone()), registry)) + .build(); + } + + private static SchemaProvider createIndexedAttestationSchemaProvider() { + return constantProviderBuilder(INDEXED_ATTESTATION_SCHEMA) + .withCreator( + PHASE0, + (registry, specConfig) -> + new IndexedAttestationSchema( + INDEXED_ATTESTATION_SCHEMA.getContainerName(registry.getMilestone()), + getMaxValidatorPerAttestationPhase0(specConfig))) + .withCreator( + ELECTRA, + (registry, specConfig) -> + new IndexedAttestationSchema( + INDEXED_ATTESTATION_SCHEMA.getContainerName(registry.getMilestone()), + getMaxValidatorPerAttestationElectra(specConfig))) + .build(); + } + private static SchemaProvider> createAttestationSchemaProvider() { return constantProviderBuilder(ATTESTATION_SCHEMA) .withCreator( - SpecMilestone.PHASE0, + PHASE0, (registry, specConfig) -> - new AttestationPhase0Schema(specConfig.getMaxValidatorsPerCommittee()) + new AttestationPhase0Schema(getMaxValidatorPerAttestationPhase0(specConfig)) .castTypeToAttestationSchema()) .withCreator( SpecMilestone.DENEB, (registry, specConfig) -> new AttestationElectraSchema( - (long) specConfig.getMaxValidatorsPerCommittee() - * specConfig.getMaxCommitteesPerSlot(), + getMaxValidatorPerAttestationElectra(specConfig), specConfig.getMaxCommitteesPerSlot()) .castTypeToAttestationSchema()) .build(); } + private static long getMaxValidatorPerAttestationPhase0(final SpecConfig specConfig) { + return specConfig.getMaxValidatorsPerCommittee(); + } + + private static long getMaxValidatorPerAttestationElectra(final SpecConfig specConfig) { + return (long) specConfig.getMaxValidatorsPerCommittee() * specConfig.getMaxCommitteesPerSlot(); + } + public SchemaRegistryBuilder() { this.cache = SchemaCache.createDefault(); } diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaTypes.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaTypes.java index c1d830df20e..1062b0c6d63 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaTypes.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/schemas/registry/SchemaTypes.java @@ -26,6 +26,8 @@ import tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.BeaconBlocksByRootRequestMessage.BeaconBlocksByRootRequestMessageSchema; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.operations.AttestationSchema; +import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashingSchema; +import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; import tech.pegasys.teku.spec.datastructures.state.HistoricalBatch.HistoricalBatchSchema; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateSchema; @@ -42,6 +44,10 @@ public class SchemaTypes { public static final SchemaId BEACON_BLOCKS_BY_ROOT_REQUEST_MESSAGE_SCHEMA = create("BEACON_BLOCKS_BY_ROOT_REQUEST_MESSAGE_SCHEMA"); + public static final SchemaId ATTESTER_SLASHING_SCHEMA = + create("ATTESTER_SLASHING_SCHEMA"); + public static final SchemaId INDEXED_ATTESTATION_SCHEMA = + create("INDEXED_ATTESTATION_SCHEMA"); public static final SchemaId> ATTESTATION_SCHEMA = create("ATTESTATION_SCHEMA"); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0Test.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0Test.java index fa23725f3a2..c1613970362 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0Test.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/blocks/blockbody/versions/phase0/BeaconBlockBodySchemaPhase0Test.java @@ -19,8 +19,6 @@ import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.TestSpecFactory; import tech.pegasys.teku.spec.config.SpecConfig; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestationSchema; -import tech.pegasys.teku.spec.datastructures.operations.versions.phase0.AttesterSlashingPhase0Schema; public class BeaconBlockBodySchemaPhase0Test { @@ -28,24 +26,18 @@ public class BeaconBlockBodySchemaPhase0Test { public void create_minimal() { final Spec spec = TestSpecFactory.createMinimalPhase0(); final SpecConfig specConfig = spec.getGenesisSpecConfig(); - final IndexedAttestationSchema indexAttestationSchemaA = - spec.getGenesisSchemaDefinitions().getIndexedAttestationSchema(); - final IndexedAttestationSchema indexAttestationSchemaB = - spec.getGenesisSchemaDefinitions().getIndexedAttestationSchema(); final BeaconBlockBodySchemaPhase0 specA = BeaconBlockBodySchemaPhase0.create( specConfig, - new AttesterSlashingPhase0Schema( - indexAttestationSchemaA.castTypeToIndexedAttestationSchema()), specConfig.getMaxValidatorsPerCommittee(), - "BeaconBlockBodyPhase0"); + "BeaconBlockBodyPhase0", + spec.getGenesisSchemaDefinitions().getSchemaRegistry()); final BeaconBlockBodySchemaPhase0 specB = BeaconBlockBodySchemaPhase0.create( specConfig, - new AttesterSlashingPhase0Schema( - indexAttestationSchemaB.castTypeToIndexedAttestationSchema()), specConfig.getMaxValidatorsPerCommittee(), - "BeaconBlockBodyPhase0"); + "BeaconBlockBodyPhase0", + spec.getGenesisSchemaDefinitions().getSchemaRegistry()); assertThat(specA).isEqualTo(specB); } @@ -54,24 +46,18 @@ public void create_minimal() { public void create_mainnet() { final Spec spec = TestSpecFactory.createMainnetPhase0(); final SpecConfig specConfig = spec.getGenesisSpecConfig(); - final IndexedAttestationSchema indexAttestationSchemaA = - spec.getGenesisSchemaDefinitions().getIndexedAttestationSchema(); - final IndexedAttestationSchema indexAttestationSchemaB = - spec.getGenesisSchemaDefinitions().getIndexedAttestationSchema(); final BeaconBlockBodySchemaPhase0 specA = BeaconBlockBodySchemaPhase0.create( specConfig, - new AttesterSlashingPhase0Schema( - indexAttestationSchemaA.castTypeToIndexedAttestationSchema()), specConfig.getMaxValidatorsPerCommittee(), - "BeaconBlockBodyPhase0"); + "BeaconBlockBodyPhase0", + spec.getGenesisSchemaDefinitions().getSchemaRegistry()); final BeaconBlockBodySchemaPhase0 specB = BeaconBlockBodySchemaPhase0.create( specConfig, - new AttesterSlashingPhase0Schema( - indexAttestationSchemaB.castTypeToIndexedAttestationSchema()), specConfig.getMaxValidatorsPerCommittee(), - "BeaconBlockBodyPhase0"); + "BeaconBlockBodyPhase0", + spec.getGenesisSchemaDefinitions().getSchemaRegistry()); assertThat(specA).isEqualTo(specB); } diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashingTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashingTest.java index 02c2d0342e6..8326d117d3c 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashingTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/operations/AttesterSlashingTest.java @@ -26,7 +26,7 @@ class AttesterSlashingTest { private final Spec spec = TestSpecFactory.createDefault(); private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec); - private final AttesterSlashingSchema attesterSlashingSchema = + private final AttesterSlashingSchema attesterSlashingSchema = spec.getGenesisSchemaDefinitions().getAttesterSlashingSchema(); private final IndexedAttestation indexedAttestation1 = dataStructureUtil.randomIndexedAttestation(); diff --git a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java index b4aae61c5df..f864a53f41f 100644 --- a/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java +++ b/ethereum/spec/src/testFixtures/java/tech/pegasys/teku/spec/util/DataStructureUtil.java @@ -1539,7 +1539,7 @@ public IndexedAttestation randomIndexedAttestation(final UInt64... attestingIndi public IndexedAttestation randomIndexedAttestation( final AttestationData data, final UInt64... attestingIndicesInput) { - final IndexedAttestationSchema indexedAttestationSchema = + final IndexedAttestationSchema indexedAttestationSchema = spec.getGenesisSchemaDefinitions().getIndexedAttestationSchema(); final SszUInt64List attestingIndices = indexedAttestationSchema.getAttestingIndicesSchema().of(attestingIndicesInput); diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java index 6273128322b..fda3089f451 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceTest.java @@ -1339,7 +1339,7 @@ private UInt64 applyAttestationFromValidator( new Checkpoint( spec.computeEpochAtSlot(updatedAttestationSlot), targetBlock.getRoot())), dataStructureUtil.randomSignature())); - final IndexedAttestationSchema indexedAttestationSchema = + final IndexedAttestationSchema indexedAttestationSchema = spec.atSlot(updatedAttestationSlot).getSchemaDefinitions().getIndexedAttestationSchema(); updatedVote.setIndexedAttestation( indexedAttestationSchema.create( diff --git a/fuzz/src/main/java/tech/pegasys/teku/fuzz/input/AttesterSlashingFuzzInput.java b/fuzz/src/main/java/tech/pegasys/teku/fuzz/input/AttesterSlashingFuzzInput.java index e22ca87402a..88d52a86f01 100644 --- a/fuzz/src/main/java/tech/pegasys/teku/fuzz/input/AttesterSlashingFuzzInput.java +++ b/fuzz/src/main/java/tech/pegasys/teku/fuzz/input/AttesterSlashingFuzzInput.java @@ -29,7 +29,7 @@ public class AttesterSlashingFuzzInput createType(final SpecVersion spec) { return ContainerSchema2.create( SszSchema.as(BeaconState.class, spec.getSchemaDefinitions().getBeaconStateSchema()), - spec.getSchemaDefinitions().getAttesterSlashingSchema().castTypeToAttesterSlashingSchema(), + spec.getSchemaDefinitions().getAttesterSlashingSchema(), AttesterSlashingFuzzInput::new); } diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/AttesterSlashingGossipManager.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/AttesterSlashingGossipManager.java index c1b6c29b2a3..3eb4167c3b8 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/AttesterSlashingGossipManager.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/AttesterSlashingGossipManager.java @@ -45,8 +45,7 @@ public AttesterSlashingGossipManager( processor, spec.atEpoch(forkInfo.getFork().getEpoch()) .getSchemaDefinitions() - .getAttesterSlashingSchema() - .castTypeToAttesterSlashingSchema(), + .getAttesterSlashingSchema(), message -> spec.computeEpochAtSlot(message.getAttestation1().getData().getSlot()), spec.getNetworkingConfig(), debugDataDumper); diff --git a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/eventsource/EventSourceHandler.java b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/eventsource/EventSourceHandler.java index b8b396e4058..05e063d5f88 100644 --- a/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/eventsource/EventSourceHandler.java +++ b/validator/remote/src/main/java/tech/pegasys/teku/validator/remote/eventsource/EventSourceHandler.java @@ -121,10 +121,7 @@ private void handleHeadEvent(final String data) throws JsonProcessingException { private void handleAttesterSlashingEvent(final String data) throws JsonProcessingException { final DeserializableTypeDefinition attesterSlashingTypeDefinition = - spec.getGenesisSchemaDefinitions() - .getAttesterSlashingSchema() - .castTypeToAttesterSlashingSchema() - .getJsonTypeDefinition(); + spec.getGenesisSchemaDefinitions().getAttesterSlashingSchema().getJsonTypeDefinition(); final AttesterSlashing attesterSlashing = JsonUtil.parse(data, attesterSlashingTypeDefinition); validatorTimingChannel.onAttesterSlashing(attesterSlashing); } diff --git a/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/eventsource/EventSourceHandlerTest.java b/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/eventsource/EventSourceHandlerTest.java index 50d035d0c42..3838c12355d 100644 --- a/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/eventsource/EventSourceHandlerTest.java +++ b/validator/remote/src/test/java/tech/pegasys/teku/validator/remote/eventsource/EventSourceHandlerTest.java @@ -84,7 +84,7 @@ void onMessage_shouldHandleHeadEvent() throws Exception { void onMessage_shouldHandleAttesterSlashingEvent() throws Exception { final IndexedAttestation indexedAttestation1 = dataStructureUtil.randomIndexedAttestation(); final IndexedAttestation indexedAttestation2 = dataStructureUtil.randomIndexedAttestation(); - final AttesterSlashingSchema attesterSlashingSchema = + final AttesterSlashingSchema attesterSlashingSchema = spec.getGenesisSchemaDefinitions().getAttesterSlashingSchema(); final AttesterSlashing attesterSlashing = attesterSlashingSchema.create(indexedAttestation1, indexedAttestation2); @@ -92,11 +92,7 @@ void onMessage_shouldHandleAttesterSlashingEvent() throws Exception { handler.onMessage( EventType.attester_slashing.name(), new MessageEvent( - JsonUtil.serialize( - attesterSlashing, - attesterSlashingSchema - .castTypeToAttesterSlashingSchema() - .getJsonTypeDefinition()))); + JsonUtil.serialize(attesterSlashing, attesterSlashingSchema.getJsonTypeDefinition()))); verify(validatorTimingChannel).onAttesterSlashing(eq(attesterSlashing)); verifyNoMoreInteractions(validatorTimingChannel);