Finish error message to constants process.
This commit is contained in:
parent
b3ad573b1f
commit
5268d03b68
|
@ -145,8 +145,7 @@ proc installNimbusApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
node.graffitiBytes = value.get().get()
|
||||
return RestApiResponse.jsonResponse((result: true))
|
||||
else:
|
||||
return RestApiResponse.jsonError(
|
||||
Http400, "You must specify a valid graffiti string")
|
||||
return RestApiResponse.jsonError(Http400, InvalidGraffitiBytesValye)
|
||||
|
||||
router.api(MethodGet, "/api/nimbus/v1/graffiti") do (
|
||||
) -> RestApiResponse:
|
||||
|
@ -159,7 +158,7 @@ proc installNimbusApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
block:
|
||||
let res = log_level.get()
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http400, "Invalid log_level value",
|
||||
return RestApiResponse.jsonError(Http400, InvalidLogLevelValueError,
|
||||
$res.error())
|
||||
res.get()
|
||||
{.gcsafe.}:
|
||||
|
@ -182,7 +181,7 @@ proc installNimbusApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
block:
|
||||
let res = node.getCurrentHead(wallSlot)
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http503, "Node is not synced yet")
|
||||
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
||||
res.get()
|
||||
let proposalState = assignClone(node.chainDag.headState)
|
||||
node.chainDag.withState(proposalState[], head.atSlot(wallSlot)):
|
||||
|
|
|
@ -162,25 +162,23 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
let connectionMask =
|
||||
block:
|
||||
if state.isErr():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Invalid state value(s)",
|
||||
return RestApiResponse.jsonError(Http400, InvalidPeerStateValueError,
|
||||
$state.error())
|
||||
let sres = validateState(state.get())
|
||||
if sres.isErr():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Invalid state value(s)",
|
||||
return RestApiResponse.jsonError(Http400, InvalidPeerStateValueError,
|
||||
$sres.error())
|
||||
sres.get()
|
||||
let directionMask =
|
||||
block:
|
||||
if direction.isErr():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Invalid direction value(s)",
|
||||
InvalidPeerDirectionValueError,
|
||||
$direction.error())
|
||||
let dres = validateDirection(direction.get())
|
||||
if dres.isErr():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Invalid direction value(s)",
|
||||
InvalidPeerDirectionValueError,
|
||||
$dres.error())
|
||||
dres.get()
|
||||
|
||||
|
@ -221,12 +219,11 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
let peer =
|
||||
block:
|
||||
if peer_id.isErr():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Unable to parse PeerID value",
|
||||
return RestApiResponse.jsonError(Http400, InvalidPeerIdValueError,
|
||||
$peer_id.error())
|
||||
let res = node.network.peers.getOrDefault(peer_id.get())
|
||||
if isNil(res):
|
||||
return RestApiResponse.jsonError(Http404, "Peer not found")
|
||||
return RestApiResponse.jsonError(Http404, PeerNotFoundError)
|
||||
res
|
||||
return RestApiResponse.jsonResponse(
|
||||
(
|
||||
|
|
|
@ -38,6 +38,8 @@ const
|
|||
"Beacon node is currently syncing and not serving request on that endpoint"
|
||||
BlockNotFoundError* =
|
||||
"Block header/data has not been found"
|
||||
BlockProduceError* =
|
||||
"Could not produce the block"
|
||||
EmptyRequestBodyError* =
|
||||
"Empty request's body"
|
||||
InvalidBlockObjectError* =
|
||||
|
@ -66,6 +68,13 @@ const
|
|||
"Invalid voluntary exit, it will never pass validation so it's rejected"
|
||||
VoluntaryExitValidationSuccess* =
|
||||
"Voluntary exit object(s) was broadcasted"
|
||||
InvalidAggregateAndProofObjectError* =
|
||||
"Unable to decode aggregate and proof object(s)"
|
||||
AggregateAndProofValidationError* =
|
||||
"Invalid aggregate and proof, it will never pass validation so it's " &
|
||||
"rejected"
|
||||
AggregateAndProofValidationSuccess* =
|
||||
"Aggregate and proof object(s) was broadcasted"
|
||||
InvalidParentRootValueError* =
|
||||
"Invalid parent root value"
|
||||
MissingSlotValueError* =
|
||||
|
@ -76,6 +85,18 @@ const
|
|||
"Missing `committee_index` value"
|
||||
InvalidCommitteeIndexValueError* =
|
||||
"Invalid committee index value"
|
||||
MissingAttestationDataRootValueError* =
|
||||
"Missing `attestation_data_root` value"
|
||||
InvalidAttestationDataRootValueError* =
|
||||
"Invalid attestation data root value"
|
||||
UnableToGetAggregatedAttestationError* =
|
||||
"Unable to retrieve an aggregated attestation"
|
||||
MissingRandaoRevealValue* =
|
||||
"Missing `randao_reveal` value"
|
||||
InvalidRandaoRevealValue* =
|
||||
"Invalid randao reveal value"
|
||||
InvalidGraffitiBytesValye* =
|
||||
"Invalid graffiti bytes value"
|
||||
InvalidEpochValueError* =
|
||||
"Invalid epoch value"
|
||||
InvalidStateIdValueError* =
|
||||
|
@ -88,6 +109,12 @@ const
|
|||
"Maximum number of validator identifier values exceeded"
|
||||
InvalidValidatorStatusValueError* =
|
||||
"Invalid validator's status value error"
|
||||
InvalidValidatorIndexValueError* =
|
||||
"Invalid validator's index value(s)"
|
||||
EmptyValidatorIndexArrayError* =
|
||||
"Empty validator's index array"
|
||||
InvalidSubscriptionRequestValueError* =
|
||||
"Invalid subscription request object(s)"
|
||||
ValidatorNotFoundError* =
|
||||
"Could not find validator"
|
||||
ValidatorStatusNotFoundError* =
|
||||
|
@ -104,10 +131,26 @@ const
|
|||
"State not found"
|
||||
SlotNotFoundError* =
|
||||
"Slot number is too far away"
|
||||
SlotNotInNextWallSlotEpochError* =
|
||||
"Requested slot not in next wall-slot epoch"
|
||||
SlotFromThePastError* =
|
||||
"Requested slot from the past"
|
||||
ProposerNotFoundError* =
|
||||
"Could not find proposer for the head and slot"
|
||||
NoHeadForSlotError* =
|
||||
"Cound not find head for slot"
|
||||
EpochOverflowValueError* =
|
||||
"Requesting epoch for which slot would overflow"
|
||||
InvalidPeerStateValueError* =
|
||||
"Invalid peer's state value(s) error"
|
||||
InvalidPeerDirectionValueError* =
|
||||
"Invalid peer's direction value(s) error"
|
||||
InvalidPeerIdValueError* =
|
||||
"Invalid peer's id value(s) error"
|
||||
PeerNotFoundError* =
|
||||
"Peer not found"
|
||||
InvalidLogLevelValueError* =
|
||||
"Invalid log level value error"
|
||||
InternalServerError* =
|
||||
"Internal server error"
|
||||
NoImplementationError* =
|
||||
|
|
|
@ -50,8 +50,9 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
|
||||
let dres = decodeBody(seq[RestValidatorIndex], contentBody.get())
|
||||
if dres.isErr():
|
||||
return RestApiResponse.jsonError(Http400, "Unable to decode " &
|
||||
"list of validator indexes", $dres.error())
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
InvalidValidatorIndexValueError,
|
||||
$dres.error())
|
||||
var res: seq[ValidatorIndex]
|
||||
let items = dres.get()
|
||||
for item in items:
|
||||
|
@ -66,7 +67,8 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
UnsupportedValidatorIndexValueError)
|
||||
res.add(vres.get())
|
||||
if len(res) == 0:
|
||||
return RestApiResponse.jsonError(Http400, "Empty indexes list")
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
EmptyValidatorIndexArrayError)
|
||||
res
|
||||
let qepoch =
|
||||
block:
|
||||
|
@ -96,8 +98,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
if not(node.isSynced(node.chainDag.head)):
|
||||
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
||||
else:
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Cound not find slot data")
|
||||
return RestApiResponse.jsonError(Http400, BlockNotFoundError)
|
||||
bref.root
|
||||
else:
|
||||
node.chainDag.genesis.root
|
||||
|
@ -195,15 +196,15 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
return RestApiResponse.jsonError(Http400, InvalidSlotValueError,
|
||||
$slot.error())
|
||||
slot.get()
|
||||
|
||||
let qrandao =
|
||||
if randao_reveal.isNone():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Missing randao_reveal value")
|
||||
return RestApiResponse.jsonError(Http400, MissingRandaoRevealValue)
|
||||
else:
|
||||
let res = randao_reveal.get()
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Incorrect randao_reveal value",
|
||||
InvalidRandaoRevealValue,
|
||||
$res.error())
|
||||
res.get()
|
||||
let qgraffiti =
|
||||
|
@ -213,7 +214,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
let res = graffiti.get()
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Incorrect graffiti bytes value",
|
||||
InvalidGraffitiBytesValye,
|
||||
$res.error())
|
||||
res.get()
|
||||
let qhead =
|
||||
|
@ -228,14 +229,13 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
res.get()
|
||||
let proposer = node.chainDag.getProposer(qhead, qslot)
|
||||
if proposer.isNone():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Could not retrieve block for slot")
|
||||
return RestApiResponse.jsonError(Http400, ProposerNotFoundError)
|
||||
let res = makeBeaconBlockForHeadAndSlot(
|
||||
node, qrandao, proposer.get()[0], qgraffiti, qhead, qslot)
|
||||
if res.isNone():
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Could not make block for slot")
|
||||
return RestApiResponse.jsonError(Http400, BlockProduceError)
|
||||
res.get()
|
||||
|
||||
return RestApiResponse.jsonResponse(message)
|
||||
|
||||
# https://ethereum.github.io/eth2.0-APIs/#/Validator/produceAttestationData
|
||||
|
@ -296,18 +296,17 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
let qroot =
|
||||
block:
|
||||
if attestation_data_root.isNone():
|
||||
return RestApiResponse.jsonError(Http400, "Missing " &
|
||||
"attestation_data_root value")
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
MissingAttestationDataRootValueError)
|
||||
let res = attestation_data_root.get()
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http400, "Incorrect " &
|
||||
"attestation_data_root value",
|
||||
$res.error())
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
InvalidAttestationDataRootValueError, $res.error())
|
||||
res.get()
|
||||
let res = node.attestationPool[].getAggregatedAttestation(qslot, qroot)
|
||||
if res.isNone():
|
||||
return RestApiResponse.jsonError(Http400, "Could not retrieve an " &
|
||||
"aggregated attestation")
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
UnableToGetAggregatedAttestationError)
|
||||
res.get()
|
||||
return RestApiResponse.jsonResponse(attestation)
|
||||
|
||||
|
@ -320,8 +319,9 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
|
||||
let dres = decodeBody(SignedAggregateAndProof, contentBody.get())
|
||||
if dres.isErr():
|
||||
return RestApiResponse.jsonError(Http400, "Unable to decode " &
|
||||
"SignedAggregateAndProof object", $dres.error())
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
InvalidAggregateAndProofObjectError,
|
||||
$dres.error())
|
||||
dres.get()
|
||||
|
||||
let wallTime = node.processor.getWallTime()
|
||||
|
@ -329,11 +329,12 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
node.processor.batchCrypto, payload, wallTime
|
||||
)
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http400, "Aggregate and proofs " &
|
||||
"verification failed", $res.error())
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
AggregateAndProofValidationError,
|
||||
$res.error())
|
||||
node.network.broadcast(node.topicAggregateAndProofs, payload)
|
||||
return RestApiResponse.jsonError(Http200,
|
||||
"Aggregate and proofs was broadcasted")
|
||||
AggregateAndProofValidationSuccess)
|
||||
|
||||
# https://ethereum.github.io/eth2.0-APIs/#/Validator/prepareBeaconCommitteeSubnet
|
||||
router.api(MethodPost,
|
||||
|
@ -348,8 +349,9 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
let dres = decodeBody(seq[RestCommitteeSubscriptionTuple],
|
||||
contentBody.get())
|
||||
if dres.isErr():
|
||||
return RestApiResponse.jsonError(Http400, "Unable to decode " &
|
||||
"subscription request(s)")
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
InvalidSubscriptionRequestValueError,
|
||||
$dres.error())
|
||||
dres.get()
|
||||
if not(node.isSynced(node.chainDag.head)):
|
||||
return RestApiResponse.jsonError(Http503, BeaconNodeInSyncError)
|
||||
|
@ -364,21 +366,21 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
if uint64(idx) >=
|
||||
lenu64(node.chainDag.headState.data.data.validators):
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
"Invalid validator_index value")
|
||||
InvalidValidatorIndexValueError)
|
||||
node.chainDag.headState.data.data.validators[idx].pubkey
|
||||
|
||||
let wallSlot = node.beaconClock.now.slotOrZero
|
||||
if wallSlot > request.slot + 1:
|
||||
return RestApiResponse.jsonError(Http400, "Past slot requested")
|
||||
return RestApiResponse.jsonError(Http400, SlotFromThePastError)
|
||||
let epoch = request.slot.epoch
|
||||
if epoch >= wallSlot.epoch and epoch - wallSlot.epoch > 1:
|
||||
return RestApiResponse.jsonError(Http400, "Slot requested not in " &
|
||||
"next wall-slot epoch")
|
||||
return RestApiResponse.jsonError(Http400,
|
||||
SlotNotInNextWallSlotEpochError)
|
||||
let head =
|
||||
block:
|
||||
let res = node.getCurrentHead(epoch)
|
||||
if res.isErr():
|
||||
return RestApiResponse.jsonError(Http400, "Unable to obtain head",
|
||||
return RestApiResponse.jsonError(Http400, NoHeadForSlotError,
|
||||
$res.error())
|
||||
res.get()
|
||||
let epochRef = node.chainDag.getEpochRef(head, epoch)
|
||||
|
|
Loading…
Reference in New Issue