mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-11 18:04:18 +00:00
# Conflicts: # .github/workflows/docker.yml # .github/workflows/local-testnet.yml # .github/workflows/test-suite.yml # Cargo.lock # Cargo.toml # beacon_node/beacon_chain/src/beacon_chain.rs # beacon_node/beacon_chain/src/builder.rs # beacon_node/beacon_chain/src/test_utils.rs # beacon_node/execution_layer/src/engine_api/json_structures.rs # beacon_node/network/src/beacon_processor/mod.rs # beacon_node/network/src/beacon_processor/worker/gossip_methods.rs # beacon_node/network/src/sync/backfill_sync/mod.rs # beacon_node/store/src/config.rs # beacon_node/store/src/hot_cold_store.rs # common/eth2_network_config/Cargo.toml # consensus/ssz/src/decode/impls.rs # consensus/ssz_derive/src/lib.rs # consensus/ssz_derive/tests/tests.rs # consensus/ssz_types/src/serde_utils/mod.rs # consensus/tree_hash/src/impls.rs # consensus/tree_hash/src/lib.rs # consensus/types/Cargo.toml # consensus/types/src/beacon_state.rs # consensus/types/src/chain_spec.rs # consensus/types/src/eth_spec.rs # consensus/types/src/fork_name.rs # lcli/Cargo.toml # lcli/src/main.rs # lcli/src/new_testnet.rs # scripts/local_testnet/el_bootnode.sh # scripts/local_testnet/genesis.json # scripts/local_testnet/geth.sh # scripts/local_testnet/setup.sh # scripts/local_testnet/start_local_testnet.sh # scripts/local_testnet/vars.env # scripts/tests/doppelganger_protection.sh # scripts/tests/genesis.json # scripts/tests/vars.env # testing/ef_tests/Cargo.toml # validator_client/src/block_service.rs
146 lines
4.2 KiB
Rust
146 lines
4.2 KiB
Rust
use crate::{DBColumn, Error, StoreItem};
|
|
use serde_derive::{Deserialize, Serialize};
|
|
use ssz::{Decode, Encode};
|
|
use ssz_derive::{Decode, Encode};
|
|
use types::{Checkpoint, Hash256, Slot};
|
|
|
|
pub const CURRENT_SCHEMA_VERSION: SchemaVersion = SchemaVersion(17);
|
|
|
|
// All the keys that get stored under the `BeaconMeta` column.
|
|
//
|
|
// We use `repeat_byte` because it's a const fn.
|
|
pub const SCHEMA_VERSION_KEY: Hash256 = Hash256::repeat_byte(0);
|
|
pub const CONFIG_KEY: Hash256 = Hash256::repeat_byte(1);
|
|
pub const SPLIT_KEY: Hash256 = Hash256::repeat_byte(2);
|
|
pub const PRUNING_CHECKPOINT_KEY: Hash256 = Hash256::repeat_byte(3);
|
|
pub const COMPACTION_TIMESTAMP_KEY: Hash256 = Hash256::repeat_byte(4);
|
|
pub const ANCHOR_INFO_KEY: Hash256 = Hash256::repeat_byte(5);
|
|
pub const BLOB_INFO_KEY: Hash256 = Hash256::repeat_byte(6);
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
|
pub struct SchemaVersion(pub u64);
|
|
|
|
impl SchemaVersion {
|
|
pub fn as_u64(self) -> u64 {
|
|
self.0
|
|
}
|
|
}
|
|
|
|
impl StoreItem for SchemaVersion {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::BeaconMeta
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
self.0.as_ssz_bytes()
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
|
Ok(SchemaVersion(u64::from_ssz_bytes(bytes)?))
|
|
}
|
|
}
|
|
|
|
/// The checkpoint used for pruning the database.
|
|
///
|
|
/// Updated whenever pruning is successful.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub struct PruningCheckpoint {
|
|
pub checkpoint: Checkpoint,
|
|
}
|
|
|
|
impl StoreItem for PruningCheckpoint {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::BeaconMeta
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
self.checkpoint.as_ssz_bytes()
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
|
Ok(PruningCheckpoint {
|
|
checkpoint: Checkpoint::from_ssz_bytes(bytes)?,
|
|
})
|
|
}
|
|
}
|
|
|
|
/// The last time the database was compacted.
|
|
pub struct CompactionTimestamp(pub u64);
|
|
|
|
impl StoreItem for CompactionTimestamp {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::BeaconMeta
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
self.0.as_ssz_bytes()
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
|
Ok(CompactionTimestamp(u64::from_ssz_bytes(bytes)?))
|
|
}
|
|
}
|
|
|
|
/// Database parameters relevant to weak subjectivity sync.
|
|
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, Serialize, Deserialize)]
|
|
pub struct AnchorInfo {
|
|
/// The slot at which the anchor state is present and which we cannot revert.
|
|
pub anchor_slot: Slot,
|
|
/// The slot from which historical blocks are available (>=).
|
|
pub oldest_block_slot: Slot,
|
|
/// The block root of the next block that needs to be added to fill in the history.
|
|
///
|
|
/// Zero if we know all blocks back to genesis.
|
|
pub oldest_block_parent: Hash256,
|
|
/// The slot from which historical states are available (>=).
|
|
pub state_upper_limit: Slot,
|
|
/// The slot before which historical states are available (<=).
|
|
pub state_lower_limit: Slot,
|
|
}
|
|
|
|
impl AnchorInfo {
|
|
/// Returns true if the block backfill has completed.
|
|
/// This is a comparison between the oldest block slot and the target backfill slot (which is
|
|
/// likely to be the closest WSP).
|
|
pub fn block_backfill_complete(&self, target_slot: Slot) -> bool {
|
|
self.oldest_block_slot <= target_slot
|
|
}
|
|
}
|
|
|
|
impl StoreItem for AnchorInfo {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::BeaconMeta
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
self.as_ssz_bytes()
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
|
Ok(Self::from_ssz_bytes(bytes)?)
|
|
}
|
|
}
|
|
|
|
/// Database parameters relevant to blob sync.
|
|
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, Serialize, Deserialize, Default)]
|
|
pub struct BlobInfo {
|
|
/// The slot after which blobs are available (>=).
|
|
pub oldest_blob_slot: Option<Slot>,
|
|
/// A separate blobs database is in use.
|
|
pub blobs_db: bool,
|
|
}
|
|
|
|
impl StoreItem for BlobInfo {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::BeaconMeta
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
self.as_ssz_bytes()
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
|
Ok(Self::from_ssz_bytes(bytes)?)
|
|
}
|
|
}
|