From 6f10e651ff25f7ba85b05aed60b2b1198c56d270 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 4 Feb 2022 14:26:27 +0100 Subject: [PATCH] rest: fix ssz preference string (#3357) --- beacon_chain/spec/eth2_apis/rest_beacon_calls.nim | 12 ++++++++---- beacon_chain/spec/eth2_apis/rest_debug_calls.nim | 12 ++++++++---- beacon_chain/spec/eth2_apis/rest_types.nim | 3 +++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim b/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim index 6a89cca91..4369196ba 100644 --- a/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim +++ b/beacon_chain/spec/eth2_apis/rest_beacon_calls.nim @@ -115,7 +115,7 @@ proc publishBlock*(body: altair.SignedBeaconBlock): RestPlainResponse {. proc getBlockPlain*(block_id: BlockIdent): RestPlainResponse {. rest, endpoint: "/eth/v1/beacon/blocks/{block_id}", - accept: "application/octet-stream,application-json;q=0.9", + accept: preferSSZ, meth: MethodGet.} ## https://ethereum.github.io/beacon-APIs/#/Beacon/getBlock @@ -138,7 +138,9 @@ proc raiseUnknownStatusError(resp: RestPlainResponse) raise newException(RestError, msg) proc getBlock*(client: RestClientRef, block_id: BlockIdent, - restAccept = ""): Future[ForkedSignedBeaconBlock] {.async.} = + restAccept = preferSSZ): Future[ForkedSignedBeaconBlock] {.async.} = + # TODO restAccept should be "" by default, but for some reason that doesn't + # work let resp = if len(restAccept) > 0: await client.getBlockPlain(block_id, restAcceptType = restAccept) @@ -176,16 +178,18 @@ proc getBlock*(client: RestClientRef, block_id: BlockIdent, proc getBlockV2Plain*(block_id: BlockIdent): RestPlainResponse {. rest, endpoint: "/eth/v2/beacon/blocks/{block_id}", - accept: "application/octet-stream,application-json;q=0.9", + accept: preferSSZ, meth: MethodGet.} ## https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockV2 proc getBlockV2*(client: RestClientRef, block_id: BlockIdent, cfg: RuntimeConfig, - restAccept = ""): Future[Option[ForkedSignedBeaconBlock]] {. + restAccept = preferSSZ): Future[Option[ForkedSignedBeaconBlock]] {. async.} = # Return the asked-for block, or None in case 404 is returned from the server. # Raises on other errors + # TODO restAccept should be "" by default, but for some reason that doesn't + # work let resp = if len(restAccept) > 0: await client.getBlockV2Plain(block_id, restAcceptType = restAccept) diff --git a/beacon_chain/spec/eth2_apis/rest_debug_calls.nim b/beacon_chain/spec/eth2_apis/rest_debug_calls.nim index 3486c64fd..9758a2040 100644 --- a/beacon_chain/spec/eth2_apis/rest_debug_calls.nim +++ b/beacon_chain/spec/eth2_apis/rest_debug_calls.nim @@ -15,12 +15,14 @@ export chronos, client, rest_types, eth2_rest_serialization proc getStatePlain*(state_id: StateIdent): RestPlainResponse {. rest, endpoint: "/eth/v1/debug/beacon/states/{state_id}", - accept: "application/octet-stream,application-json;q=0.9", + accept: preferSSZ, meth: MethodGet.} ## https://ethereum.github.io/beacon-APIs/#/Beacon/getState proc getState*(client: RestClientRef, state_id: StateIdent, - restAccept = ""): Future[phase0.BeaconState] {.async.} = + restAccept = preferSSZ): Future[phase0.BeaconState] {.async.} = + # TODO restAccept should be "" by default, but for some reason that doesn't + # work let resp = if len(restAccept) > 0: await client.getStatePlain(state_id, restAcceptType = restAccept) @@ -73,15 +75,17 @@ proc getDebugChainHeads*(): RestResponse[GetDebugChainHeadsResponse] {. proc getStateV2Plain*(state_id: StateIdent): RestPlainResponse {. rest, endpoint: "/eth/v2/debug/beacon/states/{state_id}", - accept: "application/octet-stream,application-json;q=0.9", + accept: preferSSZ, meth: MethodGet.} ## https://ethereum.github.io/beacon-APIs/#/Debug/getStateV2 proc getStateV2*(client: RestClientRef, state_id: StateIdent, cfg: RuntimeConfig, - restAccept = ""): Future[ref ForkedHashedBeaconState] {.async.} = + restAccept = preferSSZ): Future[ref ForkedHashedBeaconState] {.async.} = # nil is returned if the state is not found due to a 404 - `ref` is needed # to manage stack usage + # TODO restAccept should be "" by default, but for some reason that doesn't + # work let resp = if len(restAccept) > 0: await client.getStateV2Plain(state_id, restAcceptType = restAccept) diff --git a/beacon_chain/spec/eth2_apis/rest_types.nim b/beacon_chain/spec/eth2_apis/rest_types.nim index 677bf8c32..4e78f45a2 100644 --- a/beacon_chain/spec/eth2_apis/rest_types.nim +++ b/beacon_chain/spec/eth2_apis/rest_types.nim @@ -26,6 +26,9 @@ const # https://github.com/ethereum/eth2.0-APIs/blob/master/apis/beacon/states/validators.yaml#L17 MaximumValidatorIds* = 16384 +const + preferSSZ* = "application/octet-stream,application/json;q=0.9" + type EventTopic* {.pure.} = enum Head, Block, Attestation, VoluntaryExit, FinalizedCheckpoint, ChainReorg,