mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-31 13:17:09 +00:00
resolve merge conflicts
This commit is contained in:
68
beacon_node/http_api/src/aggregate_attestation.rs
Normal file
68
beacon_node/http_api/src/aggregate_attestation.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
use crate::api_types::GenericResponse;
|
||||
use crate::unsupported_version_rejection;
|
||||
use crate::version::{add_consensus_version_header, V1, V2};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use eth2::types::{self, EndpointVersion, Hash256, Slot};
|
||||
use std::sync::Arc;
|
||||
use types::fork_versioned_response::EmptyMetadata;
|
||||
use types::{CommitteeIndex, ForkVersionedResponse};
|
||||
use warp::{
|
||||
hyper::{Body, Response},
|
||||
reply::Reply,
|
||||
};
|
||||
|
||||
pub fn get_aggregate_attestation<T: BeaconChainTypes>(
|
||||
slot: Slot,
|
||||
attestation_data_root: &Hash256,
|
||||
committee_index: Option<CommitteeIndex>,
|
||||
endpoint_version: EndpointVersion,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
) -> Result<Response<Body>, warp::reject::Rejection> {
|
||||
let fork_name = chain.spec.fork_name_at_slot::<T::EthSpec>(slot);
|
||||
let aggregate_attestation = if fork_name.electra_enabled() {
|
||||
let Some(committee_index) = committee_index else {
|
||||
return Err(warp_utils::reject::custom_bad_request(
|
||||
"missing committee index".to_string(),
|
||||
));
|
||||
};
|
||||
chain
|
||||
.get_aggregated_attestation_electra(slot, attestation_data_root, committee_index)
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!(
|
||||
"unable to fetch aggregate: {:?}",
|
||||
e
|
||||
))
|
||||
})?
|
||||
.ok_or_else(|| {
|
||||
warp_utils::reject::custom_not_found("no matching aggregate found".to_string())
|
||||
})?
|
||||
} else {
|
||||
chain
|
||||
.get_pre_electra_aggregated_attestation_by_slot_and_root(slot, attestation_data_root)
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!(
|
||||
"unable to fetch aggregate: {:?}",
|
||||
e
|
||||
))
|
||||
})?
|
||||
.ok_or_else(|| {
|
||||
warp_utils::reject::custom_not_found("no matching aggregate found".to_string())
|
||||
})?
|
||||
};
|
||||
|
||||
if endpoint_version == V2 {
|
||||
let fork_versioned_response = ForkVersionedResponse {
|
||||
version: Some(fork_name),
|
||||
metadata: EmptyMetadata {},
|
||||
data: aggregate_attestation,
|
||||
};
|
||||
Ok(add_consensus_version_header(
|
||||
warp::reply::json(&fork_versioned_response).into_response(),
|
||||
fork_name,
|
||||
))
|
||||
} else if endpoint_version == V1 {
|
||||
Ok(warp::reply::json(&GenericResponse::from(aggregate_attestation)).into_response())
|
||||
} else {
|
||||
return Err(unsupported_version_rejection(endpoint_version));
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
//! There are also some additional, non-standard endpoints behind the `/lighthouse/` path which are
|
||||
//! used for development.
|
||||
|
||||
mod aggregate_attestation;
|
||||
mod attestation_performance;
|
||||
mod attester_duties;
|
||||
mod block_id;
|
||||
@@ -172,7 +173,7 @@ impl Default for Config {
|
||||
sse_capacity_multiplier: 1,
|
||||
enable_beacon_processor: true,
|
||||
duplicate_block_status_code: StatusCode::ACCEPTED,
|
||||
enable_light_client_server: false,
|
||||
enable_light_client_server: true,
|
||||
target_peers: 100,
|
||||
}
|
||||
}
|
||||
@@ -3419,40 +3420,15 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
not_synced_filter: Result<(), Rejection>,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>| {
|
||||
task_spawner.blocking_json_task(Priority::P0, move || {
|
||||
task_spawner.blocking_response_task(Priority::P0, move || {
|
||||
not_synced_filter?;
|
||||
let res = if endpoint_version == V2 {
|
||||
let Some(committee_index) = query.committee_index else {
|
||||
return Err(warp_utils::reject::custom_bad_request(
|
||||
"missing committee index".to_string(),
|
||||
));
|
||||
};
|
||||
chain.get_aggregated_attestation_electra(
|
||||
query.slot,
|
||||
&query.attestation_data_root,
|
||||
committee_index,
|
||||
)
|
||||
} else if endpoint_version == V1 {
|
||||
// Do nothing
|
||||
chain.get_pre_electra_aggregated_attestation_by_slot_and_root(
|
||||
query.slot,
|
||||
&query.attestation_data_root,
|
||||
)
|
||||
} else {
|
||||
return Err(unsupported_version_rejection(endpoint_version));
|
||||
};
|
||||
res.map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!(
|
||||
"unable to fetch aggregate: {:?}",
|
||||
e
|
||||
))
|
||||
})?
|
||||
.map(api_types::GenericResponse::from)
|
||||
.ok_or_else(|| {
|
||||
warp_utils::reject::custom_not_found(
|
||||
"no matching aggregate found".to_string(),
|
||||
)
|
||||
})
|
||||
crate::aggregate_attestation::get_aggregate_attestation(
|
||||
query.slot,
|
||||
&query.attestation_data_root,
|
||||
query.committee_index,
|
||||
endpoint_version,
|
||||
chain,
|
||||
)
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
//! attestations and there's no immediate cause for concern.
|
||||
use crate::task_spawner::{Priority, TaskSpawner};
|
||||
use beacon_chain::{
|
||||
validator_monitor::timestamp_now, AttestationError, BeaconChain, BeaconChainError,
|
||||
BeaconChainTypes,
|
||||
single_attestation::single_attestation_to_attestation, validator_monitor::timestamp_now,
|
||||
AttestationError, BeaconChain, BeaconChainError, BeaconChainTypes,
|
||||
};
|
||||
use beacon_processor::work_reprocessing_queue::{QueuedUnaggregate, ReprocessQueueMessage};
|
||||
use either::Either;
|
||||
@@ -183,10 +183,10 @@ fn convert_to_attestation<'a, T: BeaconChainTypes>(
|
||||
chain: &Arc<BeaconChain<T>>,
|
||||
attestation: &'a Either<Attestation<T::EthSpec>, SingleAttestation>,
|
||||
) -> Result<Cow<'a, Attestation<T::EthSpec>>, Error> {
|
||||
let a = match attestation {
|
||||
Either::Left(a) => Cow::Borrowed(a),
|
||||
Either::Right(single_attestation) => chain
|
||||
.with_committee_cache(
|
||||
match attestation {
|
||||
Either::Left(a) => Ok(Cow::Borrowed(a)),
|
||||
Either::Right(single_attestation) => {
|
||||
let conversion_result = chain.with_committee_cache(
|
||||
single_attestation.data.target.root,
|
||||
single_attestation
|
||||
.data
|
||||
@@ -197,24 +197,33 @@ fn convert_to_attestation<'a, T: BeaconChainTypes>(
|
||||
single_attestation.data.slot,
|
||||
single_attestation.committee_index,
|
||||
) else {
|
||||
return Err(BeaconChainError::AttestationError(
|
||||
types::AttestationError::NoCommitteeForSlotAndIndex {
|
||||
slot: single_attestation.data.slot,
|
||||
index: single_attestation.committee_index,
|
||||
},
|
||||
));
|
||||
return Ok(Err(AttestationError::NoCommitteeForSlotAndIndex {
|
||||
slot: single_attestation.data.slot,
|
||||
index: single_attestation.committee_index,
|
||||
}));
|
||||
};
|
||||
|
||||
let attestation =
|
||||
single_attestation.to_attestation::<T::EthSpec>(committee.committee)?;
|
||||
|
||||
Ok(Cow::Owned(attestation))
|
||||
Ok(single_attestation_to_attestation::<T::EthSpec>(
|
||||
single_attestation,
|
||||
committee.committee,
|
||||
)
|
||||
.map(Cow::Owned))
|
||||
},
|
||||
)
|
||||
.map_err(Error::FailedConversion)?,
|
||||
};
|
||||
|
||||
Ok(a)
|
||||
);
|
||||
match conversion_result {
|
||||
Ok(Ok(attestation)) => Ok(attestation),
|
||||
Ok(Err(e)) => Err(Error::Validation(e)),
|
||||
// Map the error returned by `with_committee_cache` for unknown blocks into the
|
||||
// `UnknownHeadBlock` error that is gracefully handled.
|
||||
Err(BeaconChainError::MissingBeaconBlock(beacon_block_root)) => {
|
||||
Err(Error::Validation(AttestationError::UnknownHeadBlock {
|
||||
beacon_block_root,
|
||||
}))
|
||||
}
|
||||
Err(e) => Err(Error::FailedConversion(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn publish_attestations<T: BeaconChainTypes>(
|
||||
|
||||
Reference in New Issue
Block a user