Skip to content
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

Various fixes for VC and BN REST server. #4673

Merged
merged 11 commits into from
Mar 3, 2023
3 changes: 2 additions & 1 deletion beacon_chain/rpc/rest_validator_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
InvalidSubscriptionRequestValueError,
$dres.error())
dres.get()
if node.isSynced(node.dag.head) != SyncStatus.synced:

if node.isSynced(node.dag.head) == SyncStatus.unsynced:
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)

let
Expand Down
13 changes: 13 additions & 0 deletions beacon_chain/spec/eth2_apis/rest_beacon_calls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ proc getStateValidators*(state_id: StateIdent,
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/getStateValidators

proc getStateValidatorsPlain*(
state_id: StateIdent,
id: seq[ValidatorIdent]
): RestPlainResponse {.
rest, endpoint: "/eth/v1/beacon/states/{state_id}/validators",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/getStateValidators

proc getStateValidator*(state_id: StateIdent,
validator_id: ValidatorIdent
): RestResponse[GetStateValidatorResponse] {.
Expand Down Expand Up @@ -224,6 +232,11 @@ proc getBlockRoot*(block_id: BlockIdent): RestResponse[GetBlockRootResponse] {.
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockRoot

proc getBlockRootPlain*(block_id: BlockIdent): RestPlainResponse {.
rest, endpoint: "/eth/v1/beacon/blocks/{block_id}/root",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockRoot

proc getBlockAttestations*(block_id: BlockIdent
): RestResponse[GetBlockAttestationsResponse] {.
rest, endpoint: "/eth/v1/beacon/blocks/{block_id}/attestations",
Expand Down
4 changes: 4 additions & 0 deletions beacon_chain/spec/eth2_apis/rest_config_calls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ proc getForkSchedule*(): RestResponse[GetForkScheduleResponse] {.
rest, endpoint: "/eth/v1/config/fork_schedule", meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Config/getForkSchedule

proc getForkSchedulePlain*(): RestPlainResponse {.
rest, endpoint: "/eth/v1/config/fork_schedule", meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Config/getForkSchedule

proc getSpec*(): RestResponse[GetSpecResponse] {.
rest, endpoint: "/eth/v1/config/spec", meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Config/getSpec
Expand Down
143 changes: 113 additions & 30 deletions beacon_chain/spec/eth2_apis/rest_validator_calls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,155 @@ import

export chronos, client, rest_types, eth2_rest_serialization

proc getAttesterDuties*(epoch: Epoch,
body: seq[ValidatorIndex]
): RestResponse[GetAttesterDutiesResponse] {.
proc getAttesterDuties*(
epoch: Epoch,
body: seq[ValidatorIndex]
): RestResponse[GetAttesterDutiesResponse] {.
rest, endpoint: "/eth/v1/validator/duties/attester/{epoch}",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getAttesterDuties

proc getProposerDuties*(epoch: Epoch): RestResponse[GetProposerDutiesResponse] {.
proc getAttesterDutiesPlain*(
epoch: Epoch,
body: seq[ValidatorIndex]
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/duties/attester/{epoch}",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getAttesterDuties

proc getProposerDuties*(
epoch: Epoch
): RestResponse[GetProposerDutiesResponse] {.
rest, endpoint: "/eth/v1/validator/duties/proposer/{epoch}",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getProposerDuties

proc getProposerDutiesPlain*(
epoch: Epoch
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/duties/proposer/{epoch}",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getProposerDuties

proc getSyncCommitteeDuties*(epoch: Epoch,
body: seq[ValidatorIndex]
): RestResponse[GetSyncCommitteeDutiesResponse] {.
proc getSyncCommitteeDuties*(
epoch: Epoch,
body: seq[ValidatorIndex]
): RestResponse[GetSyncCommitteeDutiesResponse] {.
rest, endpoint: "/eth/v1/validator/duties/sync/{epoch}",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getSyncCommitteeDuties

proc produceBlockV2*(slot: Slot, randao_reveal: ValidatorSig,
graffiti: GraffitiBytes
): RestResponse[ProduceBlockResponseV2] {.
rest, endpoint: "/eth/v2/validator/blocks/{slot}",
meth: MethodGet.}
proc getSyncCommitteeDutiesPlain*(
epoch: Epoch,
body: seq[ValidatorIndex]
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/duties/sync/{epoch}",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getSyncCommitteeDuties

proc produceBlockV2*(
slot: Slot,
randao_reveal: ValidatorSig,
graffiti: GraffitiBytes
): RestResponse[ProduceBlockResponseV2] {.
rest, endpoint: "/eth/v2/validator/blocks/{slot}",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/produceBlockV2

proc produceBlockV2Plain*(
slot: Slot,
randao_reveal: ValidatorSig,
graffiti: GraffitiBytes
): RestPlainResponse {.
rest, endpoint: "/eth/v2/validator/blocks/{slot}",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/produceBlockV2

proc produceBlindedBlock*(slot: Slot, randao_reveal: ValidatorSig,
graffiti: GraffitiBytes
): RestResponse[ProduceBlindedBlockResponse] {.
rest, endpoint: "/eth/v1/validator/blinded_blocks/{slot}",
meth: MethodGet.}
proc produceBlindedBlock*(
slot: Slot,
randao_reveal: ValidatorSig,
graffiti: GraffitiBytes
): RestResponse[ProduceBlindedBlockResponse] {.
rest, endpoint: "/eth/v1/validator/blinded_blocks/{slot}",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/produceBlindedBlock

proc produceBlindedBlockPlain*(
slot: Slot,
randao_reveal: ValidatorSig,
graffiti: GraffitiBytes
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/blinded_blocks/{slot}",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/produceBlindedBlock

proc produceAttestationData*(slot: Slot,
committee_index: CommitteeIndex
): RestResponse[ProduceAttestationDataResponse] {.
proc produceAttestationData*(
slot: Slot,
committee_index: CommitteeIndex
): RestResponse[ProduceAttestationDataResponse] {.
rest, endpoint: "/eth/v1/validator/attestation_data",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/produceAttestationData

proc produceAttestationDataPlain*(
slot: Slot,
committee_index: CommitteeIndex
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/attestation_data",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/produceAttestationData

proc getAggregatedAttestation*(attestation_data_root: Eth2Digest,
slot: Slot): RestResponse[GetAggregatedAttestationResponse] {.
proc getAggregatedAttestation*(
attestation_data_root: Eth2Digest,
slot: Slot
): RestResponse[GetAggregatedAttestationResponse] {.
rest, endpoint: "/eth/v1/validator/aggregate_attestation"
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getAggregatedAttestation

proc publishAggregateAndProofs*(body: seq[SignedAggregateAndProof]
): RestPlainResponse {.
proc getAggregatedAttestationPlain*(
attestation_data_root: Eth2Digest,
slot: Slot
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/aggregate_attestation"
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getAggregatedAttestation

proc publishAggregateAndProofs*(
body: seq[SignedAggregateAndProof]
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/aggregate_and_proofs",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/publishAggregateAndProofs

proc prepareBeaconCommitteeSubnet*(body: seq[RestCommitteeSubscription]): RestPlainResponse {.
proc prepareBeaconCommitteeSubnet*(
body: seq[RestCommitteeSubscription]
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/beacon_committee_subscriptions",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/prepareBeaconCommitteeSubnet

proc prepareSyncCommitteeSubnets*(body: seq[RestSyncCommitteeSubscription]): RestPlainResponse {.
proc prepareSyncCommitteeSubnets*(
body: seq[RestSyncCommitteeSubscription]
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/sync_committee_subscriptions",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/prepareSyncCommitteeSubnets

proc produceSyncCommitteeContribution*(slot: Slot,
subcommittee_index: SyncSubcommitteeIndex,
beacon_block_root: Eth2Digest
): RestResponse[ProduceSyncCommitteeContributionResponse] {.
proc produceSyncCommitteeContribution*(
slot: Slot,
subcommittee_index: SyncSubcommitteeIndex,
beacon_block_root: Eth2Digest
): RestResponse[ProduceSyncCommitteeContributionResponse] {.
rest, endpoint: "/eth/v1/validator/sync_committee_contribution",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/produceSyncCommitteeContribution

proc produceSyncCommitteeContributionPlain*(
slot: Slot,
subcommittee_index: SyncSubcommitteeIndex,
beacon_block_root: Eth2Digest
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/sync_committee_contribution",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/produceSyncCommitteeContribution
Expand Down
Loading