Skip to content

Commit

Permalink
Use ForkName Ord in BeaconBlockBody
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Jun 17, 2024
1 parent 31057eb commit 2d11fc4
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions consensus/types/src/beacon_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,11 @@ impl<E: EthSpec> From<BeaconBlockBody<E, FullPayload<E>>>
}

impl<E: EthSpec> BeaconBlockBody<E> {
/// Returns the name of the fork pertaining to `self`.
pub fn fork_name(&self) -> ForkName {
self.to_ref().fork_name()
}

pub fn block_body_merkle_proof(&self, generalized_index: usize) -> Result<Vec<Hash256>, Error> {
let field_index = match generalized_index {
light_client_update::EXECUTION_PAYLOAD_INDEX => {
Expand All @@ -834,22 +839,16 @@ impl<E: EthSpec> BeaconBlockBody<E> {
_ => return Err(Error::IndexNotSupported(generalized_index)),
};

let attestations_root = match self {
BeaconBlockBody::Base(_)
| BeaconBlockBody::Altair(_)
| BeaconBlockBody::Bellatrix(_)
| BeaconBlockBody::Capella(_)
| BeaconBlockBody::Deneb(_) => self.attestations_base()?.tree_hash_root(),
BeaconBlockBody::Electra(_) => self.attestations_electra()?.tree_hash_root(),
let attestations_root = if self.fork_name() > ForkName::Electra {
self.attestations_electra()?.tree_hash_root()
} else {
self.attestations_base()?.tree_hash_root()
};

let attester_slashings_root = match self {
BeaconBlockBody::Base(_)
| BeaconBlockBody::Altair(_)
| BeaconBlockBody::Bellatrix(_)
| BeaconBlockBody::Capella(_)
| BeaconBlockBody::Deneb(_) => self.attester_slashings_base()?.tree_hash_root(),
BeaconBlockBody::Electra(_) => self.attester_slashings_electra()?.tree_hash_root(),
let attester_slashings_root = if self.fork_name() > ForkName::Electra {
self.attester_slashings_electra()?.tree_hash_root()
} else {
self.attester_slashings_base()?.tree_hash_root()
};

let mut leaves = vec![
Expand Down

0 comments on commit 2d11fc4

Please sign in to comment.