Add TODO comments for missing implementations.

Change default REST port to use 5052 (Lighthouse).
Add missing checks for maximum amount of validator ids.
This commit is contained in:
cheatfate 2021-03-29 13:59:39 +03:00 committed by zah
parent 2cf0d3d831
commit 80e79aef97
5 changed files with 25 additions and 6 deletions

View File

@ -287,7 +287,7 @@ type
name: "rest" }: bool
restPort* {.
defaultValue: defaultEth2RpcPort
defaultValue: DefaultEth2RestPort
desc: "HTTP port for the REST service"
name: "rest-port" }: Port

View File

@ -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

View File

@ -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():

View File

@ -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():

View File

@ -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}"