Assert DB compatibility

This commit is contained in:
dapplion
2025-04-04 18:32:19 -03:00
parent f6fa2380c7
commit 2384e9659b
6 changed files with 143 additions and 45 deletions

View File

@@ -2466,7 +2466,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
}
/// Store the given `custody_info` to disk.
pub fn put_custody_info_in_batch(&self, custody_info: &CustodyInfo) -> Result<(), Error> {
pub fn put_custody_info(&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])
}

View File

@@ -2,7 +2,7 @@ use crate::{DBColumn, Error, StoreItem};
use serde::{Deserialize, Serialize};
use ssz::{Decode, Encode};
use ssz_derive::{Decode, Encode};
use types::{typenum::U4096, CGCUpdates, Checkpoint, Hash256, Slot, VariableList};
use types::{typenum::U4096, CGCUpdates, ChainSpec, Checkpoint, Hash256, Slot, VariableList};
pub const CURRENT_SCHEMA_VERSION: SchemaVersion = SchemaVersion(22);
@@ -252,10 +252,29 @@ impl StoreItem for DataColumnInfo {
/// 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.
/// Given a PeerID, compute the custody groups for the maximum CGC value.
///
/// 4096 is a random max limit that will never be reached
pub ordered_custody_columns: VariableList<u64, U4096>,
custody_groups_max_cgc: VariableList<u64, U4096>,
}
impl CustodyInfo {
pub fn new(custody_groups_max_cgc: &[u64], spec: &ChainSpec) -> Result<Self, String> {
if custody_groups_max_cgc.len() != spec.number_of_custody_groups as usize {
return Err(format!(
"custody_groups_max_cgc {} len != number_of_custody_groups",
custody_groups_max_cgc.len()
));
}
Ok(Self {
custody_groups_max_cgc: VariableList::new(custody_groups_max_cgc.to_vec())
.map_err(|e| format!("Max CGC > 4096: {e:?}"))?,
})
}
pub fn custody_groups_for_cgc(&self, cgc: u64) -> &[u64] {
&self.custody_groups_max_cgc[..self.custody_groups_max_cgc.len().min(cgc as usize)]
}
}
impl StoreItem for CustodyInfo {