Skip to content

Commit

Permalink
fix(wdpost): get path correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5459 committed Sep 14, 2023
1 parent 76e84d8 commit 89811f1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions damocles-worker/src/infra/filestore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ impl FileStore for DefaultFileStore {
custom: None,
},
Resource::Update(sid) => StoreResource {
path_type: crate::rpc::sealer::PathType::Sealed,
path_type: crate::rpc::sealer::PathType::Update,
sector_id: Some(sid),
custom: None,
},
Resource::Cache(sid) => StoreResource {
path_type: crate::rpc::sealer::PathType::Sealed,
path_type: crate::rpc::sealer::PathType::Cache,
sector_id: Some(sid),
custom: None,
},
Expand Down
34 changes: 26 additions & 8 deletions damocles-worker/src/sealing/sealing_thread/planner/wdpost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ impl PlannerTrait for WdPostPlanner {
}
}

#[derive(Debug)]
struct PostPath {
cache_dir: PathBuf,
sealed_file: PathBuf,
Expand Down Expand Up @@ -416,14 +417,15 @@ impl WdPost<'_> {
.build_paths(&wdpost_job.input)
.context("build paths")
.abort()?;

// get sealed path and cache path
let replica = wdpost_job
.input
.sectors
.iter()
.map(|sector| {
let p = paths.remove(&sector.sector_id).context("get path")?;
let p = paths.remove(&sector.sector_id).with_context(|| {
format!("get path for {}", sector.sector_id)
})?;
let replica = PoStReplicaInfo {
sector_id: sector.sector_id,
comm_r: sector.comm_r,
Expand Down Expand Up @@ -487,6 +489,7 @@ impl WdPost<'_> {
&self,
input: &WdPoStInput,
) -> Result<HashMap<SectorId, PostPath>> {
#[derive(Debug)]
struct Resources {
cache_dir: Vec<Resource>,
sealed_file: Vec<Resource>,
Expand Down Expand Up @@ -540,6 +543,7 @@ impl WdPost<'_> {
let cache_dirs = instance
.paths(resources.cache_dir.clone())
.with_context(|| format!("get cache paths for {}", ins))?;

for (resource, sealed_file) in
resources.sealed_file.iter().zip(sealed_files)
{
Expand All @@ -548,9 +552,16 @@ impl WdPost<'_> {
.expect("sector_id must be set")
.number
.into();
paths.entry(sid).and_modify(|e| {
e.sealed_file = sealed_file;
});
let mut sealed_file = Some(sealed_file);
paths
.entry(sid)
.and_modify(|e| {
e.sealed_file = sealed_file.take().unwrap();
})
.or_insert_with(|| PostPath {
cache_dir: PathBuf::new(),
sealed_file: sealed_file.take().unwrap(),
});
}
for (resource, cache_dir) in
resources.cache_dir.iter().zip(cache_dirs)
Expand All @@ -560,9 +571,16 @@ impl WdPost<'_> {
.expect("sector_id must be set")
.number
.into();
paths.entry(sid).and_modify(|e| {
e.cache_dir = cache_dir;
});
let mut cache_dir = Some(cache_dir);
paths
.entry(sid)
.and_modify(|e| {
e.cache_dir = cache_dir.take().unwrap();
})
.or_insert_with(|| PostPath {
cache_dir: cache_dir.take().unwrap(),
sealed_file: PathBuf::new(),
});
}
}
Ok(paths)
Expand Down

0 comments on commit 89811f1

Please sign in to comment.