From 51984ab54d4f2625c449f4d17cf6c18867ea1695 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Thu, 6 Feb 2025 13:38:33 +0200 Subject: [PATCH] test progress --- beacon_node/beacon_chain/src/beacon_chain.rs | 2 ++ .../http_api/src/inclusion_list_duties.rs | 10 +++----- beacon_node/http_api/src/lib.rs | 8 ++---- beacon_node/http_api/tests/tests.rs | 25 +++++++++++++++++++ .../validator_services/src/duties_service.rs | 4 +++ .../src/inclusion_list_service.rs | 1 + 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index ebfe0f01c3..e0898f3491 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -1730,6 +1730,8 @@ impl BeaconChain { let head_beacon_state = self.get_state(&head_block.root, Some(head_block.slot))?; let Some(head_beacon_state) = head_beacon_state else { + // TODO(focil) missing beacon state + println!("WEVE FAILED HERE"); return Err(Error::MissingBeaconState(head_block.root)); }; let duties = validator_indices diff --git a/beacon_node/http_api/src/inclusion_list_duties.rs b/beacon_node/http_api/src/inclusion_list_duties.rs index eee831461b..33d9ee43d7 100644 --- a/beacon_node/http_api/src/inclusion_list_duties.rs +++ b/beacon_node/http_api/src/inclusion_list_duties.rs @@ -14,9 +14,7 @@ pub fn inclusion_list_duties( ) -> Result { let current_epoch = chain .epoch() - // TODO(focil) unwrap - .unwrap(); - // .map_err(warp_utils::reject::beacon_chain_error)?; + .map_err(warp_utils::reject::unhandled_error)?; // Determine what the current epoch would be if we fast-forward our system clock by // `MAXIMUM_GOSSIP_CLOCK_DISPARITY`. @@ -37,8 +35,7 @@ pub fn inclusion_list_duties( 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) - // TODO(focil) unwrap - .unwrap(); + .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) } else if request_epoch > current_epoch + 1 { @@ -77,8 +74,7 @@ fn convert_to_api_response( let usize_indices = indices.iter().map(|i| *i as usize).collect::>(); let index_to_pubkey_map = chain .validator_pubkey_bytes_many(&usize_indices) - // TODO(focil) unwrap - .unwrap(); + .map_err(warp_utils::reject::unhandled_error)?; // .map_err(warp_utils::reject::beacon_chain_error)?; let data = duties diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 1fc5fe7399..0467657989 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -3592,9 +3592,7 @@ pub fn serve( task_spawner.spawn_async_with_rejection(Priority::P0, async move { not_synced_filter?; - let current_slot = chain.slot().unwrap(); - // TODO(focil) unwrap - // .map_err(warp_utils::reject::beacon_chain_error)?; + let current_slot = chain.slot().map_err(warp_utils::reject::unhandled_error)?; // allow a tolerance of one slot to account for clock skew // @@ -3610,9 +3608,7 @@ pub fn serve( .produce_inclusion_list(query.slot) .await .map(api_types::GenericResponse::from) - // TODO(focil) unwrap - .unwrap(); - // .map_err(warp_utils::reject::beacon_chain_error)?; + .map_err(warp_utils::reject::unhandled_error)?; Ok::<_, warp::reject::Rejection>(warp::reply::json(&data).into_response()) }) }, diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 7f25b7ceeb..1e97146fd4 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -2669,6 +2669,17 @@ impl ApiTester { interesting } + pub async fn test_post_validator_duties_inclusion_list(self) -> Self { + let current_epoch = self.chain.epoch().unwrap(); + let slot = self.chain.slot().unwrap(); + self.harness.extend_to_slot(slot).await; + for validator_indices in self.interesting_validator_indices() { + let res = self.client.post_validator_duties_inclusion_list(current_epoch, &validator_indices).await.unwrap(); + println!("{:?}", res); + } + self + } + pub async fn test_get_validator_duties_attester(self) -> Self { let current_epoch = self.chain.epoch().unwrap().as_u64(); @@ -7317,3 +7328,17 @@ async fn create_signed_inclusion_lists() { .test_create_inclusion_lists() .await; } + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_post_validator_duties_inclusion_list () { + let mut config = ApiTesterConfig::default(); + config.spec.altair_fork_epoch = Some(Epoch::new(0)); + config.spec.bellatrix_fork_epoch = Some(Epoch::new(0)); + config.spec.capella_fork_epoch = Some(Epoch::new(0)); + config.spec.deneb_fork_epoch = Some(Epoch::new(0)); + config.spec.electra_fork_epoch = Some(Epoch::new(0)); + ApiTester::new_from_config(config) + .await + .test_post_validator_duties_inclusion_list() + .await; +} diff --git a/validator_client/validator_services/src/duties_service.rs b/validator_client/validator_services/src/duties_service.rs index 69b0c50242..55eaa3221d 100644 --- a/validator_client/validator_services/src/duties_service.rs +++ b/validator_client/validator_services/src/duties_service.rs @@ -338,6 +338,10 @@ impl DutiesService { pub fn inclusion_list_duties(&self, slot: Slot) -> Vec { let epoch = slot.epoch(E::slots_per_epoch()); + if !self.spec.is_focil_enabled_for_epoch(epoch) { + return vec![] + } + // Only collect validators that are considered safe in terms of doppelganger protection. let signing_pubkeys: HashSet<_> = self .validator_store diff --git a/validator_client/validator_services/src/inclusion_list_service.rs b/validator_client/validator_services/src/inclusion_list_service.rs index a2da25ef25..329a94d10d 100644 --- a/validator_client/validator_services/src/inclusion_list_service.rs +++ b/validator_client/validator_services/src/inclusion_list_service.rs @@ -159,6 +159,7 @@ impl InclusionListService { .now() .ok_or("Unable to determine current slot from clock") .map(|slot| slot.epoch(E::slots_per_epoch())); + // TODO(focil) unused variable let _current_epoch = current_epoch.map_err(|e| { crit!(