diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetAttestationsV2.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetAttestationsV2.java index b749a40a767..a1fb01e5130 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetAttestationsV2.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetAttestationsV2.java @@ -19,6 +19,7 @@ import static tech.pegasys.teku.ethereum.json.types.EthereumTypes.MILESTONE_TYPE; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK; import static tech.pegasys.teku.infrastructure.http.RestApiConstants.CACHE_NONE; +import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_CONSENSUS_VERSION; import static tech.pegasys.teku.infrastructure.http.RestApiConstants.SLOT_QUERY_DESCRIPTION; import static tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON; import static tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition.listOf; @@ -30,6 +31,7 @@ import java.util.Optional; import tech.pegasys.teku.api.DataProvider; import tech.pegasys.teku.api.NodeDataProvider; +import tech.pegasys.teku.api.schema.Version; import tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil; import tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition; import tech.pegasys.teku.infrastructure.restapi.endpoints.EndpointMetadata; @@ -77,8 +79,13 @@ public void handleRequest(final RestApiRequest request) throws JsonProcessingExc request.getOptionalQueryParameter(SLOT_PARAMETER.withDescription(SLOT_QUERY_DESCRIPTION)); final Optional committeeIndex = request.getOptionalQueryParameter(COMMITTEE_INDEX_PARAMETER); + final ObjectAndMetaData> attestationsAndMetaData = + nodeDataProvider.getAttestationsAndMetaData(slot, committeeIndex); - request.respondOk(nodeDataProvider.getAttestationsAndMetaData(slot, committeeIndex)); + request.header( + HEADER_CONSENSUS_VERSION, + Version.fromMilestone(attestationsAndMetaData.getMilestone()).name()); + request.respondOk(attestationsAndMetaData); } private static SerializableTypeDefinition>> getResponseType( diff --git a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetAttestationsV2Test.java b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetAttestationsV2Test.java index 2d3b8b8c97a..3425a5667cc 100644 --- a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetAttestationsV2Test.java +++ b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetAttestationsV2Test.java @@ -20,6 +20,7 @@ import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_INTERNAL_SERVER_ERROR; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK; +import static tech.pegasys.teku.infrastructure.http.RestApiConstants.HEADER_CONSENSUS_VERSION; import static tech.pegasys.teku.infrastructure.restapi.MetadataTestUtil.getResponseStringFromMetadata; import static tech.pegasys.teku.infrastructure.restapi.MetadataTestUtil.verifyMetadataErrorResponse; import static tech.pegasys.teku.spec.SpecMilestone.ELECTRA; @@ -33,6 +34,7 @@ import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestTemplate; +import tech.pegasys.teku.api.schema.Version; import tech.pegasys.teku.beaconrestapi.AbstractMigratedBeaconHandlerTest; import tech.pegasys.teku.infrastructure.json.JsonTestUtil; import tech.pegasys.teku.spec.SpecMilestone; @@ -69,6 +71,8 @@ public void shouldReturnAttestationsWhenFound() throws JsonProcessingException { handler.handleRequest(request); assertThat(request.getResponseCode()).isEqualTo(SC_OK); assertThat(request.getResponseBody()).isEqualTo(attestationsAndMetaData); + assertThat(request.getResponseHeaders(HEADER_CONSENSUS_VERSION)) + .isEqualTo(Version.fromMilestone(specMilestone).name()); } @TestTemplate @@ -82,6 +86,8 @@ public void shouldReturnEmptyListWhenNoAttestations() throws JsonProcessingExcep handler.handleRequest(request); assertThat(request.getResponseCode()).isEqualTo(SC_OK); assertThat(request.getResponseBody()).isEqualTo(attestationsAndMetaData); + assertThat(request.getResponseHeaders(HEADER_CONSENSUS_VERSION)) + .isEqualTo(Version.fromMilestone(specMilestone).name()); } @TestTemplate