From f80fc8a2ff2267bb256a52b03db05eab88dcd778 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 15 Jul 2024 19:47:14 +0100 Subject: [PATCH 1/4] fix: add workaround to fix compatibility with go-eth2-client --- packages/beacon-node/src/api/rest/base.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/beacon-node/src/api/rest/base.ts b/packages/beacon-node/src/api/rest/base.ts index 20439290e939..471235fc89aa 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -94,6 +94,13 @@ export class RestApiServer { const operationId = getOperationId(req); this.logger.debug(`Req ${req.id} ${req.ip} ${operationId}`); metrics?.requests.inc({operationId}); + + const userAgent = req.headers["user-agent"]?.split("/")[0]; + if (operationId !== "produceBlockV3" && userAgent && ["Go-http-client", "Vouch"].includes(userAgent)) { + // Override Accept header to force server to return JSON + // See https://github.com/attestantio/go-eth2-client/issues/144 + req.headers.accept = "application/json"; + } }); server.addHook("preHandler", async (req, _res) => { From b8f98ca85ef68d90c99033555f0808212af23c3a Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 15 Jul 2024 20:07:55 +0100 Subject: [PATCH 2/4] Skip more endpoints --- packages/beacon-node/src/api/rest/base.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/beacon-node/src/api/rest/base.ts b/packages/beacon-node/src/api/rest/base.ts index 471235fc89aa..700e0cb1526c 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -95,8 +95,13 @@ export class RestApiServer { this.logger.debug(`Req ${req.id} ${req.ip} ${operationId}`); metrics?.requests.inc({operationId}); - const userAgent = req.headers["user-agent"]?.split("/")[0]; - if (operationId !== "produceBlockV3" && userAgent && ["Go-http-client", "Vouch"].includes(userAgent)) { + const userAgent = req.headers["user-agent"]?.split("/")[0] ?? ""; + if ( + // go-eth2-client supports handling SSZ data in response for these endpoints + ["produceBlindedBlock", "produceBlockV3", "getBlockV2", "getStateV2"].includes(operationId) && + // Only Vouch seems to override default header + ["Go-http-client", "Vouch"].includes(userAgent) + ) { // Override Accept header to force server to return JSON // See https://github.com/attestantio/go-eth2-client/issues/144 req.headers.accept = "application/json"; From b0176ba8547e2759d6630e3871be2625f5ec7f41 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 15 Jul 2024 20:16:53 +0100 Subject: [PATCH 3/4] Move comments around --- packages/beacon-node/src/api/rest/base.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/beacon-node/src/api/rest/base.ts b/packages/beacon-node/src/api/rest/base.ts index 700e0cb1526c..b0ea95ad2735 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -95,15 +95,15 @@ export class RestApiServer { this.logger.debug(`Req ${req.id} ${req.ip} ${operationId}`); metrics?.requests.inc({operationId}); - const userAgent = req.headers["user-agent"]?.split("/")[0] ?? ""; + // Workaround to fix compatibility with go-eth2-client + // See https://github.com/attestantio/go-eth2-client/issues/144 if ( // go-eth2-client supports handling SSZ data in response for these endpoints ["produceBlindedBlock", "produceBlockV3", "getBlockV2", "getStateV2"].includes(operationId) && // Only Vouch seems to override default header - ["Go-http-client", "Vouch"].includes(userAgent) + ["Go-http-client", "Vouch"].includes(req.headers["user-agent"]?.split("/")[0] ?? "") ) { // Override Accept header to force server to return JSON - // See https://github.com/attestantio/go-eth2-client/issues/144 req.headers.accept = "application/json"; } }); From a94d252aebe93644095789589058376db23d51a0 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 15 Jul 2024 20:17:04 +0100 Subject: [PATCH 4/4] Fix assertion --- packages/beacon-node/src/api/rest/base.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/beacon-node/src/api/rest/base.ts b/packages/beacon-node/src/api/rest/base.ts index b0ea95ad2735..4f5d9284f91b 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -99,7 +99,7 @@ export class RestApiServer { // See https://github.com/attestantio/go-eth2-client/issues/144 if ( // go-eth2-client supports handling SSZ data in response for these endpoints - ["produceBlindedBlock", "produceBlockV3", "getBlockV2", "getStateV2"].includes(operationId) && + !["produceBlindedBlock", "produceBlockV3", "getBlockV2", "getStateV2"].includes(operationId) && // Only Vouch seems to override default header ["Go-http-client", "Vouch"].includes(req.headers["user-agent"]?.split("/")[0] ?? "") ) {