@@ -1051,11 +1051,17 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1051
1051
/// than the split point. You shouldn't delete states from the finalized portion of the chain
1052
1052
/// (which are frozen, and won't be deleted), or valid descendents of the finalized checkpoint
1053
1053
/// (which will be deleted by this function but shouldn't be).
1054
- pub fn delete_state ( & self , state_root : & Hash256 , slot : Slot ) -> Result < ( ) , Error > {
1055
- self . do_atomically_with_block_and_blobs_cache ( vec ! [ StoreOp :: DeleteState (
1056
- * state_root,
1057
- Some ( slot) ,
1058
- ) ] )
1054
+ pub fn delete_state (
1055
+ & self ,
1056
+ state_root : & Hash256 ,
1057
+ slot : Slot ,
1058
+ prune_hot_diff : bool ,
1059
+ ) -> Result < ( ) , Error > {
1060
+ self . do_atomically_with_block_and_blobs_cache ( vec ! [ StoreOp :: DeleteState {
1061
+ state_root: * state_root,
1062
+ state_slot: Some ( slot) ,
1063
+ prune_hot_diff,
1064
+ } ] )
1059
1065
}
1060
1066
1061
1067
pub fn forwards_block_roots_iterator (
@@ -1196,7 +1202,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1196
1202
}
1197
1203
}
1198
1204
1199
- StoreOp :: DeleteState ( state_root, slot) => {
1205
+ StoreOp :: DeleteState {
1206
+ state_root,
1207
+ state_slot : slot,
1208
+ prune_hot_diff,
1209
+ } => {
1200
1210
// Delete the hot state summary.
1201
1211
let state_summary_key =
1202
1212
get_key_for_col ( DBColumn :: BeaconStateSummary . into ( ) , state_root. as_slice ( ) ) ;
@@ -1211,6 +1221,12 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1211
1221
key_value_batch. push ( KeyValueStoreOp :: DeleteKey ( state_temp_key) ) ;
1212
1222
1213
1223
// TODO(hdiff): Should delete the diff under this state root if any
1224
+ if prune_hot_diff {
1225
+ key_value_batch. push ( KeyValueStoreOp :: DeleteKey ( get_key_for_col (
1226
+ DBColumn :: BeaconStateHotDiff . into ( ) ,
1227
+ state_root. as_slice ( ) ,
1228
+ ) ) ) ;
1229
+ }
1214
1230
1215
1231
// TODO(hdiff): Review under HDiff
1216
1232
if slot. map_or ( true , |slot| slot % E :: slots_per_epoch ( ) == 0 ) {
@@ -1220,10 +1236,6 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1220
1236
}
1221
1237
}
1222
1238
1223
- StoreOp :: DeleteStateHotDiff ( _) => {
1224
- todo ! ( ) ;
1225
- }
1226
-
1227
1239
StoreOp :: DeleteExecutionPayload ( block_root) => {
1228
1240
let key = get_key_for_col ( DBColumn :: ExecPayload . into ( ) , block_root. as_slice ( ) ) ;
1229
1241
key_value_batch. push ( KeyValueStoreOp :: DeleteKey ( key) ) ;
@@ -1372,12 +1384,10 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1372
1384
self . state_cache . lock ( ) . delete_block_states ( & block_root) ;
1373
1385
}
1374
1386
1375
- StoreOp :: DeleteState ( state_root, _ ) => {
1387
+ StoreOp :: DeleteState { state_root, .. } => {
1376
1388
self . state_cache . lock ( ) . delete_state ( & state_root)
1377
1389
}
1378
1390
1379
- StoreOp :: DeleteStateHotDiff ( _) => todo ! ( ) ,
1380
-
1381
1391
StoreOp :: DeleteBlobs ( _) => ( ) ,
1382
1392
1383
1393
StoreOp :: DeleteDataColumns ( _, _) => ( ) ,
@@ -3070,7 +3080,12 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
3070
3080
"slot" => summary. slot,
3071
3081
"reason" => reason,
3072
3082
) ;
3073
- state_delete_batch. push ( StoreOp :: DeleteState ( state_root, Some ( summary. slot ) ) ) ;
3083
+ state_delete_batch. push ( StoreOp :: DeleteState {
3084
+ state_root,
3085
+ state_slot : Some ( summary. slot ) ,
3086
+ // TODO(hdiff): The logic here is duplicated from `migrate_database`
3087
+ prune_hot_diff : false ,
3088
+ } ) ;
3074
3089
}
3075
3090
}
3076
3091
}
@@ -3172,7 +3187,14 @@ pub fn migrate_database<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>(
3172
3187
3173
3188
// Delete the old summary, and the full state if we lie on an epoch boundary.
3174
3189
if !required_finalized_diff_state_roots. contains ( & state_root) {
3175
- hot_db_ops. push ( StoreOp :: DeleteState ( state_root, Some ( slot) ) ) ;
3190
+ hot_db_ops. push ( StoreOp :: DeleteState {
3191
+ state_root,
3192
+ state_slot : Some ( slot) ,
3193
+ // TODO(hdiff): must not delete *all* finalized hdiffs. Instead, keep
3194
+ // the more recent diff of each layer including the snapshot.
3195
+ // Implement a routine somewhere to figure out which diffs should be kept
3196
+ prune_hot_diff : false ,
3197
+ } ) ;
3176
3198
}
3177
3199
3178
3200
// Do not try to store states if a restore point is yet to be stored, or will never be
0 commit comments