2019-02-14 01:09:18 +00:00
|
|
|
use serde_derive::Serialize;
|
2019-05-27 06:13:32 +00:00
|
|
|
use ssz_derive::{Decode, Encode};
|
2020-02-10 23:19:36 +00:00
|
|
|
use types::{BeaconState, EthSpec, Hash256, SignedBeaconBlock};
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2020-02-10 23:19:36 +00:00
|
|
|
/// Represents some block and its associated state. Generally, this will be used for tracking the
|
2019-02-14 01:09:18 +00:00
|
|
|
/// head, justified head and finalized head.
|
2019-05-27 06:13:32 +00:00
|
|
|
#[derive(Clone, Serialize, PartialEq, Debug, Encode, Decode)]
|
2020-04-06 00:53:33 +00:00
|
|
|
pub struct BeaconSnapshot<E: EthSpec> {
|
2020-02-10 23:19:36 +00:00
|
|
|
pub beacon_block: SignedBeaconBlock<E>,
|
2019-02-14 01:09:18 +00:00
|
|
|
pub beacon_block_root: Hash256,
|
2019-05-13 04:44:43 +00:00
|
|
|
pub beacon_state: BeaconState<E>,
|
2019-02-14 01:09:18 +00:00
|
|
|
pub beacon_state_root: Hash256,
|
|
|
|
}
|
|
|
|
|
2020-04-06 00:53:33 +00:00
|
|
|
impl<E: EthSpec> BeaconSnapshot<E> {
|
2019-02-14 01:09:18 +00:00
|
|
|
/// Create a new checkpoint.
|
|
|
|
pub fn new(
|
2020-02-10 23:19:36 +00:00
|
|
|
beacon_block: SignedBeaconBlock<E>,
|
2019-02-14 01:09:18 +00:00
|
|
|
beacon_block_root: Hash256,
|
2019-05-13 04:44:43 +00:00
|
|
|
beacon_state: BeaconState<E>,
|
2019-02-14 01:09:18 +00:00
|
|
|
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,
|
2020-02-10 23:19:36 +00:00
|
|
|
beacon_block: SignedBeaconBlock<E>,
|
2019-02-14 01:09:18 +00:00
|
|
|
beacon_block_root: Hash256,
|
2019-05-13 04:44:43 +00:00
|
|
|
beacon_state: BeaconState<E>,
|
2019-02-14 01:09:18 +00:00
|
|
|
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;
|
|
|
|
}
|
2020-02-04 01:43:04 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|