Skip to content

Commit f020adb

Browse files
committed
Store latest_block_slot in state summary
1 parent ecb647f commit f020adb

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

beacon_node/beacon_chain/src/migrate.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::errors::BeaconChainError;
2-
use crate::summaries_dag::{DAGStateSummaryV22, Error as SummariesDagError, StateSummariesDAG};
2+
use crate::summaries_dag::{DAGStateSummary, Error as SummariesDagError, StateSummariesDAG};
33
use parking_lot::Mutex;
44
use slog::{debug, error, info, warn, Logger};
55
use std::collections::HashSet;
@@ -490,40 +490,31 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
490490
.load_hot_state_summaries()?
491491
.into_iter()
492492
.map(|(state_root, summary)| {
493-
let block_root = summary.latest_block_root;
494-
// This error should never happen unless we break a DB invariant
495-
let block = store
496-
.get_blinded_block(&block_root)?
497-
.ok_or(PruningError::MissingBlindedBlock(block_root))?;
498-
Ok((
493+
(
499494
state_root,
500-
DAGStateSummaryV22 {
495+
DAGStateSummary {
501496
slot: summary.slot,
502497
latest_block_root: summary.latest_block_root,
503-
block_slot: block.slot(),
504-
block_parent_root: block.parent_root(),
498+
latest_block_slot: summary.latest_block_slot,
499+
previous_state_root: summary.previous_state_root,
505500
},
506-
))
501+
)
507502
})
508-
.collect::<Result<Vec<(Hash256, DAGStateSummaryV22)>, BeaconChainError>>()?;
509-
510-
// De-duplicate block roots to reduce block reads below
511-
let summary_block_roots = HashSet::<Hash256>::from_iter(
512-
state_summaries
513-
.iter()
514-
.map(|(_, summary)| summary.latest_block_root),
515-
);
503+
.collect::<Vec<(Hash256, DAGStateSummary)>>();
516504

517505
// Sanity check, there is at least one summary with the new finalized block root
518-
if !summary_block_roots.contains(&new_finalized_checkpoint.root) {
506+
if !state_summaries
507+
.iter()
508+
.any(|(_, s)| s.latest_block_root == new_finalized_checkpoint.root)
509+
{
519510
return Err(BeaconChainError::PruningError(
520511
PruningError::MissingSummaryForFinalizedCheckpoint(
521512
new_finalized_checkpoint.root,
522513
),
523514
));
524515
}
525516

526-
StateSummariesDAG::new_from_v22(state_summaries)
517+
StateSummariesDAG::new(state_summaries)
527518
.map_err(|e| PruningError::SummariesDagError("new StateSumariesDAG", e))?
528519
};
529520

beacon_node/beacon_chain/src/schema_change/migration_schema_v24.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ pub fn upgrade_to_v24<T: BeaconChainTypes>(
172172
// blocks.
173173
//
174174
// 2. Convert the summary to the new format.
175-
let latest_block_root = old_summary.latest_block_root;
176175
let previous_state_root = if state_root == split.state_root {
177176
Hash256::ZERO
178177
} else {
@@ -203,7 +202,8 @@ pub fn upgrade_to_v24<T: BeaconChainTypes>(
203202

204203
let new_summary = HotStateSummary {
205204
slot,
206-
latest_block_root,
205+
latest_block_root: old_summary.latest_block_root,
206+
latest_block_slot: old_summary.latest_block_slot,
207207
previous_state_root,
208208
diff_base_state_root,
209209
};

beacon_node/store/src/hot_cold_store.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3501,6 +3501,7 @@ fn get_ancenstor_state_root<'a, E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E
35013501
pub struct HotStateSummary {
35023502
pub slot: Slot,
35033503
pub latest_block_root: Hash256,
3504+
pub latest_block_slot: Slot,
35043505
// FIXME(tree-states): consider not storing the storage strategy and storing a state root instead
35053506
pub diff_base_state_root: DiffBaseStateRoot,
35063507
// FIXME(tree-states): should add this as part of this migration
@@ -3583,6 +3584,7 @@ impl HotStateSummary {
35833584
Ok(HotStateSummary {
35843585
slot: state.slot(),
35853586
latest_block_root,
3587+
latest_block_slot: state.latest_block_header().slot,
35863588
diff_base_state_root,
35873589
// Note: if genesis state, it will point to its own state root
35883590
previous_state_root: get_state_root(state.slot().saturating_sub(1_u64))?,

0 commit comments

Comments
 (0)