mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Fix PublishBlockRequest SSZ decoding (#5078)
* Fix PublishBlockRequest SSZ decoding * Send header for block v1 ssz client * Delete unused function
This commit is contained in:
@@ -45,7 +45,7 @@ use eth2::types::{
|
||||
PublishBlockRequest, ValidatorBalancesRequestBody, ValidatorId, ValidatorStatus,
|
||||
ValidatorsRequestBody,
|
||||
};
|
||||
use eth2::{CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
|
||||
use eth2::{CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
|
||||
use lighthouse_network::{types::SyncState, EnrExt, NetworkGlobals, PeerId, PubsubMessage};
|
||||
use lighthouse_version::version_with_platform;
|
||||
use logging::SSELoggingComponents;
|
||||
@@ -1249,6 +1249,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
/*
|
||||
* beacon/blocks
|
||||
*/
|
||||
let consensus_version_header_filter =
|
||||
warp::header::header::<ForkName>(CONSENSUS_VERSION_HEADER);
|
||||
|
||||
// POST beacon/blocks
|
||||
let post_beacon_blocks = eth_v1
|
||||
@@ -1286,12 +1288,14 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.and(warp::path("blocks"))
|
||||
.and(warp::path::end())
|
||||
.and(warp::body::bytes())
|
||||
.and(consensus_version_header_filter)
|
||||
.and(task_spawner_filter.clone())
|
||||
.and(chain_filter.clone())
|
||||
.and(network_tx_filter.clone())
|
||||
.and(log_filter.clone())
|
||||
.then(
|
||||
move |block_bytes: Bytes,
|
||||
consensus_version: ForkName,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
@@ -1299,7 +1303,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
|
||||
let block_contents = PublishBlockRequest::<T::EthSpec>::from_ssz_bytes(
|
||||
&block_bytes,
|
||||
&chain.spec,
|
||||
consensus_version,
|
||||
)
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!("invalid SSZ: {e:?}"))
|
||||
@@ -1356,6 +1360,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.and(warp::query::<api_types::BroadcastValidationQuery>())
|
||||
.and(warp::path::end())
|
||||
.and(warp::body::bytes())
|
||||
.and(consensus_version_header_filter)
|
||||
.and(task_spawner_filter.clone())
|
||||
.and(chain_filter.clone())
|
||||
.and(network_tx_filter.clone())
|
||||
@@ -1363,6 +1368,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.then(
|
||||
move |validation_level: api_types::BroadcastValidationQuery,
|
||||
block_bytes: Bytes,
|
||||
consensus_version: ForkName,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
@@ -1370,7 +1376,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
|
||||
let block_contents = PublishBlockRequest::<T::EthSpec>::from_ssz_bytes(
|
||||
&block_bytes,
|
||||
&chain.spec,
|
||||
consensus_version,
|
||||
)
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!("invalid SSZ: {e:?}"))
|
||||
|
||||
@@ -2,17 +2,16 @@ use beacon_chain::{
|
||||
test_utils::{AttestationStrategy, BlockStrategy},
|
||||
GossipVerifiedBlock, IntoGossipVerifiedBlockContents,
|
||||
};
|
||||
use eth2::reqwest::StatusCode;
|
||||
use eth2::types::{BroadcastValidation, PublishBlockRequest, SignedBeaconBlock};
|
||||
use http_api::test_utils::InteractiveTester;
|
||||
use http_api::{publish_blinded_block, publish_block, reconstruct_block, ProvenancedBlock};
|
||||
use std::sync::Arc;
|
||||
use tree_hash::TreeHash;
|
||||
use types::{Hash256, MainnetEthSpec, Slot};
|
||||
use types::{Epoch, EthSpec, ForkName, Hash256, MainnetEthSpec, Slot};
|
||||
use warp::Rejection;
|
||||
use warp_utils::reject::CustomBadRequest;
|
||||
|
||||
use eth2::reqwest::StatusCode;
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
|
||||
/*
|
||||
@@ -190,7 +189,10 @@ pub async fn gossip_full_pass_ssz() {
|
||||
// `validator_count // 32`.
|
||||
let validator_count = 64;
|
||||
let num_initial: u64 = 31;
|
||||
let tester = InteractiveTester::<E>::new(None, validator_count).await;
|
||||
// Deneb epoch set ahead of block slot, to test fork-based decoding
|
||||
let mut spec = ForkName::Capella.make_genesis_spec(MainnetEthSpec::default_spec());
|
||||
spec.deneb_fork_epoch = Some(Epoch::new(4));
|
||||
let tester = InteractiveTester::<E>::new(Some(spec), validator_count).await;
|
||||
|
||||
// Create some chain depth.
|
||||
tester.harness.advance_slot();
|
||||
|
||||
Reference in New Issue
Block a user