@@ -7,12 +7,16 @@ use prism_errors::{DataAvailabilityError, GeneralError};
77use prism_keys:: VerifyingKey ;
88use prism_prover:: { prover:: DEFAULT_MAX_EPOCHLESS_GAP , webserver:: WebServerConfig } ;
99use prism_serde:: base64:: FromBase64 ;
10+
11+ #[ cfg( feature = "rocksdb" ) ]
12+ use prism_storage:: rocksdb:: { RocksDBConfig , RocksDBConnection } ;
1013use prism_storage:: {
1114 Database ,
1215 database:: StorageBackend ,
1316 inmemory:: InMemoryDatabase ,
14- rocksdb :: { RocksDBConfig , RocksDBConnection } ,
17+ sled :: { SledConfig , SledConnection } ,
1518} ;
19+
1620use prism_telemetry:: config:: { TelemetryConfig , get_default_telemetry_config} ;
1721use serde:: { Deserialize , Serialize } ;
1822use std:: { fs, path:: Path , str:: FromStr , sync:: Arc , time:: Duration } ;
@@ -135,7 +139,7 @@ impl Config {
135139 keystore_path : Some ( format ! ( "{}keystore.json" , path) ) ,
136140 network : Network :: from_str ( network_name) . unwrap ( ) . config ( ) ,
137141 da_layer : DALayerOption :: default ( ) ,
138- db : StorageBackend :: RocksDB ( RocksDBConfig :: new ( & format ! ( "{}data" , path) ) ) ,
142+ db : StorageBackend :: Sled ( SledConfig :: new ( & format ! ( "{}data" , path) ) ) ,
139143 telemetry : Some ( get_default_telemetry_config ( ) ) ,
140144 max_epochless_gap : DEFAULT_MAX_EPOCHLESS_GAP ,
141145 }
@@ -152,19 +156,21 @@ pub enum DALayerOption {
152156#[ derive( Debug , Default , Clone , Eq , PartialEq , Serialize , Deserialize , ValueEnum ) ]
153157pub enum DBValues {
154158 #[ default]
159+ Sled ,
160+ #[ cfg( feature = "rocksdb" ) ]
155161 RocksDB ,
156162 InMemory ,
157163}
158164
159165#[ derive( Args , Deserialize , Clone , Debug ) ]
160166pub struct DatabaseArgs {
161- #[ arg( long, value_enum, default_value_t = DBValues :: RocksDB ) ]
162- /// Storage backend to use. Default: `rocks-db `
167+ #[ arg( long, value_enum, default_value_t = DBValues :: Sled ) ]
168+ /// Storage backend to use. Default: `sled `
163169 db_type : DBValues ,
164170
165- /// Path to the RocksDB database, used when `db_type` is `rocks-db`
171+ /// Path to the database, used when `db_type` is `rocks-db` or `sled `
166172 #[ arg( long) ]
167- rocksdb_path : Option < String > ,
173+ db_path : Option < String > ,
168174}
169175
170176pub fn load_config ( args : CommandArgs ) -> Result < Config > {
@@ -178,7 +184,7 @@ pub fn load_config(args: CommandArgs) -> Result<Config> {
178184 )
179185 . context ( "Failed to ensure config file exists" ) ?;
180186
181- if let Some ( rocksdb_path) = & args. database . rocksdb_path {
187+ if let Some ( rocksdb_path) = & args. database . db_path {
182188 fs:: create_dir_all ( rocksdb_path) . context ( "Failed to create RocksDB directory" ) ?;
183189 }
184190
@@ -278,9 +284,14 @@ fn apply_command_line_args(config: Config, args: CommandArgs) -> Config {
278284 port : args. webserver . port . unwrap_or ( webserver_config. port ) ,
279285 } ) ,
280286 db : match args. database . db_type {
287+ #[ cfg( feature = "rocksdb" ) ]
281288 DBValues :: RocksDB => StorageBackend :: RocksDB ( RocksDBConfig {
282289 path : args. database . rocksdb_path . unwrap_or_else ( || format ! ( "{}/data" , prism_home) ) ,
283290 } ) ,
291+ DBValues :: Sled => StorageBackend :: Sled ( SledConfig {
292+ path : args. database . db_path . unwrap_or_else ( || format ! ( "{}/data" , prism_home) ) ,
293+ ..SledConfig :: default ( )
294+ } ) ,
284295 DBValues :: InMemory => StorageBackend :: InMemory ,
285296 } ,
286297 network : NetworkConfig {
@@ -302,13 +313,22 @@ fn apply_command_line_args(config: Config, args: CommandArgs) -> Config {
302313
303314pub fn initialize_db ( cfg : & Config ) -> Result < Arc < Box < dyn Database > > > {
304315 match & cfg. db {
316+ #[ cfg( feature = "rocksdb" ) ]
305317 StorageBackend :: RocksDB ( cfg) => {
306318 let db = RocksDBConnection :: new ( cfg)
307319 . map_err ( |e| GeneralError :: InitializationError ( e. to_string ( ) ) )
308320 . context ( "Failed to initialize RocksDB" ) ?;
309321
310322 Ok ( Arc :: new ( Box :: new ( db) as Box < dyn Database > ) )
311323 }
324+ StorageBackend :: Sled ( cfg) => {
325+ let db = SledConnection :: new ( cfg)
326+ . map_err ( |e| GeneralError :: InitializationError ( e. to_string ( ) ) )
327+ . context ( "Failed to initialize Sled" ) ?;
328+
329+ Ok ( Arc :: new ( Box :: new ( db) as Box < dyn Database > ) )
330+ }
331+
312332 StorageBackend :: InMemory => Ok ( Arc :: new (
313333 Box :: new ( InMemoryDatabase :: new ( ) ) as Box < dyn Database >
314334 ) ) ,
0 commit comments