Skip to content

Commit

Permalink
feat: FIP-0061: Add new PoSt proof types
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Mar 27, 2023
1 parent e758af0 commit 6471127
Showing 1 changed file with 88 additions and 16 deletions.
104 changes: 88 additions & 16 deletions shared/src/sector/registered_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ pub enum RegisteredPoStProof {
StackedDRGWindow512MiBV1,
StackedDRGWindow32GiBV1,
StackedDRGWindow64GiBV1,
StackedDRGWindow2KiBV1P1,
StackedDRGWindow8MiBV1P1,
StackedDRGWindow512MiBV1P1,
StackedDRGWindow32GiBV1P1,
StackedDRGWindow64GiBV1P1,
Invalid(i64),
}

Expand All @@ -116,11 +121,21 @@ impl RegisteredPoStProof {
pub fn sector_size(self) -> Result<SectorSize, String> {
use RegisteredPoStProof::*;
match self {
StackedDRGWindow2KiBV1 | StackedDRGWinning2KiBV1 => Ok(SectorSize::_2KiB),
StackedDRGWindow8MiBV1 | StackedDRGWinning8MiBV1 => Ok(SectorSize::_8MiB),
StackedDRGWindow512MiBV1 | StackedDRGWinning512MiBV1 => Ok(SectorSize::_512MiB),
StackedDRGWindow32GiBV1 | StackedDRGWinning32GiBV1 => Ok(SectorSize::_32GiB),
StackedDRGWindow64GiBV1 | StackedDRGWinning64GiBV1 => Ok(SectorSize::_64GiB),
StackedDRGWindow2KiBV1P1 | StackedDRGWindow2KiBV1 | StackedDRGWinning2KiBV1 => {
Ok(SectorSize::_2KiB)
}
StackedDRGWindow8MiBV1P1 | StackedDRGWindow8MiBV1 | StackedDRGWinning8MiBV1 => {
Ok(SectorSize::_8MiB)
}
StackedDRGWindow512MiBV1P1 | StackedDRGWindow512MiBV1 | StackedDRGWinning512MiBV1 => {
Ok(SectorSize::_512MiB)
}
StackedDRGWindow32GiBV1P1 | StackedDRGWindow32GiBV1 | StackedDRGWinning32GiBV1 => {
Ok(SectorSize::_32GiB)
}
StackedDRGWindow64GiBV1P1 | StackedDRGWindow64GiBV1 | StackedDRGWinning64GiBV1 => {
Ok(SectorSize::_64GiB)
}
Invalid(i) => Err(format!("unsupported proof type: {}", i)),
}
}
Expand All @@ -138,7 +153,12 @@ impl RegisteredPoStProof {
| StackedDRGWindow8MiBV1
| StackedDRGWindow512MiBV1
| StackedDRGWindow32GiBV1
| StackedDRGWindow64GiBV1 => Ok(192),
| StackedDRGWindow64GiBV1
| StackedDRGWindow2KiBV1P1
| StackedDRGWindow8MiBV1P1
| StackedDRGWindow512MiBV1P1
| StackedDRGWindow32GiBV1P1
| StackedDRGWindow64GiBV1P1 => Ok(192),
Invalid(i) => Err(format!("unsupported proof type: {}", i)),
}
}
Expand All @@ -148,16 +168,58 @@ impl RegisteredPoStProof {
// Resolve to post proof and then compute size from that.
use RegisteredPoStProof::*;
match self {
StackedDRGWinning64GiBV1 | StackedDRGWindow64GiBV1 => Ok(2300),
StackedDRGWinning32GiBV1 | StackedDRGWindow32GiBV1 => Ok(2349),
StackedDRGWinning2KiBV1 | StackedDRGWindow2KiBV1 => Ok(2),
StackedDRGWinning8MiBV1 | StackedDRGWindow8MiBV1 => Ok(2),
StackedDRGWinning512MiBV1 | StackedDRGWindow512MiBV1 => Ok(2),
StackedDRGWinning64GiBV1 | StackedDRGWindow64GiBV1 | StackedDRGWindow64GiBV1P1 => {
Ok(2300)
}
StackedDRGWinning32GiBV1 | StackedDRGWindow32GiBV1 | StackedDRGWindow32GiBV1P1 => {
Ok(2349)
}
StackedDRGWinning2KiBV1 | StackedDRGWindow2KiBV1 | StackedDRGWindow2KiBV1P1 => Ok(2),
StackedDRGWinning8MiBV1 | StackedDRGWindow8MiBV1 | StackedDRGWindow8MiBV1P1 => Ok(2),
StackedDRGWinning512MiBV1 | StackedDRGWindow512MiBV1 | StackedDRGWindow512MiBV1P1 => {
Ok(2)
}
Invalid(i) => Err(format!("unsupported proof type: {}", i)),
}
}
}

/// Convert the v1_1 PoSt Proof type to the older v1 types (used in nv18 and below)
pub fn convert_window_post_proof_v1p1_to_v1(
rpp: RegisteredPoStProof,
) -> Result<RegisteredPoStProof, String> {
match rpp {
RegisteredPoStProof::StackedDRGWindow2KiBV1P1 => {
Ok(RegisteredPoStProof::StackedDRGWindow2KiBV1)
}
RegisteredPoStProof::StackedDRGWindow8MiBV1P1 => {
Ok(RegisteredPoStProof::StackedDRGWindow8MiBV1)
}
RegisteredPoStProof::StackedDRGWindow512MiBV1P1 => {
Ok(RegisteredPoStProof::StackedDRGWindow512MiBV1)
}
RegisteredPoStProof::StackedDRGWindow32GiBV1P1 => {
Ok(RegisteredPoStProof::StackedDRGWindow32GiBV1)
}
RegisteredPoStProof::StackedDRGWindow64GiBV1P1 => {
Ok(RegisteredPoStProof::StackedDRGWindow64GiBV1P1)
}
i => Err(format!("not a v1p1 proof type: {:?}", i)),
}
}

/// Convert the v1_1 PoSt Proof type to the older v1 types (used in nv18 and below)
pub fn is_window_post_proof_v1p1(rpp: RegisteredPoStProof) -> bool {
match rpp {
RegisteredPoStProof::StackedDRGWindow2KiBV1P1
| RegisteredPoStProof::StackedDRGWindow8MiBV1P1
| RegisteredPoStProof::StackedDRGWindow512MiBV1P1
| RegisteredPoStProof::StackedDRGWindow32GiBV1P1
| RegisteredPoStProof::StackedDRGWindow64GiBV1P1 => true,
_ => false,
}
}

impl RegisteredSealProof {
/// Returns the sector size of the proof type, which is measured in bytes.
pub fn sector_size(self) -> Result<SectorSize, String> {
Expand Down Expand Up @@ -209,11 +271,11 @@ impl RegisteredSealProof {
pub fn registered_window_post_proof(self) -> Result<RegisteredPoStProof, String> {
use RegisteredPoStProof::*;
match self {
Self::StackedDRG64GiBV1 | Self::StackedDRG64GiBV1P1 => Ok(StackedDRGWindow64GiBV1),
Self::StackedDRG32GiBV1 | Self::StackedDRG32GiBV1P1 => Ok(StackedDRGWindow32GiBV1),
Self::StackedDRG2KiBV1 | Self::StackedDRG2KiBV1P1 => Ok(StackedDRGWindow2KiBV1),
Self::StackedDRG8MiBV1 | Self::StackedDRG8MiBV1P1 => Ok(StackedDRGWindow8MiBV1),
Self::StackedDRG512MiBV1 | Self::StackedDRG512MiBV1P1 => Ok(StackedDRGWindow512MiBV1),
Self::StackedDRG64GiBV1 | Self::StackedDRG64GiBV1P1 => Ok(StackedDRGWindow64GiBV1P1),
Self::StackedDRG32GiBV1 | Self::StackedDRG32GiBV1P1 => Ok(StackedDRGWindow32GiBV1P1),
Self::StackedDRG2KiBV1 | Self::StackedDRG2KiBV1P1 => Ok(StackedDRGWindow2KiBV1P1),
Self::StackedDRG8MiBV1 | Self::StackedDRG8MiBV1P1 => Ok(StackedDRGWindow8MiBV1P1),
Self::StackedDRG512MiBV1 | Self::StackedDRG512MiBV1P1 => Ok(StackedDRGWindow512MiBV1P1),
Self::Invalid(_) => Err(format!(
"Unsupported mapping from {:?} to PoSt-window RegisteredProof",
self
Expand Down Expand Up @@ -290,6 +352,11 @@ i64_conversion! {
StackedDRGWindow512MiBV1 => 7,
StackedDRGWindow32GiBV1 => 8,
StackedDRGWindow64GiBV1 => 9,
StackedDRGWindow2KiBV1P1 => 10,
StackedDRGWindow8MiBV1P1 => 11,
StackedDRGWindow512MiBV1P1 => 12,
StackedDRGWindow32GiBV1P1 => 13,
StackedDRGWindow64GiBV1P1 => 14,
}

i64_conversion! {
Expand Down Expand Up @@ -371,6 +438,11 @@ impl TryFrom<RegisteredPoStProof> for filecoin_proofs_api::RegisteredPoStProof {
StackedDRGWindow512MiBV1 => Ok(Self::StackedDrgWindow512MiBV1),
StackedDRGWindow32GiBV1 => Ok(Self::StackedDrgWindow32GiBV1),
StackedDRGWindow64GiBV1 => Ok(Self::StackedDrgWindow64GiBV1),
StackedDRGWindow2KiBV1P1 => Ok(Self::StackedDrgWindow2KiBV1),
StackedDRGWindow8MiBV1P1 => Ok(Self::StackedDrgWindow8MiBV1),
StackedDRGWindow512MiBV1P1 => Ok(Self::StackedDrgWindow512MiBV1),
StackedDRGWindow32GiBV1P1 => Ok(Self::StackedDrgWindow32GiBV1),
StackedDRGWindow64GiBV1P1 => Ok(Self::StackedDrgWindow64GiBV1),
Invalid(i) => Err(format!("unsupported proof type: {}", i)),
}
}
Expand Down

0 comments on commit 6471127

Please sign in to comment.