diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 53abca67ad..8eabdeb36a 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -3289,7 +3289,7 @@ impl ApiTester { .chain .spec .fork_name_at_slot::(self.chain.slot().unwrap()) - >= ForkName::Electra + .electra_enabled() { for attestation in self.chain.naive_aggregation_pool.read().iter() { let result = self diff --git a/common/eth2/src/lib.rs b/common/eth2/src/lib.rs index ff85d6e64f..e6fa6eb02f 100644 --- a/common/eth2/src/lib.rs +++ b/common/eth2/src/lib.rs @@ -346,7 +346,7 @@ impl BeaconNodeHttpClient { Ok(()) } - /// Perform a HTTP POST request with a custom timeout. + /// Perform a HTTP POST request with a custom timeout and consensus header. async fn post_with_timeout_and_consensus_header( &self, url: U, @@ -410,6 +410,7 @@ impl BeaconNodeHttpClient { /// Generic POST function supporting arbitrary responses and timeouts. /// Does not include Content-Type application/json in the request header. + /// Does include Eth-Consensus-Version in the request header. async fn post_generic_json_without_content_type_header_but_with_consensus_header< T: Serialize, U: IntoUrl, @@ -2358,7 +2359,7 @@ impl BeaconNodeHttpClient { slot: Slot, attestation_data_root: Hash256, committee_index: CommitteeIndex, - ) -> Result>>, Error> { + ) -> Result>>, Error> { let mut path = self.eth_path(V2)?; path.path_segments_mut() diff --git a/consensus/types/src/attestation.rs b/consensus/types/src/attestation.rs index 1acaee9654..1ee6c437c9 100644 --- a/consensus/types/src/attestation.rs +++ b/consensus/types/src/attestation.rs @@ -487,6 +487,23 @@ impl<'a, E: EthSpec> From> for AttestationRef<'a, E> } } +impl ForkVersionDeserialize for Attestation { + fn deserialize_by_fork<'de, D: serde::Deserializer<'de>>( + value: serde_json::Value, + fork_name: crate::ForkName, + ) -> Result { + if fork_name.electra_enabled() { + let attestation: AttestationElectra = + serde_json::from_value(value).map_err(serde::de::Error::custom)?; + Ok(Attestation::Electra(attestation)) + } else { + let attestation: AttestationBase = + serde_json::from_value(value).map_err(serde::de::Error::custom)?; + Ok(Attestation::Base(attestation)) + } + } +} + impl ForkVersionDeserialize for Vec> { fn deserialize_by_fork<'de, D: serde::Deserializer<'de>>( value: serde_json::Value, diff --git a/validator_client/src/attestation_service.rs b/validator_client/src/attestation_service.rs index 5167f8b649..30fe508a2c 100644 --- a/validator_client/src/attestation_service.rs +++ b/validator_client/src/attestation_service.rs @@ -548,7 +548,7 @@ impl AttestationService { &metrics::ATTESTATION_SERVICE_TIMES, &[metrics::AGGREGATES_HTTP_GET], ); - let aggregate_attestation_result = if fork_name.electra_enabled() { + if fork_name.electra_enabled() { beacon_node .get_validator_aggregate_attestation_v2( attestation_data.slot, @@ -556,6 +556,13 @@ impl AttestationService { committee_index, ) .await + .map_err(|e| { + format!("Failed to produce an aggregate attestation: {:?}", e) + })? + .ok_or_else(|| { + format!("No aggregate available for {:?}", attestation_data) + }) + .map(|result| result.data) } else { beacon_node .get_validator_aggregate_attestation_v1( @@ -563,14 +570,14 @@ impl AttestationService { attestation_data.tree_hash_root(), ) .await - }; - - aggregate_attestation_result - .map_err(|e| { - format!("Failed to produce an aggregate attestation: {:?}", e) - })? - .ok_or_else(|| format!("No aggregate available for {:?}", attestation_data)) - .map(|result| result.data) + .map_err(|e| { + format!("Failed to produce an aggregate attestation: {:?}", e) + })? + .ok_or_else(|| { + format!("No aggregate available for {:?}", attestation_data) + }) + .map(|result| result.data) + } }, ) .await