From 6477eecc65812990d3ea09f6b6782504546e0784 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Thu, 9 May 2024 21:19:59 -0400 Subject: [PATCH 1/3] update beacon api aggregate attestationendpoint --- beacon_node/http_api/src/lib.rs | 46 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index f8b6fcfa3c..82a6c9847b 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -3191,36 +3191,38 @@ pub fn serve( task_spawner: TaskSpawner, chain: Arc>| { task_spawner.blocking_json_task(Priority::P0, move || { - if endpoint_version == V2 { - if query.committee_index.is_none() { + 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.attestation_data_root, + committee_index, + ) } else if endpoint_version == V1 { // Do nothing - } else { - return Err(unsupported_version_rejection(endpoint_version)); - } - //TODO(electra) pass the index into the next method. - not_synced_filter?; - chain - .get_pre_electra_aggregated_attestation_by_slot_and_root( + chain.get_pre_electra_aggregated_attestation_by_slot_and_root( query.slot, &query.attestation_data_root, ) - .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(), - ) - }) + } 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(), + ) + }) }) }, ); From e4485570f22a340b7111f9a688705f2cb02b81e5 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Thu, 9 May 2024 21:29:31 -0400 Subject: [PATCH 2/3] update the naive agg pool interface (#5760) --- beacon_node/beacon_chain/src/beacon_chain.rs | 11 +++++++---- .../beacon_chain/src/naive_aggregation_pool.rs | 10 +++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 331e04069f..9cbb46afe9 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -1625,14 +1625,17 @@ impl BeaconChain { } } - // TODO(electra): call this function from the new beacon API method pub fn get_aggregated_attestation_electra( &self, - data: &AttestationData, + slot: Slot, + attestation_data_root: &Hash256, committee_index: CommitteeIndex, ) -> Result>, Error> { - let attestation_key = - crate::naive_aggregation_pool::AttestationKey::new_electra(data, committee_index); + let attestation_key = crate::naive_aggregation_pool::AttestationKey::new_electra( + slot, + *attestation_data_root, + committee_index, + ); if let Some(attestation) = self.naive_aggregation_pool.read().get(&attestation_key) { self.filter_optimistic_attestation(attestation) .map(Option::Some) diff --git a/beacon_node/beacon_chain/src/naive_aggregation_pool.rs b/beacon_node/beacon_chain/src/naive_aggregation_pool.rs index 6c4f7cdae7..a1c736cd0e 100644 --- a/beacon_node/beacon_chain/src/naive_aggregation_pool.rs +++ b/beacon_node/beacon_chain/src/naive_aggregation_pool.rs @@ -8,7 +8,8 @@ use types::consts::altair::SYNC_COMMITTEE_SUBNET_COUNT; use types::slot_data::SlotData; use types::sync_committee_contribution::SyncContributionData; use types::{ - Attestation, AttestationData, AttestationRef, EthSpec, Hash256, Slot, SyncCommitteeContribution, + Attestation, AttestationData, AttestationRef, CommitteeIndex, EthSpec, Hash256, Slot, + SyncCommitteeContribution, }; type AttestationKeyRoot = Hash256; @@ -18,7 +19,7 @@ type SyncDataRoot = Hash256; #[derive(Debug, Clone, PartialEq)] pub struct AttestationKey { data_root: Hash256, - committee_index: Option, + committee_index: Option, slot: Slot, } @@ -95,10 +96,9 @@ impl AttestationKey { } } - pub fn new_electra(data: &AttestationData, committee_index: u64) -> Self { - let slot = data.slot; + pub fn new_electra(slot: Slot, data_root: Hash256, committee_index: CommitteeIndex) -> Self { Self { - data_root: data.tree_hash_root(), + data_root, committee_index: Some(committee_index), slot, } From d505c04507bbd6a862e5ae11ad9e92530d6a03c0 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Thu, 9 May 2024 21:33:48 -0400 Subject: [PATCH 3/3] updates after merge --- beacon_node/execution_layer/src/engine_api.rs | 2 +- beacon_node/http_api/src/lib.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/beacon_node/execution_layer/src/engine_api.rs b/beacon_node/execution_layer/src/engine_api.rs index 09e36be41f..6bfd9997f4 100644 --- a/beacon_node/execution_layer/src/engine_api.rs +++ b/beacon_node/execution_layer/src/engine_api.rs @@ -644,7 +644,7 @@ impl ExecutionPayloadBodyV1 { "block {} is post-electra but payload body doesn't have withdrawals/deposit_receipts/withdrawal_requests \ Check that ELs are returning receipts and withdrawal_requests in getPayloadBody requests", header.block_hash - )) + )); }; Ok(ExecutionPayload::Electra(ExecutionPayloadElectra { parent_hash: header.parent_hash, diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 82a6c9847b..5d9a50ed07 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -3199,6 +3199,7 @@ pub fn serve( )); }; chain.get_aggregated_attestation_electra( + query.slot, &query.attestation_data_root, committee_index, )