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 |
|
||||
Web3SignerKeysResponse |
|
||||
Web3SignerSignatureResponse |
|
||||
Web3SignerStatusResponse
|
||||
Web3SignerStatusResponse |
|
||||
GetStateRootResponse |
|
||||
GetBlockRootResponse
|
||||
|
||||
RestVersioned*[T] = object
|
||||
data*: T
|
||||
|
|
|
@ -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]]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue