From c3ff1d9a84449caef4954b02d9a8185854529f67 Mon Sep 17 00:00:00 2001 From: Paul Harris Date: Tue, 22 Oct 2024 05:20:16 +1000 Subject: [PATCH] made post block header work with available information (#8758) In the case of JSON specifically, we do have the slot number, and we don't actually need the header with a slot present. Signed-off-by: Paul Harris --- CHANGELOG.md | 3 ++- .../v1/validator/PostBlindedAndUnblindedBlockTest.java | 10 +--------- .../handlers/v2/beacon/PostBlindedBlockV2.java | 5 +++-- .../beaconrestapi/handlers/v2/beacon/PostBlockV2.java | 5 +++-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63d1428b0c6..79bfa293d6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,4 +12,5 @@ - Clean up old beacon states when switching from ARCHIVE to PRUNE or MINIMAL data storage mode ### Bug Fixes - - Fixed a block production issue for Validator Client (24.10.0 to 24.10.2 teku VC), where required headers were not provided for JSON payloads. Default SSZ block production was unaffected. The required header is in the beacon-api spec but was not updated in all places for the VC. + - Fixed a block production issue for Validator Client (24.10.0 to 24.10.2 teku VC), where required headers were not provided for JSON payloads. Default SSZ block production was unaffected. + - Block production now uses json data (more like 24.8.0 did than 24.10) if the Eth-Consensus-version header is absent. diff --git a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/validator/PostBlindedAndUnblindedBlockTest.java b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/validator/PostBlindedAndUnblindedBlockTest.java index 6b85496b015..27a1fdc00ff 100644 --- a/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/validator/PostBlindedAndUnblindedBlockTest.java +++ b/data/beaconrestapi/src/integration-test/java/tech/pegasys/teku/beaconrestapi/v1/validator/PostBlindedAndUnblindedBlockTest.java @@ -17,7 +17,6 @@ import static org.mockito.Mockito.when; import static tech.pegasys.teku.beaconrestapi.v1.validator.PostBlindedAndUnblindedBlockTest.Version.V1; import static tech.pegasys.teku.beaconrestapi.v1.validator.PostBlindedAndUnblindedBlockTest.Version.V2; -import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK; import java.io.IOException; @@ -204,14 +203,7 @@ private void postRequestAndAssert( JsonUtil.serialize(request, signedBlockContainerSchema.getJsonTypeDefinition()), params, versionHeader)) { - if (version == V2 && versionHeader.isEmpty()) { - // the version header is required in V2 APIs - assertThat(response.code()).isEqualTo(SC_BAD_REQUEST); - } else { - // the version header is not required for V1 APIs, the header selector should fall back to - // the slot selector - assertThat(response.code()).isEqualTo(SC_OK); - } + assertThat(response.code()).isEqualTo(SC_OK); } } } diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostBlindedBlockV2.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostBlindedBlockV2.java index 6c3422a37f8..77c5de04450 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostBlindedBlockV2.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostBlindedBlockV2.java @@ -16,7 +16,7 @@ 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.headerBasedSelector; +import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.headerBasedSelectorWithSlotFallback; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_ACCEPTED; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NO_CONTENT; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK; @@ -114,8 +114,9 @@ broadcast but a different status code is returned (202). Pre-Bellatrix, this end .milestoneAtSlot(blockContainer.getSlot()) .equals(milestone)), context -> - headerBasedSelector( + headerBasedSelectorWithSlotFallback( context.getHeaders(), + context.getBody(), schemaDefinitionCache, SchemaDefinitions::getSignedBlindedBlockContainerSchema), spec::deserializeSignedBlindedBlockContainer) diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostBlockV2.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostBlockV2.java index 9878d8f5759..3dec9966d6c 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostBlockV2.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/PostBlockV2.java @@ -16,7 +16,7 @@ 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.headerBasedSelector; +import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.MilestoneDependentTypesUtil.headerBasedSelectorWithSlotFallback; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_ACCEPTED; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NO_CONTENT; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK; @@ -114,8 +114,9 @@ validation, a separate success response code (202) is used to indicate that the .milestoneAtSlot(blockContainer.getSlot()) .equals(milestone)), context -> - headerBasedSelector( + headerBasedSelectorWithSlotFallback( context.getHeaders(), + context.getBody(), schemaDefinitionCache, SchemaDefinitions::getSignedBlockContainerSchema), spec::deserializeSignedBlockContainer)