2022-07-29 08:36:20 +00:00
|
|
|
# beacon_chain
|
2023-03-04 13:35:39 +00:00
|
|
|
# Copyright (c) 2021-2023 Status Research & Development GmbH
|
2022-07-29 08:36:20 +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.
|
|
|
|
|
2023-07-06 09:14:22 +00:00
|
|
|
import std/strutils
|
|
|
|
import chronicles, stew/base10
|
|
|
|
import ".."/spec/eth2_apis/eth2_rest_serialization,
|
|
|
|
".."/spec/datatypes/[phase0, altair]
|
|
|
|
import "."/[common, fallback_service, scoring]
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2021-10-19 14:09:26 +00:00
|
|
|
export eth2_rest_serialization, common
|
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
const
|
|
|
|
ResponseSuccess = "Received successful response"
|
|
|
|
ResponseInvalidError = "Received invalid request response"
|
|
|
|
ResponseInternalError = "Received internal error response"
|
|
|
|
ResponseUnexpectedError = "Received unexpected error response"
|
|
|
|
ResponseNotFoundError = "Received resource missing error response"
|
|
|
|
ResponseNoSyncError = "Received nosync error response"
|
2023-03-03 20:20:01 +00:00
|
|
|
ResponseDecodeError = "Received response could not be decoded"
|
2023-05-02 11:54:44 +00:00
|
|
|
ResponseECNotInSyncError* = "Execution client not in sync"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
type
|
|
|
|
ApiResponse*[T] = Result[T, string]
|
|
|
|
ApiOperation = enum
|
|
|
|
Success, Timeout, Failure, Interrupt
|
|
|
|
|
2022-07-21 16:54:07 +00:00
|
|
|
ApiNodeResponse*[T] = object
|
|
|
|
node*: BeaconNodeServerRef
|
|
|
|
data*: ApiResponse[T]
|
|
|
|
|
|
|
|
ApiResponseSeq*[T] = object
|
|
|
|
status*: ApiOperation
|
|
|
|
data*: seq[ApiNodeResponse[T]]
|
|
|
|
|
2023-07-06 09:14:22 +00:00
|
|
|
ApiScore* = object
|
|
|
|
index*: int
|
|
|
|
score*: Opt[float64]
|
|
|
|
|
|
|
|
BestNodeResponse*[T] = object
|
|
|
|
node*: BeaconNodeServerRef
|
|
|
|
data*: ApiResponse[T]
|
|
|
|
score*: float64
|
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
const
|
|
|
|
ViableNodeStatus = {RestBeaconNodeStatus.Compatible,
|
|
|
|
RestBeaconNodeStatus.NotSynced,
|
|
|
|
RestBeaconNodeStatus.OptSynced,
|
|
|
|
RestBeaconNodeStatus.Synced}
|
|
|
|
|
2023-07-06 09:14:22 +00:00
|
|
|
proc `$`*(s: ApiScore): string =
|
|
|
|
var res = Base10.toString(uint64(s.index))
|
|
|
|
res.add(": ")
|
|
|
|
if s.score.isSome():
|
|
|
|
res.add(shortScore(s.score.get()))
|
|
|
|
else:
|
|
|
|
res.add("<n/a>")
|
|
|
|
res
|
|
|
|
|
|
|
|
proc `$`*(ss: openArray[ApiScore]): string =
|
|
|
|
"[" & ss.mapIt($it).join(",") & "]"
|
|
|
|
|
|
|
|
chronicles.formatIt(seq[ApiScore]):
|
|
|
|
$it
|
|
|
|
|
|
|
|
func init*(t: typedesc[ApiScore], node: BeaconNodeServerRef,
|
|
|
|
score: float64): ApiScore =
|
|
|
|
ApiScore(index: node.index, score: Opt.some(score))
|
|
|
|
|
|
|
|
func init*(t: typedesc[ApiScore], node: BeaconNodeServerRef): ApiScore =
|
|
|
|
ApiScore(index: node.index, score: Opt.none(float64))
|
|
|
|
|
|
|
|
func init*[T](t: typedesc[BestNodeResponse], node: BeaconNodeServerRef,
|
|
|
|
data: ApiResponse[T], score: float64): BestNodeResponse[T] =
|
|
|
|
BestNodeResponse[T](node: node, data: data, score: score)
|
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
proc lazyWaiter(node: BeaconNodeServerRef, request: FutureBase,
|
|
|
|
requestName: string, strategy: ApiStrategyKind) {.async.} =
|
2022-10-21 14:53:30 +00:00
|
|
|
try:
|
|
|
|
await allFutures(request)
|
|
|
|
if request.failed():
|
2023-05-30 08:38:34 +00:00
|
|
|
let failure = ApiNodeFailure.init(
|
|
|
|
ApiFailure.Communication, requestName, strategy, node,
|
|
|
|
$request.error.msg)
|
|
|
|
node.updateStatus(RestBeaconNodeStatus.Offline, failure)
|
2023-09-24 07:28:09 +00:00
|
|
|
except CancelledError:
|
2022-10-21 14:53:30 +00:00
|
|
|
await cancelAndWait(request)
|
|
|
|
|
|
|
|
proc lazyWait(nodes: seq[BeaconNodeServerRef], requests: seq[FutureBase],
|
2023-05-30 08:38:34 +00:00
|
|
|
timerFut: Future[void], requestName: string,
|
|
|
|
strategy: ApiStrategyKind) {.async.} =
|
2022-10-21 14:53:30 +00:00
|
|
|
doAssert(len(nodes) == len(requests))
|
|
|
|
if len(nodes) == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
var futures: seq[Future[void]]
|
|
|
|
for index in 0 ..< len(requests):
|
2023-05-30 08:38:34 +00:00
|
|
|
futures.add(lazyWaiter(nodes[index], requests[index], requestName,
|
|
|
|
strategy))
|
2022-10-21 14:53:30 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if not(isNil(timerFut)):
|
|
|
|
await allFutures(futures) or timerFut
|
|
|
|
if timerFut.finished():
|
|
|
|
var pending: seq[Future[void]]
|
|
|
|
for future in futures:
|
|
|
|
if not(future.finished()):
|
|
|
|
pending.add(future.cancelAndWait())
|
|
|
|
await allFutures(pending)
|
|
|
|
else:
|
|
|
|
await cancelAndWait(timerFut)
|
|
|
|
else:
|
|
|
|
await allFutures(futures)
|
|
|
|
|
2023-07-06 09:14:22 +00:00
|
|
|
proc apiResponseOr[T](future: FutureBase, timerFut: Future[void],
|
|
|
|
message: string): ApiResponse[T] =
|
2023-08-16 16:14:39 +00:00
|
|
|
if future.finished() and not(future.cancelled()):
|
2023-07-06 09:14:22 +00:00
|
|
|
if future.failed():
|
|
|
|
ApiResponse[T].err($future.error.msg)
|
|
|
|
else:
|
|
|
|
ApiResponse[T].ok(Future[T](future).read())
|
|
|
|
else:
|
2023-08-16 16:14:39 +00:00
|
|
|
if timerFut.finished():
|
|
|
|
ApiResponse[T].err(message)
|
|
|
|
else:
|
|
|
|
ApiResponse[T].err("Interrupted by the caller")
|
2023-07-06 09:14:22 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
template firstSuccessParallel*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
responseType: typedesc,
|
2023-03-03 20:20:01 +00:00
|
|
|
handlerType: typedesc,
|
2022-09-29 07:57:14 +00:00
|
|
|
timeout: Duration,
|
2023-02-23 00:11:00 +00:00
|
|
|
statuses: set[RestBeaconNodeStatus],
|
2022-09-29 07:57:14 +00:00
|
|
|
roles: set[BeaconNodeRole],
|
|
|
|
body1, body2: untyped
|
2023-03-03 20:20:01 +00:00
|
|
|
): ApiResponse[handlerType] =
|
2023-02-23 00:11:00 +00:00
|
|
|
var
|
|
|
|
it {.inject.}: RestClientRef
|
|
|
|
iterations = 0
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
var timerFut =
|
|
|
|
if timeout != InfiniteDuration:
|
|
|
|
sleepAsync(timeout)
|
|
|
|
else:
|
|
|
|
nil
|
|
|
|
|
2023-03-03 20:20:01 +00:00
|
|
|
var retRes: ApiResponse[handlerType]
|
2022-09-29 07:57:14 +00:00
|
|
|
while true:
|
|
|
|
var resultReady = false
|
|
|
|
let onlineNodes =
|
|
|
|
try:
|
2023-02-23 00:11:00 +00:00
|
|
|
if iterations == 0:
|
|
|
|
# We are not going to wait for BNs if there some available.
|
|
|
|
await vc.waitNodes(timerFut, statuses, roles, false)
|
|
|
|
else:
|
|
|
|
# We get here only, if all the requests are failed. To avoid requests
|
|
|
|
# spam we going to wait for changes in BNs statuses.
|
|
|
|
await vc.waitNodes(timerFut, statuses, roles, true)
|
|
|
|
vc.filterNodes(statuses, roles)
|
2022-09-29 07:57:14 +00:00
|
|
|
except CancelledError as exc:
|
|
|
|
if not(isNil(timerFut)) and not(timerFut.finished()):
|
|
|
|
await timerFut.cancelAndWait()
|
|
|
|
raise exc
|
|
|
|
except CatchableError as exc:
|
|
|
|
# This case could not be happened.
|
|
|
|
error "Unexpected exception while waiting for beacon nodes",
|
|
|
|
err_name = $exc.name, err_msg = $exc.msg
|
2023-07-06 09:14:22 +00:00
|
|
|
default(seq[BeaconNodeServerRef])
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
if len(onlineNodes) == 0:
|
2023-03-03 20:20:01 +00:00
|
|
|
retRes = ApiResponse[handlerType].err("No online beacon node(s)")
|
2022-09-29 07:57:14 +00:00
|
|
|
resultReady = true
|
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
var
|
|
|
|
(pendingRequests, pendingNodes) =
|
|
|
|
block:
|
|
|
|
var requests: seq[FutureBase]
|
|
|
|
var nodes: seq[BeaconNodeServerRef]
|
|
|
|
for node {.inject.} in onlineNodes:
|
|
|
|
it = node.client
|
|
|
|
let fut = FutureBase(body1)
|
|
|
|
requests.add(fut)
|
|
|
|
nodes.add(node)
|
|
|
|
(requests, nodes)
|
|
|
|
raceFut: Future[FutureBase]
|
|
|
|
requestsCancelled = false
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
while true:
|
|
|
|
try:
|
|
|
|
if len(pendingRequests) == 0:
|
|
|
|
if not(isNil(timerFut)) and not(timerFut.finished()):
|
|
|
|
await timerFut.cancelAndWait()
|
2023-03-03 20:20:01 +00:00
|
|
|
retRes = ApiResponse[handlerType].err(
|
2022-09-29 07:57:14 +00:00
|
|
|
"Beacon node(s) unable to satisfy request")
|
|
|
|
resultReady = true
|
2023-05-30 08:38:34 +00:00
|
|
|
break
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
raceFut = race(pendingRequests)
|
|
|
|
|
2023-08-16 16:14:39 +00:00
|
|
|
if not(isNil(timerFut)):
|
2022-09-29 07:57:14 +00:00
|
|
|
await raceFut or timerFut
|
|
|
|
else:
|
|
|
|
await allFutures(raceFut)
|
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
let
|
|
|
|
index =
|
|
|
|
if not(isNil(timerFut)) and timerFut.finished():
|
|
|
|
# Timeout exceeded first.
|
|
|
|
if not(requestsCancelled):
|
|
|
|
var pending: seq[Future[void]]
|
|
|
|
pending.add(raceFut.cancelAndWait())
|
|
|
|
for future in pendingRequests.items():
|
|
|
|
if not(future.finished()):
|
|
|
|
pending.add(future.cancelAndWait())
|
|
|
|
await allFutures(pending)
|
|
|
|
requestsCancelled = true
|
|
|
|
0
|
|
|
|
else:
|
|
|
|
let res = pendingRequests.find(raceFut.read())
|
|
|
|
doAssert(res >= 0)
|
|
|
|
res
|
|
|
|
requestFut = pendingRequests[index]
|
|
|
|
beaconNode = pendingNodes[index]
|
|
|
|
|
|
|
|
# Remove completed future from pending list.
|
|
|
|
pendingRequests.del(index)
|
|
|
|
pendingNodes.del(index)
|
|
|
|
|
|
|
|
let
|
|
|
|
node {.inject.} = beaconNode
|
|
|
|
apiResponse {.inject.} =
|
2023-07-06 09:14:22 +00:00
|
|
|
apiResponseOr[responseType](requestFut, timerFut,
|
|
|
|
"Timeout exceeded while awaiting for the response")
|
2023-05-30 08:38:34 +00:00
|
|
|
handlerResponse =
|
|
|
|
try:
|
|
|
|
body2
|
|
|
|
except CancelledError as exc:
|
|
|
|
raise exc
|
|
|
|
except CatchableError:
|
|
|
|
raiseAssert("Response handler must not raise exceptions")
|
|
|
|
|
2023-07-06 09:14:22 +00:00
|
|
|
if handlerResponse.isOk():
|
2023-05-30 08:38:34 +00:00
|
|
|
retRes = handlerResponse
|
2022-09-29 07:57:14 +00:00
|
|
|
resultReady = true
|
2023-05-30 08:38:34 +00:00
|
|
|
asyncSpawn lazyWait(pendingNodes, pendingRequests, timerFut,
|
|
|
|
RequestName, strategy)
|
|
|
|
break
|
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
except CancelledError as exc:
|
|
|
|
var pendingCancel: seq[Future[void]]
|
|
|
|
if not(isNil(raceFut)) and not(raceFut.finished()):
|
|
|
|
pendingCancel.add(raceFut.cancelAndWait())
|
|
|
|
if not(isNil(timerFut)) and not(timerFut.finished()):
|
|
|
|
pendingCancel.add(timerFut.cancelAndWait())
|
2023-07-06 09:14:22 +00:00
|
|
|
for future in pendingRequests.items():
|
2022-09-29 07:57:14 +00:00
|
|
|
if not(future.finished()):
|
|
|
|
pendingCancel.add(future.cancelAndWait())
|
2023-09-24 07:28:09 +00:00
|
|
|
await noCancel allFutures(pendingCancel)
|
2022-09-29 07:57:14 +00:00
|
|
|
raise exc
|
|
|
|
except CatchableError as exc:
|
|
|
|
# This should not be happened, because allFutures() and race() did not
|
|
|
|
# raise any exceptions.
|
|
|
|
error "Unexpected exception while processing request",
|
|
|
|
err_name = $exc.name, err_msg = $exc.msg
|
2023-03-03 20:20:01 +00:00
|
|
|
retRes = ApiResponse[handlerType].err("Unexpected error")
|
2022-09-29 07:57:14 +00:00
|
|
|
resultReady = true
|
|
|
|
if resultReady:
|
|
|
|
break
|
|
|
|
if resultReady:
|
|
|
|
break
|
2023-02-23 00:11:00 +00:00
|
|
|
|
|
|
|
inc(iterations)
|
2022-09-29 07:57:14 +00:00
|
|
|
retRes
|
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
template bestSuccess*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
responseType: typedesc,
|
2023-07-06 09:14:22 +00:00
|
|
|
handlerType: typedesc,
|
2023-02-23 00:11:00 +00:00
|
|
|
timeout: Duration,
|
|
|
|
statuses: set[RestBeaconNodeStatus],
|
|
|
|
roles: set[BeaconNodeRole],
|
|
|
|
bodyRequest,
|
2023-07-06 09:14:22 +00:00
|
|
|
bodyScore,
|
|
|
|
bodyHandler: untyped): ApiResponse[handlerType] =
|
|
|
|
var
|
|
|
|
it {.inject.}: RestClientRef
|
|
|
|
iterations = 0
|
2022-07-21 16:54:07 +00:00
|
|
|
|
|
|
|
var timerFut =
|
|
|
|
if timeout != InfiniteDuration:
|
|
|
|
sleepAsync(timeout)
|
|
|
|
else:
|
|
|
|
nil
|
|
|
|
|
2023-07-06 09:14:22 +00:00
|
|
|
var
|
|
|
|
retRes: ApiResponse[handlerType]
|
|
|
|
scores: seq[ApiScore]
|
|
|
|
bestResponse: Opt[BestNodeResponse[handlerType]]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-07-06 09:14:22 +00:00
|
|
|
block mainLoop:
|
|
|
|
while true:
|
|
|
|
let onlineNodes =
|
2022-09-29 07:57:14 +00:00
|
|
|
try:
|
2023-07-06 09:14:22 +00:00
|
|
|
if iterations == 0:
|
|
|
|
# We are not going to wait for BNs if there some available.
|
|
|
|
await vc.waitNodes(timerFut, statuses, roles, false)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-07-06 09:14:22 +00:00
|
|
|
# We get here only, if all the requests are failed. To avoid requests
|
|
|
|
# spam we going to wait for changes in BNs statuses.
|
|
|
|
await vc.waitNodes(timerFut, statuses, roles, true)
|
|
|
|
vc.filterNodes(statuses, roles)
|
2022-09-29 07:57:14 +00:00
|
|
|
except CancelledError as exc:
|
|
|
|
if not(isNil(timerFut)) and not(timerFut.finished()):
|
2023-07-06 09:14:22 +00:00
|
|
|
await timerFut.cancelAndWait()
|
2022-09-29 07:57:14 +00:00
|
|
|
raise exc
|
2023-07-06 09:14:22 +00:00
|
|
|
except CatchableError as exc:
|
|
|
|
# This case could not be happened.
|
|
|
|
error "Unexpected exception while waiting for beacon nodes",
|
|
|
|
err_name = $exc.name, err_msg = $exc.msg
|
|
|
|
default(seq[BeaconNodeServerRef])
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-07-06 09:14:22 +00:00
|
|
|
if len(onlineNodes) == 0:
|
|
|
|
retRes = ApiResponse[handlerType].err("No online beacon node(s)")
|
|
|
|
break mainLoop
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-07-06 09:14:22 +00:00
|
|
|
var
|
|
|
|
(pendingRequests, pendingNodes) =
|
|
|
|
block:
|
|
|
|
var requests: seq[FutureBase]
|
|
|
|
var nodes: seq[BeaconNodeServerRef]
|
|
|
|
for node {.inject.} in onlineNodes:
|
|
|
|
it = node.client
|
|
|
|
let fut = FutureBase(bodyRequest)
|
|
|
|
requests.add(fut)
|
|
|
|
nodes.add(node)
|
|
|
|
(requests, nodes)
|
|
|
|
perfectScoreFound = false
|
|
|
|
|
|
|
|
block innerLoop:
|
|
|
|
while len(pendingRequests) > 0:
|
|
|
|
var
|
|
|
|
finishedRequests: seq[FutureBase]
|
|
|
|
finishedNodes: seq[BeaconNodeServerRef]
|
|
|
|
raceFut: Future[FutureBase]
|
|
|
|
try:
|
|
|
|
raceFut = race(pendingRequests)
|
|
|
|
|
2023-08-16 16:14:39 +00:00
|
|
|
if not(isNil(timerFut)):
|
2023-07-06 09:14:22 +00:00
|
|
|
await raceFut or timerFut
|
|
|
|
else:
|
|
|
|
await allFutures(raceFut)
|
|
|
|
|
|
|
|
for index, future in pendingRequests.pairs():
|
|
|
|
if future.finished() or
|
|
|
|
(not(isNil(timerFut)) and timerFut.finished()):
|
|
|
|
finishedRequests.add(future)
|
|
|
|
finishedNodes.add(pendingNodes[index])
|
|
|
|
let
|
|
|
|
node {.inject.} = pendingNodes[index]
|
|
|
|
apiResponse {.inject.} =
|
|
|
|
apiResponseOr[responseType](future, timerFut,
|
|
|
|
"Timeout exceeded while awaiting for the response")
|
|
|
|
handlerResponse =
|
|
|
|
try:
|
|
|
|
bodyHandler
|
|
|
|
except CancelledError as exc:
|
|
|
|
raise exc
|
|
|
|
except CatchableError:
|
|
|
|
raiseAssert(
|
|
|
|
"Response handler must not raise exceptions")
|
|
|
|
|
|
|
|
if handlerResponse.isOk():
|
|
|
|
let
|
|
|
|
itresponse {.inject.} = handlerResponse.get()
|
|
|
|
score =
|
|
|
|
try:
|
|
|
|
bodyScore
|
|
|
|
except CancelledError as exc:
|
|
|
|
raise exc
|
|
|
|
except CatchableError:
|
|
|
|
raiseAssert("Score handler must not raise exceptions")
|
|
|
|
scores.add(ApiScore.init(node, score))
|
|
|
|
if bestResponse.isNone() or
|
|
|
|
(score > bestResponse.get().score):
|
|
|
|
bestResponse = Opt.some(
|
|
|
|
BestNodeResponse.init(node, handlerResponse, score))
|
|
|
|
if perfectScore(score):
|
|
|
|
perfectScoreFound = true
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
scores.add(ApiScore.init(node))
|
|
|
|
|
|
|
|
if perfectScoreFound:
|
|
|
|
# lazyWait will cancel `pendingRequests` on timeout.
|
|
|
|
asyncSpawn lazyWait(pendingNodes, pendingRequests, timerFut,
|
|
|
|
RequestName, strategy)
|
|
|
|
break innerLoop
|
|
|
|
|
|
|
|
if not(isNil(timerFut)) and timerFut.finished():
|
|
|
|
# If timeout is exceeded we need to cancel all the tasks which
|
|
|
|
# are still running.
|
|
|
|
var pendingCancel: seq[Future[void]]
|
|
|
|
for future in pendingRequests.items():
|
|
|
|
if not(future.finished()):
|
|
|
|
pendingCancel.add(future.cancelAndWait())
|
|
|
|
await allFutures(pendingCancel)
|
|
|
|
break innerLoop
|
|
|
|
|
|
|
|
pendingRequests.keepItIf(it notin finishedRequests)
|
|
|
|
pendingNodes.keepItIf(it notin finishedNodes)
|
|
|
|
|
|
|
|
except CancelledError as exc:
|
|
|
|
var pendingCancel: seq[Future[void]]
|
|
|
|
# `or` operation does not cancelling Futures passed as arguments.
|
|
|
|
if not(isNil(raceFut)) and not(raceFut.finished()):
|
|
|
|
pendingCancel.add(raceFut.cancelAndWait())
|
|
|
|
if not(isNil(timerFut)) and not(timerFut.finished()):
|
|
|
|
pendingCancel.add(timerFut.cancelAndWait())
|
|
|
|
# We should cancel all the requests which are still pending.
|
|
|
|
for future in pendingRequests.items():
|
|
|
|
if not(future.finished()):
|
|
|
|
pendingCancel.add(future.cancelAndWait())
|
|
|
|
# Awaiting cancellations.
|
2023-09-24 07:28:09 +00:00
|
|
|
await noCancel allFutures(pendingCancel)
|
2023-07-06 09:14:22 +00:00
|
|
|
raise exc
|
|
|
|
except CatchableError as exc:
|
|
|
|
# This should not be happened, because allFutures() and race()
|
|
|
|
# did not raise any exceptions.
|
|
|
|
error "Unexpected exception while processing request",
|
|
|
|
err_name = $exc.name, err_msg = $exc.msg
|
|
|
|
retRes = ApiResponse[handlerType].err("Unexpected error")
|
|
|
|
break mainLoop
|
|
|
|
|
|
|
|
if bestResponse.isSome():
|
|
|
|
retRes = bestResponse.get().data
|
|
|
|
break mainLoop
|
|
|
|
else:
|
|
|
|
if timerFut.finished():
|
|
|
|
retRes = ApiResponse[handlerType].err(
|
|
|
|
"Timeout exceeded while awaiting for responses")
|
|
|
|
break mainLoop
|
|
|
|
else:
|
|
|
|
# When all requests failed
|
|
|
|
discard
|
|
|
|
|
|
|
|
inc(iterations)
|
|
|
|
|
|
|
|
if retRes.isOk():
|
|
|
|
debug "Best score result selected",
|
|
|
|
request = RequestName, available_scores = scores,
|
|
|
|
best_score = shortScore(bestResponse.get().score),
|
|
|
|
best_node = bestResponse.get().node
|
|
|
|
|
|
|
|
retRes
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
template onceToAll*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
responseType: typedesc,
|
|
|
|
timeout: Duration,
|
|
|
|
statuses: set[RestBeaconNodeStatus],
|
|
|
|
roles: set[BeaconNodeRole],
|
|
|
|
body: untyped
|
|
|
|
): ApiResponseSeq[responseType] =
|
2022-09-29 07:57:14 +00:00
|
|
|
var it {.inject.}: RestClientRef
|
|
|
|
type BodyType = typeof(body)
|
|
|
|
|
|
|
|
var timerFut =
|
|
|
|
if timeout != InfiniteDuration:
|
|
|
|
sleepAsync(timeout)
|
|
|
|
else:
|
|
|
|
nil
|
|
|
|
|
|
|
|
let onlineNodes =
|
|
|
|
try:
|
2023-02-23 00:11:00 +00:00
|
|
|
await vc.waitNodes(timerFut, statuses, roles, false)
|
|
|
|
vc.filterNodes(statuses, roles)
|
2022-09-29 07:57:14 +00:00
|
|
|
except CancelledError as exc:
|
2022-07-21 16:54:07 +00:00
|
|
|
if not(isNil(timerFut)) and not(timerFut.finished()):
|
|
|
|
await timerFut.cancelAndWait()
|
|
|
|
raise exc
|
|
|
|
except CatchableError as exc:
|
|
|
|
# This case could not be happened.
|
|
|
|
error "Unexpected exception while waiting for beacon nodes",
|
|
|
|
err_name = $exc.name, err_msg = $exc.msg
|
|
|
|
var default: seq[BeaconNodeServerRef]
|
|
|
|
default
|
|
|
|
|
|
|
|
if len(onlineNodes) == 0:
|
|
|
|
# Timeout exceeded or operation was cancelled
|
|
|
|
ApiResponseSeq[responseType](status: ApiOperation.Timeout)
|
|
|
|
else:
|
|
|
|
let (pendingRequests, pendingNodes) =
|
|
|
|
block:
|
|
|
|
var requests: seq[BodyType]
|
|
|
|
var nodes: seq[BeaconNodeServerRef]
|
|
|
|
for node {.inject.} in onlineNodes:
|
|
|
|
it = node.client
|
|
|
|
let fut = body
|
|
|
|
requests.add(fut)
|
|
|
|
nodes.add(node)
|
|
|
|
(requests, nodes)
|
|
|
|
|
|
|
|
let status =
|
|
|
|
try:
|
|
|
|
if isNil(timerFut):
|
|
|
|
await allFutures(pendingRequests)
|
|
|
|
ApiOperation.Success
|
|
|
|
else:
|
|
|
|
let waitFut = allFutures(pendingRequests)
|
|
|
|
discard await race(waitFut, timerFut)
|
|
|
|
if not(waitFut.finished()):
|
|
|
|
await waitFut.cancelAndWait()
|
|
|
|
ApiOperation.Timeout
|
|
|
|
else:
|
|
|
|
if not(timerFut.finished()):
|
|
|
|
await timerFut.cancelAndWait()
|
|
|
|
ApiOperation.Success
|
|
|
|
except CancelledError as exc:
|
|
|
|
# We should cancel all the pending requests and timer before we return
|
|
|
|
# result.
|
|
|
|
var pendingCancel: seq[Future[void]]
|
|
|
|
for fut in pendingRequests:
|
|
|
|
if not(fut.finished()):
|
|
|
|
pendingCancel.add(fut.cancelAndWait())
|
|
|
|
if not(isNil(timerFut)) and not(timerFut.finished()):
|
|
|
|
pendingCancel.add(timerFut.cancelAndWait())
|
2023-09-24 07:28:09 +00:00
|
|
|
await noCancel allFutures(pendingCancel)
|
2022-07-21 16:54:07 +00:00
|
|
|
raise exc
|
|
|
|
except CatchableError:
|
|
|
|
# This should not be happened, because allFutures() and race() did not
|
|
|
|
# raise any exceptions.
|
|
|
|
ApiOperation.Failure
|
|
|
|
|
|
|
|
let responses =
|
|
|
|
block:
|
|
|
|
var res: seq[ApiNodeResponse[responseType]]
|
|
|
|
for idx, pnode in pendingNodes.pairs():
|
|
|
|
let apiResponse =
|
|
|
|
block:
|
|
|
|
let fut = pendingRequests[idx]
|
|
|
|
if fut.finished():
|
|
|
|
if fut.failed() or fut.cancelled():
|
|
|
|
let exc = fut.readError()
|
|
|
|
ApiNodeResponse[responseType](
|
|
|
|
node: pnode,
|
|
|
|
data: ApiResponse[responseType].err("[" & $exc.name & "] " &
|
|
|
|
$exc.msg)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
ApiNodeResponse[responseType](
|
|
|
|
node: pnode,
|
|
|
|
data: ApiResponse[responseType].ok(fut.read())
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
case status
|
|
|
|
of ApiOperation.Interrupt:
|
|
|
|
ApiNodeResponse[responseType](
|
|
|
|
node: pnode,
|
|
|
|
data: ApiResponse[responseType].err("Operation interrupted")
|
|
|
|
)
|
|
|
|
of ApiOperation.Timeout:
|
|
|
|
pendingNodes[idx].status = RestBeaconNodeStatus.Offline
|
|
|
|
ApiNodeResponse[responseType](
|
|
|
|
node: pnode,
|
|
|
|
data: ApiResponse[responseType].err(
|
|
|
|
"Operation timeout exceeded")
|
|
|
|
)
|
|
|
|
of ApiOperation.Success, ApiOperation.Failure:
|
|
|
|
# This should not be happened, because all Futures should be
|
|
|
|
# finished, and `Failure` processed when Future is finished.
|
|
|
|
ApiNodeResponse[responseType](
|
|
|
|
node: pnode,
|
|
|
|
data: ApiResponse[responseType].err("Unexpected error")
|
|
|
|
)
|
|
|
|
res.add(apiResponse)
|
|
|
|
res
|
|
|
|
|
|
|
|
ApiResponseSeq[responseType](status: status, data: responses)
|
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
template firstSuccessSequential*(
|
|
|
|
vc: ValidatorClientRef,
|
2023-03-03 20:20:01 +00:00
|
|
|
responseType: typedesc,
|
2023-02-23 00:11:00 +00:00
|
|
|
timeout: Duration,
|
|
|
|
statuses: set[RestBeaconNodeStatus],
|
|
|
|
roles: set[BeaconNodeRole],
|
|
|
|
body: untyped,
|
|
|
|
handlers: untyped
|
|
|
|
): untyped =
|
2021-07-13 11:15:07 +00:00
|
|
|
doAssert(timeout != ZeroDuration)
|
2023-02-23 00:11:00 +00:00
|
|
|
var
|
|
|
|
it {.inject.}: RestClientRef
|
|
|
|
iterations = 0
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
var timerFut =
|
|
|
|
if timeout != InfiniteDuration:
|
|
|
|
sleepAsync(timeout)
|
|
|
|
else:
|
|
|
|
nil
|
|
|
|
|
|
|
|
while true:
|
2022-07-14 21:11:25 +00:00
|
|
|
let onlineNodes =
|
|
|
|
try:
|
2023-02-23 00:11:00 +00:00
|
|
|
if iterations == 0:
|
|
|
|
# We are not going to wait for BNs if there some available.
|
|
|
|
await vc.waitNodes(timerFut, statuses, roles, false)
|
|
|
|
else:
|
|
|
|
# We get here only, if all the requests are failed. To avoid requests
|
|
|
|
# spam we going to wait for changes in BNs statuses.
|
|
|
|
await vc.waitNodes(timerFut, statuses, roles, true)
|
|
|
|
vc.filterNodes(statuses, roles)
|
2022-07-14 21:11:25 +00:00
|
|
|
except CancelledError as exc:
|
2023-02-23 00:11:00 +00:00
|
|
|
# waitNodes do not cancel `timoutFuture`.
|
2022-07-14 21:11:25 +00:00
|
|
|
if not(isNil(timerFut)) and not(timerFut.finished()):
|
|
|
|
await timerFut.cancelAndWait()
|
|
|
|
raise exc
|
|
|
|
except CatchableError:
|
|
|
|
# This case could not be happened.
|
|
|
|
var default: seq[BeaconNodeServerRef]
|
|
|
|
default
|
|
|
|
|
|
|
|
if len(onlineNodes) == 0:
|
|
|
|
# `onlineNodes` sequence is empty only if operation timeout exceeded.
|
|
|
|
break
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
if iterations != 0:
|
|
|
|
debug "Request got failed", iterations_count = iterations
|
2021-07-13 11:15:07 +00:00
|
|
|
|
|
|
|
var exitNow = false
|
|
|
|
|
|
|
|
for node {.inject.} in onlineNodes:
|
|
|
|
it = node.client
|
|
|
|
var bodyFut = body
|
|
|
|
|
|
|
|
let resOp =
|
|
|
|
block:
|
|
|
|
if isNil(timerFut):
|
|
|
|
try:
|
|
|
|
# We use `allFutures()` to keep result in `bodyFut`, but still
|
|
|
|
# be able to check errors.
|
|
|
|
await allFutures(bodyFut)
|
|
|
|
ApiOperation.Success
|
2022-07-14 21:11:25 +00:00
|
|
|
except CancelledError as exc:
|
2021-07-13 11:15:07 +00:00
|
|
|
# `allFutures()` could not cancel Futures.
|
2022-07-14 21:11:25 +00:00
|
|
|
if not(bodyFut.finished()):
|
|
|
|
await bodyFut.cancelAndWait()
|
|
|
|
raise exc
|
2021-07-13 11:15:07 +00:00
|
|
|
except CatchableError as exc:
|
2022-07-14 21:11:25 +00:00
|
|
|
# This case could not be happened.
|
2021-07-13 11:15:07 +00:00
|
|
|
ApiOperation.Failure
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
discard await race(bodyFut, timerFut)
|
|
|
|
if bodyFut.finished():
|
|
|
|
ApiOperation.Success
|
|
|
|
else:
|
|
|
|
await bodyFut.cancelAndWait()
|
|
|
|
ApiOperation.Timeout
|
2022-07-14 21:11:25 +00:00
|
|
|
except CancelledError as exc:
|
2021-07-13 11:15:07 +00:00
|
|
|
# `race()` could not cancel Futures.
|
2022-07-14 21:11:25 +00:00
|
|
|
var pending: seq[Future[void]]
|
2021-07-13 11:15:07 +00:00
|
|
|
if not(bodyFut.finished()):
|
2022-07-14 21:11:25 +00:00
|
|
|
pending.add(bodyFut.cancelAndWait())
|
|
|
|
if not(isNil(timerFut)) and not(timerFut.finished()):
|
|
|
|
pending.add(timerFut.cancelAndWait())
|
2023-09-24 07:28:09 +00:00
|
|
|
await noCancel allFutures(pending)
|
2022-07-14 21:11:25 +00:00
|
|
|
raise exc
|
2021-07-13 11:15:07 +00:00
|
|
|
except CatchableError as exc:
|
2022-07-14 21:11:25 +00:00
|
|
|
# This case should not happen.
|
2021-07-13 11:15:07 +00:00
|
|
|
ApiOperation.Failure
|
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var handlerStatus = false
|
2021-07-13 11:15:07 +00:00
|
|
|
block:
|
|
|
|
let apiResponse {.inject.} =
|
|
|
|
block:
|
|
|
|
if bodyFut.finished():
|
|
|
|
if bodyFut.failed() or bodyFut.cancelled():
|
|
|
|
let exc = bodyFut.readError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[responseType].err("[" & $exc.name & "] " & $exc.msg)
|
2021-07-13 11:15:07 +00:00
|
|
|
else:
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[responseType].ok(bodyFut.read())
|
2021-07-13 11:15:07 +00:00
|
|
|
else:
|
|
|
|
case resOp
|
|
|
|
of ApiOperation.Interrupt:
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[responseType].err("Operation was interrupted")
|
2021-07-13 11:15:07 +00:00
|
|
|
of ApiOperation.Timeout:
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[responseType].err("Operation timeout exceeded")
|
2021-07-13 11:15:07 +00:00
|
|
|
of ApiOperation.Success, ApiOperation.Failure:
|
|
|
|
# This should not be happened, because all Futures should be
|
|
|
|
# finished, and `Failure` processed when Future is finished.
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[responseType].err("Unexpected error")
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
handlerStatus =
|
2021-07-13 11:15:07 +00:00
|
|
|
try:
|
|
|
|
handlers
|
|
|
|
except CatchableError:
|
|
|
|
raiseAssert("Response handler must not raise exceptions")
|
|
|
|
|
|
|
|
if resOp == ApiOperation.Success:
|
2023-02-23 00:11:00 +00:00
|
|
|
if handlerStatus:
|
2021-07-13 11:15:07 +00:00
|
|
|
exitNow = true
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
exitNow = true
|
|
|
|
break
|
|
|
|
|
|
|
|
if exitNow:
|
|
|
|
break
|
|
|
|
|
2022-09-29 20:55:18 +00:00
|
|
|
proc getIndexedErrorMessage(response: RestPlainResponse): string =
|
|
|
|
let res = decodeBytes(RestIndexedErrorMessage, response.data,
|
2022-07-13 14:43:57 +00:00
|
|
|
response.contentType)
|
|
|
|
if res.isOk():
|
|
|
|
let errorObj = res.get()
|
2022-09-29 20:55:18 +00:00
|
|
|
let failures = errorObj.failures.mapIt($it.index & ": " & it.message)
|
2022-07-13 14:43:57 +00:00
|
|
|
errorObj.message & ": [" & failures.join(", ") & "]"
|
|
|
|
else:
|
2023-03-03 20:20:01 +00:00
|
|
|
"Unable to decode error response: [" & $res.error & "]"
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2023-06-08 08:44:32 +00:00
|
|
|
proc getErrorMessage*(response: RestPlainResponse): string =
|
2022-09-29 20:55:18 +00:00
|
|
|
let res = decodeBytes(RestErrorMessage, response.data,
|
2022-07-13 14:43:57 +00:00
|
|
|
response.contentType)
|
|
|
|
if res.isOk():
|
|
|
|
let errorObj = res.get()
|
|
|
|
if errorObj.stacktraces.isSome():
|
|
|
|
errorObj.message & ": [" & errorObj.stacktraces.get().join("; ") & "]"
|
|
|
|
else:
|
|
|
|
errorObj.message
|
|
|
|
else:
|
2023-03-03 20:20:01 +00:00
|
|
|
"Unable to decode error response: [" & $res.error & "]"
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
template handleCommunicationError(): untyped {.dirty.} =
|
|
|
|
let failure = ApiNodeFailure.init(ApiFailure.Communication, RequestName,
|
|
|
|
strategy, node, apiResponse.error)
|
|
|
|
node.updateStatus(RestBeaconNodeStatus.Offline, failure)
|
|
|
|
failures.add(failure)
|
|
|
|
|
|
|
|
template handleUnexpectedCode(): untyped {.dirty.} =
|
|
|
|
let failure = ApiNodeFailure.init(ApiFailure.UnexpectedCode, RequestName,
|
|
|
|
strategy, node, response.status, response.getErrorMessage())
|
|
|
|
node.updateStatus(RestBeaconNodeStatus.UnexpectedCode, failure)
|
|
|
|
failures.add(failure)
|
|
|
|
|
|
|
|
template handleUnexpectedData(): untyped {.dirty.} =
|
|
|
|
let failure = ApiNodeFailure.init(ApiFailure.UnexpectedResponse, RequestName,
|
|
|
|
strategy, node, response.status, $res.error)
|
|
|
|
node.updateStatus(RestBeaconNodeStatus.UnexpectedResponse, failure)
|
|
|
|
failures.add(failure)
|
|
|
|
|
|
|
|
template handleOptimistic(): untyped {.dirty.} =
|
|
|
|
let failure = ApiNodeFailure.init(ApiFailure.OptSynced, RequestName,
|
|
|
|
strategy, node, response.status,
|
|
|
|
"Response was sent by optimistically synced node")
|
|
|
|
node.updateStatus(RestBeaconNodeStatus.OptSynced, failure)
|
|
|
|
|
|
|
|
template handle400(): untyped {.dirty.} =
|
|
|
|
let failure = ApiNodeFailure.init(ApiFailure.Invalid, RequestName,
|
|
|
|
strategy, node, response.status, response.getErrorMessage())
|
|
|
|
node.updateStatus(RestBeaconNodeStatus.Incompatible, failure)
|
|
|
|
failures.add(failure)
|
|
|
|
|
|
|
|
template handle404(): untyped {.dirty.} =
|
|
|
|
let failure = ApiNodeFailure.init(ApiFailure.NotFound, RequestName,
|
|
|
|
strategy, node, response.status, response.getErrorMessage())
|
|
|
|
node.updateStatus(RestBeaconNodeStatus.Incompatible, failure)
|
|
|
|
failures.add(failure)
|
|
|
|
|
|
|
|
template handle500(): untyped {.dirty.} =
|
|
|
|
let failure = ApiNodeFailure.init(ApiFailure.Internal, RequestName,
|
|
|
|
strategy, node, response.status, response.getErrorMessage())
|
|
|
|
node.updateStatus(RestBeaconNodeStatus.InternalError, failure)
|
|
|
|
failures.add(failure)
|
|
|
|
|
|
|
|
template handle503(): untyped {.dirty.} =
|
|
|
|
let failure = ApiNodeFailure.init(ApiFailure.NotSynced, RequestName,
|
|
|
|
strategy, node, response.status, response.getErrorMessage())
|
|
|
|
node.updateStatus(RestBeaconNodeStatus.NotSynced, failure)
|
|
|
|
failures.add(failure)
|
|
|
|
|
2022-07-13 14:43:57 +00:00
|
|
|
proc getProposerDuties*(
|
|
|
|
vc: ValidatorClientRef,
|
2022-09-29 07:57:14 +00:00
|
|
|
epoch: Epoch,
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[GetProposerDutiesResponse] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const RequestName = "getProposerDuties"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = vc.firstSuccessParallel(RestPlainResponse,
|
|
|
|
GetProposerDutiesResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.Duties},
|
2023-03-03 20:20:01 +00:00
|
|
|
getProposerDutiesPlain(it, epoch)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetProposerDutiesResponse].err(apiResponse.error)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetProposerDutiesResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetProposerDutiesResponse].err($res.error)
|
|
|
|
else:
|
|
|
|
let data = res.get()
|
|
|
|
if data.execution_optimistic.get(false):
|
2023-05-30 08:38:34 +00:00
|
|
|
handleOptimistic()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetProposerDutiesResponse].ok(data)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetProposerDutiesResponse].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetProposerDutiesResponse].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetProposerDutiesResponse].err(ResponseNoSyncError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetProposerDutiesResponse].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-03-03 20:20:01 +00:00
|
|
|
vc.firstSuccessSequential(RestPlainResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.Duties},
|
2023-03-03 20:20:01 +00:00
|
|
|
getProposerDutiesPlain(it, epoch)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetProposerDutiesResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isOk():
|
|
|
|
let data = res.get()
|
|
|
|
if data.execution_optimistic.get(false):
|
2023-05-30 08:38:34 +00:00
|
|
|
handleOptimistic()
|
2023-03-03 20:20:01 +00:00
|
|
|
return data
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to get proposer duties", data: failures)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
proc getAttesterDuties*(
|
2022-07-13 14:43:57 +00:00
|
|
|
vc: ValidatorClientRef,
|
|
|
|
epoch: Epoch,
|
2022-09-29 07:57:14 +00:00
|
|
|
validators: seq[ValidatorIndex],
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[GetAttesterDutiesResponse] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const RequestName = "getAttesterDuties"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = vc.firstSuccessParallel(RestPlainResponse,
|
|
|
|
GetAttesterDutiesResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.Duties},
|
2023-03-03 20:20:01 +00:00
|
|
|
getAttesterDutiesPlain(it, epoch,
|
|
|
|
validators)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAttesterDutiesResponse].err(apiResponse.error)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetAttesterDutiesResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAttesterDutiesResponse].err($res.error)
|
|
|
|
else:
|
|
|
|
let data = res.get()
|
|
|
|
if data.execution_optimistic.get(false):
|
2023-05-30 08:38:34 +00:00
|
|
|
handleOptimistic()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAttesterDutiesResponse].ok(data)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAttesterDutiesResponse].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAttesterDutiesResponse].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAttesterDutiesResponse].err(ResponseNoSyncError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAttesterDutiesResponse].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-03-03 20:20:01 +00:00
|
|
|
vc.firstSuccessSequential(RestPlainResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.Duties},
|
2023-03-03 20:20:01 +00:00
|
|
|
getAttesterDutiesPlain(it, epoch, validators)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetAttesterDutiesResponse, response.data,
|
|
|
|
response.contentType)
|
2023-05-30 08:38:34 +00:00
|
|
|
if res.isOk():
|
|
|
|
let data = res.get()
|
|
|
|
if data.execution_optimistic.get(false):
|
|
|
|
handleOptimistic()
|
|
|
|
return data
|
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to get attester duties", data: failures)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
proc getSyncCommitteeDuties*(
|
2022-07-13 14:43:57 +00:00
|
|
|
vc: ValidatorClientRef,
|
|
|
|
epoch: Epoch,
|
2022-09-29 07:57:14 +00:00
|
|
|
validators: seq[ValidatorIndex],
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[GetSyncCommitteeDutiesResponse] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const RequestName = "getSyncCommitteeDuties"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
|
|
|
let res = vc.firstSuccessParallel(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
|
|
|
GetSyncCommitteeDutiesResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.Duties},
|
2023-03-03 20:20:01 +00:00
|
|
|
getSyncCommitteeDutiesPlain(it, epoch, validators)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetSyncCommitteeDutiesResponse].err(apiResponse.error)
|
2021-08-23 10:41:48 +00:00
|
|
|
else:
|
2022-09-29 07:57:14 +00:00
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetSyncCommitteeDutiesResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetSyncCommitteeDutiesResponse].err($res.error)
|
|
|
|
else:
|
|
|
|
let data = res.get()
|
|
|
|
if data.execution_optimistic.get(false):
|
2023-05-30 08:38:34 +00:00
|
|
|
handleOptimistic()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetSyncCommitteeDutiesResponse].ok(data)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetSyncCommitteeDutiesResponse].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetSyncCommitteeDutiesResponse].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetSyncCommitteeDutiesResponse].err(ResponseNoSyncError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetSyncCommitteeDutiesResponse].err(
|
|
|
|
ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-03-03 20:20:01 +00:00
|
|
|
vc.firstSuccessSequential(
|
|
|
|
RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.Duties},
|
|
|
|
getSyncCommitteeDutiesPlain(it, epoch, validators)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetSyncCommitteeDutiesResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isOk():
|
|
|
|
let data = res.get()
|
|
|
|
if data.execution_optimistic.get(false):
|
2023-05-30 08:38:34 +00:00
|
|
|
handleOptimistic()
|
2023-03-03 20:20:01 +00:00
|
|
|
return data
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2021-08-23 10:41:48 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to get sync committee duties", data: failures)
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
proc getForkSchedule*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
strategy: ApiStrategyKind
|
|
|
|
): Future[seq[Fork]] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const RequestName = "getForkSchedule"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = vc.firstSuccessParallel(RestPlainResponse,
|
|
|
|
GetForkScheduleResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.Duties},
|
2023-03-03 20:20:01 +00:00
|
|
|
getForkSchedulePlain(it)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetForkScheduleResponse].err(apiResponse.error)
|
2021-07-13 11:15:07 +00:00
|
|
|
else:
|
2022-09-29 07:57:14 +00:00
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetForkScheduleResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetForkScheduleResponse].err($res.error)
|
|
|
|
else:
|
|
|
|
ApiResponse[GetForkScheduleResponse].ok(res.get())
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetForkScheduleResponse].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetForkScheduleResponse].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get().data
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-03-03 20:20:01 +00:00
|
|
|
vc.firstSuccessSequential(RestPlainResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.Duties},
|
2023-03-03 20:20:01 +00:00
|
|
|
getForkSchedulePlain(it)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetForkScheduleResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isOk(): return res.get().data
|
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to get fork schedule", data: failures)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-07-13 14:43:57 +00:00
|
|
|
proc getHeadBlockRoot*(
|
2022-09-29 07:57:14 +00:00
|
|
|
vc: ValidatorClientRef,
|
|
|
|
strategy: ApiStrategyKind
|
2023-03-03 20:20:01 +00:00
|
|
|
): Future[DataOptimisticObject[RestRoot]] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const RequestName = "getHeadBlockRoot"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
let blockIdent = BlockIdent.init(BlockIdentType.Head)
|
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = vc.firstSuccessParallel(RestPlainResponse,
|
|
|
|
GetBlockRootResponse,
|
2022-09-29 07:57:14 +00:00
|
|
|
SlotDuration,
|
2023-02-23 00:11:00 +00:00
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.SyncCommitteeData},
|
2023-03-03 20:20:01 +00:00
|
|
|
getBlockRootPlain(it, blockIdent)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetBlockRootResponse].err(apiResponse.error)
|
2022-05-10 10:03:40 +00:00
|
|
|
else:
|
2022-09-29 07:57:14 +00:00
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetBlockRootResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetBlockRootResponse].err($res.error)
|
|
|
|
else:
|
|
|
|
let data = res.get()
|
|
|
|
if data.execution_optimistic.get(false):
|
2023-05-30 08:38:34 +00:00
|
|
|
handleOptimistic()
|
|
|
|
failures.add(failure)
|
2023-05-02 11:54:44 +00:00
|
|
|
ApiResponse[GetBlockRootResponse].err(ResponseECNotInSyncError)
|
|
|
|
else:
|
|
|
|
ApiResponse[GetBlockRootResponse].ok(data)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetBlockRootResponse].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 404:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle404()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetBlockRootResponse].err(ResponseNotFoundError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetBlockRootResponse].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetBlockRootResponse].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-03-03 20:20:01 +00:00
|
|
|
vc.firstSuccessSequential(RestPlainResponse, #RestResponse[GetBlockRootResponse],
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.SyncCommitteeData},
|
2023-03-03 20:20:01 +00:00
|
|
|
getBlockRootPlain(it, blockIdent)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetBlockRootResponse, response.data,
|
|
|
|
response.contentType)
|
2023-05-30 08:38:34 +00:00
|
|
|
if res.isErr():
|
|
|
|
handleUnexpectedData()
|
|
|
|
false
|
|
|
|
else:
|
2023-03-03 20:20:01 +00:00
|
|
|
let data = res.get()
|
|
|
|
if data.execution_optimistic.get(false):
|
2023-05-30 08:38:34 +00:00
|
|
|
handleOptimistic()
|
|
|
|
failures.add(failure)
|
2023-05-02 11:54:44 +00:00
|
|
|
false
|
|
|
|
else:
|
|
|
|
return data
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 404:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle404()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to get head block root", data: failures)
|
2022-05-10 10:03:40 +00:00
|
|
|
|
|
|
|
proc getValidators*(
|
2022-07-13 14:43:57 +00:00
|
|
|
vc: ValidatorClientRef,
|
2022-09-29 07:57:14 +00:00
|
|
|
id: seq[ValidatorIdent],
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[seq[RestValidator]] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const RequestName = "getStateValidators"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2021-07-13 11:15:07 +00:00
|
|
|
let stateIdent = StateIdent.init(StateIdentType.Head)
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = vc.firstSuccessParallel(
|
|
|
|
RestPlainResponse,
|
|
|
|
GetStateValidatorsResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.Duties},
|
|
|
|
getStateValidatorsPlain(it, stateIdent, id)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetStateValidatorsResponse].err(apiResponse.error)
|
2021-07-13 11:15:07 +00:00
|
|
|
else:
|
2022-09-29 07:57:14 +00:00
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetStateValidatorsResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetStateValidatorsResponse].err($res.error)
|
|
|
|
else:
|
|
|
|
let data = res.get()
|
|
|
|
if data.execution_optimistic.get(false):
|
2023-05-30 08:38:34 +00:00
|
|
|
handleOptimistic()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetStateValidatorsResponse].ok(data)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetStateValidatorsResponse].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 404:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle404()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetStateValidatorsResponse].err(ResponseNotFoundError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetStateValidatorsResponse].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetStateValidatorsResponse].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get().data
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-03-03 20:20:01 +00:00
|
|
|
vc.firstSuccessSequential(RestPlainResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.Duties},
|
2023-03-03 20:20:01 +00:00
|
|
|
getStateValidatorsPlain(it, stateIdent, id)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetStateValidatorsResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isOk():
|
|
|
|
let data = res.get()
|
|
|
|
if data.execution_optimistic.get(false):
|
2023-05-30 08:38:34 +00:00
|
|
|
handleOptimistic()
|
2023-03-03 20:20:01 +00:00
|
|
|
return data.data
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 404:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle404()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to get state's validators", data: failures)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
proc produceAttestationData*(
|
2022-07-13 14:43:57 +00:00
|
|
|
vc: ValidatorClientRef,
|
|
|
|
slot: Slot,
|
2022-09-29 07:57:14 +00:00
|
|
|
committee_index: CommitteeIndex,
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[AttestationData] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const RequestName = "produceAttestationData"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
2023-07-06 09:14:22 +00:00
|
|
|
of ApiStrategyKind.First:
|
2022-09-29 07:57:14 +00:00
|
|
|
let res = vc.firstSuccessParallel(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
|
|
|
ProduceAttestationDataResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
OneThirdDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.AttestationData},
|
2023-03-03 20:20:01 +00:00
|
|
|
produceAttestationDataPlain(it, slot, committee_index)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceAttestationDataResponse].err(apiResponse.error)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(ProduceAttestationDataResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceAttestationDataResponse].err($res.error)
|
|
|
|
else:
|
|
|
|
ApiResponse[ProduceAttestationDataResponse].ok(res.get())
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceAttestationDataResponse].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceAttestationDataResponse].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceAttestationDataResponse].err(
|
|
|
|
ResponseNoSyncError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceAttestationDataResponse].err(
|
|
|
|
ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get().data
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-07-06 09:14:22 +00:00
|
|
|
of ApiStrategyKind.Best:
|
|
|
|
let res = vc.bestSuccess(
|
|
|
|
RestPlainResponse,
|
|
|
|
ProduceAttestationDataResponse,
|
|
|
|
OneThirdDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.AttestationData},
|
|
|
|
produceAttestationDataPlain(it, slot, committee_index),
|
|
|
|
getAttestationDataScore(vc, itresponse)):
|
|
|
|
if apiResponse.isErr():
|
|
|
|
handleCommunicationError()
|
|
|
|
ApiResponse[ProduceAttestationDataResponse].err(apiResponse.error)
|
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
|
|
|
let res = decodeBytes(ProduceAttestationDataResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isErr():
|
|
|
|
handleUnexpectedData()
|
|
|
|
ApiResponse[ProduceAttestationDataResponse].err($res.error)
|
|
|
|
else:
|
|
|
|
ApiResponse[ProduceAttestationDataResponse].ok(res.get())
|
|
|
|
of 400:
|
|
|
|
handle400()
|
|
|
|
ApiResponse[ProduceAttestationDataResponse].err(ResponseInvalidError)
|
|
|
|
of 500:
|
|
|
|
handle500()
|
|
|
|
ApiResponse[ProduceAttestationDataResponse].err(ResponseInternalError)
|
|
|
|
of 503:
|
|
|
|
handle503()
|
|
|
|
ApiResponse[ProduceAttestationDataResponse].err(
|
|
|
|
ResponseNoSyncError)
|
|
|
|
else:
|
|
|
|
handleUnexpectedCode()
|
|
|
|
ApiResponse[ProduceAttestationDataResponse].err(
|
|
|
|
ResponseUnexpectedError)
|
|
|
|
if res.isErr():
|
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
|
|
|
return res.get().data
|
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
of ApiStrategyKind.Priority:
|
|
|
|
vc.firstSuccessSequential(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
OneThirdDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.AttestationData},
|
2023-03-03 20:20:01 +00:00
|
|
|
produceAttestationDataPlain(it, slot, committee_index)):
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(ProduceAttestationDataResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isOk(): return res.get().data
|
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to produce attestation data", data: failures)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-07-13 14:43:57 +00:00
|
|
|
proc submitPoolAttestations*(
|
|
|
|
vc: ValidatorClientRef,
|
2022-09-29 07:57:14 +00:00
|
|
|
data: seq[Attestation],
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[bool] {.async.} =
|
2022-09-29 07:57:14 +00:00
|
|
|
const
|
2023-05-30 08:38:34 +00:00
|
|
|
RequestName = "submitPoolAttestations"
|
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
2023-02-23 00:11:00 +00:00
|
|
|
let res = vc.firstSuccessParallel(RestPlainResponse,
|
2023-03-03 20:20:01 +00:00
|
|
|
bool,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.AttestationPublish},
|
|
|
|
submitPoolAttestations(it, data)):
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(apiResponse.error)
|
2021-07-13 11:15:07 +00:00
|
|
|
else:
|
2022-09-29 07:57:14 +00:00
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].ok(true)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-02-23 00:11:00 +00:00
|
|
|
vc.firstSuccessSequential(RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.AttestationPublish},
|
|
|
|
submitPoolAttestations(it, data)):
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
|
|
|
return true
|
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to submit attestations", data: failures)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-07-13 14:43:57 +00:00
|
|
|
proc submitPoolSyncCommitteeSignature*(
|
|
|
|
vc: ValidatorClientRef,
|
2022-09-29 07:57:14 +00:00
|
|
|
data: SyncCommitteeMessage,
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[bool] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const
|
|
|
|
RequestName = "submitPoolSyncCommitteeSignatures"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
let restData = RestSyncCommitteeMessage.init(
|
|
|
|
data.slot,
|
|
|
|
data.beacon_block_root,
|
|
|
|
data.validator_index,
|
|
|
|
data.signature
|
|
|
|
)
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
|
|
|
let res = vc.firstSuccessParallel(
|
2023-02-23 00:11:00 +00:00
|
|
|
RestPlainResponse,
|
2023-03-03 20:20:01 +00:00
|
|
|
bool,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.SyncCommitteePublish},
|
2022-09-29 07:57:14 +00:00
|
|
|
submitPoolSyncCommitteeSignatures(it, @[restData])):
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(apiResponse.error)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].ok(true)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
|
|
|
vc.firstSuccessSequential(
|
2023-02-23 00:11:00 +00:00
|
|
|
RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.SyncCommitteePublish},
|
2022-09-29 07:57:14 +00:00
|
|
|
submitPoolSyncCommitteeSignatures(it, @[restData])):
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
|
|
|
return true
|
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to submit sync committee message", data: failures)
|
2022-05-10 10:03:40 +00:00
|
|
|
|
2022-07-13 14:43:57 +00:00
|
|
|
proc getAggregatedAttestation*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
slot: Slot,
|
2022-09-29 07:57:14 +00:00
|
|
|
root: Eth2Digest,
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[Attestation] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const
|
|
|
|
RequestName = "getAggregatedAttestation"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
|
|
|
let res = vc.firstSuccessParallel(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
|
|
|
GetAggregatedAttestationResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
OneThirdDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.AggregatedData},
|
2023-03-03 20:20:01 +00:00
|
|
|
getAggregatedAttestationPlain(it, root, slot)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAggregatedAttestationResponse].err(apiResponse.error)
|
2021-07-13 11:15:07 +00:00
|
|
|
else:
|
2022-09-29 07:57:14 +00:00
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetAggregatedAttestationResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAggregatedAttestationResponse].err($res.error)
|
|
|
|
else:
|
|
|
|
ApiResponse[GetAggregatedAttestationResponse].ok(res.get())
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAggregatedAttestationResponse].err(
|
|
|
|
ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAggregatedAttestationResponse].err(
|
|
|
|
ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[GetAggregatedAttestationResponse].err(
|
|
|
|
ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get().data
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
|
|
|
vc.firstSuccessSequential(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
OneThirdDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.AggregatedData},
|
2023-03-03 20:20:01 +00:00
|
|
|
getAggregatedAttestationPlain(it, root, slot)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(GetAggregatedAttestationResponse, response.data,
|
|
|
|
response.contentType)
|
|
|
|
if res.isOk(): return res.get().data
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to get aggregated attestation", data: failures)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
proc produceSyncCommitteeContribution*(
|
2022-07-13 14:43:57 +00:00
|
|
|
vc: ValidatorClientRef,
|
|
|
|
slot: Slot,
|
|
|
|
subcommitteeIndex: SyncSubcommitteeIndex,
|
2022-09-29 07:57:14 +00:00
|
|
|
root: Eth2Digest,
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[SyncCommitteeContribution] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const
|
|
|
|
RequestName = "produceSyncCommitteeContribution"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
|
|
|
let res = vc.firstSuccessParallel(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
|
|
|
ProduceSyncCommitteeContributionResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
OneThirdDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.SyncCommitteeData},
|
2023-03-03 20:20:01 +00:00
|
|
|
produceSyncCommitteeContributionPlain(it, slot, subcommitteeIndex, root)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceSyncCommitteeContributionResponse].err(
|
|
|
|
apiResponse.error)
|
2022-05-10 10:03:40 +00:00
|
|
|
else:
|
2022-09-29 07:57:14 +00:00
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(ProduceSyncCommitteeContributionResponse,
|
|
|
|
response.data, response.contentType)
|
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceSyncCommitteeContributionResponse].err(
|
|
|
|
$res.error)
|
|
|
|
else:
|
|
|
|
ApiResponse[ProduceSyncCommitteeContributionResponse].ok(res.get())
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceSyncCommitteeContributionResponse].err(
|
|
|
|
ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceSyncCommitteeContributionResponse].err(
|
|
|
|
ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceSyncCommitteeContributionResponse].err(
|
|
|
|
ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get().data
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
|
|
|
vc.firstSuccessSequential(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
OneThirdDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.SyncCommitteeData},
|
2023-03-03 20:20:01 +00:00
|
|
|
produceSyncCommitteeContributionPlain(it, slot, subcommitteeIndex, root)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
let res = decodeBytes(ProduceSyncCommitteeContributionResponse,
|
|
|
|
response.data, response.contentType)
|
|
|
|
if res.isOk(): return res.get().data
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-05-10 10:03:40 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to produce sync committee contribution", data: failures)
|
2022-05-10 10:03:40 +00:00
|
|
|
|
|
|
|
proc publishAggregateAndProofs*(
|
2022-07-13 14:43:57 +00:00
|
|
|
vc: ValidatorClientRef,
|
2022-09-29 07:57:14 +00:00
|
|
|
data: seq[SignedAggregateAndProof],
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[bool] {.async.} =
|
2022-09-29 07:57:14 +00:00
|
|
|
const
|
2023-05-30 08:38:34 +00:00
|
|
|
RequestName = "publishAggregateAndProofs"
|
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
2023-02-23 00:11:00 +00:00
|
|
|
let res = vc.firstSuccessParallel(RestPlainResponse,
|
2023-03-03 20:20:01 +00:00
|
|
|
bool,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.AggregatedPublish},
|
|
|
|
publishAggregateAndProofs(it, data)):
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(apiResponse.error)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].ok(true)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-02-23 00:11:00 +00:00
|
|
|
vc.firstSuccessSequential(RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.AggregatedPublish},
|
|
|
|
publishAggregateAndProofs(it, data)):
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
|
|
|
return true
|
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to publish aggregated attestation", data: failures)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
proc publishContributionAndProofs*(
|
2022-07-13 14:43:57 +00:00
|
|
|
vc: ValidatorClientRef,
|
2022-09-29 07:57:14 +00:00
|
|
|
data: seq[RestSignedContributionAndProof],
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[bool] {.async.} =
|
2022-09-29 07:57:14 +00:00
|
|
|
const
|
2023-05-30 08:38:34 +00:00
|
|
|
RequestName = "publishContributionAndProofs"
|
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
2023-02-23 00:11:00 +00:00
|
|
|
let res = vc.firstSuccessParallel(RestPlainResponse,
|
2023-03-03 20:20:01 +00:00
|
|
|
bool,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.SyncCommitteePublish},
|
|
|
|
publishContributionAndProofs(it, data)):
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(apiResponse.error)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].ok(true)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseUnexpectedError)
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-02-23 00:11:00 +00:00
|
|
|
vc.firstSuccessSequential(RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.SyncCommitteePublish},
|
|
|
|
publishContributionAndProofs(it, data)):
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
|
|
|
return true
|
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to publish sync committee contribution", data: failures)
|
2022-05-10 10:03:40 +00:00
|
|
|
|
|
|
|
proc produceBlockV2*(
|
2022-07-13 14:43:57 +00:00
|
|
|
vc: ValidatorClientRef,
|
|
|
|
slot: Slot,
|
|
|
|
randao_reveal: ValidatorSig,
|
2022-09-29 07:57:14 +00:00
|
|
|
graffiti: GraffitiBytes,
|
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[ProduceBlockResponseV2] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const
|
|
|
|
RequestName = "produceBlockV2"
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
|
|
|
let res = vc.firstSuccessParallel(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
|
|
|
ProduceBlockResponseV2,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.BlockProposalData},
|
2023-03-03 20:20:01 +00:00
|
|
|
produceBlockV2Plain(it, slot, randao_reveal, graffiti)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlockResponseV2].err(apiResponse.error)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-06-14 06:04:15 +00:00
|
|
|
let
|
|
|
|
version = response.headers.getString("eth-consensus-version")
|
|
|
|
res = decodeBytes(ProduceBlockResponseV2, response.data,
|
|
|
|
response.contentType, version)
|
2023-03-03 20:20:01 +00:00
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlockResponseV2].err($res.error)
|
|
|
|
else:
|
|
|
|
ApiResponse[ProduceBlockResponseV2].ok(res.get())
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlockResponseV2].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlockResponseV2].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlockResponseV2].err(ResponseNoSyncError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlockResponseV2].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
|
|
|
vc.firstSuccessSequential(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.BlockProposalData},
|
2023-03-03 20:20:01 +00:00
|
|
|
produceBlockV2Plain(it, slot, randao_reveal, graffiti)):
|
2022-09-29 07:57:14 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-06-14 06:04:15 +00:00
|
|
|
let
|
|
|
|
version = response.headers.getString("eth-consensus-version")
|
|
|
|
res = decodeBytes(ProduceBlockResponseV2, response.data,
|
|
|
|
response.contentType, version)
|
2023-03-03 20:20:01 +00:00
|
|
|
if res.isOk(): return res.get()
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to produce block", data: failures)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-07-13 14:43:57 +00:00
|
|
|
proc publishBlock*(
|
|
|
|
vc: ValidatorClientRef,
|
2023-06-23 09:30:16 +00:00
|
|
|
data: RestPublishedSignedBlockContents,
|
2022-09-29 07:57:14 +00:00
|
|
|
strategy: ApiStrategyKind
|
2022-07-13 14:43:57 +00:00
|
|
|
): Future[bool] {.async.} =
|
2022-09-29 07:57:14 +00:00
|
|
|
const
|
2023-05-30 08:38:34 +00:00
|
|
|
RequestName = "publishBlock"
|
2022-09-29 07:57:14 +00:00
|
|
|
BlockBroadcasted = "Block not passed validation, but still published"
|
2023-05-30 08:38:34 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
|
|
|
let res = block:
|
2023-02-23 00:11:00 +00:00
|
|
|
vc.firstSuccessParallel(RestPlainResponse,
|
2023-03-03 20:20:01 +00:00
|
|
|
bool,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.BlockProposalPublish}):
|
|
|
|
case data.kind
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
2022-09-29 07:57:14 +00:00
|
|
|
publishBlock(it, data.phase0Data)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
2022-09-29 07:57:14 +00:00
|
|
|
publishBlock(it, data.altairData)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
2022-09-29 07:57:14 +00:00
|
|
|
publishBlock(it, data.bellatrixData)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
2022-11-22 11:56:05 +00:00
|
|
|
publishBlock(it, data.capellaData)
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
2023-06-23 09:30:16 +00:00
|
|
|
publishBlock(it, data.denebData)
|
2022-09-29 07:57:14 +00:00
|
|
|
do:
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(apiResponse.error)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].ok(true)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 202:
|
2023-06-23 09:30:16 +00:00
|
|
|
debug BlockBroadcasted, node = node,
|
|
|
|
blck = shortLog(ForkedSignedBeaconBlock.init(data))
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].ok(true)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInvalidError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInternalError)
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseNoSyncError)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-09-29 07:57:14 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-09-29 07:57:14 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-02-23 00:11:00 +00:00
|
|
|
vc.firstSuccessSequential(RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-09-29 07:57:14 +00:00
|
|
|
{BeaconNodeRole.BlockProposalPublish}):
|
|
|
|
case data.kind
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
2022-09-29 07:57:14 +00:00
|
|
|
publishBlock(it, data.phase0Data)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
2022-09-29 07:57:14 +00:00
|
|
|
publishBlock(it, data.altairData)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
2022-09-29 07:57:14 +00:00
|
|
|
publishBlock(it, data.bellatrixData)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
2022-11-24 14:38:07 +00:00
|
|
|
publishBlock(it, data.capellaData)
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
2023-06-23 09:30:16 +00:00
|
|
|
publishBlock(it, data.denebData)
|
|
|
|
|
2022-11-24 09:14:05 +00:00
|
|
|
do:
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
|
|
|
return true
|
|
|
|
of 202:
|
2023-06-23 09:30:16 +00:00
|
|
|
debug BlockBroadcasted, node = node,
|
|
|
|
blck = shortLog(ForkedSignedBeaconBlock.init(data))
|
2022-11-24 09:14:05 +00:00
|
|
|
return true
|
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to publish block", data: failures)
|
2022-11-24 09:14:05 +00:00
|
|
|
|
|
|
|
proc produceBlindedBlock*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
slot: Slot,
|
|
|
|
randao_reveal: ValidatorSig,
|
|
|
|
graffiti: GraffitiBytes,
|
|
|
|
strategy: ApiStrategyKind
|
|
|
|
): Future[ProduceBlindedBlockResponse] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const
|
|
|
|
RequestName = "produceBlindedBlock"
|
2022-11-24 09:14:05 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-11-24 09:14:05 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
|
|
|
let res = vc.firstSuccessParallel(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
|
|
|
ProduceBlindedBlockResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.BlockProposalData},
|
2023-03-03 20:20:01 +00:00
|
|
|
produceBlindedBlockPlain(it, slot, randao_reveal, graffiti)):
|
2022-11-24 09:14:05 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlindedBlockResponse].err(apiResponse.error)
|
2022-11-24 09:14:05 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-06-14 06:04:15 +00:00
|
|
|
let
|
|
|
|
version = response.headers.getString("eth-consensus-version")
|
|
|
|
res = decodeBytes(ProduceBlindedBlockResponse, response.data,
|
|
|
|
response.contentType, version)
|
2023-03-03 20:20:01 +00:00
|
|
|
if res.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlindedBlockResponse].err($res.error)
|
|
|
|
else:
|
|
|
|
ApiResponse[ProduceBlindedBlockResponse].ok(res.get())
|
2022-11-24 09:14:05 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
# TODO(cheatfate): We not going to update BN status for this handler,
|
|
|
|
# because BN reports 400 for any type of error that does not mean
|
|
|
|
# that BN is incompatible.
|
|
|
|
let failure = ApiNodeFailure.init(ApiFailure.Invalid, RequestName,
|
|
|
|
strategy, node, response.status, response.getErrorMessage())
|
|
|
|
failures.add(failure)
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlindedBlockResponse].err(ResponseInvalidError)
|
2022-11-24 09:14:05 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlindedBlockResponse].err(ResponseInternalError)
|
2022-11-24 09:14:05 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlindedBlockResponse].err(ResponseNoSyncError)
|
2022-11-24 09:14:05 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[ProduceBlindedBlockResponse].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-11-24 09:14:05 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-11-24 09:14:05 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
|
|
|
vc.firstSuccessSequential(
|
2023-03-03 20:20:01 +00:00
|
|
|
RestPlainResponse,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
|
|
|
{BeaconNodeRole.BlockProposalData},
|
2023-03-03 20:20:01 +00:00
|
|
|
produceBlindedBlockPlain(it, slot, randao_reveal, graffiti)):
|
2022-11-24 09:14:05 +00:00
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-06-14 06:04:15 +00:00
|
|
|
let
|
|
|
|
version = response.headers.getString("eth-consensus-version")
|
|
|
|
res = decodeBytes(ProduceBlindedBlockResponse, response.data,
|
|
|
|
response.contentType, version)
|
2023-03-03 20:20:01 +00:00
|
|
|
if res.isOk(): return res.get()
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedData()
|
2023-03-03 20:20:01 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-11-24 09:14:05 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to produce blinded block", data: failures)
|
2022-11-24 09:14:05 +00:00
|
|
|
|
|
|
|
proc publishBlindedBlock*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
data: ForkedSignedBlindedBeaconBlock,
|
|
|
|
strategy: ApiStrategyKind
|
|
|
|
): Future[bool] {.async.} =
|
|
|
|
const
|
2023-05-30 08:38:34 +00:00
|
|
|
RequestName = "publishBlindedBlock"
|
2022-11-24 09:14:05 +00:00
|
|
|
BlockBroadcasted = "Block not passed validation, but still published"
|
2023-05-30 08:38:34 +00:00
|
|
|
|
2023-02-23 00:11:00 +00:00
|
|
|
var failures: seq[ApiNodeFailure]
|
2022-11-24 09:14:05 +00:00
|
|
|
|
|
|
|
case strategy
|
|
|
|
of ApiStrategyKind.First, ApiStrategyKind.Best:
|
|
|
|
let res = block:
|
2023-02-23 00:11:00 +00:00
|
|
|
vc.firstSuccessParallel(RestPlainResponse,
|
2023-03-03 20:20:01 +00:00
|
|
|
bool,
|
2023-02-23 00:11:00 +00:00
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-11-24 09:14:05 +00:00
|
|
|
{BeaconNodeRole.BlockProposalPublish}):
|
|
|
|
case data.kind
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
2022-11-24 09:14:05 +00:00
|
|
|
publishBlindedBlock(it, data.phase0Data)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
2022-11-24 09:14:05 +00:00
|
|
|
publishBlindedBlock(it, data.altairData)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
2022-11-24 09:14:05 +00:00
|
|
|
publishBlindedBlock(it, data.bellatrixData)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
2022-11-24 14:38:07 +00:00
|
|
|
publishBlindedBlock(it, data.capellaData)
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
2023-02-23 10:37:45 +00:00
|
|
|
debugRaiseAssert $denebImplementationMissing &
|
2023-02-23 00:11:00 +00:00
|
|
|
": validator_client/api.nim:publishBlindedBlock (1)"
|
2022-12-14 17:30:56 +00:00
|
|
|
let f = newFuture[RestPlainResponse]("")
|
|
|
|
f.fail(new RestError)
|
|
|
|
f
|
2022-11-24 09:14:05 +00:00
|
|
|
do:
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(apiResponse.error)
|
2022-11-24 09:14:05 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].ok(true)
|
2022-11-24 09:14:05 +00:00
|
|
|
of 202:
|
2023-05-30 08:38:34 +00:00
|
|
|
debug BlockBroadcasted, node = node, blck = shortLog(data)
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].ok(true)
|
2022-11-24 09:14:05 +00:00
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInvalidError)
|
2022-11-24 09:14:05 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseInternalError)
|
2022-11-24 09:14:05 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseNoSyncError)
|
2022-11-24 09:14:05 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-03-03 20:20:01 +00:00
|
|
|
ApiResponse[bool].err(ResponseUnexpectedError)
|
2023-02-23 00:11:00 +00:00
|
|
|
|
2022-11-24 09:14:05 +00:00
|
|
|
if res.isErr():
|
2023-02-23 00:11:00 +00:00
|
|
|
raise (ref ValidatorApiError)(msg: res.error, data: failures)
|
2023-03-03 20:20:01 +00:00
|
|
|
return res.get()
|
2022-11-24 09:14:05 +00:00
|
|
|
|
|
|
|
of ApiStrategyKind.Priority:
|
2023-02-23 00:11:00 +00:00
|
|
|
vc.firstSuccessSequential(RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-11-24 09:14:05 +00:00
|
|
|
{BeaconNodeRole.BlockProposalPublish}):
|
|
|
|
case data.kind
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
2022-11-24 09:14:05 +00:00
|
|
|
publishBlindedBlock(it, data.phase0Data)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
2022-11-24 09:14:05 +00:00
|
|
|
publishBlindedBlock(it, data.altairData)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
2022-11-24 09:14:05 +00:00
|
|
|
publishBlindedBlock(it, data.bellatrixData)
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
2022-11-24 14:38:07 +00:00
|
|
|
publishBlindedBlock(it, data.capellaData)
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
2023-02-23 10:37:45 +00:00
|
|
|
debugRaiseAssert $denebImplementationMissing &
|
2023-02-23 00:11:00 +00:00
|
|
|
": validator_client/api.nim:publishBlindedBlock (2)"
|
2022-12-14 17:30:56 +00:00
|
|
|
let f = newFuture[RestPlainResponse]("")
|
|
|
|
f.fail(new RestError)
|
|
|
|
f
|
2022-09-29 07:57:14 +00:00
|
|
|
do:
|
|
|
|
if apiResponse.isErr():
|
2023-05-30 08:38:34 +00:00
|
|
|
handleCommunicationError()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.get()
|
|
|
|
case response.status:
|
|
|
|
of 200:
|
|
|
|
return true
|
|
|
|
of 202:
|
2023-05-30 08:38:34 +00:00
|
|
|
debug BlockBroadcasted, node = node, blck = shortLog(data)
|
2022-09-29 07:57:14 +00:00
|
|
|
return true
|
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle400()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle500()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
handle503()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
handleUnexpectedCode()
|
2023-02-23 00:11:00 +00:00
|
|
|
false
|
2022-09-29 07:57:14 +00:00
|
|
|
|
2023-05-30 08:38:34 +00:00
|
|
|
raise (ref ValidatorApiError)(
|
|
|
|
msg: "Failed to publish blinded block", data: failures)
|
2021-07-13 11:15:07 +00:00
|
|
|
|
2022-05-10 10:03:40 +00:00
|
|
|
proc prepareBeaconCommitteeSubnet*(
|
2022-07-13 14:43:57 +00:00
|
|
|
vc: ValidatorClientRef,
|
2022-09-29 07:57:14 +00:00
|
|
|
data: seq[RestCommitteeSubscription],
|
2022-11-03 19:23:33 +00:00
|
|
|
): Future[int] {.async.} =
|
|
|
|
logScope: request = "prepareBeaconCommitteeSubnet"
|
2023-02-23 00:11:00 +00:00
|
|
|
let resp = vc.onceToAll(RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-11-03 19:23:33 +00:00
|
|
|
{BeaconNodeRole.AggregatedData},
|
|
|
|
prepareBeaconCommitteeSubnet(it, data))
|
|
|
|
if len(resp.data) == 0:
|
|
|
|
# We did not get any response from beacon nodes.
|
|
|
|
case resp.status
|
|
|
|
of ApiOperation.Success:
|
|
|
|
# This should not be happened, there should be present at least one
|
|
|
|
# successfull response.
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Timeout:
|
|
|
|
debug "Unable to subscribe to beacon committee subnets in time",
|
|
|
|
timeout = SlotDuration
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Interrupt:
|
|
|
|
debug "Beacon committee subscription request was interrupted"
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Failure:
|
|
|
|
debug "Unexpected error happened while subscribing to beacon committee " &
|
|
|
|
"subnets"
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
var count = 0
|
|
|
|
for apiResponse in resp.data:
|
|
|
|
if apiResponse.data.isErr():
|
|
|
|
debug "Unable to subscribe to beacon committee subnets",
|
2023-03-03 20:20:01 +00:00
|
|
|
endpoint = apiResponse.node, error = apiResponse.data.error
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2022-11-03 19:23:33 +00:00
|
|
|
let response = apiResponse.data.get()
|
|
|
|
if response.status == 200:
|
|
|
|
inc(count)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2022-11-03 19:23:33 +00:00
|
|
|
debug "Subscription to beacon commitee subnets failed",
|
|
|
|
status = response.status, endpoint = apiResponse.node,
|
2023-03-03 20:20:01 +00:00
|
|
|
reason = response.getErrorMessage()
|
2022-11-03 19:23:33 +00:00
|
|
|
return count
|
2022-05-10 10:03:40 +00:00
|
|
|
|
|
|
|
proc prepareSyncCommitteeSubnets*(
|
2022-07-13 14:43:57 +00:00
|
|
|
vc: ValidatorClientRef,
|
2022-09-29 07:57:14 +00:00
|
|
|
data: seq[RestSyncCommitteeSubscription],
|
2022-11-03 19:23:33 +00:00
|
|
|
): Future[int] {.async.} =
|
|
|
|
logScope: request = "prepareSyncCommitteeSubnet"
|
2023-02-23 00:11:00 +00:00
|
|
|
let resp = vc.onceToAll(RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-11-03 19:23:33 +00:00
|
|
|
{BeaconNodeRole.SyncCommitteeData},
|
|
|
|
prepareSyncCommitteeSubnets(it, data))
|
|
|
|
if len(resp.data) == 0:
|
|
|
|
# We did not get any response from beacon nodes.
|
|
|
|
case resp.status
|
|
|
|
of ApiOperation.Success:
|
|
|
|
# This should not be happened, there should be present at least one
|
|
|
|
# successfull response.
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Timeout:
|
|
|
|
debug "Unable to prepare sync committee subnets in time",
|
|
|
|
timeout = SlotDuration
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Interrupt:
|
|
|
|
debug "Sync committee subnets preparation request was interrupted"
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Failure:
|
|
|
|
debug "Unexpected error happened while preparing sync committee subnets"
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
var count = 0
|
|
|
|
for apiResponse in resp.data:
|
|
|
|
if apiResponse.data.isErr():
|
|
|
|
debug "Unable to prepare sync committee subnets",
|
2023-03-03 20:20:01 +00:00
|
|
|
endpoint = apiResponse.node, error = apiResponse.data.error
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2022-11-03 19:23:33 +00:00
|
|
|
let response = apiResponse.data.get()
|
|
|
|
if response.status == 200:
|
|
|
|
inc(count)
|
2022-09-29 07:57:14 +00:00
|
|
|
else:
|
2022-11-03 19:23:33 +00:00
|
|
|
debug "Sync committee subnets preparation failed",
|
|
|
|
status = response.status, endpoint = apiResponse.node,
|
|
|
|
message = response.getErrorMessage()
|
|
|
|
return count
|
2022-07-21 16:54:07 +00:00
|
|
|
|
2022-10-21 14:53:30 +00:00
|
|
|
proc prepareBeaconProposer*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
data: seq[PrepareBeaconProposer]
|
|
|
|
): Future[int] {.async.} =
|
|
|
|
logScope: request = "prepareBeaconProposer"
|
2023-02-23 00:11:00 +00:00
|
|
|
let resp = vc.onceToAll(RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-10-21 14:53:30 +00:00
|
|
|
{BeaconNodeRole.BlockProposalPublish},
|
|
|
|
prepareBeaconProposer(it, data))
|
|
|
|
if len(resp.data) == 0:
|
|
|
|
# We did not get any response from beacon nodes.
|
|
|
|
case resp.status
|
|
|
|
of ApiOperation.Success:
|
|
|
|
# This should not be happened, there should be present at least one
|
|
|
|
# successfull response.
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Timeout:
|
|
|
|
debug "Unable to perform beacon proposer preparation request in time",
|
|
|
|
timeout = SlotDuration
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Interrupt:
|
|
|
|
debug "Beacon proposer's preparation request was interrupted"
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Failure:
|
|
|
|
debug "Unexpected error happened while preparing beacon proposers"
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
var count = 0
|
|
|
|
for apiResponse in resp.data:
|
|
|
|
if apiResponse.data.isErr():
|
|
|
|
debug "Unable to perform beacon proposer preparation request",
|
2023-03-03 20:20:01 +00:00
|
|
|
endpoint = apiResponse.node, error = apiResponse.data.error
|
2022-10-21 14:53:30 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.data.get()
|
|
|
|
if response.status == 200:
|
|
|
|
inc(count)
|
|
|
|
else:
|
|
|
|
debug "Beacon proposer preparation failed", status = response.status,
|
2023-03-03 20:20:01 +00:00
|
|
|
endpoint = apiResponse.node, reason = response.getErrorMessage()
|
2022-10-21 14:53:30 +00:00
|
|
|
return count
|
2022-10-29 09:00:51 +00:00
|
|
|
|
|
|
|
proc registerValidator*(
|
|
|
|
vc: ValidatorClientRef,
|
|
|
|
data: seq[SignedValidatorRegistrationV1]
|
|
|
|
): Future[int] {.async.} =
|
|
|
|
logScope: request = "registerValidators"
|
2023-02-23 00:11:00 +00:00
|
|
|
let resp = vc.onceToAll(RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-10-29 09:00:51 +00:00
|
|
|
{BeaconNodeRole.BlockProposalPublish},
|
|
|
|
registerValidator(it, data))
|
|
|
|
if len(resp.data) == 0:
|
|
|
|
# We did not get any response from beacon nodes.
|
|
|
|
case resp.status
|
|
|
|
of ApiOperation.Success:
|
|
|
|
# This should not be happened, there should be present at least one
|
|
|
|
# successfull response.
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Timeout:
|
|
|
|
debug "Unable to register validators in time",
|
|
|
|
timeout = SlotDuration
|
|
|
|
return 0
|
|
|
|
of ApiOperation.Interrupt:
|
|
|
|
debug "Validator registration was interrupted"
|
2023-05-30 08:38:34 +00:00
|
|
|
return 0
|
2022-10-29 09:00:51 +00:00
|
|
|
of ApiOperation.Failure:
|
|
|
|
debug "Unexpected error happened while registering validators"
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
var count = 0
|
|
|
|
for apiResponse in resp.data:
|
|
|
|
if apiResponse.data.isErr():
|
|
|
|
debug "Unable to register validator with beacon node",
|
2023-03-03 20:20:01 +00:00
|
|
|
endpoint = apiResponse.node, error = apiResponse.data.error
|
2022-10-29 09:00:51 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.data.get()
|
|
|
|
if response.status == 200:
|
|
|
|
inc(count)
|
|
|
|
else:
|
|
|
|
debug "Unable to register validators with beacon node",
|
2022-11-03 19:23:33 +00:00
|
|
|
status = response.status, endpoint = apiResponse.node,
|
2023-03-03 20:20:01 +00:00
|
|
|
reason = response.getErrorMessage()
|
2022-10-29 09:00:51 +00:00
|
|
|
return count
|
2022-12-06 11:29:00 +00:00
|
|
|
|
|
|
|
proc getValidatorsLiveness*(
|
|
|
|
vc: ValidatorClientRef, epoch: Epoch,
|
|
|
|
validators: seq[ValidatorIndex]
|
|
|
|
): Future[GetValidatorsLivenessResponse] {.async.} =
|
2023-05-30 08:38:34 +00:00
|
|
|
const
|
2023-09-11 10:07:34 +00:00
|
|
|
RequestName = "getLiveness"
|
2023-02-23 00:11:00 +00:00
|
|
|
let resp = vc.onceToAll(RestPlainResponse,
|
|
|
|
SlotDuration,
|
|
|
|
ViableNodeStatus,
|
2022-12-06 11:29:00 +00:00
|
|
|
{BeaconNodeRole.Duties},
|
|
|
|
getValidatorsLiveness(it, epoch, validators))
|
|
|
|
case resp.status
|
|
|
|
of ApiOperation.Timeout:
|
|
|
|
debug "Unable to perform validator's liveness request in time",
|
|
|
|
timeout = SlotDuration
|
|
|
|
return GetValidatorsLivenessResponse()
|
|
|
|
of ApiOperation.Interrupt:
|
|
|
|
debug "Validator's liveness request was interrupted"
|
|
|
|
return GetValidatorsLivenessResponse()
|
|
|
|
of ApiOperation.Failure:
|
|
|
|
debug "Unexpected error happened while receiving validator's liveness"
|
|
|
|
return GetValidatorsLivenessResponse()
|
|
|
|
of ApiOperation.Success:
|
|
|
|
let defaultLiveness = RestLivenessItem(index: ValidatorIndex(high(uint32)))
|
|
|
|
var activities: Table[ValidatorIndex, RestLivenessItem]
|
|
|
|
for apiResponse in resp.data:
|
|
|
|
if apiResponse.data.isErr():
|
|
|
|
debug "Unable to retrieve validators liveness data",
|
2023-03-03 20:20:01 +00:00
|
|
|
endpoint = apiResponse.node, error = apiResponse.data.error
|
2022-12-06 11:29:00 +00:00
|
|
|
else:
|
|
|
|
let response = apiResponse.data.get()
|
|
|
|
case response.status
|
|
|
|
of 200:
|
|
|
|
let res = decodeBytes(GetValidatorsLivenessResponse,
|
|
|
|
response.data, response.contentType)
|
|
|
|
if res.isOk():
|
|
|
|
let list = res.get().data
|
|
|
|
if len(list) != len(validators):
|
|
|
|
debug "Received incomplete validators liveness response",
|
|
|
|
endpoint = apiResponse.node,
|
|
|
|
validators_count = len(validators),
|
|
|
|
activities_count = len(list)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
var updated = 0
|
|
|
|
for item in list:
|
|
|
|
activities.withValue(item.index, stored):
|
|
|
|
if item.is_live:
|
|
|
|
stored[].is_live = true
|
|
|
|
inc(updated)
|
|
|
|
do:
|
|
|
|
activities[item.index] = item
|
|
|
|
inc(updated)
|
|
|
|
debug "Received validators liveness response",
|
|
|
|
endpoint = apiResponse.node,
|
|
|
|
validators_count = len(validators),
|
|
|
|
activities_count = len(list),
|
|
|
|
updated_count = updated
|
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
let failure = ApiNodeFailure.init(
|
|
|
|
ApiFailure.UnexpectedResponse, RequestName,
|
|
|
|
apiResponse.node, response.status, $res.error)
|
2023-09-11 10:07:34 +00:00
|
|
|
# We do not update beacon node's status anymore because of
|
|
|
|
# issue #5377.
|
2022-12-06 11:29:00 +00:00
|
|
|
continue
|
|
|
|
of 400:
|
2023-05-30 08:38:34 +00:00
|
|
|
let failure = ApiNodeFailure.init(
|
|
|
|
ApiFailure.Invalid, RequestName,
|
|
|
|
apiResponse.node, response.status, response.getErrorMessage())
|
2023-09-11 10:07:34 +00:00
|
|
|
# We do not update beacon node's status anymore because of
|
|
|
|
# issue #5377.
|
2022-12-06 11:29:00 +00:00
|
|
|
continue
|
|
|
|
of 500:
|
2023-05-30 08:38:34 +00:00
|
|
|
let failure = ApiNodeFailure.init(
|
|
|
|
ApiFailure.Internal, RequestName,
|
|
|
|
apiResponse.node, response.status, response.getErrorMessage())
|
2023-09-11 10:07:34 +00:00
|
|
|
# We do not update beacon node's status anymore because of
|
|
|
|
# issue #5377.
|
2022-12-06 11:29:00 +00:00
|
|
|
continue
|
|
|
|
of 503:
|
2023-05-30 08:38:34 +00:00
|
|
|
let failure = ApiNodeFailure.init(
|
|
|
|
ApiFailure.NotSynced, RequestName,
|
|
|
|
apiResponse.node, response.status, response.getErrorMessage())
|
2023-09-11 10:07:34 +00:00
|
|
|
# We do not update beacon node's status anymore because of
|
|
|
|
# issue #5377.
|
2022-12-06 11:29:00 +00:00
|
|
|
continue
|
|
|
|
else:
|
2023-05-30 08:38:34 +00:00
|
|
|
let failure = ApiNodeFailure.init(
|
|
|
|
ApiFailure.UnexpectedCode, RequestName,
|
|
|
|
apiResponse.node, response.status, response.getErrorMessage())
|
2023-09-11 10:07:34 +00:00
|
|
|
# We do not update beacon node's status anymore because of
|
|
|
|
# issue #5377.
|
2022-12-06 11:29:00 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
var response =
|
|
|
|
block:
|
|
|
|
var res: seq[RestLivenessItem]
|
|
|
|
for vindex in validators:
|
|
|
|
let item = activities.getOrDefault(vindex, defaultLiveness)
|
|
|
|
if item == defaultLiveness:
|
|
|
|
debug "Validator is missing in response",
|
|
|
|
validator_index = vindex
|
|
|
|
return GetValidatorsLivenessResponse()
|
|
|
|
else:
|
|
|
|
res.add(item)
|
|
|
|
res
|
|
|
|
|
|
|
|
return GetValidatorsLivenessResponse(data: response)
|