From fb65f281487a65fd9401d00147d8ef078ed0bcad Mon Sep 17 00:00:00 2001 From: zenground0 Date: Wed, 22 May 2024 13:47:42 -0600 Subject: [PATCH] Fix many miner tests --- .../miner/tests/check_sector_proven_test.rs | 1 + actors/miner/tests/exported_getters.rs | 5 +- actors/miner/tests/prove_commit.rs | 51 ++++--- actors/miner/tests/util.rs | 134 ++++++++---------- 4 files changed, 89 insertions(+), 102 deletions(-) diff --git a/actors/miner/tests/check_sector_proven_test.rs b/actors/miner/tests/check_sector_proven_test.rs index a1ce14fa0..40ab482f9 100644 --- a/actors/miner/tests/check_sector_proven_test.rs +++ b/actors/miner/tests/check_sector_proven_test.rs @@ -17,6 +17,7 @@ fn setup() -> (ActorHarness, MockRuntime) { #[test] fn successfully_check_sector_is_proven() { + let _ = pretty_env_logger::init(); let (mut h, rt) = setup(); let sectors = diff --git a/actors/miner/tests/exported_getters.rs b/actors/miner/tests/exported_getters.rs index b6c6bf9c8..587fe777c 100644 --- a/actors/miner/tests/exported_getters.rs +++ b/actors/miner/tests/exported_getters.rs @@ -115,8 +115,7 @@ fn collateral_getters() { let precommit_params = h.make_pre_commit_params(sector_no, precommit_epoch - 1, expiration, vec![]); - let precommit = - h.pre_commit_sector_and_get(&rt, precommit_params, PreCommitConfig::empty(), true); + h.pre_commit_sector_and_get(&rt, precommit_params, PreCommitConfig::empty(), true); // run prove commit logic rt.set_epoch(prove_commit_epoch); @@ -127,7 +126,7 @@ fn collateral_getters() { let sector = h .prove_commit_sector_and_confirm( &rt, - &precommit, + &vec![], h.make_prove_commit_params(sector_no), pcc, ) diff --git a/actors/miner/tests/prove_commit.rs b/actors/miner/tests/prove_commit.rs index 4a64aa1f9..03eea96c3 100644 --- a/actors/miner/tests/prove_commit.rs +++ b/actors/miner/tests/prove_commit.rs @@ -52,8 +52,9 @@ fn prove_single_sector() { let verified_deal_space = BigInt::from(verified_deal.size.0); // Pre-commit with a deal in order to exercise non-zero deal weights. + let deal_ids = vec![1]; let precommit_params = - h.make_pre_commit_params(sector_no, precommit_epoch - 1, expiration, vec![1]); + h.make_pre_commit_params(sector_no, precommit_epoch - 1, expiration, deal_ids.clone()); let precommit = h.pre_commit_sector_and_get(&rt, precommit_params, PreCommitConfig::empty(), true); @@ -78,7 +79,7 @@ fn prove_single_sector() { let sector = h .prove_commit_sector_and_confirm( &rt, - &precommit, + &deal_ids, h.make_prove_commit_params(sector_no), pcc, ) @@ -169,10 +170,12 @@ fn prove_sectors_from_batch_pre_commit() { let sector_expiration = dl_info.period_end() + DEFAULT_SECTOR_EXPIRATION * rt.policy.wpost_proving_period; + let deal_ids1 = vec![1]; + let deal_ids2 = vec![2, 3]; let sectors = vec![ h.make_pre_commit_params(100, precommit_epoch - 1, sector_expiration, vec![]), - h.make_pre_commit_params(101, precommit_epoch - 1, sector_expiration, vec![1]), // 1 * 32GiB verified deal - h.make_pre_commit_params(102, precommit_epoch - 1, sector_expiration, vec![2, 3]), // 2 * 16GiB verified deals + h.make_pre_commit_params(101, precommit_epoch - 1, sector_expiration, deal_ids1.clone()), // 1 * 32GiB verified deal + h.make_pre_commit_params(102, precommit_epoch - 1, sector_expiration, deal_ids2.clone()), // 2 * 16GiB verified deals ]; let deal_space: i64 = 32 << 30; @@ -234,7 +237,7 @@ fn prove_sectors_from_batch_pre_commit() { let sector = h .prove_commit_sector_and_confirm( &rt, - precommit, + &vec![], h.make_prove_commit_params(precommit.info.sector_number), ProveCommitConfig::default(), ) @@ -261,7 +264,7 @@ fn prove_sectors_from_batch_pre_commit() { let sector = h .prove_commit_sector_and_confirm( &rt, - precommit, + &deal_ids1, h.make_prove_commit_params(precommit.info.sector_number), pcc, ) @@ -288,7 +291,7 @@ fn prove_sectors_from_batch_pre_commit() { let sector = h .prove_commit_sector_and_confirm( &rt, - precommit, + &deal_ids2, h.make_prove_commit_params(precommit.info.sector_number), pcc, ) @@ -314,6 +317,7 @@ fn invalid_proof_rejected() { h.construct_and_verify(&rt); let deadline = h.deadline(&rt); + let deal_ids = vec![1]; // Make a good commitment for the proof to target. let sector_no = 100; @@ -321,7 +325,7 @@ fn invalid_proof_rejected() { sector_no, precommit_epoch - 1, deadline.period_end() + DEFAULT_SECTOR_EXPIRATION * rt.policy.wpost_proving_period, - vec![1], + deal_ids.clone(), ); let precommit = h.pre_commit_sector_and_get(&rt, params, PreCommitConfig::default(), true); @@ -331,7 +335,7 @@ fn invalid_proof_rejected() { ExitCode::USR_NOT_FOUND, h.prove_commit_sector_and_confirm( &rt, - &precommit, + &deal_ids, h.make_prove_commit_params(sector_no + 1), ProveCommitConfig::empty(), ), @@ -348,7 +352,7 @@ fn invalid_proof_rejected() { ExitCode::USR_ILLEGAL_ARGUMENT, h.prove_commit_sector_and_confirm( &rt, - &precommit, + &deal_ids, h.make_prove_commit_params(sector_no), ProveCommitConfig::empty(), ), @@ -361,7 +365,7 @@ fn invalid_proof_rejected() { ExitCode::USR_FORBIDDEN, h.prove_commit_sector_and_confirm( &rt, - &precommit, + &deal_ids, h.make_prove_commit_params(sector_no), ProveCommitConfig::empty(), ), @@ -378,7 +382,7 @@ fn invalid_proof_rejected() { ExitCode::USR_ILLEGAL_ARGUMENT, h.prove_commit_sector_and_confirm( &rt, - &precommit, + &deal_ids, h.make_prove_commit_params(sector_no), ProveCommitConfig { verify_deals_exit, ..Default::default() }, ), @@ -388,7 +392,7 @@ fn invalid_proof_rejected() { rt.balance.replace(TokenAmount::from_whole(1_000)); let prove_commit = h.make_prove_commit_params(sector_no); - h.prove_commit_sector_and_confirm(&rt, &precommit, prove_commit, ProveCommitConfig::empty()) + h.prove_commit_sector_and_confirm(&rt, &deal_ids, prove_commit, ProveCommitConfig::empty()) .unwrap(); let st = h.get_state(&rt); @@ -406,7 +410,7 @@ fn invalid_proof_rejected() { ExitCode::USR_NOT_FOUND, h.prove_commit_sector_and_confirm( &rt, - &precommit, + &deal_ids, h.make_prove_commit_params(sector_no), ProveCommitConfig::empty(), ), @@ -455,7 +459,7 @@ fn prove_commit_aborts_if_pledge_requirement_not_met() { ExitCode::USR_INSUFFICIENT_FUNDS, h.prove_commit_sector_and_confirm( &rt, - &precommit, + &vec![], h.make_prove_commit_params(h.next_sector_no), ProveCommitConfig::empty(), ), @@ -468,7 +472,7 @@ fn prove_commit_aborts_if_pledge_requirement_not_met() { ); h.prove_commit_sector_and_confirm( &rt, - &precommit, + &vec![], h.make_prove_commit_params(h.next_sector_no), ProveCommitConfig::empty(), ) @@ -478,7 +482,7 @@ fn prove_commit_aborts_if_pledge_requirement_not_met() { #[test] fn prove_commit_just_after_period_start_permits_post() { - let h = ActorHarness::new(PERIOD_OFFSET); + let mut h = ActorHarness::new(PERIOD_OFFSET); let rt = h.new_runtime(); rt.balance.replace(BIG_BALANCE.clone()); @@ -489,11 +493,11 @@ fn prove_commit_just_after_period_start_permits_post() { // Commit a sector the very next epoch rt.set_epoch(PERIOD_OFFSET + 2); - let sector = - h.commit_and_prove_sector(&rt, MAX_SECTOR_NUMBER, DEFAULT_SECTOR_EXPIRATION, vec![]); + let sectors = + h.commit_and_prove_sectors(&rt, 1, DEFAULT_SECTOR_EXPIRATION as u64, vec![], true); // advance cron to activate power. - h.advance_and_submit_posts(&rt, &[sector]); + h.advance_and_submit_posts(&rt, &[sectors.first().unwrap().clone()]); h.check_state(&rt); } @@ -508,6 +512,7 @@ fn verify_proof_does_not_vest_funds() { h.construct_and_verify(&rt); let deadline = h.deadline(&rt); + let deal_ids = vec![1]; // Make a good commitment for the proof to target. let sector_no = 100; @@ -515,9 +520,9 @@ fn verify_proof_does_not_vest_funds() { sector_no, precommit_epoch - 1, deadline.period_end() + DEFAULT_SECTOR_EXPIRATION * rt.policy.wpost_proving_period, - vec![1], + deal_ids.clone(), ); - let precommit = h.pre_commit_sector_and_get(&rt, params, PreCommitConfig::default(), true); + h.pre_commit_sector_and_get(&rt, params, PreCommitConfig::default(), true); // add 1000 tokens that vest immediately let mut st = h.get_state(&rt); @@ -536,6 +541,6 @@ fn verify_proof_does_not_vest_funds() { let prove_commit = h.make_prove_commit_params(sector_no); // The below call expects exactly the pledge delta for the proven sector, zero for any other vesting. - h.prove_commit_sector_and_confirm(&rt, &precommit, prove_commit, ProveCommitConfig::empty()) + h.prove_commit_sector_and_confirm(&rt, &deal_ids, prove_commit, ProveCommitConfig::empty()) .unwrap(); } diff --git a/actors/miner/tests/util.rs b/actors/miner/tests/util.rs index efbfa4c22..b252c6192 100644 --- a/actors/miner/tests/util.rs +++ b/actors/miner/tests/util.rs @@ -64,15 +64,14 @@ use fil_actor_miner::{ ActiveBeneficiary, Actor, ApplyRewardParams, BeneficiaryTerm, BitFieldQueue, ChangeBeneficiaryParams, ChangeMultiaddrsParams, ChangePeerIDParams, ChangeWorkerAddressParams, CheckSectorProvenParams, CompactCommD, CompactPartitionsParams, CompactSectorNumbersParams, - CronEventPayload, DataActivationNotification, Deadline, - DeadlineInfo, Deadlines, DeclareFaultsParams, DeclareFaultsRecoveredParams, - DeferredCronEventParams, DisputeWindowedPoStParams, ExpirationQueue, ExpirationSet, - ExtendSectorExpiration2Params, ExtendSectorExpirationParams, FaultDeclaration, - GetAvailableBalanceReturn, GetBeneficiaryReturn, GetControlAddressesReturn, - GetMultiaddrsReturn, GetPeerIDReturn, Method, Method as MinerMethod, - MinerConstructorParams as ConstructorParams, MinerInfo, Partition, PendingBeneficiaryChange, - PieceActivationManifest, PieceChange, PieceReturn, PoStPartition, PowerPair, - PreCommitSectorBatchParams, PreCommitSectorBatchParams2, PreCommitSectorParams, + CronEventPayload, DataActivationNotification, Deadline, DeadlineInfo, Deadlines, + DeclareFaultsParams, DeclareFaultsRecoveredParams, DeferredCronEventParams, + DisputeWindowedPoStParams, ExpirationQueue, ExpirationSet, ExtendSectorExpiration2Params, + ExtendSectorExpirationParams, FaultDeclaration, GetAvailableBalanceReturn, + GetBeneficiaryReturn, GetControlAddressesReturn, GetMultiaddrsReturn, GetPeerIDReturn, Method, + Method as MinerMethod, MinerConstructorParams as ConstructorParams, MinerInfo, Partition, + PendingBeneficiaryChange, PieceActivationManifest, PieceChange, PieceReturn, PoStPartition, + PowerPair, PreCommitSectorBatchParams, PreCommitSectorBatchParams2, PreCommitSectorParams, ProveCommitAggregateParams, ProveCommitSectorParams, ProveCommitSectors3Params, ProveCommitSectors3Return, QuantSpec, RecoveryDeclaration, ReportConsensusFaultParams, SectorActivationManifest, SectorChanges, SectorContentChangedParams, @@ -97,6 +96,8 @@ use fil_actors_runtime::{ VERIFIED_REGISTRY_ACTOR_ADDR, }; +const DEFAULT_PIECE_SIZE: u64 = 128; + const RECEIVER_ID: u64 = 1000; pub const TEST_RANDOMNESS_ARRAY_FROM_ONE: [u8; 32] = [ @@ -412,19 +413,30 @@ impl ActorHarness { let sector_deal_ids = deal_ids.get(i).and_then(|ids| Some(ids.clone())).unwrap_or_default(); let has_deals = !sector_deal_ids.is_empty(); - let params = self.make_pre_commit_params( + + let compact_commd = if !has_deals { + CompactCommD::empty() + } else { + let piece_cids: Vec = deal_ids[i] + .iter() + .map(|_deal_id| make_piece_cid(sector_no, i, DEFAULT_PIECE_SIZE)) + .collect(); + + sector_commd_from_pieces(&piece_cids) + }; + + let info = self.make_pre_commit_params_v2( sector_no, precommit_epoch - 1, expiration, - sector_deal_ids, + // We are committing with deals but pass their info in CommD as PCD with deal_ids will fail after nv21 + vec![], + compact_commd, ); - let pcc = if !has_deals { - PreCommitConfig::new(None) - } else { - PreCommitConfig::new(Some(make_unsealed_cid("1".as_bytes()))) - }; - let precommit = self.pre_commit_sector_and_get(rt, params, pcc, first && i == 0); - precommits.push(precommit); + + let precommit = + self.pre_commit_sector_batch_v2_and_get(rt, vec![info], first && i == 0); + precommits.extend(precommit); self.next_sector_no += 1; } @@ -434,11 +446,11 @@ impl ActorHarness { ); let mut info = Vec::with_capacity(num_sectors); - for pc in precommits { + for (i, pc) in precommits.iter().enumerate() { let sector = self .prove_commit_sector_and_confirm( rt, - &pc, + &deal_ids[i], self.make_prove_commit_params(pc.info.sector_number), prove_cfg.clone(), ) @@ -449,44 +461,6 @@ impl ActorHarness { info } - pub fn commit_and_prove_sector( - &self, - rt: &MockRuntime, - sector_no: SectorNumber, - lifetime_periods: i64, - deal_ids: Vec, - ) -> SectorOnChainInfo { - let precommit_epoch = *rt.epoch.borrow(); - let deadline = self.deadline(rt); - let expiration = deadline.period_end() + lifetime_periods * rt.policy.wpost_proving_period; - - // Precommit - let pre_commit_params = - self.make_pre_commit_params(sector_no, precommit_epoch - 1, expiration, deal_ids); - let precommit = self.pre_commit_sector_and_get( - rt, - pre_commit_params.clone(), - PreCommitConfig::default(), - true, - ); - - self.advance_to_epoch_with_cron( - rt, - precommit_epoch + rt.policy.pre_commit_challenge_delay + 1, - ); - - let sector_info = self - .prove_commit_sector_and_confirm( - rt, - &precommit, - self.make_prove_commit_params(pre_commit_params.sector_number), - ProveCommitConfig::empty(), - ) - .unwrap(); - rt.reset(); - sector_info - } - pub fn compact_sector_numbers_raw( &self, rt: &MockRuntime, @@ -703,6 +677,20 @@ impl ActorHarness { result } + pub fn pre_commit_sector_batch_v2_and_get( + &self, + rt: &MockRuntime, + sectors: Vec, + first: bool, + ) -> Vec { + let result = self.pre_commit_sector_batch_v2(rt, §ors, first, &self.base_fee).unwrap(); + + expect_empty(result); + rt.verify(); + + sectors.iter().map(|sector| self.get_precommit(rt, sector.sector_number)).collect() + } + pub fn pre_commit_sector_and_get( &self, rt: &MockRuntime, @@ -770,34 +758,28 @@ impl ActorHarness { pub fn prove_commit_sector_and_confirm( &self, rt: &MockRuntime, - _pc: &SectorPreCommitOnChainInfo, + deal_ids: &Vec, params: ProveCommitSectorParams, cfg: ProveCommitConfig, ) -> Result { let sector_number = params.sector_number; + const CLIENT_ID: ActorID = 1000; + + let mut piece_specs = vec![]; + + for deal_id in deal_ids.iter() { + piece_specs.push((DEFAULT_PIECE_SIZE, CLIENT_ID, NO_ALLOCATION_ID, *deal_id)); - let mut pieces: Vec = vec![]; - - for deal in cfg.activated_deals.get(§or_number).unwrap_or(&Vec::new()) { - let verified_allocation_key = if deal.allocation_id == NO_ALLOCATION_ID { + // TODO modify this ^ for ProveCommitCfgs that specify particular deals and piece cids + /* let verified_allocation_key = if deal.allocation_id == NO_ALLOCATION_ID { None } else { Some(VerifiedAllocationKey { client: deal.client, id: deal.allocation_id }) }; - // To match old behavior send message to f05, but since calls are mocked the data we send doesn't matter - let notify = vec![DataActivationNotification { - address: STORAGE_MARKET_ACTOR_ADDR, - payload: RawBytes::new(deal.data.into()), - }]; - pieces.push(PieceActivationManifest { - cid: deal.data, - size: deal.size, - verified_allocation_key, - notify, - }); + */ } - let activation_manifest = SectorActivationManifest { sector_number, pieces }; + let manifest = make_activation_manifest(sector_number, &piece_specs); let req_activation_succ = true; // Doesn't really matter since there's only 1 let req_notif_succ = false; // CPSV could not require this as it happened in cron @@ -822,7 +804,7 @@ impl ActorHarness { }; let _ = self.prove_commit_sectors3( rt, - &[activation_manifest], + &[manifest], req_activation_succ, req_notif_succ, false,