Skip to content

Commit

Permalink
Get electra_op_pool up to date (#5756)
Browse files Browse the repository at this point in the history
* fix get attesting indices (#5742)

* fix get attesting indices

* better errors

* fix compile

* only get committee index once

* Ef test fixes (#5753)

* attestation related ef test fixes

* delete commented out stuff

* Fix Aggregation Pool for Electra (#5754)

* Fix Aggregation Pool for Electra

* Remove Outdated Interface

* fix ssz (#5755)

---------

Co-authored-by: realbigsean <sean@sigmaprime.io>
  • Loading branch information
ethDreamer and realbigsean authored May 9, 2024
1 parent 7cb7653 commit ab9e58a
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 108 deletions.
5 changes: 3 additions & 2 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,11 @@ pub fn obtain_indexed_attestation_and_committees_per_slot<T: BeaconChainTypes>(
attesting_indices_electra::get_indexed_attestation(&committees, att)
.map(|attestation| (attestation, committees_per_slot))
.map_err(|e| {
if e == BlockOperationError::BeaconStateError(NoCommitteeFound) {
let index = att.committee_index();
if e == BlockOperationError::BeaconStateError(NoCommitteeFound(index)) {
Error::NoCommitteeForSlotAndIndex {
slot: att.data.slot,
index: att.committee_index(),
index,
}
} else {
Error::Invalid(e)
Expand Down
38 changes: 30 additions & 8 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,11 +1612,28 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// Returns an aggregated `Attestation`, if any, that has a matching `attestation.data`.
///
/// The attestation will be obtained from `self.naive_aggregation_pool`.
pub fn get_aggregated_attestation(
pub fn get_aggregated_attestation_base(
&self,
data: &AttestationData,
) -> Result<Option<Attestation<T::EthSpec>>, Error> {
if let Some(attestation) = self.naive_aggregation_pool.read().get(data) {
let attestation_key = crate::naive_aggregation_pool::AttestationKey::new_base(data);
if let Some(attestation) = self.naive_aggregation_pool.read().get(&attestation_key) {
self.filter_optimistic_attestation(attestation)
.map(Option::Some)
} else {
Ok(None)
}
}

// TODO(electra): call this function from the new beacon API method
pub fn get_aggregated_attestation_electra(
&self,
data: &AttestationData,
committee_index: CommitteeIndex,
) -> Result<Option<Attestation<T::EthSpec>>, Error> {
let attestation_key =
crate::naive_aggregation_pool::AttestationKey::new_electra(data, committee_index);
if let Some(attestation) = self.naive_aggregation_pool.read().get(&attestation_key) {
self.filter_optimistic_attestation(attestation)
.map(Option::Some)
} else {
Expand All @@ -1628,16 +1645,21 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// `attestation.data.tree_hash_root()`.
///
/// The attestation will be obtained from `self.naive_aggregation_pool`.
pub fn get_aggregated_attestation_by_slot_and_root(
///
/// NOTE: This function will *only* work with pre-electra attestations and it only
/// exists to support the pre-electra validator API method.
pub fn get_pre_electra_aggregated_attestation_by_slot_and_root(
&self,
slot: Slot,
attestation_data_root: &Hash256,
) -> Result<Option<Attestation<T::EthSpec>>, Error> {
if let Some(attestation) = self
.naive_aggregation_pool
.read()
.get_by_slot_and_root(slot, attestation_data_root)
{
let attestation_key =
crate::naive_aggregation_pool::AttestationKey::new_base_from_slot_and_root(
slot,
*attestation_data_root,
);

if let Some(attestation) = self.naive_aggregation_pool.read().get(&attestation_key) {
self.filter_optimistic_attestation(attestation)
.map(Option::Some)
} else {
Expand Down
Loading

0 comments on commit ab9e58a

Please sign in to comment.