From e373e9a1077b2b67ea6b9e69c8bee194d40dcde8 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 9 Aug 2023 19:42:14 +1000 Subject: [PATCH] Fix genesis state storage for genesis sync (#4589) --- beacon_node/beacon_chain/src/builder.rs | 7 ++++--- beacon_node/store/src/hot_cold_store.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/beacon_node/beacon_chain/src/builder.rs b/beacon_node/beacon_chain/src/builder.rs index fe72a1e964d..8aaa1b918e7 100644 --- a/beacon_node/beacon_chain/src/builder.rs +++ b/beacon_node/beacon_chain/src/builder.rs @@ -337,12 +337,13 @@ where .build_caches(&self.spec) .map_err(|e| format!("Failed to build genesis state caches: {:?}", e))?; - store - .update_finalized_state(beacon_state_root, beacon_block_root, beacon_state.clone()) - .map_err(|e| format!("Failed to set genesis state as finalized state: {:?}", e))?; + info!(store.log, "Storing genesis state"; "state_root" => ?beacon_state_root); store .put_state(&beacon_state_root, &beacon_state) .map_err(|e| format!("Failed to store genesis state: {:?}", e))?; + store + .update_finalized_state(beacon_state_root, beacon_block_root, beacon_state.clone()) + .map_err(|e| format!("Failed to set genesis state as finalized state: {:?}", e))?; // Store the genesis block's execution payload (if any) in the hot database. if let Some(execution_payload) = &payload { diff --git a/beacon_node/store/src/hot_cold_store.rs b/beacon_node/store/src/hot_cold_store.rs index 190f10064ac..7321722a746 100644 --- a/beacon_node/store/src/hot_cold_store.rs +++ b/beacon_node/store/src/hot_cold_store.rs @@ -939,6 +939,11 @@ impl, Cold: ItemStore> HotColdDB .lock() .put_state(*state_root, block_root, state)? { + debug!( + self.log, + "Skipping storage of cached state"; + "slot" => state.slot() + ); return Ok(()); } @@ -1119,7 +1124,7 @@ impl, Cold: ItemStore> HotColdDB // If the prior state is the split state and it isn't cached then load it in // entirety from disk. This should only happen on first start up. - if prior_state_root == split_read_lock.state_root { + if prior_state_root == split_read_lock.state_root || prior_summary.slot == 0 { debug!( self.log, "Using split state as base state for replay"; @@ -1317,7 +1322,8 @@ impl, Cold: ItemStore> HotColdDB if slot >= split.slot { Ok(state_root == split.state_root - || self.spec.fork_activated_at_slot::(slot).is_some()) + || self.spec.fork_activated_at_slot::(slot).is_some() + || slot == 0) } else { Err(Error::SlotIsBeforeSplit { slot }) }