From c56cb0a48517076b0827e85f0d8552feda963d14 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Sun, 4 Apr 2021 12:48:44 +0300 Subject: [PATCH] Fix /api/eth/v1/node/peers arguments handling. Fix maximum Epoch handling. --- beacon_chain/rpc/beacon_rest_api.nim | 6 +++++- beacon_chain/rpc/node_rest_api.nim | 16 ++++++++-------- beacon_chain/rpc/validator_rest_api.nim | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/beacon_chain/rpc/beacon_rest_api.nim b/beacon_chain/rpc/beacon_rest_api.nim index 7dc2d281e..4baef57f6 100644 --- a/beacon_chain/rpc/beacon_rest_api.nim +++ b/beacon_chain/rpc/beacon_rest_api.nim @@ -487,7 +487,11 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) = if repoch.isErr(): return RestApiResponse.jsonError(Http400, "Invalid epoch value", $repoch.error()) - some(repoch.get()) + let res = repoch.get() + if res > MaxEpoch: + return RestApiResponse.jsonError(Http400, "Requesting epoch for " & + "which slot would overflow") + some(res) else: none[Epoch]() let vindex = diff --git a/beacon_chain/rpc/node_rest_api.nim b/beacon_chain/rpc/node_rest_api.nim index 44a0c8d37..d44856d24 100644 --- a/beacon_chain/rpc/node_rest_api.nim +++ b/beacon_chain/rpc/node_rest_api.nim @@ -157,15 +157,15 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) = ) router.api(MethodGet, "/api/eth/v1/node/peers") do ( - states: seq[PeerStateKind], - directions: seq[PeerDirectKind]) -> RestApiResponse: + state: seq[PeerStateKind], + direction: seq[PeerDirectKind]) -> RestApiResponse: let connectionMask = block: - if states.isErr(): + if state.isErr(): return RestApiResponse.jsonError(Http400, "Invalid state value(s)", - $states.error()) - let sres = validateState(states.get()) + $state.error()) + let sres = validateState(state.get()) if sres.isErr(): return RestApiResponse.jsonError(Http400, "Invalid state value(s)", @@ -173,11 +173,11 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) = sres.get() let directionMask = block: - if directions.isErr(): + if direction.isErr(): return RestApiResponse.jsonError(Http400, "Invalid direction value(s)", - $directions.error()) - let dres = validateDirection(directions.get()) + $direction.error()) + let dres = validateDirection(direction.get()) if dres.isErr(): return RestApiResponse.jsonError(Http400, "Invalid direction value(s)", diff --git a/beacon_chain/rpc/validator_rest_api.nim b/beacon_chain/rpc/validator_rest_api.nim index 317f9e36c..467454363 100644 --- a/beacon_chain/rpc/validator_rest_api.nim +++ b/beacon_chain/rpc/validator_rest_api.nim @@ -59,7 +59,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) = return RestApiResponse.jsonError(Http400, "Incorrect epoch value", $epoch.error()) let res = epoch.get() - if res >= MaxEpoch: + if res > MaxEpoch: return RestApiResponse.jsonError(Http400, "Requesting epoch for " & "which slot would overflow") res @@ -129,7 +129,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) = return RestApiResponse.jsonError(Http400, "Incorrect epoch value", $epoch.error()) let res = epoch.get() - if res >= MaxEpoch: + if res > MaxEpoch: return RestApiResponse.jsonError(Http400, "Requesting epoch for " & "which slot would overflow") res