VC: Fix getBlockRoot() response with execution_optimistic. (#4622)
* Fix getStateRoot() and getBlockRoot() API functions which should obtain `execution_optimistic` field. Fix sync committee service to check `execution_optimistic` field of getBlockRoot() response. * 2nd part. * Remove presets usage.
This commit is contained in:
parent
822c339607
commit
218ea42220
|
@ -132,7 +132,9 @@ type
|
||||||
Web3SignerErrorResponse |
|
Web3SignerErrorResponse |
|
||||||
Web3SignerKeysResponse |
|
Web3SignerKeysResponse |
|
||||||
Web3SignerSignatureResponse |
|
Web3SignerSignatureResponse |
|
||||||
Web3SignerStatusResponse
|
Web3SignerStatusResponse |
|
||||||
|
GetStateRootResponse |
|
||||||
|
GetBlockRootResponse
|
||||||
|
|
||||||
RestVersioned*[T] = object
|
RestVersioned*[T] = object
|
||||||
data*: T
|
data*: T
|
||||||
|
|
|
@ -613,6 +613,10 @@ type
|
||||||
RestRoot* = object
|
RestRoot* = object
|
||||||
root*: Eth2Digest
|
root*: Eth2Digest
|
||||||
|
|
||||||
|
DataRestRoot* = object
|
||||||
|
execution_optimistic*: Option[bool]
|
||||||
|
data*: RestRoot
|
||||||
|
|
||||||
# Types based on the OAPI yaml file - used in responses to requests
|
# Types based on the OAPI yaml file - used in responses to requests
|
||||||
GetBeaconHeadResponse* = DataEnclosedObject[Slot]
|
GetBeaconHeadResponse* = DataEnclosedObject[Slot]
|
||||||
GetAggregatedAttestationResponse* = DataEnclosedObject[Attestation]
|
GetAggregatedAttestationResponse* = DataEnclosedObject[Attestation]
|
||||||
|
@ -620,7 +624,7 @@ type
|
||||||
GetBlockAttestationsResponse* = DataEnclosedObject[seq[Attestation]]
|
GetBlockAttestationsResponse* = DataEnclosedObject[seq[Attestation]]
|
||||||
GetBlockHeaderResponse* = DataEnclosedObject[RestBlockHeaderInfo]
|
GetBlockHeaderResponse* = DataEnclosedObject[RestBlockHeaderInfo]
|
||||||
GetBlockHeadersResponse* = DataEnclosedObject[seq[RestBlockHeaderInfo]]
|
GetBlockHeadersResponse* = DataEnclosedObject[seq[RestBlockHeaderInfo]]
|
||||||
GetBlockRootResponse* = DataEnclosedObject[RestRoot]
|
GetBlockRootResponse* = DataRestRoot
|
||||||
GetDebugChainHeadsResponse* = DataEnclosedObject[seq[RestChainHead]]
|
GetDebugChainHeadsResponse* = DataEnclosedObject[seq[RestChainHead]]
|
||||||
GetDepositContractResponse* = DataEnclosedObject[RestDepositContract]
|
GetDepositContractResponse* = DataEnclosedObject[RestDepositContract]
|
||||||
GetDepositSnapshotResponse* = DataEnclosedObject[RestDepositSnapshot]
|
GetDepositSnapshotResponse* = DataEnclosedObject[RestDepositSnapshot]
|
||||||
|
@ -641,7 +645,7 @@ type
|
||||||
GetSpecVCResponse* = DataEnclosedObject[RestSpecVC]
|
GetSpecVCResponse* = DataEnclosedObject[RestSpecVC]
|
||||||
GetStateFinalityCheckpointsResponse* = DataEnclosedObject[RestBeaconStatesFinalityCheckpoints]
|
GetStateFinalityCheckpointsResponse* = DataEnclosedObject[RestBeaconStatesFinalityCheckpoints]
|
||||||
GetStateForkResponse* = DataEnclosedObject[Fork]
|
GetStateForkResponse* = DataEnclosedObject[Fork]
|
||||||
GetStateRootResponse* = DataEnclosedObject[RestRoot]
|
GetStateRootResponse* = DataRestRoot
|
||||||
GetStateValidatorBalancesResponse* = DataEnclosedObject[seq[RestValidatorBalance]]
|
GetStateValidatorBalancesResponse* = DataEnclosedObject[seq[RestValidatorBalance]]
|
||||||
GetStateValidatorResponse* = DataEnclosedObject[RestValidator]
|
GetStateValidatorResponse* = DataEnclosedObject[RestValidator]
|
||||||
GetStateValidatorsResponse* = DataEnclosedObject[seq[RestValidator]]
|
GetStateValidatorsResponse* = DataEnclosedObject[seq[RestValidator]]
|
||||||
|
|
|
@ -895,7 +895,7 @@ proc getForkSchedule*(
|
||||||
proc getHeadBlockRoot*(
|
proc getHeadBlockRoot*(
|
||||||
vc: ValidatorClientRef,
|
vc: ValidatorClientRef,
|
||||||
strategy: ApiStrategyKind
|
strategy: ApiStrategyKind
|
||||||
): Future[RestRoot] {.async.} =
|
): Future[DataRestRoot] {.async.} =
|
||||||
logScope:
|
logScope:
|
||||||
request = "getHeadBlockRoot"
|
request = "getHeadBlockRoot"
|
||||||
strategy = $strategy
|
strategy = $strategy
|
||||||
|
@ -937,7 +937,7 @@ proc getHeadBlockRoot*(
|
||||||
RestBeaconNodeStatus.Offline
|
RestBeaconNodeStatus.Offline
|
||||||
if res.isErr():
|
if res.isErr():
|
||||||
raise newException(ValidatorApiError, res.error())
|
raise newException(ValidatorApiError, res.error())
|
||||||
return res.get().data.data
|
return res.get().data
|
||||||
|
|
||||||
of ApiStrategyKind.Priority:
|
of ApiStrategyKind.Priority:
|
||||||
vc.firstSuccessSequential(RestResponse[GetBlockRootResponse], SlotDuration,
|
vc.firstSuccessSequential(RestResponse[GetBlockRootResponse], SlotDuration,
|
||||||
|
@ -951,7 +951,7 @@ proc getHeadBlockRoot*(
|
||||||
case response.status
|
case response.status
|
||||||
of 200:
|
of 200:
|
||||||
trace ResponseSuccess, endpoint = node
|
trace ResponseSuccess, endpoint = node
|
||||||
return response.data.data
|
return response.data
|
||||||
of 400:
|
of 400:
|
||||||
debug ResponseInvalidError, response_code = response.status,
|
debug ResponseInvalidError, response_code = response.status,
|
||||||
endpoint = node
|
endpoint = node
|
||||||
|
|
|
@ -348,7 +348,19 @@ proc publishSyncMessagesAndContributions(service: SyncCommitteeServiceRef,
|
||||||
block:
|
block:
|
||||||
try:
|
try:
|
||||||
let res = await vc.getHeadBlockRoot(ApiStrategyKind.First)
|
let res = await vc.getHeadBlockRoot(ApiStrategyKind.First)
|
||||||
res.root
|
if res.execution_optimistic.isNone():
|
||||||
|
## The `execution_optimistic` is missing from the response, we assume
|
||||||
|
## that the BN is unaware optimistic sync, so we consider the BN
|
||||||
|
## to be synchronized with the network.
|
||||||
|
## TODO (cheatfate): This should be removed when VC will be able to
|
||||||
|
## handle getSpec() API call with fork constants.
|
||||||
|
res.data.root
|
||||||
|
else:
|
||||||
|
if res.execution_optimistic.get():
|
||||||
|
error "Could not obtain head block's root because beacon node " &
|
||||||
|
"only optimistically synced", slot = slot
|
||||||
|
return
|
||||||
|
res.data.root
|
||||||
except ValidatorApiError as exc:
|
except ValidatorApiError as exc:
|
||||||
error "Unable to retrieve head block's root to sign", reason = exc.msg
|
error "Unable to retrieve head block's root to sign", reason = exc.msg
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue