Skip to content

Commit 8076305

Browse files
authored
replace simple_qa_power with extensible flags (#1395)
* replace simple_qa_power with extensible flags * use u32 for SectorOnChainInfoFlags
1 parent 6d73502 commit 8076305

File tree

7 files changed

+30
-15
lines changed

7 files changed

+30
-15
lines changed

Cargo.lock

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ members = [
6464
# Common
6565
serde = { version = "1.0.136", features = ["derive"] }
6666
anyhow = "1.0.65"
67+
bitflags = "2.4.0"
6768
num = { version = "0.4", features = ["serde"] }
6869
num-derive = "0.3.3"
6970
num-traits = "0.2.14"

actors/miner/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ keywords = ["filecoin", "web3", "wasm"]
1414
crate-type = ["cdylib", "lib"]
1515

1616
[dependencies]
17+
bitflags = { workspace = true }
1718
fil_actors_runtime = { workspace = true }
1819
frc42_dispatch = { workspace = true }
1920
fvm_shared = { workspace = true }

actors/miner/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3415,7 +3415,7 @@ fn extend_sector_committment(
34153415
validate_extended_expiration(policy, curr_epoch, new_expiration, sector)?;
34163416

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

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

3742-
new_sector_info.simple_qa_power = true;
3742+
new_sector_info.flags.set(SectorOnChainInfoFlags::SIMPLE_QA_POWER, true);
37433743
new_sector_info.sealed_cid = activated_data.seal_cid;
37443744
new_sector_info.sector_key_cid = match new_sector_info.sector_key_cid {
37453745
None => Some(sector_info.sealed_cid),
@@ -4841,7 +4841,7 @@ fn activate_new_sector_infos(
48414841
power_base_epoch: activation_epoch,
48424842
replaced_day_reward: TokenAmount::zero(),
48434843
sector_key_cid: None,
4844-
simple_qa_power: true,
4844+
flags: SectorOnChainInfoFlags::SIMPLE_QA_POWER,
48454845
};
48464846

48474847
new_sector_numbers.push(new_sector_info.sector_number);

actors/miner/src/types.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use fvm_shared::sector::{
1818
use fvm_shared::smooth::FilterEstimate;
1919

2020
use fil_actors_runtime::DealWeight;
21+
use serde::{Deserialize, Serialize};
2122

2223
use crate::commd::CompactCommD;
2324
use crate::ext::verifreg::ClaimID;
@@ -357,8 +358,17 @@ pub struct SectorOnChainInfo {
357358
pub replaced_day_reward: TokenAmount,
358359
/// The original SealedSectorCID, only gets set on the first ReplicaUpdate
359360
pub sector_key_cid: Option<Cid>,
360-
// Flag for QA power mechanism introduced in fip 0045
361-
pub simple_qa_power: bool,
361+
/// Additional flags, see [`SectorOnChainInfoFlags`]
362+
pub flags: SectorOnChainInfoFlags,
363+
}
364+
365+
bitflags::bitflags! {
366+
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default, Debug)]
367+
#[serde(transparent)]
368+
pub struct SectorOnChainInfoFlags: u32 {
369+
/// QA power mechanism introduced in FIP-0045
370+
const SIMPLE_QA_POWER = 0x1;
371+
}
362372
}
363373

364374
#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize_tuple, Deserialize_tuple)]

integration_tests/src/tests/extend_sectors_test.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use fil_actor_market::{DealMetaArray, State as MarketState};
1010
use fil_actor_miner::{
1111
max_prove_commit_duration, power_for_sector, ExpirationExtension, ExpirationExtension2,
1212
ExtendSectorExpiration2Params, ExtendSectorExpirationParams, Method as MinerMethod, PowerPair,
13-
ProveReplicaUpdatesParams2, ReplicaUpdate2, SectorClaim, Sectors, State as MinerState,
13+
ProveReplicaUpdatesParams2, ReplicaUpdate2, SectorClaim, SectorOnChainInfoFlags, Sectors,
14+
State as MinerState,
1415
};
1516
use fil_actor_verifreg::Method as VerifregMethod;
1617
use fil_actors_runtime::runtime::Policy;
@@ -191,7 +192,7 @@ pub fn extend_legacy_sector_with_deals_test(v: &dyn VM, do_extend2: bool) {
191192
// Note: we don't need to explicitly set verified weight using the legacy method
192193
// because legacy and simple qa power deal weight calculations line up for fully packed sectors
193194
// We do need to set simple_qa_power to false
194-
sector_info.simple_qa_power = false;
195+
sector_info.flags.set(SectorOnChainInfoFlags::SIMPLE_QA_POWER, false);
195196

196197
// Manually craft state to match legacy sectors
197198
mutate_state(v, &miner_id, |st: &mut MinerState| {

integration_tests/src/tests/replica_update_test.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ use fil_actor_market::Method as MarketMethod;
1616
use fil_actor_miner::{
1717
power_for_sector, DisputeWindowedPoStParams, ExpirationExtension, ExtendSectorExpirationParams,
1818
Method as MinerMethod, PowerPair, ProveCommitSectorParams, ProveReplicaUpdatesParams,
19-
ProveReplicaUpdatesParams2, ReplicaUpdate, ReplicaUpdate2, SectorOnChainInfo, Sectors,
20-
State as MinerState, TerminateSectorsParams, TerminationDeclaration, SECTORS_AMT_BITWIDTH,
19+
ProveReplicaUpdatesParams2, ReplicaUpdate, ReplicaUpdate2, SectorOnChainInfo,
20+
SectorOnChainInfoFlags, Sectors, State as MinerState, TerminateSectorsParams,
21+
TerminationDeclaration, SECTORS_AMT_BITWIDTH,
2122
};
2223
use fil_actor_verifreg::Method as VerifregMethod;
2324
use fil_actors_runtime::runtime::Policy;
@@ -665,7 +666,7 @@ pub fn extend_after_upgrade_test(v: &dyn VM) {
665666

666667
let sector_number = sector_info.sector_number;
667668
let mut legacy_sector = sector_info;
668-
legacy_sector.simple_qa_power = false;
669+
legacy_sector.flags.set(SectorOnChainInfoFlags::SIMPLE_QA_POWER, false);
669670

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

0 commit comments

Comments
 (0)