@@ -36,6 +36,32 @@ pub fn store_full_state_v22<E: EthSpec>(
36
36
Ok ( ( ) )
37
37
}
38
38
39
+ /// Fetch a V22 state from the database either as a full state or using block replay.
40
+ pub fn get_state_v22 < T : BeaconChainTypes > (
41
+ db : & Arc < HotColdDB < T :: EthSpec , T :: HotStore , T :: ColdStore > > ,
42
+ state_root : & Hash256 ,
43
+ spec : & ChainSpec ,
44
+ ) -> Result < Option < BeaconState < T :: EthSpec > > , Error > {
45
+ let Some ( summary) = db. get_item :: < HotStateSummaryV22 > ( state_root) ? else {
46
+ return Ok ( None ) ;
47
+ } ;
48
+ let Some ( base_state) =
49
+ get_full_state_v22 ( & db. hot_db , & summary. epoch_boundary_state_root , spec) ?
50
+ else {
51
+ return Ok ( None ) ;
52
+ } ;
53
+ // Loading hot states via block replay doesn't care about the schema version, so we can use
54
+ // the DB's current method for this.
55
+ let update_cache = false ;
56
+ db. load_hot_state_using_replay (
57
+ base_state,
58
+ summary. slot ,
59
+ summary. latest_block_root ,
60
+ update_cache,
61
+ )
62
+ . map ( Some )
63
+ }
64
+
39
65
pub fn get_full_state_v22 < KV : KeyValueStore < E > , E : EthSpec > (
40
66
db : & KV ,
41
67
state_root : & Hash256 ,
@@ -139,6 +165,20 @@ pub struct HotStateSummaryV22 {
139
165
epoch_boundary_state_root : Hash256 ,
140
166
}
141
167
168
+ impl StoreItem for HotStateSummaryV22 {
169
+ fn db_column ( ) -> DBColumn {
170
+ DBColumn :: BeaconStateSummary
171
+ }
172
+
173
+ fn as_store_bytes ( & self ) -> Vec < u8 > {
174
+ self . as_ssz_bytes ( )
175
+ }
176
+
177
+ fn from_store_bytes ( bytes : & [ u8 ] ) -> Result < Self , Error > {
178
+ Ok ( Self :: from_ssz_bytes ( bytes) ?)
179
+ }
180
+ }
181
+
142
182
pub fn upgrade_to_v24 < T : BeaconChainTypes > (
143
183
db : Arc < HotColdDB < T :: EthSpec , T :: HotStore , T :: ColdStore > > ,
144
184
) -> Result < Vec < KeyValueStoreOp > , Error > {
@@ -319,19 +359,8 @@ pub fn upgrade_to_v24<T: BeaconChainTypes>(
319
359
320
360
match storage_strategy {
321
361
StorageStrategy :: DiffFrom ( _) | StorageStrategy :: Snapshot => {
322
- // We choose to not compute states during the epoch with block replay for
323
- // simplicity. Therefore we can only support a hot heriarchy config where the
324
- // lowest layer is >= log2(SLOTS_PER_EPOCH).
325
- // FIXME(tree-states): we need to remove this restriction.
326
- if slot % T :: EthSpec :: slots_per_epoch ( ) != 0 {
327
- return Err ( Error :: MigrationError ( format ! (
328
- "Hot hierarchy config lowest value must be >= {}" ,
329
- T :: EthSpec :: slots_per_epoch( ) . trailing_zeros( )
330
- ) ) ) ;
331
- }
332
-
333
- // Load the full state and re-store it as a snapshot or diff.
334
- let state = get_full_state_v22 ( & db. hot_db , & state_root, & db. spec ) ?
362
+ // Load the state and re-store it as a snapshot or diff.
363
+ let state = get_state_v22 :: < T > ( & db, & state_root, & db. spec ) ?
335
364
. ok_or ( Error :: MissingState ( state_root) ) ?;
336
365
337
366
// Store immediately so that future diffs can load and diff from it.
0 commit comments