From 66edda2690f4c20d8dd83f0eca6b790221aba296 Mon Sep 17 00:00:00 2001 From: Paul Etscheit Date: Mon, 1 Sep 2025 04:22:40 +0200 Subject: [PATCH] Impl ForkVersionDecode for beacon state (#7954) --- consensus/types/src/beacon_block_body.rs | 2 +- consensus/types/src/beacon_state.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/consensus/types/src/beacon_block_body.rs b/consensus/types/src/beacon_block_body.rs index 73d02dbe61..7df9c3f3cb 100644 --- a/consensus/types/src/beacon_block_body.rs +++ b/consensus/types/src/beacon_block_body.rs @@ -170,7 +170,7 @@ impl<'a, E: EthSpec, Payload: AbstractExecPayload> BeaconBlockBodyRef<'a, E, } } - pub(crate) fn body_merkle_leaves(&self) -> Vec { + pub fn body_merkle_leaves(&self) -> Vec { let mut leaves = vec![]; match self { Self::Base(body) => { diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 5f3dff56cc..d2efbfe909 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -2632,6 +2632,12 @@ impl BeaconState { } } +impl ForkVersionDecode for BeaconState { + fn from_ssz_bytes_by_fork(bytes: &[u8], fork_name: ForkName) -> Result { + Ok(map_fork_name!(fork_name, Self, <_>::from_ssz_bytes(bytes)?)) + } +} + impl BeaconState { /// The number of fields of the `BeaconState` rounded up to the nearest power of two. /// @@ -2760,7 +2766,7 @@ impl BeaconState { Ok(proof) } - fn generate_proof( + pub fn generate_proof( &self, field_index: usize, leaves: &[Hash256], @@ -2775,7 +2781,7 @@ impl BeaconState { Ok(proof) } - fn get_beacon_state_leaves(&self) -> Vec { + pub fn get_beacon_state_leaves(&self) -> Vec { let mut leaves = vec![]; #[allow(clippy::arithmetic_side_effects)] match self {