Retrospective invalidation of exec. payloads for opt. sync (#2837)

## Issue Addressed

NA

## Proposed Changes

Adds the functionality to allow blocks to be validated/invalidated after their import as per the [optimistic sync spec](https://github.com/ethereum/consensus-specs/blob/dev/sync/optimistic.md#how-to-optimistically-import-blocks). This means:

- Updating `ProtoArray` to allow flipping the `execution_status` of ancestors/descendants based on payload validity updates.
- Creating separation between `execution_layer` and the `beacon_chain` by creating a `PayloadStatus` struct.
- Refactoring how the `execution_layer` selects a `PayloadStatus` from the multiple statuses returned from multiple EEs.
- Adding testing framework for optimistic imports.
- Add `ExecutionBlockHash(Hash256)` new-type struct to avoid confusion between *beacon block roots* and *execution payload hashes*.
- Add `merge` to [`FORKS`](c3a793fd73/Makefile (L17)) in the `Makefile` to ensure we test the beacon chain with merge settings.
    - Fix some tests here that were failing due to a missing execution layer.

## TODO

- [ ] Balance tests

Co-authored-by: Mark Mackey <mark@sigmaprime.io>
This commit is contained in:
Paul Hauner
2022-02-28 22:07:48 +00:00
parent 5e1f8a8480
commit 27e83b888c
50 changed files with 3358 additions and 768 deletions

View File

@@ -1,5 +1,5 @@
use super::Context;
use crate::engine_api::{http::*, PayloadStatusV1, PayloadStatusV1Status};
use crate::engine_api::{http::*, *};
use crate::json_structures::*;
use serde::de::DeserializeOwned;
use serde_json::Value as JsonValue;
@@ -57,26 +57,29 @@ pub async fn handle_rpc<T: EthSpec>(
ENGINE_NEW_PAYLOAD_V1 => {
let request: JsonExecutionPayloadV1<T> = get_param(params, 0)?;
let response = if let Some(status) = *ctx.static_new_payload_response.lock() {
match status {
PayloadStatusV1Status::Valid => PayloadStatusV1 {
status,
latest_valid_hash: Some(request.block_hash),
validation_error: None,
},
PayloadStatusV1Status::Syncing => PayloadStatusV1 {
status,
latest_valid_hash: None,
validation_error: None,
},
_ => unimplemented!("invalid static newPayloadResponse"),
}
let (static_response, should_import) =
if let Some(mut response) = ctx.static_new_payload_response.lock().clone() {
if response.status.status == PayloadStatusV1Status::Valid {
response.status.latest_valid_hash = Some(request.block_hash)
}
(Some(response.status), response.should_import)
} else {
(None, true)
};
let dynamic_response = if should_import {
Some(
ctx.execution_block_generator
.write()
.new_payload(request.into()),
)
} else {
ctx.execution_block_generator
.write()
.new_payload(request.into())
None
};
let response = static_response.or(dynamic_response).unwrap();
Ok(serde_json::to_value(JsonPayloadStatusV1::from(response)).unwrap())
}
ENGINE_GET_PAYLOAD_V1 => {
@@ -95,8 +98,7 @@ pub async fn handle_rpc<T: EthSpec>(
let forkchoice_state: JsonForkChoiceStateV1 = get_param(params, 0)?;
let payload_attributes: Option<JsonPayloadAttributesV1> = get_param(params, 1)?;
let head_block_hash = forkchoice_state.head_block_hash;
let id = ctx
let response = ctx
.execution_block_generator
.write()
.forkchoice_updated_v1(
@@ -104,15 +106,7 @@ pub async fn handle_rpc<T: EthSpec>(
payload_attributes.map(|json| json.into()),
)?;
Ok(serde_json::to_value(JsonForkchoiceUpdatedV1Response {
payload_status: JsonPayloadStatusV1 {
status: JsonPayloadStatusV1Status::Valid,
latest_valid_hash: Some(head_block_hash),
validation_error: None,
},
payload_id: id.map(Into::into),
})
.unwrap())
Ok(serde_json::to_value(response).unwrap())
}
other => Err(format!(
"The method {} does not exist/is not available",