@@ -114,7 +114,9 @@ impl ArchiveServiceClients {
114114 let precomputed_block: PrecomputedBlock = match breadcrumb. try_into ( ) {
115115 Ok ( block) => block,
116116 Err ( _) => {
117- node:: core:: warn!( summary = "Failed to convert breadcrumb to precomputed block" ) ;
117+ node:: core:: warn!(
118+ summary = "Failed to convert breadcrumb to precomputed block"
119+ ) ;
118120 return ;
119121 }
120122 } ;
@@ -131,11 +133,19 @@ impl ArchiveServiceClients {
131133 } ;
132134
133135 if options. uses_local_precomputed_storage ( ) {
134- // TODO(adonagy): Cleanup the unwraps (fn that returns a Result + log the error)
135136 if let Some ( path) = & self . local_path {
136- let file_path = Path :: new ( path) . join ( key. clone ( ) ) ;
137- let mut file = File :: create ( file_path) . unwrap ( ) ;
138- file. write_all ( & data) . unwrap ( ) ;
137+ let key_clone = key. clone ( ) ;
138+ match write_to_local_storage ( path, & key, & data) {
139+ Ok ( _) => node:: core:: info!(
140+ summary = "Successfully wrote precomputed block to local storage" ,
141+ key = key_clone
142+ ) ,
143+ Err ( e) => node:: core:: warn!(
144+ summary = "Failed to write precomputed block to local storage" ,
145+ key = key_clone,
146+ error = e. to_string( )
147+ ) ,
148+ }
139149 } else {
140150 node:: core:: warn!( summary = "Local precomputed storage path not set" ) ;
141151 }
@@ -273,3 +283,22 @@ impl node::transition_frontier::archive::archive_service::ArchiveService for Nod
273283// Note: Placeholder for the wasm implementation, if we decide to include an archive mode in the future
274284#[ cfg( target_arch = "wasm32" ) ]
275285mod rpc { }
286+
287+ fn write_to_local_storage ( base_path : & str , key : & str , data : & [ u8 ] ) -> Result < ( ) , Error > {
288+ use std:: fs:: { create_dir_all, File } ;
289+ use std:: path:: Path ;
290+
291+ let path = Path :: new ( base_path) . join ( key) ;
292+ if let Some ( parent) = path. parent ( ) {
293+ create_dir_all ( parent)
294+ . map_err ( |e| Error :: UploadError ( format ! ( "Directory creation failed: {}" , e) ) ) ?;
295+ }
296+
297+ let mut file = File :: create ( & path)
298+ . map_err ( |e| Error :: UploadError ( format ! ( "File creation failed: {}" , e) ) ) ?;
299+
300+ file. write_all ( data)
301+ . map_err ( |e| Error :: UploadError ( format ! ( "File write failed: {}" , e) ) ) ?;
302+
303+ Ok ( ( ) )
304+ }
0 commit comments