From 71bcde86deeed470b8ef036ef68c71470ce764e3 Mon Sep 17 00:00:00 2001 From: Cayman Date: Mon, 15 Jul 2024 16:17:24 -0400 Subject: [PATCH 1/5] chore: bump package versions to 1.20.1 --- lerna.json | 2 +- packages/api/package.json | 10 +++++----- packages/beacon-node/package.json | 26 +++++++++++++------------- packages/cli/package.json | 26 +++++++++++++------------- packages/config/package.json | 6 +++--- packages/db/package.json | 8 ++++---- packages/flare/package.json | 14 +++++++------- packages/fork-choice/package.json | 12 ++++++------ packages/light-client/package.json | 12 ++++++------ packages/logger/package.json | 6 +++--- packages/params/package.json | 2 +- packages/prover/package.json | 18 +++++++++--------- packages/reqresp/package.json | 12 ++++++------ packages/spec-test-util/package.json | 4 ++-- packages/state-transition/package.json | 10 +++++----- packages/test-utils/package.json | 6 +++--- packages/types/package.json | 4 ++-- packages/utils/package.json | 2 +- packages/validator/package.json | 18 +++++++++--------- 19 files changed, 99 insertions(+), 99 deletions(-) diff --git a/lerna.json b/lerna.json index 2f8525637607..bfba68d36c54 100644 --- a/lerna.json +++ b/lerna.json @@ -4,7 +4,7 @@ ], "npmClient": "yarn", "useNx": true, - "version": "1.20.0", + "version": "1.20.1", "stream": true, "command": { "version": { diff --git a/packages/api/package.json b/packages/api/package.json index d5f261aa284a..280d4bf4e9ef 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.20.0", + "version": "1.20.1", "type": "module", "exports": { ".": { @@ -72,10 +72,10 @@ "dependencies": { "@chainsafe/persistent-merkle-tree": "^0.7.1", "@chainsafe/ssz": "^0.15.1", - "@lodestar/config": "^1.20.0", - "@lodestar/params": "^1.20.0", - "@lodestar/types": "^1.20.0", - "@lodestar/utils": "^1.20.0", + "@lodestar/config": "^1.20.1", + "@lodestar/params": "^1.20.1", + "@lodestar/types": "^1.20.1", + "@lodestar/utils": "^1.20.1", "eventsource": "^2.0.2", "qs": "^6.11.1" }, diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index 3b93116d8737..c57de6eb5781 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.20.0", + "version": "1.20.1", "type": "module", "exports": { ".": { @@ -120,18 +120,18 @@ "@libp2p/peer-id-factory": "^4.1.0", "@libp2p/prometheus-metrics": "^3.0.21", "@libp2p/tcp": "9.0.23", - "@lodestar/api": "^1.20.0", - "@lodestar/config": "^1.20.0", - "@lodestar/db": "^1.20.0", - "@lodestar/fork-choice": "^1.20.0", - "@lodestar/light-client": "^1.20.0", - "@lodestar/logger": "^1.20.0", - "@lodestar/params": "^1.20.0", - "@lodestar/reqresp": "^1.20.0", - "@lodestar/state-transition": "^1.20.0", - "@lodestar/types": "^1.20.0", - "@lodestar/utils": "^1.20.0", - "@lodestar/validator": "^1.20.0", + "@lodestar/api": "^1.20.1", + "@lodestar/config": "^1.20.1", + "@lodestar/db": "^1.20.1", + "@lodestar/fork-choice": "^1.20.1", + "@lodestar/light-client": "^1.20.1", + "@lodestar/logger": "^1.20.1", + "@lodestar/params": "^1.20.1", + "@lodestar/reqresp": "^1.20.1", + "@lodestar/state-transition": "^1.20.1", + "@lodestar/types": "^1.20.1", + "@lodestar/utils": "^1.20.1", + "@lodestar/validator": "^1.20.1", "@multiformats/multiaddr": "^12.1.3", "c-kzg": "^2.1.2", "datastore-core": "^9.1.1", diff --git a/packages/cli/package.json b/packages/cli/package.json index 088e0e8b636e..4f27d030c735 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@chainsafe/lodestar", - "version": "1.20.0", + "version": "1.20.1", "description": "Command line interface for lodestar", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -63,17 +63,17 @@ "@libp2p/crypto": "^4.1.0", "@libp2p/peer-id": "^4.1.0", "@libp2p/peer-id-factory": "^4.1.0", - "@lodestar/api": "^1.20.0", - "@lodestar/beacon-node": "^1.20.0", - "@lodestar/config": "^1.20.0", - "@lodestar/db": "^1.20.0", - "@lodestar/light-client": "^1.20.0", - "@lodestar/logger": "^1.20.0", - "@lodestar/params": "^1.20.0", - "@lodestar/state-transition": "^1.20.0", - "@lodestar/types": "^1.20.0", - "@lodestar/utils": "^1.20.0", - "@lodestar/validator": "^1.20.0", + "@lodestar/api": "^1.20.1", + "@lodestar/beacon-node": "^1.20.1", + "@lodestar/config": "^1.20.1", + "@lodestar/db": "^1.20.1", + "@lodestar/light-client": "^1.20.1", + "@lodestar/logger": "^1.20.1", + "@lodestar/params": "^1.20.1", + "@lodestar/state-transition": "^1.20.1", + "@lodestar/types": "^1.20.1", + "@lodestar/utils": "^1.20.1", + "@lodestar/validator": "^1.20.1", "@multiformats/multiaddr": "^12.1.3", "deepmerge": "^4.3.1", "ethers": "^6.7.0", @@ -89,7 +89,7 @@ "yargs": "^17.7.1" }, "devDependencies": { - "@lodestar/test-utils": "^1.20.0", + "@lodestar/test-utils": "^1.20.1", "@types/debug": "^4.1.7", "@types/got": "^9.6.12", "@types/inquirer": "^9.0.3", diff --git a/packages/config/package.json b/packages/config/package.json index b773ae3e0eb1..f25d67bb687d 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -1,6 +1,6 @@ { "name": "@lodestar/config", - "version": "1.20.0", + "version": "1.20.1", "description": "Chain configuration required for lodestar", "author": "ChainSafe Systems", "license": "Apache-2.0", @@ -65,7 +65,7 @@ ], "dependencies": { "@chainsafe/ssz": "^0.15.1", - "@lodestar/params": "^1.20.0", - "@lodestar/types": "^1.20.0" + "@lodestar/params": "^1.20.1", + "@lodestar/types": "^1.20.1" } } diff --git a/packages/db/package.json b/packages/db/package.json index 4f496533a1fe..f883ff39291d 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -1,6 +1,6 @@ { "name": "@lodestar/db", - "version": "1.20.0", + "version": "1.20.1", "description": "DB modules of Lodestar", "author": "ChainSafe Systems", "homepage": "https://github.com/ChainSafe/lodestar#readme", @@ -36,12 +36,12 @@ }, "dependencies": { "@chainsafe/ssz": "^0.15.1", - "@lodestar/config": "^1.20.0", - "@lodestar/utils": "^1.20.0", + "@lodestar/config": "^1.20.1", + "@lodestar/utils": "^1.20.1", "classic-level": "^1.4.1", "it-all": "^3.0.4" }, "devDependencies": { - "@lodestar/logger": "^1.20.0" + "@lodestar/logger": "^1.20.1" } } diff --git a/packages/flare/package.json b/packages/flare/package.json index e464d2bd9f2b..b9a02da63383 100644 --- a/packages/flare/package.json +++ b/packages/flare/package.json @@ -1,6 +1,6 @@ { "name": "@lodestar/flare", - "version": "1.20.0", + "version": "1.20.1", "description": "Beacon chain debugging tool", "author": "ChainSafe Systems", "license": "Apache-2.0", @@ -60,12 +60,12 @@ "dependencies": { "@chainsafe/bls": "7.1.3", "@chainsafe/bls-keygen": "^0.4.0", - "@lodestar/api": "^1.20.0", - "@lodestar/config": "^1.20.0", - "@lodestar/params": "^1.20.0", - "@lodestar/state-transition": "^1.20.0", - "@lodestar/types": "^1.20.0", - "@lodestar/utils": "^1.20.0", + "@lodestar/api": "^1.20.1", + "@lodestar/config": "^1.20.1", + "@lodestar/params": "^1.20.1", + "@lodestar/state-transition": "^1.20.1", + "@lodestar/types": "^1.20.1", + "@lodestar/utils": "^1.20.1", "source-map-support": "^0.5.21", "yargs": "^17.7.1" }, diff --git a/packages/fork-choice/package.json b/packages/fork-choice/package.json index 43b67d179ecd..8352c751aa37 100644 --- a/packages/fork-choice/package.json +++ b/packages/fork-choice/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.20.0", + "version": "1.20.1", "type": "module", "exports": "./lib/index.js", "types": "./lib/index.d.ts", @@ -37,11 +37,11 @@ }, "dependencies": { "@chainsafe/ssz": "^0.15.1", - "@lodestar/config": "^1.20.0", - "@lodestar/params": "^1.20.0", - "@lodestar/state-transition": "^1.20.0", - "@lodestar/types": "^1.20.0", - "@lodestar/utils": "^1.20.0" + "@lodestar/config": "^1.20.1", + "@lodestar/params": "^1.20.1", + "@lodestar/state-transition": "^1.20.1", + "@lodestar/types": "^1.20.1", + "@lodestar/utils": "^1.20.1" }, "keywords": [ "ethereum", diff --git a/packages/light-client/package.json b/packages/light-client/package.json index 4ef321e271ce..68e8bf6a26dd 100644 --- a/packages/light-client/package.json +++ b/packages/light-client/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.20.0", + "version": "1.20.1", "type": "module", "exports": { ".": { @@ -76,11 +76,11 @@ "@chainsafe/bls": "7.1.3", "@chainsafe/persistent-merkle-tree": "^0.7.1", "@chainsafe/ssz": "^0.15.1", - "@lodestar/api": "^1.20.0", - "@lodestar/config": "^1.20.0", - "@lodestar/params": "^1.20.0", - "@lodestar/types": "^1.20.0", - "@lodestar/utils": "^1.20.0", + "@lodestar/api": "^1.20.1", + "@lodestar/config": "^1.20.1", + "@lodestar/params": "^1.20.1", + "@lodestar/types": "^1.20.1", + "@lodestar/utils": "^1.20.1", "mitt": "^3.0.0" }, "devDependencies": { diff --git a/packages/logger/package.json b/packages/logger/package.json index e8f3554a194d..15e33b579ba0 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.20.0", + "version": "1.20.1", "type": "module", "exports": { ".": { @@ -66,14 +66,14 @@ }, "types": "lib/index.d.ts", "dependencies": { - "@lodestar/utils": "^1.20.0", + "@lodestar/utils": "^1.20.1", "winston": "^3.8.2", "winston-daily-rotate-file": "^4.7.1", "winston-transport": "^4.5.0" }, "devDependencies": { "@chainsafe/threads": "^1.11.1", - "@lodestar/test-utils": "^1.20.0", + "@lodestar/test-utils": "^1.20.1", "@types/triple-beam": "^1.3.2", "triple-beam": "^1.3.0" }, diff --git a/packages/params/package.json b/packages/params/package.json index dcaf86cb9ef3..c8505204c42e 100644 --- a/packages/params/package.json +++ b/packages/params/package.json @@ -1,6 +1,6 @@ { "name": "@lodestar/params", - "version": "1.20.0", + "version": "1.20.1", "description": "Chain parameters required for lodestar", "author": "ChainSafe Systems", "license": "Apache-2.0", diff --git a/packages/prover/package.json b/packages/prover/package.json index 59accc218e64..577e3bc105e2 100644 --- a/packages/prover/package.json +++ b/packages/prover/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.20.0", + "version": "1.20.1", "type": "module", "exports": { ".": { @@ -69,13 +69,13 @@ "@ethereumjs/tx": "^4.1.2", "@ethereumjs/util": "^8.0.6", "@ethereumjs/vm": "^6.4.2", - "@lodestar/api": "^1.20.0", - "@lodestar/config": "^1.20.0", - "@lodestar/light-client": "^1.20.0", - "@lodestar/logger": "^1.20.0", - "@lodestar/params": "^1.20.0", - "@lodestar/types": "^1.20.0", - "@lodestar/utils": "^1.20.0", + "@lodestar/api": "^1.20.1", + "@lodestar/config": "^1.20.1", + "@lodestar/light-client": "^1.20.1", + "@lodestar/logger": "^1.20.1", + "@lodestar/params": "^1.20.1", + "@lodestar/types": "^1.20.1", + "@lodestar/utils": "^1.20.1", "ethereum-cryptography": "^2.0.0", "find-up": "^6.3.0", "http-proxy": "^1.18.1", @@ -84,7 +84,7 @@ "yargs": "^17.7.1" }, "devDependencies": { - "@lodestar/test-utils": "^1.20.0", + "@lodestar/test-utils": "^1.20.1", "@types/http-proxy": "^1.17.10", "@types/yargs": "^17.0.24", "axios": "^1.3.4", diff --git a/packages/reqresp/package.json b/packages/reqresp/package.json index 9540d8a4cfd4..8091e4f16ee7 100644 --- a/packages/reqresp/package.json +++ b/packages/reqresp/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.20.0", + "version": "1.20.1", "type": "module", "exports": { ".": { @@ -54,9 +54,9 @@ "dependencies": { "@chainsafe/fast-crc32c": "^4.1.1", "@libp2p/interface": "^1.3.0", - "@lodestar/config": "^1.20.0", - "@lodestar/params": "^1.20.0", - "@lodestar/utils": "^1.20.0", + "@lodestar/config": "^1.20.1", + "@lodestar/params": "^1.20.1", + "@lodestar/utils": "^1.20.1", "it-all": "^3.0.4", "it-pipe": "^3.0.1", "snappy": "^7.2.2", @@ -65,8 +65,8 @@ "uint8arraylist": "^2.4.7" }, "devDependencies": { - "@lodestar/logger": "^1.20.0", - "@lodestar/types": "^1.20.0", + "@lodestar/logger": "^1.20.1", + "@lodestar/types": "^1.20.1", "libp2p": "1.4.3" }, "peerDependencies": { diff --git a/packages/spec-test-util/package.json b/packages/spec-test-util/package.json index 248dce2eae3c..f5f590d55fa0 100644 --- a/packages/spec-test-util/package.json +++ b/packages/spec-test-util/package.json @@ -1,6 +1,6 @@ { "name": "@lodestar/spec-test-util", - "version": "1.20.0", + "version": "1.20.1", "description": "Spec test suite generator from yaml test files", "author": "ChainSafe Systems", "license": "Apache-2.0", @@ -62,7 +62,7 @@ "blockchain" ], "dependencies": { - "@lodestar/utils": "^1.20.0", + "@lodestar/utils": "^1.20.1", "axios": "^1.3.4", "rimraf": "^4.4.1", "snappyjs": "^0.7.0", diff --git a/packages/state-transition/package.json b/packages/state-transition/package.json index 4a5f97807e80..7dc542762cbf 100644 --- a/packages/state-transition/package.json +++ b/packages/state-transition/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.20.0", + "version": "1.20.1", "type": "module", "exports": { ".": { @@ -64,10 +64,10 @@ "@chainsafe/persistent-merkle-tree": "^0.7.1", "@chainsafe/persistent-ts": "^0.19.1", "@chainsafe/ssz": "^0.15.1", - "@lodestar/config": "^1.20.0", - "@lodestar/params": "^1.20.0", - "@lodestar/types": "^1.20.0", - "@lodestar/utils": "^1.20.0", + "@lodestar/config": "^1.20.1", + "@lodestar/params": "^1.20.1", + "@lodestar/types": "^1.20.1", + "@lodestar/utils": "^1.20.1", "bigint-buffer": "^1.1.5" }, "keywords": [ diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index ff913236d09c..45fb3d0e0909 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -1,7 +1,7 @@ { "name": "@lodestar/test-utils", "private": true, - "version": "1.20.0", + "version": "1.20.1", "description": "Test utilities reused across other packages", "author": "ChainSafe Systems", "license": "Apache-2.0", @@ -59,8 +59,8 @@ "dependencies": { "@chainsafe/bls": "7.1.3", "@chainsafe/bls-keystore": "^3.0.1", - "@lodestar/params": "^1.20.0", - "@lodestar/utils": "^1.20.0", + "@lodestar/params": "^1.20.1", + "@lodestar/utils": "^1.20.1", "axios": "^1.3.4", "testcontainers": "^10.2.1", "tmp": "^0.2.1", diff --git a/packages/types/package.json b/packages/types/package.json index 2918c3f6547f..6d69d501134f 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.20.0", + "version": "1.20.1", "type": "module", "exports": { ".": { @@ -71,7 +71,7 @@ "types": "lib/index.d.ts", "dependencies": { "@chainsafe/ssz": "^0.15.1", - "@lodestar/params": "^1.20.0", + "@lodestar/params": "^1.20.1", "ethereum-cryptography": "^2.0.0" }, "keywords": [ diff --git a/packages/utils/package.json b/packages/utils/package.json index 01aa35d7b990..8ad6f8b6b93b 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.20.0", + "version": "1.20.1", "type": "module", "exports": "./lib/index.js", "files": [ diff --git a/packages/validator/package.json b/packages/validator/package.json index 3c39e2f63bf1..c4929ffb6eca 100644 --- a/packages/validator/package.json +++ b/packages/validator/package.json @@ -1,6 +1,6 @@ { "name": "@lodestar/validator", - "version": "1.20.0", + "version": "1.20.1", "description": "A Typescript implementation of the validator client", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -47,17 +47,17 @@ "dependencies": { "@chainsafe/bls": "7.1.3", "@chainsafe/ssz": "^0.15.1", - "@lodestar/api": "^1.20.0", - "@lodestar/config": "^1.20.0", - "@lodestar/db": "^1.20.0", - "@lodestar/params": "^1.20.0", - "@lodestar/state-transition": "^1.20.0", - "@lodestar/types": "^1.20.0", - "@lodestar/utils": "^1.20.0", + "@lodestar/api": "^1.20.1", + "@lodestar/config": "^1.20.1", + "@lodestar/db": "^1.20.1", + "@lodestar/params": "^1.20.1", + "@lodestar/state-transition": "^1.20.1", + "@lodestar/types": "^1.20.1", + "@lodestar/utils": "^1.20.1", "strict-event-emitter-types": "^2.0.0" }, "devDependencies": { - "@lodestar/test-utils": "^1.20.0", + "@lodestar/test-utils": "^1.20.1", "bigint-buffer": "^1.1.5", "rimraf": "^4.4.1" } From e883d633d4072a82e152440444f5d9e71e7834f2 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 15 Jul 2024 16:19:52 +0100 Subject: [PATCH 2/5] fix: default to json if client accepts all media types (#6950) --- packages/api/src/utils/headers.ts | 7 ++++++- packages/api/src/utils/server/handler.ts | 2 +- packages/api/test/unit/utils/headers.test.ts | 10 +++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/api/src/utils/headers.ts b/packages/api/src/utils/headers.ts index 0646bb109fbb..5ef5346612fa 100644 --- a/packages/api/src/utils/headers.ts +++ b/packages/api/src/utils/headers.ts @@ -44,7 +44,12 @@ export function parseAcceptHeader(accept?: string, supported = SUPPORTED_MEDIA_T // Normalize here, using 1 as the default qvalue const quality = current.includes(";") ? current.split(";") : [current, "q=1"]; - const mediaType = quality[0].trim(); + let mediaType = quality[0].trim(); + + if (mediaType === "*/*") { + // Default to json if all media types are accepted + mediaType = MediaType.json; + } // If the mime type isn't acceptable, move on to the next entry if (!isSupportedMediaType(mediaType, supported)) { diff --git a/packages/api/src/utils/server/handler.ts b/packages/api/src/utils/server/handler.ts index 479212493885..a3cd9a43a56a 100644 --- a/packages/api/src/utils/server/handler.ts +++ b/packages/api/src/utils/server/handler.ts @@ -44,7 +44,7 @@ export function createFastifyHandler( if (definition.resp.isEmpty) { // Ignore Accept header, the response will be sent without body responseMediaType = null; - } else if (acceptHeader === undefined || acceptHeader === "*/*") { + } else if (acceptHeader === undefined) { // Default to json to not force user to set header, e.g. when using curl responseMediaType = MediaType.json; } else { diff --git a/packages/api/test/unit/utils/headers.test.ts b/packages/api/test/unit/utils/headers.test.ts index c3bcf6bc79c2..3416335b0dcd 100644 --- a/packages/api/test/unit/utils/headers.test.ts +++ b/packages/api/test/unit/utils/headers.test.ts @@ -5,13 +5,15 @@ describe("utils / headers", () => { describe("parseAcceptHeader", () => { const testCases: {header: string | undefined; expected: MediaType | null}[] = [ {header: undefined, expected: null}, - {header: "*/*", expected: null}, + {header: "*/*", expected: MediaType.json}, {header: "application/json", expected: MediaType.json}, {header: "application/octet-stream", expected: MediaType.ssz}, {header: "application/invalid", expected: null}, {header: "application/invalid;q=1,application/octet-stream;q=0.1", expected: MediaType.ssz}, {header: "application/octet-stream;q=0.5,application/json;q=1", expected: MediaType.json}, {header: "application/octet-stream;q=1,application/json;q=0.1", expected: MediaType.ssz}, + {header: "application/octet-stream;q=1,application/json;q=0.9", expected: MediaType.ssz}, + {header: "application/octet-stream;q=1,*/*;q=0.9", expected: MediaType.ssz}, {header: "application/octet-stream,application/json;q=0.1", expected: MediaType.ssz}, {header: "application/octet-stream;,application/json;q=0.1", expected: MediaType.json}, {header: "application/octet-stream;q=2,application/json;q=0.1", expected: MediaType.json}, @@ -20,6 +22,12 @@ describe("utils / headers", () => { {header: "application/octet-stream ; q=0.5 , application/json ; q=1", expected: MediaType.json}, {header: "application/octet-stream ; q=1 , application/json ; q=0.1", expected: MediaType.ssz}, {header: "application/octet-stream;q=1,application/json;q=0.1", expected: MediaType.ssz}, + { + // Default Accept header set by chrome browser + header: + "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", + expected: MediaType.json, + }, // The implementation is order dependent, however, RFC-9110 doesn't specify a preference. // The following tests serve to document the behavior at the time of implementation- not a From 4751dfe4e39cf8cd24af42ac8fdf0bb9da005b15 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 15 Jul 2024 20:57:45 +0100 Subject: [PATCH 3/5] fix: add workaround to fix compatibility with go-eth2-client (#6953) * fix: add workaround to fix compatibility with go-eth2-client * Skip more endpoints * Move comments around * Fix assertion --- packages/beacon-node/src/api/rest/base.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/beacon-node/src/api/rest/base.ts b/packages/beacon-node/src/api/rest/base.ts index 20439290e939..4f5d9284f91b 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -94,6 +94,18 @@ export class RestApiServer { const operationId = getOperationId(req); this.logger.debug(`Req ${req.id} ${req.ip} ${operationId}`); metrics?.requests.inc({operationId}); + + // 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(req.headers["user-agent"]?.split("/")[0] ?? "") + ) { + // Override Accept header to force server to return JSON + req.headers.accept = "application/json"; + } }); server.addHook("preHandler", async (req, _res) => { From 4696307aac94e50085bba6606e39a8c8598f69c5 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Mon, 15 Jul 2024 21:01:23 +0100 Subject: [PATCH 4/5] fix: expose metadata headers to scripts running in the browser (#6952) --- packages/api/src/utils/headers.ts | 6 ++++++ packages/api/src/utils/metadata.ts | 7 +++++++ .../test/e2e/api/impl/lightclient/endpoint.test.ts | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/api/src/utils/headers.ts b/packages/api/src/utils/headers.ts index 5ef5346612fa..5f3c6e3e1dfc 100644 --- a/packages/api/src/utils/headers.ts +++ b/packages/api/src/utils/headers.ts @@ -4,6 +4,12 @@ export enum HttpHeader { ContentType = "content-type", Accept = "accept", Authorization = "authorization", + /** + * Used to indicate which response headers should be made available to + * scripts running in the browser, in response to a cross-origin request. + * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers + */ + ExposeHeaders = "access-control-expose-headers", } export enum MediaType { diff --git a/packages/api/src/utils/metadata.ts b/packages/api/src/utils/metadata.ts index 8376113efec8..1eaa4132119f 100644 --- a/packages/api/src/utils/metadata.ts +++ b/packages/api/src/utils/metadata.ts @@ -5,6 +5,7 @@ import {StringType, ssz, stringType} from "@lodestar/types"; import {ResponseMetadataCodec} from "./types.js"; import {toBoolean} from "./serdes.js"; import {toForkName} from "./fork.js"; +import {HttpHeader} from "./headers.js"; export const VersionType = new ContainerType({ /** @@ -90,6 +91,7 @@ export const ExecutionOptimisticCodec: ResponseMetadataCodec ExecutionOptimisticType.fromJson(val), toHeadersObject: (val) => ({ [MetaHeader.ExecutionOptimistic]: val.executionOptimistic.toString(), + [HttpHeader.ExposeHeaders]: MetaHeader.ExecutionOptimistic, }), fromHeaders: (headers) => ({ executionOptimistic: toBoolean(headers.getOrDefault(MetaHeader.ExecutionOptimistic, "false")), @@ -101,6 +103,7 @@ export const VersionCodec: ResponseMetadataCodec = { fromJson: (val) => VersionType.fromJson(val), toHeadersObject: (val) => ({ [MetaHeader.Version]: val.version, + [HttpHeader.ExposeHeaders]: MetaHeader.Version, }), fromHeaders: (headers) => ({ version: toForkName(headers.getRequired(MetaHeader.Version)), @@ -113,6 +116,7 @@ export const ExecutionOptimisticAndVersionCodec: ResponseMetadataCodec ({ [MetaHeader.ExecutionOptimistic]: val.executionOptimistic.toString(), [MetaHeader.Version]: val.version, + [HttpHeader.ExposeHeaders]: [MetaHeader.ExecutionOptimistic, MetaHeader.Version].toString(), }), fromHeaders: (headers) => ({ executionOptimistic: toBoolean(headers.getOrDefault(MetaHeader.ExecutionOptimistic, "false")), @@ -126,6 +130,7 @@ export const ExecutionOptimisticAndFinalizedCodec: ResponseMetadataCodec ({ [MetaHeader.ExecutionOptimistic]: val.executionOptimistic.toString(), [MetaHeader.Finalized]: val.finalized.toString(), + [HttpHeader.ExposeHeaders]: [MetaHeader.ExecutionOptimistic, MetaHeader.Finalized].toString(), }), fromHeaders: (headers) => ({ executionOptimistic: toBoolean(headers.getOrDefault(MetaHeader.ExecutionOptimistic, "false")), @@ -141,6 +146,7 @@ export const ExecutionOptimisticFinalizedAndVersionCodec: ResponseMetadataCodec< [MetaHeader.ExecutionOptimistic]: val.executionOptimistic.toString(), [MetaHeader.Finalized]: val.finalized.toString(), [MetaHeader.Version]: val.version, + [HttpHeader.ExposeHeaders]: [MetaHeader.ExecutionOptimistic, MetaHeader.Finalized, MetaHeader.Version].toString(), }), fromHeaders: (headers) => ({ executionOptimistic: toBoolean(headers.getOrDefault(MetaHeader.ExecutionOptimistic, "false")), @@ -156,6 +162,7 @@ export const ExecutionOptimisticAndDependentRootCodec: ResponseMetadataCodec ({ [MetaHeader.ExecutionOptimistic]: val.executionOptimistic.toString(), [MetaHeader.DependentRoot]: val.dependentRoot, + [HttpHeader.ExposeHeaders]: [MetaHeader.ExecutionOptimistic, MetaHeader.DependentRoot].toString(), }), fromHeaders: (headers) => ({ executionOptimistic: toBoolean(headers.getOrDefault(MetaHeader.ExecutionOptimistic, "false")), diff --git a/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts b/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts index 0f13575a5ec4..afb4863dbe44 100644 --- a/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts +++ b/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts @@ -2,7 +2,7 @@ import {describe, it, beforeEach, afterEach, expect} from "vitest"; import bls from "@chainsafe/bls"; import {createBeaconConfig, ChainConfig} from "@lodestar/config"; import {chainConfig as chainConfigDef} from "@lodestar/config/default"; -import {getClient, routes} from "@lodestar/api"; +import {getClient, HttpHeader, routes} from "@lodestar/api"; import {sleep} from "@lodestar/utils"; import {ForkName, SYNC_COMMITTEE_SIZE} from "@lodestar/params"; import {Validator} from "@lodestar/validator"; @@ -102,6 +102,8 @@ describe("lightclient api", function () { expect(update.attestedHeader.beacon.slot).toBe(slot - 1); // version is set expect(res.meta().version).toBe(ForkName.altair); + // Ensure version header is made available to scripts running in the browser + expect(res.headers.get(HttpHeader.ExposeHeaders)?.includes("Eth-Consensus-Version")).toBe(true); }); it.skip("getLightClientFinalityUpdate()", async function () { From c1877bffb5b03af34d4853cbfa3e349883a5eedb Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Tue, 16 Jul 2024 00:16:27 +0100 Subject: [PATCH 5/5] fix: update user-agent check for go-eth2-client (#6958) * fix: update user-agent check for go-eth2-client * Remove confusing comment --- 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 4f5d9284f91b..5f191bf76beb 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -101,7 +101,7 @@ export class RestApiServer { // 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(req.headers["user-agent"]?.split("/")[0] ?? "") + ["go-eth2-client", "Go-http-client", "Vouch"].includes(req.headers["user-agent"]?.split("/")[0] ?? "") ) { // Override Accept header to force server to return JSON req.headers.accept = "application/json";