Skip to content

Commit 495bb0c

Browse files
author
Adrian Nagy
committed
fix(wasm): archive build
1 parent ad037a0 commit 495bb0c

File tree

1 file changed

+33
-5
lines changed
  • node/common/src/service/archive

1 file changed

+33
-5
lines changed

node/common/src/service/archive/mod.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::io::Write;
66

77
use mina_p2p_messages::v2::PrecomputedBlock;
88
use openmina_core::NetworkConfig;
9-
use reqwest::Url;
109
use std::net::SocketAddr;
1110

1211
use super::NodeService;
@@ -38,13 +37,15 @@ pub struct ArchiveService {
3837
archive_sender: mpsc::UnboundedSender<BlockApplyResult>,
3938
}
4039

40+
#[cfg(not(target_arch = "wasm32"))]
4141
struct ArchiveServiceClients {
4242
archiver_address: Option<SocketAddr>,
4343
aws_client: Option<aws::ArchiveAWSClient>,
4444
gcp_client: Option<gcp::ArchiveGCPClient>,
4545
local_path: Option<String>,
4646
}
4747

48+
#[cfg(not(target_arch = "wasm32"))]
4849
impl ArchiveServiceClients {
4950
async fn new(options: &ArchiveStorageOptions, work_dir: String) -> Result<Self, Error> {
5051
let aws_client = if options.uses_aws_precomputed_storage() {
@@ -72,7 +73,7 @@ impl ArchiveServiceClients {
7273
let archiver_address = if options.uses_archiver_process() {
7374
let address = std::env::var("OPENMINA_ARCHIVE_ADDRESS")
7475
.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");
7677

7778
// Convert URL to SocketAddr
7879
let socket_addrs = address.socket_addrs(|| None).expect("Invalid URL");
@@ -243,16 +244,31 @@ impl ArchiveService {
243244
// Note: Placeholder for the wasm implementation, if we decide to include an archive mode in the future
244245
#[cfg(target_arch = "wasm32")]
245246
fn run(
246-
mut archive_receiver: mpsc::UnboundedReceiver<ArchiveTransitionFronntierDiff>,
247-
address: SocketAddr,
247+
mut archive_receiver: mpsc::UnboundedReceiver<BlockApplyResult>,
248248
options: ArchiveStorageOptions,
249+
work_dir: String,
249250
) {
250251
unimplemented!()
251252
}
252253

253254
pub fn start(options: ArchiveStorageOptions, work_dir: String) -> Self {
254255
let (archive_sender, archive_receiver) = mpsc::unbounded_channel::<BlockApplyResult>();
255256

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+
) {
256272
let runtime = tokio::runtime::Builder::new_current_thread()
257273
.enable_all()
258274
.build()
@@ -264,8 +280,20 @@ impl ArchiveService {
264280
runtime.block_on(Self::run(archive_receiver, options, work_dir));
265281
})
266282
.unwrap();
283+
}
267284

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();
269297
}
270298
}
271299

0 commit comments

Comments
 (0)