@@ -6,7 +6,6 @@ use std::io::Write;
6
6
7
7
use mina_p2p_messages:: v2:: PrecomputedBlock ;
8
8
use openmina_core:: NetworkConfig ;
9
- use reqwest:: Url ;
10
9
use std:: net:: SocketAddr ;
11
10
12
11
use super :: NodeService ;
@@ -38,13 +37,15 @@ pub struct ArchiveService {
38
37
archive_sender : mpsc:: UnboundedSender < BlockApplyResult > ,
39
38
}
40
39
40
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
41
41
struct ArchiveServiceClients {
42
42
archiver_address : Option < SocketAddr > ,
43
43
aws_client : Option < aws:: ArchiveAWSClient > ,
44
44
gcp_client : Option < gcp:: ArchiveGCPClient > ,
45
45
local_path : Option < String > ,
46
46
}
47
47
48
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
48
49
impl ArchiveServiceClients {
49
50
async fn new ( options : & ArchiveStorageOptions , work_dir : String ) -> Result < Self , Error > {
50
51
let aws_client = if options. uses_aws_precomputed_storage ( ) {
@@ -72,7 +73,7 @@ impl ArchiveServiceClients {
72
73
let archiver_address = if options. uses_archiver_process ( ) {
73
74
let address = std:: env:: var ( "OPENMINA_ARCHIVE_ADDRESS" )
74
75
. expect ( "OPENMINA_ARCHIVE_ADDRESS is not set" ) ;
75
- let address = Url :: parse ( & address) . expect ( "Invalid URL" ) ;
76
+ let address = reqwest :: Url :: parse ( & address) . expect ( "Invalid URL" ) ;
76
77
77
78
// Convert URL to SocketAddr
78
79
let socket_addrs = address. socket_addrs ( || None ) . expect ( "Invalid URL" ) ;
@@ -243,16 +244,31 @@ impl ArchiveService {
243
244
// Note: Placeholder for the wasm implementation, if we decide to include an archive mode in the future
244
245
#[ cfg( target_arch = "wasm32" ) ]
245
246
fn run (
246
- mut archive_receiver : mpsc:: UnboundedReceiver < ArchiveTransitionFronntierDiff > ,
247
- address : SocketAddr ,
247
+ mut archive_receiver : mpsc:: UnboundedReceiver < BlockApplyResult > ,
248
248
options : ArchiveStorageOptions ,
249
+ work_dir : String ,
249
250
) {
250
251
unimplemented ! ( )
251
252
}
252
253
253
254
pub fn start ( options : ArchiveStorageOptions , work_dir : String ) -> Self {
254
255
let ( archive_sender, archive_receiver) = mpsc:: unbounded_channel :: < BlockApplyResult > ( ) ;
255
256
257
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
258
+ Self :: start_native ( archive_receiver, options, work_dir) ;
259
+
260
+ #[ cfg( target_arch = "wasm32" ) ]
261
+ Self :: start_wasm ( archive_receiver, options, work_dir) ;
262
+
263
+ Self :: new ( archive_sender)
264
+ }
265
+
266
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
267
+ fn start_native (
268
+ archive_receiver : mpsc:: UnboundedReceiver < BlockApplyResult > ,
269
+ options : ArchiveStorageOptions ,
270
+ work_dir : String ,
271
+ ) {
256
272
let runtime = tokio:: runtime:: Builder :: new_current_thread ( )
257
273
. enable_all ( )
258
274
. build ( )
@@ -264,8 +280,20 @@ impl ArchiveService {
264
280
runtime. block_on ( Self :: run ( archive_receiver, options, work_dir) ) ;
265
281
} )
266
282
. unwrap ( ) ;
283
+ }
267
284
268
- Self :: new ( archive_sender)
285
+ #[ cfg( target_arch = "wasm32" ) ]
286
+ fn start_wasm (
287
+ archive_receiver : mpsc:: UnboundedReceiver < BlockApplyResult > ,
288
+ options : ArchiveStorageOptions ,
289
+ work_dir : String ,
290
+ ) {
291
+ thread:: Builder :: new ( )
292
+ . name ( "openmina_archive" . to_owned ( ) )
293
+ . spawn ( move || {
294
+ Self :: run ( archive_receiver, options, work_dir) ;
295
+ } )
296
+ . unwrap ( ) ;
269
297
}
270
298
}
271
299
0 commit comments