Impl ForkVersionDecode for beacon state (#7954)

This commit is contained in:
Paul Etscheit
2025-09-01 04:22:40 +02:00
committed by GitHub
parent 438fb65d45
commit 66edda2690
2 changed files with 9 additions and 3 deletions

View File

@@ -170,7 +170,7 @@ impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> BeaconBlockBodyRef<'a, E,
} }
} }
pub(crate) fn body_merkle_leaves(&self) -> Vec<Hash256> { pub fn body_merkle_leaves(&self) -> Vec<Hash256> {
let mut leaves = vec![]; let mut leaves = vec![];
match self { match self {
Self::Base(body) => { Self::Base(body) => {

View File

@@ -2632,6 +2632,12 @@ impl<E: EthSpec> BeaconState<E> {
} }
} }
impl<E: EthSpec> ForkVersionDecode for BeaconState<E> {
fn from_ssz_bytes_by_fork(bytes: &[u8], fork_name: ForkName) -> Result<Self, ssz::DecodeError> {
Ok(map_fork_name!(fork_name, Self, <_>::from_ssz_bytes(bytes)?))
}
}
impl<E: EthSpec> BeaconState<E> { impl<E: EthSpec> BeaconState<E> {
/// The number of fields of the `BeaconState` rounded up to the nearest power of two. /// The number of fields of the `BeaconState` rounded up to the nearest power of two.
/// ///
@@ -2760,7 +2766,7 @@ impl<E: EthSpec> BeaconState<E> {
Ok(proof) Ok(proof)
} }
fn generate_proof( pub fn generate_proof(
&self, &self,
field_index: usize, field_index: usize,
leaves: &[Hash256], leaves: &[Hash256],
@@ -2775,7 +2781,7 @@ impl<E: EthSpec> BeaconState<E> {
Ok(proof) Ok(proof)
} }
fn get_beacon_state_leaves(&self) -> Vec<Hash256> { pub fn get_beacon_state_leaves(&self) -> Vec<Hash256> {
let mut leaves = vec![]; let mut leaves = vec![];
#[allow(clippy::arithmetic_side_effects)] #[allow(clippy::arithmetic_side_effects)]
match self { match self {