diff --git a/packages/beacon-node/src/api/rest/base.ts b/packages/beacon-node/src/api/rest/base.ts index 44746f89502a..323626051f17 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -138,18 +138,6 @@ 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 - !["produceBlockV3", "getBlockV2", "getStateV2"].includes(operationId) && - // Only Vouch seems to override default header - ["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"; - } }); server.addHook("preHandler", async (req, _res) => { diff --git a/packages/cli/src/networks/index.ts b/packages/cli/src/networks/index.ts index f1b31807dc0c..188e3bfcff0d 100644 --- a/packages/cli/src/networks/index.ts +++ b/packages/cli/src/networks/index.ts @@ -1,6 +1,6 @@ import fs from "node:fs"; import {ENR} from "@chainsafe/enr"; -import {HttpHeader, MediaType, WireFormat, getClient} from "@lodestar/api"; +import {WireFormat, getClient} from "@lodestar/api"; import {getStateSlotFromBytes} from "@lodestar/beacon-node"; import {ChainConfig, ChainForkConfig} from "@lodestar/config"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; @@ -10,7 +10,7 @@ import { getLatestBlockRoot, loadState, } from "@lodestar/state-transition"; -import {Slot} from "@lodestar/types"; +import {Slot, sszTypesFor} from "@lodestar/types"; import {Checkpoint} from "@lodestar/types/phase0"; import {Logger, callFnWhenAwait, formatBytes, fromHex} from "@lodestar/utils"; import {fetch} from "@lodestar/utils"; @@ -173,38 +173,26 @@ export async function fetchWeakSubjectivityState( } // getStateV2 should be available for all forks including phase0 - const getStatePromise = api.debug.getStateV2( - {stateId}, - { - responseWireFormat: WireFormat.ssz, - headers: { - // Set Accept header explicitly to fix Checkpointz incompatibility - // See https://github.com/ethpandaops/checkpointz/issues/165 - [HttpHeader.Accept]: MediaType.ssz, - }, - } - ); - - const wsStateBytes = await callFnWhenAwait( + const getStatePromise = api.debug.getStateV2({stateId}, {responseWireFormat: WireFormat.ssz}); + + const {wsStateBytes, fork} = await callFnWhenAwait( getStatePromise, () => logger.info("Download in progress, please wait..."), GET_STATE_LOG_INTERVAL ).then((res) => { - return res.ssz(); + return {wsStateBytes: res.ssz(), fork: res.meta().version}; }); const wsSlot = getStateSlotFromBytes(wsStateBytes); const logData = {stateId, size: formatBytes(wsStateBytes.length)}; logger.info("Download completed", typeof stateId === "number" ? logData : {...logData, slot: wsSlot}); - // It should not be required to get fork type from bytes but Checkpointz does not return - // Eth-Consensus-Version header, see https://github.com/ethpandaops/checkpointz/issues/164 + let wsState: BeaconStateAllForks; if (lastDbState && lastDbValidatorsBytes) { // use lastDbState to load wsState if possible to share the same state tree wsState = loadState(config, lastDbState, wsStateBytes, lastDbValidatorsBytes).state; } else { - const stateType = config.getForkTypes(wsSlot).BeaconState; - wsState = stateType.deserializeToViewDU(wsStateBytes); + wsState = sszTypesFor(fork).BeaconState.deserializeToViewDU(wsStateBytes); } return {