-
-
Notifications
You must be signed in to change notification settings - Fork 416
feat: add POST endpoints for validators and validator_balances #6655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import {ContainerType} from "@chainsafe/ssz"; | |||||||||
| import {phase0, CommitteeIndex, Slot, ValidatorIndex, Epoch, Root, ssz, StringType, RootHex} from "@lodestar/types"; | ||||||||||
| import {ApiClientResponse} from "../../../interfaces.js"; | ||||||||||
| import {HttpStatusCode} from "../../../utils/client/httpStatusCode.js"; | ||||||||||
| import {fromU64Str, toU64Str} from "../../../utils/serdes.js"; | ||||||||||
| import { | ||||||||||
| RoutesData, | ||||||||||
| ReturnTypes, | ||||||||||
|
|
@@ -190,6 +191,30 @@ export type Api = { | |||||||||
| > | ||||||||||
| >; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Get validators from state | ||||||||||
| * Returns filterable list of validators with their balance, status and index. | ||||||||||
| * @param stateId State identifier. | ||||||||||
| * Can be one of: "head" (canonical head in node's view), "genesis", "finalized", "justified", \<slot\>, \<hex encoded stateRoot with 0x prefix\>. | ||||||||||
| * @param id Either hex encoded public key (with 0x prefix) or validator index | ||||||||||
| * @param status [Validator status specification](https://hackmd.io/ofFJ5gOmQpu1jjHilHbdQQ) | ||||||||||
| */ | ||||||||||
| postStateValidators( | ||||||||||
| stateId: StateId, | ||||||||||
| filters?: ValidatorFilters | ||||||||||
| ): Promise< | ||||||||||
| ApiClientResponse< | ||||||||||
| { | ||||||||||
| [HttpStatusCode.OK]: { | ||||||||||
| data: ValidatorResponse[]; | ||||||||||
| executionOptimistic: ExecutionOptimistic; | ||||||||||
| finalized: Finalized; | ||||||||||
| }; | ||||||||||
| }, | ||||||||||
| HttpStatusCode.BAD_REQUEST | HttpStatusCode.NOT_FOUND | ||||||||||
| > | ||||||||||
| >; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Get validator from state by id | ||||||||||
| * Returns validator specified by state and id or public key along with status and balance. | ||||||||||
|
|
@@ -236,6 +261,29 @@ export type Api = { | |||||||||
| > | ||||||||||
| >; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Get validator balances from state | ||||||||||
| * Returns filterable list of validator balances. | ||||||||||
| * @param stateId State identifier. | ||||||||||
| * Can be one of: "head" (canonical head in node's view), "genesis", "finalized", "justified", \<slot\>, \<hex encoded stateRoot with 0x prefix\>. | ||||||||||
| * @param id Either hex encoded public key (with 0x prefix) or validator index | ||||||||||
| */ | ||||||||||
| postStateValidatorBalances( | ||||||||||
| stateId: StateId, | ||||||||||
| indices?: ValidatorId[] | ||||||||||
| ): Promise< | ||||||||||
| ApiClientResponse< | ||||||||||
| { | ||||||||||
| [HttpStatusCode.OK]: { | ||||||||||
| data: ValidatorBalance[]; | ||||||||||
| executionOptimistic: ExecutionOptimistic; | ||||||||||
| finalized: Finalized; | ||||||||||
| }; | ||||||||||
| }, | ||||||||||
| HttpStatusCode.BAD_REQUEST | ||||||||||
| > | ||||||||||
| >; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Get all committees for a state. | ||||||||||
| * Retrieves the committees for the given state. | ||||||||||
|
|
@@ -290,7 +338,9 @@ export const routesData: RoutesData<Api> = { | |||||||||
| getStateRandao: {url: "/eth/v1/beacon/states/{state_id}/randao", method: "GET"}, | ||||||||||
| getStateValidator: {url: "/eth/v1/beacon/states/{state_id}/validators/{validator_id}", method: "GET"}, | ||||||||||
| getStateValidators: {url: "/eth/v1/beacon/states/{state_id}/validators", method: "GET"}, | ||||||||||
| postStateValidators: {url: "/eth/v1/beacon/states/{state_id}/validators", method: "POST"}, | ||||||||||
| getStateValidatorBalances: {url: "/eth/v1/beacon/states/{state_id}/validator_balances", method: "GET"}, | ||||||||||
| postStateValidatorBalances: {url: "/eth/v1/beacon/states/{state_id}/validator_balances", method: "POST"}, | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||||||||||
|
|
@@ -306,7 +356,9 @@ export type ReqTypes = { | |||||||||
| getStateRandao: {params: {state_id: StateId}; query: {epoch?: number}}; | ||||||||||
| getStateValidator: {params: {state_id: StateId; validator_id: ValidatorId}}; | ||||||||||
| getStateValidators: {params: {state_id: StateId}; query: {id?: ValidatorId[]; status?: ValidatorStatus[]}}; | ||||||||||
| postStateValidators: {params: {state_id: StateId}; body: {ids?: string[]; statuses?: ValidatorStatus[]}}; | ||||||||||
| getStateValidatorBalances: {params: {state_id: StateId}; query: {id?: ValidatorId[]}}; | ||||||||||
| postStateValidatorBalances: {params: {state_id: StateId}; body?: string[]}; | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| export function getReqSerializers(): ReqSerializers<Api, ReqTypes> { | ||||||||||
|
|
@@ -365,6 +417,27 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> { | |||||||||
| }, | ||||||||||
| }, | ||||||||||
|
|
||||||||||
| postStateValidators: { | ||||||||||
| writeReq: (state_id, filters) => ({ | ||||||||||
| params: {state_id}, | ||||||||||
| body: { | ||||||||||
| ids: filters?.id?.map((id) => (typeof id === "string" ? id : toU64Str(id))), | ||||||||||
| statuses: filters?.status, | ||||||||||
| }, | ||||||||||
| }), | ||||||||||
| parseReq: ({params, body}) => [ | ||||||||||
| params.state_id, | ||||||||||
| { | ||||||||||
| id: body.ids?.map((id) => (typeof id === "string" && id.startsWith("0x") ? id : fromU64Str(id))), | ||||||||||
| status: body.statuses, | ||||||||||
| }, | ||||||||||
| ], | ||||||||||
| schema: { | ||||||||||
| params: {state_id: Schema.StringRequired}, | ||||||||||
| body: Schema.Object, | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
|
|
||||||||||
| getStateValidatorBalances: { | ||||||||||
| writeReq: (state_id, id) => ({params: {state_id}, query: {id}}), | ||||||||||
| parseReq: ({params, query}) => [params.state_id, query.id], | ||||||||||
|
|
@@ -373,6 +446,21 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> { | |||||||||
| query: {id: Schema.UintOrStringArray}, | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
|
|
||||||||||
| postStateValidatorBalances: { | ||||||||||
| writeReq: (state_id, ids) => ({ | ||||||||||
| params: {state_id}, | ||||||||||
| body: ids?.map((id) => (typeof id === "string" ? id : toU64Str(id))) || [], | ||||||||||
| }), | ||||||||||
| parseReq: ({params, body}) => [ | ||||||||||
| params.state_id, | ||||||||||
| body?.map((id) => (typeof id === "string" && id.startsWith("0x") ? id : fromU64Str(id))), | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, if we use string for validator index inside Lodestar it is likely unintended and should be fixed. And even though the type of It only has to be a stringified number over the wire apis/beacon/states/validators.yaml#L115-L120 ids:
type: array
uniqueItems: true
items:
description: "Either hex encoded public key (any bytes48 with 0x prefix) or validator index"
type: string # <--
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indices store strictly uses type lodestar/packages/validator/src/services/indices.ts Lines 42 to 45 in 5ccae1c
|
||||||||||
| ], | ||||||||||
| schema: { | ||||||||||
| params: {state_id: Schema.StringRequired}, | ||||||||||
| body: Schema.UintOrStringArray, | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| }; | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -435,8 +523,10 @@ export function getReturnTypes(): ReturnTypes<Api> { | |||||||||
| getStateRandao: WithFinalized(ContainerDataExecutionOptimistic(RandaoContainer)), | ||||||||||
| getStateFinalityCheckpoints: WithFinalized(ContainerDataExecutionOptimistic(FinalityCheckpoints)), | ||||||||||
| getStateValidators: WithFinalized(ContainerDataExecutionOptimistic(ArrayOf(ValidatorResponse))), | ||||||||||
| postStateValidators: WithFinalized(ContainerDataExecutionOptimistic(ArrayOf(ValidatorResponse))), | ||||||||||
| getStateValidator: WithFinalized(ContainerDataExecutionOptimistic(ValidatorResponse)), | ||||||||||
| getStateValidatorBalances: WithFinalized(ContainerDataExecutionOptimistic(ArrayOf(ValidatorBalance))), | ||||||||||
| postStateValidatorBalances: WithFinalized(ContainerDataExecutionOptimistic(ArrayOf(ValidatorBalance))), | ||||||||||
| getEpochCommittees: WithFinalized(ContainerDataExecutionOptimistic(ArrayOf(EpochCommitteeResponse))), | ||||||||||
| getEpochSyncCommittees: WithFinalized(ContainerDataExecutionOptimistic(EpochSyncCommitteesResponse)), | ||||||||||
| }; | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.