Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update power, reward and market actors, rt and registered proofs relative to miner actor #458

Merged
merged 15 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blockchain/chain/src/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ where
.get::<PowerState>(&act.state)
.map_err(|e| e.to_string())?
{
tpow = state.total_network_power;
tpow = state.total_quality_adj_power;
}
}
let log2_p = if tpow > BigUint::zero() {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/state_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ where
let ps: power::State = self.load_actor_state(&*STORAGE_POWER_ACTOR_ADDR, state_cid)?;

if let Some(claim) = ps.get_claim(self.bs.as_ref(), addr)? {
Ok((claim.power, ps.total_network_power))
Ok((claim.raw_byte_power, claim.quality_adj_power))
} else {
Err(Error::State(
"Failed to retrieve claimed power from actor state".to_owned(),
Expand Down
9 changes: 6 additions & 3 deletions types/src/sector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ pub use self::registered_proof::*;
pub use self::seal::*;

use encoding::{repr::*, tuple::*};
use num_bigint::BigInt;
use num_bigint::BigUint;
use num_derive::FromPrimitive;
use std::fmt;
use vm::ActorID;

pub type SectorNumber = u64;

/// Unit of storage power (measured in bytes)
pub type StoragePower = BigInt;
pub type StoragePower = BigUint;

pub type SectorQuality = BigUint;
dutterbutter marked this conversation as resolved.
Show resolved Hide resolved

/// SectorSize indicates one of a set of possible sizes in the network.
#[derive(Clone, Debug, PartialEq, Copy, FromPrimitive, Serialize_repr, Deserialize_repr)]
Expand All @@ -31,6 +33,7 @@ pub enum SectorSize {
_8MiB = 8 << 20,
_512MiB = 512 << 20,
_32GiB = 32 << 30,
_64GiB = 2 * (32 << 30),
}

impl fmt::Display for SectorSize {
Expand All @@ -40,7 +43,7 @@ impl fmt::Display for SectorSize {
}

/// Sector ID which contains the sector number and the actor ID for the miner.
#[derive(Debug, Default, PartialEq, Serialize_tuple, Deserialize_tuple)]
#[derive(Clone, Debug, Default, PartialEq, Serialize_tuple, Deserialize_tuple)]
pub struct SectorID {
pub miner: ActorID,
pub number: SectorNumber,
Expand Down
45 changes: 45 additions & 0 deletions types/src/sector/registered_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ pub enum RegisteredProof {

StackedDRG32GiBWinningPoSt = 15,
StackedDRG32GiBWindowPoSt = 16,

StackedDRG64GiBSeal = 17,

StackedDRG64GiBWinningPoSt = 18,
StackedDRG64GiBWindowPoSt = 19,
}

impl RegisteredProof {
Expand All @@ -44,6 +49,9 @@ impl RegisteredProof {
pub fn sector_size(self) -> SectorSize {
use RegisteredProof::*;
match self {
StackedDRG64GiBSeal | StackedDRG64GiBWindowPoSt | StackedDRG64GiBWinningPoSt => {
SectorSize::_64GiB
}
StackedDRG32GiBSeal
| StackedDRG32GiBPoSt
| StackedDRG32GiBWindowPoSt
Expand All @@ -63,11 +71,38 @@ impl RegisteredProof {
}
}

/// Returns the partition size, in sectors, associated with a proof type.
/// The partition size is the number of sectors proven in a single PoSt proof.
pub fn window_post_partitions_sector(self) -> u64 {
// Resolve to seal proof and then compute size from that.
use RegisteredProof::*;
match self {
StackedDRG64GiBSeal | StackedDRG64GiBWindowPoSt | StackedDRG64GiBWinningPoSt => 2300,
StackedDRG32GiBSeal
| StackedDRG32GiBPoSt
| StackedDRG32GiBWindowPoSt
| StackedDRG32GiBWinningPoSt => 2349,
StackedDRG2KiBSeal
| StackedDRG2KiBPoSt
| StackedDRG2KiBWindowPoSt
| StackedDRG2KiBWinningPoSt => 2,
StackedDRG8MiBSeal
| StackedDRG8MiBPoSt
| StackedDRG8MiBWindowPoSt
| StackedDRG8MiBWinningPoSt => 2,
StackedDRG512MiBSeal
| StackedDRG512MiBPoSt
| StackedDRG512MiBWindowPoSt
| StackedDRG512MiBWinningPoSt => 2,
}
}

/// 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 {
StackedDRG64GiBSeal | StackedDRG64GiBWindowPoSt => Ok(StackedDRG64GiBWindowPoSt),
StackedDRG32GiBSeal | StackedDRG32GiBWinningPoSt => Ok(StackedDRG32GiBWinningPoSt),
StackedDRG2KiBSeal | StackedDRG2KiBWinningPoSt => Ok(StackedDRG2KiBWinningPoSt),
StackedDRG8MiBSeal | StackedDRG8MiBWinningPoSt => Ok(StackedDRG8MiBWinningPoSt),
Expand All @@ -84,6 +119,7 @@ impl RegisteredProof {
pub fn registered_window_post_proof(self) -> Result<RegisteredProof, String> {
use RegisteredProof::*;
match self {
StackedDRG64GiBSeal | StackedDRG64GiBWindowPoSt => Ok(StackedDRG64GiBWindowPoSt),
StackedDRG32GiBSeal | StackedDRG32GiBWindowPoSt => Ok(StackedDRG32GiBWindowPoSt),
StackedDRG2KiBSeal | StackedDRG2KiBWindowPoSt => Ok(StackedDRG2KiBWindowPoSt),
StackedDRG8MiBSeal | StackedDRG8MiBWindowPoSt => Ok(StackedDRG8MiBWindowPoSt),
Expand All @@ -100,6 +136,9 @@ impl RegisteredProof {
pub fn registered_seal_proof(self) -> RegisteredProof {
use RegisteredProof::*;
match self {
StackedDRG64GiBSeal | StackedDRG64GiBWindowPoSt | StackedDRG64GiBWinningPoSt => {
StackedDRG64GiBSeal
}
StackedDRG32GiBSeal
| StackedDRG32GiBPoSt
| StackedDRG32GiBWindowPoSt
Expand Down Expand Up @@ -131,6 +170,9 @@ impl From<RegisteredProof> for RegisteredSealProof {
use RegisteredProof::*;

match p {
StackedDRG64GiBSeal | StackedDRG64GiBWindowPoSt | StackedDRG64GiBWinningPoSt => {
RegisteredSealProof::StackedDrg64GiBV1
}
StackedDRG32GiBSeal
| StackedDRG32GiBPoSt
| StackedDRG32GiBWindowPoSt
Expand All @@ -156,6 +198,9 @@ impl From<RegisteredProof> for RegisteredPoStProof {
use RegisteredProof::*;

match p {
StackedDRG64GiBSeal | StackedDRG64GiBWindowPoSt | StackedDRG64GiBWinningPoSt => {
RegisteredPoStProof::StackedDrgWindow64GiBV1
}
StackedDRG32GiBSeal
| StackedDRG32GiBPoSt
| StackedDRG32GiBWindowPoSt
Expand Down
10 changes: 5 additions & 5 deletions types/src/sector/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ pub type SealRandomness = Randomness;
pub type InteractiveSealRandomness = Randomness;

/// Information needed to verify a seal proof.
#[derive(Debug, PartialEq, Default, Serialize_tuple, Deserialize_tuple)]
#[derive(Clone, Debug, PartialEq, Default, Serialize_tuple, Deserialize_tuple)]
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 on_chain: SealVerifyParams,
pub randomness: SealRandomness,
pub interactive_randomness: InteractiveSealRandomness,
pub unsealed_cid: Cid,
}

/// OnChainSealVerifyInfo is the structure of information that must be sent with
/// SealVerifyParams is the structure of information that must be sent with
/// a message to commit a sector. Most of this information is not needed in the
/// state tree but will be verified in sm.CommitSector. See SealCommitment for
/// data stored on the state tree for each sector.
#[derive(Debug, PartialEq, Default, Serialize_tuple, Deserialize_tuple)]
pub struct OnChainSealVerifyInfo {
#[derive(Clone, Debug, PartialEq, Default, Serialize_tuple, Deserialize_tuple)]
pub struct SealVerifyParams {
pub sealed_cid: Cid,
pub interactive_epoch: ChainEpoch,
pub registered_proof: RegisteredProof,
Expand Down
7 changes: 3 additions & 4 deletions types/src/sector/serde_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use super::{
OnChainSealVerifyInfo, OnChainWindowPoStVerifyInfo, PoStProof, SealVerifyInfo,
WindowPoStVerifyInfo,
OnChainWindowPoStVerifyInfo, PoStProof, SealVerifyInfo, SealVerifyParams, WindowPoStVerifyInfo,
};
use cid::{multihash::Identity, Cid};
use encoding::{from_slice, to_vec};
Expand All @@ -14,12 +13,12 @@ fn empty_cid() -> Cid {

#[test]
fn default_serializations() {
let ocs = OnChainSealVerifyInfo {
let ocs = SealVerifyParams {
sealed_cid: empty_cid(),
..Default::default()
};
let bz = to_vec(&ocs).unwrap();
assert_eq!(from_slice::<OnChainSealVerifyInfo>(&bz).unwrap(), ocs);
assert_eq!(from_slice::<SealVerifyParams>(&bz).unwrap(), ocs);

let s = SealVerifyInfo {
unsealed_cid: empty_cid(),
Expand Down
5 changes: 5 additions & 0 deletions vm/actor/src/builtin/market/deal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ use vm::TokenAmount;
pub struct DealProposal {
pub piece_cid: Cid,
pub piece_size: PaddedPieceSize,
pub verified_deal: bool,
pub client: Address,
pub provider: Address,

// Nominal start epoch. Deal payment is linear between StartEpoch and EndEpoch,
// with total amount StoragePricePerEpoch * (EndEpoch - StartEpoch).
// Storage deal must appear in a sealed (proven) sector no later than StartEpoch,
// otherwise it is invalid.
pub start_epoch: ChainEpoch,
pub end_epoch: ChainEpoch,
#[serde(with = "biguint_ser")]
Expand Down
35 changes: 16 additions & 19 deletions vm/actor/src/builtin/market/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use self::policy::*;
pub use self::state::State;
pub use self::types::*;
use crate::{
make_map, request_miner_control_addrs, BalanceTable, DealID, DealWeight, OptionalEpoch,
SetMultimap, BURNT_FUNDS_ACTOR_ADDR, CALLER_TYPES_SIGNABLE, MINER_ACTOR_CODE_ID,
SYSTEM_ACTOR_ADDR,
make_map, request_miner_control_addrs, BalanceTable, DealID, OptionalEpoch, SetMultimap,
BURNT_FUNDS_ACTOR_ADDR, CALLER_TYPES_SIGNABLE, MINER_ACTOR_CODE_ID, SYSTEM_ACTOR_ADDR,
};
use address::Address;
use cid::Cid;
Expand All @@ -23,8 +22,7 @@ use fil_types::PieceInfo;
use ipld_amt::Amt;
use ipld_blockstore::BlockStore;
use message::Message;
use num_bigint::bigint_ser::BigIntSer;
use num_bigint::{BigInt, BigUint};
use num_bigint::BigUint;
use num_derive::FromPrimitive;
use num_traits::{FromPrimitive, Zero};
use runtime::{ActorCode, Runtime};
Expand Down Expand Up @@ -312,15 +310,15 @@ impl Actor {
fn verify_deals_on_sector_prove_commit<BS, RT>(
rt: &mut RT,
params: VerifyDealsOnSectorProveCommitParams,
) -> Result<DealWeight, ActorError>
) -> Result<VerifyDealsOnSectorProveCommitReturn, ActorError>
where
BS: BlockStore,
RT: Runtime<BS>,
{
rt.validate_immediate_caller_type(std::iter::once(&*MINER_ACTOR_CODE_ID))?;
let miner_addr = *rt.message().from();
let mut total_deal_space_time = BigInt::zero();
let mut deal_weight = BigInt::zero();
let mut total_deal_space_time = BigUint::zero();
let mut total_verified_deal_space_time = BigUint::zero();

rt.transaction::<State, Result<(), ActorError>, _>(|st, rt| {
// if there are no dealIDs, it is a CommittedCapacity sector
Expand Down Expand Up @@ -365,24 +363,23 @@ impl Actor {

// compute deal weight
let deal_space_time = proposal.duration() * proposal.piece_size.0;
total_deal_space_time += deal_space_time;
if proposal.verified_deal {
total_verified_deal_space_time += deal_space_time;
} else {
total_deal_space_time += deal_space_time;
}
}
st.states = states
.flush()
.map_err(|e| ActorError::new(ExitCode::ErrIllegalState, e.into()))?;

let epoch_value = params
.sector_expiry
.checked_sub(rt.curr_epoch())
.unwrap_or(1u64);

let sector_space_time = BigInt::from(params.sector_size as u64) * epoch_value;
deal_weight = total_deal_space_time / sector_space_time;

Ok(())
})??;

Ok(deal_weight)
Ok(VerifyDealsOnSectorProveCommitReturn {
deal_weight: total_deal_space_time,
verified_deal_weight: total_verified_deal_space_time,
})
}

/// Terminate a set of deals in response to their containing sector being terminated.
Expand Down Expand Up @@ -685,7 +682,7 @@ impl ActorCode for Actor {
}
Some(Method::VerifyDealsOnSectorProveCommit) => {
let res = Self::verify_deals_on_sector_prove_commit(rt, params.deserialize()?)?;
Ok(Serialized::serialize(BigIntSer(&res))?)
Ok(Serialized::serialize(&res)?)
}
Some(Method::OnMinerSectorsTerminate) => {
Self::on_miners_sector_terminate(rt, params.deserialize()?)?;
Expand Down
12 changes: 10 additions & 2 deletions vm/actor/src/builtin/market/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use super::deal::ClientDealProposal;
use crate::DealWeight;
use address::Address;
use clock::ChainEpoch;
use encoding::tuple::*;
use fil_types::{RegisteredProof, SectorSize};
use fil_types::RegisteredProof;
use num_bigint::biguint_ser;
use vm::{DealID, TokenAmount};

Expand Down Expand Up @@ -39,10 +40,17 @@ pub struct PublishStorageDealsReturn {
#[derive(Serialize_tuple, Deserialize_tuple)]
pub struct VerifyDealsOnSectorProveCommitParams {
pub deal_ids: Vec<DealID>,
pub sector_size: SectorSize,
pub sector_expiry: ChainEpoch,
}

#[derive(Serialize_tuple, Deserialize_tuple)]
pub struct VerifyDealsOnSectorProveCommitReturn {
#[serde(with = "biguint_ser")]
pub deal_weight: DealWeight,
#[serde(with = "biguint_ser")]
pub verified_deal_weight: DealWeight,
}

#[derive(Serialize_tuple, Deserialize_tuple)]
pub struct ComputeDataCommitmentParams {
pub deal_ids: Vec<DealID>,
Expand Down
11 changes: 6 additions & 5 deletions vm/actor/src/builtin/miner/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use fil_types::{RegisteredProof, SectorInfo, SectorNumber, SectorSize};
use ipld_amt::{Amt, Error as AmtError};
use ipld_blockstore::BlockStore;
use ipld_hamt::{Error as HamtError, Hamt};
use num_bigint::bigint_ser;
use num_bigint::biguint_ser;
use num_bigint::BigInt;
use num_bigint::BigUint;
use runtime::Runtime;
use vm::{DealID, TokenAmount};

Expand Down Expand Up @@ -299,8 +298,8 @@ pub struct SectorOnChainInfo {
pub activation_epoch: ChainEpoch,

/// Integral of active deals over sector lifetime, 0 if CommittedCapacity sector
#[serde(with = "bigint_ser")]
pub deal_weight: BigInt,
#[serde(with = "biguint_ser")]
pub deal_weight: BigUint,

/// Fixed pledge collateral requirement determined at activation
#[serde(with = "biguint_ser")]
Expand All @@ -316,10 +315,12 @@ fn as_storage_weight_desc(
sector_size: SectorSize,
sector_info: SectorOnChainInfo,
) -> power::SectorStorageWeightDesc {
// TODO update verified_deal_weight
power::SectorStorageWeightDesc {
sector_size,
deal_weight: sector_info.deal_weight,
deal_weight: sector_info.deal_weight.clone(), // temp clone
dutterbutter marked this conversation as resolved.
Show resolved Hide resolved
duration: sector_info.info.expiration - sector_info.activation_epoch,
verified_deal_weight: sector_info.deal_weight, // temp
dutterbutter marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading