Skip to content

Commit 595557f

Browse files
fixups from rebase
1 parent 330b206 commit 595557f

File tree

4 files changed

+31
-78
lines changed

4 files changed

+31
-78
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fendermint/app/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ futures-util = { workspace = true }
2020
hex = { workspace = true }
2121
iroh = { workspace = true }
2222
iroh-blobs = { workspace = true }
23-
iroh-manager = { path = "../../recall/iroh_manager" }
2423
k256 = { workspace = true }
2524
lazy_static = { workspace = true }
2625
libipld = { workspace = true }
@@ -96,7 +95,7 @@ ipc-observability = { workspace = true }
9695
entangler = { workspace = true }
9796
entangler_storage = { workspace = true }
9897

99-
iroh_manager = { path = "../../recall/iroh_manager" }
98+
iroh-manager = { path = "../../recall/iroh_manager" }
10099

101100
[dev-dependencies]
102101
tempfile = { workspace = true }

fendermint/app/src/cmd/objects.rs

+28-67
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use anyhow::anyhow;
1010
use anyhow::Context;
1111
use bytes::Buf;
1212
use entangler::{ChunkRange, Config, EntanglementResult, Entangler};
13-
use entangler::{ChunkRange, Config, Entangler};
1413
use entangler_storage::iroh::IrohStorage as EntanglerIrohStorage;
15-
use entangler_storage::iroh::{BlobsWrapper, IrohStorage as EntanglerIrohStorage};
16-
use fendermint_actor_blobs_shared::state::Hash as BlobHash;
1714
use fendermint_actor_bucket::{GetParams, Object};
1815
use fendermint_app_settings::objects::ObjectsSettings;
1916
use fendermint_rpc::{client::FendermintClient, message::GasParams, QueryClient};
@@ -26,7 +23,8 @@ use fvm_shared::{
2623
use ipc_api::ethers_address_to_fil_address;
2724

2825
use iroh::NodeAddr;
29-
use iroh_blobs::{provider::AddProgress, rpc::client::blobs::BlobStatus, util::SetTagOption, Hash};
26+
use iroh_blobs::hashseq::HashSeq;
27+
use iroh_blobs::{rpc::client::blobs::BlobStatus, util::SetTagOption, Hash};
3028
use iroh_manager::{get_blob_hash_and_size, IrohNode};
3129
use lazy_static::lazy_static;
3230
use prometheus::{register_histogram, register_int_counter, Histogram, IntCounter};
@@ -87,7 +85,7 @@ cmd! {
8785
.and(with_iroh(iroh_node.clone()))
8886
.and(warp::multipart::form().max_length(settings.max_object_size + 1024 * 1024)) // max_object_size + 1MB for form overhead
8987
.and(with_max_size(settings.max_object_size))
90-
.and_then(handle_object_upload_with_manager);
88+
.and_then(handle_object_upload);
9189

9290
let objects_download = warp::path!("v1" / "objects" / String / ..)
9391
.and(warp::path::tail())
@@ -98,7 +96,7 @@ cmd! {
9896
.and(warp::query::<HeightQuery>())
9997
.and(with_client(client.clone()))
10098
.and(with_iroh(iroh_node.clone()))
101-
.and_then(handle_object_download_with_manager);
99+
.and_then(handle_object_download);
102100

103101
let router = health
104102
.or(node_addr)
@@ -286,19 +284,6 @@ struct UploadResponse {
286284
metadata_hash: String,
287285
}
288286

289-
async fn handle_object_upload_with_manager(
290-
mut iroh: IrohManager,
291-
form_data: warp::multipart::FormData,
292-
max_size: u64,
293-
) -> Result<impl Reply, Rejection> {
294-
let iroh_client = iroh.client().await.map_err(|e| {
295-
Rejection::from(BadRequest {
296-
message: format!("failed to load iroh client: {}", e),
297-
})
298-
})?;
299-
handle_object_upload(iroh_client, form_data, max_size).await
300-
}
301-
302287
async fn handle_object_upload(
303288
iroh: IrohNode,
304289
form_data: warp::multipart::FormData,
@@ -403,7 +388,7 @@ async fn handle_object_upload(
403388
})?;
404389

405390
let hash = *temp_tag.hash();
406-
let new_tag = iroh::blobs::Tag(format!("temp-{hash}-{upload_id}").into());
391+
let new_tag = iroh_blobs::Tag(format!("temp-{hash}-{upload_id}").into());
407392
batch.persist_to(temp_tag, new_tag).await.map_err(|e| {
408393
Rejection::from(BadRequest {
409394
message: format!("failed to persist blob: {}", e),
@@ -412,7 +397,7 @@ async fn handle_object_upload(
412397

413398
drop(batch);
414399

415-
let status = iroh.blobs().status(hash).await.map_err(|e| {
400+
let status = iroh.blobs_client().status(hash).await.map_err(|e| {
416401
Rejection::from(BadRequest {
417402
message: format!("failed to check blob status: {}", e),
418403
})
@@ -471,7 +456,7 @@ async fn handle_object_upload(
471456
}
472457

473458
async fn tag_entangled_data(
474-
iroh: &iroh::client::Iroh,
459+
iroh: &IrohNode,
475460
ent_result: &EntanglementResult,
476461
upload_id: Uuid,
477462
) -> Result<Hash, anyhow::Error> {
@@ -498,7 +483,7 @@ async fn tag_entangled_data(
498483
.collect::<Vec<_>>()
499484
.join(", ");
500485

501-
let batch = iroh.blobs().batch().await?;
486+
let batch = iroh.blobs_client().batch().await?;
502487

503488
// make a hash sequence object from the hashes and upload it to iroh
504489
let hash_seq = hashes.into_iter().collect::<HashSeq>();
@@ -512,7 +497,7 @@ async fn tag_entangled_data(
512497
);
513498

514499
// this tag will be replaced later by the validator to "stored-seq-{hash_seq_hash}"
515-
let hash_seq_tag = iroh::blobs::Tag(format!("temp-seq-{hash_seq_hash}").into());
500+
let hash_seq_tag = iroh_blobs::Tag(format!("temp-seq-{hash_seq_hash}").into());
516501
batch.persist_to(temp_tag, hash_seq_tag).await?;
517502

518503
drop(batch);
@@ -523,13 +508,13 @@ async fn tag_entangled_data(
523508
.info
524509
.get("tag")
525510
.ok_or_else(|| anyhow!("Missing tag in entanglement upload result"))?;
526-
let tag = iroh::blobs::Tag::from(tag_value.clone());
527-
iroh.tags().delete(tag).await?;
511+
let tag = iroh_blobs::Tag::from(tag_value.clone());
512+
iroh.blobs_client().tags().delete(tag).await?;
528513
}
529514

530515
// remove upload tags
531-
let orig_tag = iroh::blobs::Tag(format!("temp-{orig_hash}-{upload_id}").into());
532-
iroh.tags().delete(orig_tag).await?;
516+
let orig_tag = iroh_blobs::Tag(format!("temp-{orig_hash}-{upload_id}").into());
517+
iroh.blobs_client().tags().delete(orig_tag).await?;
533518

534519
Ok(hash_seq_hash)
535520
}
@@ -580,32 +565,6 @@ pub(crate) struct ObjectRange {
580565
body: Body,
581566
}
582567

583-
async fn handle_object_download_with_manager<F: QueryClient + Send + Sync>(
584-
address: String,
585-
tail: Tail,
586-
method: String,
587-
range: Option<String>,
588-
height_query: HeightQuery,
589-
client: F,
590-
mut iroh: IrohManager,
591-
) -> Result<impl Reply, Rejection> {
592-
let iroh_client = iroh.client().await.map_err(|e| {
593-
Rejection::from(BadRequest {
594-
message: format!("failed to load iroh client: {}", e),
595-
})
596-
})?;
597-
handle_object_download(
598-
address,
599-
tail,
600-
method,
601-
range,
602-
height_query,
603-
client,
604-
iroh_client,
605-
)
606-
.await
607-
}
608-
609568
async fn handle_object_download<F: QueryClient + Send + Sync>(
610569
address: String,
611570
tail: Tail,
@@ -637,11 +596,13 @@ async fn handle_object_download<F: QueryClient + Send + Sync>(
637596
match maybe_object {
638597
Some(object) => {
639598
let hash = Hash::from_bytes(object.hash.0);
640-
let (hash, size) = get_blob_hash_and_size(&iroh, hash).await.map_err(|e| {
641-
Rejection::from(BadRequest {
642-
message: e.to_string(),
643-
})
644-
})?;
599+
let (hash, size) = get_blob_hash_and_size(iroh.blobs_client(), hash)
600+
.await
601+
.map_err(|e| {
602+
Rejection::from(BadRequest {
603+
message: e.to_string(),
604+
})
605+
})?;
645606

646607
let ent = new_entangler(&iroh).map_err(|e| {
647608
Rejection::from(BadRequest {
@@ -938,13 +899,13 @@ mod tests {
938899

939900
/// Prepares test data for object download tests by uploading data, creating entanglement,
940901
/// and properly tagging the hash sequence
941-
async fn simulate_blob_upload(
942-
iroh: &iroh::client::Iroh,
943-
data: impl Into<Bytes>,
944-
) -> (Hash, Hash) {
902+
async fn simulate_blob_upload(iroh: &IrohNode, data: impl Into<Bytes>) -> (Hash, Hash) {
945903
let data = data.into(); // Convert to Bytes first, which implements Send
946-
let ent = new_entangler(iroh.clone()).unwrap();
947-
let ent_result = ent.upload(data).await.unwrap();
904+
let ent = new_entangler(iroh).unwrap();
905+
let data_stream = Box::pin(futures::stream::once(async move {
906+
Ok::<Bytes, std::io::Error>(data)
907+
}));
908+
let ent_result = ent.upload(data_stream).await.unwrap();
948909

949910
let metadata = ent
950911
.download_metadata(ent_result.metadata_hash.as_str())
@@ -964,13 +925,13 @@ mod tests {
964925
)
965926
.collect::<HashSeq>();
966927

967-
let batch = iroh.blobs().batch().await.unwrap();
928+
let batch = iroh.blobs_client().batch().await.unwrap();
968929
let temp_tag = batch.add_bytes(hash_seq).await.unwrap();
969930
let hash_seq_hash = *temp_tag.hash();
970931

971932
// Add a tag to the hash sequence as expected by the system
972933
let tag_name = format!("temp-seq-{hash_seq_hash}");
973-
let hash_seq_tag = iroh::blobs::Tag(tag_name.into());
934+
let hash_seq_tag = iroh_blobs::Tag(tag_name.into());
974935
batch.persist_to(temp_tag, hash_seq_tag).await.unwrap();
975936
drop(batch);
976937

recall/iroh_manager/src/lib.rs

-9
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,11 @@ mod node;
99
pub use self::manager::IrohManager;
1010
pub use self::node::IrohNode;
1111

12-
use std::path::{Path, PathBuf};
13-
use std::sync::Arc;
14-
1512
use anyhow::{anyhow, Result};
16-
use iroh::protocol::Router;
17-
use iroh::Endpoint;
1813
use iroh_blobs::hashseq::HashSeq;
19-
use iroh_blobs::net_protocol::Blobs;
2014
use iroh_blobs::rpc::client::blobs::BlobStatus;
2115
use iroh_blobs::Hash;
2216
use num_traits::Zero;
23-
use tokio::sync::Mutex;
24-
25-
pub type IrohBlobsClient = iroh_blobs::rpc::client::blobs::MemClient;
2617

2718
/// Returns the user blob hash and size from the hash sequence.
2819
/// The user blob hash is the first hash in the sequence.

0 commit comments

Comments
 (0)