mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-29 20:27:14 +00:00
Work in progress block separation
This commit is contained in:
@@ -693,7 +693,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
let root = self.block_root_at_slot(request_slot, skips)?;
|
||||
|
||||
if let Some(block_root) = root {
|
||||
Ok(self.store.get_blinded_block(&block_root)?)
|
||||
Ok(self
|
||||
.store
|
||||
.get_blinded_block(&block_root, Some(request_slot))?)
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
@@ -919,7 +921,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
) -> Result<Option<SignedBeaconBlock<T::EthSpec>>, Error> {
|
||||
// Load block from database, returning immediately if we have the full block w payload
|
||||
// stored.
|
||||
let blinded_block = match self.store.try_get_full_block(block_root)? {
|
||||
let blinded_block = match self.store.try_get_full_block(block_root, None)? {
|
||||
Some(DatabaseBlock::Full(block)) => return Ok(Some(block)),
|
||||
Some(DatabaseBlock::Blinded(block)) => block,
|
||||
None => return Ok(None),
|
||||
@@ -975,7 +977,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
&self,
|
||||
block_root: &Hash256,
|
||||
) -> Result<Option<SignedBlindedBeaconBlock<T::EthSpec>>, Error> {
|
||||
Ok(self.store.get_blinded_block(block_root)?)
|
||||
Ok(self.store.get_blinded_block(block_root, None)?)
|
||||
}
|
||||
|
||||
/// Returns the state at the given root, if any.
|
||||
@@ -4629,7 +4631,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
|
||||
let beacon_block = self
|
||||
.store
|
||||
.get_blinded_block(&beacon_block_root)?
|
||||
.get_blinded_block(&beacon_block_root, None)?
|
||||
.ok_or_else(|| {
|
||||
Error::DBInconsistent(format!("Missing block {}", beacon_block_root))
|
||||
})?;
|
||||
|
||||
@@ -322,7 +322,7 @@ where
|
||||
metrics::inc_counter(&metrics::BALANCES_CACHE_MISSES);
|
||||
let justified_block = self
|
||||
.store
|
||||
.get_blinded_block(&self.justified_checkpoint.root)
|
||||
.get_blinded_block(&self.justified_checkpoint.root, None)
|
||||
.map_err(Error::FailedToReadBlock)?
|
||||
.ok_or(Error::MissingBlock(self.justified_checkpoint.root))?
|
||||
.deconstruct()
|
||||
|
||||
@@ -256,7 +256,7 @@ where
|
||||
.ok_or("Fork choice not found in store")?;
|
||||
|
||||
let genesis_block = store
|
||||
.get_blinded_block(&chain.genesis_block_root)
|
||||
.get_blinded_block(&chain.genesis_block_root, Some(Slot::new(0)))
|
||||
.map_err(|e| descriptive_db_error("genesis block", &e))?
|
||||
.ok_or("Genesis block not found in store")?;
|
||||
let genesis_state = store
|
||||
@@ -618,7 +618,7 @@ where
|
||||
// Try to decode the head block according to the current fork, if that fails, try
|
||||
// to backtrack to before the most recent fork.
|
||||
let (head_block_root, head_block, head_reverted) =
|
||||
match store.get_full_block(&initial_head_block_root) {
|
||||
match store.get_full_block(&initial_head_block_root, None) {
|
||||
Ok(Some(block)) => (initial_head_block_root, block, false),
|
||||
Ok(None) => return Err("Head block not found in store".into()),
|
||||
Err(StoreError::SszDecodeError(_)) => {
|
||||
|
||||
@@ -269,7 +269,7 @@ impl<T: BeaconChainTypes> CanonicalHead<T> {
|
||||
let fork_choice_view = fork_choice.cached_fork_choice_view();
|
||||
let beacon_block_root = fork_choice_view.head_block_root;
|
||||
let beacon_block = store
|
||||
.get_full_block(&beacon_block_root)?
|
||||
.get_full_block(&beacon_block_root, None)?
|
||||
.ok_or(Error::MissingBeaconBlock(beacon_block_root))?;
|
||||
let beacon_state_root = beacon_block.state_root();
|
||||
let beacon_state = store
|
||||
@@ -639,7 +639,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.unwrap_or_else(|| {
|
||||
let beacon_block = self
|
||||
.store
|
||||
.get_full_block(&new_view.head_block_root)?
|
||||
.get_full_block(&new_view.head_block_root, None)?
|
||||
.ok_or(Error::MissingBeaconBlock(new_view.head_block_root))?;
|
||||
|
||||
let beacon_state_root = beacon_block.state_root();
|
||||
|
||||
@@ -107,7 +107,7 @@ pub fn reset_fork_choice_to_finalization<E: EthSpec, Hot: ItemStore<E>, Cold: It
|
||||
let finalized_checkpoint = head_state.finalized_checkpoint();
|
||||
let finalized_block_root = finalized_checkpoint.root;
|
||||
let finalized_block = store
|
||||
.get_full_block(&finalized_block_root)
|
||||
.get_full_block(&finalized_block_root, None)
|
||||
.map_err(|e| format!("Error loading finalized block: {:?}", e))?
|
||||
.ok_or_else(|| {
|
||||
format!(
|
||||
|
||||
@@ -93,7 +93,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
ChunkWriter::<BlockRoots, _, _>::new(&self.store.cold_db, prev_block_slot.as_usize())?;
|
||||
|
||||
let mut cold_batch = Vec::with_capacity(blocks.len());
|
||||
let mut hot_batch = Vec::with_capacity(blocks.len());
|
||||
|
||||
for block in blocks_to_import.iter().rev() {
|
||||
// Check chain integrity.
|
||||
@@ -109,7 +108,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
|
||||
// Store block in the hot database without payload.
|
||||
self.store
|
||||
.blinded_block_as_kv_store_ops(&block_root, block, &mut hot_batch);
|
||||
.blinded_block_as_cold_kv_store_ops(&block_root, block, &mut cold_batch);
|
||||
|
||||
// Store block roots, including at all skip slots in the freezer DB.
|
||||
for slot in (block.slot().as_usize()..prev_block_slot.as_usize()).rev() {
|
||||
@@ -177,10 +176,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
drop(verify_timer);
|
||||
drop(sig_timer);
|
||||
|
||||
// Write the I/O batches to disk, writing the blocks themselves first, as it's better
|
||||
// for the hot DB to contain extra blocks than for the cold DB to point to blocks that
|
||||
// do not exist.
|
||||
self.store.hot_db.do_atomically(hot_batch)?;
|
||||
// Write the I/O batch to disk.
|
||||
self.store.cold_db.do_atomically(cold_batch)?;
|
||||
|
||||
// Update the anchor.
|
||||
|
||||
@@ -424,7 +424,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
|
||||
// so delete it from the head tracker but leave it and its states in the database
|
||||
// This is suboptimal as it wastes disk space, but it's difficult to fix. A re-sync
|
||||
// can be used to reclaim the space.
|
||||
let head_state_root = match store.get_blinded_block(&head_hash) {
|
||||
let head_state_root = match store.get_blinded_block(&head_hash, Some(head_slot)) {
|
||||
Ok(Some(block)) => block.state_root(),
|
||||
Ok(None) => {
|
||||
return Err(BeaconStateError::MissingBeaconBlock(head_hash.into()).into())
|
||||
|
||||
@@ -71,7 +71,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
}
|
||||
|
||||
// 2. Check on disk.
|
||||
if self.store.get_blinded_block(&block_root)?.is_some() {
|
||||
if self.store.get_blinded_block(&block_root, None)?.is_some() {
|
||||
cache.block_roots.put(block_root, ());
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ pub fn upgrade_to_v12<T: BeaconChainTypes>(
|
||||
.unrealized_justified_checkpoint
|
||||
.root;
|
||||
let justified_block = db
|
||||
.get_blinded_block(&justified_block_root)?
|
||||
.get_blinded_block(&justified_block_root, None)?
|
||||
.ok_or_else(|| {
|
||||
Error::SchemaMigrationError(format!(
|
||||
"unrealized justified block missing for migration: {justified_block_root:?}",
|
||||
|
||||
@@ -91,7 +91,7 @@ pub fn upgrade_to_v9<T: BeaconChainTypes>(
|
||||
Ok(None) => return Err(Error::BlockNotFound(block_root)),
|
||||
// There was an error reading a pre-v9 block. Try reading it as a post-v9 block.
|
||||
Err(_) => {
|
||||
if db.try_get_full_block(&block_root)?.is_some() {
|
||||
if db.try_get_full_block(&block_root, None)?.is_some() {
|
||||
// The block is present as a post-v9 block, assume that it was already
|
||||
// correctly migrated.
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user