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.
|
2021-11-07 21:03:23 +00:00
|
|
|
import std/[typetraits, strutils, sets]
|
2022-01-08 20:06:34 +00:00
|
|
|
import stew/[results, base10], chronicles
|
2022-01-05 14:49:10 +00:00
|
|
|
import ".."/[beacon_chain_db, beacon_node],
|
2021-09-23 22:13:25 +00:00
|
|
|
".."/networking/eth2_network,
|
|
|
|
".."/consensus_object_pools/[blockchain_dag, spec_cache,
|
|
|
|
attestation_pool, sync_committee_msg_pool],
|
|
|
|
".."/validators/validator_duties,
|
2021-11-07 21:03:23 +00:00
|
|
|
".."/spec/[beaconstate, forks, network],
|
2022-01-05 14:49:10 +00:00
|
|
|
".."/spec/datatypes/[phase0, altair],
|
|
|
|
"."/[rest_utils, state_ttl_cache]
|
2021-03-23 22:50:18 +00:00
|
|
|
|
2021-10-27 12:01:11 +00:00
|
|
|
export rest_utils
|
|
|
|
|
2021-03-23 22:50:18 +00:00
|
|
|
logScope: topics = "rest_validatorapi"
|
|
|
|
|
|
|
|
proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
2021-08-23 10:41:48 +00:00
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/getAttesterDuties
|
2022-01-06 07:38:40 +00:00
|
|
|
router.api(MethodPost, "/eth/v1/validator/duties/attester/{epoch}") do (
|
2021-03-23 22:50:18 +00:00
|
|
|
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-10-18 08:54:20 +00:00
|
|
|
var res: HashSet[ValidatorIndex]
|
2021-04-06 08:00:26 +00:00
|
|
|
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-10-18 08:54:20 +00:00
|
|
|
res.incl(vres.get())
|
2021-04-06 08:00:26 +00:00
|
|
|
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())
|
2022-01-08 20:06:34 +00:00
|
|
|
let
|
|
|
|
res = epoch.get()
|
|
|
|
wallTime = node.beaconClock.now() + MAXIMUM_GOSSIP_CLOCK_DISPARITY
|
|
|
|
wallEpoch = wallTime.slotOrZero().epoch
|
|
|
|
if res > wallEpoch + 1:
|
|
|
|
return RestApiResponse.jsonError(Http400, InvalidEpochValueError,
|
|
|
|
"Cannot request duties past next epoch")
|
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()
|
2022-01-08 20:06:34 +00:00
|
|
|
let droot = qhead.prevDependentBlock(node.dag.tail, qepoch).root
|
2021-03-23 22:50:18 +00:00
|
|
|
let duties =
|
|
|
|
block:
|
2021-05-20 17:56:12 +00:00
|
|
|
var res: seq[RestAttesterDuty]
|
2022-01-05 18:38:04 +00:00
|
|
|
let epochRef = block:
|
|
|
|
let tmp = node.dag.getEpochRef(qhead, qepoch, true)
|
|
|
|
if isErr(tmp):
|
|
|
|
return RestApiResponse.jsonError(Http400, PrunedStateError)
|
|
|
|
tmp.get()
|
|
|
|
|
2022-01-08 23:28:49 +00:00
|
|
|
let
|
|
|
|
committees_per_slot = get_committee_count_per_slot(epochRef)
|
|
|
|
for committee_index in get_committee_indices(committees_per_slot):
|
2022-01-11 10:01:54 +00:00
|
|
|
for slot in qepoch.slots():
|
2022-01-08 23:28:49 +00:00
|
|
|
let committee = get_beacon_committee(epochRef, slot, committee_index)
|
|
|
|
for index_in_committee, validator_index in committee:
|
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,
|
2022-01-08 23:28:49 +00:00
|
|
|
committee_index: committee_index,
|
|
|
|
committee_length: lenu64(committee),
|
2021-03-23 22:50:18 +00:00
|
|
|
committees_at_slot: committees_per_slot,
|
2022-01-08 23:28:49 +00:00
|
|
|
validator_committee_index: uint64(index_in_committee),
|
2021-03-23 22:50:18 +00:00
|
|
|
slot: slot
|
|
|
|
)
|
|
|
|
)
|
|
|
|
res
|
|
|
|
return RestApiResponse.jsonResponseWRoot(duties, droot)
|
|
|
|
|
2021-08-23 10:41:48 +00:00
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/getProposerDuties
|
2022-01-06 07:38:40 +00:00
|
|
|
router.api(MethodGet, "/eth/v1/validator/duties/proposer/{epoch}") do (
|
2021-03-23 22:50:18 +00:00
|
|
|
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())
|
2022-01-08 20:06:34 +00:00
|
|
|
let
|
|
|
|
res = epoch.get()
|
|
|
|
wallTime = node.beaconClock.now() + MAXIMUM_GOSSIP_CLOCK_DISPARITY
|
|
|
|
wallEpoch = wallTime.slotOrZero().epoch
|
|
|
|
if res > wallEpoch + 1:
|
|
|
|
return RestApiResponse.jsonError(Http400, InvalidEpochValueError,
|
|
|
|
"Cannot request duties past next epoch")
|
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()
|
2022-01-08 20:06:34 +00:00
|
|
|
let droot = qhead.dependentBlock(node.dag.tail, qepoch).root
|
2021-03-23 22:50:18 +00:00
|
|
|
let duties =
|
|
|
|
block:
|
2021-05-20 17:56:12 +00:00
|
|
|
var res: seq[RestProposerDuty]
|
2022-01-05 18:38:04 +00:00
|
|
|
let epochRef = block:
|
|
|
|
let tmp = node.dag.getEpochRef(qhead, qepoch, true)
|
|
|
|
if isErr(tmp):
|
|
|
|
return RestApiResponse.jsonError(Http400, PrunedStateError)
|
|
|
|
tmp.get()
|
2021-06-01 11:13:40 +00:00
|
|
|
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(),
|
2022-01-11 10:01:54 +00:00
|
|
|
slot: qepoch.start_slot() + i
|
2021-03-23 22:50:18 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
res
|
|
|
|
return RestApiResponse.jsonResponseWRoot(duties, droot)
|
|
|
|
|
2022-01-06 07:38:40 +00:00
|
|
|
router.api(MethodPost, "/eth/v1/validator/duties/sync/{epoch}") do (
|
2021-10-14 10:38:38 +00:00
|
|
|
epoch: Epoch, contentBody: Option[ContentBody]) -> RestApiResponse:
|
|
|
|
let indexList =
|
|
|
|
block:
|
|
|
|
if contentBody.isNone():
|
|
|
|
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
|
|
|
|
let dres = decodeBody(seq[RestValidatorIndex], contentBody.get())
|
|
|
|
if dres.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidValidatorIndexValueError,
|
|
|
|
$dres.error())
|
|
|
|
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,
|
|
|
|
TooHighValidatorIndexValueError)
|
|
|
|
of ValidatorIndexError.UnsupportedValue:
|
|
|
|
return RestApiResponse.jsonError(Http500,
|
|
|
|
UnsupportedValidatorIndexValueError)
|
|
|
|
res.add(vres.get())
|
|
|
|
if len(res) == 0:
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
EmptyValidatorIndexArrayError)
|
|
|
|
res
|
|
|
|
let qepoch =
|
|
|
|
block:
|
|
|
|
if epoch.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400, InvalidEpochValueError,
|
|
|
|
$epoch.error())
|
|
|
|
let res = epoch.get()
|
|
|
|
if res > MaxEpoch:
|
|
|
|
return RestApiResponse.jsonError(Http400, EpochOverflowValueError)
|
|
|
|
|
|
|
|
res
|
|
|
|
|
2021-11-30 01:14:31 +00:00
|
|
|
# We use a local proc in order to:
|
|
|
|
# * avoid code duplication
|
|
|
|
# * reduce code bloat from `withState`
|
|
|
|
proc produceResponse(requestedValidatorIndices: openArray[ValidatorIndex],
|
|
|
|
syncCommittee: openArray[ValidatorPubKey],
|
|
|
|
stateValidators: seq[Validator]
|
|
|
|
): seq[RestSyncCommitteeDuty] {.nimcall.} =
|
|
|
|
result = newSeqOfCap[RestSyncCommitteeDuty](len(requestedValidatorIndices))
|
|
|
|
for requestedValidatorIdx in requestedValidatorIndices:
|
|
|
|
if requestedValidatorIdx.uint64 >= stateValidators.lenu64:
|
|
|
|
# If the requested validator index was not valid within this old
|
|
|
|
# state, it's not possible that it will sit on the sync committee.
|
|
|
|
# Since this API must omit results for validators that don't have
|
|
|
|
# duties, we can simply ingnore this requested index.
|
|
|
|
# (we won't bother to validate it agains a more recent state).
|
|
|
|
continue
|
|
|
|
|
|
|
|
let requestedValidatorPubkey =
|
|
|
|
stateValidators[requestedValidatorIdx].pubkey
|
|
|
|
|
|
|
|
var indicesInSyncCommittee = newSeq[IndexInSyncCommittee]()
|
|
|
|
for idx, syncCommitteeMemberPubkey in syncCommittee:
|
|
|
|
if syncCommitteeMemberPubkey == requestedValidatorPubkey:
|
|
|
|
indicesInSyncCommittee.add(IndexInSyncCommittee idx)
|
|
|
|
|
|
|
|
if indicesInSyncCommittee.len > 0:
|
|
|
|
result.add RestSyncCommitteeDuty(
|
|
|
|
pubkey: requestedValidatorPubkey,
|
|
|
|
validator_index: requestedValidatorIdx,
|
|
|
|
validator_sync_committee_indices: indicesInSyncCommittee)
|
|
|
|
|
|
|
|
template emptyResponse: auto =
|
|
|
|
newSeq[RestSyncCommitteeDuty]()
|
|
|
|
|
|
|
|
# We check the head state first in order to avoid costly replays
|
|
|
|
# if possible:
|
|
|
|
let
|
|
|
|
qSyncPeriod = sync_committee_period(qepoch)
|
|
|
|
headEpoch = node.dag.head.slot.epoch
|
|
|
|
headSyncPeriod = sync_committee_period(headEpoch)
|
|
|
|
|
|
|
|
if qSyncPeriod == headSyncPeriod:
|
|
|
|
let res = withState(node.dag.headState.data):
|
|
|
|
when stateFork >= BeaconStateFork.Altair:
|
|
|
|
produceResponse(indexList,
|
|
|
|
state.data.current_sync_committee.pubkeys.data,
|
|
|
|
state.data.validators.asSeq)
|
|
|
|
else:
|
|
|
|
emptyResponse()
|
|
|
|
return RestApiResponse.jsonResponse(res)
|
|
|
|
elif qSyncPeriod == (headSyncPeriod + 1):
|
|
|
|
let res = withState(node.dag.headState.data):
|
|
|
|
when stateFork >= BeaconStateFork.Altair:
|
|
|
|
produceResponse(indexList,
|
|
|
|
state.data.next_sync_committee.pubkeys.data,
|
|
|
|
state.data.validators.asSeq)
|
|
|
|
else:
|
|
|
|
emptyResponse()
|
|
|
|
return RestApiResponse.jsonResponse(res)
|
|
|
|
elif qSyncPeriod > headSyncPeriod:
|
|
|
|
# The requested epoch may still be too far in the future.
|
|
|
|
if not(node.isSynced(node.dag.head)):
|
|
|
|
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
|
|
|
else:
|
|
|
|
return RestApiResponse.jsonError(Http400, EpochFromFutureError)
|
|
|
|
else:
|
|
|
|
# The slot at the start of the sync committee period is likely to have a
|
|
|
|
# state snapshot in the database, so we can restore the state relatively
|
|
|
|
# cheaply:
|
|
|
|
let earliestSlotInQSyncPeriod =
|
|
|
|
Slot(qSyncPeriod * SLOTS_PER_SYNC_COMMITTEE_PERIOD)
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
# The DAG can offer a short-cut for getting just the information we need
|
|
|
|
# in order to compute the sync committee for the epoch. See the following
|
|
|
|
# discussion for more details:
|
|
|
|
# https://github.com/status-im/nimbus-eth2/pull/3133#pullrequestreview-817184693
|
limit by-root requests to non-finalized blocks (#3293)
* limit by-root requests to non-finalized blocks
Presently, we keep a mapping from block root to `BlockRef` in memory -
this has simplified reasoning about the dag, but is not sustainable with
the chain growing.
We can distinguish between two cases where by-root access is useful:
* unfinalized blocks - this is where the beacon chain is operating
generally, by validating incoming data as interesting for future fork
choice decisions - bounded by the length of the unfinalized period
* finalized blocks - historical access in the REST API etc - no bounds,
really
In this PR, we limit the by-root block index to the first use case:
finalized chain data can more efficiently be addressed by slot number.
Future work includes:
* limiting the `BlockRef` horizon in general - each instance is 40
bytes+overhead which adds up - this needs further refactoring to deal
with the tail vs state problem
* persisting the finalized slot-to-hash index - this one also keeps
growing unbounded (albeit slowly)
Anyway, this PR easily shaves ~128mb of memory usage at the time of
writing.
* No longer honor `BeaconBlocksByRoot` requests outside of the
non-finalized period - previously, Nimbus would generously return any
block through this libp2p request - per the spec, finalized blocks
should be fetched via `BeaconBlocksByRange` instead.
* return `Opt[BlockRef]` instead of `nil` when blocks can't be found -
this becomes a lot more common now and thus deserves more attention
* `dag.blocks` -> `dag.forkBlocks` - this index only carries unfinalized
blocks from now - `finalizedBlocks` covers the other `BlockRef`
instances
* in backfill, verify that the last backfilled block leads back to
genesis, or panic
* add backfill timings to log
* fix missing check that `BlockRef` block can be fetched with
`getForkedBlock` reliably
* shortcut doppelganger check when feature is not enabled
* in REST/JSON-RPC, fetch blocks without involving `BlockRef`
* fix dag.blocks ref
2022-01-21 11:33:16 +00:00
|
|
|
let bs = node.dag.getBlockAtSlot(earliestSlotInQSyncPeriod)
|
2022-01-05 18:38:04 +00:00
|
|
|
if bs.blck.isNil:
|
|
|
|
return RestApiResponse.jsonError(Http404, StateNotFoundError)
|
|
|
|
|
|
|
|
node.withStateForBlockSlot(bs):
|
2021-11-30 01:14:31 +00:00
|
|
|
let res = withState(stateData().data):
|
|
|
|
when stateFork >= BeaconStateFork.Altair:
|
|
|
|
produceResponse(indexList,
|
|
|
|
state.data.current_sync_committee.pubkeys.data,
|
|
|
|
state.data.validators.asSeq)
|
|
|
|
else:
|
|
|
|
emptyResponse()
|
|
|
|
return RestApiResponse.jsonResponse(res)
|
2021-10-14 10:38:38 +00:00
|
|
|
|
|
|
|
return RestApiResponse.jsonError(Http404, StateNotFoundError)
|
|
|
|
|
2021-08-23 10:41:48 +00:00
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/produceBlock
|
2022-01-06 07:38:40 +00:00
|
|
|
router.api(MethodGet, "/eth/v1/validator/blocks/{slot}") do (
|
2021-03-23 22:50:18 +00:00
|
|
|
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()
|
|
|
|
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,
|
2022-01-05 15:42:29 +00:00
|
|
|
InvalidGraffitiBytesValue,
|
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-08-27 09:00:06 +00:00
|
|
|
if res.isErr():
|
2021-08-29 14:50:21 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, res.error())
|
2021-03-23 22:50:18 +00:00
|
|
|
res.get()
|
2021-08-09 06:08:18 +00:00
|
|
|
return
|
2021-08-29 14:50:21 +00:00
|
|
|
case message.kind
|
|
|
|
of BeaconBlockFork.Phase0:
|
2021-10-18 16:37:27 +00:00
|
|
|
RestApiResponse.jsonResponse(message.phase0Data)
|
2021-08-09 06:08:18 +00:00
|
|
|
else:
|
2021-08-29 14:50:21 +00:00
|
|
|
RestApiResponse.jsonError(Http400,
|
|
|
|
"Unable to produce block for altair fork")
|
2021-04-08 14:34:05 +00:00
|
|
|
|
2021-08-23 10:41:48 +00:00
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/produceBlockV2
|
2022-01-06 07:38:40 +00:00
|
|
|
router.api(MethodGet, "/eth/v2/validator/blocks/{slot}") do (
|
2021-08-09 06:08:18 +00:00
|
|
|
slot: Slot, randao_reveal: Option[ValidatorSig],
|
|
|
|
graffiti: Option[GraffitiBytes]) -> RestApiResponse:
|
|
|
|
let message =
|
|
|
|
block:
|
|
|
|
let qslot =
|
|
|
|
block:
|
|
|
|
if slot.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400, InvalidSlotValueError,
|
|
|
|
$slot.error())
|
|
|
|
slot.get()
|
|
|
|
let qrandao =
|
|
|
|
if randao_reveal.isNone():
|
|
|
|
return RestApiResponse.jsonError(Http400, MissingRandaoRevealValue)
|
|
|
|
else:
|
|
|
|
let res = randao_reveal.get()
|
|
|
|
if res.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidRandaoRevealValue,
|
|
|
|
$res.error())
|
|
|
|
res.get()
|
|
|
|
let qgraffiti =
|
|
|
|
if graffiti.isNone():
|
|
|
|
defaultGraffitiBytes()
|
|
|
|
else:
|
|
|
|
let res = graffiti.get()
|
|
|
|
if res.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
2022-01-05 15:42:29 +00:00
|
|
|
InvalidGraffitiBytesValue,
|
2021-08-09 06:08:18 +00:00
|
|
|
$res.error())
|
|
|
|
res.get()
|
|
|
|
let qhead =
|
|
|
|
block:
|
|
|
|
let res = node.getCurrentHead(qslot)
|
|
|
|
if res.isErr():
|
|
|
|
if not(node.isSynced(node.dag.head)):
|
|
|
|
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
|
|
|
else:
|
|
|
|
return RestApiResponse.jsonError(Http400, NoHeadForSlotError,
|
|
|
|
$res.error())
|
|
|
|
res.get()
|
|
|
|
let proposer = node.dag.getProposer(qhead, qslot)
|
|
|
|
if proposer.isNone():
|
|
|
|
return RestApiResponse.jsonError(Http400, ProposerNotFoundError)
|
|
|
|
let res = await makeBeaconBlockForHeadAndSlot(
|
|
|
|
node, qrandao, proposer.get(), qgraffiti, qhead, qslot)
|
2021-08-27 09:00:06 +00:00
|
|
|
if res.isErr():
|
2021-08-29 14:50:21 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, res.error())
|
2021-08-09 06:08:18 +00:00
|
|
|
res.get()
|
2021-08-29 14:50:21 +00:00
|
|
|
return RestApiResponse.jsonResponsePlain(message)
|
2021-03-23 22:50:18 +00:00
|
|
|
|
2021-08-23 10:41:48 +00:00
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/produceAttestationData
|
2022-01-06 07:38:40 +00:00
|
|
|
router.api(MethodGet, "/eth/v1/validator/attestation_data") do (
|
2021-03-23 22:50:18 +00:00
|
|
|
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()
|
2022-01-05 18:38:04 +00:00
|
|
|
let epochRef = block:
|
|
|
|
let tmp = node.dag.getEpochRef(qhead, qslot.epoch, true)
|
|
|
|
if isErr(tmp):
|
|
|
|
return RestApiResponse.jsonError(Http400, PrunedStateError)
|
|
|
|
tmp.get()
|
2021-03-23 22:50:18 +00:00
|
|
|
makeAttestationData(epochRef, qhead.atSlot(qslot), qindex)
|
|
|
|
return RestApiResponse.jsonResponse(adata)
|
|
|
|
|
2021-08-23 10:41:48 +00:00
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/getAggregatedAttestation
|
2022-01-06 07:38:40 +00:00
|
|
|
router.api(MethodGet, "/eth/v1/validator/aggregate_attestation") do (
|
2021-03-23 22:50:18 +00:00
|
|
|
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)
|
|
|
|
|
2021-08-23 10:41:48 +00:00
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/publishAggregateAndProofs
|
2022-01-06 07:38:40 +00:00
|
|
|
router.api(MethodPost, "/eth/v1/validator/aggregate_and_proofs") do (
|
2021-03-23 22:50:18 +00:00
|
|
|
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-08-23 10:41:48 +00:00
|
|
|
# Since our validation logic supports batch processing, we will submit all
|
|
|
|
# aggregated attestations for validation.
|
|
|
|
var pending =
|
|
|
|
block:
|
|
|
|
var res: seq[Future[SendResult]]
|
|
|
|
for proof in proofs:
|
|
|
|
res.add(node.sendAggregateAndProof(proof))
|
|
|
|
res
|
|
|
|
await allFutures(pending)
|
|
|
|
for future in pending:
|
|
|
|
if future.done():
|
|
|
|
let res = future.read()
|
|
|
|
if res.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
AggregateAndProofValidationError,
|
|
|
|
$res.error())
|
|
|
|
else:
|
|
|
|
return RestApiResponse.jsonError(Http500,
|
|
|
|
"Unexpected server failure, while sending aggregate and proof")
|
2021-07-13 11:15:07 +00:00
|
|
|
return RestApiResponse.jsonMsgResponse(AggregateAndProofValidationSuccess)
|
2021-03-23 22:50:18 +00:00
|
|
|
|
2021-08-23 10:41:48 +00:00
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/prepareBeaconCommitteeSubnet
|
2021-03-23 22:50:18 +00:00
|
|
|
router.api(MethodPost,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/eth/v1/validator/beacon_committee_subscriptions") do (
|
2021-03-23 22:50:18 +00:00
|
|
|
contentBody: Option[ContentBody]) -> RestApiResponse:
|
|
|
|
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
|
|
|
|
2021-12-03 15:04:58 +00:00
|
|
|
let
|
|
|
|
wallSlot = node.beaconClock.now.slotOrZero
|
|
|
|
wallEpoch = wallSlot.epoch
|
|
|
|
head = node.dag.head
|
|
|
|
|
|
|
|
var currentEpoch, nextEpoch: Option[EpochRef]
|
|
|
|
template getAndCacheEpochRef(epochRefVar: var Option[EpochRef],
|
|
|
|
epoch: Epoch): EpochRef =
|
|
|
|
if epochRefVar.isNone:
|
2022-01-05 18:38:04 +00:00
|
|
|
epochRefVar = block:
|
|
|
|
let epochRef = node.dag.getEpochRef(head, epoch, true)
|
|
|
|
if isErr(epochRef):
|
|
|
|
return RestApiResponse.jsonError(Http400, PrunedStateError)
|
|
|
|
some epochRef.get()
|
|
|
|
|
2021-12-03 15:04:58 +00:00
|
|
|
epochRefVar.get
|
|
|
|
|
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-11-12 22:29:28 +00:00
|
|
|
if uint64(request.validator_index) >=
|
|
|
|
lenu64(getStateField(node.dag.headState.data, validators)):
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
2021-12-03 15:04:58 +00:00
|
|
|
InvalidValidatorIndexValueError)
|
2021-03-23 22:50:18 +00:00
|
|
|
if wallSlot > request.slot + 1:
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, SlotFromThePastError)
|
2021-12-03 15:04:58 +00:00
|
|
|
|
2021-03-23 22:50:18 +00:00
|
|
|
let epoch = request.slot.epoch
|
2021-12-03 15:04:58 +00:00
|
|
|
let epochRef = if epoch == wallEpoch:
|
|
|
|
currentEpoch.getAndCacheEpochRef(wallEpoch)
|
|
|
|
elif epoch == wallEpoch + 1:
|
|
|
|
nextEpoch.getAndCacheEpochRef(wallEpoch + 1)
|
|
|
|
else:
|
2021-04-08 14:34:05 +00:00
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
SlotNotInNextWallSlotEpochError)
|
2021-12-03 15:04:58 +00:00
|
|
|
|
2021-10-20 09:16:48 +00:00
|
|
|
let subnet_id = compute_subnet_for_attestation(
|
2021-03-23 22:50:18 +00:00
|
|
|
get_committee_count_per_slot(epochRef), request.slot,
|
|
|
|
request.committee_index)
|
2021-10-18 09:11:44 +00:00
|
|
|
|
|
|
|
node.registerDuty(
|
2021-10-20 09:16:48 +00:00
|
|
|
request.slot, subnet_id, request.validator_index,
|
2021-10-18 09:11:44 +00:00
|
|
|
request.is_aggregator)
|
|
|
|
|
2021-12-20 19:20:31 +00:00
|
|
|
let validator_pubkey = getStateField(
|
|
|
|
node.dag.headState.data, validators).asSeq()[request.validator_index].pubkey
|
|
|
|
|
|
|
|
node.validatorMonitor[].addAutoMonitor(
|
|
|
|
validator_pubkey, ValidatorIndex(request.validator_index))
|
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
return RestApiResponse.jsonMsgResponse(BeaconCommitteeSubscriptionSuccess)
|
2021-04-13 10:19:31 +00:00
|
|
|
|
2021-09-23 22:13:25 +00:00
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/prepareSyncCommitteeSubnets
|
|
|
|
router.api(MethodPost,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/eth/v1/validator/sync_committee_subscriptions") do (
|
2021-09-23 22:13:25 +00:00
|
|
|
contentBody: Option[ContentBody]) -> RestApiResponse:
|
|
|
|
let subscriptions =
|
|
|
|
block:
|
|
|
|
if contentBody.isNone():
|
|
|
|
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
|
|
|
|
let dres = decodeBody(seq[RestSyncCommitteeSubscription],
|
|
|
|
contentBody.get())
|
|
|
|
if dres.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidSyncCommitteeSubscriptionRequestError)
|
|
|
|
let subs = dres.get()
|
|
|
|
for item in subs:
|
|
|
|
if item.until_epoch > MaxEpoch:
|
|
|
|
return RestApiResponse.jsonError(Http400, EpochOverflowValueError)
|
|
|
|
if item.until_epoch < node.dag.cfg.ALTAIR_FORK_EPOCH:
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
EpochFromTheIncorrectForkError)
|
|
|
|
if uint64(item.validator_index) >=
|
|
|
|
lenu64(getStateField(node.dag.headState.data, validators)):
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidValidatorIndexValueError)
|
2021-12-20 19:20:31 +00:00
|
|
|
let validator_pubkey = getStateField(
|
|
|
|
node.dag.headState.data, validators).asSeq()[item.validator_index].pubkey
|
|
|
|
|
|
|
|
node.validatorMonitor[].addAutoMonitor(
|
|
|
|
validator_pubkey, ValidatorIndex(item.validator_index))
|
|
|
|
|
2021-09-23 22:13:25 +00:00
|
|
|
subs
|
|
|
|
|
2022-01-08 20:06:34 +00:00
|
|
|
# TODO because we subscribe to all sync committee subnets, we don not need
|
|
|
|
# to remember which ones are requested by validator clients
|
2021-09-23 22:13:25 +00:00
|
|
|
return RestApiResponse.jsonMsgResponse(SyncCommitteeSubscriptionSuccess)
|
|
|
|
|
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/produceSyncCommitteeContribution
|
|
|
|
router.api(MethodGet,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/eth/v1/validator/sync_committee_contribution") do (
|
2022-01-17 15:44:28 +00:00
|
|
|
slot: Option[Slot], subcommittee_index: Option[SyncSubCommitteeIndex],
|
2021-09-23 22:13:25 +00:00
|
|
|
beacon_block_root: Option[Eth2Digest]) -> RestApiResponse:
|
|
|
|
let qslot =
|
|
|
|
if slot.isNone():
|
|
|
|
return RestApiResponse.jsonError(Http400, MissingSlotValueError)
|
|
|
|
else:
|
|
|
|
let res = slot.get()
|
|
|
|
if res.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400, InvalidSlotValueError,
|
|
|
|
$res.error())
|
|
|
|
let rslot = res.get()
|
|
|
|
if epoch(rslot) < node.dag.cfg.ALTAIR_FORK_EPOCH:
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
SlotFromTheIncorrectForkError)
|
|
|
|
rslot
|
|
|
|
let qindex =
|
|
|
|
if subcommittee_index.isNone():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
MissingSubCommitteeIndexValueError)
|
|
|
|
else:
|
2022-01-17 15:44:28 +00:00
|
|
|
let res = subcommittee_index.get()
|
2021-09-23 22:13:25 +00:00
|
|
|
if res.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
2022-01-08 23:28:49 +00:00
|
|
|
InvalidSubCommitteeIndexValueError,
|
|
|
|
$res.error())
|
|
|
|
res.get()
|
2021-09-23 22:13:25 +00:00
|
|
|
let qroot =
|
|
|
|
if beacon_block_root.isNone():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
MissingBeaconBlockRootValueError)
|
|
|
|
else:
|
|
|
|
let res = beacon_block_root.get()
|
|
|
|
if res.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidBeaconBlockRootValueError,
|
|
|
|
$res.error())
|
|
|
|
res.get()
|
|
|
|
|
|
|
|
# Check if node is fully synced.
|
|
|
|
let sres = node.getCurrentHead(qslot)
|
|
|
|
if sres.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
|
|
|
|
|
|
|
var contribution = SyncCommitteeContribution()
|
|
|
|
let res = node.syncCommitteeMsgPool[].produceContribution(
|
2021-09-28 18:02:01 +00:00
|
|
|
qslot, qroot, qindex, contribution)
|
2021-09-23 22:13:25 +00:00
|
|
|
if not(res):
|
|
|
|
return RestApiResponse.jsonError(Http400, ProduceContributionError)
|
|
|
|
return RestApiResponse.jsonResponse(contribution)
|
|
|
|
|
|
|
|
# https://ethereum.github.io/beacon-APIs/#/Validator/publishContributionAndProofs
|
|
|
|
router.api(MethodPost,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/eth/v1/validator/contribution_and_proofs") do (
|
2021-09-23 22:13:25 +00:00
|
|
|
contentBody: Option[ContentBody]) -> RestApiResponse:
|
|
|
|
let proofs =
|
|
|
|
block:
|
|
|
|
if contentBody.isNone():
|
|
|
|
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
|
|
|
|
let dres = decodeBody(seq[SignedContributionAndProof],
|
|
|
|
contentBody.get())
|
|
|
|
if dres.isErr():
|
|
|
|
return RestApiResponse.jsonError(Http400,
|
|
|
|
InvalidContributionAndProofMessageError)
|
|
|
|
dres.get()
|
|
|
|
|
|
|
|
let pending =
|
|
|
|
block:
|
|
|
|
var res: seq[Future[SendResult]]
|
|
|
|
for proof in proofs:
|
|
|
|
res.add(node.sendSyncCommitteeContribution(proof, true))
|
|
|
|
res
|
|
|
|
|
|
|
|
let failures =
|
|
|
|
block:
|
|
|
|
var res: seq[RestAttestationsFailure]
|
|
|
|
await allFutures(pending)
|
|
|
|
for index, future in pending.pairs():
|
|
|
|
if future.done():
|
|
|
|
let fres = future.read()
|
|
|
|
if fres.isErr():
|
|
|
|
let failure = RestAttestationsFailure(index: uint64(index),
|
|
|
|
message: $fres.error())
|
|
|
|
res.add(failure)
|
|
|
|
elif future.failed() or future.cancelled():
|
|
|
|
# This is unexpected failure, so we log the error message.
|
|
|
|
let exc = future.readError()
|
|
|
|
let failure = RestAttestationsFailure(index: uint64(index),
|
|
|
|
message: $exc.msg)
|
|
|
|
res.add(failure)
|
|
|
|
res
|
|
|
|
|
|
|
|
if len(failures) > 0:
|
|
|
|
return RestApiResponse.jsonErrorList(Http400,
|
|
|
|
ContributionAndProofValidationError,
|
|
|
|
failures)
|
|
|
|
else:
|
|
|
|
return RestApiResponse.jsonMsgResponse(
|
|
|
|
ContributionAndProofValidationSuccess
|
|
|
|
)
|
|
|
|
|
2022-01-06 07:38:40 +00:00
|
|
|
# Legacy URLS - Nimbus <= 1.5.5 used to expose the REST API with an additional
|
|
|
|
# `/api` path component
|
2021-04-13 10:19:31 +00:00
|
|
|
router.redirect(
|
|
|
|
MethodPost,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/duties/attester/{epoch}",
|
|
|
|
"/eth/v1/validator/duties/attester/{epoch}"
|
2021-04-13 10:19:31 +00:00
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/duties/proposer/{epoch}",
|
|
|
|
"/eth/v1/validator/duties/proposer/{epoch}"
|
2021-04-13 10:19:31 +00:00
|
|
|
)
|
2021-10-14 10:38:38 +00:00
|
|
|
router.redirect(
|
|
|
|
MethodPost,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/duties/sync/{epoch}",
|
|
|
|
"/eth/v1/validator/duties/sync/{epoch}"
|
2021-10-14 10:38:38 +00:00
|
|
|
)
|
2021-04-13 10:19:31 +00:00
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/blocks/{slot}",
|
|
|
|
"/eth/v1/validator/blocks/{slot}"
|
2021-04-13 10:19:31 +00:00
|
|
|
)
|
2021-08-09 06:08:18 +00:00
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v2/validator/blocks/{slot}",
|
|
|
|
"/eth/v2/validator/blocks/{slot}"
|
2021-08-09 06:08:18 +00:00
|
|
|
)
|
2021-04-13 10:19:31 +00:00
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/attestation_data",
|
|
|
|
"/eth/v1/validator/attestation_data"
|
2021-04-13 10:19:31 +00:00
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/aggregate_attestation",
|
|
|
|
"/eth/v1/validator/aggregate_attestation"
|
2021-04-13 10:19:31 +00:00
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodPost,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/aggregate_and_proofs",
|
|
|
|
"/eth/v1/validator/aggregate_and_proofs"
|
2021-04-13 10:19:31 +00:00
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodPost,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/beacon_committee_subscriptions",
|
|
|
|
"/eth/v1/validator/beacon_committee_subscriptions"
|
2021-04-13 10:19:31 +00:00
|
|
|
)
|
2021-09-23 22:13:25 +00:00
|
|
|
router.redirect(
|
|
|
|
MethodPost,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/sync_committee_subscriptions",
|
|
|
|
"/eth/v1/validator/sync_committee_subscriptions"
|
2021-09-23 22:13:25 +00:00
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/sync_committee_contribution",
|
|
|
|
"/eth/v1/validator/sync_committee_contribution"
|
2021-09-23 22:13:25 +00:00
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodPost,
|
2022-01-06 07:38:40 +00:00
|
|
|
"/api/eth/v1/validator/contribution_and_proofs",
|
|
|
|
"/eth/v1/validator/contribution_and_proofs"
|
2021-09-23 22:13:25 +00:00
|
|
|
)
|