mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 21:04:41 +00:00
Merge remote-tracking branch 'origin/unstable' into tree-states
This commit is contained in:
@@ -14,6 +14,7 @@ mod build_block_contents;
|
||||
mod builder_states;
|
||||
mod database;
|
||||
mod metrics;
|
||||
mod produce_block;
|
||||
mod proposer_duties;
|
||||
mod publish_blocks;
|
||||
mod standard_block_rewards;
|
||||
@@ -27,10 +28,11 @@ mod validator;
|
||||
mod validator_inclusion;
|
||||
mod version;
|
||||
|
||||
use crate::produce_block::{produce_blinded_block_v2, produce_block_v2, produce_block_v3};
|
||||
use beacon_chain::{
|
||||
attestation_verification::VerifiedAttestation, observed_operations::ObservationOutcome,
|
||||
validator_monitor::timestamp_now, AttestationError as AttnError, BeaconChain, BeaconChainError,
|
||||
BeaconChainTypes, ProduceBlockVerification, WhenSlotSkipped,
|
||||
BeaconChainTypes, WhenSlotSkipped,
|
||||
};
|
||||
use beacon_processor::BeaconProcessorSend;
|
||||
pub use block_id::BlockId;
|
||||
@@ -39,8 +41,7 @@ use bytes::Bytes;
|
||||
use directory::DEFAULT_ROOT_DIR;
|
||||
use eth2::types::{
|
||||
self as api_types, BroadcastValidation, EndpointVersion, ForkChoice, ForkChoiceNode,
|
||||
SignedBlindedBlockContents, SignedBlockContents, SkipRandaoVerification, ValidatorId,
|
||||
ValidatorStatus,
|
||||
SignedBlindedBlockContents, SignedBlockContents, ValidatorId, ValidatorStatus,
|
||||
};
|
||||
use lighthouse_network::{types::SyncState, EnrExt, NetworkGlobals, PeerId, PubsubMessage};
|
||||
use lighthouse_version::version_with_platform;
|
||||
@@ -74,7 +75,7 @@ use tokio_stream::{
|
||||
};
|
||||
use types::{
|
||||
Attestation, AttestationData, AttestationShufflingId, AttesterSlashing, BeaconStateError,
|
||||
BlindedPayload, CommitteeCache, ConfigAndPreset, Epoch, EthSpec, ForkName, FullPayload,
|
||||
BlindedPayload, CommitteeCache, ConfigAndPreset, Epoch, EthSpec, ForkName,
|
||||
ProposerPreparationData, ProposerSlashing, RelativeEpoch, SignedAggregateAndProof,
|
||||
SignedBlsToExecutionChange, SignedContributionAndProof, SignedValidatorRegistrationData,
|
||||
SignedVoluntaryExit, Slot, SyncCommitteeMessage, SyncContributionData,
|
||||
@@ -82,7 +83,7 @@ use types::{
|
||||
use validator::pubkey_to_validator_index;
|
||||
use version::{
|
||||
add_consensus_version_header, execution_optimistic_finalized_fork_versioned_response,
|
||||
fork_versioned_response, inconsistent_fork_rejection, unsupported_version_rejection, V1, V2,
|
||||
inconsistent_fork_rejection, unsupported_version_rejection, V1, V2, V3,
|
||||
};
|
||||
use warp::http::StatusCode;
|
||||
use warp::sse::Event;
|
||||
@@ -3050,17 +3051,17 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
))
|
||||
}))
|
||||
.and(warp::path::end())
|
||||
.and(warp::header::optional::<api_types::Accept>("accept"))
|
||||
.and(not_while_syncing_filter.clone())
|
||||
.and(warp::query::<api_types::ValidatorBlocksQuery>())
|
||||
.and(warp::header::optional::<api_types::Accept>("accept"))
|
||||
.and(task_spawner_filter.clone())
|
||||
.and(chain_filter.clone())
|
||||
.and(log_filter.clone())
|
||||
.then(
|
||||
|endpoint_version: EndpointVersion,
|
||||
slot: Slot,
|
||||
query: api_types::ValidatorBlocksQuery,
|
||||
accept_header: Option<api_types::Accept>,
|
||||
query: api_types::ValidatorBlocksQuery,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
log: Logger| {
|
||||
@@ -3071,60 +3072,10 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
"slot" => slot
|
||||
);
|
||||
|
||||
let randao_reveal = query.randao_reveal.decompress().map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!(
|
||||
"randao reveal is not a valid BLS signature: {:?}",
|
||||
e
|
||||
))
|
||||
})?;
|
||||
|
||||
let randao_verification =
|
||||
if query.skip_randao_verification == SkipRandaoVerification::Yes {
|
||||
if !randao_reveal.is_infinity() {
|
||||
return Err(warp_utils::reject::custom_bad_request(
|
||||
"randao_reveal must be point-at-infinity if verification is skipped"
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
ProduceBlockVerification::NoVerification
|
||||
} else {
|
||||
ProduceBlockVerification::VerifyRandao
|
||||
};
|
||||
|
||||
let (block, _, maybe_blobs) = chain
|
||||
.produce_block_with_verification::<FullPayload<T::EthSpec>>(
|
||||
randao_reveal,
|
||||
slot,
|
||||
query.graffiti.map(Into::into),
|
||||
randao_verification,
|
||||
)
|
||||
.await
|
||||
.map_err(warp_utils::reject::block_production_error)?;
|
||||
let fork_name = block
|
||||
.to_ref()
|
||||
.fork_name(&chain.spec)
|
||||
.map_err(inconsistent_fork_rejection)?;
|
||||
|
||||
let block_contents =
|
||||
build_block_contents::build_block_contents(fork_name, block, maybe_blobs)?;
|
||||
|
||||
match accept_header {
|
||||
Some(api_types::Accept::Ssz) => Response::builder()
|
||||
.status(200)
|
||||
.header("Content-Type", "application/octet-stream")
|
||||
.body(block_contents.as_ssz_bytes().into())
|
||||
.map(|res: Response<Bytes>| {
|
||||
add_consensus_version_header(res, fork_name)
|
||||
})
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_server_error(format!(
|
||||
"failed to create response: {}",
|
||||
e
|
||||
))
|
||||
}),
|
||||
_ => fork_versioned_response(endpoint_version, fork_name, block_contents)
|
||||
.map(|response| warp::reply::json(&response).into_response())
|
||||
.map(|res| add_consensus_version_header(res, fork_name)),
|
||||
if endpoint_version == V3 {
|
||||
produce_block_v3(endpoint_version, accept_header, chain, slot, query).await
|
||||
} else {
|
||||
produce_block_v2(endpoint_version, accept_header, chain, slot, query).await
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -3152,65 +3103,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>| {
|
||||
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
|
||||
let randao_reveal = query.randao_reveal.decompress().map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!(
|
||||
"randao reveal is not a valid BLS signature: {:?}",
|
||||
e
|
||||
))
|
||||
})?;
|
||||
|
||||
let randao_verification =
|
||||
if query.skip_randao_verification == SkipRandaoVerification::Yes {
|
||||
if !randao_reveal.is_infinity() {
|
||||
return Err(warp_utils::reject::custom_bad_request(
|
||||
"randao_reveal must be point-at-infinity if verification is skipped"
|
||||
.into()
|
||||
));
|
||||
}
|
||||
ProduceBlockVerification::NoVerification
|
||||
} else {
|
||||
ProduceBlockVerification::VerifyRandao
|
||||
};
|
||||
|
||||
let (block, _, maybe_blobs) = chain
|
||||
.produce_block_with_verification::<BlindedPayload<T::EthSpec>>(
|
||||
randao_reveal,
|
||||
slot,
|
||||
query.graffiti.map(Into::into),
|
||||
randao_verification,
|
||||
)
|
||||
produce_blinded_block_v2(EndpointVersion(2), accept_header, chain, slot, query)
|
||||
.await
|
||||
.map_err(warp_utils::reject::block_production_error)?;
|
||||
let fork_name = block
|
||||
.to_ref()
|
||||
.fork_name(&chain.spec)
|
||||
.map_err(inconsistent_fork_rejection)?;
|
||||
|
||||
let block_contents = build_block_contents::build_blinded_block_contents(
|
||||
fork_name,
|
||||
block,
|
||||
maybe_blobs,
|
||||
)?;
|
||||
|
||||
match accept_header {
|
||||
Some(api_types::Accept::Ssz) => Response::builder()
|
||||
.status(200)
|
||||
.header("Content-Type", "application/octet-stream")
|
||||
.body(block_contents.as_ssz_bytes().into())
|
||||
.map(|res: Response<Bytes>| {
|
||||
add_consensus_version_header(res, fork_name)
|
||||
})
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_server_error(format!(
|
||||
"failed to create response: {}",
|
||||
e
|
||||
))
|
||||
}),
|
||||
// Pose as a V2 endpoint so we return the fork `version`.
|
||||
_ => fork_versioned_response(V2, fork_name, block_contents)
|
||||
.map(|response| warp::reply::json(&response).into_response())
|
||||
.map(|res| add_consensus_version_header(res, fork_name)),
|
||||
}
|
||||
})
|
||||
},
|
||||
);
|
||||
@@ -3738,7 +3632,6 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.as_ref()
|
||||
.ok_or(BeaconChainError::BuilderMissing)
|
||||
.map_err(warp_utils::reject::beacon_chain_error)?;
|
||||
|
||||
builder
|
||||
.post_builder_validators(&filtered_registration_data)
|
||||
.await
|
||||
@@ -4703,6 +4596,14 @@ fn publish_pubsub_message<T: EthSpec>(
|
||||
)
|
||||
}
|
||||
|
||||
/// Publish a message to the libp2p pubsub network.
|
||||
fn publish_pubsub_messages<T: EthSpec>(
|
||||
network_tx: &UnboundedSender<NetworkMessage<T>>,
|
||||
messages: Vec<PubsubMessage<T>>,
|
||||
) -> Result<(), warp::Rejection> {
|
||||
publish_network_message(network_tx, NetworkMessage::Publish { messages })
|
||||
}
|
||||
|
||||
/// Publish a message to the libp2p network.
|
||||
fn publish_network_message<T: EthSpec>(
|
||||
network_tx: &UnboundedSender<NetworkMessage<T>>,
|
||||
|
||||
Reference in New Issue
Block a user