@@ -158,7 +158,7 @@ pub fn upgrade_to_v24<T: BeaconChainTypes>(
158158 db. hot_db . do_atomically ( ops) ?;
159159 diffs_written += 1 ;
160160 }
161- StorageStrategy :: ReplayFrom ( _ ) => {
161+ StorageStrategy :: ReplayFrom ( diff_base_slot ) => {
162162 // Optimization: instead of having to load the state of each summary we load x32
163163 // less states by manually computing the HotStateSummary roots using the
164164 // computed state dag.
@@ -167,34 +167,31 @@ pub fn upgrade_to_v24<T: BeaconChainTypes>(
167167 // blocks.
168168 //
169169 // 2. Convert the summary to the new format.
170- let previous_state_root = if state_root == split. state_root {
171- Hash256 :: ZERO
172- } else {
170+ if state_root == split. state_root {
171+ return Err ( Error :: MigrationError (
172+ "unreachable: split state should be stored as a snapshot"
173+ . to_string ( ) ,
174+ ) ) ;
175+ }
176+ let previous_state_root = state_summaries_dag
177+ . previous_state_root ( state_root)
178+ . map_err ( |e| {
179+ Error :: MigrationError ( format ! (
180+ "error computing previous_state_root {e:?}"
181+ ) )
182+ } ) ?;
183+
184+ let diff_base_state_root = DiffBaseStateRoot :: new (
185+ diff_base_slot,
173186 state_summaries_dag
174- . previous_state_root ( state_root)
187+ . ancestor_state_root_at_slot ( state_root, diff_base_slot )
175188 . map_err ( |e| {
176189 Error :: MigrationError ( format ! (
177- "error computing previous_state_root {e:?}"
190+ "error computing ancestor_state_root_at_slot \
191+ ({state_root:?}, {diff_base_slot}): {e:?}"
178192 ) )
179- } ) ?
180- } ;
181-
182- let diff_base_state_root = if let Some ( diff_base_slot) =
183- storage_strategy. diff_base_slot ( )
184- {
185- DiffBaseStateRoot :: new (
186- diff_base_slot,
187- state_summaries_dag
188- . ancestor_state_root_at_slot ( state_root, diff_base_slot)
189- . map_err ( |e| {
190- Error :: MigrationError ( format ! (
191- "error computing ancestor_state_root_at_slot({state_root:?}, {diff_base_slot}) {e:?}"
192- ) )
193- } ) ?,
194- )
195- } else {
196- DiffBaseStateRoot :: zero ( )
197- } ;
193+ } ) ?,
194+ ) ;
198195
199196 let new_summary = HotStateSummary {
200197 slot,
0 commit comments