Skip to content

Commit bb23f2a

Browse files
committed
Add a new test and fix split loading
1 parent 6094e23 commit bb23f2a

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

beacon_node/beacon_chain/tests/store_tests.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,6 +3679,68 @@ async fn ancestor_state_root_prior_to_split() {
36793679
assert_ne!(store.get_split_slot(), 0);
36803680
}
36813681

3682+
// Test that the chain operates correctly when the split state is stored as a ReplayFrom.
3683+
#[tokio::test]
3684+
async fn replay_from_split_state() {
3685+
let db_path = tempdir().unwrap();
3686+
3687+
let spec = test_spec::<E>();
3688+
3689+
let store_config = StoreConfig {
3690+
prune_payloads: false,
3691+
hierarchy_config: HierarchyConfig::from_str("5").unwrap(),
3692+
..StoreConfig::default()
3693+
};
3694+
let chain_config = ChainConfig {
3695+
reconstruct_historic_states: false,
3696+
..ChainConfig::default()
3697+
};
3698+
let import_all_data_columns = false;
3699+
3700+
let store = get_store_generic(&db_path, store_config.clone(), spec.clone());
3701+
let harness = get_harness_generic(
3702+
store.clone(),
3703+
LOW_VALIDATOR_COUNT,
3704+
chain_config,
3705+
import_all_data_columns,
3706+
);
3707+
3708+
// Produce blocks until we finalize epoch 3 which will not be stored as a snapshot.
3709+
let num_blocks = 5 * E::slots_per_epoch() as usize;
3710+
3711+
harness
3712+
.extend_chain(
3713+
num_blocks,
3714+
BlockStrategy::OnCanonicalHead,
3715+
AttestationStrategy::AllValidators,
3716+
)
3717+
.await;
3718+
3719+
let split = store.get_split_info();
3720+
let anchor_slot = store.get_anchor_info().anchor_slot;
3721+
assert_eq!(split.slot, 3 * E::slots_per_epoch());
3722+
assert_eq!(anchor_slot, 0);
3723+
assert!(store
3724+
.hierarchy
3725+
.storage_strategy(split.slot, anchor_slot)
3726+
.unwrap()
3727+
.is_replay_from());
3728+
3729+
// Close the database and reopen it.
3730+
drop(store);
3731+
drop(harness);
3732+
3733+
let store = get_store_generic(&db_path, store_config, spec);
3734+
3735+
// Check that the split state is still accessible.
3736+
assert_eq!(store.get_split_slot(), split.slot);
3737+
let state = store
3738+
.get_hot_state(&split.state_root, false)
3739+
.unwrap()
3740+
.expect("split state should be present");
3741+
assert_eq!(state.slot(), split.slot);
3742+
}
3743+
36823744
/// Checks that two chains are the same, for the purpose of these tests.
36833745
///
36843746
/// Several fields that are hard/impossible to check are ignored (e.g., the store).

beacon_node/store/src/hot_cold_store.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
27692769
// Load the hot state summary to get the block root.
27702770
let latest_block_root = self
27712771
.load_block_root_from_summary_any_version(&split.state_root)
2772-
.map_err(|e| Error::LoadHotStateSummaryForSplit(e.into()))?
27732772
.ok_or(HotColdDBError::MissingSplitState(
27742773
split.state_root,
27752774
split.slot,
@@ -2820,13 +2819,14 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
28202819
pub fn load_block_root_from_summary_any_version(
28212820
&self,
28222821
state_root: &Hash256,
2823-
) -> Result<Option<Hash256>, Error> {
2824-
self.load_hot_state_summary(state_root)
2825-
.map(|opt_summary| opt_summary.map(|summary| summary.latest_block_root))
2826-
.or_else(|_| {
2827-
self.load_hot_state_summary_v22(state_root)
2828-
.map(|opt_summary| opt_summary.map(|summary| summary.latest_block_root))
2829-
})
2822+
) -> Option<Hash256> {
2823+
if let Ok(Some(summary)) = self.load_hot_state_summary(state_root) {
2824+
return Some(summary.latest_block_root);
2825+
}
2826+
if let Ok(Some(summary)) = self.load_hot_state_summary_v22(state_root) {
2827+
return Some(summary.latest_block_root);
2828+
}
2829+
None
28302830
}
28312831

28322832
/// Load all hot state summaries present in the hot DB

0 commit comments

Comments
 (0)