1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use std::collections::BTreeMap;
use anyhow::Result;
use filecoin_proofs_api::StorageProofsError;
use super::tasks::{
SnapEncode, SnapProve, Transfer, TransferRoute, TreeD, WindowPoSt, WindowPoStOutput, WinningPoSt, WinningPoStOutput, C2, PC1, PC2,
};
use crate::core::{Processor, Task};
use crate::fil_proofs::{
create_tree_d, generate_window_post, generate_winning_post, seal_commit_phase2, seal_pre_commit_phase1, seal_pre_commit_phase2,
snap_encode_into, snap_generate_sector_update_proof, to_prover_id, PartitionProofBytes, PrivateReplicaInfo,
};
mod transfer;
#[derive(Copy, Clone, Default, Debug)]
pub struct BuiltinProcessor;
impl Processor<TreeD> for BuiltinProcessor {
fn process(&self, task: TreeD) -> Result<<TreeD as Task>::Output> {
create_tree_d(task.registered_proof, Some(task.staged_file), task.cache_dir).map(|_| true)
}
}
impl Processor<PC1> for BuiltinProcessor {
fn process(&self, task: PC1) -> Result<<PC1 as Task>::Output> {
seal_pre_commit_phase1(
task.registered_proof,
task.cache_path,
task.in_path,
task.out_path,
task.prover_id,
task.sector_id,
task.ticket,
&task.piece_infos[..],
)
}
}
impl Processor<PC2> for BuiltinProcessor {
fn process(&self, task: PC2) -> Result<<PC2 as Task>::Output> {
seal_pre_commit_phase2(task.pc1out, task.cache_dir, task.sealed_file)
}
}
impl Processor<C2> for BuiltinProcessor {
fn process(&self, task: C2) -> Result<<C2 as Task>::Output> {
seal_commit_phase2(task.c1out, task.prover_id, task.sector_id)
}
}
impl Processor<SnapEncode> for BuiltinProcessor {
fn process(&self, task: SnapEncode) -> Result<<SnapEncode as Task>::Output> {
snap_encode_into(
task.registered_proof,
task.new_replica_path,
task.new_cache_path,
task.sector_path,
task.sector_cache_path,
task.staged_data_path,
&task.piece_infos[..],
)
}
}
impl Processor<SnapProve> for BuiltinProcessor {
fn process(&self, task: SnapProve) -> Result<<SnapProve as Task>::Output> {
snap_generate_sector_update_proof(
task.registered_proof,
task.vannilla_proofs.into_iter().map(PartitionProofBytes).collect(),
task.comm_r_old,
task.comm_r_new,
task.comm_d_new,
)
}
}
impl Processor<Transfer> for BuiltinProcessor {
fn process(&self, task: Transfer) -> Result<<Transfer as Task>::Output> {
task.routes.into_iter().try_for_each(|route| transfer::do_transfer(&route))?;
Ok(true)
}
}
impl Processor<WindowPoSt> for BuiltinProcessor {
fn process(&self, task: WindowPoSt) -> Result<<WindowPoSt as Task>::Output> {
let replicas = BTreeMap::from_iter(task.replicas.into_iter().map(|rep| {
(
rep.sector_id,
PrivateReplicaInfo::new(task.proof_type, rep.comm_r, rep.cache_dir, rep.sealed_file),
)
}));
generate_window_post(&task.seed, &replicas, to_prover_id(task.miner_id))
.map(|proofs| WindowPoStOutput {
proofs: proofs.into_iter().map(|r| r.1).collect(),
faults: vec![],
})
.or_else(|e| {
if let Some(StorageProofsError::FaultySectors(sectors)) = e.downcast_ref::<StorageProofsError>() {
return Ok(WindowPoStOutput {
proofs: vec![],
faults: sectors.iter().map(|id| (*id).into()).collect(),
});
}
Err(e)
})
}
}
impl Processor<WinningPoSt> for BuiltinProcessor {
fn process(&self, task: WinningPoSt) -> Result<<WinningPoSt as Task>::Output> {
let replicas = BTreeMap::from_iter(task.replicas.into_iter().map(|rep| {
(
rep.sector_id,
PrivateReplicaInfo::new(task.proof_type, rep.comm_r, rep.cache_dir, rep.sealed_file),
)
}));
generate_winning_post(&task.seed, &replicas, to_prover_id(task.miner_id)).map(|proofs| WinningPoStOutput {
proofs: proofs.into_iter().map(|r| r.1).collect(),
})
}
}