@@ -3,7 +3,7 @@ use std::{
33 fs:: File ,
44 io:: Write ,
55 net:: { IpAddr , Ipv4Addr , SocketAddr } ,
6- path:: Path ,
6+ path:: PathBuf ,
77 sync:: {
88 mpsc:: { Receiver , Sender } ,
99 Arc , Mutex ,
@@ -170,7 +170,7 @@ pub fn get_blocks_for_range(
170170 blocks_per_sec : f64 ,
171171 _ping_timeout : Duration ,
172172 network : Network ,
173- block_dir : & Path ,
173+ block_dir : Option < PathBuf > ,
174174 chain : Arc < ChainstateManager > ,
175175 hints : & Hints ,
176176 peers : Arc < Mutex < Vec < SocketAddr > > > ,
@@ -222,19 +222,22 @@ pub fn get_blocks_for_range(
222222 let unspent_indexes: HashSet < u64 > =
223223 hints. get_indexes ( block_height) . into_iter ( ) . collect ( ) ;
224224 // tracing::info!("{task_id} -> {block_height}:{hash}");
225- let file_path = block_dir. join ( format ! ( "{hash}.block" ) ) ;
226- let file = File :: create_new ( file_path) ;
227- let mut file = match file {
228- Ok ( file) => file,
229- Err ( e) => {
230- tracing:: warn!( "Conflicting open files at: {}" , block_height) ;
231- tracing:: warn!( "{e}" ) ;
232- panic ! ( "files cannot conflict" ) ;
233- }
234- } ;
235- let block_bytes = consensus:: serialize ( & block) ;
236- file. write_all ( & block_bytes)
237- . expect ( "failed to write block file" ) ;
225+ if let Some ( block_dir) = block_dir. as_ref ( ) {
226+ let file_path = block_dir. join ( format ! ( "{hash}.block" ) ) ;
227+ let file = File :: create_new ( file_path) ;
228+ let mut file = match file {
229+ Ok ( file) => file,
230+ Err ( e) => {
231+ tracing:: warn!( "Conflicting open files at: {}" , block_height) ;
232+ tracing:: warn!( "{e}" ) ;
233+ panic ! ( "files cannot conflict" ) ;
234+ }
235+ } ;
236+ let block_bytes = consensus:: serialize ( & block) ;
237+ file. write_all ( & block_bytes)
238+ . expect ( "failed to write block file" ) ;
239+ file. sync_data ( ) . expect ( "could not sync file with OS" ) ;
240+ }
238241 // tracing::info!("Wrote {hash} to file");
239242 let ( _, transactions) = block. into_parts ( ) ;
240243 let mut output_index = 0 ;
0 commit comments