diff --git a/actors/miner/src/lib.rs b/actors/miner/src/lib.rs index e1efb44ce..53ec2b2f4 100644 --- a/actors/miner/src/lib.rs +++ b/actors/miner/src/lib.rs @@ -119,7 +119,7 @@ pub enum Method { ApplyRewards = 14, ReportConsensusFault = 15, WithdrawBalance = 16, - //ConfirmSectorProofsValid = 17, // Deprecated + ConfirmSectorProofsValid = 17, ChangeMultiaddrs = 18, CompactPartitions = 19, CompactSectorNumbers = 20, @@ -2167,6 +2167,70 @@ impl Actor { Ok(ProveCommitSectorsNIReturn { activation_results: result }) } + fn confirm_sector_proofs_valid( + rt: &impl Runtime, + params: ConfirmSectorProofsParams, + ) -> Result<(), ActorError> { + rt.validate_immediate_caller_is(std::iter::once(&STORAGE_POWER_ACTOR_ADDR))?; + + /* validate params */ + // This should be enforced by the power actor. We log here just in case + // something goes wrong. + if params.sectors.len() > ext::power::MAX_MINER_PROVE_COMMITS_PER_EPOCH { + warn!( + "confirmed more prove commits in an epoch than permitted: {} > {}", + params.sectors.len(), + ext::power::MAX_MINER_PROVE_COMMITS_PER_EPOCH + ); + } + let st: State = rt.state()?; + let store = rt.store(); + // This skips missing pre-commits. + let precommited_sectors = + st.find_precommitted_sectors(store, ¶ms.sectors).map_err(|e| { + e.downcast_default( + ExitCode::USR_ILLEGAL_STATE, + "failed to load pre-committed sectors", + ) + })?; + + let data_activations: Vec = + precommited_sectors.iter().map(|x| x.clone().into()).collect(); + let info = get_miner_info(rt.store(), &st)?; + + /* + For all sectors + - CommD was specified at precommit + - If deal IDs were specified at precommit the CommD was checked against them + Therefore CommD on precommit has already been provided and checked so no further processing needed + */ + let compute_commd = false; + let (batch_return, data_activations) = + activate_sectors_deals(rt, &data_activations, compute_commd)?; + let successful_activations = batch_return.successes(&precommited_sectors); + + let pledge_inputs = NetworkPledgeInputs { + network_qap: params.quality_adj_power_smoothed, + network_baseline: params.reward_baseline_power, + circulating_supply: rt.total_fil_circ_supply(), + epoch_reward: params.reward_smoothed, + }; + activate_new_sector_infos( + rt, + successful_activations.clone(), + data_activations.clone(), + &pledge_inputs, + &info, + )?; + + for (pc, data) in successful_activations.iter().zip(data_activations.iter()) { + let unsealed_cid = pc.info.unsealed_cid.0; + emit::sector_activated(rt, pc.info.sector_number, unsealed_cid, &data.pieces)?; + } + + Ok(()) + } + fn check_sector_proven( rt: &impl Runtime, params: CheckSectorProvenParams, @@ -5946,6 +6010,7 @@ impl ActorCode for Actor { ApplyRewards => apply_rewards, ReportConsensusFault => report_consensus_fault, WithdrawBalance|WithdrawBalanceExported => withdraw_balance, + ConfirmSectorProofsValid => confirm_sector_proofs_valid, ChangeMultiaddrs|ChangeMultiaddrsExported => change_multiaddresses, CompactPartitions => compact_partitions, CompactSectorNumbers => compact_sector_numbers, diff --git a/actors/miner/src/types.rs b/actors/miner/src/types.rs index d34ae33e3..8939eb759 100644 --- a/actors/miner/src/types.rs +++ b/actors/miner/src/types.rs @@ -14,7 +14,7 @@ use fvm_shared::piece::PaddedPieceSize; use fvm_shared::randomness::Randomness; use fvm_shared::sector::{ PoStProof, RegisteredAggregateProof, RegisteredPoStProof, RegisteredSealProof, - RegisteredUpdateProof, SectorNumber, SectorSize, + RegisteredUpdateProof, SectorNumber, SectorSize, StoragePower, }; use fvm_shared::ActorID; use serde::{Deserialize, Serialize}; @@ -88,6 +88,15 @@ pub struct ChangeMultiaddrsParams { pub new_multi_addrs: Vec, } +#[derive(Serialize_tuple, Deserialize_tuple)] +pub struct ConfirmSectorProofsParams { + pub sectors: Vec, + pub reward_smoothed: FilterEstimate, + #[serde(with = "bigint_ser")] + pub reward_baseline_power: StoragePower, + pub quality_adj_power_smoothed: FilterEstimate, +} + #[derive(Serialize_tuple, Deserialize_tuple)] pub struct DeferredCronEventParams { #[serde(with = "strict_bytes")] diff --git a/actors/power/src/ext.rs b/actors/power/src/ext.rs index 9c821c1d0..270ca5591 100644 --- a/actors/power/src/ext.rs +++ b/actors/power/src/ext.rs @@ -3,7 +3,8 @@ use fvm_ipld_encoding::tuple::*; use fvm_ipld_encoding::{strict_bytes, BytesDe}; use fvm_shared::address::Address; -use fvm_shared::sector::RegisteredPoStProof; +use fvm_shared::bigint::bigint_ser; +use fvm_shared::sector::{RegisteredPoStProof, SectorNumber, StoragePower}; use fvm_shared::METHOD_CONSTRUCTOR; use num_derive::FromPrimitive; @@ -35,8 +36,18 @@ pub mod init { pub mod miner { use super::*; + pub const CONFIRM_SECTOR_PROOFS_VALID_METHOD: u64 = 17; pub const ON_DEFERRED_CRON_EVENT_METHOD: u64 = 12; + #[derive(Serialize_tuple, Deserialize_tuple)] + pub struct ConfirmSectorProofsParams { + pub sectors: Vec, + pub reward_smoothed: FilterEstimate, + #[serde(with = "bigint_ser")] + pub reward_baseline_power: StoragePower, + pub quality_adj_power_smoothed: FilterEstimate, + } + #[derive(Serialize_tuple, Deserialize_tuple)] pub struct MinerConstructorParams { pub owner: Address,