## Issue Addressed Synchronize dependencies and edition on the workspace `Cargo.toml` ## Proposed Changes with https://github.com/rust-lang/cargo/issues/8415 merged it's now possible to synchronize details on the workspace `Cargo.toml` like the metadata and dependencies. By only having dependencies that are shared between multiple crates aligned on the workspace `Cargo.toml` it's easier to not miss duplicate versions of the same dependency and therefore ease on the compile times. ## Additional Info this PR also removes the no longer required direct dependency of the `serde_derive` crate. should be reviewed after https://github.com/sigp/lighthouse/pull/4639 get's merged. closes https://github.com/sigp/lighthouse/issues/4651 Co-authored-by: Michael Sproul <michael@sigmaprime.io> Co-authored-by: Michael Sproul <micsproul@gmail.com>
60 lines
1.9 KiB
Rust
60 lines
1.9 KiB
Rust
use serde::Serialize;
|
|
use std::sync::Arc;
|
|
use types::{
|
|
beacon_state::CloneConfig, AbstractExecPayload, BeaconState, EthSpec, FullPayload, 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)]
|
|
pub struct BeaconSnapshot<E: EthSpec, Payload: AbstractExecPayload<E> = FullPayload<E>> {
|
|
pub beacon_block: Arc<SignedBeaconBlock<E, Payload>>,
|
|
pub beacon_block_root: Hash256,
|
|
pub beacon_state: BeaconState<E>,
|
|
}
|
|
|
|
impl<E: EthSpec, Payload: AbstractExecPayload<E>> BeaconSnapshot<E, Payload> {
|
|
/// Create a new checkpoint.
|
|
pub fn new(
|
|
beacon_block: Arc<SignedBeaconBlock<E, Payload>>,
|
|
beacon_block_root: Hash256,
|
|
beacon_state: BeaconState<E>,
|
|
) -> Self {
|
|
Self {
|
|
beacon_block,
|
|
beacon_block_root,
|
|
beacon_state,
|
|
}
|
|
}
|
|
|
|
/// Returns the state root from `self.beacon_block`.
|
|
///
|
|
/// ## Caution
|
|
///
|
|
/// It is not strictly enforced that `root(self.beacon_state) == self.beacon_state_root()`.
|
|
pub fn beacon_state_root(&self) -> Hash256 {
|
|
self.beacon_block.message().state_root()
|
|
}
|
|
|
|
/// Update all fields of the checkpoint.
|
|
pub fn update(
|
|
&mut self,
|
|
beacon_block: Arc<SignedBeaconBlock<E, Payload>>,
|
|
beacon_block_root: Hash256,
|
|
beacon_state: BeaconState<E>,
|
|
) {
|
|
self.beacon_block = beacon_block;
|
|
self.beacon_block_root = beacon_block_root;
|
|
self.beacon_state = beacon_state;
|
|
}
|
|
|
|
pub fn clone_with(&self, clone_config: CloneConfig) -> Self {
|
|
Self {
|
|
beacon_block: self.beacon_block.clone(),
|
|
beacon_block_root: self.beacon_block_root,
|
|
beacon_state: self.beacon_state.clone_with(clone_config),
|
|
}
|
|
}
|
|
}
|