Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions beacon_node/beacon_chain/src/schema_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ pub fn migrate_schema<T: BeaconChainTypes>(
db.store_schema_version_atomically(to, ops)
}
(SchemaVersion(26), SchemaVersion(27)) => {
let ops = migration_schema_v27::upgrade_to_v27::<T>(db.clone())?;
db.store_schema_version_atomically(to, ops)
// This migration updates the blobs db. The schema version
// is bumped inside upgrade_to_v27.
migration_schema_v27::upgrade_to_v27::<T>(db.clone())
}
(SchemaVersion(27), SchemaVersion(26)) => {
let ops = migration_schema_v27::downgrade_from_v27::<T>(db.clone())?;
db.store_schema_version_atomically(to, ops)
// Downgrading is essentially a no-op and is only possible
// if peer das isn't scheduled.
migration_schema_v27::downgrade_from_v27::<T>(db.clone())?;
db.store_schema_version_atomically(to, vec![])
}
// Anything else is an error.
(_, _) => Err(HotColdDBError::UnsupportedSchemaVersion {
Expand Down
39 changes: 9 additions & 30 deletions beacon_node/beacon_chain/src/schema_change/migration_schema_v27.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
use crate::BeaconChainTypes;
use ssz::Encode;
use std::sync::Arc;
use store::metadata::DataColumnCustodyInfo;
use store::metadata::DATA_COLUMN_CUSTODY_INFO_KEY;
use store::{DBColumn, Error, HotColdDB, KeyValueStoreOp};
use tracing::info;
use store::{metadata::SchemaVersion, Error, HotColdDB};

/// Add `DataColumnCustodyInfo` entry to v27.
pub fn upgrade_to_v27<T: BeaconChainTypes>(
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
) -> Result<Vec<KeyValueStoreOp>, Error> {
let ops = if db.spec.is_peer_das_scheduled() {
info!("Adding `DataColumnCustodyInfo` to the db");
let data_column_custody_info = DataColumnCustodyInfo {
earliest_data_column_slot: None,
};
vec![KeyValueStoreOp::PutKeyValue(
DBColumn::BeaconDataColumnCustodyInfo,
DATA_COLUMN_CUSTODY_INFO_KEY.as_slice().to_vec(),
data_column_custody_info.as_ssz_bytes(),
)]
} else {
// Delete it from the db if PeerDAS hasn't been scheduled
vec![KeyValueStoreOp::DeleteKey(
DBColumn::BeaconDataColumnCustodyInfo,
DATA_COLUMN_CUSTODY_INFO_KEY.as_slice().to_vec(),
)]
};
) -> Result<(), Error> {
if db.spec.is_peer_das_scheduled() {
db.put_data_column_custody_info(None)?;
db.store_schema_version_atomically(SchemaVersion(27), vec![])?;
}

Ok(ops)
Ok(())
}

pub fn downgrade_from_v27<T: BeaconChainTypes>(
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>,
) -> Result<Vec<KeyValueStoreOp>, Error> {
) -> Result<(), Error> {
if db.spec.is_peer_das_scheduled() {
return Err(Error::MigrationError(
"Cannot downgrade from v27 if peerDAS is scheduled".to_string(),
));
}
let ops = vec![KeyValueStoreOp::DeleteKey(
DBColumn::BeaconDataColumnCustodyInfo,
DATA_COLUMN_CUSTODY_INFO_KEY.as_slice().to_vec(),
)];
Ok(ops)
Ok(())
}
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/validator_custody.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl CustodyContext {
new_custody_group_count: updated_cgc,
sampling_count: self
.num_of_custody_groups_to_sample(Some(effective_epoch), spec),
slot: current_slot,
effective_epoch: current_slot.epoch(E::slots_per_epoch()),
});
}
}
Expand Down Expand Up @@ -288,7 +288,7 @@ impl CustodyContext {
pub struct CustodyCountChanged {
pub new_custody_group_count: u64,
pub sampling_count: u64,
pub slot: Slot,
pub effective_epoch: Epoch,
}

/// The custody information that gets persisted across runs.
Expand Down
10 changes: 10 additions & 0 deletions beacon_node/beacon_chain/tests/schema_stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async fn schema_stability() {
check_metadata_sizes(&store);
check_op_pool(&store);
check_custody_context(&store, &harness.spec);
check_custody_info(&store, &harness.spec);
check_persisted_chain(&store);

// Not covered here:
Expand Down Expand Up @@ -146,6 +147,15 @@ fn check_custody_context(store: &Store<E>, spec: &ChainSpec) {
}
}

fn check_custody_info(store: &Store<E>, spec: &ChainSpec) {
let data_column_custody_info = store.get_data_column_custody_info().unwrap();
if spec.is_peer_das_scheduled() {
assert_eq!(data_column_custody_info.unwrap().as_ssz_bytes().len(), 13);
} else {
assert!(data_column_custody_info.is_none());
}
}

fn check_persisted_chain(store: &Store<E>) {
let chain = store
.get_item::<PersistedBeaconChain>(&Hash256::ZERO)
Expand Down
6 changes: 5 additions & 1 deletion beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3849,7 +3849,11 @@ pub fn serve<T: BeaconChainTypes>(
.advertise_false_custody_group_count
.is_none()
{
chain.update_data_column_custody_info(Some(cgc_change.slot))
chain.update_data_column_custody_info(Some(
cgc_change
.effective_epoch
.start_slot(T::EthSpec::slots_per_epoch()),
))
}
network_tx.send(NetworkMessage::CustodyCountChanged {
new_custody_group_count: cgc_change.new_custody_group_count,
Expand Down
30 changes: 15 additions & 15 deletions beacon_node/network/src/status.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use beacon_chain::{BeaconChain, BeaconChainTypes};
use types::{EthSpec, FixedBytesExtended, Hash256, Slot};
use types::{EthSpec, FixedBytesExtended, Hash256};

use lighthouse_network::rpc::{methods::StatusMessageV2, StatusMessage};
/// Trait to produce a `StatusMessage` representing the state of the given `beacon_chain`.
Expand Down Expand Up @@ -29,21 +29,21 @@ pub(crate) fn status_message<T: BeaconChainTypes>(beacon_chain: &BeaconChain<T>)
finalized_checkpoint.root = Hash256::zero();
}

// If there is no data column custody info in the db, that indicates that
// no recent cgc changes have occurred and no cgc backfill is in progress.
let earliest_available_slot = if let Ok(Some(data_column_custody_info)) =
beacon_chain.store.get_data_column_custody_info()
{
std::cmp::max(
beacon_chain.store.get_anchor_info().oldest_block_slot,
data_column_custody_info
.earliest_data_column_slot
.unwrap_or(Slot::new(0)),
)
} else {
beacon_chain.store.get_anchor_info().oldest_block_slot
};
let earliest_available_data_column_slot = beacon_chain
.store
.get_data_column_custody_info()
.ok()
.flatten()
.and_then(|info| info.earliest_data_column_slot);

// If data_column_custody_info.earliest_data_column_slot is `None`,
// no recent cgc changes have occurred and no cgc backfill is in progress.
let earliest_available_slot =
if let Some(earliest_available_data_column_slot) = earliest_available_data_column_slot {
earliest_available_data_column_slot
} else {
beacon_chain.store.get_anchor_info().oldest_block_slot
};
StatusMessage::V2(StatusMessageV2 {
fork_digest,
finalized_root: finalized_checkpoint.root,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/store/src/hot_cold_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<E: EthSpec> BlockCache<E> {
.get(block_root)
.and_then(|map| map.get(column_index).cloned())
}
pub fn get_data_column_custody_info(&mut self) -> Option<DataColumnCustodyInfo> {
pub fn get_data_column_custody_info(&self) -> Option<DataColumnCustodyInfo> {
self.data_column_custody_info_cache.clone()
}
pub fn delete_block(&mut self, block_root: &Hash256) {
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/store/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ssz::{Decode, Encode};
use ssz_derive::{Decode, Encode};
use types::{Hash256, Slot};

pub const CURRENT_SCHEMA_VERSION: SchemaVersion = SchemaVersion(26);
pub const CURRENT_SCHEMA_VERSION: SchemaVersion = SchemaVersion(27);

// All the keys that get stored under the `BeaconMeta` column.
//
Expand Down
Loading