From 728fad77ee8fc2f8d53c6f6f4f1a90d66658803c Mon Sep 17 00:00:00 2001 From: Gabriel Fukushima Date: Tue, 30 Jul 2024 13:43:20 +1000 Subject: [PATCH] Replace spec for SchemaDefinitionCache (#8482) Signed-off-by: Gabriel Fukushima --- .../JsonTypeDefinitionBeaconRestApi.java | 2 +- .../v1/beacon/PostAttesterSlashing.java | 27 ++++++++++--------- .../v1/beacon/PostAttesterSlashingTest.java | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/JsonTypeDefinitionBeaconRestApi.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/JsonTypeDefinitionBeaconRestApi.java index ab073602f7e..66d9e3c2f1b 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/JsonTypeDefinitionBeaconRestApi.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/JsonTypeDefinitionBeaconRestApi.java @@ -241,7 +241,7 @@ private static RestApi create( .endpoint(new PostAttestation(dataProvider, schemaCache)) .endpoint(new GetAttesterSlashings(dataProvider, spec)) .endpoint(new GetAttesterSlashingsV2(dataProvider, schemaCache)) - .endpoint(new PostAttesterSlashing(dataProvider, spec)) + .endpoint(new PostAttesterSlashing(dataProvider, schemaCache)) .endpoint(new GetProposerSlashings(dataProvider)) .endpoint(new PostProposerSlashing(dataProvider)) .endpoint(new GetVoluntaryExits(dataProvider)) diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostAttesterSlashing.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostAttesterSlashing.java index 23d0e3f0be9..029d8f04ad2 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostAttesterSlashing.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostAttesterSlashing.java @@ -26,9 +26,9 @@ import tech.pegasys.teku.infrastructure.restapi.endpoints.EndpointMetadata; import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiEndpoint; import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiRequest; -import tech.pegasys.teku.spec.Spec; +import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing; -import tech.pegasys.teku.spec.datastructures.operations.IndexedAttestation; +import tech.pegasys.teku.spec.schemas.SchemaDefinitionCache; import tech.pegasys.teku.statetransition.validation.InternalValidationResult; import tech.pegasys.teku.statetransition.validation.ValidationResultCode; @@ -36,11 +36,13 @@ public class PostAttesterSlashing extends RestApiEndpoint { public static final String ROUTE = "/eth/v1/beacon/pool/attester_slashings"; private final NodeDataProvider nodeDataProvider; - public PostAttesterSlashing(final DataProvider dataProvider, final Spec spec) { - this(dataProvider.getNodeDataProvider(), spec); + public PostAttesterSlashing( + final DataProvider dataProvider, final SchemaDefinitionCache schemaDefinitionCache) { + this(dataProvider.getNodeDataProvider(), schemaDefinitionCache); } - public PostAttesterSlashing(final NodeDataProvider provider, final Spec spec) { + public PostAttesterSlashing( + final NodeDataProvider provider, final SchemaDefinitionCache schemaDefinitionCache) { super( EndpointMetadata.post(ROUTE) .operationId("submitPoolAttesterSlashings") @@ -48,7 +50,7 @@ public PostAttesterSlashing(final NodeDataProvider provider, final Spec spec) { .description( "Submits attester slashing object to node's pool and if passes validation node MUST broadcast it to network.") .tags(TAG_BEACON) - .requestBodyType(getRequestType(spec)) + .requestBodyType(getRequestType(schemaDefinitionCache)) .response(SC_OK, "Success") .build()); this.nodeDataProvider = provider; @@ -77,13 +79,12 @@ public void handleRequest(final RestApiRequest request) throws JsonProcessingExc })); } - private static DeserializableTypeDefinition getRequestType(final Spec spec) { - // TODO EIP-7549 handle electra indexed attestations - final IndexedAttestation.IndexedAttestationSchema indexedAttestationSchema = - spec.getGenesisSchemaDefinitions().getIndexedAttestationSchema(); - final AttesterSlashing.AttesterSlashingSchema attesterSlashingSchema = - new AttesterSlashing.AttesterSlashingSchema(indexedAttestationSchema); + private static DeserializableTypeDefinition getRequestType( + final SchemaDefinitionCache schemaDefinitionCache) { - return attesterSlashingSchema.getJsonTypeDefinition(); + return schemaDefinitionCache + .getSchemaDefinition(SpecMilestone.PHASE0) + .getAttesterSlashingSchema() + .getJsonTypeDefinition(); } } diff --git a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostAttesterSlashingTest.java b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostAttesterSlashingTest.java index ab7302db2a6..bb7e27defee 100644 --- a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostAttesterSlashingTest.java +++ b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostAttesterSlashingTest.java @@ -38,7 +38,7 @@ public class PostAttesterSlashingTest extends AbstractMigratedBeaconHandlerTest @BeforeEach void setup() { - setHandler(new PostAttesterSlashing(nodeDataProvider, spec)); + setHandler(new PostAttesterSlashing(nodeDataProvider, schemaDefinitionCache)); } @Test