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

Move some constants & types out of fvm_shared #1517

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 actors/market/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ log = { workspace = true }
num-derive = { workspace = true }
num-traits = { workspace = true }
serde = { workspace = true }
lazy_static = { workspace = true }

[dev-dependencies]
fil_actors_runtime = { workspace = true, features = ["test_utils", "sector-default"] }
Expand All @@ -41,7 +42,6 @@ fvm_ipld_amt = { workspace = true }
multihash = { workspace = true }
regex = { workspace = true }
itertools = { workspace = true }
lazy_static = { workspace = true }

[features]
fil-actor = ["fil_actors_runtime/fil-actor"]
8 changes: 7 additions & 1 deletion actors/market/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ use fvm_shared::clock::ChainEpoch;
use fvm_shared::econ::TokenAmount;
use fvm_shared::piece::PaddedPieceSize;
use fvm_shared::sector::StoragePower;
use fvm_shared::TOTAL_FILECOIN;
use lazy_static::lazy_static;
use num_traits::Zero;

pub mod detail {
/// Maximum length of a deal label.
pub const DEAL_MAX_LABEL_SIZE: usize = 256;
}

lazy_static! {
/// Total (assumed) Filecoin available to the network. This is only used to bound the maximum
/// deal collateral and price.
pub static ref TOTAL_FILECOIN: TokenAmount = TokenAmount::from_whole(2_000_000_000);
}

/// Bounds (inclusive) on deal duration.
pub(super) fn deal_duration_bounds(_size: PaddedPieceSize) -> (ChainEpoch, ChainEpoch) {
(180 * EPOCHS_IN_DAY, 1278 * EPOCHS_IN_DAY)
Expand Down
3 changes: 1 addition & 2 deletions actors/market/tests/publish_storage_deals_failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use fvm_shared::piece::PaddedPieceSize;

use fvm_shared::TOTAL_FILECOIN;

use cid::Cid;
use fil_actor_market::ext::account::{AuthenticateMessageParams, AUTHENTICATE_MESSAGE_METHOD};
use fil_actor_market::policy::TOTAL_FILECOIN;

mod harness;
use fvm_ipld_encoding::ipld_block::IpldBlock;
Expand Down
8 changes: 7 additions & 1 deletion actors/miner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use anyhow::{anyhow, Error};
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use cid::multihash::Code::Blake2b256;
use cid::Cid;
use fil_actors_runtime::runtime::policy_constants::MAX_SECTOR_NUMBER;
use fvm_ipld_bitfield::{BitField, Validate};
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::ipld_block::IpldBlock;
Expand All @@ -24,7 +25,12 @@ use fvm_shared::error::*;
use fvm_shared::piece::PieceInfo;
use fvm_shared::randomness::*;
use fvm_shared::reward::ThisEpochRewardReturn;
use fvm_shared::sector::*;
use fvm_shared::sector::{
AggregateSealVerifyInfo, AggregateSealVerifyProofAndInfos, InteractiveSealRandomness,
PoStProof, RegisteredAggregateProof, RegisteredPoStProof, RegisteredSealProof,
RegisteredUpdateProof, ReplicaUpdateInfo, SealRandomness, SealVerifyInfo, SectorID, SectorInfo,
SectorNumber, SectorSize, StoragePower, WindowPoStVerifyInfo,
};
use fvm_shared::smooth::FilterEstimate;
use fvm_shared::{ActorID, MethodNum, METHOD_CONSTRUCTOR, METHOD_SEND};
use itertools::Itertools;
Expand Down
16 changes: 7 additions & 9 deletions actors/miner/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use fvm_shared::bigint::{BigInt, Integer};
use fvm_shared::clock::ChainEpoch;
use fvm_shared::commcid::{FIL_COMMITMENT_SEALED, POSEIDON_BLS12_381_A1_FC1};
use fvm_shared::econ::TokenAmount;
use fvm_shared::sector::{
RegisteredPoStProof, RegisteredSealProof, SectorQuality, SectorSize, StoragePower,
};
use fvm_shared::sector::{RegisteredPoStProof, RegisteredSealProof, SectorSize, StoragePower};
use lazy_static::lazy_static;

use super::types::SectorOnChainInfo;
Expand Down Expand Up @@ -110,16 +108,16 @@ pub const MIN_SECTOR_EXPIRATION: i64 = 180 * EPOCHS_IN_DAY;

/// DealWeight and VerifiedDealWeight are spacetime occupied by regular deals and verified deals in a sector.
/// Sum of DealWeight and VerifiedDealWeight should be less than or equal to total SpaceTime of a sector.
/// Sectors full of VerifiedDeals will have a SectorQuality of VerifiedDealWeightMultiplier/QualityBaseMultiplier.
/// Sectors full of Deals will have a SectorQuality of DealWeightMultiplier/QualityBaseMultiplier.
/// Sectors with neither will have a SectorQuality of QualityBaseMultiplier/QualityBaseMultiplier.
/// SectorQuality of a sector is a weighted average of multipliers based on their proportions.
/// Sectors full of VerifiedDeals will have a BigInt of VerifiedDealWeightMultiplier/QualityBaseMultiplier.
/// Sectors full of Deals will have a BigInt of DealWeightMultiplier/QualityBaseMultiplier.
/// Sectors with neither will have a BigInt of QualityBaseMultiplier/QualityBaseMultiplier.
/// BigInt of a sector is a weighted average of multipliers based on their proportions.
pub fn quality_for_weight(
size: SectorSize,
duration: ChainEpoch,
deal_weight: &DealWeight,
verified_weight: &DealWeight,
) -> SectorQuality {
) -> BigInt {
let sector_space_time = BigInt::from(size as u64) * BigInt::from(duration);
let total_deal_space_time = deal_weight + verified_weight;

Expand All @@ -129,7 +127,7 @@ pub fn quality_for_weight(
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 =
let scaled_up_weighted_sum_space_time: BigInt =
weighted_sum_space_time << SECTOR_QUALITY_PRECISION;

scaled_up_weighted_sum_space_time
Expand Down
3 changes: 2 additions & 1 deletion actors/miner/src/sectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use std::collections::BTreeSet;

use anyhow::anyhow;
use cid::Cid;
use fil_actors_runtime::runtime::policy_constants::MAX_SECTOR_NUMBER;
use fil_actors_runtime::{actor_error, ActorDowncast, ActorError, Array, AsActorError};
use fvm_ipld_amt::Error as AmtError;
use fvm_ipld_bitfield::BitField;
use fvm_ipld_blockstore::Blockstore;
use fvm_shared::error::ExitCode;
use fvm_shared::sector::{SectorNumber, MAX_SECTOR_NUMBER};
use fvm_shared::sector::SectorNumber;

use super::SectorOnChainInfo;

Expand Down
3 changes: 2 additions & 1 deletion actors/miner/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::ops::Neg;
use anyhow::{anyhow, Error};
use cid::multihash::Code;
use cid::Cid;
use fil_actors_runtime::runtime::policy_constants::MAX_SECTOR_NUMBER;
use fil_actors_runtime::runtime::Policy;
use fil_actors_runtime::{
actor_error, make_empty_map, make_map_with_root_and_bitwidth, u64_key, ActorDowncast,
Expand All @@ -24,7 +25,7 @@ use fvm_shared::address::Address;
use fvm_shared::clock::{ChainEpoch, QuantSpec, EPOCH_UNDEFINED};
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use fvm_shared::sector::{RegisteredPoStProof, SectorNumber, SectorSize, MAX_SECTOR_NUMBER};
use fvm_shared::sector::{RegisteredPoStProof, SectorNumber, SectorSize};
use fvm_shared::{ActorID, HAMT_BIT_WIDTH};
use itertools::Itertools;
use num_traits::Zero;
Expand Down
3 changes: 2 additions & 1 deletion actors/miner/tests/compact_sector_numbers_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use fil_actors_runtime::test_utils::{expect_abort, MockRuntime};
use fvm_shared::address::Address;
use fvm_shared::sector::MAX_SECTOR_NUMBER;
use fvm_shared::{clock::ChainEpoch, error::ExitCode};

mod util;
Expand All @@ -18,6 +17,8 @@ fn setup() -> (ActorHarness, MockRuntime) {
}

mod compact_sector_numbers_test {
use fil_actors_runtime::runtime::policy_constants::MAX_SECTOR_NUMBER;

use super::*;

#[test]
Expand Down
3 changes: 2 additions & 1 deletion actors/miner/tests/exported_getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use fil_actor_miner::{
Actor, GetAvailableBalanceReturn, GetOwnerReturn, GetSectorSizeReturn,
IsControllingAddressParam, IsControllingAddressReturn, Method,
};
use fil_actors_runtime::runtime::policy_constants::MAX_SECTOR_NUMBER;
use fil_actors_runtime::test_utils::EVM_ACTOR_CODE_ID;
use fil_actors_runtime::INIT_ACTOR_ADDR;
use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_shared::address::Address;
use fvm_shared::{clock::ChainEpoch, econ::TokenAmount, sector::MAX_SECTOR_NUMBER};
use fvm_shared::{clock::ChainEpoch, econ::TokenAmount};
use std::ops::Sub;

mod util;
Expand Down
3 changes: 2 additions & 1 deletion actors/miner/tests/miner_actor_test_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use fil_actor_miner::{
VestSpec,
};
use fil_actors_runtime::network::EPOCHS_IN_DAY;
use fil_actors_runtime::runtime::policy_constants::MAX_SECTOR_NUMBER;
use fil_actors_runtime::test_utils::*;
use fvm_shared::address::Address;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::consensus::{ConsensusFault, ConsensusFaultType};
use fvm_shared::deal::DealID;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use fvm_shared::sector::{RegisteredSealProof, SectorNumber, MAX_SECTOR_NUMBER};
use fvm_shared::sector::{RegisteredSealProof, SectorNumber};

use num_traits::Zero;

Expand Down
6 changes: 4 additions & 2 deletions actors/miner/tests/prove_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use fvm_shared::{
clock::ChainEpoch,
econ::TokenAmount,
error::ExitCode,
sector::{StoragePower, MAX_SECTOR_NUMBER},
sector::StoragePower,
smooth::FilterEstimate,
};
use std::collections::HashMap;
Expand All @@ -13,7 +13,9 @@ use fil_actor_miner::{
initial_pledge_for_power, max_prove_commit_duration, pre_commit_deposit_for_power,
qa_power_for_weight, qa_power_max, PowerPair, PreCommitSectorBatchParams, VestSpec,
};
use fil_actors_runtime::test_utils::make_piece_cid;
use fil_actors_runtime::{
runtime::policy_constants::MAX_SECTOR_NUMBER, test_utils::make_piece_cid,
};
use fil_actors_runtime::{runtime::Runtime, test_utils::expect_abort, DealWeight};
use util::*;

Expand Down
3 changes: 2 additions & 1 deletion actors/miner/tests/sector_number_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use fil_actors_runtime::runtime::Policy;
use fil_actors_runtime::test_utils::*;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::error::ExitCode;
use fvm_shared::sector::MAX_SECTOR_NUMBER;

mod util;
use util::*;
Expand All @@ -16,6 +15,8 @@ use state_harness::*;
const PERIOD_OFFSET: ChainEpoch = 0;

mod sector_number_allocation {
use fil_actors_runtime::runtime::policy_constants::MAX_SECTOR_NUMBER;

use super::*;

#[test]
Expand Down
6 changes: 5 additions & 1 deletion actors/reward/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
use fvm_ipld_encoding::repr::*;
use fvm_ipld_encoding::tuple::*;
use fvm_shared::bigint::bigint_ser;
use fvm_shared::bigint::BigInt;
use fvm_shared::clock::{ChainEpoch, EPOCH_UNDEFINED};
use fvm_shared::econ::TokenAmount;

use fvm_shared::sector::{Spacetime, StoragePower};
use fvm_shared::sector::StoragePower;
use fvm_shared::smooth::{AlphaBetaFilter, FilterEstimate, DEFAULT_ALPHA, DEFAULT_BETA};
use lazy_static::lazy_static;
use num_derive::FromPrimitive;

/// The unit of spacetime committed to the network
pub type Spacetime = BigInt;

use super::logic::*;

lazy_static! {
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/src/tests/commit_post_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cid::Cid;
use export_macro::vm_test;
use fil_actors_runtime::runtime::policy_constants::MAX_SECTOR_NUMBER;
use fvm_ipld_bitfield::BitField;
use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_ipld_encoding::RawBytes;
Expand All @@ -8,7 +9,7 @@ use fvm_shared::bigint::Zero;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use fvm_shared::randomness::Randomness;
use fvm_shared::sector::{PoStProof, RegisteredSealProof, SectorNumber, MAX_SECTOR_NUMBER};
use fvm_shared::sector::{PoStProof, RegisteredSealProof, SectorNumber};

use crate::expects::Expect;
use crate::util::{
Expand Down
10 changes: 8 additions & 2 deletions runtime/src/builtin/network.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use fvm_shared::clock::EPOCH_DURATION_SECONDS;
pub use fvm_shared::BLOCKS_PER_EPOCH as EXPECTED_LEADERS_PER_EPOCH;
/// Assumed epoch duration. If this changes, a large state-migration will need to be run to update
/// expirations, etc.
pub const EPOCH_DURATION_SECONDS: i64 = 30;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commentary: again assumed duration, but isn't something that gets defined by the actors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but changing this would require a massive migration so I think it's OK if the actors assume a specific duration. But I'll comment on that.


pub const SECONDS_IN_HOUR: i64 = 3600;
pub const SECONDS_IN_DAY: i64 = 86400;
pub const SECONDS_IN_YEAR: i64 = 31556925;
pub const EPOCHS_IN_HOUR: i64 = SECONDS_IN_HOUR / EPOCH_DURATION_SECONDS;
pub const EPOCHS_IN_DAY: i64 = SECONDS_IN_DAY / EPOCH_DURATION_SECONDS;
pub const EPOCHS_IN_YEAR: i64 = SECONDS_IN_YEAR / EPOCH_DURATION_SECONDS;

/// This is a protocol constant from Filecoin and depends on expected consensus. Here it is used to
/// determine expected rewards, fault penalties, etc. This will need to be changed if expected
/// consensus ever changes (and, likely, so will pledge, etc.).
pub const EXPECTED_LEADERS_PER_EPOCH: u64 = 5;
1 change: 0 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_hamt::Sha256;
use fvm_ipld_hamt::{BytesKey, Error as HamtError, Hamt};
use fvm_shared::bigint::BigInt;
pub use fvm_shared::BLOCKS_PER_EPOCH as EXPECTED_LEADERS_PER_EPOCH;
use serde::de::DeserializeOwned;
use serde::Serialize;
use unsigned_varint::decode::Error as UVarintError;
Expand Down
6 changes: 5 additions & 1 deletion runtime/src/runtime/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,14 @@ impl Default for Policy {

pub mod policy_constants {
use fvm_shared::clock::ChainEpoch;
use fvm_shared::clock::EPOCH_DURATION_SECONDS;
use fvm_shared::sector::SectorNumber;

use crate::builtin::*;

/// The maximum assignable sector number.
/// Raising this would require modifying our AMT implementation.
pub const MAX_SECTOR_NUMBER: SectorNumber = i64::MAX as u64;

// See comments on Policy struct.
pub const MAX_AGGREGATED_SECTORS: u64 = 819;

Expand Down
Loading