diff --git a/actors/market/src/lib.rs b/actors/market/src/lib.rs index 74d60cf5ce..2be396a63f 100644 --- a/actors/market/src/lib.rs +++ b/actors/market/src/lib.rs @@ -502,7 +502,7 @@ impl Actor { let st: State = rt.state()?; let proposal_array = st.get_proposal_array(rt.store())?; - let mut sectors_data = Vec::with_capacity(params.sectors.len()); + let mut unsealed_cids = Vec::with_capacity(params.sectors.len()); for sector in params.sectors.iter() { let sector_proposals = get_proposals(&proposal_array, §or.deal_ids, st.next_id)?; let sector_size = sector @@ -524,10 +524,10 @@ impl Actor { Some(compute_data_commitment(rt, §or_proposals, sector.sector_type)?) }; - sectors_data.push(SectorDealData { commd }); + unsealed_cids.push(commd); } - Ok(VerifyDealsForActivationReturn { sectors: sectors_data }) + Ok(VerifyDealsForActivationReturn { unsealed_cids }) } /// Activate a set of deals grouped by sector, returning the size and @@ -590,9 +590,9 @@ impl Actor { // This construction could be replaced with a single "update deal state" // state method, possibly batched over all deal ids at once. let update_result: Result<(), ActorError> = - proposals.into_iter().try_for_each(|(deal_id, proposal)| { + proposals.iter().try_for_each(|(deal_id, proposal)| { let s = st - .find_deal_state(rt.store(), deal_id) + .find_deal_state(rt.store(), *deal_id) .context(format!("error looking up deal state for {}", deal_id))?; if s.is_some() { @@ -603,7 +603,7 @@ impl Actor { )); } - let propc = rt_deal_cid(rt, &proposal)?; + let propc = rt_deal_cid(rt, proposal)?; // Confirm the deal is in the pending proposals queue. // It will be removed from this queue later, during cron. @@ -619,7 +619,7 @@ impl Actor { // Extract and remove any verified allocation ID for the pending deal. let allocation = st - .remove_pending_deal_allocation_id(rt.store(), &deal_id_key(deal_id)) + .remove_pending_deal_allocation_id(rt.store(), &deal_id_key(*deal_id)) .context(format!( "failed to remove pending deal allocation id {}", deal_id @@ -637,7 +637,7 @@ impl Actor { } deal_states.push(( - deal_id, + *deal_id, DealState { sector_start_epoch: curr_epoch, last_updated_epoch: EPOCH_UNDEFINED, @@ -645,15 +645,22 @@ impl Actor { verified_claim: allocation, }, )); - activated_deals.insert(deal_id); + activated_deals.insert(*deal_id); Ok(()) }); + let data_commitment = if params.compute_cid && !p.deal_ids.is_empty() { + Some(compute_data_commitment(rt, &proposals, p.sector_type)?) + } else { + None + }; + match update_result { Ok(_) => { activations.push(SectorDealActivation { nonverified_deal_space: deal_spaces.deal_space, verified_infos, + unsealed_cid: data_commitment, }); batch_gen.add_success(); } diff --git a/actors/market/src/types.rs b/actors/market/src/types.rs index fd63e3bab6..2bdde9cb14 100644 --- a/actors/market/src/types.rs +++ b/actors/market/src/types.rs @@ -86,22 +86,19 @@ pub struct SectorDeals { #[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq)] pub struct VerifyDealsForActivationReturn { - pub sectors: Vec, -} - -#[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq, Default)] -pub struct SectorDealData { - /// Option::None signifies commitment to empty sector, meaning no deals. - pub commd: Option, + // The unsealed CID computed from the deals specified for each sector. + // A None indicates no deals were specified. + pub unsealed_cids: Vec>, } #[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq)] -#[serde(transparent)] pub struct BatchActivateDealsParams { /// Deals to activate, grouped by sector. /// A failed deal activation will cause other deals in the same sector group to also fail, /// but allow other sectors to proceed. pub sectors: Vec, + /// Requests computation of an unsealed CID for each sector from the provided deals. + pub compute_cid: bool, } // Information about a verified deal that has been activated. @@ -121,6 +118,9 @@ pub struct SectorDealActivation { pub nonverified_deal_space: BigInt, /// Information about each verified deal activated. pub verified_infos: Vec, + /// Unsealed CID computed from the deals specified for the sector. + /// A None indicates no deals were specified, or the computation was not requested. + pub unsealed_cid: Option, } #[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq)] diff --git a/actors/market/tests/activate_deal_failures.rs b/actors/market/tests/activate_deal_failures.rs index 9f1f0e13b6..0ba40faba5 100644 --- a/actors/market/tests/activate_deal_failures.rs +++ b/actors/market/tests/activate_deal_failures.rs @@ -37,6 +37,7 @@ fn fail_when_caller_is_not_the_provider_of_the_deal() { sector_type: RegisteredSealProof::StackedDRG8MiBV1, deal_ids: vec![deal_id], }], + false, ) .unwrap(); let res: BatchActivateDealsResult = @@ -59,7 +60,7 @@ fn fail_when_caller_is_not_a_storage_miner_actor() { sector_expiry: 0, sector_type: RegisteredSealProof::StackedDRG8MiBV1, }; - let params = BatchActivateDealsParams { sectors: vec![sector_activation] }; + let params = BatchActivateDealsParams { sectors: vec![sector_activation], compute_cid: false }; expect_abort( ExitCode::USR_FORBIDDEN, @@ -85,6 +86,7 @@ fn fail_when_deal_has_not_been_published_before() { sector_expiry: EPOCHS_IN_DAY, deal_ids: vec![DealID::from(42u32)], }], + false, ) .unwrap(); let res: BatchActivateDealsResult = @@ -120,6 +122,7 @@ fn fail_when_deal_has_already_been_activated() { sector_expiry, deal_ids: vec![deal_id], }], + false, ) .unwrap(); let res: BatchActivateDealsResult = diff --git a/actors/market/tests/batch_activate_deals.rs b/actors/market/tests/batch_activate_deals.rs index 7b0b0fc913..b02359a446 100644 --- a/actors/market/tests/batch_activate_deals.rs +++ b/actors/market/tests/batch_activate_deals.rs @@ -55,7 +55,7 @@ fn activate_deals_across_multiple_sectors() { (END_EPOCH + 2, vec![unverified_deal_2_id]), // contains unverified deal only ]; - let res = batch_activate_deals(&rt, PROVIDER_ADDR, §ors); + let res = batch_activate_deals(&rt, PROVIDER_ADDR, §ors, false); // three sectors activated successfully assert!(res.activation_results.all_ok()); @@ -121,7 +121,7 @@ fn sectors_fail_and_succeed_independently_during_batch_activation() { SectorDeals { deal_ids: vec![id_4], sector_type, sector_expiry: END_EPOCH + 2 }, // sector succeeds ]; - let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals).unwrap(); + let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false).unwrap(); let res: BatchActivateDealsResult = res.unwrap().deserialize().expect("VerifyDealsForActivation failed!"); @@ -172,7 +172,7 @@ fn handles_sectors_empty_of_deals_gracefully() { SectorDeals { deal_ids: vec![], sector_type, sector_expiry: END_EPOCH + 2 }, // empty sector ]; - let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals).unwrap(); + let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false).unwrap(); let res: BatchActivateDealsResult = res.unwrap().deserialize().expect("VerifyDealsForActivation failed!"); @@ -221,7 +221,7 @@ fn fails_to_activate_sectors_containing_duplicate_deals() { SectorDeals { deal_ids: vec![id_3], sector_type, sector_expiry: END_EPOCH }, ]; - let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals).unwrap(); + let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false).unwrap(); let res: BatchActivateDealsResult = res.unwrap().deserialize().expect("VerifyDealsForActivation failed!"); diff --git a/actors/market/tests/harness.rs b/actors/market/tests/harness.rs index c024f79d84..8443c97415 100644 --- a/actors/market/tests/harness.rs +++ b/actors/market/tests/harness.rs @@ -320,7 +320,7 @@ pub fn activate_deals( deal_ids: &[DealID], ) -> BatchActivateDealsResult { rt.set_epoch(current_epoch); - + let compute_cid = false; let ret = batch_activate_deals_raw( rt, provider, @@ -329,6 +329,7 @@ pub fn activate_deals( sector_expiry, sector_type: RegisteredSealProof::StackedDRG8MiBV1, }], + compute_cid, ) .unwrap(); @@ -352,6 +353,7 @@ pub fn batch_activate_deals( rt: &MockRuntime, provider: Address, sectors: &[(ChainEpoch, Vec)], + compute_cid: bool, ) -> BatchActivateDealsResult { let sectors_deals: Vec = sectors .iter() @@ -361,7 +363,7 @@ pub fn batch_activate_deals( sector_type: RegisteredSealProof::StackedDRG8MiBV1, }) .collect(); - let ret = batch_activate_deals_raw(rt, provider, sectors_deals).unwrap(); + let ret = batch_activate_deals_raw(rt, provider, sectors_deals, compute_cid).unwrap(); let ret: BatchActivateDealsResult = ret.unwrap().deserialize().expect("VerifyDealsForActivation failed!"); @@ -376,11 +378,12 @@ pub fn batch_activate_deals_raw( rt: &MockRuntime, provider: Address, sectors_deals: Vec, + compute_cid: bool, ) -> Result, ActorError> { rt.set_caller(*MINER_ACTOR_CODE_ID, provider); rt.expect_validate_caller_type(vec![Type::Miner]); - let params = BatchActivateDealsParams { sectors: sectors_deals }; + let params = BatchActivateDealsParams { sectors: sectors_deals, compute_cid }; let ret = rt.call::( Method::BatchActivateDeals as u64, diff --git a/actors/market/tests/market_actor_test.rs b/actors/market/tests/market_actor_test.rs index e4d3f40520..142974fe6f 100644 --- a/actors/market/tests/market_actor_test.rs +++ b/actors/market/tests/market_actor_test.rs @@ -1697,6 +1697,7 @@ fn fail_when_current_epoch_greater_than_start_epoch_of_deal() { sector_type: RegisteredSealProof::StackedDRG8MiBV1, deal_ids: vec![deal_id], }], + false, ) .unwrap(); @@ -1731,6 +1732,7 @@ fn fail_when_end_epoch_of_deal_greater_than_sector_expiry() { sector_type: RegisteredSealProof::StackedDRG8MiBV1, deal_ids: vec![deal_id], }], + false, ) .unwrap(); @@ -1758,7 +1760,7 @@ fn fail_to_activate_all_deals_if_one_deal_fails() { start_epoch, end_epoch, ); - batch_activate_deals(&rt, PROVIDER_ADDR, &[(sector_expiry, vec![deal_id1])]); + batch_activate_deals(&rt, PROVIDER_ADDR, &[(sector_expiry, vec![deal_id1])], false); let deal_id2 = generate_and_publish_deal( &rt, @@ -1776,6 +1778,7 @@ fn fail_to_activate_all_deals_if_one_deal_fails() { sector_type: RegisteredSealProof::StackedDRG8MiBV1, deal_ids: vec![deal_id1, deal_id2], }], + false, ) .unwrap(); let res: BatchActivateDealsResult = diff --git a/actors/market/tests/verify_deals_for_activation_test.rs b/actors/market/tests/verify_deals_for_activation_test.rs index 19832ef683..b255cb6a99 100644 --- a/actors/market/tests/verify_deals_for_activation_test.rs +++ b/actors/market/tests/verify_deals_for_activation_test.rs @@ -51,8 +51,8 @@ fn verify_deal_and_activate_to_get_deal_space_for_unverified_deal_proposal() { ); let a_response = activate_deals(&rt, SECTOR_EXPIRY, PROVIDER_ADDR, CURR_EPOCH, &[deal_id]); let s_response = a_response.activations.get(0).unwrap(); - assert_eq!(1, v_response.sectors.len()); - assert_eq!(Some(make_piece_cid("1".as_bytes())), v_response.sectors[0].commd); + assert_eq!(1, v_response.unsealed_cids.len()); + assert_eq!(Some(make_piece_cid("1".as_bytes())), v_response.unsealed_cids[0]); assert!(s_response.verified_infos.is_empty()); assert_eq!(BigInt::from(deal_proposal.piece_size.0), s_response.nonverified_deal_space); @@ -87,8 +87,8 @@ fn verify_deal_and_activate_to_get_deal_space_for_verified_deal_proposal() { let a_response = activate_deals(&rt, SECTOR_EXPIRY, PROVIDER_ADDR, CURR_EPOCH, &[deal_id]); let s_response = a_response.activations.get(0).unwrap(); - assert_eq!(1, response.sectors.len()); - assert_eq!(Some(make_piece_cid("1".as_bytes())), response.sectors[0].commd); + assert_eq!(1, response.unsealed_cids.len()); + assert_eq!(Some(make_piece_cid("1".as_bytes())), response.unsealed_cids[0]); assert_eq!(1, s_response.verified_infos.len()); assert_eq!(deal_proposal.piece_size, s_response.verified_infos[0].size); assert_eq!(deal_proposal.client.id().unwrap(), s_response.verified_infos[0].client); @@ -148,7 +148,7 @@ fn verification_and_weights_for_verified_and_unverified_deals() { let a_response = activate_deals(&rt, SECTOR_EXPIRY, PROVIDER_ADDR, CURR_EPOCH, &deal_ids); let s_response = a_response.activations.get(0).unwrap(); - assert_eq!(1, response.sectors.len()); + assert_eq!(1, response.unsealed_cids.len()); let returned_verified_space: BigInt = s_response.verified_infos.iter().map(|info| BigInt::from(info.size.0)).sum(); assert_eq!(verified_space, returned_verified_space); diff --git a/actors/miner/src/ext.rs b/actors/miner/src/ext.rs index 6102e580a6..cc07020a7f 100644 --- a/actors/miner/src/ext.rs +++ b/actors/miner/src/ext.rs @@ -1,5 +1,4 @@ use cid::Cid; -use fil_actors_runtime::BatchReturn; use fvm_ipld_encoding::tuple::*; use fvm_ipld_encoding::RawBytes; use fvm_shared::bigint::{bigint_ser, BigInt}; @@ -12,12 +11,13 @@ use fvm_shared::sector::{RegisteredSealProof, StoragePower}; use fvm_shared::smooth::FilterEstimate; use fvm_shared::ActorID; +use fil_actors_runtime::BatchReturn; + pub mod account { pub const PUBKEY_ADDRESS_METHOD: u64 = 2; } pub mod market { - use super::*; pub const VERIFY_DEALS_FOR_ACTIVATION_METHOD: u64 = 5; @@ -32,9 +32,9 @@ pub mod market { } #[derive(Serialize_tuple, Deserialize_tuple)] - #[serde(transparent)] pub struct BatchActivateDealsParams { pub sectors: Vec, + pub compute_cid: bool, } #[derive(Serialize_tuple, Deserialize_tuple, Clone)] @@ -57,24 +57,17 @@ pub mod market { } #[derive(Serialize_tuple, Deserialize_tuple, Clone)] - pub struct DealActivation { + pub struct SectorDealActivation { #[serde(with = "bigint_ser")] pub nonverified_deal_space: BigInt, pub verified_infos: Vec, + pub unsealed_cid: Option, } #[derive(Serialize_tuple, Deserialize_tuple, Clone)] pub struct BatchActivateDealsResult { pub activation_results: BatchReturn, - pub activations: Vec, - } - - #[derive(Serialize_tuple, Deserialize_tuple, Clone, Default)] - pub struct DealSpaces { - #[serde(with = "bigint_ser")] - pub deal_space: BigInt, - #[serde(with = "bigint_ser")] - pub verified_deal_space: BigInt, + pub activations: Vec, } #[derive(Serialize_tuple, Deserialize_tuple)] @@ -100,15 +93,9 @@ pub mod market { pub sectors: &'a [SectorDeals], } - #[derive(Serialize_tuple, Deserialize_tuple, Default, Clone)] - pub struct SectorDealData { - /// Option::None signifies commitment to empty sector, meaning no deals. - pub commd: Option, - } - #[derive(Serialize_tuple, Deserialize_tuple, Default, Clone)] pub struct VerifyDealsForActivationReturn { - pub sectors: Vec, + pub unsealed_cids: Vec>, } } diff --git a/actors/miner/src/lib.rs b/actors/miner/src/lib.rs index 24518ced86..3b59c74325 100644 --- a/actors/miner/src/lib.rs +++ b/actors/miner/src/lib.rs @@ -1162,52 +1162,33 @@ impl Actor { sector_type: usi.sector_info.seal_proof, }) .collect(); + // Request CommD computation while activating deals. let (batch_return, deals_spaces) = - batch_activate_deals_and_claim_allocations(rt, &activation_infos)?; + batch_activate_deals_and_claim_allocations(rt, &activation_infos, true)?; // associate the successfully activated sectors with the ReplicaUpdateInner and SectorOnChainInfo - let validated_updates: Vec<(&UpdateAndSectorInfo, ext::market::DealSpaces)> = + let validated_updates: Vec<(&UpdateAndSectorInfo, DealActivationInfo)> = batch_return.successes(&update_sector_infos).into_iter().zip(deals_spaces).collect(); if validated_updates.is_empty() { return Err(actor_error!(illegal_argument, "no valid updates")); } - let sectors_deals: Vec = validated_updates - .iter() - .map(|(usi, _)| ext::market::SectorDeals { - deal_ids: usi.update.deals.clone(), - sector_expiry: usi.sector_info.expiration, - sector_type: usi.sector_info.seal_proof, - }) - .collect(); - // Errors past this point cause the prove_replica_updates call to fail (no more skipping sectors) - let deal_data = request_deal_data(rt, §ors_deals)?; - if deal_data.sectors.len() != validated_updates.len() { - return Err(actor_error!( - illegal_state, - "deal weight request returned {} records, expected {}", - deal_data.sectors.len(), - validated_updates.len() - )); - } - struct UpdateWithDetails<'a> { update: &'a ReplicaUpdateInner, sector_info: &'a SectorOnChainInfo, - deal_spaces: &'a ext::market::DealSpaces, + deal_info: &'a DealActivationInfo, full_unsealed_cid: Cid, } // Group declarations by deadline let mut decls_by_deadline = BTreeMap::>::new(); let mut deadlines_to_load = Vec::::new(); - for ((usi, deal_spaces), deal_data) in - validated_updates.iter().zip(deal_data.sectors.iter()) - { - let computed_commd = - CompactCommD::new(deal_data.commd).get_cid(usi.sector_info.seal_proof)?; + for (usi, deal_activation) in &validated_updates { + // Computation of CommD was requested, so None can be interpreted as zero data. + let computed_commd = CompactCommD::new(deal_activation.unsealed_cid) + .get_cid(usi.sector_info.seal_proof)?; if let Some(ref declared_commd) = usi.update.new_unsealed_cid { if !declared_commd.eq(&computed_commd) { info!( @@ -1224,7 +1205,7 @@ impl Actor { decls_by_deadline.entry(dl).or_default().push(UpdateWithDetails { update: usi.update, sector_info: &usi.sector_info, - deal_spaces, + deal_info: deal_activation, full_unsealed_cid: computed_commd, }); } @@ -1304,9 +1285,9 @@ impl Actor { let duration = new_sector_info.expiration - new_sector_info.power_base_epoch; new_sector_info.deal_weight = - with_details.deal_spaces.deal_space.clone() * duration; + with_details.deal_info.unverified_space.clone() * duration; new_sector_info.verified_deal_weight = - with_details.deal_spaces.verified_deal_space.clone() * duration; + with_details.deal_info.verified_space.clone() * duration; // compute initial pledge let qa_pow = qa_power_for_weight( @@ -1870,12 +1851,12 @@ impl Actor { // gather information from other actors let reward_stats = request_current_epoch_block_reward(rt)?; let power_total = request_current_total_power(rt)?; - let deal_data_vec = request_deal_data(rt, §ors_deals)?; - if deal_data_vec.sectors.len() != sectors.len() { + let verify_return = verify_deals(rt, §ors_deals)?; + if verify_return.unsealed_cids.len() != sectors.len() { return Err(actor_error!( illegal_state, "deal weight request returned {} records, expected {}", - deal_data_vec.sectors.len(), + verify_return.unsealed_cids.len(), sectors.len() )); } @@ -1946,19 +1927,19 @@ impl Actor { return Err(actor_error!(illegal_argument, "too many deals for sector {} > {}", precommit.deal_ids.len(), deal_count_max)); } - let deal_data = &deal_data_vec.sectors[i]; + let computed_cid = &verify_return.unsealed_cids[i]; // 1. verify that precommit.unsealed_cid is correct // 2. create a new on_chain_precommit let commd = match precommit.unsealed_cid { // if the CommD is unknown, use CommD computed by the market - None => CompactCommD::new(deal_data.commd), + None => CompactCommD::new(*computed_cid), Some(x) => x, }; - if commd.0 != deal_data.commd { + if commd.0 != *computed_cid { return Err(actor_error!(illegal_argument, "computed {:?} and passed {:?} CommDs not equal", - deal_data.commd, commd)); + computed_cid, commd)); } @@ -4408,7 +4389,7 @@ fn get_verify_info( }) } -fn request_deal_data( +fn verify_deals( rt: &impl Runtime, sectors: &[ext::market::SectorDeals], ) -> Result { @@ -4419,7 +4400,7 @@ fn request_deal_data( } if deal_count == 0 { return Ok(ext::market::VerifyDealsForActivationReturn { - sectors: vec![Default::default(); sectors.len()], + unsealed_cids: vec![None; sectors.len()], }); } @@ -4812,7 +4793,7 @@ fn confirm_sector_proofs_valid_internal( .collect(); let (batch_return, activated_sectors) = - batch_activate_deals_and_claim_allocations(rt, &deals_activation_infos)?; + batch_activate_deals_and_claim_allocations(rt, &deals_activation_infos, false)?; let (total_pledge, newly_vested) = rt.transaction(|state: &mut State, rt| { let policy = rt.policy(); @@ -4838,8 +4819,8 @@ fn confirm_sector_proofs_valid_internal( continue; } - let deal_weight = deal_spaces.deal_space * duration; - let verified_deal_weight = deal_spaces.verified_deal_space * duration; + let deal_weight = deal_spaces.unverified_space * duration; + let verified_deal_weight = deal_spaces.verified_space * duration; let power = qa_power_for_weight( info.sector_size, @@ -4956,20 +4937,29 @@ fn confirm_sector_proofs_valid_internal( Ok(()) } +struct DealActivationInfo { + pub unverified_space: BigInt, + pub verified_space: BigInt, + // None indicates either no deals or computation was not requested. + pub unsealed_cid: Option, +} + /// Activates the deals then claims allocations for any verified deals /// Successfully activated sectors have their DealSpaces returned /// Failure to claim datacap for any verified deal results in the whole batch failing fn batch_activate_deals_and_claim_allocations( rt: &impl Runtime, activation_infos: &[DealsActivationInfo], -) -> Result<(BatchReturn, Vec), ActorError> { + compute_unsealed_cid: bool, +) -> Result<(BatchReturn, Vec), ActorError> { let batch_activation_res = match activation_infos.iter().all(|p| p.deal_ids.is_empty()) { true => ext::market::BatchActivateDealsResult { // if all sectors are empty of deals, skip calling the market actor activations: vec![ - ext::market::DealActivation { + ext::market::SectorDealActivation { nonverified_deal_space: BigInt::default(), verified_infos: Vec::default(), + unsealed_cid: None, }; activation_infos.len() ], @@ -4989,6 +4979,7 @@ fn batch_activate_deals_and_claim_allocations( ext::market::BATCH_ACTIVATE_DEALS_METHOD, IpldBlock::serialize_cbor(&ext::market::BatchActivateDealsParams { sectors: sector_activation_params, + compute_cid: compute_unsealed_cid, })?, TokenAmount::zero(), ))?; @@ -5065,9 +5056,10 @@ fn batch_activate_deals_and_claim_allocations( .activations .iter() .zip(claim_res.sector_claims) - .map(|(sector_deals, sector_claim)| ext::market::DealSpaces { - verified_deal_space: sector_claim.claimed_space, - deal_space: sector_deals.nonverified_deal_space.clone(), + .map(|(sector_deals, sector_claim)| DealActivationInfo { + unverified_space: sector_deals.nonverified_deal_space.clone(), + verified_space: sector_claim.claimed_space, + unsealed_cid: sector_deals.unsealed_cid, }) .collect(); diff --git a/actors/miner/tests/aggregate_prove_commit.rs b/actors/miner/tests/aggregate_prove_commit.rs index 801fbeb2c3..9ce62cd1df 100644 --- a/actors/miner/tests/aggregate_prove_commit.rs +++ b/actors/miner/tests/aggregate_prove_commit.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; -use fil_actor_market::DealSpaces; use fil_actor_miner::{ initial_pledge_for_power, qa_power_for_weight, PowerPair, QUALITY_BASE_MULTIPLIER, VERIFIED_DEAL_WEIGHT_MULTIPLIER, @@ -34,15 +33,12 @@ fn valid_precommits_then_aggregate_provecommit() { let prove_commit_epoch = precommit_epoch + rt.policy.pre_commit_challenge_delay + 1; // something on deadline boundary but > 180 days + let deal_space = 0; let verified_deal_space = actor.sector_size as u64; let expiration = dl_info.period_end() + rt.policy.wpost_proving_period * DEFAULT_SECTOR_EXPIRATION; // fill the sector with verified seals let duration = expiration - prove_commit_epoch; - let deal_spaces = DealSpaces { - deal_space: BigInt::zero(), - verified_deal_space: BigInt::from(verified_deal_space), - }; let mut precommits = vec![]; let mut sector_nos_bf = BitField::new(); @@ -90,8 +86,8 @@ fn valid_precommits_then_aggregate_provecommit() { // The sector is exactly full with verified deals, so expect fully verified power. let expected_power = BigInt::from(actor.sector_size as i64) * (VERIFIED_DEAL_WEIGHT_MULTIPLIER.clone() / QUALITY_BASE_MULTIPLIER.clone()); - let deal_weight = deal_spaces.deal_space * duration; - let verified_deal_weight = deal_spaces.verified_deal_space * duration; + let deal_weight = BigInt::from(deal_space) * duration; + let verified_deal_weight = BigInt::from(verified_deal_space) * duration; let qa_power = qa_power_for_weight( actor.sector_size, expiration - *rt.epoch.borrow(), diff --git a/actors/miner/tests/miner_actor_test_precommit_batch.rs b/actors/miner/tests/miner_actor_test_precommit_batch.rs index 774a481656..41eb49e1b2 100644 --- a/actors/miner/tests/miner_actor_test_precommit_batch.rs +++ b/actors/miner/tests/miner_actor_test_precommit_batch.rs @@ -1,4 +1,4 @@ -use fil_actor_market::{Method as MarketMethod, SectorDealData}; +use fil_actor_market::Method as MarketMethod; use fil_actor_miner::{ aggregate_pre_commit_network_fee, max_prove_commit_duration, pre_commit_deposit_for_power, qa_power_max, PreCommitSectorBatchParams, PreCommitSectorParams, State, @@ -61,10 +61,8 @@ fn assert_simple_batch( dl_info.period_end() + DEFAULT_SECTOR_EXPIRATION * rt.policy.wpost_proving_period; // on deadline boundary but > 180 days let mut sectors = vec![PreCommitSectorParams::default(); batch_size]; - let mut conf = PreCommitBatchConfig { - sector_deal_data: vec![SectorDealData::default(); batch_size], - first_for_miner: true, - }; + let mut conf = + PreCommitBatchConfig { sector_unsealed_cid: vec![None; batch_size], first_for_miner: true }; let mut deposits = vec![TokenAmount::zero(); batch_size]; for i in 0..batch_size { @@ -79,7 +77,7 @@ fn assert_simple_batch( deals.ids, ); - conf.sector_deal_data[i] = SectorDealData { commd: deals.commd }; + conf.sector_unsealed_cid[i] = deals.commd; let pwr_estimate = qa_power_max(h.sector_size); deposits[i] = pre_commit_deposit_for_power( &h.epoch_reward_smooth, @@ -123,7 +121,7 @@ fn assert_simple_batch( let st: State = rt.get_state(); for i in 0..batch_size { assert_eq!(precommit_epoch, precommits[i].pre_commit_epoch); - assert_eq!(conf.sector_deal_data[i].commd, precommits[i].info.unsealed_cid.0); + assert_eq!(conf.sector_unsealed_cid[i], precommits[i].info.unsealed_cid.0); assert_eq!(sector_nos[i], precommits[i].info.sector_number); @@ -306,7 +304,7 @@ mod miner_actor_precommit_batch { h.pre_commit_sector_batch( &rt, PreCommitSectorBatchParams { sectors }, - &PreCommitBatchConfig { sector_deal_data: vec![], first_for_miner: true }, + &PreCommitBatchConfig { sector_unsealed_cid: vec![], first_for_miner: true }, &TokenAmount::zero(), ), ); @@ -346,7 +344,7 @@ mod miner_actor_precommit_batch { h.pre_commit_sector_batch( &rt, PreCommitSectorBatchParams { sectors }, - &PreCommitBatchConfig { sector_deal_data: vec![], first_for_miner: true }, + &PreCommitBatchConfig { sector_unsealed_cid: vec![], first_for_miner: true }, &TokenAmount::zero(), ), ); @@ -396,11 +394,11 @@ mod miner_actor_precommit_batch { }); //mismatch here - sector_deal_data.push(SectorDealData { commd: Some(make_piece_cid(&[2])) }); + sector_deal_data.push(Some(make_piece_cid(&[2]))); } let vdparams = VerifyDealsForActivationParams { sectors: sector_deals }; - let vdreturn = VerifyDealsForActivationReturn { sectors: sector_deal_data }; + let vdreturn = VerifyDealsForActivationReturn { unsealed_cids: sector_deal_data }; rt.expect_send_simple( STORAGE_MARKET_ACTOR_ADDR, MarketMethod::VerifyDealsForActivation as u64, diff --git a/actors/miner/tests/prove_commit.rs b/actors/miner/tests/prove_commit.rs index db6f47653c..1bb939e3d1 100644 --- a/actors/miner/tests/prove_commit.rs +++ b/actors/miner/tests/prove_commit.rs @@ -1,10 +1,5 @@ -use fil_actor_market::{DealSpaces, SectorDealData}; -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::Runtime, test_utils::expect_abort, DealWeight}; +use std::collections::HashMap; + use fvm_shared::{ bigint::{BigInt, Zero}, clock::ChainEpoch, @@ -13,12 +8,17 @@ use fvm_shared::{ sector::{StoragePower, MAX_SECTOR_NUMBER}, smooth::FilterEstimate, }; -use std::collections::HashMap; - -mod util; +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::Runtime, test_utils::expect_abort, DealWeight}; use util::*; +mod util; + // an expiration ~10 days greater than effective min expiration taking into account 30 days max // between pre and prove commit const DEFAULT_SECTOR_EXPIRATION: ChainEpoch = 220; @@ -46,11 +46,9 @@ fn prove_single_sector() { let expiration = dl_info.period_end() + DEFAULT_SECTOR_EXPIRATION * rt.policy.wpost_proving_period; // something on deadline boundary but > 180 days // Fill the sector with verified deals + let deal_space = 0; let verified_deal = test_verified_deal(h.sector_size as u64); - let deal_spaces = DealSpaces { - deal_space: BigInt::zero(), - verified_deal_space: BigInt::from(verified_deal.size.0), - }; + let verified_deal_space = BigInt::from(verified_deal.size.0); // Pre-commit with a deal in order to exercise non-zero deal weights. let precommit_params = @@ -101,8 +99,8 @@ fn prove_single_sector() { // The sector is exactly full with verified deals, so expect fully verified power. let duration = precommit.info.expiration - prove_commit_epoch; - let deal_weight = deal_spaces.deal_space * duration; - let verified_deal_weight = deal_spaces.verified_deal_space * duration; + let deal_weight = BigInt::from(deal_space) * duration; + let verified_deal_weight = BigInt::from(verified_deal_space) * duration; let expected_power = StoragePower::from(h.sector_size as u64) * (VERIFIED_DEAL_WEIGHT_MULTIPLIER / QUALITY_BASE_MULTIPLIER); let qa_power = @@ -187,11 +185,7 @@ fn prove_sectors_from_batch_pre_commit() { let verified_deal_weight = deal_space * DealWeight::from(deal_lifespan); let conf = PreCommitBatchConfig { - sector_deal_data: vec![ - SectorDealData { commd: None }, - SectorDealData { commd: Some(make_piece_cid(b"1")) }, - SectorDealData { commd: Some(make_piece_cid(b"2|3")) }, - ], + sector_unsealed_cid: vec![None, Some(make_piece_cid(b"1")), Some(make_piece_cid(b"2|3"))], first_for_miner: true, }; diff --git a/actors/miner/tests/util.rs b/actors/miner/tests/util.rs index f43a7896ee..07bfecc682 100644 --- a/actors/miner/tests/util.rs +++ b/actors/miner/tests/util.rs @@ -1,14 +1,59 @@ #![allow(clippy::all)] +use std::collections::{BTreeMap, BTreeSet, HashMap}; +use std::convert::TryInto; +use std::iter; +use std::ops::Neg; + +use cid::multihash::MultihashDigest; +use cid::Cid; +use fvm_ipld_amt::Amt; +use fvm_ipld_bitfield::iter::Ranges; +use fvm_ipld_bitfield::{BitField, UnvalidatedBitField, Validate}; +use fvm_ipld_blockstore::{Blockstore, MemoryBlockstore}; +use fvm_ipld_encoding::de::Deserialize; +use fvm_ipld_encoding::ipld_block::IpldBlock; +use fvm_ipld_encoding::ser::Serialize; +use fvm_ipld_encoding::{BytesDe, CborStore, RawBytes}; +use fvm_shared::address::Address; +use fvm_shared::bigint::BigInt; +use fvm_shared::bigint::Zero; +use fvm_shared::clock::QuantSpec; +use fvm_shared::clock::{ChainEpoch, NO_QUANTIZATION}; +use fvm_shared::commcid::{FIL_COMMITMENT_SEALED, FIL_COMMITMENT_UNSEALED}; +use fvm_shared::consensus::ConsensusFault; +use fvm_shared::crypto::hash::SupportedHashes; +use fvm_shared::deal::DealID; +use fvm_shared::econ::TokenAmount; +use fvm_shared::error::ExitCode; +use fvm_shared::piece::PaddedPieceSize; +use fvm_shared::randomness::Randomness; +use fvm_shared::randomness::RANDOMNESS_LENGTH; +use fvm_shared::sector::{ + AggregateSealVerifyInfo, PoStProof, RegisteredPoStProof, RegisteredSealProof, SealVerifyInfo, + SectorID, SectorInfo, SectorNumber, SectorSize, StoragePower, WindowPoStVerifyInfo, +}; +use fvm_shared::smooth::FilterEstimate; +use fvm_shared::{MethodNum, HAMT_BIT_WIDTH, METHOD_SEND}; +use itertools::Itertools; +use lazy_static::lazy_static; +use multihash::derive::Multihash; + use fil_actor_account::Method as AccountMethod; use fil_actor_market::{ - BatchActivateDealsParams, BatchActivateDealsResult, DealSpaces, Method as MarketMethod, - OnMinerSectorsTerminateParams, SectorDealActivation, SectorDealData, SectorDeals, - VerifiedDealInfo, VerifyDealsForActivationParams, VerifyDealsForActivationReturn, + BatchActivateDealsParams, BatchActivateDealsResult, Method as MarketMethod, + OnMinerSectorsTerminateParams, SectorDealActivation, SectorDeals, VerifiedDealInfo, + VerifyDealsForActivationParams, VerifyDealsForActivationReturn, }; use fil_actor_miner::ext::market::ON_MINER_SECTORS_TERMINATE_METHOD; use fil_actor_miner::ext::power::{UPDATE_CLAIMED_POWER_METHOD, UPDATE_PLEDGE_TOTAL_METHOD}; use fil_actor_miner::ext::verifreg::CLAIM_ALLOCATIONS_METHOD; +use fil_actor_miner::ext::verifreg::{ + Claim as FILPlusClaim, ClaimID, GetClaimsParams, GetClaimsReturn, +}; +use fil_actor_miner::testing::{ + check_deadline_state_invariants, check_state_invariants, DeadlineStateSummary, +}; use fil_actor_miner::{ aggregate_pre_commit_network_fee, aggregate_prove_commit_network_fee, consensus_fault_penalty, ext, initial_pledge_for_power, locked_reward_from_reward, max_prove_commit_duration, @@ -35,11 +80,7 @@ use fil_actor_power::{ CurrentTotalPowerReturn, EnrollCronEventParams, Method as PowerMethod, UpdateClaimedPowerParams, }; use fil_actor_reward::{Method as RewardMethod, ThisEpochRewardReturn}; - -use fil_actor_miner::ext::verifreg::{ - Claim as FILPlusClaim, ClaimID, GetClaimsParams, GetClaimsReturn, -}; - +use fil_actors_runtime::cbor::serialize; use fil_actors_runtime::runtime::{DomainSeparationTag, Policy, Runtime, RuntimePolicy}; use fil_actors_runtime::{test_utils::*, BatchReturn, BatchReturnGen}; use fil_actors_runtime::{ @@ -47,50 +88,6 @@ use fil_actors_runtime::{ INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR, }; -use fvm_ipld_amt::Amt; -use fvm_shared::bigint::Zero; - -use fvm_ipld_bitfield::iter::Ranges; -use fvm_ipld_bitfield::{BitField, UnvalidatedBitField, Validate}; -use fvm_ipld_blockstore::{Blockstore, MemoryBlockstore}; -use fvm_ipld_encoding::de::Deserialize; -use fvm_ipld_encoding::ser::Serialize; -use fvm_ipld_encoding::{BytesDe, CborStore, RawBytes}; -use fvm_shared::address::Address; -use fvm_shared::bigint::BigInt; -use fvm_shared::clock::QuantSpec; -use fvm_shared::clock::{ChainEpoch, NO_QUANTIZATION}; -use fvm_shared::commcid::{FIL_COMMITMENT_SEALED, FIL_COMMITMENT_UNSEALED}; -use fvm_shared::consensus::ConsensusFault; -use fvm_shared::deal::DealID; -use fvm_shared::econ::TokenAmount; -use fvm_shared::error::ExitCode; -use fvm_shared::piece::PaddedPieceSize; -use fvm_shared::randomness::Randomness; -use fvm_shared::randomness::RANDOMNESS_LENGTH; -use fvm_shared::sector::{ - AggregateSealVerifyInfo, PoStProof, RegisteredPoStProof, RegisteredSealProof, SealVerifyInfo, - SectorID, SectorInfo, SectorNumber, SectorSize, StoragePower, WindowPoStVerifyInfo, -}; -use fvm_shared::smooth::FilterEstimate; -use fvm_shared::{MethodNum, HAMT_BIT_WIDTH, METHOD_SEND}; - -use cid::multihash::MultihashDigest; -use cid::Cid; -use itertools::Itertools; -use lazy_static::lazy_static; -use multihash::derive::Multihash; - -use fil_actor_miner::testing::{ - check_deadline_state_invariants, check_state_invariants, DeadlineStateSummary, -}; -use fil_actors_runtime::cbor::serialize; -use fvm_ipld_encoding::ipld_block::IpldBlock; -use fvm_shared::crypto::hash::SupportedHashes; -use std::collections::{BTreeMap, BTreeSet, HashMap}; -use std::convert::TryInto; -use std::iter; -use std::ops::Neg; const RECEIVER_ID: u64 = 1000; @@ -568,12 +565,12 @@ impl ActorHarness { base_fee, ) } else { - let mut deal_data = Vec::new(); + let mut commds = Vec::new(); let v1 = params .sectors .iter() .map(|s| { - deal_data.push(SectorDealData { commd: s.unsealed_cid.0 }); + commds.push(s.unsealed_cid.0); PreCommitSectorParams { seal_proof: s.seal_proof, sector_number: s.sector_number, @@ -610,15 +607,15 @@ impl ActorHarness { let v2: Vec<_> = params .sectors .iter() - .zip(conf.sector_deal_data.iter().chain(iter::repeat(&SectorDealData { commd: None }))) - .map(|(s, dd)| SectorPreCommitInfo { + .zip(conf.sector_unsealed_cid.iter().chain(iter::repeat(&None))) + .map(|(s, cid)| SectorPreCommitInfo { seal_proof: s.seal_proof, sector_number: s.sector_number, sealed_cid: s.sealed_cid, seal_rand_epoch: s.seal_rand_epoch, deal_ids: s.deal_ids.clone(), expiration: s.expiration, - unsealed_cid: CompactCommD::new(dd.commd), + unsealed_cid: CompactCommD::new(*cid), }) .collect(); @@ -666,14 +663,14 @@ impl ActorHarness { deal_ids: sector.deal_ids.clone(), }); - sector_deal_data.push(SectorDealData { commd: sector.unsealed_cid.0 }); + sector_deal_data.push(sector.unsealed_cid.0); // Sanity check on expectations let sector_has_deals = !sector.deal_ids.is_empty(); any_deals |= sector_has_deals; } if any_deals { let vdparams = VerifyDealsForActivationParams { sectors: sector_deals }; - let vdreturn = VerifyDealsForActivationReturn { sectors: sector_deal_data }; + let vdreturn = VerifyDealsForActivationReturn { unsealed_cids: sector_deal_data }; rt.expect_send_simple( STORAGE_MARKET_ACTOR_ADDR, MarketMethod::VerifyDealsForActivation as u64, @@ -755,7 +752,7 @@ impl ActorHarness { deal_ids: params.deal_ids.clone(), }], }; - let vdreturn = VerifyDealsForActivationReturn { sectors: vec![conf.0] }; + let vdreturn = VerifyDealsForActivationReturn { unsealed_cids: vec![conf.0] }; rt.expect_send_simple( STORAGE_MARKET_ACTOR_ADDR, @@ -1062,7 +1059,7 @@ impl ActorHarness { for pc in pcs { if !pc.info.deal_ids.is_empty() { - let deal_spaces = cfg.deal_spaces(&pc.info.sector_number); + let deal_space = cfg.deal_space(pc.info.sector_number); let activate_params = SectorDeals { deal_ids: pc.info.deal_ids.clone(), sector_expiry: pc.info.expiration, @@ -1071,12 +1068,13 @@ impl ActorHarness { sector_activation_params.push(activate_params); let ret = SectorDealActivation { - nonverified_deal_space: deal_spaces.deal_space, + nonverified_deal_space: deal_space, verified_infos: cfg .verified_deal_infos .get(&pc.info.sector_number) .cloned() .unwrap_or_default(), + unsealed_cid: None, }; let mut activate_deals_exit = ExitCode::OK; @@ -1119,6 +1117,7 @@ impl ActorHarness { sector_activations.push(SectorDealActivation { nonverified_deal_space: BigInt::zero(), verified_infos: vec![], + unsealed_cid: None, }); sector_activation_results.add_success(); sectors_claims.push(ext::verifreg::SectorAllocationClaims { @@ -1136,6 +1135,7 @@ impl ActorHarness { MarketMethod::BatchActivateDeals as u64, IpldBlock::serialize_cbor(&BatchActivateDealsParams { sectors: sector_activation_params, + compute_cid: false, }) .unwrap(), TokenAmount::zero(), @@ -1183,11 +1183,12 @@ impl ActorHarness { let mut expected_raw_power = BigInt::from(0); for pc in valid_pcs { - let spaces = cfg.deal_spaces(&pc.info.sector_number); + let deal_space = cfg.deal_space(pc.info.sector_number); + let verified_deal_space = cfg.verified_deal_space(pc.info.sector_number); let duration = pc.info.expiration - *rt.epoch.borrow(); - let deal_weight = spaces.deal_space * duration; - let verified_deal_weight = spaces.verified_deal_space * duration; + let deal_weight = deal_space * duration; + let verified_deal_weight = verified_deal_space * duration; if duration >= rt.policy.min_sector_expiration { let qa_power_delta = qa_power_for_weight( self.sector_size, @@ -2671,7 +2672,7 @@ impl PoStConfig { } #[derive(Default)] -pub struct PreCommitConfig(pub SectorDealData); +pub struct PreCommitConfig(pub Option); #[allow(dead_code)] impl PreCommitConfig { @@ -2680,7 +2681,7 @@ impl PreCommitConfig { } pub fn new(commd: Option) -> PreCommitConfig { - PreCommitConfig { 0: SectorDealData { commd } } + PreCommitConfig { 0: commd } } pub fn default() -> PreCommitConfig { @@ -2722,25 +2723,25 @@ impl ProveCommitConfig { self.verified_deal_infos.insert(sector, deals); } - pub fn deal_spaces(&self, sector: &SectorNumber) -> DealSpaces { - let verified_deal_space = match self.verified_deal_infos.get(sector) { + pub fn deal_space(&self, sector: SectorNumber) -> BigInt { + self.deal_space.get(§or).cloned().unwrap_or_default() + } + + pub fn verified_deal_space(&self, sector: SectorNumber) -> BigInt { + match self.verified_deal_infos.get(§or) { None => BigInt::zero(), Some(infos) => infos .iter() .map(|info| BigInt::from(info.size.0)) .reduce(|x, a| x + a) .unwrap_or_default(), - }; - DealSpaces { - deal_space: self.deal_space.get(sector).cloned().unwrap_or_default(), - verified_deal_space, } } } #[derive(Default)] pub struct PreCommitBatchConfig { - pub sector_deal_data: Vec, + pub sector_unsealed_cid: Vec>, pub first_for_miner: bool, } diff --git a/integration_tests/src/expects.rs b/integration_tests/src/expects.rs index 3ff5f28fd6..664fd24e42 100644 --- a/integration_tests/src/expects.rs +++ b/integration_tests/src/expects.rs @@ -43,9 +43,11 @@ impl Expect { deals: Vec, sector_expiry: ChainEpoch, sector_type: RegisteredSealProof, + compute_cid: bool, ) -> ExpectInvocation { let params = IpldBlock::serialize_cbor(&BatchActivateDealsParams { sectors: vec![SectorDeals { deal_ids: deals, sector_expiry, sector_type }], + compute_cid, }) .unwrap(); ExpectInvocation { diff --git a/integration_tests/src/tests/extend_sectors_test.rs b/integration_tests/src/tests/extend_sectors_test.rs index 1a71dcda8f..667da74c6b 100644 --- a/integration_tests/src/tests/extend_sectors_test.rs +++ b/integration_tests/src/tests/extend_sectors_test.rs @@ -628,6 +628,7 @@ pub fn extend_updated_sector_with_claims_test(v: &dyn VM) { deal_ids.clone(), initial_sector_info.expiration, initial_sector_info.seal_proof, + true, ), ExpectInvocation { from: miner_id, diff --git a/integration_tests/src/tests/replica_update_test.rs b/integration_tests/src/tests/replica_update_test.rs index 91bc108ee1..23dd8d5860 100644 --- a/integration_tests/src/tests/replica_update_test.rs +++ b/integration_tests/src/tests/replica_update_test.rs @@ -1010,6 +1010,7 @@ pub fn replica_update_verified_deal_test(v: &dyn VM) { deal_ids.clone(), old_sector_info.expiration, old_sector_info.seal_proof, + true, ), ExpectInvocation { from: maddr,