From 80e79aef97b3b7a8d852107a67d2bfb57765c34d Mon Sep 17 00:00:00 2001 From: cheatfate Date: Mon, 29 Mar 2021 13:59:39 +0300 Subject: [PATCH] Add TODO comments for missing implementations. Change default REST port to use 5052 (Lighthouse). Add missing checks for maximum amount of validator ids. --- beacon_chain/conf.nim | 2 +- beacon_chain/rpc/beacon_rest_api.nim | 19 +++++++++++++++++-- beacon_chain/rpc/event_rest_api.nim | 3 ++- beacon_chain/rpc/validator_rest_api.nim | 4 ++-- beacon_chain/spec/network.nim | 3 +++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index c8c50c639..b47c609c7 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -287,7 +287,7 @@ type name: "rest" }: bool restPort* {. - defaultValue: defaultEth2RpcPort + defaultValue: DefaultEth2RestPort desc: "HTTP port for the REST service" name: "rest-port" }: Port diff --git a/beacon_chain/rpc/beacon_rest_api.nim b/beacon_chain/rpc/beacon_rest_api.nim index deaa8582b..49cb6eeab 100644 --- a/beacon_chain/rpc/beacon_rest_api.nim +++ b/beacon_chain/rpc/beacon_rest_api.nim @@ -18,6 +18,11 @@ import logScope: topics = "rest_beaconapi" +const + # https://github.com/ethereum/eth2.0-APIs/blob/master/apis/beacon/states/validator_balances.yaml#L17 + # https://github.com/ethereum/eth2.0-APIs/blob/master/apis/beacon/states/validators.yaml#L17 + MaximumValidatorIds = 30 + type ValidatorTuple = tuple index: ValidatorIndex @@ -212,7 +217,11 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) = if id.isErr(): return RestApiResponse.jsonError(Http400, "Invalid validator identifier(s)") - id.get() + let ires = id.get() + if len(ires) > MaximumValidatorIds: + return RestApiResponse.jsonError(Http400, + "Maximum number of id values exceeded") + ires let validatorsMask = block: @@ -350,7 +359,11 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) = if id.isErr(): return RestApiResponse.jsonError(Http400, "Invalid validator identifier(s)") - id.get() + let ires = id.get() + if len(ires) > MaximumValidatorIds: + return RestApiResponse.jsonError(Http400, + "Maximum number of id values exceeded") + ires let (keySet, indexSet) = block: var res1: HashSet[ValidatorPubKey] @@ -471,6 +484,8 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) = # https://ethereum.github.io/eth2.0-APIs/#/Beacon/getBlockHeaders router.api(MethodGet, "/api/eth/v1/beacon/headers") do ( slot: Option[Slot], parent_root: Option[Eth2Digest]) -> RestApiResponse: + # TODO (cheatfate): This call could not be implemented because structure + # of database do not allow to query blocks by `parent_root`. return RestApiResponse.jsonError(Http500, "Not implemented yet") # https://ethereum.github.io/eth2.0-APIs/#/Beacon/getBlockHeader diff --git a/beacon_chain/rpc/event_rest_api.nim b/beacon_chain/rpc/event_rest_api.nim index 83e21896f..2a694b985 100644 --- a/beacon_chain/rpc/event_rest_api.nim +++ b/beacon_chain/rpc/event_rest_api.nim @@ -51,7 +51,8 @@ proc validateEventTopics(events: seq[EventTopic]): Result[EventTopics, proc installEventApiHandlers*(router: var RestRouter, node: BeaconNode) = router.api(MethodGet, "/api/eth/v1/events") do ( topics: seq[EventTopic]) -> RestApiResponse: - + # TODO (cheatfate): This call is not fully implemented yet, because there + # missing infrastructure to raise/catch global events (eventbus). let eventTopics = block: if topics.isErr(): diff --git a/beacon_chain/rpc/validator_rest_api.nim b/beacon_chain/rpc/validator_rest_api.nim index c5bdb00bf..df2325c6d 100644 --- a/beacon_chain/rpc/validator_rest_api.nim +++ b/beacon_chain/rpc/validator_rest_api.nim @@ -335,8 +335,8 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) = router.api(MethodPost, "/api/eth/v1/validator/beacon_committee_subscriptions") do ( contentBody: Option[ContentBody]) -> RestApiResponse: - # TODO: This call could not be finished because more complex peer manager - # is needed. + # TODO (cheatfate): This call could not be finished because more complex + # peer manager implementation needed. let requests = block: if contentBody.isNone(): diff --git a/beacon_chain/spec/network.nim b/beacon_chain/spec/network.nim index cdcb1d009..ea1c7ccdb 100644 --- a/beacon_chain/spec/network.nim +++ b/beacon_chain/spec/network.nim @@ -30,6 +30,9 @@ const # This is not part of the spec yet! Keep in sync with BASE_RPC_PORT defaultEth2RpcPort* = 9190 + # This is not part of the spec! But its port which uses Lighthouse + DefaultEth2RestPort* = 5052 + func getBeaconBlocksTopic*(forkDigest: ForkDigest): string = try: &"/eth2/{$forkDigest}/{topicBeaconBlocksSuffix}"