33
44use std:: ops:: Range ;
55
6- #[ cfg( all ( unix , feature = "rocksdb" ) ) ]
7- use crate :: { providers:: RocksDBProvider , RocksDBProviderFactory } ;
6+ #[ cfg( feature = "rocksdb" ) ]
7+ use crate :: providers:: RocksDBProvider ;
88use crate :: {
99 providers:: { StaticFileProvider , StaticFileProviderRWRefMut } ,
1010 StaticFileProviderFactory ,
@@ -36,16 +36,6 @@ type EitherWriterTy<'a, P, T> = EitherWriter<
3636 <P as NodePrimitivesProvider >:: Primitives ,
3737> ;
3838
39- #[ cfg( all( unix, feature = "rocksdb" ) ) ]
40- type RocksDBReader = RocksDBProvider ;
41- #[ cfg( not( all( unix, feature = "rocksdb" ) ) ) ]
42- type RocksDBReader = ( ) ;
43-
44- #[ cfg( all( unix, feature = "rocksdb" ) ) ]
45- type RocksDBWriter = RocksDBProvider ;
46- #[ cfg( not( all( unix, feature = "rocksdb" ) ) ) ]
47- type RocksDBWriter = ( ) ;
48-
4939/// Represents a destination for writing data, either to database, static files, or `RocksDB`.
5040#[ derive( Debug , Display ) ]
5141pub enum EitherWriter < ' a , CURSOR , N > {
@@ -54,7 +44,8 @@ pub enum EitherWriter<'a, CURSOR, N> {
5444 /// Write to static file
5545 StaticFile ( StaticFileProviderRWRefMut < ' a , N > ) ,
5646 /// Write to `RocksDB`
57- RocksDB ( RocksDBWriter ) ,
47+ #[ cfg( feature = "rocksdb" ) ]
48+ RocksDB ( RocksDBProvider ) ,
5849}
5950
6051impl < ' a > EitherWriter < ' a , ( ) , ( ) > {
@@ -124,37 +115,39 @@ impl<'a> EitherWriter<'a, (), ()> {
124115 }
125116 }
126117
127- /// Creates a new [`EitherWriter`] for transaction hash numbers based on storage settings.
128- #[ cfg( all( unix, feature = "rocksdb" ) ) ]
129- pub fn new_transaction_hash_numbers < P > (
130- provider : & ' a P ,
131- ) -> ProviderResult < EitherWriterTy < ' a , P , tables:: TransactionHashNumbers > >
118+ /// Creates a new [`EitherWriter`] for storages history based on storage settings.
119+ #[ cfg( feature = "rocksdb" ) ]
120+ pub fn new_storages_history < P > (
121+ provider : & P ,
122+ rocksdb : RocksDBProvider ,
123+ ) -> ProviderResult < EitherWriterTy < ' a , P , tables:: StoragesHistory > >
132124 where
133- P : DBProvider + NodePrimitivesProvider + StorageSettingsCache + RocksDBProviderFactory ,
125+ P : DBProvider + NodePrimitivesProvider + StorageSettingsCache ,
134126 P :: Tx : DbTxMut ,
135127 {
136- if provider. cached_storage_settings ( ) . transaction_hash_numbers_in_rocksdb {
137- Ok ( EitherWriter :: RocksDB ( provider . rocksdb_provider ( ) ) )
128+ if provider. cached_storage_settings ( ) . storages_history_in_rocksdb {
129+ Ok ( EitherWriter :: RocksDB ( rocksdb ) )
138130 } else {
139- Ok ( EitherWriter :: Database (
140- provider. tx_ref ( ) . cursor_write :: < tables:: TransactionHashNumbers > ( ) ?,
141- ) )
131+ Ok ( EitherWriter :: Database ( provider. tx_ref ( ) . cursor_write :: < tables:: StoragesHistory > ( ) ?) )
142132 }
143133 }
144134
145- /// Creates a new [`EitherWriter`] for storages history based on storage settings.
146- #[ cfg( all( unix, feature = "rocksdb" ) ) ]
147- pub fn new_storages_history < P > (
148- provider : & ' a P ,
149- ) -> ProviderResult < EitherWriterTy < ' a , P , tables:: StoragesHistory > >
135+ /// Creates a new [`EitherWriter`] for transaction hash numbers based on storage settings.
136+ #[ cfg( feature = "rocksdb" ) ]
137+ pub fn new_transaction_hash_numbers < P > (
138+ provider : & P ,
139+ rocksdb : RocksDBProvider ,
140+ ) -> ProviderResult < EitherWriterTy < ' a , P , tables:: TransactionHashNumbers > >
150141 where
151- P : DBProvider + NodePrimitivesProvider + StorageSettingsCache + RocksDBProviderFactory ,
142+ P : DBProvider + NodePrimitivesProvider + StorageSettingsCache ,
152143 P :: Tx : DbTxMut ,
153144 {
154- if provider. cached_storage_settings ( ) . storages_history_in_rocksdb {
155- Ok ( EitherWriter :: RocksDB ( provider . rocksdb_provider ( ) ) )
145+ if provider. cached_storage_settings ( ) . transaction_hash_numbers_in_rocksdb {
146+ Ok ( EitherWriter :: RocksDB ( rocksdb ) )
156147 } else {
157- Ok ( EitherWriter :: Database ( provider. tx_ref ( ) . cursor_write :: < tables:: StoragesHistory > ( ) ?) )
148+ Ok ( EitherWriter :: Database (
149+ provider. tx_ref ( ) . cursor_write :: < tables:: TransactionHashNumbers > ( ) ?,
150+ ) )
158151 }
159152 }
160153}
@@ -167,6 +160,7 @@ impl<'a, CURSOR, N: NodePrimitives> EitherWriter<'a, CURSOR, N> {
167160 match self {
168161 Self :: Database ( _) => Ok ( ( ) ) ,
169162 Self :: StaticFile ( writer) => writer. increment_block ( expected_block_number) ,
163+ #[ cfg( feature = "rocksdb" ) ]
170164 Self :: RocksDB ( _) => Err ( ProviderError :: UnsupportedProvider ) ,
171165 }
172166 }
@@ -181,6 +175,7 @@ impl<'a, CURSOR, N: NodePrimitives> EitherWriter<'a, CURSOR, N> {
181175 match self {
182176 Self :: Database ( _) => Ok ( ( ) ) ,
183177 Self :: StaticFile ( writer) => writer. ensure_at_block ( block_number) ,
178+ #[ cfg( feature = "rocksdb" ) ]
184179 Self :: RocksDB ( _) => Err ( ProviderError :: UnsupportedProvider ) ,
185180 }
186181 }
@@ -196,6 +191,7 @@ where
196191 match self {
197192 Self :: Database ( cursor) => Ok ( cursor. append ( tx_num, receipt) ?) ,
198193 Self :: StaticFile ( writer) => writer. append_receipt ( tx_num, receipt) ,
194+ #[ cfg( feature = "rocksdb" ) ]
199195 Self :: RocksDB ( _) => Err ( ProviderError :: UnsupportedProvider ) ,
200196 }
201197 }
@@ -210,6 +206,7 @@ where
210206 match self {
211207 Self :: Database ( cursor) => Ok ( cursor. append ( tx_num, sender) ?) ,
212208 Self :: StaticFile ( writer) => writer. append_transaction_sender ( tx_num, sender) ,
209+ #[ cfg( feature = "rocksdb" ) ]
213210 Self :: RocksDB ( _) => Err ( ProviderError :: UnsupportedProvider ) ,
214211 }
215212 }
@@ -227,6 +224,7 @@ where
227224 Ok ( ( ) )
228225 }
229226 Self :: StaticFile ( writer) => writer. append_transaction_senders ( senders) ,
227+ #[ cfg( feature = "rocksdb" ) ]
230228 Self :: RocksDB ( _) => Err ( ProviderError :: UnsupportedProvider ) ,
231229 }
232230 }
@@ -259,6 +257,7 @@ where
259257
260258 writer. prune_transaction_senders ( to_delete, block) ?;
261259 }
260+ #[ cfg( feature = "rocksdb" ) ]
262261 Self :: RocksDB ( _) => return Err ( ProviderError :: UnsupportedProvider ) ,
263262 }
264263
@@ -274,7 +273,8 @@ pub enum EitherReader<CURSOR, N> {
274273 /// Read from static file
275274 StaticFile ( StaticFileProvider < N > ) ,
276275 /// Read from `RocksDB`
277- RocksDB ( RocksDBReader ) ,
276+ #[ cfg( feature = "rocksdb" ) ]
277+ RocksDB ( RocksDBProvider ) ,
278278}
279279
280280impl EitherReader < ( ) , ( ) > {
@@ -295,37 +295,39 @@ impl EitherReader<(), ()> {
295295 }
296296 }
297297
298- /// Creates a new [`EitherReader`] for transaction hash numbers based on storage settings.
299- #[ cfg( all ( unix , feature = "rocksdb" ) ) ]
300- pub fn new_transaction_hash_numbers < P > (
298+ /// Creates a new [`EitherReader`] for storages history based on storage settings.
299+ #[ cfg( feature = "rocksdb" ) ]
300+ pub fn new_storages_history < P > (
301301 provider : & P ,
302- ) -> ProviderResult < EitherReaderTy < P , tables:: TransactionHashNumbers > >
302+ rocksdb : RocksDBProvider ,
303+ ) -> ProviderResult < EitherReaderTy < P , tables:: StoragesHistory > >
303304 where
304- P : DBProvider + NodePrimitivesProvider + StorageSettingsCache + RocksDBProviderFactory ,
305+ P : DBProvider + NodePrimitivesProvider + StorageSettingsCache ,
305306 P :: Tx : DbTx ,
306307 {
307- if provider. cached_storage_settings ( ) . transaction_hash_numbers_in_rocksdb {
308- Ok ( EitherReader :: RocksDB ( provider . rocksdb_provider ( ) ) )
308+ if provider. cached_storage_settings ( ) . storages_history_in_rocksdb {
309+ Ok ( EitherReader :: RocksDB ( rocksdb ) )
309310 } else {
310- Ok ( EitherReader :: Database (
311- provider. tx_ref ( ) . cursor_read :: < tables:: TransactionHashNumbers > ( ) ?,
312- ) )
311+ Ok ( EitherReader :: Database ( provider. tx_ref ( ) . cursor_read :: < tables:: StoragesHistory > ( ) ?) )
313312 }
314313 }
315314
316- /// Creates a new [`EitherReader`] for storages history based on storage settings.
317- #[ cfg( all ( unix , feature = "rocksdb" ) ) ]
318- pub fn new_storages_history < P > (
315+ /// Creates a new [`EitherReader`] for transaction hash numbers based on storage settings.
316+ #[ cfg( feature = "rocksdb" ) ]
317+ pub fn new_transaction_hash_numbers < P > (
319318 provider : & P ,
320- ) -> ProviderResult < EitherReaderTy < P , tables:: StoragesHistory > >
319+ rocksdb : RocksDBProvider ,
320+ ) -> ProviderResult < EitherReaderTy < P , tables:: TransactionHashNumbers > >
321321 where
322- P : DBProvider + NodePrimitivesProvider + StorageSettingsCache + RocksDBProviderFactory ,
322+ P : DBProvider + NodePrimitivesProvider + StorageSettingsCache ,
323323 P :: Tx : DbTx ,
324324 {
325- if provider. cached_storage_settings ( ) . storages_history_in_rocksdb {
326- Ok ( EitherReader :: RocksDB ( provider . rocksdb_provider ( ) ) )
325+ if provider. cached_storage_settings ( ) . transaction_hash_numbers_in_rocksdb {
326+ Ok ( EitherReader :: RocksDB ( rocksdb ) )
327327 } else {
328- Ok ( EitherReader :: Database ( provider. tx_ref ( ) . cursor_read :: < tables:: StoragesHistory > ( ) ?) )
328+ Ok ( EitherReader :: Database (
329+ provider. tx_ref ( ) . cursor_read :: < tables:: TransactionHashNumbers > ( ) ?,
330+ ) )
329331 }
330332 }
331333}
@@ -356,6 +358,7 @@ where
356358 Some ( result. map ( |sender| ( tx_num, sender) ) )
357359 } )
358360 . collect :: < ProviderResult < HashMap < _ , _ > > > ( ) ,
361+ #[ cfg( feature = "rocksdb" ) ]
359362 Self :: RocksDB ( _) => Err ( ProviderError :: UnsupportedProvider ) ,
360363 }
361364 }
0 commit comments