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

replace simple_qa_power with extensible flags #1395

Merged
merged 2 commits into from
Sep 2, 2023
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
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ members = [
# Common
serde = { version = "1.0.136", features = ["derive"] }
anyhow = "1.0.65"
bitflags = "2.4.0"
num = { version = "0.4", features = ["serde"] }
num-derive = "0.3.3"
num-traits = "0.2.14"
Expand Down
1 change: 1 addition & 0 deletions actors/miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ keywords = ["filecoin", "web3", "wasm"]
crate-type = ["cdylib", "lib"]

[dependencies]
bitflags = { workspace = true }
fil_actors_runtime = { workspace = true }
frc42_dispatch = { workspace = true }
fvm_shared = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions actors/miner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3415,7 +3415,7 @@ fn extend_sector_committment(
validate_extended_expiration(policy, curr_epoch, new_expiration, sector)?;

// all simple_qa_power sectors with VerifiedDealWeight > 0 MUST check all claims
if sector.simple_qa_power {
if sector.flags.contains(SectorOnChainInfoFlags::SIMPLE_QA_POWER) {
extend_simple_qap_sector(
policy,
new_expiration,
Expand All @@ -3440,7 +3440,7 @@ fn extend_sector_committment_legacy(
validate_extended_expiration(policy, curr_epoch, new_expiration, sector)?;

// it is an error to do legacy sector expiration on simple-qa power sectors with deal weight
if sector.simple_qa_power
if sector.flags.contains(SectorOnChainInfoFlags::SIMPLE_QA_POWER)
&& (sector.verified_deal_weight > BigInt::zero() || sector.deal_weight > BigInt::zero())
{
return Err(actor_error!(
Expand Down Expand Up @@ -3739,7 +3739,7 @@ fn update_existing_sector_info(
) -> SectorOnChainInfo {
let mut new_sector_info = sector_info.clone();

new_sector_info.simple_qa_power = true;
new_sector_info.flags.set(SectorOnChainInfoFlags::SIMPLE_QA_POWER, true);
new_sector_info.sealed_cid = activated_data.seal_cid;
new_sector_info.sector_key_cid = match new_sector_info.sector_key_cid {
None => Some(sector_info.sealed_cid),
Expand Down Expand Up @@ -4841,7 +4841,7 @@ fn activate_new_sector_infos(
power_base_epoch: activation_epoch,
replaced_day_reward: TokenAmount::zero(),
sector_key_cid: None,
simple_qa_power: true,
flags: SectorOnChainInfoFlags::SIMPLE_QA_POWER,
};

new_sector_numbers.push(new_sector_info.sector_number);
Expand Down
14 changes: 12 additions & 2 deletions actors/miner/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use fvm_shared::sector::{
use fvm_shared::smooth::FilterEstimate;

use fil_actors_runtime::DealWeight;
use serde::{Deserialize, Serialize};

use crate::commd::CompactCommD;
use crate::ext::verifreg::ClaimID;
Expand Down Expand Up @@ -357,8 +358,17 @@ pub struct SectorOnChainInfo {
pub replaced_day_reward: TokenAmount,
/// The original SealedSectorCID, only gets set on the first ReplicaUpdate
pub sector_key_cid: Option<Cid>,
// Flag for QA power mechanism introduced in fip 0045
pub simple_qa_power: bool,
/// Additional flags, see [`SectorOnChainInfoFlags`]
pub flags: SectorOnChainInfoFlags,
}

bitflags::bitflags! {
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Debug)]
#[serde(transparent)]
pub struct SectorOnChainInfoFlags: u32 {
/// QA power mechanism introduced in FIP-0045
const SIMPLE_QA_POWER = 0x1;
}
}

#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize_tuple, Deserialize_tuple)]
Expand Down
5 changes: 3 additions & 2 deletions integration_tests/src/tests/extend_sectors_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use fil_actor_market::{DealMetaArray, State as MarketState};
use fil_actor_miner::{
max_prove_commit_duration, power_for_sector, ExpirationExtension, ExpirationExtension2,
ExtendSectorExpiration2Params, ExtendSectorExpirationParams, Method as MinerMethod, PowerPair,
ProveReplicaUpdatesParams2, ReplicaUpdate2, SectorClaim, Sectors, State as MinerState,
ProveReplicaUpdatesParams2, ReplicaUpdate2, SectorClaim, SectorOnChainInfoFlags, Sectors,
State as MinerState,
};
use fil_actor_verifreg::Method as VerifregMethod;
use fil_actors_runtime::runtime::Policy;
Expand Down Expand Up @@ -191,7 +192,7 @@ pub fn extend_legacy_sector_with_deals_test(v: &dyn VM, do_extend2: bool) {
// Note: we don't need to explicitly set verified weight using the legacy method
// because legacy and simple qa power deal weight calculations line up for fully packed sectors
// We do need to set simple_qa_power to false
sector_info.simple_qa_power = false;
sector_info.flags.set(SectorOnChainInfoFlags::SIMPLE_QA_POWER, false);

// Manually craft state to match legacy sectors
mutate_state(v, &miner_id, |st: &mut MinerState| {
Expand Down
7 changes: 4 additions & 3 deletions integration_tests/src/tests/replica_update_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use fil_actor_market::Method as MarketMethod;
use fil_actor_miner::{
power_for_sector, DisputeWindowedPoStParams, ExpirationExtension, ExtendSectorExpirationParams,
Method as MinerMethod, PowerPair, ProveCommitSectorParams, ProveReplicaUpdatesParams,
ProveReplicaUpdatesParams2, ReplicaUpdate, ReplicaUpdate2, SectorOnChainInfo, Sectors,
State as MinerState, TerminateSectorsParams, TerminationDeclaration, SECTORS_AMT_BITWIDTH,
ProveReplicaUpdatesParams2, ReplicaUpdate, ReplicaUpdate2, SectorOnChainInfo,
SectorOnChainInfoFlags, Sectors, State as MinerState, TerminateSectorsParams,
TerminationDeclaration, SECTORS_AMT_BITWIDTH,
};
use fil_actor_verifreg::Method as VerifregMethod;
use fil_actors_runtime::runtime::Policy;
Expand Down Expand Up @@ -665,7 +666,7 @@ pub fn extend_after_upgrade_test(v: &dyn VM) {

let sector_number = sector_info.sector_number;
let mut legacy_sector = sector_info;
legacy_sector.simple_qa_power = false;
legacy_sector.flags.set(SectorOnChainInfoFlags::SIMPLE_QA_POWER, false);

let blockstore = &DynBlockstore::wrap(v.blockstore());
mutate_state(v, &miner_id, |st: &mut MinerState| {
Expand Down