Skip to content

Commit

Permalink
Add headers to Endpoint's Metadata where applicable (#8138)
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 authored Mar 25, 2024
1 parent 1d8255a commit 15f5a84
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
"operationId" : "publishBlindedBlock",
"summary" : "Publish a signed blinded block",
"description" : "Submit a signed blinded beacon block to the beacon node to be broadcast and imported. The beacon node performs the required validation.",
"parameters" : [ {
"name" : "Eth-Consensus-Version",
"in" : "header",
"schema" : {
"type" : "string",
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ],
"description" : "Version of the block being submitted, if using SSZ encoding."
}
} ],
"requestBody" : {
"content" : {
"application/octet-stream" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
"operationId" : "publishBlock",
"summary" : "Publish a signed block",
"description" : "Submit a signed beacon block to the beacon node to be broadcast and imported. After Deneb, this additionally instructs the beacon node to broadcast and import all given blobs. The beacon node performs the required validation.",
"parameters" : [ {
"name" : "Eth-Consensus-Version",
"in" : "header",
"schema" : {
"type" : "string",
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ],
"description" : "Version of the block being submitted, if using SSZ encoding."
}
} ],
"requestBody" : {
"content" : {
"application/octet-stream" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"example" : "consensus_and_equivocation",
"format" : "string"
}
}, {
"name" : "Eth-Consensus-Version",
"required" : true,
"in" : "header",
"schema" : {
"type" : "string",
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ],
"description" : "Version of the block being submitted."
}
} ],
"requestBody" : {
"content" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
"example" : "consensus_and_equivocation",
"format" : "string"
}
}, {
"name" : "Eth-Consensus-Version",
"required" : true,
"in" : "header",
"schema" : {
"type" : "string",
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ],
"description" : "Version of the block being submitted."
}
} ],
"requestBody" : {
"content" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.beaconrestapi;

import static tech.pegasys.teku.ethereum.json.types.EthereumTypes.MILESTONE_TYPE;
import static tech.pegasys.teku.ethereum.json.types.EthereumTypes.SIGNATURE_TYPE;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.ATTESTATION_DATA_ROOT;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.BEACON_BLOCK_ROOT;
Expand All @@ -24,6 +25,7 @@
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.EPOCH;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.EPOCH_QUERY_DESCRIPTION;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.GRAFFITI;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_CONSENSUS_VERSION;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.INDEX;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.PARAM_BLOCK_ID;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.PARAM_BLOCK_ID_DESCRIPTION;
Expand Down Expand Up @@ -71,6 +73,7 @@
import tech.pegasys.teku.infrastructure.json.types.StringValueTypeDefinition;
import tech.pegasys.teku.infrastructure.restapi.endpoints.ParameterMetadata;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader;
import tech.pegasys.teku.spec.datastructures.metadata.BlockAndMetaData;
import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel;
Expand Down Expand Up @@ -241,6 +244,9 @@ public class BeaconRestApiTypes {
PARAMETER_BROADCAST_VALIDATION =
new ParameterMetadata<>(PARAM_BROADCAST_VALIDATION, BROADCAST_VALIDATION_VALUE);

public static final ParameterMetadata<SpecMilestone> ETH_CONSENSUS_VERSION_TYPE =
new ParameterMetadata<>(HEADER_CONSENSUS_VERSION, MILESTONE_TYPE);

@SuppressWarnings("JavaCase")
public enum BroadcastValidationParameter {
gossip,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.beaconrestapi.handlers.v1.beacon;

import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.ETH_CONSENSUS_VERSION_TYPE;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.getSchemaDefinitionForAllSupportedMilestones;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.slotBasedSelector;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_ACCEPTED;
Expand Down Expand Up @@ -95,6 +96,9 @@ private static EndpointMetadata createMetadata(
schemaDefinitionCache,
SchemaDefinitions::getSignedBlindedBlockContainerSchema),
spec::deserializeSignedBlindedBlockContainer)
.header(
ETH_CONSENSUS_VERSION_TYPE.withDescription(
"Version of the block being submitted, if using SSZ encoding."))
.response(SC_OK, "Block has been successfully broadcast, validated and imported.")
.response(
SC_ACCEPTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.beaconrestapi.handlers.v1.beacon;

import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.ETH_CONSENSUS_VERSION_TYPE;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.getSchemaDefinitionForAllSupportedMilestones;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.slotBasedSelector;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_ACCEPTED;
Expand Down Expand Up @@ -98,6 +99,9 @@ private static EndpointMetadata createMetadata(
schemaDefinitionCache,
SchemaDefinitions::getSignedBlockContainerSchema),
spec::deserializeSignedBlockContainer)
.header(
ETH_CONSENSUS_VERSION_TYPE.withDescription(
"Version of the block being submitted, if using SSZ encoding."))
.response(SC_OK, "Block has been successfully broadcast, validated and imported.")
.response(
SC_ACCEPTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.beaconrestapi.handlers.v2.beacon;

import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.ETH_CONSENSUS_VERSION_TYPE;
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.PARAMETER_BROADCAST_VALIDATION;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.getSchemaDefinitionForAllSupportedMilestones;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.slotBasedSelector;
Expand Down Expand Up @@ -117,6 +118,8 @@ broadcast but a different status code is returned (202). Pre-Bellatrix, this end
schemaDefinitionCache,
SchemaDefinitions::getSignedBlindedBlockContainerSchema),
spec::deserializeSignedBlindedBlockContainer)
.headerRequired(
ETH_CONSENSUS_VERSION_TYPE.withDescription("Version of the block being submitted."))
.response(SC_OK, "Block has been successfully broadcast, validated and imported.")
.response(
SC_ACCEPTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.beaconrestapi.handlers.v2.beacon;

import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.ETH_CONSENSUS_VERSION_TYPE;
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.PARAMETER_BROADCAST_VALIDATION;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.getSchemaDefinitionForAllSupportedMilestones;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.slotBasedSelector;
Expand Down Expand Up @@ -117,6 +118,8 @@ validation, a separate success response code (202) is used to indicate that the
schemaDefinitionCache,
SchemaDefinitions::getSignedBlockContainerSchema),
spec::deserializeSignedBlockContainer)
.headerRequired(
ETH_CONSENSUS_VERSION_TYPE.withDescription("Version of the block being submitted."))
.response(SC_OK, "Block has been successfully broadcast, validated and imported.")
.response(
SC_ACCEPTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import tech.pegasys.teku.ethereum.execution.types.Eth1Address;
import tech.pegasys.teku.infrastructure.http.RestApiConstants;
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.infrastructure.json.types.EnumTypeDefinition;
import tech.pegasys.teku.infrastructure.json.types.StringValueTypeDefinition;
import tech.pegasys.teku.infrastructure.restapi.openapi.response.OctetStreamResponseContentTypeDefinition;
import tech.pegasys.teku.infrastructure.restapi.openapi.response.ResponseContentTypeDefinition;
Expand Down Expand Up @@ -91,8 +92,8 @@ public class EthereumTypes {
.format("byte")
.build();

public static final DeserializableTypeDefinition<SpecMilestone> MILESTONE_TYPE =
DeserializableTypeDefinition.enumOf(
public static final StringValueTypeDefinition<SpecMilestone> MILESTONE_TYPE =
new EnumTypeDefinition<>(
SpecMilestone.class, milestone -> milestone.name().toLowerCase(Locale.ROOT), Set.of());

public static <X extends SszData, T extends ObjectAndMetaData<X>>
Expand Down

0 comments on commit 15f5a84

Please sign in to comment.