File tree Expand file tree Collapse file tree 4 files changed +44
-43
lines changed
crates/fuel-core/src/state Expand file tree Collapse file tree 4 files changed +44
-43
lines changed Original file line number Diff line number Diff line change @@ -20,10 +20,7 @@ use fuel_core::{
2020 GenesisDatabase ,
2121 } ,
2222 service:: Config ,
23- state:: {
24- historical_rocksdb:: HistoricalRocksDB ,
25- rocks_db:: ShallowTempDir ,
26- } ,
23+ state:: historical_rocksdb:: HistoricalRocksDB ,
2724} ;
2825use fuel_core_benches:: * ;
2926use fuel_core_storage:: {
@@ -67,12 +64,12 @@ use rand::{
6764pub struct BenchDb {
6865 db : GenesisDatabase ,
6966 /// Used for RAII cleanup. Contents of this directory are deleted on drop.
70- _tmp_dir : ShallowTempDir ,
67+ _tmp_dir : utils :: ShallowTempDir ,
7168}
7269
7370impl BenchDb {
7471 fn new ( contract_id : & ContractId ) -> anyhow:: Result < Self > {
75- let tmp_dir = ShallowTempDir :: new ( ) ;
72+ let tmp_dir = utils :: ShallowTempDir :: new ( ) ;
7673
7774 let db = HistoricalRocksDB :: < OnChain > :: default_open (
7875 tmp_dir. path ( ) ,
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ use std::{
3838
3939pub mod default_gas_costs;
4040pub mod import;
41+ pub mod utils;
4142
4243pub use fuel_core_storage:: vm_storage:: VmStorage ;
4344pub use rand:: Rng ;
Original file line number Diff line number Diff line change 1+ use rand:: RngCore ;
2+ use std:: {
3+ env,
4+ path:: PathBuf ,
5+ } ;
6+
7+ /// Reimplementation of `tempdir::TempDir` that allows creating a new
8+ /// instance without actually creating a new directory on the filesystem.
9+ /// This is needed since rocksdb requires empty directory for checkpoints.
10+ pub struct ShallowTempDir {
11+ path : PathBuf ,
12+ }
13+
14+ impl Default for ShallowTempDir {
15+ fn default ( ) -> Self {
16+ Self :: new ( )
17+ }
18+ }
19+
20+ impl ShallowTempDir {
21+ /// Creates a random directory.
22+ pub fn new ( ) -> Self {
23+ let mut rng = rand:: thread_rng ( ) ;
24+ let mut path = env:: temp_dir ( ) ;
25+ path. push ( format ! ( "fuel-core-shallow-{}" , rng. next_u64( ) ) ) ;
26+ Self { path }
27+ }
28+
29+ /// Returns the path of the directory.
30+ pub fn path ( & self ) -> & PathBuf {
31+ & self . path
32+ }
33+ }
34+
35+ impl Drop for ShallowTempDir {
36+ fn drop ( & mut self ) {
37+ // Ignore errors
38+ let _ = std:: fs:: remove_dir_all ( & self . path ) ;
39+ }
40+ }
Original file line number Diff line number Diff line change @@ -35,7 +35,6 @@ use fuel_core_storage::{
3535 Result as StorageResult ,
3636} ;
3737use itertools:: Itertools ;
38- use rand:: RngCore ;
3938use rocksdb:: {
4039 BlockBasedOptions ,
4140 BoundColumnFamily ,
@@ -55,7 +54,6 @@ use rocksdb::{
5554use std:: {
5655 cmp,
5756 collections:: BTreeMap ,
58- env,
5957 fmt,
6058 fmt:: Formatter ,
6159 iter,
@@ -69,41 +67,6 @@ use tempfile::TempDir;
6967
7068type DB = DBWithThreadMode < MultiThreaded > ;
7169
72- /// Reimplementation of `tempdir::TempDir` that allows creating a new
73- /// instance without actually creating a new directory on the filesystem.
74- /// This is needed since rocksdb requires empty directory for checkpoints.
75- pub struct ShallowTempDir {
76- path : PathBuf ,
77- }
78-
79- impl Default for ShallowTempDir {
80- fn default ( ) -> Self {
81- Self :: new ( )
82- }
83- }
84-
85- impl ShallowTempDir {
86- /// Creates a random directory.
87- pub fn new ( ) -> Self {
88- let mut rng = rand:: thread_rng ( ) ;
89- let mut path = env:: temp_dir ( ) ;
90- path. push ( format ! ( "fuel-core-shallow-{}" , rng. next_u64( ) ) ) ;
91- Self { path }
92- }
93-
94- /// Returns the path of the directory.
95- pub fn path ( & self ) -> & PathBuf {
96- & self . path
97- }
98- }
99-
100- impl Drop for ShallowTempDir {
101- fn drop ( & mut self ) {
102- // Ignore errors
103- let _ = std:: fs:: remove_dir_all ( & self . path ) ;
104- }
105- }
106-
10770type DropFn = Box < dyn FnOnce ( ) + Send + Sync > ;
10871#[ derive( Default ) ]
10972struct DropResources {
You can’t perform that action at this time.
0 commit comments