Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
914bb1e
persist light client updates
eserilev Apr 2, 2024
c308768
update beacon chain to serve light client updates
eserilev Apr 2, 2024
e332b00
resolve todos
eserilev Apr 2, 2024
3a93933
cache best update
eserilev Apr 3, 2024
b9bdd88
extend cache parts
eserilev Apr 10, 2024
9671423
is better light client update
eserilev Apr 10, 2024
5861417
resolve merge conflict
eserilev Apr 10, 2024
6e0fa26
initial api changes
eserilev Apr 11, 2024
c8af8fb
add lc update db column
eserilev Apr 15, 2024
45a5d8d
fmt
eserilev Apr 16, 2024
2545655
added tests
eserilev Apr 28, 2024
3029f2c
add sim
eserilev Apr 28, 2024
fad083a
Merge branch 'unstable' of https://github.com/sigp/lighthouse into pe…
eserilev May 14, 2024
49a7e61
fix some weird issues with the simulator
eserilev May 15, 2024
00d4fd0
tests
eserilev May 27, 2024
4b8683c
Merge branch 'unstable' of https://github.com/sigp/lighthouse into pe…
eserilev May 27, 2024
6f12133
test changes
eserilev May 29, 2024
9464518
merge conflict
eserilev May 29, 2024
22e9201
testing
eserilev May 31, 2024
1946100
started work on ef tests and some code clean up
eserilev Jun 3, 2024
2b1e47d
update tests
eserilev Jun 4, 2024
211601c
linting
eserilev Jun 4, 2024
891d677
noop pre altair, were still failing on electra though
eserilev Jun 5, 2024
d729fea
allow for zeroed light client header
eserilev Jun 10, 2024
58f178a
Merge branch 'unstable' of https://github.com/sigp/lighthouse into pe…
eserilev Jun 10, 2024
fe2b43d
merge unstable
eserilev Jun 10, 2024
1774e63
remove unwraps
eserilev Jun 10, 2024
af9b20d
remove unwraps
eserilev Jun 10, 2024
d82226b
fetch bootstrap without always querying for state
eserilev Jun 11, 2024
ce765f3
storing bootstrap parts in db
eserilev Jun 12, 2024
4a9b088
mroe code cleanup
eserilev Jun 13, 2024
7a0fdae
test
eserilev Jun 17, 2024
93a97ea
prune sync committee branches from dropped chains
eserilev Jun 24, 2024
d8e6891
Update light_client_update.rs
dapplion Jun 25, 2024
bfd6ca2
merge unstable
eserilev Jun 25, 2024
fa7cd25
move functionality to helper methods
eserilev Jun 25, 2024
bb69c48
refactor is best update fn
eserilev Jun 25, 2024
fa50339
refactor is best update fn
eserilev Jun 25, 2024
89ae007
improve organization of light client server cache logic
eserilev Jun 25, 2024
7fcf032
fork diget calc, and only spawn as many blcoks as we need for the lc …
eserilev Jun 25, 2024
b4c5775
resovle merge conflict
eserilev Jun 25, 2024
0fdf544
add electra bootstrap logic, add logic to cache current sync committee
eserilev Jun 25, 2024
d983c3b
add latest sync committe branch cache
eserilev Jun 26, 2024
8bf1bc6
fetch lc update from the cache if it exists
eserilev Jun 26, 2024
f70b93e
fmt
eserilev Jun 26, 2024
eb19b0d
Fix beacon_chain tests
dapplion Jul 5, 2024
bcda61b
Add debug code to update ranking_order ef test
dapplion Jul 5, 2024
e8691db
Fix compare code
dapplion Jul 5, 2024
50a29c5
merge conflicts
eserilev Jul 26, 2024
194bf5a
merge conflict
eserilev Jul 29, 2024
6458ec9
add better error messaging
eserilev Jul 29, 2024
206a629
resolve merge conflicts
eserilev Aug 12, 2024
807ec80
remove lc update from basicsim
eserilev Aug 12, 2024
8c1f980
rename sync comittte variable and fix persist condition
eserilev Aug 13, 2024
8ef297b
refactor get_light_client_update logic
eserilev Aug 13, 2024
e75b84f
add better comments, return helpful error messages over http and rpc
eserilev Aug 13, 2024
de331f0
pruning canonical non checkpoint slots
eserilev Aug 14, 2024
35c5453
fix test
eserilev Aug 15, 2024
091bff1
rerun test
eserilev Aug 15, 2024
dddc5a8
update pruning logic, add tests
eserilev Aug 22, 2024
d5eab8c
fix tests
eserilev Aug 22, 2024
c42c580
fix imports
eserilev Aug 22, 2024
8686eb2
fmt
eserilev Aug 22, 2024
ea0e0c4
refactor db code
eserilev Aug 22, 2024
430b00b
Refactor db method
eserilev Aug 22, 2024
5646203
Refactor db method
eserilev Aug 22, 2024
c99135d
lc electra changes
eserilev Aug 26, 2024
6035114
Merge branch 'unstable' of https://github.com/sigp/lighthouse into li…
eserilev Aug 26, 2024
a202eac
add additional comments
eserilev Aug 28, 2024
37b733f
testing lc merkle changes
eserilev Aug 28, 2024
643f2e9
lc electra
eserilev Sep 3, 2024
6062b47
update struct defs
eserilev Sep 5, 2024
97c9e28
Merge branch 'unstable' of https://github.com/sigp/lighthouse into li…
eserilev Sep 5, 2024
42c2a1e
fix merge
eserilev Sep 5, 2024
a62e3c8
Merge branch 'unstable' of https://github.com/sigp/lighthouse into pe…
eserilev Sep 5, 2024
f66aa7c
fix merge
eserilev Sep 5, 2024
b9c3f44
linting
eserilev Sep 5, 2024
d8822a0
merge conflict
eserilev Sep 6, 2024
82a57b5
prevent overflow
eserilev Sep 6, 2024
e141c80
enable lc server for http api tests
eserilev Sep 6, 2024
7d406a9
Merge branch 'unstable' of https://github.com/sigp/lighthouse into li…
eserilev Sep 7, 2024
df1bfe6
get tests working:
eserilev Sep 7, 2024
1159320
remove related TODOs
eserilev Sep 7, 2024
6d1aa25
fix test lint
eserilev Sep 7, 2024
ba5f3aa
Merge branch 'persist-light-client-bootstrap' of https://github.com/e…
eserilev Sep 7, 2024
521d5f2
fix tests
eserilev Sep 9, 2024
3f102a1
fix conflicts
eserilev Sep 9, 2024
1873484
remove prints
eserilev Sep 9, 2024
d5f01ae
Merge branch 'persist-light-client-bootstrap' of https://github.com/e…
eserilev Sep 9, 2024
05b6426
remove warning
eserilev Sep 9, 2024
acd4d5e
resolve conflicts
eserilev Sep 9, 2024
f4c2d28
merge conflicts
eserilev Sep 10, 2024
9bf4f67
linting
eserilev Sep 10, 2024
e5144c5
remove comments
eserilev Sep 10, 2024
52b95bb
cleanup
eserilev Sep 10, 2024
8ab621e
linting
eserilev Sep 10, 2024
d142b81
Merge branch 'unstable' of https://github.com/sigp/lighthouse into li…
eserilev Sep 16, 2024
2338ec3
pre/post electra light client cached data
eserilev Sep 16, 2024
aa08704
add proof type alias
eserilev Sep 16, 2024
b23642e
move is_empty_branch method out of impl
eserilev Sep 16, 2024
9341d87
add ssz tests for all forks
eserilev Sep 16, 2024
af07434
refactor beacon state proof codepaths
eserilev Sep 16, 2024
0f85398
rename method
eserilev Sep 16, 2024
1c04873
fmt
eserilev Sep 16, 2024
9223a68
clean up proof logic
eserilev Sep 16, 2024
6809f6b
refactor merkle proof api
eserilev Sep 17, 2024
d1f6079
fmt
eserilev Sep 17, 2024
b0a3a14
Merge branch 'unstable' into light-client-electra
eserilev Sep 19, 2024
7d67d0d
Use superstruct mapping macros
michaelsproul Sep 23, 2024
22e2be5
Merge branch 'unstable' of https://github.com/sigp/lighthouse into li…
eserilev Sep 23, 2024
fa6e999
rename proof to merkleproof
eserilev Sep 23, 2024
894044a
fmt
eserilev Sep 23, 2024
9909661
Resolve merge conflicts
eserilev Oct 3, 2024
ba44370
merge conflicts
eserilev Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 17 additions & 29 deletions beacon_node/beacon_chain/src/light_client_server_cache.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
use crate::errors::BeaconChainError;
use crate::{metrics, BeaconChainTypes, BeaconStore};
use eth2::types::light_client_update::CurrentSyncCommitteeProofLen;
use parking_lot::{Mutex, RwLock};
use safe_arith::SafeArith;
use slog::{debug, Logger};
use ssz::Decode;
use ssz_types::FixedVector;
use std::num::NonZeroUsize;
use std::sync::Arc;
use store::DBColumn;
use store::KeyValueStore;
use tree_hash::TreeHash;
use types::light_client_update::{
FinalizedRootProofLen, NextSyncCommitteeProofLen, CURRENT_SYNC_COMMITTEE_INDEX,
FINALIZED_ROOT_INDEX, NEXT_SYNC_COMMITTEE_INDEX,
};
use types::non_zero_usize::new_non_zero_usize;
use types::{
BeaconBlockRef, BeaconState, ChainSpec, Checkpoint, EthSpec, ForkName, Hash256,
LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate,
LightClientUpdate, Slot, SyncAggregate, SyncCommittee,
LightClientUpdate, MerkleProof, Slot, SyncAggregate, SyncCommittee,
};

/// A prev block cache miss requires to re-generate the state of the post-parent block. Items in the
Expand Down Expand Up @@ -69,17 +63,14 @@ impl<T: BeaconChainTypes> LightClientServerCache<T> {
block_post_state: &mut BeaconState<T::EthSpec>,
) -> Result<(), BeaconChainError> {
let _timer = metrics::start_timer(&metrics::LIGHT_CLIENT_SERVER_CACHE_STATE_DATA_TIMES);

let fork_name = spec.fork_name_at_slot::<T::EthSpec>(block.slot());
// Only post-altair
if spec.fork_name_at_slot::<T::EthSpec>(block.slot()) == ForkName::Base {
return Ok(());
if fork_name.altair_enabled() {
// Persist in memory cache for a descendent block
let cached_data = LightClientCachedData::from_state(block_post_state)?;
self.prev_block_cache.lock().put(block_root, cached_data);
}

// Persist in memory cache for a descendent block

let cached_data = LightClientCachedData::from_state(block_post_state)?;
self.prev_block_cache.lock().put(block_root, cached_data);

Ok(())
}

Expand Down Expand Up @@ -413,34 +404,31 @@ impl<T: BeaconChainTypes> Default for LightClientServerCache<T> {
}
}

type FinalityBranch = FixedVector<Hash256, FinalizedRootProofLen>;
type NextSyncCommitteeBranch = FixedVector<Hash256, NextSyncCommitteeProofLen>;
type CurrentSyncCommitteeBranch = FixedVector<Hash256, CurrentSyncCommitteeProofLen>;

#[derive(Clone)]
struct LightClientCachedData<E: EthSpec> {
finalized_checkpoint: Checkpoint,
finality_branch: FinalityBranch,
next_sync_committee_branch: NextSyncCommitteeBranch,
current_sync_committee_branch: CurrentSyncCommitteeBranch,
finality_branch: MerkleProof,
next_sync_committee_branch: MerkleProof,
current_sync_committee_branch: MerkleProof,
next_sync_committee: Arc<SyncCommittee<E>>,
current_sync_committee: Arc<SyncCommittee<E>>,
finalized_block_root: Hash256,
}

impl<E: EthSpec> LightClientCachedData<E> {
fn from_state(state: &mut BeaconState<E>) -> Result<Self, BeaconChainError> {
let (finality_branch, next_sync_committee_branch, current_sync_committee_branch) = (
state.compute_finalized_root_proof()?,
state.compute_current_sync_committee_proof()?,
state.compute_next_sync_committee_proof()?,
);
Ok(Self {
finalized_checkpoint: state.finalized_checkpoint(),
finality_branch: state.compute_merkle_proof(FINALIZED_ROOT_INDEX)?.into(),
finality_branch,
next_sync_committee: state.next_sync_committee()?.clone(),
current_sync_committee: state.current_sync_committee()?.clone(),
next_sync_committee_branch: state
.compute_merkle_proof(NEXT_SYNC_COMMITTEE_INDEX)?
.into(),
current_sync_committee_branch: state
.compute_merkle_proof(CURRENT_SYNC_COMMITTEE_INDEX)?
.into(),
next_sync_committee_branch,
current_sync_committee_branch,
finalized_block_root: state.finalized_checkpoint().root,
})
}
Expand Down
12 changes: 0 additions & 12 deletions beacon_node/beacon_chain/tests/store_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,6 @@ async fn light_client_bootstrap_test() {
.build()
.expect("should build");

let current_state = harness.get_current_state();

if ForkName::Electra == current_state.fork_name_unchecked() {
// TODO(electra) fix beacon state `compute_merkle_proof`
return;
}

let finalized_checkpoint = beacon_chain
.canonical_head
.cached_head()
Expand Down Expand Up @@ -353,11 +346,6 @@ async fn light_client_updates_test() {

let current_state = harness.get_current_state();

if ForkName::Electra == current_state.fork_name_unchecked() {
// TODO(electra) fix beacon state `compute_merkle_proof`
return;
}

// calculate the sync period from the previous slot
let sync_period = (current_state.slot() - Slot::new(1))
.epoch(E::slots_per_epoch())
Expand Down
8 changes: 3 additions & 5 deletions beacon_node/store/src/hot_cold_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use std::path::Path;
use std::sync::Arc;
use std::time::Duration;
use types::data_column_sidecar::{ColumnIndex, DataColumnSidecar, DataColumnSidecarList};
use types::light_client_update::CurrentSyncCommitteeProofLen;
use types::*;

/// On-disk database that stores finalized states efficiently.
Expand Down Expand Up @@ -641,15 +640,14 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
pub fn get_sync_committee_branch(
&self,
block_root: &Hash256,
) -> Result<Option<FixedVector<Hash256, CurrentSyncCommitteeProofLen>>, Error> {
) -> Result<Option<MerkleProof>, Error> {
let column = DBColumn::SyncCommitteeBranch;

if let Some(bytes) = self
.hot_db
.get_bytes(column.into(), &block_root.as_ssz_bytes())?
{
let sync_committee_branch: FixedVector<Hash256, CurrentSyncCommitteeProofLen> =
FixedVector::from_ssz_bytes(&bytes)?;
let sync_committee_branch = Vec::<Hash256>::from_ssz_bytes(&bytes)?;
return Ok(Some(sync_committee_branch));
}

Expand Down Expand Up @@ -677,7 +675,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
pub fn store_sync_committee_branch(
&self,
block_root: Hash256,
sync_committee_branch: &FixedVector<Hash256, CurrentSyncCommitteeProofLen>,
sync_committee_branch: &MerkleProof,
) -> Result<(), Error> {
let column = DBColumn::SyncCommitteeBranch;
self.hot_db.put_bytes(
Expand Down
92 changes: 56 additions & 36 deletions consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2506,33 +2506,64 @@ impl<E: EthSpec> BeaconState<E> {
Ok(())
}

pub fn compute_merkle_proof(&self, generalized_index: usize) -> Result<Vec<Hash256>, Error> {
// 1. Convert generalized index to field index.
let field_index = match generalized_index {
pub fn compute_current_sync_committee_proof(&self) -> Result<Vec<Hash256>, Error> {
// Sync committees are top-level fields, subtract off the generalized indices
// for the internal nodes. Result should be 22 or 23, the field offset of the committee
// in the `BeaconState`:
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#beaconstate
let field_index = if self.fork_name_unchecked().electra_enabled() {
light_client_update::CURRENT_SYNC_COMMITTEE_INDEX_ELECTRA
} else {
light_client_update::CURRENT_SYNC_COMMITTEE_INDEX
| light_client_update::NEXT_SYNC_COMMITTEE_INDEX => {
// Sync committees are top-level fields, subtract off the generalized indices
// for the internal nodes. Result should be 22 or 23, the field offset of the committee
// in the `BeaconState`:
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#beaconstate
generalized_index
.checked_sub(self.num_fields_pow2())
.ok_or(Error::IndexNotSupported(generalized_index))?
}
light_client_update::FINALIZED_ROOT_INDEX => {
// Finalized root is the right child of `finalized_checkpoint`, divide by two to get
// the generalized index of `state.finalized_checkpoint`.
let finalized_checkpoint_generalized_index = generalized_index / 2;
// Subtract off the internal nodes. Result should be 105/2 - 32 = 20 which matches
// position of `finalized_checkpoint` in `BeaconState`.
finalized_checkpoint_generalized_index
.checked_sub(self.num_fields_pow2())
.ok_or(Error::IndexNotSupported(generalized_index))?
}
_ => return Err(Error::IndexNotSupported(generalized_index)),
};
let leaves = self.get_beacon_state_leaves();
self.generate_proof(field_index, &leaves)
}

// 2. Get all `BeaconState` leaves.
pub fn compute_next_sync_committee_proof(&self) -> Result<Vec<Hash256>, Error> {
// Sync committees are top-level fields, subtract off the generalized indices
// for the internal nodes. Result should be 22 or 23, the field offset of the committee
// in the `BeaconState`:
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#beaconstate
let field_index = if self.fork_name_unchecked().electra_enabled() {
light_client_update::NEXT_SYNC_COMMITTEE_INDEX_ELECTRA
} else {
light_client_update::NEXT_SYNC_COMMITTEE_INDEX
};
let leaves = self.get_beacon_state_leaves();
self.generate_proof(field_index, &leaves)
}

pub fn compute_finalized_root_proof(&self) -> Result<Vec<Hash256>, Error> {
// Finalized root is the right child of `finalized_checkpoint`, divide by two to get
// the generalized index of `state.finalized_checkpoint`.
let field_index = if self.fork_name_unchecked().electra_enabled() {
// Index should be 169/2 - 64 = 20 which matches the position
// of `finalized_checkpoint` in `BeaconState`
light_client_update::FINALIZED_ROOT_INDEX_ELECTRA
} else {
// Index should be 105/2 - 32 = 20 which matches the position
// of `finalized_checkpoint` in `BeaconState`
light_client_update::FINALIZED_ROOT_INDEX
};
let leaves = self.get_beacon_state_leaves();
let mut proof = self.generate_proof(field_index, &leaves)?;
proof.insert(0, self.finalized_checkpoint().epoch.tree_hash_root());
Ok(proof)
}

fn generate_proof(
&self,
field_index: usize,
leaves: &[Hash256],
) -> Result<Vec<Hash256>, Error> {
let depth = self.num_fields_pow2().ilog2() as usize;
let tree = merkle_proof::MerkleTree::create(leaves, depth);
let (_, proof) = tree.generate_proof(field_index, depth)?;
Ok(proof)
}

fn get_beacon_state_leaves(&self) -> Vec<Hash256> {
let mut leaves = vec![];
#[allow(clippy::arithmetic_side_effects)]
match self {
Expand Down Expand Up @@ -2568,18 +2599,7 @@ impl<E: EthSpec> BeaconState<E> {
}
};

// 3. Make deposit tree.
// Use the depth of the `BeaconState` fields (i.e. `log2(32) = 5`).
let depth = light_client_update::CURRENT_SYNC_COMMITTEE_PROOF_LEN;
let tree = merkle_proof::MerkleTree::create(&leaves, depth);
let (_, mut proof) = tree.generate_proof(field_index, depth)?;

// 4. If we're proving the finalized root, patch in the finalized epoch to complete the proof.
if generalized_index == light_client_update::FINALIZED_ROOT_INDEX {
proof.insert(0, self.finalized_checkpoint().epoch.tree_hash_root());
}

Ok(proof)
leaves
}
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub use crate::light_client_optimistic_update::{
};
pub use crate::light_client_update::{
Error as LightClientUpdateError, LightClientUpdate, LightClientUpdateAltair,
LightClientUpdateCapella, LightClientUpdateDeneb, LightClientUpdateElectra,
LightClientUpdateCapella, LightClientUpdateDeneb, LightClientUpdateElectra, MerkleProof,
};
pub use crate::participation_flags::ParticipationFlags;
pub use crate::payload::{
Expand Down
57 changes: 42 additions & 15 deletions consensus/types/src/light_client_bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ pub struct LightClientBootstrap<E: EthSpec> {
/// The `SyncCommittee` used in the requested period.
pub current_sync_committee: Arc<SyncCommittee<E>>,
/// Merkle proof for sync committee
#[superstruct(
only(Altair, Capella, Deneb),
partial_getter(rename = "current_sync_committee_branch_altair")
)]
pub current_sync_committee_branch: FixedVector<Hash256, CurrentSyncCommitteeProofLen>,
#[superstruct(
only(Electra),
partial_getter(rename = "current_sync_committee_branch_electra")
)]
pub current_sync_committee_branch: FixedVector<Hash256, CurrentSyncCommitteeProofLenElectra>,
}

impl<E: EthSpec> LightClientBootstrap<E> {
Expand Down Expand Up @@ -115,7 +124,7 @@ impl<E: EthSpec> LightClientBootstrap<E> {
pub fn new(
block: &SignedBlindedBeaconBlock<E>,
current_sync_committee: Arc<SyncCommittee<E>>,
current_sync_committee_branch: FixedVector<Hash256, CurrentSyncCommitteeProofLen>,
current_sync_committee_branch: Vec<Hash256>,
chain_spec: &ChainSpec,
) -> Result<Self, Error> {
let light_client_bootstrap = match block
Expand All @@ -126,22 +135,22 @@ impl<E: EthSpec> LightClientBootstrap<E> {
ForkName::Altair | ForkName::Bellatrix => Self::Altair(LightClientBootstrapAltair {
header: LightClientHeaderAltair::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch,
current_sync_committee_branch: current_sync_committee_branch.into(),
}),
ForkName::Capella => Self::Capella(LightClientBootstrapCapella {
header: LightClientHeaderCapella::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch,
current_sync_committee_branch: current_sync_committee_branch.into(),
}),
ForkName::Deneb => Self::Deneb(LightClientBootstrapDeneb {
header: LightClientHeaderDeneb::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch,
current_sync_committee_branch: current_sync_committee_branch.into(),
}),
ForkName::Electra => Self::Electra(LightClientBootstrapElectra {
header: LightClientHeaderElectra::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch,
current_sync_committee_branch: current_sync_committee_branch.into(),
}),
};

Expand All @@ -155,9 +164,7 @@ impl<E: EthSpec> LightClientBootstrap<E> {
) -> Result<Self, Error> {
let mut header = beacon_state.latest_block_header().clone();
header.state_root = beacon_state.update_tree_hash_cache()?;
let current_sync_committee_branch =
FixedVector::new(beacon_state.compute_merkle_proof(CURRENT_SYNC_COMMITTEE_INDEX)?)?;

let current_sync_committee_branch = beacon_state.compute_current_sync_committee_proof()?;
let current_sync_committee = beacon_state.current_sync_committee()?.clone();

let light_client_bootstrap = match block
Expand All @@ -168,22 +175,22 @@ impl<E: EthSpec> LightClientBootstrap<E> {
ForkName::Altair | ForkName::Bellatrix => Self::Altair(LightClientBootstrapAltair {
header: LightClientHeaderAltair::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch,
current_sync_committee_branch: current_sync_committee_branch.into(),
}),
ForkName::Capella => Self::Capella(LightClientBootstrapCapella {
header: LightClientHeaderCapella::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch,
current_sync_committee_branch: current_sync_committee_branch.into(),
}),
ForkName::Deneb => Self::Deneb(LightClientBootstrapDeneb {
header: LightClientHeaderDeneb::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch,
current_sync_committee_branch: current_sync_committee_branch.into(),
}),
ForkName::Electra => Self::Electra(LightClientBootstrapElectra {
header: LightClientHeaderElectra::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch,
current_sync_committee_branch: current_sync_committee_branch.into(),
}),
};

Expand All @@ -210,8 +217,28 @@ impl<E: EthSpec> ForkVersionDeserialize for LightClientBootstrap<E> {

#[cfg(test)]
mod tests {
use super::*;
use crate::MainnetEthSpec;
// `ssz_tests!` can only be defined once per namespace
#[cfg(test)]
mod altair {
use crate::{LightClientBootstrapAltair, MainnetEthSpec};
ssz_tests!(LightClientBootstrapAltair<MainnetEthSpec>);
}

#[cfg(test)]
mod capella {
use crate::{LightClientBootstrapCapella, MainnetEthSpec};
ssz_tests!(LightClientBootstrapCapella<MainnetEthSpec>);
}

ssz_tests!(LightClientBootstrapDeneb<MainnetEthSpec>);
#[cfg(test)]
mod deneb {
use crate::{LightClientBootstrapDeneb, MainnetEthSpec};
ssz_tests!(LightClientBootstrapDeneb<MainnetEthSpec>);
}

#[cfg(test)]
mod electra {
use crate::{LightClientBootstrapElectra, MainnetEthSpec};
ssz_tests!(LightClientBootstrapElectra<MainnetEthSpec>);
}
}
Loading
Loading