mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 08:52:54 +00:00
More progress
This commit is contained in:
@@ -7,10 +7,11 @@ use crate::impls::beacon_state::{get_full_state, store_full_state};
|
||||
use crate::iter::{BlockRootsIterator, ParentRootBlockIterator, RootsIterator};
|
||||
use crate::memory_store::MemoryStore;
|
||||
use crate::metadata::{
|
||||
AnchorInfo, BlobInfo, CompactionTimestamp, DataColumnInfo, PruningCheckpoint, SchemaVersion,
|
||||
ANCHOR_FOR_ARCHIVE_NODE, ANCHOR_INFO_KEY, ANCHOR_UNINITIALIZED, BLOB_INFO_KEY,
|
||||
COMPACTION_TIMESTAMP_KEY, CONFIG_KEY, CURRENT_SCHEMA_VERSION, DATA_COLUMN_INFO_KEY,
|
||||
PRUNING_CHECKPOINT_KEY, SCHEMA_VERSION_KEY, SPLIT_KEY, STATE_UPPER_LIMIT_NO_RETAIN,
|
||||
AnchorInfo, BlobInfo, CGCUpdatesStore, CompactionTimestamp, CustodyInfo, DataColumnInfo,
|
||||
PruningCheckpoint, SchemaVersion, ANCHOR_FOR_ARCHIVE_NODE, ANCHOR_INFO_KEY,
|
||||
ANCHOR_UNINITIALIZED, BLOB_INFO_KEY, CGC_UPDATES_KEY, COMPACTION_TIMESTAMP_KEY, CONFIG_KEY,
|
||||
CURRENT_SCHEMA_VERSION, CUSTODY_INFO_KEY, DATA_COLUMN_INFO_KEY, PRUNING_CHECKPOINT_KEY,
|
||||
SCHEMA_VERSION_KEY, SPLIT_KEY, STATE_UPPER_LIMIT_NO_RETAIN,
|
||||
};
|
||||
use crate::state_cache::{PutStateOutcome, StateCache};
|
||||
use crate::{
|
||||
@@ -374,6 +375,14 @@ impl<E: EthSpec> HotColdDB<E, BeaconNodeBackend<E>, BeaconNodeBackend<E>> {
|
||||
if let Some(disk_config) = db.load_config()? {
|
||||
let split = db.get_split_info();
|
||||
let anchor = db.get_anchor_info();
|
||||
// TODO(das): We need to check that the persited columns already in the DB are
|
||||
// compatible with a new PeerID if applicable. We don't want to compare the full PeerId
|
||||
// of the existing DB and the runtime PeerId. Instead we want to assert that the
|
||||
// **sorted** set of columns of the persisted post-peerdas blocks with data is the same
|
||||
// as the runtime sorted set. With validator custody blocks may have more or less
|
||||
// columns. We need to compare the largest set of the non-pruned columns. In a single
|
||||
// runtime the PeerID does not change so all stored blocks are consistent with each
|
||||
// other.
|
||||
db.config
|
||||
.check_compatibility(&disk_config, &split, &anchor)?;
|
||||
|
||||
@@ -2451,6 +2460,30 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
data_column_info.as_kv_store_op(DATA_COLUMN_INFO_KEY)
|
||||
}
|
||||
|
||||
/// Load custody info from disk.
|
||||
pub fn get_custody_info(&self) -> Result<Option<CustodyInfo>, Error> {
|
||||
self.hot_db.get(&CUSTODY_INFO_KEY)
|
||||
}
|
||||
|
||||
/// Store the given `custody_info` to disk.
|
||||
pub fn put_custody_info_in_batch(&self, custody_info: &CustodyInfo) -> Result<(), Error> {
|
||||
let kv_store_op = custody_info.as_kv_store_op(CUSTODY_INFO_KEY);
|
||||
self.hot_db.do_atomically(vec![kv_store_op])
|
||||
}
|
||||
|
||||
/// Load `cgc_updates` from disk.
|
||||
pub fn get_cgc_updates(&self) -> Result<Option<CGCUpdates>, Error> {
|
||||
self.hot_db
|
||||
.get::<CGCUpdatesStore>(&CGC_UPDATES_KEY)
|
||||
.map(|r| r.map(|r| r.value))
|
||||
}
|
||||
|
||||
/// Store the given `cgc_updates` to disk.
|
||||
pub fn put_cgc_updates(&self, cgc_updates: CGCUpdates) -> Result<(), Error> {
|
||||
let kv_store_op = CGCUpdatesStore { value: cgc_updates }.as_kv_store_op(CGC_UPDATES_KEY);
|
||||
self.hot_db.do_atomically(vec![kv_store_op])
|
||||
}
|
||||
|
||||
/// Return the slot-window describing the available historic states.
|
||||
///
|
||||
/// Returns `(lower_limit, upper_limit)`.
|
||||
|
||||
@@ -305,6 +305,8 @@ pub enum DBColumn {
|
||||
ForkChoice,
|
||||
#[strum(serialize = "pkc")]
|
||||
PubkeyCache,
|
||||
#[strum(serialize = "lix")]
|
||||
LocalIndices,
|
||||
/// For the legacy table mapping restore point numbers to state roots.
|
||||
///
|
||||
/// DEPRECATED. Can be removed once schema v22 is buried by a hard fork.
|
||||
@@ -396,6 +398,7 @@ impl DBColumn {
|
||||
| Self::Eth1Cache
|
||||
| Self::ForkChoice
|
||||
| Self::PubkeyCache
|
||||
| Self::LocalIndices
|
||||
| Self::BeaconRestorePoint
|
||||
| Self::DhtEnrs
|
||||
| Self::OptimisticTransitionBlock => 32,
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::{DBColumn, Error, StoreItem};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use types::{Checkpoint, Hash256, Slot};
|
||||
use types::{typenum::U4096, CGCUpdates, Checkpoint, Hash256, Slot, VariableList};
|
||||
|
||||
pub const CURRENT_SCHEMA_VERSION: SchemaVersion = SchemaVersion(22);
|
||||
|
||||
@@ -17,6 +17,8 @@ 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);
|
||||
pub const DATA_COLUMN_INFO_KEY: Hash256 = Hash256::repeat_byte(7);
|
||||
pub const CUSTODY_INFO_KEY: Hash256 = Hash256::repeat_byte(8);
|
||||
pub const CGC_UPDATES_KEY: Hash256 = Hash256::repeat_byte(9);
|
||||
|
||||
/// State upper limit value used to indicate that a node is not storing historic states.
|
||||
pub const STATE_UPPER_LIMIT_NO_RETAIN: Slot = Slot::new(u64::MAX);
|
||||
@@ -246,3 +248,46 @@ impl StoreItem for DataColumnInfo {
|
||||
Ok(Self::from_ssz_bytes(bytes)?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Database parameters relevant to data column sync.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, Serialize, Deserialize)]
|
||||
pub struct CustodyInfo {
|
||||
/// Given a PeerID, compute the set of custody columns with the maximum CGC value, then sort
|
||||
/// them numerically.
|
||||
/// 4096 is a random max limit that will never be reached
|
||||
pub ordered_custody_columns: VariableList<u64, U4096>,
|
||||
}
|
||||
|
||||
impl StoreItem for CustodyInfo {
|
||||
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 data column sync.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, Serialize, Deserialize)]
|
||||
pub struct CGCUpdatesStore {
|
||||
pub value: CGCUpdates,
|
||||
}
|
||||
|
||||
impl StoreItem for CGCUpdatesStore {
|
||||
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)?)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user