@@ -35,7 +35,7 @@ use state_processing::{
35
35
use std:: cmp:: min;
36
36
use std:: convert:: TryInto ;
37
37
use std:: marker:: PhantomData ;
38
- use std:: path:: { Path , PathBuf } ;
38
+ use std:: path:: Path ;
39
39
use std:: sync:: Arc ;
40
40
use std:: time:: Duration ;
41
41
use types:: blob_sidecar:: BlobSidecarList ;
@@ -61,7 +61,7 @@ pub struct HotColdDB<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
61
61
/// Cold database containing compact historical data.
62
62
pub cold_db : Cold ,
63
63
/// Database containing blobs. If None, store falls back to use `cold_db`.
64
- pub blobs_db : Option < Cold > ,
64
+ pub blobs_db : Cold ,
65
65
/// Hot database containing duplicated but quick-to-access recent data.
66
66
///
67
67
/// The hot database also contains all blocks.
@@ -138,7 +138,6 @@ pub enum HotColdDBError {
138
138
MissingExecutionPayload ( Hash256 ) ,
139
139
MissingFullBlockExecutionPayloadPruned ( Hash256 , Slot ) ,
140
140
MissingAnchorInfo ,
141
- MissingPathToBlobsDatabase ,
142
141
BlobsPreviouslyInDefaultStore ,
143
142
HotStateSummaryError ( BeaconStateError ) ,
144
143
RestorePointDecodeError ( ssz:: DecodeError ) ,
@@ -178,7 +177,7 @@ impl<E: EthSpec> HotColdDB<E, MemoryStore<E>, MemoryStore<E>> {
178
177
anchor_info : RwLock :: new ( None ) ,
179
178
blob_info : RwLock :: new ( BlobInfo :: default ( ) ) ,
180
179
cold_db : MemoryStore :: open ( ) ,
181
- blobs_db : Some ( MemoryStore :: open ( ) ) ,
180
+ blobs_db : MemoryStore :: open ( ) ,
182
181
hot_db : MemoryStore :: open ( ) ,
183
182
block_cache : Mutex :: new ( BlockCache :: new ( config. block_cache_size ) ) ,
184
183
state_cache : Mutex :: new ( LruCache :: new ( config. historic_state_cache_size ) ) ,
@@ -202,7 +201,7 @@ impl<E: EthSpec> HotColdDB<E, LevelDB<E>, LevelDB<E>> {
202
201
pub fn open (
203
202
hot_path : & Path ,
204
203
cold_path : & Path ,
205
- blobs_db_path : Option < PathBuf > ,
204
+ blobs_db_path : & Path ,
206
205
migrate_schema : impl FnOnce ( Arc < Self > , SchemaVersion , SchemaVersion ) -> Result < ( ) , Error > ,
207
206
config : StoreConfig ,
208
207
spec : ChainSpec ,
@@ -215,7 +214,7 @@ impl<E: EthSpec> HotColdDB<E, LevelDB<E>, LevelDB<E>> {
215
214
anchor_info : RwLock :: new ( None ) ,
216
215
blob_info : RwLock :: new ( BlobInfo :: default ( ) ) ,
217
216
cold_db : LevelDB :: open ( cold_path) ?,
218
- blobs_db : None ,
217
+ blobs_db : LevelDB :: open ( blobs_db_path ) ? ,
219
218
hot_db : LevelDB :: open ( hot_path) ?,
220
219
block_cache : Mutex :: new ( BlockCache :: new ( config. block_cache_size ) ) ,
221
220
state_cache : Mutex :: new ( LruCache :: new ( config. historic_state_cache_size ) ) ,
@@ -271,37 +270,29 @@ impl<E: EthSpec> HotColdDB<E, LevelDB<E>, LevelDB<E>> {
271
270
Some ( blob_info) => {
272
271
// If the oldest block slot is already set do not allow the blob DB path to be
273
272
// changed (require manual migration).
274
- if blob_info. oldest_blob_slot . is_some ( ) {
275
- if blobs_db_path. is_some ( ) && !blob_info. blobs_db {
276
- return Err ( HotColdDBError :: BlobsPreviouslyInDefaultStore . into ( ) ) ;
277
- } else if blobs_db_path. is_none ( ) && blob_info. blobs_db {
278
- return Err ( HotColdDBError :: MissingPathToBlobsDatabase . into ( ) ) ;
279
- }
273
+ if blob_info. oldest_blob_slot . is_some ( ) && !blob_info. blobs_db {
274
+ return Err ( HotColdDBError :: BlobsPreviouslyInDefaultStore . into ( ) ) ;
280
275
}
281
276
// Set the oldest blob slot to the Deneb fork slot if it is not yet set.
277
+ // Always initialize `blobs_db` to true, we no longer support storing the blobs
278
+ // in the freezer DB, because the UX is strictly worse for relocating the DB.
282
279
let oldest_blob_slot = blob_info. oldest_blob_slot . or ( deneb_fork_slot) ;
283
280
BlobInfo {
284
281
oldest_blob_slot,
285
- blobs_db : blobs_db_path . is_some ( ) ,
282
+ blobs_db : true ,
286
283
}
287
284
}
288
285
// First start.
289
286
None => BlobInfo {
290
287
// Set the oldest blob slot to the Deneb fork slot if it is not yet set.
291
288
oldest_blob_slot : deneb_fork_slot,
292
- blobs_db : blobs_db_path . is_some ( ) ,
289
+ blobs_db : true ,
293
290
} ,
294
291
} ;
295
- if new_blob_info. blobs_db {
296
- if let Some ( path) = & blobs_db_path {
297
- db. blobs_db = Some ( LevelDB :: open ( path. as_path ( ) ) ?) ;
298
- }
299
- }
300
292
db. compare_and_set_blob_info_with_write ( <_ >:: default ( ) , new_blob_info. clone ( ) ) ?;
301
293
info ! (
302
294
db. log,
303
295
"Blob DB initialized" ;
304
- "separate_db" => new_blob_info. blobs_db,
305
296
"path" => ?blobs_db_path,
306
297
"oldest_blob_slot" => ?new_blob_info. oldest_blob_slot,
307
298
) ;
@@ -575,8 +566,8 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
575
566
576
567
/// Check if the blobs for a block exists on disk.
577
568
pub fn blobs_exist ( & self , block_root : & Hash256 ) -> Result < bool , Error > {
578
- let blobs_db = self . blobs_db . as_ref ( ) . unwrap_or ( & self . cold_db ) ;
579
- blobs_db . key_exists ( DBColumn :: BeaconBlob . into ( ) , block_root. as_bytes ( ) )
569
+ self . blobs_db
570
+ . key_exists ( DBColumn :: BeaconBlob . into ( ) , block_root. as_bytes ( ) )
580
571
}
581
572
582
573
/// Determine whether a block exists in the database.
@@ -592,13 +583,12 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
592
583
. key_delete ( DBColumn :: BeaconBlock . into ( ) , block_root. as_bytes ( ) ) ?;
593
584
self . hot_db
594
585
. key_delete ( DBColumn :: ExecPayload . into ( ) , block_root. as_bytes ( ) ) ?;
595
- let blobs_db = self . blobs_db . as_ref ( ) . unwrap_or ( & self . cold_db ) ;
596
- blobs_db . key_delete ( DBColumn :: BeaconBlob . into ( ) , block_root. as_bytes ( ) )
586
+ self . blobs_db
587
+ . key_delete ( DBColumn :: BeaconBlob . into ( ) , block_root. as_bytes ( ) )
597
588
}
598
589
599
590
pub fn put_blobs ( & self , block_root : & Hash256 , blobs : BlobSidecarList < E > ) -> Result < ( ) , Error > {
600
- let blobs_db = self . blobs_db . as_ref ( ) . unwrap_or ( & self . cold_db ) ;
601
- blobs_db. put_bytes (
591
+ self . blobs_db . put_bytes (
602
592
DBColumn :: BeaconBlob . into ( ) ,
603
593
block_root. as_bytes ( ) ,
604
594
& blobs. as_ssz_bytes ( ) ,
@@ -988,9 +978,9 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
988
978
let mut guard = self . block_cache . lock ( ) ;
989
979
990
980
let blob_cache_ops = blobs_ops. clone ( ) ;
991
- let blobs_db = self . blobs_db . as_ref ( ) . unwrap_or ( & self . cold_db ) ;
992
981
// Try to execute blobs store ops.
993
- blobs_db. do_atomically ( self . convert_to_kv_batch ( blobs_ops) ?) ?;
982
+ self . blobs_db
983
+ . do_atomically ( self . convert_to_kv_batch ( blobs_ops) ?) ?;
994
984
995
985
let hot_db_cache_ops = hot_db_ops. clone ( ) ;
996
986
// Try to execute hot db store ops.
@@ -1018,7 +1008,8 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1018
1008
} ;
1019
1009
* op = reverse_op;
1020
1010
}
1021
- blobs_db. do_atomically ( self . convert_to_kv_batch ( blob_cache_ops) ?) ?;
1011
+ self . blobs_db
1012
+ . do_atomically ( self . convert_to_kv_batch ( blob_cache_ops) ?) ?;
1022
1013
return Err ( e) ;
1023
1014
}
1024
1015
@@ -1436,15 +1427,16 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1436
1427
1437
1428
/// Fetch blobs for a given block from the store.
1438
1429
pub fn get_blobs ( & self , block_root : & Hash256 ) -> Result < Option < BlobSidecarList < E > > , Error > {
1439
- let blobs_db = self . blobs_db . as_ref ( ) . unwrap_or ( & self . cold_db ) ;
1440
-
1441
1430
// Check the cache.
1442
1431
if let Some ( blobs) = self . block_cache . lock ( ) . get_blobs ( block_root) {
1443
1432
metrics:: inc_counter ( & metrics:: BEACON_BLOBS_CACHE_HIT_COUNT ) ;
1444
1433
return Ok ( Some ( blobs. clone ( ) ) ) ;
1445
1434
}
1446
1435
1447
- match blobs_db. get_bytes ( DBColumn :: BeaconBlob . into ( ) , block_root. as_bytes ( ) ) ? {
1436
+ match self
1437
+ . blobs_db
1438
+ . get_bytes ( DBColumn :: BeaconBlob . into ( ) , block_root. as_bytes ( ) ) ?
1439
+ {
1448
1440
Some ( ref blobs_bytes) => {
1449
1441
let blobs = BlobSidecarList :: from_ssz_bytes ( blobs_bytes) ?;
1450
1442
self . block_cache
@@ -1640,7 +1632,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
1640
1632
} ) ;
1641
1633
let blob_info = BlobInfo {
1642
1634
oldest_blob_slot,
1643
- blobs_db : self . blobs_db . is_some ( ) ,
1635
+ blobs_db : true ,
1644
1636
} ;
1645
1637
self . compare_and_set_blob_info ( self . get_blob_info ( ) , blob_info)
1646
1638
}
0 commit comments