@@ -7,7 +7,7 @@ use fork_choice::{ForkChoice, ResetPayloadStatuses};
77use ssz:: { Decode , Encode } ;
88use ssz_derive:: { Decode , Encode } ;
99use std:: sync:: Arc ;
10- use store:: { DBColumn , Error , HotColdDB , KeyValueStoreOp , StoreItem } ;
10+ use store:: { DBColumn , Error , HotColdDB , KeyValueStore , KeyValueStoreOp , StoreItem } ;
1111use types:: { Hash256 , Slot } ;
1212
1313/// 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);
1616pub fn upgrade_to_v23 < T : BeaconChainTypes > (
1717 db : Arc < HotColdDB < T :: EthSpec , T :: HotStore , T :: ColdStore > > ,
1818) -> Result < Vec < KeyValueStoreOp > , Error > {
19- // Set the head-tracker to empty
19+ // 1) Set the head-tracker to empty
2020 let Some ( persisted_beacon_chain_v22) =
2121 db. get_item :: < PersistedBeaconChainV22 > ( & BEACON_CHAIN_DB_KEY ) ?
2222 else {
@@ -29,7 +29,19 @@ pub fn upgrade_to_v23<T: BeaconChainTypes>(
2929 genesis_block_root : persisted_beacon_chain_v22. genesis_block_root ,
3030 } ;
3131
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+ }
3345
3446 Ok ( ops)
3547}
0 commit comments