mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
* Add state cache, remove store cache * Only build the head committee cache * Fix compile error * Fix compile error from merge * Rename state_cache -> checkpoint_cache * Rename Checkpoint -> Snapshot * Tidy, add comments * Tidy up find_head function * Change some checkpoint -> snapshot * Add tests * Expose max_len * Remove dead code * Tidy * Fix bug
54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
use serde_derive::Serialize;
|
|
use ssz_derive::{Decode, Encode};
|
|
use types::{BeaconState, EthSpec, Hash256, SignedBeaconBlock};
|
|
|
|
/// Represents some block and its associated state. Generally, this will be used for tracking the
|
|
/// head, justified head and finalized head.
|
|
#[derive(Clone, Serialize, PartialEq, Debug, Encode, Decode)]
|
|
pub struct BeaconSnapshot<E: EthSpec> {
|
|
pub beacon_block: SignedBeaconBlock<E>,
|
|
pub beacon_block_root: Hash256,
|
|
pub beacon_state: BeaconState<E>,
|
|
pub beacon_state_root: Hash256,
|
|
}
|
|
|
|
impl<E: EthSpec> BeaconSnapshot<E> {
|
|
/// Create a new checkpoint.
|
|
pub fn new(
|
|
beacon_block: SignedBeaconBlock<E>,
|
|
beacon_block_root: Hash256,
|
|
beacon_state: BeaconState<E>,
|
|
beacon_state_root: Hash256,
|
|
) -> Self {
|
|
Self {
|
|
beacon_block,
|
|
beacon_block_root,
|
|
beacon_state,
|
|
beacon_state_root,
|
|
}
|
|
}
|
|
|
|
/// Update all fields of the checkpoint.
|
|
pub fn update(
|
|
&mut self,
|
|
beacon_block: SignedBeaconBlock<E>,
|
|
beacon_block_root: Hash256,
|
|
beacon_state: BeaconState<E>,
|
|
beacon_state_root: Hash256,
|
|
) {
|
|
self.beacon_block = beacon_block;
|
|
self.beacon_block_root = beacon_block_root;
|
|
self.beacon_state = beacon_state;
|
|
self.beacon_state_root = beacon_state_root;
|
|
}
|
|
|
|
pub fn clone_with_only_committee_caches(&self) -> Self {
|
|
Self {
|
|
beacon_block: self.beacon_block.clone(),
|
|
beacon_block_root: self.beacon_block_root,
|
|
beacon_state: self.beacon_state.clone_with_only_committee_caches(),
|
|
beacon_state_root: self.beacon_state_root,
|
|
}
|
|
}
|
|
}
|