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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
use super::{types::SectorOnChainInfo, PowerPair, BASE_REWARD_FOR_DISPUTED_WINDOW_POST};
use crate::{network::*, DealWeight};
use clock::ChainEpoch;
use fil_types::{
NetworkVersion, RegisteredPoStProof, RegisteredSealProof, SectorQuality, SectorSize,
StoragePower,
};
use num_bigint::{BigInt, Integer};
use std::cmp;
use vm::TokenAmount;
pub const MAX_AGGREGATED_SECTORS: usize = 819;
pub const MIN_AGGREGATED_SECTORS: usize = 4;
pub const MAX_AGGREGATED_PROOF_SIZE: usize = 81960;
pub const PRE_COMMIT_SECTOR_BATCH_MAX_SIZE: usize = 256;
pub const EXPIRED_PRE_COMMIT_CLEAN_UP_DELAY: i64 = 8 * EPOCHS_IN_HOUR;
pub const WPOST_PROVING_PERIOD: ChainEpoch = EPOCHS_IN_DAY;
pub const WPOST_CHALLENGE_WINDOW: ChainEpoch = 30 * 60 / EPOCH_DURATION_SECONDS;
pub const WPOST_PERIOD_DEADLINES: u64 = 48;
pub const WPOST_MAX_CHAIN_COMMIT_AGE: ChainEpoch = WPOST_CHALLENGE_WINDOW;
pub const WPOST_DISPUTE_WINDOW: ChainEpoch = 2 * CHAIN_FINALITY;
pub const SECTORS_MAX: usize = 32 << 20;
pub const MAX_PARTITIONS_PER_DEADLINE: u64 = 3000;
pub const MAX_CONTROL_ADDRESSES: usize = 10;
pub const MAX_PEER_ID_LENGTH: usize = 128;
pub const MAX_MULTIADDR_DATA: usize = 1024;
pub const MAX_PROVE_COMMIT_SIZE_V4: usize = 1024;
pub const MAX_PROVE_COMMIT_SIZE_V5: usize = 10240;
pub const ADDRESSED_PARTITIONS_MAX: u64 = MAX_PARTITIONS_PER_DEADLINE;
pub const DELCARATIONS_MAX: u64 = ADDRESSED_PARTITIONS_MAX;
pub const ADDRESSED_SECTORS_MAX: u64 = 25_000;
pub fn load_partitions_sectors_max(partition_sector_count: u64) -> u64 {
cmp::min(
ADDRESSED_SECTORS_MAX / partition_sector_count,
ADDRESSED_PARTITIONS_MAX,
)
}
pub const NEW_SECTORS_PER_PERIOD_MAX: usize = 128 << 10;
pub const CHAIN_FINALITY: ChainEpoch = 900;
pub const SEALED_CID_PREFIX: cid::Prefix = cid::Prefix {
version: cid::Version::V1,
codec: cid::FIL_COMMITMENT_SEALED,
mh_type: cid::POSEIDON_BLS12_381_A1_FC1,
mh_len: 32,
};
pub fn can_pre_commit_seal_proof(proof: RegisteredSealProof) -> bool {
use RegisteredSealProof::*;
#[cfg(feature = "devnet")]
{
if matches!(proof, StackedDRG2KiBV1 | StackedDRG2KiBV1P1) {
return true;
}
}
matches!(proof, StackedDRG32GiBV1P1 | StackedDRG64GiBV1P1)
}
pub fn can_extend_seal_proof_type(proof: RegisteredSealProof, nv: NetworkVersion) -> bool {
use RegisteredSealProof::*;
if nv >= NetworkVersion::V7 && nv <= NetworkVersion::V10 {
return matches!(proof, StackedDRG32GiBV1P1 | StackedDRG64GiBV1P1);
}
true
}
pub fn max_prove_commit_duration(proof: RegisteredSealProof) -> Option<ChainEpoch> {
use RegisteredSealProof::*;
match proof {
StackedDRG32GiBV1 | StackedDRG2KiBV1 | StackedDRG8MiBV1 | StackedDRG512MiBV1
| StackedDRG64GiBV1 => Some(EPOCHS_IN_DAY + PRE_COMMIT_CHALLENGE_DELAY),
StackedDRG32GiBV1P1 | StackedDRG64GiBV1P1 | StackedDRG512MiBV1P1 | StackedDRG8MiBV1P1
| StackedDRG2KiBV1P1 => Some(30 * EPOCHS_IN_DAY + PRE_COMMIT_CHALLENGE_DELAY),
_ => None,
}
}
pub fn seal_proof_sector_maximum_lifetime(
proof: RegisteredSealProof,
nv: NetworkVersion,
) -> Option<ChainEpoch> {
use RegisteredSealProof::*;
if nv < NetworkVersion::V11 {
return match proof {
StackedDRG32GiBV1 | StackedDRG2KiBV1 | StackedDRG8MiBV1 | StackedDRG512MiBV1
| StackedDRG64GiBV1 | StackedDRG32GiBV1P1 | StackedDRG2KiBV1P1 | StackedDRG8MiBV1P1
| StackedDRG512MiBV1P1 | StackedDRG64GiBV1P1 => Some(EPOCHS_IN_YEAR * 5),
_ => None,
};
}
match proof {
StackedDRG32GiBV1 | StackedDRG2KiBV1 | StackedDRG8MiBV1 | StackedDRG512MiBV1
| StackedDRG64GiBV1 => Some(EPOCHS_IN_DAY * 540),
StackedDRG32GiBV1P1 | StackedDRG2KiBV1P1 | StackedDRG8MiBV1P1 | StackedDRG512MiBV1P1
| StackedDRG64GiBV1P1 => Some(EPOCHS_IN_YEAR * 5),
_ => None,
}
}
pub const MAX_PRE_COMMIT_RANDOMNESS_LOOKBACK: ChainEpoch = EPOCHS_IN_DAY + CHAIN_FINALITY;
#[cfg(not(feature = "devnet"))]
pub const PRE_COMMIT_CHALLENGE_DELAY: ChainEpoch = 150;
#[cfg(feature = "devnet")]
pub const PRE_COMMIT_CHALLENGE_DELAY: ChainEpoch = 10;
pub const WPOST_CHALLENGE_LOOKBACK: ChainEpoch = 20;
pub const FAULT_DECLARATION_CUTOFF: ChainEpoch = WPOST_CHALLENGE_LOOKBACK + 50;
pub const FAULT_MAX_AGE: ChainEpoch = WPOST_PROVING_PERIOD * 42;
pub const WORKER_KEY_CHANGE_DELAY: ChainEpoch = CHAIN_FINALITY;
pub const MIN_SECTOR_EXPIRATION: i64 = 180 * EPOCHS_IN_DAY;
pub const MAX_SECTOR_EXPIRATION_EXTENSION: i64 = 540 * EPOCHS_IN_DAY;
pub const DEAL_LIMIT_DENOMINATOR: u64 = 134217728;
pub const CONSENSUS_FAULT_INELIGIBILITY_DURATION: ChainEpoch = CHAIN_FINALITY;
fn quality_for_weight(
size: SectorSize,
duration: ChainEpoch,
deal_weight: &DealWeight,
verified_weight: &DealWeight,
) -> SectorQuality {
let sector_space_time = BigInt::from(size as u64) * BigInt::from(duration);
let total_deal_space_time = deal_weight + verified_weight;
let weighted_base_space_time =
(§or_space_time - total_deal_space_time) * &*QUALITY_BASE_MULTIPLIER;
let weighted_deal_space_time = deal_weight * &*DEAL_WEIGHT_MULTIPLIER;
let weighted_verified_space_time = verified_weight * &*VERIFIED_DEAL_WEIGHT_MULTIPLIER;
let weighted_sum_space_time =
weighted_base_space_time + weighted_deal_space_time + weighted_verified_space_time;
let scaled_up_weighted_sum_space_time: SectorQuality =
weighted_sum_space_time << SECTOR_QUALITY_PRECISION;
scaled_up_weighted_sum_space_time
.div_floor(§or_space_time)
.div_floor(&QUALITY_BASE_MULTIPLIER)
}
pub fn qa_power_for_weight(
size: SectorSize,
duration: ChainEpoch,
deal_weight: &DealWeight,
verified_weight: &DealWeight,
) -> StoragePower {
let quality = quality_for_weight(size, duration, deal_weight, verified_weight);
(BigInt::from(size as u64) * quality) >> SECTOR_QUALITY_PRECISION
}
pub fn qa_power_for_sector(size: SectorSize, sector: &SectorOnChainInfo) -> StoragePower {
let duration = sector.expiration - sector.activation;
qa_power_for_weight(
size,
duration,
§or.deal_weight,
§or.verified_deal_weight,
)
}
pub fn sector_deals_max(size: SectorSize) -> u64 {
cmp::max(256, size as u64 / DEAL_LIMIT_DENOMINATOR)
}
pub struct VestSpec {
pub initial_delay: ChainEpoch,
pub vest_period: ChainEpoch,
pub step_duration: ChainEpoch,
pub quantization: ChainEpoch,
}
pub const REWARD_VESTING_SPEC: VestSpec = VestSpec {
initial_delay: 0,
vest_period: 180 * EPOCHS_IN_DAY,
step_duration: EPOCHS_IN_DAY,
quantization: 12 * EPOCHS_IN_HOUR,
};
pub const CONSENSUS_FAULT_REPORTER_DEFAULT_SHARE: i64 = 4;
pub fn reward_for_consensus_slash_report(epoch_reward: &TokenAmount) -> TokenAmount {
epoch_reward.div_floor(
&(BigInt::from(EXPECTED_LEADERS_PER_EPOCH)
* BigInt::from(CONSENSUS_FAULT_REPORTER_DEFAULT_SHARE)),
)
}
pub fn reward_for_disputed_window_post(
_proof_type: RegisteredPoStProof,
_disputed_power: PowerPair,
) -> TokenAmount {
BASE_REWARD_FOR_DISPUTED_WINDOW_POST.clone()
}