mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Store changes to persist data columns (#6073)
* Store changes to persist data columns. Co-authored-by: dapplion <35266934+dapplion@users.noreply.github.com> * Update to use `eip7594_fork_epoch` for data column slot in Store. * Fix formatting. * Merge branch 'unstable' into data-columns-store # Conflicts: # beacon_node/store/src/lib.rs # consensus/types/src/chain_spec.rs * Minor refactor. * Merge branch 'unstable' into data-columns-store # Conflicts: # beacon_node/store/src/metrics.rs * Init data colum info at PeerDAS epoch instead of Deneb fork epoch. Address review comments. * Remove Deneb-related comments
This commit is contained in:
@@ -44,6 +44,8 @@ use std::sync::Arc;
|
||||
use strum::{EnumString, IntoStaticStr};
|
||||
pub use types::*;
|
||||
|
||||
const DATA_COLUMN_DB_KEY_SIZE: usize = 32 + 8;
|
||||
|
||||
pub type ColumnIter<'a, K> = Box<dyn Iterator<Item = Result<(K, Vec<u8>), Error>> + 'a>;
|
||||
pub type ColumnKeyIter<'a, K> = Box<dyn Iterator<Item = Result<K, Error>> + 'a>;
|
||||
|
||||
@@ -109,9 +111,7 @@ pub trait KeyValueStore<E: EthSpec>: Sync + Send + Sized + 'static {
|
||||
Box::new(std::iter::empty())
|
||||
}
|
||||
|
||||
fn iter_raw_keys(&self, _column: DBColumn, _prefix: &[u8]) -> RawKeyIter {
|
||||
Box::new(std::iter::empty())
|
||||
}
|
||||
fn iter_raw_keys(&self, column: DBColumn, prefix: &[u8]) -> RawKeyIter;
|
||||
|
||||
/// Iterate through all keys in a particular column.
|
||||
fn iter_column_keys<K: Key>(&self, column: DBColumn) -> ColumnKeyIter<K>;
|
||||
@@ -150,6 +150,28 @@ pub fn get_col_from_key(key: &[u8]) -> Option<String> {
|
||||
String::from_utf8(key[0..3].to_vec()).ok()
|
||||
}
|
||||
|
||||
pub fn get_data_column_key(block_root: &Hash256, column_index: &ColumnIndex) -> Vec<u8> {
|
||||
let mut result = block_root.as_bytes().to_vec();
|
||||
result.extend_from_slice(&column_index.to_le_bytes());
|
||||
result
|
||||
}
|
||||
|
||||
pub fn parse_data_column_key(data: Vec<u8>) -> Result<(Hash256, ColumnIndex), Error> {
|
||||
if data.len() != DBColumn::BeaconDataColumn.key_size() {
|
||||
return Err(Error::InvalidKey);
|
||||
}
|
||||
// split_at panics if 32 < 40 which will never happen after the length check above
|
||||
let (block_root_bytes, column_index_bytes) = data.split_at(32);
|
||||
let block_root = Hash256::from_slice(block_root_bytes);
|
||||
// column_index_bytes is asserted to be 8 bytes after the length check above
|
||||
let column_index = ColumnIndex::from_le_bytes(
|
||||
column_index_bytes
|
||||
.try_into()
|
||||
.map_err(|_| Error::InvalidKey)?,
|
||||
);
|
||||
Ok((block_root, column_index))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
#[derive(Clone)]
|
||||
pub enum KeyValueStoreOp {
|
||||
@@ -210,11 +232,13 @@ pub enum StoreOp<'a, E: EthSpec> {
|
||||
PutBlock(Hash256, Arc<SignedBeaconBlock<E>>),
|
||||
PutState(Hash256, &'a BeaconState<E>),
|
||||
PutBlobs(Hash256, BlobSidecarList<E>),
|
||||
PutDataColumns(Hash256, DataColumnSidecarList<E>),
|
||||
PutStateSummary(Hash256, HotStateSummary),
|
||||
PutStateTemporaryFlag(Hash256),
|
||||
DeleteStateTemporaryFlag(Hash256),
|
||||
DeleteBlock(Hash256),
|
||||
DeleteBlobs(Hash256),
|
||||
DeleteDataColumns(Hash256, Vec<ColumnIndex>),
|
||||
DeleteState(Hash256, Option<Slot>),
|
||||
DeleteExecutionPayload(Hash256),
|
||||
KeyValueOp(KeyValueStoreOp),
|
||||
@@ -230,6 +254,8 @@ pub enum DBColumn {
|
||||
BeaconBlock,
|
||||
#[strum(serialize = "blb")]
|
||||
BeaconBlob,
|
||||
#[strum(serialize = "bdc")]
|
||||
BeaconDataColumn,
|
||||
/// For full `BeaconState`s in the hot database (finalized or fork-boundary states).
|
||||
#[strum(serialize = "ste")]
|
||||
BeaconState,
|
||||
@@ -317,6 +343,7 @@ impl DBColumn {
|
||||
| Self::BeaconHistoricalRoots
|
||||
| Self::BeaconHistoricalSummaries
|
||||
| Self::BeaconRandaoMixes => 8,
|
||||
Self::BeaconDataColumn => DATA_COLUMN_DB_KEY_SIZE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user