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()
}