mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-15 09:48:20 +00:00
resolve merge conflict and migrate il service to new pardigmn
This commit is contained in:
@@ -36,7 +36,7 @@ mod validators;
|
||||
mod version;
|
||||
use crate::light_client::{get_light_client_bootstrap, get_light_client_updates};
|
||||
use crate::produce_block::{produce_blinded_block_v2, produce_block_v2, produce_block_v3};
|
||||
use crate::version::fork_versioned_response;
|
||||
use crate::version::beacon_response;
|
||||
use beacon_chain::{
|
||||
attestation_verification::VerifiedAttestation, observed_operations::ObservationOutcome,
|
||||
validator_monitor::timestamp_now, AttestationError as AttnError, BeaconChain, BeaconChainError,
|
||||
@@ -49,9 +49,9 @@ use bytes::Bytes;
|
||||
use directory::DEFAULT_ROOT_DIR;
|
||||
use either::Either;
|
||||
use eth2::types::{
|
||||
self as api_types, BroadcastValidation, EndpointVersion, ForkChoice, ForkChoiceNode,
|
||||
LightClientUpdatesQuery, PublishBlockRequest, ValidatorBalancesRequestBody, ValidatorId,
|
||||
ValidatorStatus, ValidatorsRequestBody,
|
||||
self as api_types, BroadcastValidation, ContextDeserialize, EndpointVersion, ForkChoice,
|
||||
ForkChoiceNode, LightClientUpdatesQuery, PublishBlockRequest, ValidatorBalancesRequestBody,
|
||||
ValidatorId, ValidatorStatus, ValidatorsRequestBody,
|
||||
};
|
||||
use eth2::{CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
|
||||
use health_metrics::observe::Observe;
|
||||
@@ -70,6 +70,7 @@ use serde_json::Value;
|
||||
use slot_clock::SlotClock;
|
||||
use ssz::Encode;
|
||||
pub use state_id::StateId;
|
||||
use std::collections::HashSet;
|
||||
use std::future::Future;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
@@ -88,10 +89,10 @@ use tokio_stream::{
|
||||
StreamExt,
|
||||
};
|
||||
use tracing::{debug, error, info, warn};
|
||||
use types::AttestationData;
|
||||
use types::{
|
||||
fork_versioned_response::EmptyMetadata, Attestation, AttestationData, AttestationShufflingId,
|
||||
AttesterSlashing, BeaconStateError, ChainSpec, Checkpoint, CommitteeCache, ConfigAndPreset,
|
||||
Epoch, EthSpec, ForkName, ForkVersionedResponse, Hash256, ProposerPreparationData,
|
||||
Attestation, AttestationShufflingId, AttesterSlashing, BeaconStateError, ChainSpec, Checkpoint,
|
||||
CommitteeCache, ConfigAndPreset, Epoch, EthSpec, ForkName, Hash256, ProposerPreparationData,
|
||||
ProposerSlashing, RelativeEpoch, SignedAggregateAndProof, SignedBlindedBeaconBlock,
|
||||
SignedBlsToExecutionChange, SignedContributionAndProof, SignedInclusionList,
|
||||
SignedValidatorRegistrationData, SignedVoluntaryExit, Slot, SyncCommitteeMessage,
|
||||
@@ -100,8 +101,8 @@ use types::{
|
||||
use validator::pubkey_to_validator_index;
|
||||
use version::{
|
||||
add_consensus_version_header, add_ssz_content_type_header,
|
||||
execution_optimistic_finalized_fork_versioned_response, inconsistent_fork_rejection,
|
||||
unsupported_version_rejection, V1, V2, V3,
|
||||
execution_optimistic_finalized_beacon_response, inconsistent_fork_rejection,
|
||||
unsupported_version_rejection, ResponseIncludesVersion, V1, V2, V3,
|
||||
};
|
||||
use warp::http::StatusCode;
|
||||
use warp::hyper::Body;
|
||||
@@ -216,37 +217,67 @@ pub fn prometheus_metrics() -> warp::filters::log::Log<impl Fn(warp::filters::lo
|
||||
|
||||
// First line covers `POST /v1/beacon/blocks` only
|
||||
equals("v1/beacon/blocks")
|
||||
.or_else(|| starts_with("v1/validator/blocks"))
|
||||
.or_else(|| starts_with("v2/validator/blocks"))
|
||||
.or_else(|| starts_with("v1/validator/blinded_blocks"))
|
||||
.or_else(|| starts_with("v1/validator/duties/attester"))
|
||||
.or_else(|| starts_with("v1/validator/duties/proposer"))
|
||||
.or_else(|| starts_with("v1/validator/duties/sync"))
|
||||
.or_else(|| starts_with("v1/validator/duties/inclusion_list"))
|
||||
.or_else(|| starts_with("v1/validator/attestation_data"))
|
||||
.or_else(|| starts_with("v1/validator/aggregate_attestation"))
|
||||
.or_else(|| starts_with("v2/validator/aggregate_attestation"))
|
||||
.or_else(|| starts_with("v1/validator/aggregate_and_proofs"))
|
||||
.or_else(|| starts_with("v2/validator/aggregate_and_proofs"))
|
||||
.or_else(|| starts_with("v1/validator/sync_committee_contribution"))
|
||||
.or_else(|| starts_with("v1/validator/inclusion_list"))
|
||||
.or_else(|| starts_with("v1/validator/contribution_and_proofs"))
|
||||
.or_else(|| starts_with("v1/validator/beacon_committee_subscriptions"))
|
||||
.or_else(|| starts_with("v1/validator/sync_committee_subscriptions"))
|
||||
.or_else(|| starts_with("v1/beacon/blob_sidecars"))
|
||||
.or_else(|| starts_with("v1/beacon/blocks/head/root"))
|
||||
.or_else(|| starts_with("v1/beacon/blinded_blocks"))
|
||||
.or_else(|| starts_with("v1/beacon/deposit_snapshot"))
|
||||
.or_else(|| starts_with("v1/beacon/headers"))
|
||||
.or_else(|| starts_with("v1/beacon/light_client"))
|
||||
.or_else(|| starts_with("v1/beacon/pool/attestations"))
|
||||
.or_else(|| starts_with("v2/beacon/pool/attestations"))
|
||||
.or_else(|| starts_with("v1/beacon/pool/attester_slashings"))
|
||||
.or_else(|| starts_with("v1/beacon/pool/bls_to_execution_changes"))
|
||||
.or_else(|| starts_with("v1/beacon/pool/proposer_slashings"))
|
||||
.or_else(|| starts_with("v1/beacon/pool/sync_committees"))
|
||||
.or_else(|| starts_with("v1/beacon/blocks/head/root"))
|
||||
.or_else(|| starts_with("v1/validator/prepare_beacon_proposer"))
|
||||
.or_else(|| starts_with("v1/validator/register_validator"))
|
||||
.or_else(|| starts_with("v1/beacon/pool/voluntary_exits"))
|
||||
.or_else(|| starts_with("v1/beacon/rewards/blocks"))
|
||||
.or_else(|| starts_with("v1/beacon/rewards/attestations"))
|
||||
.or_else(|| starts_with("v1/beacon/rewards/sync_committee"))
|
||||
.or_else(|| starts_with("v1/beacon/rewards"))
|
||||
.or_else(|| starts_with("v1/beacon/states"))
|
||||
.or_else(|| starts_with("v1/beacon/"))
|
||||
.or_else(|| starts_with("v2/beacon/"))
|
||||
.or_else(|| starts_with("v1/builder/states"))
|
||||
.or_else(|| starts_with("v1/config/deposit_contract"))
|
||||
.or_else(|| starts_with("v1/config/fork_schedule"))
|
||||
.or_else(|| starts_with("v1/config/spec"))
|
||||
.or_else(|| starts_with("v1/config/"))
|
||||
.or_else(|| starts_with("v1/debug/"))
|
||||
.or_else(|| starts_with("v2/debug/"))
|
||||
.or_else(|| starts_with("v1/events"))
|
||||
.or_else(|| starts_with("v1/events/"))
|
||||
.or_else(|| starts_with("v1/node/"))
|
||||
.or_else(|| starts_with("v1/node/health"))
|
||||
.or_else(|| starts_with("v1/node/identity"))
|
||||
.or_else(|| starts_with("v1/node/peers"))
|
||||
.or_else(|| starts_with("v1/node/peer_count"))
|
||||
.or_else(|| starts_with("v1/node/syncing"))
|
||||
.or_else(|| starts_with("v1/node/version"))
|
||||
.or_else(|| starts_with("v1/node"))
|
||||
.or_else(|| starts_with("v1/validator/aggregate_and_proofs"))
|
||||
.or_else(|| starts_with("v2/validator/aggregate_and_proofs"))
|
||||
.or_else(|| starts_with("v1/validator/aggregate_attestation"))
|
||||
.or_else(|| starts_with("v2/validator/aggregate_attestation"))
|
||||
.or_else(|| starts_with("v1/validator/attestation_data"))
|
||||
.or_else(|| starts_with("v1/validator/beacon_committee_subscriptions"))
|
||||
.or_else(|| starts_with("v1/validator/blinded_blocks"))
|
||||
.or_else(|| starts_with("v2/validator/blinded_blocks"))
|
||||
.or_else(|| starts_with("v1/validator/blocks"))
|
||||
.or_else(|| starts_with("v2/validator/blocks"))
|
||||
.or_else(|| starts_with("v3/validator/blocks"))
|
||||
.or_else(|| starts_with("v1/validator/contribution_and_proofs"))
|
||||
.or_else(|| starts_with("v1/validator/duties/attester"))
|
||||
.or_else(|| starts_with("v1/validator/duties/proposer"))
|
||||
.or_else(|| starts_with("v1/validator/duties/sync"))
|
||||
.or_else(|| starts_with("v1/validator/inclusion_list"))
|
||||
.or_else(|| starts_with("v1/validator/liveness"))
|
||||
.or_else(|| starts_with("v1/validator/prepare_beacon_proposer"))
|
||||
.or_else(|| starts_with("v1/validator/register_validator"))
|
||||
.or_else(|| starts_with("v1/validator/sync_committee_contribution"))
|
||||
.or_else(|| starts_with("v1/validator/sync_committee_subscriptions"))
|
||||
.or_else(|| starts_with("v1/validator/"))
|
||||
.or_else(|| starts_with("v2/validator/"))
|
||||
.or_else(|| starts_with("v3/validator/"))
|
||||
.or_else(|| starts_with("lighthouse"))
|
||||
.unwrap_or("other")
|
||||
};
|
||||
|
||||
@@ -259,6 +290,38 @@ pub fn prometheus_metrics() -> warp::filters::log::Log<impl Fn(warp::filters::lo
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates a `warp` logging wrapper which we use to create `tracing` logs.
|
||||
pub fn tracing_logging() -> warp::filters::log::Log<impl Fn(warp::filters::log::Info) + Clone> {
|
||||
warp::log::custom(move |info| {
|
||||
let status = info.status();
|
||||
// Ensure elapsed time is in milliseconds.
|
||||
let elapsed = info.elapsed().as_secs_f64() * 1000.0;
|
||||
let path = info.path();
|
||||
let method = info.method().to_string();
|
||||
|
||||
if status == StatusCode::OK
|
||||
|| status == StatusCode::NOT_FOUND
|
||||
|| status == StatusCode::PARTIAL_CONTENT
|
||||
{
|
||||
debug!(
|
||||
elapsed_ms = %elapsed,
|
||||
status = %status,
|
||||
path = %path,
|
||||
method = %method,
|
||||
"Processed HTTP API request"
|
||||
);
|
||||
} else {
|
||||
warn!(
|
||||
elapsed_ms = %elapsed,
|
||||
status = %status,
|
||||
path = %path,
|
||||
method = %method,
|
||||
"Error processing HTTP API request"
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates a server that will serve requests using information from `ctx`.
|
||||
///
|
||||
/// The server will shut down gracefully when the `shutdown` future resolves.
|
||||
@@ -650,7 +713,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.clone()
|
||||
.and(warp::path("validator_balances"))
|
||||
.and(warp::path::end())
|
||||
.and(warp_utils::json::json())
|
||||
.and(warp_utils::json::json_no_body())
|
||||
.then(
|
||||
|state_id: StateId,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
@@ -1093,8 +1156,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
|state_id: StateId,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>| {
|
||||
task_spawner.blocking_json_task(Priority::P1, move || {
|
||||
let (data, execution_optimistic, finalized) = state_id
|
||||
task_spawner.blocking_response_task(Priority::P1, move || {
|
||||
let (data, execution_optimistic, finalized, fork_name) = state_id
|
||||
.map_state_and_execution_optimistic_and_finalized(
|
||||
&chain,
|
||||
|state, execution_optimistic, finalized| {
|
||||
@@ -1104,15 +1167,23 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
));
|
||||
};
|
||||
|
||||
Ok((deposits.clone(), execution_optimistic, finalized))
|
||||
Ok((
|
||||
deposits.clone(),
|
||||
execution_optimistic,
|
||||
finalized,
|
||||
state.fork_name_unchecked(),
|
||||
))
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(api_types::ExecutionOptimisticFinalizedResponse {
|
||||
execution_optimistic_finalized_beacon_response(
|
||||
ResponseIncludesVersion::Yes(fork_name),
|
||||
execution_optimistic,
|
||||
finalized,
|
||||
data,
|
||||
execution_optimistic: Some(execution_optimistic),
|
||||
finalized: Some(finalized),
|
||||
})
|
||||
)
|
||||
.map(|res| warp::reply::json(&res).into_response())
|
||||
.map(|resp| add_consensus_version_header(resp, fork_name))
|
||||
})
|
||||
},
|
||||
);
|
||||
@@ -1126,8 +1197,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
|state_id: StateId,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>| {
|
||||
task_spawner.blocking_json_task(Priority::P1, move || {
|
||||
let (data, execution_optimistic, finalized) = state_id
|
||||
task_spawner.blocking_response_task(Priority::P1, move || {
|
||||
let (data, execution_optimistic, finalized, fork_name) = state_id
|
||||
.map_state_and_execution_optimistic_and_finalized(
|
||||
&chain,
|
||||
|state, execution_optimistic, finalized| {
|
||||
@@ -1137,7 +1208,48 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
));
|
||||
};
|
||||
|
||||
Ok((withdrawals.clone(), execution_optimistic, finalized))
|
||||
Ok((
|
||||
withdrawals.clone(),
|
||||
execution_optimistic,
|
||||
finalized,
|
||||
state.fork_name_unchecked(),
|
||||
))
|
||||
},
|
||||
)?;
|
||||
|
||||
execution_optimistic_finalized_beacon_response(
|
||||
ResponseIncludesVersion::Yes(fork_name),
|
||||
execution_optimistic,
|
||||
finalized,
|
||||
data,
|
||||
)
|
||||
.map(|res| warp::reply::json(&res).into_response())
|
||||
.map(|resp| add_consensus_version_header(resp, fork_name))
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
// GET beacon/states/{state_id}/pending_consolidations
|
||||
let get_beacon_state_pending_consolidations = beacon_states_path
|
||||
.clone()
|
||||
.and(warp::path("pending_consolidations"))
|
||||
.and(warp::path::end())
|
||||
.then(
|
||||
|state_id: StateId,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>| {
|
||||
task_spawner.blocking_json_task(Priority::P1, move || {
|
||||
let (data, execution_optimistic, finalized) = state_id
|
||||
.map_state_and_execution_optimistic_and_finalized(
|
||||
&chain,
|
||||
|state, execution_optimistic, finalized| {
|
||||
let Ok(consolidations) = state.pending_consolidations() else {
|
||||
return Err(warp_utils::reject::custom_bad_request(
|
||||
"Pending consolidations not found".to_string(),
|
||||
));
|
||||
};
|
||||
|
||||
Ok((consolidations.clone(), execution_optimistic, finalized))
|
||||
},
|
||||
)?;
|
||||
|
||||
@@ -1312,21 +1424,30 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.and(warp::path("beacon"))
|
||||
.and(warp::path("blocks"))
|
||||
.and(warp::path::end())
|
||||
.and(warp_utils::json::json())
|
||||
.and(warp::body::json())
|
||||
.and(consensus_version_header_filter)
|
||||
.and(task_spawner_filter.clone())
|
||||
.and(chain_filter.clone())
|
||||
.and(network_tx_filter.clone())
|
||||
.and(network_globals.clone())
|
||||
.then(
|
||||
move |block_contents: PublishBlockRequest<T::EthSpec>,
|
||||
move |value: serde_json::Value,
|
||||
consensus_version: ForkName,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>| {
|
||||
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
|
||||
let request = PublishBlockRequest::<T::EthSpec>::context_deserialize(
|
||||
&value,
|
||||
consensus_version,
|
||||
)
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!("invalid JSON: {e:?}"))
|
||||
})?;
|
||||
publish_blocks::publish_block(
|
||||
None,
|
||||
ProvenancedBlock::local_from_publish_request(block_contents),
|
||||
ProvenancedBlock::local_from_publish_request(request),
|
||||
chain,
|
||||
&network_tx,
|
||||
BroadcastValidation::default(),
|
||||
@@ -1382,22 +1503,32 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.and(warp::path("blocks"))
|
||||
.and(warp::query::<api_types::BroadcastValidationQuery>())
|
||||
.and(warp::path::end())
|
||||
.and(warp_utils::json::json())
|
||||
.and(warp::body::json())
|
||||
.and(consensus_version_header_filter)
|
||||
.and(task_spawner_filter.clone())
|
||||
.and(chain_filter.clone())
|
||||
.and(network_tx_filter.clone())
|
||||
.and(network_globals.clone())
|
||||
.then(
|
||||
move |validation_level: api_types::BroadcastValidationQuery,
|
||||
block_contents: PublishBlockRequest<T::EthSpec>,
|
||||
value: serde_json::Value,
|
||||
consensus_version: ForkName,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>| {
|
||||
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
|
||||
let request = PublishBlockRequest::<T::EthSpec>::context_deserialize(
|
||||
&value,
|
||||
consensus_version,
|
||||
)
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!("invalid JSON: {e:?}"))
|
||||
})?;
|
||||
|
||||
publish_blocks::publish_block(
|
||||
None,
|
||||
ProvenancedBlock::local_from_publish_request(block_contents),
|
||||
ProvenancedBlock::local_from_publish_request(request),
|
||||
chain,
|
||||
&network_tx,
|
||||
validation_level.broadcast_validation,
|
||||
@@ -1630,6 +1761,12 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.fork_name(&chain.spec)
|
||||
.map_err(inconsistent_fork_rejection)?;
|
||||
|
||||
let require_version = match endpoint_version {
|
||||
V1 => ResponseIncludesVersion::No,
|
||||
V2 => ResponseIncludesVersion::Yes(fork_name),
|
||||
_ => return Err(unsupported_version_rejection(endpoint_version)),
|
||||
};
|
||||
|
||||
match accept_header {
|
||||
Some(api_types::Accept::Ssz) => Response::builder()
|
||||
.status(200)
|
||||
@@ -1641,9 +1778,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
e
|
||||
))
|
||||
}),
|
||||
_ => execution_optimistic_finalized_fork_versioned_response(
|
||||
endpoint_version,
|
||||
fork_name,
|
||||
_ => execution_optimistic_finalized_beacon_response(
|
||||
require_version,
|
||||
execution_optimistic,
|
||||
finalized,
|
||||
block,
|
||||
@@ -1703,9 +1839,15 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.attestations()
|
||||
.map(|att| att.clone_as_attestation())
|
||||
.collect::<Vec<_>>();
|
||||
let res = execution_optimistic_finalized_fork_versioned_response(
|
||||
endpoint_version,
|
||||
fork_name,
|
||||
|
||||
let require_version = match endpoint_version {
|
||||
V1 => ResponseIncludesVersion::No,
|
||||
V2 => ResponseIncludesVersion::Yes(fork_name),
|
||||
_ => return Err(unsupported_version_rejection(endpoint_version)),
|
||||
};
|
||||
|
||||
let res = execution_optimistic_finalized_beacon_response(
|
||||
require_version,
|
||||
execution_optimistic,
|
||||
finalized,
|
||||
&atts,
|
||||
@@ -1752,9 +1894,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
}),
|
||||
_ => {
|
||||
// Post as a V2 endpoint so we return the fork version.
|
||||
execution_optimistic_finalized_fork_versioned_response(
|
||||
V2,
|
||||
fork_name,
|
||||
execution_optimistic_finalized_beacon_response(
|
||||
ResponseIncludesVersion::Yes(fork_name),
|
||||
execution_optimistic,
|
||||
finalized,
|
||||
block,
|
||||
@@ -1808,9 +1949,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
}),
|
||||
_ => {
|
||||
// Post as a V2 endpoint so we return the fork version.
|
||||
let res = execution_optimistic_finalized_fork_versioned_response(
|
||||
V2,
|
||||
fork_name,
|
||||
let res = execution_optimistic_finalized_beacon_response(
|
||||
ResponseIncludesVersion::Yes(fork_name),
|
||||
execution_optimistic,
|
||||
finalized,
|
||||
&blob_sidecar_list_filtered,
|
||||
@@ -1932,11 +2072,11 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
query: api_types::AttestationPoolQuery| {
|
||||
task_spawner.blocking_response_task(Priority::P1, move || {
|
||||
let query_filter = |data: &AttestationData| {
|
||||
let query_filter = |data: &AttestationData, committee_indices: HashSet<u64>| {
|
||||
query.slot.is_none_or(|slot| slot == data.slot)
|
||||
&& query
|
||||
.committee_index
|
||||
.is_none_or(|index| index == data.index)
|
||||
.is_none_or(|index| committee_indices.contains(&index))
|
||||
};
|
||||
|
||||
let mut attestations = chain.op_pool.get_filtered_attestations(query_filter);
|
||||
@@ -1945,7 +2085,9 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.naive_aggregation_pool
|
||||
.read()
|
||||
.iter()
|
||||
.filter(|&att| query_filter(att.data()))
|
||||
.filter(|&att| {
|
||||
query_filter(att.data(), att.get_committee_indices_map())
|
||||
})
|
||||
.cloned(),
|
||||
);
|
||||
// Use the current slot to find the fork version, and convert all messages to the
|
||||
@@ -1968,7 +2110,13 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let res = fork_versioned_response(endpoint_version, fork_name, &attestations)?;
|
||||
let require_version = match endpoint_version {
|
||||
V1 => ResponseIncludesVersion::No,
|
||||
V2 => ResponseIncludesVersion::Yes(fork_name),
|
||||
_ => return Err(unsupported_version_rejection(endpoint_version)),
|
||||
};
|
||||
|
||||
let res = beacon_response(require_version, &attestations);
|
||||
Ok(add_consensus_version_header(
|
||||
warp::reply::json(&res).into_response(),
|
||||
fork_name,
|
||||
@@ -2057,7 +2205,13 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let res = fork_versioned_response(endpoint_version, fork_name, &slashings)?;
|
||||
let require_version = match endpoint_version {
|
||||
V1 => ResponseIncludesVersion::No,
|
||||
V2 => ResponseIncludesVersion::Yes(fork_name),
|
||||
_ => return Err(unsupported_version_rejection(endpoint_version)),
|
||||
};
|
||||
|
||||
let res = beacon_response(require_version, &slashings);
|
||||
Ok(add_consensus_version_header(
|
||||
warp::reply::json(&res).into_response(),
|
||||
fork_name,
|
||||
@@ -2521,7 +2675,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
|
||||
let fork_name = chain
|
||||
.spec
|
||||
.fork_name_at_slot::<T::EthSpec>(*update.signature_slot());
|
||||
.fork_name_at_slot::<T::EthSpec>(update.get_slot());
|
||||
match accept_header {
|
||||
Some(api_types::Accept::Ssz) => Response::builder()
|
||||
.status(200)
|
||||
@@ -2533,11 +2687,10 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
e
|
||||
))
|
||||
}),
|
||||
_ => Ok(warp::reply::json(&ForkVersionedResponse {
|
||||
version: Some(fork_name),
|
||||
metadata: EmptyMetadata {},
|
||||
data: update,
|
||||
})
|
||||
_ => Ok(warp::reply::json(&beacon_response(
|
||||
ResponseIncludesVersion::Yes(fork_name),
|
||||
update,
|
||||
))
|
||||
.into_response()),
|
||||
}
|
||||
.map(|resp| add_consensus_version_header(resp, fork_name))
|
||||
@@ -2582,11 +2735,10 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
e
|
||||
))
|
||||
}),
|
||||
_ => Ok(warp::reply::json(&ForkVersionedResponse {
|
||||
version: Some(fork_name),
|
||||
metadata: EmptyMetadata {},
|
||||
data: update,
|
||||
})
|
||||
_ => Ok(warp::reply::json(&beacon_response(
|
||||
ResponseIncludesVersion::Yes(fork_name),
|
||||
update,
|
||||
))
|
||||
.into_response()),
|
||||
}
|
||||
.map(|resp| add_consensus_version_header(resp, fork_name))
|
||||
@@ -2778,7 +2930,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.and(task_spawner_filter.clone())
|
||||
.and(chain_filter.clone())
|
||||
.then(
|
||||
|endpoint_version: EndpointVersion,
|
||||
|_endpoint_version: EndpointVersion,
|
||||
state_id: StateId,
|
||||
accept_header: Option<api_types::Accept>,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
@@ -2822,9 +2974,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
let fork_name = state
|
||||
.fork_name(&chain.spec)
|
||||
.map_err(inconsistent_fork_rejection)?;
|
||||
let res = execution_optimistic_finalized_fork_versioned_response(
|
||||
endpoint_version,
|
||||
fork_name,
|
||||
let res = execution_optimistic_finalized_beacon_response(
|
||||
ResponseIncludesVersion::Yes(fork_name),
|
||||
execution_optimistic,
|
||||
finalized,
|
||||
&state,
|
||||
@@ -3174,13 +3325,14 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
let direction = dir.into();
|
||||
let state = peer_info.connection_status().clone().into();
|
||||
|
||||
let state_matches = query.state.as_ref().is_none_or(|states| {
|
||||
states.iter().any(|state_param| *state_param == state)
|
||||
});
|
||||
let direction_matches =
|
||||
query.direction.as_ref().is_none_or(|directions| {
|
||||
directions.iter().any(|dir_param| *dir_param == direction)
|
||||
});
|
||||
let state_matches = query
|
||||
.state
|
||||
.as_ref()
|
||||
.is_none_or(|states| states.contains(&state));
|
||||
let direction_matches = query
|
||||
.direction
|
||||
.as_ref()
|
||||
.is_none_or(|directions| directions.contains(&direction));
|
||||
|
||||
if state_matches && direction_matches {
|
||||
peers.push(api_types::PeerData {
|
||||
@@ -3304,7 +3456,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
if endpoint_version == V3 {
|
||||
produce_block_v3(accept_header, chain, slot, query).await
|
||||
} else {
|
||||
produce_block_v2(endpoint_version, accept_header, chain, slot, query).await
|
||||
produce_block_v2(accept_header, chain, slot, query).await
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -3334,8 +3486,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
chain: Arc<BeaconChain<T>>| {
|
||||
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
|
||||
not_synced_filter?;
|
||||
produce_blinded_block_v2(EndpointVersion(2), accept_header, chain, slot, query)
|
||||
.await
|
||||
produce_blinded_block_v2(accept_header, chain, slot, query).await
|
||||
})
|
||||
},
|
||||
);
|
||||
@@ -4848,6 +4999,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.uor(get_beacon_state_randao)
|
||||
.uor(get_beacon_state_pending_deposits)
|
||||
.uor(get_beacon_state_pending_partial_withdrawals)
|
||||
.uor(get_beacon_state_pending_consolidations)
|
||||
.uor(get_beacon_headers)
|
||||
.uor(get_beacon_headers_block_id)
|
||||
.uor(get_beacon_block)
|
||||
@@ -4960,6 +5112,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
),
|
||||
)
|
||||
.recover(warp_utils::reject::handle_rejection)
|
||||
.with(tracing_logging())
|
||||
.with(prometheus_metrics())
|
||||
// Add a `Server` header.
|
||||
.map(|reply| warp::reply::with_header(reply, "Server", &version_with_platform()))
|
||||
|
||||
Reference in New Issue
Block a user