@@ -7,7 +7,7 @@ use fork_choice::{ForkChoice, ResetPayloadStatuses};
7
7
use ssz:: { Decode , Encode } ;
8
8
use ssz_derive:: { Decode , Encode } ;
9
9
use std:: sync:: Arc ;
10
- use store:: { DBColumn , Error , HotColdDB , KeyValueStoreOp , StoreItem } ;
10
+ use store:: { DBColumn , Error , HotColdDB , KeyValueStore , KeyValueStoreOp , StoreItem } ;
11
11
use types:: { Hash256 , Slot } ;
12
12
13
13
/// Dummy value to use for the canonical head block root, see below.
@@ -16,7 +16,7 @@ pub const DUMMY_CANONICAL_HEAD_BLOCK_ROOT: Hash256 = Hash256::repeat_byte(0xff);
16
16
pub fn upgrade_to_v23 < T : BeaconChainTypes > (
17
17
db : Arc < HotColdDB < T :: EthSpec , T :: HotStore , T :: ColdStore > > ,
18
18
) -> Result < Vec < KeyValueStoreOp > , Error > {
19
- // Set the head-tracker to empty
19
+ // 1) Set the head-tracker to empty
20
20
let Some ( persisted_beacon_chain_v22) =
21
21
db. get_item :: < PersistedBeaconChainV22 > ( & BEACON_CHAIN_DB_KEY ) ?
22
22
else {
@@ -29,7 +29,19 @@ pub fn upgrade_to_v23<T: BeaconChainTypes>(
29
29
genesis_block_root : persisted_beacon_chain_v22. genesis_block_root ,
30
30
} ;
31
31
32
- let ops = vec ! [ persisted_beacon_chain. as_kv_store_op( BEACON_CHAIN_DB_KEY ) ] ;
32
+ let mut ops = vec ! [ persisted_beacon_chain. as_kv_store_op( BEACON_CHAIN_DB_KEY ) ] ;
33
+
34
+ // 2) Wipe out all state temporary flags. While un-used in V23, if there's a rollback we could
35
+ // end-up with an inconsistent DB.
36
+ for state_root_result in db
37
+ . hot_db
38
+ . iter_column_keys :: < Hash256 > ( DBColumn :: BeaconStateTemporary )
39
+ {
40
+ ops. push ( KeyValueStoreOp :: DeleteKey (
41
+ DBColumn :: BeaconStateTemporary ,
42
+ state_root_result?. as_slice ( ) . to_vec ( ) ,
43
+ ) ) ;
44
+ }
33
45
34
46
Ok ( ops)
35
47
}
0 commit comments