From 218ea42220847e98da2f73c5a058cce8087ac780 Mon Sep 17 00:00:00 2001 From: Eugene Kabanov Date: Wed, 15 Feb 2023 16:09:31 +0200 Subject: [PATCH] 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. --- .../spec/eth2_apis/eth2_rest_serialization.nim | 4 +++- beacon_chain/spec/eth2_apis/rest_types.nim | 8 ++++++-- beacon_chain/validator_client/api.nim | 6 +++--- .../validator_client/sync_committee_service.nim | 14 +++++++++++++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index 8cb94b190..c90111dee 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -132,7 +132,9 @@ type Web3SignerErrorResponse | Web3SignerKeysResponse | Web3SignerSignatureResponse | - Web3SignerStatusResponse + Web3SignerStatusResponse | + GetStateRootResponse | + GetBlockRootResponse RestVersioned*[T] = object data*: T diff --git a/beacon_chain/spec/eth2_apis/rest_types.nim b/beacon_chain/spec/eth2_apis/rest_types.nim index 206edaca9..e6d2e9c73 100644 --- a/beacon_chain/spec/eth2_apis/rest_types.nim +++ b/beacon_chain/spec/eth2_apis/rest_types.nim @@ -613,6 +613,10 @@ type RestRoot* = object root*: Eth2Digest + DataRestRoot* = object + execution_optimistic*: Option[bool] + data*: RestRoot + # Types based on the OAPI yaml file - used in responses to requests GetBeaconHeadResponse* = DataEnclosedObject[Slot] GetAggregatedAttestationResponse* = DataEnclosedObject[Attestation] @@ -620,7 +624,7 @@ type GetBlockAttestationsResponse* = DataEnclosedObject[seq[Attestation]] GetBlockHeaderResponse* = DataEnclosedObject[RestBlockHeaderInfo] GetBlockHeadersResponse* = DataEnclosedObject[seq[RestBlockHeaderInfo]] - GetBlockRootResponse* = DataEnclosedObject[RestRoot] + GetBlockRootResponse* = DataRestRoot GetDebugChainHeadsResponse* = DataEnclosedObject[seq[RestChainHead]] GetDepositContractResponse* = DataEnclosedObject[RestDepositContract] GetDepositSnapshotResponse* = DataEnclosedObject[RestDepositSnapshot] @@ -641,7 +645,7 @@ type GetSpecVCResponse* = DataEnclosedObject[RestSpecVC] GetStateFinalityCheckpointsResponse* = DataEnclosedObject[RestBeaconStatesFinalityCheckpoints] GetStateForkResponse* = DataEnclosedObject[Fork] - GetStateRootResponse* = DataEnclosedObject[RestRoot] + GetStateRootResponse* = DataRestRoot GetStateValidatorBalancesResponse* = DataEnclosedObject[seq[RestValidatorBalance]] GetStateValidatorResponse* = DataEnclosedObject[RestValidator] GetStateValidatorsResponse* = DataEnclosedObject[seq[RestValidator]] diff --git a/beacon_chain/validator_client/api.nim b/beacon_chain/validator_client/api.nim index 147d930a7..6d8b00ea5 100644 --- a/beacon_chain/validator_client/api.nim +++ b/beacon_chain/validator_client/api.nim @@ -895,7 +895,7 @@ proc getForkSchedule*( proc getHeadBlockRoot*( vc: ValidatorClientRef, strategy: ApiStrategyKind - ): Future[RestRoot] {.async.} = + ): Future[DataRestRoot] {.async.} = logScope: request = "getHeadBlockRoot" strategy = $strategy @@ -937,7 +937,7 @@ proc getHeadBlockRoot*( RestBeaconNodeStatus.Offline if res.isErr(): raise newException(ValidatorApiError, res.error()) - return res.get().data.data + return res.get().data of ApiStrategyKind.Priority: vc.firstSuccessSequential(RestResponse[GetBlockRootResponse], SlotDuration, @@ -951,7 +951,7 @@ proc getHeadBlockRoot*( case response.status of 200: trace ResponseSuccess, endpoint = node - return response.data.data + return response.data of 400: debug ResponseInvalidError, response_code = response.status, endpoint = node diff --git a/beacon_chain/validator_client/sync_committee_service.nim b/beacon_chain/validator_client/sync_committee_service.nim index bae5e2728..dd3efc6b0 100644 --- a/beacon_chain/validator_client/sync_committee_service.nim +++ b/beacon_chain/validator_client/sync_committee_service.nim @@ -348,7 +348,19 @@ proc publishSyncMessagesAndContributions(service: SyncCommitteeServiceRef, block: try: 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: error "Unable to retrieve head block's root to sign", reason = exc.msg return