pub fn validate_parent_beacon_block_root_presence(
    chain_spec: &ChainSpec,
    version: EngineApiMessageVersion,
    validation_kind: MessageValidationKind,
    timestamp: u64,
    has_parent_beacon_block_root: bool
) -> Result<(), EngineObjectValidationError>
Expand description

Validate the presence of the parentBeaconBlockRoot field according to the given timestamp. This method is meant to be used with either a payloadAttributes field or a full payload, with the engine_forkchoiceUpdated and engine_newPayload methods respectively.

After Cancun, the parentBeaconBlockRoot field must be Some. Before Cancun, the parentBeaconBlockRoot field must be None.

If the engine API message version is V1 or V2, and the timestamp is post-Cancun, then this will return EngineObjectValidationError::UnsupportedFork.

If the timestamp is before the Cancun fork and the engine API message version is V3, then this will return EngineObjectValidationError::UnsupportedFork.

If the engine API message version is V3, but the parentBeaconBlockRoot is None, then this will return VersionSpecificValidationError::NoParentBeaconBlockRootPostCancun.

This implements the following Engine API spec rules:

  1. Client software MUST check that provided set of parameters and their fields strictly matches the expected one and return -32602: Invalid params error if this check fails. Any field having null value MUST be considered as not provided.

For engine_forkchoiceUpdatedV3:

  1. Client software MUST check that provided set of parameters and their fields strictly matches the expected one and return -32602: Invalid params error if this check fails. Any field having null value MUST be considered as not provided.

  2. Extend point (7) of the engine_forkchoiceUpdatedV1 specification by defining the following sequence of checks that MUST be run over payloadAttributes:

    1. payloadAttributes matches the PayloadAttributesV3 structure, return -38003: Invalid payload attributes on failure.
    2. payloadAttributes.timestamp falls within the time frame of the Cancun fork, return -38005: Unsupported fork on failure.
    3. payloadAttributes.timestamp is greater than timestamp of a block referenced by forkchoiceState.headBlockHash, return -38003: Invalid payload attributes on failure.
    4. If any of the above checks fails, the forkchoiceState update MUST NOT be rolled back.

For engine_newPayloadV3:

  1. Client software MUST return -38005: Unsupported fork error if the timestamp of the payload does not fall within the time frame of the Cancun fork.

Returning the right error code (ie, if the client should return -38003: Invalid payload attributes is handled by the message_validation_kind parameter. If the parameter is MessageValidationKind::Payload, then the error code will be -32602: Invalid params. If the parameter is MessageValidationKind::PayloadAttributes, then the error code will be -38003: Invalid payload attributes.