debugging

This commit is contained in:
Eitan Seri-Levi
2025-02-15 12:14:58 +02:00
parent 7eb040c70e
commit cdbdb5226d
23 changed files with 252 additions and 157 deletions

View File

@@ -1,10 +1,10 @@
use beacon_chain::{BeaconChain, BeaconChainTypes};
use eth2::types::{self as api_types};
use slot_clock::SlotClock;
use types::{Epoch, EthSpec, Hash256, InclusionListDuty};
use types::{Epoch, EthSpec, Hash256, InclusionListDuty, PublicKeyBytes};
/// The struct that is returned to the requesting HTTP client.
type ApiDuties = api_types::DutiesResponse<Vec<api_types::InclusionListDutyData>>;
type ApiDuties = api_types::DutiesResponse<Vec<InclusionListDuty>>;
/// Handles a request from the HTTP API for inclusion list duties.
pub fn inclusion_list_duties<T: BeaconChainTypes>(
@@ -13,6 +13,15 @@ pub fn inclusion_list_duties<T: BeaconChainTypes>(
chain: &BeaconChain<T>,
) -> Result<ApiDuties, warp::reject::Rejection> {
let current_epoch = chain.epoch().map_err(warp_utils::reject::unhandled_error)?;
let request_indices = request_indices
.iter()
.map(|i| *i as usize)
.collect::<Vec<_>>();
let indices_and_pubkeys: Vec<(usize, PublicKeyBytes)> = chain
.validator_pubkey_bytes_many(&request_indices)
.map_err(|_| warp_utils::reject::custom_server_error("unable to fetch pubkey".into()))?
.into_iter()
.collect();
// Determine what the current epoch would be if we fast-forward our system clock by
// `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
@@ -32,10 +41,10 @@ pub fn inclusion_list_duties<T: BeaconChainTypes>(
{
let head_block_root = chain.canonical_head.cached_head().head_block_root();
let (duties, dependent_root) = chain
.validator_inclusion_list_duties(request_indices, request_epoch, head_block_root)
.validator_inclusion_list_duties(&indices_and_pubkeys, request_epoch, head_block_root)
.map_err(warp_utils::reject::unhandled_error)?;
//.map_err(warp_utils::reject::beacon_chain_error)?;
convert_to_api_response(duties, request_indices, dependent_root, chain)
convert_to_api_response(duties, &request_indices, dependent_root, chain)
} else if request_epoch > current_epoch + 1 {
Err(warp_utils::reject::custom_bad_request(format!(
"request epoch {} is more than one epoch past the current epoch {}",
@@ -52,13 +61,14 @@ pub fn inclusion_list_duties<T: BeaconChainTypes>(
}
}
/// Convert the internal representation of attester duties into the format returned to the HTTP
// TODO(focil) unused chain
/// Convert the internal representation of inclusion duties into the format returned to the HTTP
/// client.
fn convert_to_api_response<T: BeaconChainTypes>(
duties: Vec<Option<InclusionListDuty>>,
indices: &[u64],
indices: &[usize],
dependent_root: Hash256,
chain: &BeaconChain<T>,
_chain: &BeaconChain<T>,
) -> Result<ApiDuties, warp::reject::Rejection> {
// Protect against an inconsistent slot clock.
if duties.len() != indices.len() {
@@ -69,26 +79,23 @@ fn convert_to_api_response<T: BeaconChainTypes>(
)));
}
let usize_indices = indices.iter().map(|i| *i as usize).collect::<Vec<_>>();
let index_to_pubkey_map = chain
.validator_pubkey_bytes_many(&usize_indices)
.map_err(warp_utils::reject::unhandled_error)?;
// TODO(focil)
// let usize_indices = indices.iter().map(|i| *i as usize).collect::<Vec<_>>();
// let index_to_pubkey_map = chain
// .validator_pubkey_bytes_many(indices)
// .map_err(warp_utils::reject::unhandled_error)?;
// .map_err(warp_utils::reject::beacon_chain_error)?;
let data = duties
.into_iter()
.zip(indices)
.filter_map(|(duty_opt, &validator_index)| {
.filter_map(|(duty_opt, _)| {
let duty = duty_opt?;
Some(api_types::InclusionListDutyData {
validator_index,
pubkey: *index_to_pubkey_map.get(&(validator_index as usize))?,
slot: duty.slot,
})
Some(duty)
})
.collect::<Vec<_>>();
// TODO: account for optimistic execution
// TODO(focil): account for optimistic execution
Ok(api_types::DutiesResponse {
dependent_root,
execution_optimistic: None,

View File

@@ -3584,11 +3584,13 @@ pub fn serve<T: BeaconChainTypes>(
.and(not_while_syncing_filter.clone())
.and(task_spawner_filter.clone())
.and(chain_filter.clone())
.and(log_filter.clone())
.then(
|query: api_types::ValidatorInclusionListQuery,
not_synced_filter: Result<(), Rejection>,
task_spawner: TaskSpawner<T::EthSpec>,
chain: Arc<BeaconChain<T>>| {
chain: Arc<BeaconChain<T>>,
log: Logger| {
task_spawner.spawn_async_with_rejection(Priority::P0, async move {
not_synced_filter?;
@@ -3604,11 +3606,21 @@ pub fn serve<T: BeaconChainTypes>(
)));
}
let data = chain
let data = match chain
.produce_inclusion_list(query.slot)
.await
.map(api_types::GenericResponse::from)
.map_err(warp_utils::reject::unhandled_error)?;
{
Ok(data) => data,
Err(e) => {
error!(
log,
"Failed producing IL";
"err" => format!("{:?}", e),
);
return Err(warp_utils::reject::unhandled_error(e));
}
};
Ok::<_, warp::reject::Rejection>(warp::reply::json(&data).into_response())
})
},