Skip to content

Commit

Permalink
Replace spec for SchemaDefinitionCache (#8482)
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Fukushima <[email protected]>
  • Loading branch information
gfukushima authored Jul 30, 2024
1 parent 63d225a commit 728fad7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,31 @@
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;

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")
.summary("Submit AttesterSlashing object to node's pool")
.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;
Expand Down Expand Up @@ -77,13 +79,12 @@ public void handleRequest(final RestApiRequest request) throws JsonProcessingExc
}));
}

private static DeserializableTypeDefinition<AttesterSlashing> 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<AttesterSlashing> getRequestType(
final SchemaDefinitionCache schemaDefinitionCache) {

return attesterSlashingSchema.getJsonTypeDefinition();
return schemaDefinitionCache
.getSchemaDefinition(SpecMilestone.PHASE0)
.getAttesterSlashingSchema()
.getJsonTypeDefinition();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class PostAttesterSlashingTest extends AbstractMigratedBeaconHandlerTest

@BeforeEach
void setup() {
setHandler(new PostAttesterSlashing(nodeDataProvider, spec));
setHandler(new PostAttesterSlashing(nodeDataProvider, schemaDefinitionCache));
}

@Test
Expand Down

0 comments on commit 728fad7

Please sign in to comment.