After bump fixes.

This commit is contained in:
cheatfate 2023-06-03 13:31:44 +03:00
parent 7a3bbfd6e2
commit 956cdc076e
No known key found for this signature in database
GPG Key ID: 46ADD633A7201F95
2 changed files with 46 additions and 119 deletions

View File

@ -678,6 +678,12 @@ template handle500(): untyped {.dirty.} =
node.updateStatus(RestBeaconNodeStatus.InternalError, failure) node.updateStatus(RestBeaconNodeStatus.InternalError, failure)
failures.add(failure) failures.add(failure)
template handle501(): untyped {.dirty.} =
let failure = ApiNodeFailure.init(ApiFailure.NotImplemented, RequestName,
strategy, node, response.status, response.getErrorMessage())
node.updateStatus(RestBeaconNodeStatus.Incompatible, failure)
failures.add(failure)
template handle503(): untyped {.dirty.} = template handle503(): untyped {.dirty.} =
let failure = ApiNodeFailure.init(ApiFailure.NotSynced, RequestName, let failure = ApiNodeFailure.init(ApiFailure.NotSynced, RequestName,
strategy, node, response.status, response.getErrorMessage()) strategy, node, response.status, response.getErrorMessage())
@ -2439,11 +2445,8 @@ proc submitBeaconCommitteeSelections*(
data: seq[RestBeaconCommitteeSelection], data: seq[RestBeaconCommitteeSelection],
strategy: ApiStrategyKind strategy: ApiStrategyKind
): Future[SubmitBeaconCommitteeSelectionsResponse] {.async.} = ): Future[SubmitBeaconCommitteeSelectionsResponse] {.async.} =
logScope: const
request = "submitBeaconCommitteeSelections" RequestName = "submitBeaconCommitteeSelections"
strategy = $strategy
const ErrorMessage = "Unable to submit beacon committee selections"
var failures: seq[ApiNodeFailure] var failures: seq[ApiNodeFailure]
@ -2457,9 +2460,7 @@ proc submitBeaconCommitteeSelections*(
{BeaconNodeRole.Duties}, {BeaconNodeRole.Duties},
submitBeaconCommitteeSelectionsPlain(it, data)): submitBeaconCommitteeSelectionsPlain(it, data)):
if apiResponse.isErr(): if apiResponse.isErr():
debug ErrorMessage, endpoint = node, error = apiResponse.error handleCommunicationError()
node.updateStatus(RestBeaconNodeStatus.Offline)
failures.add(ApiNodeFailure.init(node, ApiFailure.Communication))
ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err( ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err(
apiResponse.error) apiResponse.error)
else: else:
@ -2469,43 +2470,28 @@ proc submitBeaconCommitteeSelections*(
let res = decodeBytes(SubmitBeaconCommitteeSelectionsResponse, let res = decodeBytes(SubmitBeaconCommitteeSelectionsResponse,
response.data, response.contentType) response.data, response.contentType)
if res.isErr(): if res.isErr():
node.updateStatus(RestBeaconNodeStatus.Unexpected) handleUnexpectedData()
ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err($res.error) ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err($res.error)
else: else:
ApiResponse[SubmitBeaconCommitteeSelectionsResponse].ok(res.get()) ApiResponse[SubmitBeaconCommitteeSelectionsResponse].ok(res.get())
of 400: of 400:
debug ResponseInvalidError, response_code = response.status, handle400()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Incompatible)
failures.add(ApiNodeFailure.init(node, ApiFailure.Invalid))
ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err( ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err(
ResponseInvalidError) ResponseInvalidError)
of 500: of 500:
debug ResponseInternalError, response_code = response.status, handle500()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.InternalError)
failures.add(ApiNodeFailure.init(node, ApiFailure.Internal))
ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err( ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err(
ResponseInternalError) ResponseInternalError)
of 501: of 501:
warn ResponseNotImplementedError, response_code = response.status, handle501()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Incompatible)
failures.add(ApiNodeFailure.init(node, ApiFailure.Invalid))
ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err( ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err(
ResponseNotImplementedError) ResponseNotImplementedError)
of 503: of 503:
debug ResponseNoSyncError, response_code = response.status, handle503()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.NotSynced)
failures.add(ApiNodeFailure.init(node, ApiFailure.NotSynced))
ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err( ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err(
ResponseNoSyncError) ResponseNoSyncError)
else: else:
debug ResponseUnexpectedError, response_code = response.status, handleUnexpectedCode()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Unexpected)
failures.add(ApiNodeFailure.init(node, ApiFailure.Unexpected))
ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err( ApiResponse[SubmitBeaconCommitteeSelectionsResponse].err(
ResponseUnexpectedError) ResponseUnexpectedError)
@ -2520,9 +2506,7 @@ proc submitBeaconCommitteeSelections*(
{BeaconNodeRole.Duties}, {BeaconNodeRole.Duties},
submitBeaconCommitteeSelectionsPlain(it, data)): submitBeaconCommitteeSelectionsPlain(it, data)):
if apiResponse.isErr(): if apiResponse.isErr():
debug ErrorMessage, endpoint = node, error = apiResponse.error handleCommunicationError()
node.updateStatus(RestBeaconNodeStatus.Offline)
failures.add(ApiNodeFailure.init(node, ApiFailure.Communication))
false false
else: else:
let response = apiResponse.get() let response = apiResponse.get()
@ -2530,56 +2514,35 @@ proc submitBeaconCommitteeSelections*(
of 200: of 200:
let res = decodeBytes(SubmitBeaconCommitteeSelectionsResponse, let res = decodeBytes(SubmitBeaconCommitteeSelectionsResponse,
response.data, response.contentType) response.data, response.contentType)
if res.isOk(): if res.isOk(): return res.get()
return res.get() handleUnexpectedData()
debug ResponseDecodeError, response_code = response.status,
endpoint = node, reason = res.error
node.updateStatus(RestBeaconNodeStatus.Unexpected)
failures.add(ApiNodeFailure.init(node, ApiFailure.Invalid))
false false
of 400: of 400:
debug ResponseInvalidError, response_code = response.status, handle400()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Incompatible)
failures.add(ApiNodeFailure.init(node, ApiFailure.Invalid))
false false
of 500: of 500:
debug ResponseInternalError, response_code = response.status, handle500()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.InternalError)
failures.add(ApiNodeFailure.init(node, ApiFailure.Internal))
false false
of 501: of 501:
warn ResponseNotImplementedError, response_code = response.status, handle501()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Incompatible)
failures.add(ApiNodeFailure.init(node, ApiFailure.Invalid))
false false
of 503: of 503:
debug ResponseNoSyncError, response_code = response.status, handle503()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.NotSynced)
failures.add(ApiNodeFailure.init(node, ApiFailure.NotSynced))
false false
else: else:
debug ResponseUnexpectedError, response_code = response.status, handleUnexpectedCode()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Unexpected)
failures.add(ApiNodeFailure.init(node, ApiFailure.Unexpected))
false false
raise (ref ValidatorApiError)(msg: ErrorMessage, data: failures) raise (ref ValidatorApiError)(
msg: "Failed to submit beacon committee selections", data: failures)
proc submitSyncCommitteeSelections*( proc submitSyncCommitteeSelections*(
vc: ValidatorClientRef, vc: ValidatorClientRef,
data: seq[RestSyncCommitteeSelection], data: seq[RestSyncCommitteeSelection],
strategy: ApiStrategyKind strategy: ApiStrategyKind
): Future[SubmitSyncCommitteeSelectionsResponse] {.async.} = ): Future[SubmitSyncCommitteeSelectionsResponse] {.async.} =
logScope: const
request = "submitSyncCommitteeSelections" RequestName = "submitBeaconCommitteeSelections"
strategy = $strategy
const ErrorMessage = "Unable to submit sync committee selections"
var failures: seq[ApiNodeFailure] var failures: seq[ApiNodeFailure]
@ -2593,9 +2556,7 @@ proc submitSyncCommitteeSelections*(
{BeaconNodeRole.Duties}, {BeaconNodeRole.Duties},
submitSyncCommitteeSelectionsPlain(it, data)): submitSyncCommitteeSelectionsPlain(it, data)):
if apiResponse.isErr(): if apiResponse.isErr():
debug ErrorMessage, endpoint = node, error = apiResponse.error handleCommunicationError()
node.updateStatus(RestBeaconNodeStatus.Offline)
failures.add(ApiNodeFailure.init(node, ApiFailure.Communication))
ApiResponse[SubmitSyncCommitteeSelectionsResponse].err( ApiResponse[SubmitSyncCommitteeSelectionsResponse].err(
apiResponse.error) apiResponse.error)
else: else:
@ -2605,43 +2566,28 @@ proc submitSyncCommitteeSelections*(
let res = decodeBytes(SubmitSyncCommitteeSelectionsResponse, let res = decodeBytes(SubmitSyncCommitteeSelectionsResponse,
response.data, response.contentType) response.data, response.contentType)
if res.isErr(): if res.isErr():
node.updateStatus(RestBeaconNodeStatus.Unexpected) handleUnexpectedData()
ApiResponse[SubmitSyncCommitteeSelectionsResponse].err($res.error) ApiResponse[SubmitSyncCommitteeSelectionsResponse].err($res.error)
else: else:
ApiResponse[SubmitSyncCommitteeSelectionsResponse].ok(res.get()) ApiResponse[SubmitSyncCommitteeSelectionsResponse].ok(res.get())
of 400: of 400:
debug ResponseInvalidError, response_code = response.status, handle400()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Incompatible)
failures.add(ApiNodeFailure.init(node, ApiFailure.Invalid))
ApiResponse[SubmitSyncCommitteeSelectionsResponse].err( ApiResponse[SubmitSyncCommitteeSelectionsResponse].err(
ResponseInvalidError) ResponseInvalidError)
of 500: of 500:
debug ResponseInternalError, response_code = response.status, handle500()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.InternalError)
failures.add(ApiNodeFailure.init(node, ApiFailure.Internal))
ApiResponse[SubmitSyncCommitteeSelectionsResponse].err( ApiResponse[SubmitSyncCommitteeSelectionsResponse].err(
ResponseInternalError) ResponseInternalError)
of 501: of 501:
warn ResponseNotImplementedError, response_code = response.status, handle501()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Incompatible)
failures.add(ApiNodeFailure.init(node, ApiFailure.Invalid))
ApiResponse[SubmitSyncCommitteeSelectionsResponse].err( ApiResponse[SubmitSyncCommitteeSelectionsResponse].err(
ResponseNotImplementedError) ResponseNotImplementedError)
of 503: of 503:
debug ResponseNoSyncError, response_code = response.status, handle503()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.NotSynced)
failures.add(ApiNodeFailure.init(node, ApiFailure.NotSynced))
ApiResponse[SubmitSyncCommitteeSelectionsResponse].err( ApiResponse[SubmitSyncCommitteeSelectionsResponse].err(
ResponseNoSyncError) ResponseNoSyncError)
else: else:
debug ResponseUnexpectedError, response_code = response.status, handleUnexpectedCode()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Unexpected)
failures.add(ApiNodeFailure.init(node, ApiFailure.Unexpected))
ApiResponse[SubmitSyncCommitteeSelectionsResponse].err( ApiResponse[SubmitSyncCommitteeSelectionsResponse].err(
ResponseUnexpectedError) ResponseUnexpectedError)
@ -2656,9 +2602,7 @@ proc submitSyncCommitteeSelections*(
{BeaconNodeRole.Duties}, {BeaconNodeRole.Duties},
submitSyncCommitteeSelectionsPlain(it, data)): submitSyncCommitteeSelectionsPlain(it, data)):
if apiResponse.isErr(): if apiResponse.isErr():
debug ErrorMessage, endpoint = node, error = apiResponse.error handleCommunicationError()
node.updateStatus(RestBeaconNodeStatus.Offline)
failures.add(ApiNodeFailure.init(node, ApiFailure.Communication))
false false
else: else:
let response = apiResponse.get() let response = apiResponse.get()
@ -2666,42 +2610,24 @@ proc submitSyncCommitteeSelections*(
of 200: of 200:
let res = decodeBytes(SubmitSyncCommitteeSelectionsResponse, let res = decodeBytes(SubmitSyncCommitteeSelectionsResponse,
response.data, response.contentType) response.data, response.contentType)
if res.isOk(): if res.isOk(): return res.get()
return res.get() handleUnexpectedData()
debug ResponseDecodeError, response_code = response.status,
endpoint = node, reason = res.error
node.updateStatus(RestBeaconNodeStatus.Unexpected)
failures.add(ApiNodeFailure.init(node, ApiFailure.Invalid))
false false
of 400: of 400:
debug ResponseInvalidError, response_code = response.status, handle400()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Incompatible)
failures.add(ApiNodeFailure.init(node, ApiFailure.Invalid))
false false
of 500: of 500:
debug ResponseInternalError, response_code = response.status, handle500()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.InternalError)
failures.add(ApiNodeFailure.init(node, ApiFailure.Internal))
false false
of 501: of 501:
warn ResponseNotImplementedError, response_code = response.status, handle501()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Incompatible)
failures.add(ApiNodeFailure.init(node, ApiFailure.Invalid))
false false
of 503: of 503:
debug ResponseNoSyncError, response_code = response.status, handle503()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.NotSynced)
failures.add(ApiNodeFailure.init(node, ApiFailure.NotSynced))
false false
else: else:
debug ResponseUnexpectedError, response_code = response.status, handleUnexpectedCode()
endpoint = node, reason = response.getErrorMessage()
node.updateStatus(RestBeaconNodeStatus.Unexpected)
failures.add(ApiNodeFailure.init(node, ApiFailure.Unexpected))
false false
raise (ref ValidatorApiError)(msg: ErrorMessage, data: failures) raise (ref ValidatorApiError)(
msg: "Failed to submit sync committee selections", data: failures)

View File

@ -199,7 +199,7 @@ type
ApiFailure* {.pure.} = enum ApiFailure* {.pure.} = enum
Communication, Invalid, NotFound, OptSynced, NotSynced, Internal, Communication, Invalid, NotFound, OptSynced, NotSynced, Internal,
UnexpectedCode, UnexpectedResponse, NoError NotImplemented, UnexpectedCode, UnexpectedResponse, NoError
ApiNodeFailure* = object ApiNodeFailure* = object
node*: BeaconNodeServerRef node*: BeaconNodeServerRef
@ -281,6 +281,7 @@ proc `$`*(failure: ApiFailure): string =
of ApiFailure.NotSynced: "not-synced" of ApiFailure.NotSynced: "not-synced"
of ApiFailure.OptSynced: "opt-synced" of ApiFailure.OptSynced: "opt-synced"
of ApiFailure.Internal: "internal-issue" of ApiFailure.Internal: "internal-issue"
of ApiFailure.NotImplemented: "not-implemented"
of ApiFailure.UnexpectedCode: "unexpected-code" of ApiFailure.UnexpectedCode: "unexpected-code"
of ApiFailure.UnexpectedResponse: "unexpected-data" of ApiFailure.UnexpectedResponse: "unexpected-data"
of ApiFailure.NoError: "status-update" of ApiFailure.NoError: "status-update"