2021-04-16 08:49:37 +00:00
|
|
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
2021-03-23 22:50:18 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
import
|
|
|
|
std/[typetraits, strutils, deques, sets, options],
|
|
|
|
stew/[results, base10],
|
|
|
|
chronicles,
|
|
|
|
nimcrypto/utils as ncrutils,
|
|
|
|
../beacon_node_common, ../networking/eth2_network,
|
|
|
|
../consensus_object_pools/[blockchain_dag, spec_cache, attestation_pool],
|
|
|
|
../gossip_processing/gossip_validation,
|
|
|
|
../validators/validator_duties,
|
2021-06-23 14:43:18 +00:00
|
|
|
../spec/[crypto, digest, forkedbeaconstate_helpers, network],
|
|
|
|
../spec/datatypes/base,
|
2021-03-23 22:50:18 +00:00
|
|
|
../ssz/merkleization,
|
2021-08-03 15:17:11 +00:00
|
|
|
./rest_utils
|
2021-03-23 22:50:18 +00:00
|
|
|
|
|
|
|
logScope: topics = "rest_validatorapi"
|
|
|
|
|
|
|
|
proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|
|
|
# https://ethereum.github.io/eth2.0-APIs/#/Validator/getAttesterDuties
|
|
|
|
router.api(MethodPost, "/api/eth/v1/validator/duties/attester/{epoch}") do (
|
|
|
|
epoch: Epoch, contentBody: Option[ContentBody]) -> RestApiResponse:
|
|
|
|
let indexList =
|
|
|
|
block:
|
|
|
|
if contentBody.isNone():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
|
2021-04-06 08:00:26 +00:00
|
|
|
let dres = decodeBody(seq[RestValidatorIndex], contentBody.get())
|
2021-03-23 22:50:18 +00:00
|
|
|
if dres.isErr():
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidValidatorIndexValueError,
|
|
|
|
$dres.error())
|
2021-04-06 08:00:26 +00:00
|
|
|
var res: seq[ValidatorIndex]
|
|
|
|
let items = dres.get()
|
|
|
|
for item in items:
|
|
|
|
let vres = item.toValidatorIndex()
|
|
|
|
if vres.isErr():
|
|
|
|
case vres.error()
|
|
|
|
of ValidatorIndexError.TooHighValue:
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
2021-04-08 10:49:28 +00:00
|
|
|
TooHighValidatorIndexValueError)
|
2021-04-06 08:00:26 +00:00
|
|
|
of ValidatorIndexError.UnsupportedValue:
|
|
|
|
return RestApiResponse.jsonError(Http500,
|
2021-04-08 10:49:28 +00:00
|
|
|
UnsupportedValidatorIndexValueError)
|
2021-04-06 08:00:26 +00:00
|
|
|
res.add(vres.get())
|
|
|
|
if len(res) == 0:
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
EmptyValidatorIndexArrayError)
|
2021-04-06 08:00:26 +00:00
|
|
|
res
|
2021-03-23 22:50:18 +00:00
|
|
|
let qepoch =
|
|
|
|
block:
|
|
|
|
if epoch.isErr():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, InvalidEpochValueError,
|
2021-03-23 22:50:18 +00:00
|
|
|
$epoch.error())
|
|
|
|
let res = epoch.get()
|
2021-04-04 09:48:44 +00:00
|
|
|
if res > MaxEpoch:
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, EpochOverflowValueError)
|
2021-03-23 22:50:18 +00:00
|
|
|
res
|
|
|
|
let qhead =
|
|
|
|
block:
|
|
|
|
let res = node.getCurrentHead(qepoch)
|
|
|
|
if res.isErr():
|
2021-04-27 20:46:24 +00:00
|
|
|
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
2021-03-23 22:50:18 +00:00
|
|
|
res.get()
|
|
|
|
let droot =
|
|
|
|
if qepoch >= Epoch(2):
|
2021-05-20 13:09:27 +00:00
|
|
|
qhead.atSlot(compute_start_slot_at_epoch(qepoch - 1) - 1).blck.root
|
2021-03-23 22:50:18 +00:00
|
|
|
else:
|
2021-06-01 11:13:40 +00:00
|
|
|
node.dag.genesis.root
|
2021-03-23 22:50:18 +00:00
|
|
|
let duties =
|
|
|
|
block:
|
2021-05-20 17:56:12 +00:00
|
|
|
var res: seq[RestAttesterDuty]
|
2021-06-01 11:13:40 +00:00
|
|
|
let epochRef = node.dag.getEpochRef(qhead, qepoch)
|
2021-03-23 22:50:18 +00:00
|
|
|
let committees_per_slot = get_committee_count_per_slot(epochRef)
|
|
|
|
for i in 0 ..< SLOTS_PER_EPOCH:
|
|
|
|
let slot = compute_start_slot_at_epoch(qepoch) + i
|
|
|
|
for committee_index in 0'u64 ..< committees_per_slot:
|
|
|
|
let commitee = get_beacon_committee(
|
|
|
|
epochRef, slot, CommitteeIndex(committee_index)
|
|
|
|
)
|
|
|
|
for index_in_committee, validator_index in commitee:
|
2021-06-10 07:37:02 +00:00
|
|
|
if validator_index in indexList:
|
|
|
|
let validator_key = epochRef.validatorKey(validator_index)
|
|
|
|
if validator_key.isSome():
|
2021-03-23 22:50:18 +00:00
|
|
|
res.add(
|
2021-05-20 17:56:12 +00:00
|
|
|
RestAttesterDuty(
|
2021-06-10 07:37:02 +00:00
|
|
|
pubkey: validator_key.get().toPubKey(),
|
2021-03-23 22:50:18 +00:00
|
|
|
validator_index: validator_index,
|
|
|
|
committee_index: CommitteeIndex(committee_index),
|
|
|
|
committee_length: lenu64(commitee),
|
|
|
|
committees_at_slot: committees_per_slot,
|
|
|
|
validator_committee_index:
|
|
|
|
ValidatorIndex(index_in_committee),
|
|
|
|
slot: slot
|
|
|
|
)
|
|
|
|
)
|
|
|
|
res
|
|
|
|
return RestApiResponse.jsonResponseWRoot(duties, droot)
|
|
|
|
|
|
|
|
# https://ethereum.github.io/eth2.0-APIs/#/Validator/getProposerDuties
|
|
|
|
router.api(MethodGet, "/api/eth/v1/validator/duties/proposer/{epoch}") do (
|
|
|
|
epoch: Epoch) -> RestApiResponse:
|
|
|
|
let qepoch =
|
|
|
|
block:
|
|
|
|
if epoch.isErr():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, InvalidEpochValueError,
|
2021-03-23 22:50:18 +00:00
|
|
|
$epoch.error())
|
|
|
|
let res = epoch.get()
|
2021-04-04 09:48:44 +00:00
|
|
|
if res > MaxEpoch:
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, EpochOverflowValueError)
|
2021-03-23 22:50:18 +00:00
|
|
|
res
|
|
|
|
let qhead =
|
|
|
|
block:
|
|
|
|
let res = node.getCurrentHead(qepoch)
|
|
|
|
if res.isErr():
|
2021-04-27 20:46:24 +00:00
|
|
|
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
2021-03-23 22:50:18 +00:00
|
|
|
res.get()
|
|
|
|
let droot =
|
|
|
|
if qepoch >= Epoch(2):
|
2021-05-20 13:09:27 +00:00
|
|
|
qhead.atSlot(compute_start_slot_at_epoch(qepoch - 1) - 1).blck.root
|
2021-03-23 22:50:18 +00:00
|
|
|
else:
|
2021-06-01 11:13:40 +00:00
|
|
|
node.dag.genesis.root
|
2021-03-23 22:50:18 +00:00
|
|
|
let duties =
|
|
|
|
block:
|
2021-05-20 17:56:12 +00:00
|
|
|
var res: seq[RestProposerDuty]
|
2021-06-01 11:13:40 +00:00
|
|
|
let epochRef = node.dag.getEpochRef(qhead, qepoch)
|
|
|
|
for i, bp in epochRef.beacon_proposers:
|
2021-06-10 07:37:02 +00:00
|
|
|
if i == 0 and qepoch == 0:
|
|
|
|
# Fix for https://github.com/status-im/nimbus-eth2/issues/2488
|
|
|
|
# Slot(0) at Epoch(0) do not have a proposer.
|
|
|
|
continue
|
|
|
|
|
2021-06-01 11:13:40 +00:00
|
|
|
if bp.isSome():
|
2021-03-23 22:50:18 +00:00
|
|
|
res.add(
|
2021-05-20 17:56:12 +00:00
|
|
|
RestProposerDuty(
|
2021-06-10 07:37:02 +00:00
|
|
|
pubkey: epochRef.validatorKey(bp.get()).get().toPubKey(),
|
2021-06-01 11:13:40 +00:00
|
|
|
validator_index: bp.get(),
|
2021-03-23 22:50:18 +00:00
|
|
|
slot: compute_start_slot_at_epoch(qepoch) + i
|
|
|
|
)
|
|
|
|
)
|
|
|
|
res
|
|
|
|
return RestApiResponse.jsonResponseWRoot(duties, droot)
|
|
|
|
|
|
|
|
# https://ethereum.github.io/eth2.0-APIs/#/Validator/produceBlock
|
|
|
|
router.api(MethodGet, "/api/eth/v1/validator/blocks/{slot}") do (
|
|
|
|
slot: Slot, randao_reveal: Option[ValidatorSig],
|
|
|
|
graffiti: Option[GraffitiBytes]) -> RestApiResponse:
|
|
|
|
let message =
|
|
|
|
block:
|
|
|
|
let qslot =
|
|
|
|
block:
|
|
|
|
if slot.isErr():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, InvalidSlotValueError,
|
2021-03-23 22:50:18 +00:00
|
|
|
$slot.error())
|
|
|
|
slot.get()
|
2021-04-08 14:34:05 +00:00
|
|
|
|
2021-03-23 22:50:18 +00:00
|
|
|
let qrandao =
|
|
|
|
if randao_reveal.isNone():
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, MissingRandaoRevealValue)
|
2021-03-23 22:50:18 +00:00
|
|
|
else:
|
|
|
|
let res = randao_reveal.get()
|
|
|
|
if res.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
2021-04-08 14:34:05 +00:00
|
|
|
InvalidRandaoRevealValue,
|
2021-03-23 22:50:18 +00:00
|
|
|
$res.error())
|
|
|
|
res.get()
|
|
|
|
let qgraffiti =
|
|
|
|
if graffiti.isNone():
|
|
|
|
defaultGraffitiBytes()
|
|
|
|
else:
|
|
|
|
let res = graffiti.get()
|
|
|
|
if res.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
2021-04-08 14:34:05 +00:00
|
|
|
InvalidGraffitiBytesValye,
|
2021-03-23 22:50:18 +00:00
|
|
|
$res.error())
|
|
|
|
res.get()
|
|
|
|
let qhead =
|
|
|
|
block:
|
|
|
|
let res = node.getCurrentHead(qslot)
|
|
|
|
if res.isErr():
|
2021-06-01 11:13:40 +00:00
|
|
|
if not(node.isSynced(node.dag.head)):
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
2021-03-23 22:50:18 +00:00
|
|
|
else:
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, NoHeadForSlotError,
|
2021-03-23 22:50:18 +00:00
|
|
|
$res.error())
|
|
|
|
res.get()
|
2021-06-01 11:13:40 +00:00
|
|
|
let proposer = node.dag.getProposer(qhead, qslot)
|
2021-03-23 22:50:18 +00:00
|
|
|
if proposer.isNone():
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, ProposerNotFoundError)
|
2021-05-20 10:44:13 +00:00
|
|
|
let res = await makeBeaconBlockForHeadAndSlot(
|
2021-06-01 11:13:40 +00:00
|
|
|
node, qrandao, proposer.get(), qgraffiti, qhead, qslot)
|
2021-03-23 22:50:18 +00:00
|
|
|
if res.isNone():
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, BlockProduceError)
|
2021-03-23 22:50:18 +00:00
|
|
|
res.get()
|
2021-04-08 14:34:05 +00:00
|
|
|
|
2021-03-23 22:50:18 +00:00
|
|
|
return RestApiResponse.jsonResponse(message)
|
|
|
|
|
|
|
|
# https://ethereum.github.io/eth2.0-APIs/#/Validator/produceAttestationData
|
|
|
|
router.api(MethodGet, "/api/eth/v1/validator/attestation_data") do (
|
|
|
|
slot: Option[Slot],
|
|
|
|
committee_index: Option[CommitteeIndex]) -> RestApiResponse:
|
|
|
|
let adata =
|
|
|
|
block:
|
|
|
|
let qslot =
|
|
|
|
block:
|
|
|
|
if slot.isNone():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, MissingSlotValueError)
|
2021-03-23 22:50:18 +00:00
|
|
|
let res = slot.get()
|
|
|
|
if res.isErr():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, InvalidSlotValueError,
|
2021-03-23 22:50:18 +00:00
|
|
|
$res.error())
|
|
|
|
res.get()
|
|
|
|
let qindex =
|
|
|
|
block:
|
|
|
|
if committee_index.isNone():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
2021-04-08 10:49:28 +00:00
|
|
|
MissingCommitteeIndexValueError)
|
2021-03-23 22:50:18 +00:00
|
|
|
let res = committee_index.get()
|
|
|
|
if res.isErr():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidCommitteeIndexValueError,
|
2021-03-23 22:50:18 +00:00
|
|
|
$res.error())
|
|
|
|
res.get()
|
|
|
|
let qhead =
|
|
|
|
block:
|
|
|
|
let res = node.getCurrentHead(qslot)
|
|
|
|
if res.isErr():
|
2021-04-27 20:46:24 +00:00
|
|
|
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
2021-03-23 22:50:18 +00:00
|
|
|
res.get()
|
2021-06-01 11:13:40 +00:00
|
|
|
let epochRef = node.dag.getEpochRef(qhead, qslot.epoch)
|
2021-03-23 22:50:18 +00:00
|
|
|
makeAttestationData(epochRef, qhead.atSlot(qslot), qindex)
|
|
|
|
return RestApiResponse.jsonResponse(adata)
|
|
|
|
|
|
|
|
# https://ethereum.github.io/eth2.0-APIs/#/Validator/getAggregatedAttestation
|
|
|
|
router.api(MethodGet, "/api/eth/v1/validator/aggregate_attestation") do (
|
|
|
|
attestation_data_root: Option[Eth2Digest],
|
|
|
|
slot: Option[Slot]) -> RestApiResponse:
|
|
|
|
let attestation =
|
|
|
|
block:
|
|
|
|
let qslot =
|
|
|
|
block:
|
|
|
|
if slot.isNone():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, MissingSlotValueError)
|
2021-03-23 22:50:18 +00:00
|
|
|
let res = slot.get()
|
|
|
|
if res.isErr():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, InvalidSlotValueError,
|
2021-03-23 22:50:18 +00:00
|
|
|
$res.error())
|
|
|
|
res.get()
|
|
|
|
let qroot =
|
|
|
|
block:
|
|
|
|
if attestation_data_root.isNone():
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
MissingAttestationDataRootValueError)
|
2021-03-23 22:50:18 +00:00
|
|
|
let res = attestation_data_root.get()
|
|
|
|
if res.isErr():
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidAttestationDataRootValueError, $res.error())
|
2021-03-23 22:50:18 +00:00
|
|
|
res.get()
|
|
|
|
let res = node.attestationPool[].getAggregatedAttestation(qslot, qroot)
|
|
|
|
if res.isNone():
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
UnableToGetAggregatedAttestationError)
|
2021-03-23 22:50:18 +00:00
|
|
|
res.get()
|
|
|
|
return RestApiResponse.jsonResponse(attestation)
|
|
|
|
|
|
|
|
# https://ethereum.github.io/eth2.0-APIs/#/Validator/publishAggregateAndProofs
|
|
|
|
router.api(MethodPost, "/api/eth/v1/validator/aggregate_and_proofs") do (
|
|
|
|
contentBody: Option[ContentBody]) -> RestApiResponse:
|
2021-05-20 18:43:42 +00:00
|
|
|
let proofs =
|
2021-03-23 22:50:18 +00:00
|
|
|
block:
|
|
|
|
if contentBody.isNone():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
|
2021-05-20 18:43:42 +00:00
|
|
|
let dres = decodeBody(seq[SignedAggregateAndProof], contentBody.get())
|
2021-03-23 22:50:18 +00:00
|
|
|
if dres.isErr():
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidAggregateAndProofObjectError,
|
|
|
|
$dres.error())
|
2021-03-23 22:50:18 +00:00
|
|
|
dres.get()
|
|
|
|
|
2021-05-20 18:43:42 +00:00
|
|
|
for item in proofs:
|
2021-07-07 09:09:47 +00:00
|
|
|
let wallTime = node.processor.getCurrentBeaconTime()
|
2021-05-20 18:43:42 +00:00
|
|
|
let res = await node.attestationPool.validateAggregate(
|
|
|
|
node.processor.batchCrypto, item, wallTime
|
|
|
|
)
|
|
|
|
if res.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
AggregateAndProofValidationError,
|
|
|
|
$res.error())
|
2021-07-14 12:18:52 +00:00
|
|
|
node.network.broadcast(
|
|
|
|
getAggregateAndProofsTopic(node.dag.forkDigests.phase0), item)
|
2021-08-03 10:32:55 +00:00
|
|
|
notice "Aggregated attestation sent",
|
|
|
|
attestation = shortLog(item.message.aggregate),
|
|
|
|
signature = shortLog(item.signature)
|
2021-05-20 18:43:42 +00:00
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
return RestApiResponse.jsonMsgResponse(AggregateAndProofValidationSuccess)
|
2021-03-23 22:50:18 +00:00
|
|
|
|
|
|
|
# https://ethereum.github.io/eth2.0-APIs/#/Validator/prepareBeaconCommitteeSubnet
|
|
|
|
router.api(MethodPost,
|
|
|
|
"/api/eth/v1/validator/beacon_committee_subscriptions") do (
|
|
|
|
contentBody: Option[ContentBody]) -> RestApiResponse:
|
2021-03-29 10:59:39 +00:00
|
|
|
# TODO (cheatfate): This call could not be finished because more complex
|
|
|
|
# peer manager implementation needed.
|
2021-03-23 22:50:18 +00:00
|
|
|
let requests =
|
|
|
|
block:
|
|
|
|
if contentBody.isNone():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
|
2021-05-20 17:56:12 +00:00
|
|
|
let dres = decodeBody(seq[RestCommitteeSubscription],
|
2021-03-23 22:50:18 +00:00
|
|
|
contentBody.get())
|
|
|
|
if dres.isErr():
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidSubscriptionRequestValueError,
|
|
|
|
$dres.error())
|
2021-03-23 22:50:18 +00:00
|
|
|
dres.get()
|
2021-06-01 11:13:40 +00:00
|
|
|
if not(node.isSynced(node.dag.head)):
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
2021-03-23 22:50:18 +00:00
|
|
|
|
|
|
|
for request in requests:
|
2021-04-18 08:24:59 +00:00
|
|
|
if uint64(request.committee_index) >= uint64(MAX_COMMITTEES_PER_SLOT):
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidCommitteeIndexValueError)
|
2021-03-23 22:50:18 +00:00
|
|
|
let validator_pubkey =
|
|
|
|
block:
|
|
|
|
let idx = request.validator_index
|
|
|
|
if uint64(idx) >=
|
2021-06-11 17:51:46 +00:00
|
|
|
lenu64(getStateField(node.dag.headState.data, validators)):
|
2021-03-23 22:50:18 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
2021-04-08 14:34:05 +00:00
|
|
|
InvalidValidatorIndexValueError)
|
2021-06-11 17:51:46 +00:00
|
|
|
getStateField(node.dag.headState.data, validators)[idx].pubkey
|
2021-03-23 22:50:18 +00:00
|
|
|
|
|
|
|
let wallSlot = node.beaconClock.now.slotOrZero
|
|
|
|
if wallSlot > request.slot + 1:
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, SlotFromThePastError)
|
2021-03-23 22:50:18 +00:00
|
|
|
let epoch = request.slot.epoch
|
|
|
|
if epoch >= wallSlot.epoch and epoch - wallSlot.epoch > 1:
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
SlotNotInNextWallSlotEpochError)
|
2021-03-23 22:50:18 +00:00
|
|
|
let head =
|
|
|
|
block:
|
|
|
|
let res = node.getCurrentHead(epoch)
|
|
|
|
if res.isErr():
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, NoHeadForSlotError,
|
2021-03-23 22:50:18 +00:00
|
|
|
$res.error())
|
|
|
|
res.get()
|
2021-06-01 11:13:40 +00:00
|
|
|
let epochRef = node.dag.getEpochRef(head, epoch)
|
2021-03-23 22:50:18 +00:00
|
|
|
let subnet = uint8(compute_subnet_for_attestation(
|
|
|
|
get_committee_count_per_slot(epochRef), request.slot,
|
|
|
|
request.committee_index)
|
|
|
|
)
|
2021-07-13 11:15:07 +00:00
|
|
|
warn "Beacon committee subscription request served, but not implemented"
|
|
|
|
return RestApiResponse.jsonMsgResponse(BeaconCommitteeSubscriptionSuccess)
|
2021-04-13 10:19:31 +00:00
|
|
|
|
|
|
|
router.redirect(
|
|
|
|
MethodPost,
|
|
|
|
"/eth/v1/validator/duties/attester/{epoch}",
|
|
|
|
"/api/eth/v1/validator/duties/attester/{epoch}"
|
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
|
|
|
"/eth/v1/validator/duties/proposer/{epoch}",
|
|
|
|
"/api/eth/v1/validator/duties/proposer/{epoch}"
|
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
|
|
|
"/eth/v1/validator/blocks/{slot}",
|
|
|
|
"/api/eth/v1/validator/blocks/{slot}"
|
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
|
|
|
"/eth/v1/validator/attestation_data",
|
|
|
|
"/api/eth/v1/validator/attestation_data"
|
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
|
|
|
"/eth/v1/validator/aggregate_attestation",
|
|
|
|
"/api/eth/v1/validator/aggregate_attestation"
|
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodPost,
|
|
|
|
"/eth/v1/validator/aggregate_and_proofs",
|
|
|
|
"/api/eth/v1/validator/aggregate_and_proofs"
|
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodPost,
|
|
|
|
"/eth/v1/validator/beacon_committee_subscriptions",
|
|
|
|
"/api/eth/v1/validator/beacon_committee_subscriptions"
|
|
|
|
)
|