Sidecar inclusion proof (#4900)

* Refactor BlobSidecar to new type

* Fix some compile errors

* Gossip verification compiles

* Fix http api types take 1

* Fix another round of compile errors

* Beacon node crate compiles

* EF tests compile

* Remove all blob signing from VC

* fmt

* Tests compile

* Fix some tests

* Fix more http tests

* get compiling

* Fix gossip conditions and tests

* Add basic proof generation and verification

* remove unnecessary ssz decode

* add back build_sidecar

* remove default at fork for blobs

* fix beacon chain tests

* get relase tests compiling

* fix lints

* fix existing spec tests

* add new ef tests

* fix gossip duplicate rule

* lints

* add back sidecar signature check in gossip

* add finalized descendant check to blob sidecar gossip

* fix error conversion

* fix release tests

* sidecar inclusion self review cleanup

* Add proof verification and computation metrics

* Remove accidentally committed file

* Unify some block and blob errors; add slashing conditions for sidecars

* Address review comment

* Clean up re-org tests (#4957)

* Address more review comments

* Add Comments & Eliminate Unnecessary Clones

* update names

* Update beacon_node/beacon_chain/src/metrics.rs

Co-authored-by: Jimmy Chen <jchen.tc@gmail.com>

* Update beacon_node/network/src/network_beacon_processor/tests.rs

Co-authored-by: Jimmy Chen <jchen.tc@gmail.com>

* pr feedback

* fix test compile

* Sidecar Inclusion proof small refactor and updates (#4967)

* Update some comments, variables and small cosmetic fixes.

* Couple blobs and proofs into a tuple in `PayloadAndBlobs` for simplicity and safety.

* Update function comment.

* Update testing/ef_tests/src/cases/merkle_proof_validity.rs

Co-authored-by: Jimmy Chen <jchen.tc@gmail.com>

* Rename the block and blob wrapper types used in the beacon API interfaces.

* make sure gossip invalid blobs are passed to the slasher (#4970)

* Add blob headers to slasher before adding to DA checker

* Replace Vec with HashSet in BlockQueue

* fmt

* Rename gindex -> index

* Simplify gossip condition

---------

Co-authored-by: realbigsean <seananderson33@gmail.com>
Co-authored-by: realbigsean <sean@sigmaprime.io>
Co-authored-by: Michael Sproul <michael@sigmaprime.io>
Co-authored-by: Mark Mackey <mark@sigmaprime.io>
Co-authored-by: Jimmy Chen <jchen.tc@gmail.com>
This commit is contained in:
Pawan Dhananjay
2023-12-05 08:19:59 -08:00
committed by GitHub
parent ec8edfb89a
commit 31044402ee
74 changed files with 1950 additions and 2270 deletions

View File

@@ -3,8 +3,7 @@ use std::sync::Arc;
use types::{payload::BlockProductionVersion, *};
use beacon_chain::{
BeaconBlockResponse, BeaconBlockResponseType, BeaconChain, BeaconChainTypes,
ProduceBlockVerification,
BeaconBlockResponseWrapper, BeaconChain, BeaconChainTypes, ProduceBlockVerification,
};
use eth2::types::{self as api_types, EndpointVersion, SkipRandaoVerification};
use ssz::Encode;
@@ -69,35 +68,23 @@ pub async fn produce_block_v3<T: BeaconChainTypes>(
warp_utils::reject::custom_bad_request(format!("failed to fetch a block: {:?}", e))
})?;
match block_response_type {
BeaconBlockResponseType::Full(block_response) => {
build_response_v3(chain, block_response, endpoint_version, accept_header)
}
BeaconBlockResponseType::Blinded(block_response) => {
build_response_v3(chain, block_response, endpoint_version, accept_header)
}
}
build_response_v3(chain, block_response_type, endpoint_version, accept_header)
}
pub fn build_response_v3<T: BeaconChainTypes, E: EthSpec, Payload: AbstractExecPayload<E>>(
pub fn build_response_v3<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
block_response: BeaconBlockResponse<E, Payload>,
block_response: BeaconBlockResponseWrapper<T::EthSpec>,
endpoint_version: EndpointVersion,
accept_header: Option<api_types::Accept>,
) -> Result<Response<Body>, warp::Rejection> {
let fork_name = block_response
.block
.to_ref()
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;
let execution_payload_value = block_response.execution_payload_value();
let consensus_block_value = block_response.consensus_block_value();
let execution_payload_blinded = block_response.is_blinded();
let block_contents = build_block_contents::build_block_contents(
fork_name,
block_response.block,
block_response.maybe_side_car,
)?;
let execution_payload_blinded = Payload::block_type() == BlockType::Blinded;
let block_contents = build_block_contents::build_block_contents(fork_name, block_response)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()
@@ -107,9 +94,9 @@ pub fn build_response_v3<T: BeaconChainTypes, E: EthSpec, Payload: AbstractExecP
.map(|res: Response<Body>| add_consensus_version_header(res, fork_name))
.map(|res| add_execution_payload_blinded_header(res, execution_payload_blinded))
.map(|res: Response<Body>| {
add_execution_payload_value_header(res, block_response.execution_payload_value)
add_execution_payload_value_header(res, execution_payload_value)
})
.map(|res| add_consensus_block_value_header(res, block_response.consensus_block_value))
.map(|res| add_consensus_block_value_header(res, consensus_block_value))
.map_err(|e| -> warp::Rejection {
warp_utils::reject::custom_server_error(format!("failed to create response: {}", e))
}),
@@ -117,10 +104,8 @@ pub fn build_response_v3<T: BeaconChainTypes, E: EthSpec, Payload: AbstractExecP
.map(|response| warp::reply::json(&response).into_response())
.map(|res| add_consensus_version_header(res, fork_name))
.map(|res| add_execution_payload_blinded_header(res, execution_payload_blinded))
.map(|res| {
add_execution_payload_value_header(res, block_response.execution_payload_value)
})
.map(|res| add_consensus_block_value_header(res, block_response.consensus_block_value)),
.map(|res| add_execution_payload_value_header(res, execution_payload_value))
.map(|res| add_consensus_block_value_header(res, consensus_block_value)),
}
}
@@ -150,14 +135,7 @@ pub async fn produce_blinded_block_v2<T: BeaconChainTypes>(
.await
.map_err(warp_utils::reject::block_production_error)?;
match block_response_type {
BeaconBlockResponseType::Full(block_response) => {
build_response_v2(chain, block_response, endpoint_version, accept_header)
}
BeaconBlockResponseType::Blinded(block_response) => {
build_response_v2(chain, block_response, endpoint_version, accept_header)
}
}
build_response_v2(chain, block_response_type, endpoint_version, accept_header)
}
pub async fn produce_block_v2<T: BeaconChainTypes>(
@@ -187,33 +165,20 @@ pub async fn produce_block_v2<T: BeaconChainTypes>(
.await
.map_err(warp_utils::reject::block_production_error)?;
match block_response_type {
BeaconBlockResponseType::Full(block_response) => {
build_response_v2(chain, block_response, endpoint_version, accept_header)
}
BeaconBlockResponseType::Blinded(block_response) => {
build_response_v2(chain, block_response, endpoint_version, accept_header)
}
}
build_response_v2(chain, block_response_type, endpoint_version, accept_header)
}
pub fn build_response_v2<T: BeaconChainTypes, E: EthSpec, Payload: AbstractExecPayload<E>>(
pub fn build_response_v2<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
block_response: BeaconBlockResponse<E, Payload>,
block_response: BeaconBlockResponseWrapper<T::EthSpec>,
endpoint_version: EndpointVersion,
accept_header: Option<api_types::Accept>,
) -> Result<Response<Body>, warp::Rejection> {
let fork_name = block_response
.block
.to_ref()
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;
let block_contents = build_block_contents::build_block_contents(
fork_name,
block_response.block,
block_response.maybe_side_car,
)?;
let block_contents = build_block_contents::build_block_contents(fork_name, block_response)?;
match accept_header {
Some(api_types::Accept::Ssz) => Response::builder()