Skip to content

Commit

Permalink
Update to new PoSt sector types (#357)
Browse files Browse the repository at this point in the history
* Update to new PoSt sector types

* Add todos
  • Loading branch information
austinabell authored Apr 20, 2020
1 parent 8f0fc1d commit ff5260a
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 129 deletions.
2 changes: 1 addition & 1 deletion vm/actor/src/builtin/miner/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::{power, u64_key, BytesKey, OptionalEpoch, HAMT_BIT_WIDTH};
use ::serde::{Deserialize, Deserializer, Serialize, Serializer};
use address::Address;
use cid::Cid;
use clock::ChainEpoch;
Expand All @@ -16,6 +15,7 @@ use num_bigint::BigInt;
use rleplus::bitvec::prelude::{BitVec, Lsb0};
use rleplus::{BitVecDe, BitVecSer};
use runtime::Runtime;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use vm::{DealID, RegisteredProof, SectorInfo, SectorNumber, SectorSize, TokenAmount};

/// Miner actor state
Expand Down
7 changes: 4 additions & 3 deletions vm/default_runtime/src/gas_syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use runtime::{ConsensusFault, Syscalls};
use std::cell::RefCell;
use std::rc::Rc;
use vm::{
ActorError, GasTracker, PieceInfo, PoStVerifyInfo, PriceList, RegisteredProof, SealVerifyInfo,
ActorError, GasTracker, PieceInfo, PriceList, RegisteredProof, SealVerifyInfo,
WindowPoStVerifyInfo,
};

/// Syscall wrapper to charge gas on syscalls
Expand Down Expand Up @@ -63,7 +64,7 @@ where
.unwrap();
self.syscalls.verify_seal(vi)
}
fn verify_post(&self, vi: &PoStVerifyInfo) -> Result<(), ActorError> {
fn verify_post(&self, vi: &WindowPoStVerifyInfo) -> Result<(), ActorError> {
self.gas
.borrow_mut()
.charge_gas(self.price_list.on_verify_post(vi))
Expand Down Expand Up @@ -115,7 +116,7 @@ mod tests {
fn verify_seal(&self, _vi: &SealVerifyInfo) -> Result<(), ActorError> {
Ok(Default::default())
}
fn verify_post(&self, _vi: &PoStVerifyInfo) -> Result<(), ActorError> {
fn verify_post(&self, _vi: &WindowPoStVerifyInfo) -> Result<(), ActorError> {
Ok(Default::default())
}
fn verify_consensus_fault(
Expand Down
6 changes: 3 additions & 3 deletions vm/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use forest_encoding::{blake2b_256, Cbor};
use ipld_blockstore::BlockStore;
use message::UnsignedMessage;
use vm::{
ActorError, ExitCode, MethodNum, PieceInfo, PoStVerifyInfo, Randomness, RegisteredProof,
SealVerifyInfo, Serialized, TokenAmount,
ActorError, ExitCode, MethodNum, PieceInfo, Randomness, RegisteredProof, SealVerifyInfo,
Serialized, TokenAmount, WindowPoStVerifyInfo,
};

/// Runtime is the VM's internal runtime object.
Expand Down Expand Up @@ -162,7 +162,7 @@ pub trait Syscalls {
todo!()
}
/// Verifies a proof of spacetime.
fn verify_post(&self, _vi: &PoStVerifyInfo) -> Result<(), ActorError> {
fn verify_post(&self, _vi: &WindowPoStVerifyInfo) -> Result<(), ActorError> {
// TODO
todo!()
}
Expand Down
5 changes: 3 additions & 2 deletions vm/src/gas/price_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::{
MethodNum, PieceInfo, PoStVerifyInfo, RegisteredProof, SealVerifyInfo, TokenAmount, METHOD_SEND,
MethodNum, PieceInfo, RegisteredProof, SealVerifyInfo, TokenAmount, WindowPoStVerifyInfo,
METHOD_SEND,
};
use clock::ChainEpoch;
use crypto::SignatureType;
Expand Down Expand Up @@ -147,7 +148,7 @@ impl PriceList {
}
/// Returns gas required for PoSt verification
#[inline]
pub fn on_verify_post(&self, _info: &PoStVerifyInfo) -> i64 {
pub fn on_verify_post(&self, _info: &WindowPoStVerifyInfo) -> i64 {
self.verify_post_base
}
/// Returns gas required for verifying consensus fault
Expand Down
75 changes: 26 additions & 49 deletions vm/src/sector/post.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::{ActorID, Randomness, RegisteredProof, SectorID, SectorNumber};
use crate::{ActorID, Randomness, RegisteredProof, SectorNumber};
use cid::Cid;

// TODO check if this can be changed to an array
pub type ChallengeTicketsCommitment = Vec<u8>;
pub type PoStRandomness = Randomness;
pub type PartialTicket = [u8; 32];

/// PoStVerifyInfo is the structure of all the information a verifier
/// needs to verify a PoSt.
#[derive(Debug, PartialEq, Default)]
pub struct PoStVerifyInfo {
pub randomness: PoStRandomness,
pub candidates: Vec<PoStCandidate>,
pub proofs: Vec<PoStProof>,
pub eligible_sectors: Vec<SectorInfo>,
pub prover: ActorID,
pub challenge_count: u64,
}

// TODO docs
#[derive(Debug, PartialEq, Default)]
/// Information about a sector necessary for PoSt verification
#[derive(Debug, PartialEq, Default, Clone, Eq)]
pub struct SectorInfo {
/// Used when sealing - needs to be mapped to PoSt registered proof when used to verify a PoSt
pub proof: RegisteredProof,
Expand All @@ -31,43 +16,35 @@ pub struct SectorInfo {
}

// TODO docs
#[derive(Debug, PartialEq, Default)]
pub struct OnChainElectionPoStVerifyInfo {
/// each PoStCandidate has its own RegisteredProof
pub candidates: Vec<PoStCandidate>,
/// each PoStProof has its own RegisteredProof
pub proofs: Vec<PoStProof>,
#[derive(Debug, PartialEq, Default, Clone, Eq)]
pub struct PoStProof {
pub registered_proof: RegisteredProof,
// TODO revisit if can be array in future
pub proof_bytes: Vec<u8>,
}

// TODO docs
#[derive(Debug, PartialEq, Default)]
pub struct OnChainPoStVerifyInfo {
/// each PoStCandidate has its own RegisteredProof
pub candidates: Vec<PoStCandidate>,
/// each PoStProof has its own RegisteredProof
/// Information needed to verify a Winning PoSt attached to a block header.
/// Note: this is not used within the state machine, but by the consensus/election mechanisms.
#[derive(Debug, PartialEq, Default, Clone, Eq)]
pub struct WinningPoStVerifyInfo {
pub randomness: PoStRandomness,
pub proofs: Vec<PoStProof>,
pub challenge_sectors: Vec<SectorInfo>,
/// Used to derive 32-byte prover ID
pub prover: ActorID,
}

// TODO docs
#[derive(Debug, PartialEq, Default)]
pub struct PoStCandidate {
pub registered_proof: RegisteredProof,
pub ticket: PartialTicket,
pub private_proof: PrivatePoStCandidateProof,
pub sector_id: SectorID,
pub challenge_index: usize,
}

// TODO docs
/// Information needed to verify a Window PoSt submitted directly to a miner actor.
#[derive(Debug, PartialEq, Default, Clone, Eq)]
pub struct PoStProof {
pub registered_proof: RegisteredProof,
pub proof_bytes: Vec<u8>,
pub struct WindowPoStVerifyInfo {
pub randomness: PoStRandomness,
pub proofs: Vec<PoStProof>,
pub private_proof: Vec<SectorInfo>,
pub prover: ActorID,
}

// TODO docs
#[derive(Debug, PartialEq, Default)]
pub struct PrivatePoStCandidateProof {
pub registered_proof: RegisteredProof,
pub externalized: Vec<u8>,
/// Information submitted by a miner to provide a Window PoSt.
#[derive(Debug, PartialEq, Default, Clone, Eq)]
pub struct OnChainWindowPoStVerifyInfo {
pub proofs: Vec<PoStProof>,
}
94 changes: 74 additions & 20 deletions vm/src/sector/registered_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,25 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
#[repr(u8)]
pub enum RegisteredProof {
StackedDRG32GiBSeal = 1,
StackedDRG32GiBPoSt = 2,
StackedDRG32GiBPoSt = 2, // TODO unused (revisit if being removed)
StackedDRG2KiBSeal = 3,
StackedDRG2KiBPoSt = 4,
StackedDRG2KiBPoSt = 4, // TODO unused (revisit if being removed)
StackedDRG8MiBSeal = 5,
StackedDRG8MiBPoSt = 6,
StackedDRG8MiBPoSt = 6, // TODO unused (revisit if being removed)
StackedDRG512MiBSeal = 7,
StackedDRG512MiBPoSt = 8,
StackedDRG512MiBPoSt = 8, // TODO unused (revisit if being removed)

StackedDRG2KiBWinningPoSt = 9,
StackedDRG2KiBWindowPoSt = 10,

StackedDRG8MiBWinningPoSt = 11,
StackedDRG8MiBWindowPoSt = 12,

StackedDRG512MiBWinningPoSt = 13,
StackedDRG512MiBWindowPoSt = 14,

StackedDRG32GiBWinningPoSt = 15,
StackedDRG32GiBWindowPoSt = 16,
}

impl RegisteredProof {
Expand All @@ -29,23 +41,54 @@ impl RegisteredProof {
pub fn sector_size(self) -> SectorSize {
use RegisteredProof::*;
match self {
StackedDRG32GiBSeal | StackedDRG32GiBPoSt => SectorSize::_32GiB,
StackedDRG2KiBSeal | StackedDRG2KiBPoSt => SectorSize::_2KiB,
StackedDRG8MiBSeal | StackedDRG8MiBPoSt => SectorSize::_8MiB,
StackedDRG512MiBSeal | StackedDRG512MiBPoSt => SectorSize::_512MiB,
StackedDRG32GiBSeal
| StackedDRG32GiBPoSt
| StackedDRG32GiBWindowPoSt
| StackedDRG32GiBWinningPoSt => SectorSize::_32GiB,
StackedDRG2KiBSeal
| StackedDRG2KiBPoSt
| StackedDRG2KiBWindowPoSt
| StackedDRG2KiBWinningPoSt => SectorSize::_2KiB,
StackedDRG8MiBSeal
| StackedDRG8MiBPoSt
| StackedDRG8MiBWindowPoSt
| StackedDRG8MiBWinningPoSt => SectorSize::_8MiB,
StackedDRG512MiBSeal
| StackedDRG512MiBPoSt
| StackedDRG512MiBWindowPoSt
| StackedDRG512MiBWinningPoSt => SectorSize::_512MiB,
}
}

/// Produces the winning PoSt-specific RegisteredProof corresponding
/// to the receiving RegisteredProof.
pub fn registered_winning_post_proof(self) -> Result<RegisteredProof, String> {
use RegisteredProof::*;
match self {
StackedDRG32GiBSeal | StackedDRG32GiBWinningPoSt => Ok(StackedDRG32GiBWinningPoSt),
StackedDRG2KiBSeal | StackedDRG2KiBWinningPoSt => Ok(StackedDRG2KiBWinningPoSt),
StackedDRG8MiBSeal | StackedDRG8MiBWinningPoSt => Ok(StackedDRG8MiBWinningPoSt),
StackedDRG512MiBSeal | StackedDRG512MiBWinningPoSt => Ok(StackedDRG512MiBWinningPoSt),
_ => Err(format!(
"Unsupported mapping from {:?} to PoSt-winning RegisteredProof",
self
)),
}
}

/// RegisteredPoStProof produces the PoSt-specific RegisteredProof corresponding
/// Produces the windowed PoSt-specific RegisteredProof corresponding
/// to the receiving RegisteredProof.
pub fn registered_post_proof(self) -> RegisteredProof {
pub fn registered_window_post_proof(self) -> Result<RegisteredProof, String> {
use RegisteredProof::*;
match self {
StackedDRG32GiBSeal => StackedDRG32GiBPoSt,
StackedDRG2KiBSeal => StackedDRG2KiBPoSt,
StackedDRG8MiBSeal => StackedDRG8MiBPoSt,
StackedDRG512MiBSeal => StackedDRG512MiBPoSt,
p => p,
StackedDRG32GiBSeal | StackedDRG32GiBWindowPoSt => Ok(StackedDRG32GiBWindowPoSt),
StackedDRG2KiBSeal | StackedDRG2KiBWindowPoSt => Ok(StackedDRG2KiBWindowPoSt),
StackedDRG8MiBSeal | StackedDRG8MiBWindowPoSt => Ok(StackedDRG8MiBWindowPoSt),
StackedDRG512MiBSeal | StackedDRG512MiBWindowPoSt => Ok(StackedDRG512MiBWindowPoSt),
_ => Err(format!(
"Unsupported mapping from {:?} to PoSt-window RegisteredProof",
self
)),
}
}

Expand All @@ -54,11 +97,22 @@ impl RegisteredProof {
pub fn registered_seal_proof(self) -> RegisteredProof {
use RegisteredProof::*;
match self {
StackedDRG32GiBPoSt => StackedDRG32GiBSeal,
StackedDRG2KiBPoSt => StackedDRG2KiBSeal,
StackedDRG8MiBPoSt => StackedDRG8MiBSeal,
StackedDRG512MiBPoSt => StackedDRG512MiBSeal,
p => p,
StackedDRG32GiBSeal
| StackedDRG32GiBPoSt
| StackedDRG32GiBWindowPoSt
| StackedDRG32GiBWinningPoSt => StackedDRG32GiBSeal,
StackedDRG2KiBSeal
| StackedDRG2KiBPoSt
| StackedDRG2KiBWindowPoSt
| StackedDRG2KiBWinningPoSt => StackedDRG2KiBSeal,
StackedDRG8MiBSeal
| StackedDRG8MiBPoSt
| StackedDRG8MiBWindowPoSt
| StackedDRG8MiBWinningPoSt => StackedDRG8MiBSeal,
StackedDRG512MiBSeal
| StackedDRG512MiBPoSt
| StackedDRG512MiBWindowPoSt
| StackedDRG512MiBWinningPoSt => StackedDRG512MiBSeal,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/sector/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use clock::ChainEpoch;
pub type SealRandomness = Randomness;
pub type InteractiveSealRandomness = Randomness;

/// SealVerifyInfo is the structure of all the information a verifier
/// needs to verify a Seal.
/// Information needed to verify a seal proof.
#[derive(Debug, PartialEq, Default)]
pub struct SealVerifyInfo {
pub sector_id: SectorID,
// TODO revisit issue to remove this: https://github.com/filecoin-project/specs-actors/issues/276
pub on_chain: OnChainSealVerifyInfo,
pub randomness: SealRandomness,
pub interactive_randomness: InteractiveSealRandomness,
Expand Down
Loading

0 comments on commit ff5260a

Please sign in to comment.