Skip to content

Commit 15f5a84

Browse files
authored
Add headers to Endpoint's Metadata where applicable (Consensys#8138)
1 parent 1d8255a commit 15f5a84

File tree

10 files changed

+59
-2
lines changed

10 files changed

+59
-2
lines changed

data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_beacon_blinded_blocks.json

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
"operationId" : "publishBlindedBlock",
55
"summary" : "Publish a signed blinded block",
66
"description" : "Submit a signed blinded beacon block to the beacon node to be broadcast and imported. The beacon node performs the required validation.",
7+
"parameters" : [ {
8+
"name" : "Eth-Consensus-Version",
9+
"in" : "header",
10+
"schema" : {
11+
"type" : "string",
12+
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ],
13+
"description" : "Version of the block being submitted, if using SSZ encoding."
14+
}
15+
} ],
716
"requestBody" : {
817
"content" : {
918
"application/octet-stream" : {

data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v1_beacon_blocks.json

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
"operationId" : "publishBlock",
55
"summary" : "Publish a signed block",
66
"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.",
7+
"parameters" : [ {
8+
"name" : "Eth-Consensus-Version",
9+
"in" : "header",
10+
"schema" : {
11+
"type" : "string",
12+
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ],
13+
"description" : "Version of the block being submitted, if using SSZ encoding."
14+
}
15+
} ],
716
"requestBody" : {
817
"content" : {
918
"application/octet-stream" : {

data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v2_beacon_blinded_blocks.json

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
"example" : "consensus_and_equivocation",
1414
"format" : "string"
1515
}
16+
}, {
17+
"name" : "Eth-Consensus-Version",
18+
"required" : true,
19+
"in" : "header",
20+
"schema" : {
21+
"type" : "string",
22+
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ],
23+
"description" : "Version of the block being submitted."
24+
}
1625
} ],
1726
"requestBody" : {
1827
"content" : {

data/beaconrestapi/src/integration-test/resources/tech/pegasys/teku/beaconrestapi/beacon/paths/_eth_v2_beacon_blocks.json

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
"example" : "consensus_and_equivocation",
1414
"format" : "string"
1515
}
16+
}, {
17+
"name" : "Eth-Consensus-Version",
18+
"required" : true,
19+
"in" : "header",
20+
"schema" : {
21+
"type" : "string",
22+
"enum" : [ "phase0", "altair", "bellatrix", "capella", "deneb", "electra" ],
23+
"description" : "Version of the block being submitted."
24+
}
1625
} ],
1726
"requestBody" : {
1827
"content" : {

data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/BeaconRestApiTypes.java

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
package tech.pegasys.teku.beaconrestapi;
1515

16+
import static tech.pegasys.teku.ethereum.json.types.EthereumTypes.MILESTONE_TYPE;
1617
import static tech.pegasys.teku.ethereum.json.types.EthereumTypes.SIGNATURE_TYPE;
1718
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.ATTESTATION_DATA_ROOT;
1819
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.BEACON_BLOCK_ROOT;
@@ -24,6 +25,7 @@
2425
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.EPOCH;
2526
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.EPOCH_QUERY_DESCRIPTION;
2627
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.GRAFFITI;
28+
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_CONSENSUS_VERSION;
2729
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.INDEX;
2830
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.PARAM_BLOCK_ID;
2931
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.PARAM_BLOCK_ID_DESCRIPTION;
@@ -71,6 +73,7 @@
7173
import tech.pegasys.teku.infrastructure.json.types.StringValueTypeDefinition;
7274
import tech.pegasys.teku.infrastructure.restapi.endpoints.ParameterMetadata;
7375
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
76+
import tech.pegasys.teku.spec.SpecMilestone;
7477
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader;
7578
import tech.pegasys.teku.spec.datastructures.metadata.BlockAndMetaData;
7679
import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel;
@@ -241,6 +244,9 @@ public class BeaconRestApiTypes {
241244
PARAMETER_BROADCAST_VALIDATION =
242245
new ParameterMetadata<>(PARAM_BROADCAST_VALIDATION, BROADCAST_VALIDATION_VALUE);
243246

247+
public static final ParameterMetadata<SpecMilestone> ETH_CONSENSUS_VERSION_TYPE =
248+
new ParameterMetadata<>(HEADER_CONSENSUS_VERSION, MILESTONE_TYPE);
249+
244250
@SuppressWarnings("JavaCase")
245251
public enum BroadcastValidationParameter {
246252
gossip,

data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostBlindedBlock.java

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

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

16+
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.ETH_CONSENSUS_VERSION_TYPE;
1617
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.getSchemaDefinitionForAllSupportedMilestones;
1718
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.slotBasedSelector;
1819
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_ACCEPTED;
@@ -95,6 +96,9 @@ private static EndpointMetadata createMetadata(
9596
schemaDefinitionCache,
9697
SchemaDefinitions::getSignedBlindedBlockContainerSchema),
9798
spec::deserializeSignedBlindedBlockContainer)
99+
.header(
100+
ETH_CONSENSUS_VERSION_TYPE.withDescription(
101+
"Version of the block being submitted, if using SSZ encoding."))
98102
.response(SC_OK, "Block has been successfully broadcast, validated and imported.")
99103
.response(
100104
SC_ACCEPTED,

data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostBlock.java

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

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

16+
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.ETH_CONSENSUS_VERSION_TYPE;
1617
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.getSchemaDefinitionForAllSupportedMilestones;
1718
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.slotBasedSelector;
1819
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_ACCEPTED;
@@ -98,6 +99,9 @@ private static EndpointMetadata createMetadata(
9899
schemaDefinitionCache,
99100
SchemaDefinitions::getSignedBlockContainerSchema),
100101
spec::deserializeSignedBlockContainer)
102+
.header(
103+
ETH_CONSENSUS_VERSION_TYPE.withDescription(
104+
"Version of the block being submitted, if using SSZ encoding."))
101105
.response(SC_OK, "Block has been successfully broadcast, validated and imported.")
102106
.response(
103107
SC_ACCEPTED,

data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostBlindedBlockV2.java

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

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

16+
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.ETH_CONSENSUS_VERSION_TYPE;
1617
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.PARAMETER_BROADCAST_VALIDATION;
1718
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.getSchemaDefinitionForAllSupportedMilestones;
1819
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.slotBasedSelector;
@@ -117,6 +118,8 @@ broadcast but a different status code is returned (202). Pre-Bellatrix, this end
117118
schemaDefinitionCache,
118119
SchemaDefinitions::getSignedBlindedBlockContainerSchema),
119120
spec::deserializeSignedBlindedBlockContainer)
121+
.headerRequired(
122+
ETH_CONSENSUS_VERSION_TYPE.withDescription("Version of the block being submitted."))
120123
.response(SC_OK, "Block has been successfully broadcast, validated and imported.")
121124
.response(
122125
SC_ACCEPTED,

data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostBlockV2.java

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

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

16+
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.ETH_CONSENSUS_VERSION_TYPE;
1617
import static tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes.PARAMETER_BROADCAST_VALIDATION;
1718
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.getSchemaDefinitionForAllSupportedMilestones;
1819
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.slotBasedSelector;
@@ -117,6 +118,8 @@ validation, a separate success response code (202) is used to indicate that the
117118
schemaDefinitionCache,
118119
SchemaDefinitions::getSignedBlockContainerSchema),
119120
spec::deserializeSignedBlockContainer)
121+
.headerRequired(
122+
ETH_CONSENSUS_VERSION_TYPE.withDescription("Version of the block being submitted."))
120123
.response(SC_OK, "Block has been successfully broadcast, validated and imported.")
121124
.response(
122125
SC_ACCEPTED,

ethereum/json-types/src/main/java/tech/pegasys/teku/ethereum/json/types/EthereumTypes.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import tech.pegasys.teku.ethereum.execution.types.Eth1Address;
2626
import tech.pegasys.teku.infrastructure.http.RestApiConstants;
2727
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
28+
import tech.pegasys.teku.infrastructure.json.types.EnumTypeDefinition;
2829
import tech.pegasys.teku.infrastructure.json.types.StringValueTypeDefinition;
2930
import tech.pegasys.teku.infrastructure.restapi.openapi.response.OctetStreamResponseContentTypeDefinition;
3031
import tech.pegasys.teku.infrastructure.restapi.openapi.response.ResponseContentTypeDefinition;
@@ -91,8 +92,8 @@ public class EthereumTypes {
9192
.format("byte")
9293
.build();
9394

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

9899
public static <X extends SszData, T extends ObjectAndMetaData<X>>

0 commit comments

Comments
 (0)