vc_processors/builtin/
tasks.rs

1//! Built-in tasks.
2//!
3
4use std::collections::HashMap;
5use std::path::PathBuf;
6
7use filecoin_proofs::UnpaddedBytesAmount;
8use serde::{Deserialize, Serialize};
9
10use crate::core::Task;
11use crate::fil_proofs::{
12    ActorID, ChallengeSeed, Commitment, PieceInfo, ProverId, RegisteredPoStProof, RegisteredSealProof, RegisteredUpdateProof,
13    SealCommitPhase1Output, SealCommitPhase2Output, SealPreCommitPhase1Output, SealPreCommitPhase2Output, SectorId, SnapEncodeOutput,
14    SnapProveOutput, SnarkProof, Ticket,
15};
16
17/// name str for add_pieces
18pub const STAGE_NAME_ADD_PIECES: &str = "add_pieces";
19
20/// name str for tree_d
21pub const STAGE_NAME_TREED: &str = "tree_d";
22
23/// name str for pc1
24pub const STAGE_NAME_PC1: &str = "pc1";
25
26/// name str for pc2
27pub const STAGE_NAME_PC2: &str = "pc2";
28
29/// name str for c1
30pub const STAGE_NAME_C1: &str = "c1";
31
32/// name str for c2
33pub const STAGE_NAME_C2: &str = "c2";
34
35/// name str for snap encode
36pub const STAGE_NAME_SNAP_ENCODE: &str = "snap_encode";
37
38/// name str for snap prove
39pub const STAGE_NAME_SNAP_PROVE: &str = "snap_prove";
40
41/// name str for data transfer
42pub const STAGE_NAME_TRANSFER: &str = "transfer";
43
44/// name str for window post
45pub const STAGE_NAME_WINDOW_POST: &str = "window_post";
46
47/// name str for window post
48pub const STAGE_NAME_WINNING_POST: &str = "winning_post";
49
50#[derive(Clone, Debug, Serialize, Deserialize)]
51#[serde(rename_all = "camelCase")]
52pub enum PieceFile {
53    Url(String),
54    Local(PathBuf),
55    Pledge,
56}
57
58#[derive(Clone, Debug, Serialize, Deserialize)]
59pub struct Piece {
60    pub piece_file: PieceFile,
61    pub payload_size: u64,
62    pub piece_size: UnpaddedBytesAmount,
63}
64
65/// Task of add_piece
66#[derive(Clone, Debug, Serialize, Deserialize)]
67pub struct AddPieces {
68    pub seal_proof_type: RegisteredSealProof,
69    pub pieces: Vec<Piece>,
70    pub staged_filepath: PathBuf,
71}
72
73impl Task for AddPieces {
74    const STAGE: &'static str = STAGE_NAME_ADD_PIECES;
75
76    type Output = Vec<PieceInfo>;
77}
78
79/// Task of tree_d
80#[derive(Clone, Debug, Serialize, Deserialize)]
81pub struct TreeD {
82    pub registered_proof: RegisteredSealProof,
83    pub staged_file: PathBuf,
84    pub cache_dir: PathBuf,
85}
86
87impl Task for TreeD {
88    const STAGE: &'static str = STAGE_NAME_TREED;
89    type Output = bool;
90}
91
92/// Task of pre-commit phase1
93#[derive(Clone, Debug, Serialize, Deserialize)]
94pub struct PC1 {
95    pub registered_proof: RegisteredSealProof,
96    pub cache_path: PathBuf,
97    pub in_path: PathBuf,
98    pub out_path: PathBuf,
99    pub prover_id: ProverId,
100    pub sector_id: SectorId,
101    pub ticket: Ticket,
102    pub piece_infos: Vec<PieceInfo>,
103}
104
105impl Task for PC1 {
106    const STAGE: &'static str = STAGE_NAME_PC1;
107    type Output = SealPreCommitPhase1Output;
108}
109
110/// Task of pre-commit phase2
111#[derive(Clone, Debug, Serialize, Deserialize)]
112pub struct PC2 {
113    pub pc1out: SealPreCommitPhase1Output,
114    pub cache_dir: PathBuf,
115    pub sealed_file: PathBuf,
116}
117
118impl Task for PC2 {
119    const STAGE: &'static str = STAGE_NAME_PC2;
120    type Output = SealPreCommitPhase2Output;
121}
122
123/// Task of commit phase2
124#[derive(Clone, Debug, Serialize, Deserialize)]
125pub struct C2 {
126    pub c1out: SealCommitPhase1Output,
127    pub prover_id: ProverId,
128    pub sector_id: SectorId,
129    pub miner_id: ActorID,
130}
131
132impl Task for C2 {
133    const STAGE: &'static str = STAGE_NAME_C2;
134    type Output = SealCommitPhase2Output;
135}
136
137/// Task of snap encode
138#[derive(Clone, Debug, Serialize, Deserialize)]
139pub struct SnapEncode {
140    pub registered_proof: RegisteredUpdateProof,
141
142    pub new_replica_path: PathBuf,
143
144    pub new_cache_path: PathBuf,
145
146    pub sector_path: PathBuf,
147
148    pub sector_cache_path: PathBuf,
149
150    pub staged_data_path: PathBuf,
151
152    pub piece_infos: Vec<PieceInfo>,
153}
154
155impl Task for SnapEncode {
156    const STAGE: &'static str = STAGE_NAME_SNAP_ENCODE;
157    type Output = SnapEncodeOutput;
158}
159
160/// Task of snap prove
161#[derive(Clone, Debug, Serialize, Deserialize)]
162pub struct SnapProve {
163    pub registered_proof: RegisteredUpdateProof,
164
165    pub vannilla_proofs: Vec<Vec<u8>>,
166
167    pub comm_r_old: Commitment,
168
169    pub comm_r_new: Commitment,
170
171    pub comm_d_new: Commitment,
172}
173
174impl Task for SnapProve {
175    const STAGE: &'static str = STAGE_NAME_SNAP_PROVE;
176    type Output = SnapProveOutput;
177}
178
179#[derive(Clone, Debug, Serialize, Deserialize)]
180pub struct TransferStoreInfo {
181    pub name: String,
182    pub meta: Option<HashMap<String, String>>,
183}
184
185#[derive(Clone, Debug, Serialize, Deserialize)]
186pub struct TransferItem {
187    pub store_name: Option<String>,
188    pub uri: PathBuf,
189}
190
191#[derive(Clone, Debug, Serialize, Deserialize)]
192pub struct TransferOption {
193    pub is_dir: bool,
194    pub allow_link: bool,
195}
196
197#[derive(Clone, Debug, Serialize, Deserialize)]
198pub struct TransferRoute {
199    pub src: TransferItem,
200    pub dest: TransferItem,
201    pub opt: Option<TransferOption>,
202}
203
204/// Task of transfer
205#[derive(Clone, Debug, Serialize, Deserialize)]
206pub struct Transfer {
207    /// store infos used in transfer items
208    pub stores: HashMap<String, TransferStoreInfo>,
209
210    pub routes: Vec<TransferRoute>,
211}
212
213impl Task for Transfer {
214    const STAGE: &'static str = STAGE_NAME_TRANSFER;
215
216    type Output = bool;
217}
218
219#[derive(Clone, Debug, Serialize, Deserialize)]
220pub struct PoStReplicaInfo {
221    pub sector_id: SectorId,
222    pub comm_r: Commitment,
223    pub cache_dir: PathBuf,
224    pub sealed_file: PathBuf,
225}
226
227#[derive(Clone, Debug, Serialize, Deserialize)]
228pub struct WindowPoStOutput {
229    pub proofs: Vec<SnarkProof>,
230    pub faults: Vec<u64>,
231}
232
233#[derive(Clone, Debug, Serialize, Deserialize)]
234pub struct WindowPoSt {
235    pub miner_id: ActorID,
236    pub proof_type: RegisteredPoStProof,
237    pub replicas: Vec<PoStReplicaInfo>,
238    pub seed: ChallengeSeed,
239}
240
241impl Task for WindowPoSt {
242    const STAGE: &'static str = STAGE_NAME_WINDOW_POST;
243
244    type Output = WindowPoStOutput;
245}
246
247#[derive(Clone, Debug, Serialize, Deserialize)]
248pub struct WinningPoStOutput {
249    pub proofs: Vec<SnarkProof>,
250}
251
252#[derive(Clone, Debug, Serialize, Deserialize)]
253pub struct WinningPoSt {
254    pub miner_id: ActorID,
255    pub proof_type: RegisteredPoStProof,
256    pub replicas: Vec<PoStReplicaInfo>,
257    pub seed: ChallengeSeed,
258}
259
260impl Task for WinningPoSt {
261    const STAGE: &'static str = STAGE_NAME_WINNING_POST;
262
263    type Output = WinningPoStOutput;
264}