mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Fix electra light client types (#6361)
* persist light client updates * update beacon chain to serve light client updates * resolve todos * cache best update * extend cache parts * is better light client update * resolve merge conflict * initial api changes * add lc update db column * fmt * added tests * add sim * Merge branch 'unstable' of https://github.com/sigp/lighthouse into persist-light-client-updates * fix some weird issues with the simulator * tests * Merge branch 'unstable' of https://github.com/sigp/lighthouse into persist-light-client-updates * test changes * merge conflict * testing * started work on ef tests and some code clean up * update tests * linting * noop pre altair, were still failing on electra though * allow for zeroed light client header * Merge branch 'unstable' of https://github.com/sigp/lighthouse into persist-light-client-updates * merge unstable * remove unwraps * remove unwraps * fetch bootstrap without always querying for state * storing bootstrap parts in db * mroe code cleanup * test * prune sync committee branches from dropped chains * Update light_client_update.rs * merge unstable * move functionality to helper methods * refactor is best update fn * refactor is best update fn * improve organization of light client server cache logic * fork diget calc, and only spawn as many blcoks as we need for the lc update test * resovle merge conflict * add electra bootstrap logic, add logic to cache current sync committee * add latest sync committe branch cache * fetch lc update from the cache if it exists * fmt * Fix beacon_chain tests * Add debug code to update ranking_order ef test * Fix compare code * merge conflicts * merge conflict * add better error messaging * resolve merge conflicts * remove lc update from basicsim * rename sync comittte variable and fix persist condition * refactor get_light_client_update logic * add better comments, return helpful error messages over http and rpc * pruning canonical non checkpoint slots * fix test * rerun test * update pruning logic, add tests * fix tests * fix imports * fmt * refactor db code * Refactor db method * Refactor db method * lc electra changes * Merge branch 'unstable' of https://github.com/sigp/lighthouse into light-client-electra * add additional comments * testing lc merkle changes * lc electra * update struct defs * Merge branch 'unstable' of https://github.com/sigp/lighthouse into light-client-electra * fix merge * Merge branch 'unstable' of https://github.com/sigp/lighthouse into persist-light-client-bootstrap * fix merge * linting * merge conflict * prevent overflow * enable lc server for http api tests * Merge branch 'unstable' of https://github.com/sigp/lighthouse into light-client-electra * get tests working: * remove related TODOs * fix test lint * Merge branch 'persist-light-client-bootstrap' of https://github.com/eserilev/lighthouse into light-client-electra * fix tests * fix conflicts * remove prints * Merge branch 'persist-light-client-bootstrap' of https://github.com/eserilev/lighthouse into light-client-electra * remove warning * resolve conflicts * merge conflicts * linting * remove comments * cleanup * linting * Merge branch 'unstable' of https://github.com/sigp/lighthouse into light-client-electra * pre/post electra light client cached data * add proof type alias * move is_empty_branch method out of impl * add ssz tests for all forks * refactor beacon state proof codepaths * rename method * fmt * clean up proof logic * refactor merkle proof api * fmt * Merge branch 'unstable' into light-client-electra * Use superstruct mapping macros * Merge branch 'unstable' of https://github.com/sigp/lighthouse into light-client-electra * rename proof to merkleproof * fmt * Resolve merge conflicts * merge conflicts
This commit is contained in:
@@ -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
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -413,16 +404,12 @@ 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,
|
||||
@@ -430,17 +417,18 @@ struct LightClientCachedData<E: EthSpec> {
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user