From 4d20e04008d0ccef077fd22e05fc5bf9c5e75656 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Thu, 11 Jan 2024 18:28:23 +0400 Subject: [PATCH] tests pass --- actors/market/src/state.rs | 1 + .../market/tests/cron_tick_deal_slashing.rs | 12 ++-- actors/market/tests/deal_api_test.rs | 3 +- actors/market/tests/harness.rs | 16 +---- actors/market/tests/market_actor_test.rs | 6 +- .../tests/on_miner_sectors_terminate.rs | 26 ++++---- .../tests/random_cron_epoch_during_publish.rs | 11 +--- actors/miner/src/emit.rs | 25 +++----- actors/miner/src/ext.rs | 1 - actors/miner/src/lib.rs | 37 +++++------ integration_tests/src/expects.rs | 64 ++++++++++--------- .../src/tests/commit_post_test.rs | 19 +++--- .../src/tests/extend_sectors_test.rs | 16 ++--- .../src/tests/prove_commit2_test.rs | 17 +++-- .../src/tests/replica_update2_test.rs | 15 ++--- .../src/tests/replica_update_test.rs | 18 ++---- .../src/tests/verified_claim_test.rs | 2 +- integration_tests/src/util/workflows.rs | 36 +++++------ test_vm/src/messaging.rs | 1 - 19 files changed, 148 insertions(+), 178 deletions(-) diff --git a/actors/market/src/state.rs b/actors/market/src/state.rs index 584f4c143..6a4b09091 100644 --- a/actors/market/src/state.rs +++ b/actors/market/src/state.rs @@ -734,6 +734,7 @@ impl State { //////////////////////////////////////////////////////////////////////////////// // Deal state operations //////////////////////////////////////////////////////////////////////////////// + // Returns (amount slashed, if the deal should be removed, if the deal is past it's end epoch and completed successfully) pub fn process_deal_update( &mut self, store: &BS, diff --git a/actors/market/tests/cron_tick_deal_slashing.rs b/actors/market/tests/cron_tick_deal_slashing.rs index 8087d3d10..5d758010e 100644 --- a/actors/market/tests/cron_tick_deal_slashing.rs +++ b/actors/market/tests/cron_tick_deal_slashing.rs @@ -90,7 +90,7 @@ fn deal_is_slashed() { // terminate rt.set_epoch(tc.termination_epoch); - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![deal_id]); // cron tick let cron_tick_epoch = process_epoch(tc.deal_start, deal_id); @@ -136,7 +136,7 @@ fn deal_is_slashed_at_the_end_epoch_should_not_be_slashed_and_should_be_consider // as deal is considered to be expired. rt.set_epoch(END_EPOCH); - terminate_deals_for(&rt, PROVIDER_ADDR, &[SECTOR_NUMBER], vec![]); + terminate_deals(&rt, PROVIDER_ADDR, &[SECTOR_NUMBER], vec![]); // on the next cron tick, it will be processed as expired let current = END_EPOCH + 300; @@ -183,7 +183,7 @@ fn deal_payment_and_slashing_correctly_processed_in_same_crontick() { // set slash epoch of deal let slash_epoch = current + Policy::default().deal_updates_interval + 1; rt.set_epoch(slash_epoch); - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![deal_id]); let duration = slash_epoch - current; let current = current + Policy::default().deal_updates_interval + 2; @@ -241,7 +241,7 @@ fn slash_multiple_deals_in_the_same_epoch() { // set slash epoch of deal at 100 epochs past last process epoch rt.set_epoch(process_epoch(START_EPOCH, deal_id3) + 100); - terminate_deals(&rt, PROVIDER_ADDR, &[SECTOR_NUMBER]); + terminate_deals(&rt, PROVIDER_ADDR, &[SECTOR_NUMBER], vec![deal_id1, deal_id2, deal_id3]); // process slashing of deals 200 epochs later rt.set_epoch(process_epoch(START_EPOCH, deal_id3) + 300); @@ -310,7 +310,7 @@ fn regular_payments_till_deal_is_slashed_and_then_slashing_is_processed() { // now terminate the deal 1 epoch later rt.set_epoch(process_start + Policy::default().deal_updates_interval + 1); - terminate_deals(&rt, PROVIDER_ADDR, &[SECTOR_NUMBER]); + terminate_deals(&rt, PROVIDER_ADDR, &[SECTOR_NUMBER], vec![deal_id]); // Setting the epoch to anything less than next schedule will not make any change even though the deal is slashed rt.set_epoch(process_start + 2 * Policy::default().deal_updates_interval - 1); @@ -365,7 +365,7 @@ fn regular_payments_till_deal_expires_and_then_we_attempt_to_slash_it_but_it_wil // as deal is considered to be expired. let duration = END_EPOCH - current; rt.set_epoch(END_EPOCH); - terminate_deals_for(&rt, PROVIDER_ADDR, &[SECTOR_NUMBER], vec![]); + terminate_deals(&rt, PROVIDER_ADDR, &[SECTOR_NUMBER], vec![]); // next epoch for cron schedule is endEpoch + 300 -> // setting epoch to higher than that will cause deal to be expired, payment will be made diff --git a/actors/market/tests/deal_api_test.rs b/actors/market/tests/deal_api_test.rs index 96b61a2ea..4b772e64a 100644 --- a/actors/market/tests/deal_api_test.rs +++ b/actors/market/tests/deal_api_test.rs @@ -131,7 +131,8 @@ fn activation() { // terminate early let terminate_epoch = activate_epoch + 100; rt.set_epoch(terminate_epoch); - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![id]); let activation: GetDealActivationReturn = query_deal(&rt, Method::GetDealActivationExported, id); assert_eq!(activate_epoch, activation.activated); diff --git a/actors/market/tests/harness.rs b/actors/market/tests/harness.rs index 1c878bac7..6fe040ee4 100644 --- a/actors/market/tests/harness.rs +++ b/actors/market/tests/harness.rs @@ -418,6 +418,8 @@ pub fn batch_activate_deals_raw( rt.set_caller(*MINER_ACTOR_CODE_ID, provider); rt.expect_validate_caller_type(vec![Type::Miner]); + let params = BatchActivateDealsParams { sectors: sectors_deals, compute_cid }; + for deal_id in expected_activated_deals { let dp = get_deal_proposal(rt, deal_id); @@ -429,9 +431,6 @@ pub fn batch_activate_deals_raw( dp.provider.id().unwrap(), ); } - - let params = BatchActivateDealsParams { sectors: sectors_deals, compute_cid }; - let ret = rt.call::( Method::BatchActivateDeals as u64, IpldBlock::serialize_cbor(¶ms).unwrap(), @@ -1241,7 +1240,7 @@ pub fn generate_deal_proposal( ) } -pub fn terminate_deals_for( +pub fn terminate_deals( rt: &MockRuntime, miner_addr: Address, sectors: &[SectorNumber], @@ -1252,15 +1251,6 @@ pub fn terminate_deals_for( rt.verify(); } -pub fn terminate_deals(rt: &MockRuntime, miner_addr: Address, sectors: &[SectorNumber]) { - let all_deal_ids = - sectors.iter().flat_map(|s| get_sector_deal_ids(rt, &miner_addr, *s)).collect::>(); - - let ret = terminate_deals_raw(rt, miner_addr, sectors, all_deal_ids).unwrap(); - assert!(ret.is_none()); - rt.verify(); -} - pub fn terminate_deals_raw( rt: &MockRuntime, miner_addr: Address, diff --git a/actors/market/tests/market_actor_test.rs b/actors/market/tests/market_actor_test.rs index b27c6cb61..0da2336c9 100644 --- a/actors/market/tests/market_actor_test.rs +++ b/actors/market/tests/market_actor_test.rs @@ -339,7 +339,7 @@ fn worker_balance_after_withdrawal_must_account_for_slashed_funds() { // slash the deal rt.set_epoch(publish_epoch + 1); - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![deal_id]); let st = get_deal_state(&rt, deal_id); assert_eq!(publish_epoch + 1, st.slash_epoch); @@ -1486,7 +1486,7 @@ fn slash_a_deal_and_make_payment_for_another_deal_in_the_same_epoch() { // slash deal1 let slash_epoch = process_epoch(start_epoch, deal_id2) + ChainEpoch::from(100); rt.set_epoch(slash_epoch); - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![deal_id1]); // cron tick will slash deal1 and make payment for deal2 rt.expect_send_simple( @@ -1940,7 +1940,7 @@ fn locked_fund_tracking_states() { // slash deal1 rt.set_epoch(curr + 1); - terminate_deals(&rt, m1.provider, &[sector_number]); + terminate_deals(&rt, m1.provider, &[sector_number], vec![deal_id1]); // cron tick to slash deal1 and expire deal2 rt.set_epoch(end_epoch); diff --git a/actors/market/tests/on_miner_sectors_terminate.rs b/actors/market/tests/on_miner_sectors_terminate.rs index 2934479f2..da68309cf 100644 --- a/actors/market/tests/on_miner_sectors_terminate.rs +++ b/actors/market/tests/on_miner_sectors_terminate.rs @@ -54,11 +54,11 @@ fn terminate_multiple_deals_from_single_provider() { .try_into() .unwrap(); - terminate_deals(&rt, PROVIDER_ADDR, &[id1]); + terminate_deals(&rt, PROVIDER_ADDR, &[id1], vec![id1]); assert_deals_terminated(&rt, current_epoch, &[id1]); assert_deals_not_terminated(&rt, &[id2, id3]); - terminate_deals(&rt, PROVIDER_ADDR, &[id2, id3]); + terminate_deals(&rt, PROVIDER_ADDR, &[id2, id3], vec![id2, id3]); assert_deals_terminated(&rt, current_epoch, &[id1, id2, id3]); } @@ -111,13 +111,13 @@ fn terminate_multiple_deals_from_multiple_providers() { ); assert!(ret.activation_results.all_ok()); - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![deal1, deal2, deal3]); assert_deals_terminated(&rt, current_epoch, &[deal1, deal2, deal3]); assert_eq!(Vec::::new(), get_sector_deal_ids(&rt, &PROVIDER_ADDR, sector_number)); assert_deals_not_terminated(&rt, &[deal4, deal5]); assert_eq!(vec![deal4, deal5], get_sector_deal_ids(&rt, &provider2, sector_number)); - terminate_deals(&rt, provider2, &[sector_number]); + terminate_deals(&rt, provider2, &[sector_number], vec![deal4, deal5]); assert_deals_terminated(&rt, current_epoch, &[deal4, deal5]); assert_eq!(Vec::::new(), get_sector_deal_ids(&rt, &provider2, sector_number)); check_state(&rt); @@ -144,7 +144,7 @@ fn ignore_sector_that_does_not_exist() { let ret = activate_deals(&rt, sector_expiry, PROVIDER_ADDR, current_epoch, sector_number, &[deal1]); assert!(ret.activation_results.all_ok()); - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number + 1]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number + 1], vec![]); let s = get_deal_state(&rt, deal1); assert_eq!(s.slash_epoch, -1); @@ -197,7 +197,7 @@ fn terminate_valid_deals_along_with_just_expired_deal() { let new_epoch = end_epoch - 1; rt.set_epoch(new_epoch); - terminate_deals_for(&rt, PROVIDER_ADDR, &[sector_number], vec![deal1, deal2]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![deal1, deal2]); assert_deals_terminated(&rt, new_epoch, &[deal1, deal2]); // Not cleaned up yet. assert_deals_not_terminated(&rt, &[deal3]); @@ -256,7 +256,7 @@ fn terminate_valid_deals_along_with_expired_and_cleaned_up_deal() { cron_tick(&rt); - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![deal_ids[0]]); assert_deals_terminated(&rt, new_epoch, &deal_ids[0..0]); assert_deal_deleted(&rt, deal_ids[1], &deal2, sector_number); check_state(&rt); @@ -285,11 +285,11 @@ fn terminating_a_deal_the_second_time_does_not_change_its_slash_epoch() { assert!(ret.activation_results.all_ok()); // terminating the deal so slash epoch is the current epoch - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![deal1]); // set a new epoch and terminate again -> however slash epoch will still be the old epoch. rt.set_epoch(current_epoch + 1); - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![]); let s = get_deal_state(&rt, deal1); assert_eq!(s.slash_epoch, current_epoch); check_state(&rt); @@ -331,7 +331,7 @@ fn terminating_new_deals_and_an_already_terminated_deal_only_terminates_the_new_ ); assert!(ret.activation_results.all_ok()); // Terminate them - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![deal1]); // Activate other deals in the same sector let ret = activate_deals( @@ -346,7 +346,7 @@ fn terminating_new_deals_and_an_already_terminated_deal_only_terminates_the_new_ // set a new epoch and terminate again let new_epoch = current_epoch + 1; rt.set_epoch(new_epoch); - terminate_deals(&rt, PROVIDER_ADDR, &[sector_number]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![deal2, deal3]); let s1 = get_deal_state(&rt, deal1); assert_eq!(s1.slash_epoch, current_epoch); @@ -383,7 +383,7 @@ fn do_not_terminate_deal_if_end_epoch_is_equal_to_or_less_than_current_epoch() { activate_deals(&rt, sector_expiry, PROVIDER_ADDR, current_epoch, sector_number, &[deal1]); assert!(ret.activation_results.all_ok()); rt.set_epoch(end_epoch); - terminate_deals_for(&rt, PROVIDER_ADDR, &[sector_number], vec![]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![]); assert_deals_not_terminated(&rt, &[deal1]); // deal2 has end epoch less than current epoch when terminate is called @@ -400,7 +400,7 @@ fn do_not_terminate_deal_if_end_epoch_is_equal_to_or_less_than_current_epoch() { activate_deals(&rt, sector_expiry, PROVIDER_ADDR, current_epoch, sector_number, &[deal2]); assert!(ret.activation_results.all_ok()); rt.set_epoch(end_epoch + 1); - terminate_deals_for(&rt, PROVIDER_ADDR, &[sector_number], vec![]); + terminate_deals(&rt, PROVIDER_ADDR, &[sector_number], vec![]); assert_deals_not_terminated(&rt, &[deal2]); check_state(&rt); diff --git a/actors/market/tests/random_cron_epoch_during_publish.rs b/actors/market/tests/random_cron_epoch_during_publish.rs index ef7e77b75..772a5e2f2 100644 --- a/actors/market/tests/random_cron_epoch_during_publish.rs +++ b/actors/market/tests/random_cron_epoch_during_publish.rs @@ -152,15 +152,8 @@ fn activation_after_deal_start_epoch_but_before_it_is_processed_fails() { let curr_epoch = START_EPOCH + 1; rt.set_epoch(curr_epoch); - let res = activate_deals_for( - &rt, - SECTOR_EXPIRY, - PROVIDER_ADDR, - curr_epoch, - SECTOR_NUMBER, - &[deal_id], - vec![], - ); + let res = + activate_deals_for(&rt, SECTOR_EXPIRY, PROVIDER_ADDR, curr_epoch, SECTOR_NUMBER, &[deal_id], vec![]); assert_eq!(res.activation_results.codes(), vec![EX_DEAL_EXPIRED]); check_state(&rt); } diff --git a/actors/miner/src/emit.rs b/actors/miner/src/emit.rs index 40aa99399..c802285cb 100644 --- a/actors/miner/src/emit.rs +++ b/actors/miner/src/emit.rs @@ -1,7 +1,4 @@ use cid::Cid; -use fvm_shared::bigint::BigInt; -use fvm_shared::piece::PaddedPieceSize; -// A namespace for helpers that build and emit provider Actor events. use fil_actors_runtime::runtime::Runtime; use fil_actors_runtime::{ActorError, EventBuilder}; use fvm_shared::sector::SectorNumber; @@ -17,8 +14,8 @@ pub fn sector_precommitted(rt: &impl Runtime, sector: SectorNumber) -> Result<() pub fn sector_activated( rt: &impl Runtime, sector: SectorNumber, - unsealed_cid: &Cid, - pieces: &[(Cid, PaddedPieceSize)], + unsealed_cid: Option, + pieces: &[(Cid, u64)], ) -> Result<(), ActorError> { rt.emit_event( &EventBuilder::new() @@ -32,8 +29,8 @@ pub fn sector_activated( pub fn sector_updated( rt: &impl Runtime, sector: SectorNumber, - unsealed_cid: &Cid, - pieces: &[(Cid, PaddedPieceSize)], + unsealed_cid: Option, + pieces: &[(Cid, u64)], ) -> Result<(), ActorError> { rt.emit_event( &EventBuilder::new() @@ -54,8 +51,8 @@ trait WithSectorInfo { fn with_sector_info( self, sector: SectorNumber, - unsealed_cid: &Cid, - pieces: &[(Cid, PaddedPieceSize)], + unsealed_cid: Option, + pieces: &[(Cid, u64)], ) -> EventBuilder; } @@ -63,16 +60,14 @@ impl WithSectorInfo for EventBuilder { fn with_sector_info( self, sector: SectorNumber, - unsealed_cid: &Cid, - pieces: &[(Cid, PaddedPieceSize)], + unsealed_cid: Option, + pieces: &[(Cid, u64)], ) -> EventBuilder { let mut event = - self.field_indexed("sector", §or).field_indexed("unsealed-cid", unsealed_cid); + self.field_indexed("sector", §or).field_indexed("unsealed-cid", &unsealed_cid); for piece in pieces { - event = event - .field_indexed("piece-cid", &piece.0) - .field("piece-size", &BigInt::from(piece.1 .0)); + event = event.field_indexed("piece-cid", &piece.0).field("piece-size", &piece.1); } event } diff --git a/actors/miner/src/ext.rs b/actors/miner/src/ext.rs index d3e0bd69b..3d7ae2795 100644 --- a/actors/miner/src/ext.rs +++ b/actors/miner/src/ext.rs @@ -23,7 +23,6 @@ pub mod market { pub const VERIFY_DEALS_FOR_ACTIVATION_METHOD: u64 = 5; pub const BATCH_ACTIVATE_DEALS_METHOD: u64 = 6; pub const ON_MINER_SECTORS_TERMINATE_METHOD: u64 = 7; - pub const GET_DEAL_DATA_COMMITMENT: u64 = frc42_dispatch::method_hash!("GetDealDataCommitment"); #[derive(Serialize_tuple, Deserialize_tuple)] pub struct SectorDeals { diff --git a/actors/miner/src/lib.rs b/actors/miner/src/lib.rs index dafee5cdd..b2ba3425d 100644 --- a/actors/miner/src/lib.rs +++ b/actors/miner/src/lib.rs @@ -20,7 +20,7 @@ use fvm_shared::clock::{ChainEpoch, QuantSpec}; use fvm_shared::deal::DealID; use fvm_shared::econ::TokenAmount; use fvm_shared::error::*; -use fvm_shared::piece::{PaddedPieceSize, PieceInfo}; +use fvm_shared::piece::PieceInfo; use fvm_shared::randomness::*; use fvm_shared::reward::ThisEpochRewardReturn; use fvm_shared::sector::*; @@ -835,11 +835,11 @@ impl Actor { )?; for (i, pc) in activated_precommits.iter().enumerate() { - let unsealed_cid = pc.info.unsealed_cid.get_cid(pc.info.seal_proof)?; + let unsealed_cid = pc.info.unsealed_cid.0; emit::sector_activated( rt, pc.info.sector_number, - &unsealed_cid, + unsealed_cid, pieces.get(i).unwrap(), )?; } @@ -985,7 +985,7 @@ impl Actor { emit::sector_updated( rt, usi.update.sector_number, - &computed_commd, + Some(computed_commd), pieces.get(i).unwrap(), )?; } @@ -1192,14 +1192,12 @@ impl Actor { pieces: &update.pieces, }); - // create a Vec<(Cid, PaddedPieceSize)> from update.pieces and call emit::sector_updated - let pieces: Vec<(Cid, PaddedPieceSize)> = - update.pieces.iter().map(|x| (x.cid, x.size)).collect(); + let pieces: Vec<(Cid, u64)> = update.pieces.iter().map(|x| (x.cid, x.size.0)).collect(); emit::sector_updated( rt, update.sector, - sector_commds.get(&update.sector).unwrap(), + sector_commds.get(&update.sector).copied(), &pieces, )?; } @@ -1907,11 +1905,11 @@ impl Actor { pieces: &activations.pieces, }); - let pieces: Vec<(Cid, PaddedPieceSize)> = - activations.pieces.iter().map(|p| (p.cid, p.size)).collect(); - let unsealed_cid = sector.info.unsealed_cid.get_cid(sector.info.seal_proof)?; + let pieces: Vec<(Cid, u64)> = + activations.pieces.iter().map(|p| (p.cid, p.size.0)).collect(); + let unsealed_cid = sector.info.unsealed_cid.0; - emit::sector_activated(rt, sector.info.sector_number, &unsealed_cid, &pieces)?; + emit::sector_activated(rt, sector.info.sector_number, unsealed_cid, &pieces)?; } notify_data_consumers(rt, ¬ifications, params.require_notification_success)?; @@ -2027,11 +2025,11 @@ impl Actor { )?; for (i, pc) in successful_activations.iter().enumerate() { - let unsealed_cid = pc.info.unsealed_cid.get_cid(pc.info.seal_proof)?; + let unsealed_cid = pc.info.unsealed_cid.0; emit::sector_activated( rt, pc.info.sector_number, - &unsealed_cid, + unsealed_cid, pieces.get(i).unwrap(), )?; } @@ -5497,8 +5495,7 @@ fn activate_sectors_deals( rt: &impl Runtime, activation_infos: &[DealsActivationInput], compute_unsealed_cid: bool, -) -> Result<(BatchReturn, Vec, Vec>), ActorError> -{ +) -> Result<(BatchReturn, Vec, 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 @@ -5541,7 +5538,7 @@ fn activate_sectors_deals( return Err(actor_error!(illegal_argument, "all deals failed to activate")); } - let mut piece_infos: Vec> = vec![]; + let mut piece_infos: Vec> = vec![]; // Filter the DealsActivationInfo for successfully activated sectors let successful_activation_infos = @@ -5584,14 +5581,14 @@ fn activate_sectors_deals( .iter() .zip(claim_res.sector_claims) .map(|(sector_deals, sector_claim)| { - let mut piece_infos_for_sector: Vec<(Cid, PaddedPieceSize)> = vec![]; + let mut piece_infos_for_sector: Vec<(Cid, u64)> = vec![]; for verified_info in §or_deals.verified_infos { - piece_infos_for_sector.push((verified_info.data, verified_info.size)); + piece_infos_for_sector.push((verified_info.data, verified_info.size.0)); } for unverified_info in §or_deals.unverified_infos { - piece_infos_for_sector.push((unverified_info.data, unverified_info.size)); + piece_infos_for_sector.push((unverified_info.data, unverified_info.size.0)); } piece_infos.push(piece_infos_for_sector); diff --git a/integration_tests/src/expects.rs b/integration_tests/src/expects.rs index f50b8d1b3..29d1b9e51 100644 --- a/integration_tests/src/expects.rs +++ b/integration_tests/src/expects.rs @@ -6,11 +6,9 @@ use fvm_ipld_bitfield::BitField; use fvm_ipld_encoding::ipld_block::IpldBlock; use fvm_ipld_encoding::RawBytes; use fvm_shared::address::Address; -use fvm_shared::bigint::BigInt; use fvm_shared::clock::ChainEpoch; use fvm_shared::deal::DealID; use fvm_shared::econ::TokenAmount; -use fvm_shared::piece::PaddedPieceSize; use fvm_shared::sector::{RegisteredSealProof, SectorNumber}; use fvm_shared::{ActorID, METHOD_SEND}; use num_traits::Zero; @@ -47,27 +45,31 @@ impl Expect { pub fn market_activate_deals( from: ActorID, deals: Vec, + // TODO: A more future-proof one would take the deals as a Vec<(DealID, ActorId)> + client_id: ActorID, sector_number: SectorNumber, sector_expiry: ChainEpoch, sector_type: RegisteredSealProof, compute_cid: bool, - client_id: &ActorID, ) -> ExpectInvocation { - let events: Vec = deals - .iter() - .map(|deal_id| Expect::build_market_event("deal-activated", deal_id, client_id, &from)) - .collect(); - let params = IpldBlock::serialize_cbor(&BatchActivateDealsParams { sectors: vec![SectorDeals { sector_number, - deal_ids: deals, + deal_ids: deals.clone(), sector_expiry, sector_type, }], compute_cid, }) .unwrap(); + + let events: Vec = deals + .iter() + .map(|deal_id| { + Expect::build_market_event("deal-activated", deal_id.clone(), client_id, from) + }) + .collect(); + ExpectInvocation { from, to: STORAGE_MARKET_ACTOR_ADDR, @@ -83,19 +85,20 @@ impl Expect { from: ActorID, epoch: ChainEpoch, sectors: Vec, - deal_clients: Vec<(DealID, ActorID)>, + deals: Vec<(DealID, ActorID)>, ) -> ExpectInvocation { - let events: Vec = deal_clients - .iter() - .map(|(deal_id, client)| { - Expect::build_market_event("deal-terminated", deal_id, client, &from) - }) - .collect(); - let bf = BitField::try_from_bits(sectors).unwrap(); let params = IpldBlock::serialize_cbor(&OnMinerSectorsTerminateParams { epoch, sectors: bf }) .unwrap(); + + let events: Vec = deals + .into_iter() + .map(|(deal_id, client)| { + Expect::build_market_event("deal-terminated", deal_id, client, from.clone()) + }) + .collect(); + ExpectInvocation { from, to: STORAGE_MARKET_ACTOR_ADDR, @@ -369,9 +372,9 @@ impl Expect { pub fn build_verifreg_event( typ: &str, - id: &u64, - client: &ActorID, - provider: &ActorID, + id: u64, + client: ActorID, + provider: ActorID, ) -> EmittedEvent { EmittedEvent { emitter: VERIFIED_REGISTRY_ACTOR_ID, @@ -387,9 +390,9 @@ impl Expect { pub fn build_market_event( typ: &str, - deal_id: &DealID, - client: &ActorID, - provider: &ActorID, + deal_id: DealID, + client: ActorID, + provider: ActorID, ) -> EmittedEvent { EmittedEvent { emitter: STORAGE_MARKET_ACTOR_ID, @@ -420,10 +423,10 @@ impl Expect { pub fn build_sector_activation_event( typ: &str, - miner_id: &ActorID, - sector_number: &SectorNumber, - unsealed_cid: &Cid, - pieces: &Vec<(Cid, PaddedPieceSize)>, + miner_id: ActorID, + sector_number: SectorNumber, + unsealed_cid: Option, + pieces: &Vec<(Cid, u64)>, ) -> EmittedEvent { let mut base_event = EventBuilder::new() .typ(typ) @@ -431,11 +434,10 @@ impl Expect { .field_indexed("unsealed-cid", &unsealed_cid); for piece in pieces { - base_event = base_event - .field_indexed("piece-cid", &piece.0) - .field("piece-size", &BigInt::from(piece.1 .0)); + base_event = + base_event.field_indexed("piece-cid", &piece.0).field("piece-size", &piece.1); } - EmittedEvent { emitter: *miner_id, event: base_event.build().unwrap() } + EmittedEvent { emitter: miner_id, event: base_event.build().unwrap() } } } diff --git a/integration_tests/src/tests/commit_post_test.rs b/integration_tests/src/tests/commit_post_test.rs index 786657d39..b714a642b 100644 --- a/integration_tests/src/tests/commit_post_test.rs +++ b/integration_tests/src/tests/commit_post_test.rs @@ -7,7 +7,6 @@ use fvm_shared::address::Address; use fvm_shared::bigint::Zero; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; -use fvm_shared::piece::PaddedPieceSize; use fvm_shared::randomness::Randomness; use fvm_shared::sector::{PoStProof, RegisteredSealProof, SectorNumber, MAX_SECTOR_NUMBER}; @@ -78,7 +77,6 @@ fn setup(v: &dyn VM) -> (MinerInfo, SectorInfo) { None, ); let pc = &infos[0]; - let unsealed_cid = pc.info.unsealed_cid.get_cid(pc.info.seal_proof).unwrap(); let balances = miner_balance(v, &id_addr); assert!(balances.pre_commit_deposit.is_positive()); @@ -86,6 +84,7 @@ fn setup(v: &dyn VM) -> (MinerInfo, SectorInfo) { let prove_time = v.epoch() + Policy::default().pre_commit_challenge_delay + 1; advance_by_deadline_to_epoch(v, &id_addr, prove_time); + let unsealed_cid = pc.info.unsealed_cid.0; // prove commit, cron, advance to post time let prove_params = ProveCommitSectorParams { sector_number, proof: vec![].into() }; let prove_params_ser = IpldBlock::serialize_cbor(&prove_params).unwrap(); @@ -116,7 +115,7 @@ fn setup(v: &dyn VM) -> (MinerInfo, SectorInfo) { ) .unwrap(); assert_eq!(ExitCode::OK, res.code); - let pieces: Vec<(Cid, PaddedPieceSize)> = vec![]; + let pieces: Vec<(Cid, u64)> = vec![]; ExpectInvocation { to: CRON_ACTOR_ADDR, method: CronMethod::EpochTick as u64, @@ -137,9 +136,9 @@ fn setup(v: &dyn VM) -> (MinerInfo, SectorInfo) { )]), events: vec![Expect::build_sector_activation_event( "sector-activated", - &id_addr.id().unwrap(), - §or_number, - &unsealed_cid, + id_addr.id().unwrap(), + sector_number, + unsealed_cid, &pieces, )], ..Default::default() @@ -774,12 +773,12 @@ pub fn aggregate_one_precommit_expires_test(v: &dyn VM) { let events: Vec = later_precommits .iter() .map(|info| { - let pieces: Vec<(Cid, PaddedPieceSize)> = vec![]; - let unsealed_cid = &info.info.unsealed_cid.get_cid(info.info.seal_proof).unwrap(); + let pieces: Vec<(Cid, u64)> = vec![]; + let unsealed_cid = info.info.unsealed_cid.0; Expect::build_sector_activation_event( "sector-activated", - &miner_id, - &info.info.sector_number, + miner_id, + info.info.sector_number, unsealed_cid, &pieces, ) diff --git a/integration_tests/src/tests/extend_sectors_test.rs b/integration_tests/src/tests/extend_sectors_test.rs index 1ab47b767..68ff6185f 100644 --- a/integration_tests/src/tests/extend_sectors_test.rs +++ b/integration_tests/src/tests/extend_sectors_test.rs @@ -657,7 +657,7 @@ pub fn extend_updated_sector_with_claims_test(v: &dyn VM) { let old_power = power_for_sector(seal_proof.sector_size().unwrap(), &initial_sector_info); - let pieces: Vec<(Cid, PaddedPieceSize)> = vec![(piece_cid, piece_size)]; + let pieces: Vec<(Cid, u64)> = vec![(piece_cid, piece_size.0)]; let pis: Vec = vec![PieceInfo { cid: piece_cid, size: piece_size }]; let unsealed_cid = v.primitives().compute_unsealed_sector_cid(seal_proof, &pis).unwrap(); @@ -670,11 +670,11 @@ pub fn extend_updated_sector_with_claims_test(v: &dyn VM) { Expect::market_activate_deals( miner_id, deal_ids, + verified_client.id().unwrap(), sector_number, initial_sector_info.expiration, initial_sector_info.seal_proof, true, - &verified_client.id().unwrap(), ), ExpectInvocation { from: miner_id, @@ -682,9 +682,9 @@ pub fn extend_updated_sector_with_claims_test(v: &dyn VM) { method: VerifregMethod::ClaimAllocations as u64, events: vec![Expect::build_verifreg_event( "claim", - &claim_id, - &verified_client.id().unwrap(), - &miner_id, + claim_id, + verified_client.id().unwrap(), + miner_id, )], ..Default::default() }, @@ -698,9 +698,9 @@ pub fn extend_updated_sector_with_claims_test(v: &dyn VM) { ]), events: vec![Expect::build_sector_activation_event( "sector-updated", - &miner_id, - §or_number, - &unsealed_cid, + miner_id, + sector_number, + Some(unsealed_cid), &pieces, )], ..Default::default() diff --git a/integration_tests/src/tests/prove_commit2_test.rs b/integration_tests/src/tests/prove_commit2_test.rs index c5f3d4a91..22ffd12b4 100644 --- a/integration_tests/src/tests/prove_commit2_test.rs +++ b/integration_tests/src/tests/prove_commit2_test.rs @@ -228,15 +228,14 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) { .iter() .enumerate() .map(|(i, sa)| { - let unsealed_cid = meta.get(i).unwrap().commd.get_cid(seal_proof).unwrap(); + let unsealed_cid = meta.get(i).unwrap().commd.0; - let pieces: Vec<(Cid, PaddedPieceSize)> = - sa.pieces.iter().map(|p| (p.cid, p.size)).collect(); + let pieces: Vec<(Cid, u64)> = sa.pieces.iter().map(|p| (p.cid, p.size.0)).collect(); Expect::build_sector_activation_event( "sector-activated", - &miner_id, - &sa.sector_number, - &unsealed_cid, + miner_id, + sa.sector_number, + unsealed_cid, &pieces, ) }) @@ -293,9 +292,9 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) { .unwrap(), ), events: vec![ - Expect::build_verifreg_event("claim", &alloc_ids_s2[0], &client_id, &miner_id), - Expect::build_verifreg_event("claim", &alloc_ids_s2[1], &client_id, &miner_id), - Expect::build_verifreg_event("claim", &alloc_ids_s4[0], &client_id, &miner_id), + Expect::build_verifreg_event("claim", alloc_ids_s2[0], client_id, miner_id), + Expect::build_verifreg_event("claim", alloc_ids_s2[1], client_id, miner_id), + Expect::build_verifreg_event("claim", alloc_ids_s4[0], client_id, miner_id), ], ..Default::default() }, diff --git a/integration_tests/src/tests/replica_update2_test.rs b/integration_tests/src/tests/replica_update2_test.rs index cf3e61741..486b89466 100644 --- a/integration_tests/src/tests/replica_update2_test.rs +++ b/integration_tests/src/tests/replica_update2_test.rs @@ -283,8 +283,7 @@ pub fn prove_replica_update2_test(v: &dyn VM) { let events: Vec = manifests .iter() .map(|m| { - let pieces: Vec<(Cid, PaddedPieceSize)> = - m.pieces.iter().map(|p| (p.cid, p.size)).collect(); + let pieces: Vec<(Cid, u64)> = m.pieces.iter().map(|p| (p.cid, p.size.0)).collect(); let pis: Vec = m.pieces.iter().map(|p| PieceInfo { cid: p.cid, size: p.size }).collect(); @@ -292,9 +291,9 @@ pub fn prove_replica_update2_test(v: &dyn VM) { v.primitives().compute_unsealed_sector_cid(seal_proof, &pis).unwrap(); Expect::build_sector_activation_event( "sector-updated", - &miner_id, - &m.sector, - &unsealed_cid, + miner_id, + m.sector, + Some(unsealed_cid), &pieces, ) }) @@ -351,9 +350,9 @@ pub fn prove_replica_update2_test(v: &dyn VM) { .unwrap(), ), events: vec![ - Expect::build_verifreg_event("claim", &alloc_ids_s2[0], &client_id, &miner_id), - Expect::build_verifreg_event("claim", &alloc_ids_s2[1], &client_id, &miner_id), - Expect::build_verifreg_event("claim", &alloc_ids_s4[0], &client_id, &miner_id), + Expect::build_verifreg_event("claim", alloc_ids_s2[0], client_id, miner_id), + Expect::build_verifreg_event("claim", alloc_ids_s2[1], client_id, miner_id), + Expect::build_verifreg_event("claim", alloc_ids_s4[0], client_id, miner_id), ], ..Default::default() }, diff --git a/integration_tests/src/tests/replica_update_test.rs b/integration_tests/src/tests/replica_update_test.rs index 94effe6ae..e30283296 100644 --- a/integration_tests/src/tests/replica_update_test.rs +++ b/integration_tests/src/tests/replica_update_test.rs @@ -1043,15 +1043,11 @@ pub fn replica_update_verified_deal_test(v: &dyn VM) { assert_eq!(vec![100], bf_all(updated_sectors)); let claim_id = 1_u64; - let claim_event = Expect::build_verifreg_event( - "claim", - &claim_id, - &client.id().unwrap(), - &maddr.id().unwrap(), - ); + let claim_event = + Expect::build_verifreg_event("claim", claim_id, client.id().unwrap(), maddr.id().unwrap()); let old_power = power_for_sector(seal_proof.sector_size().unwrap(), &old_sector_info); - let pieces: Vec<(Cid, PaddedPieceSize)> = vec![(proposal.piece_cid, proposal.piece_size)]; + let pieces: Vec<(Cid, u64)> = vec![(proposal.piece_cid, proposal.piece_size.0)]; let pis: Vec = vec![PieceInfo { cid: proposal.piece_cid, size: proposal.piece_size }]; let unsealed_cid = v.primitives().compute_unsealed_sector_cid(seal_proof, &pis).unwrap(); @@ -1065,11 +1061,11 @@ pub fn replica_update_verified_deal_test(v: &dyn VM) { Expect::market_activate_deals( miner_id, deal_ids.clone(), + client.id().unwrap(), sector_number, old_sector_info.expiration, old_sector_info.seal_proof, true, - &client.id().unwrap(), ), ExpectInvocation { from: miner_id, @@ -1089,9 +1085,9 @@ pub fn replica_update_verified_deal_test(v: &dyn VM) { ]), events: vec![Expect::build_sector_activation_event( "sector-updated", - &miner_id, - §or_number, - &unsealed_cid, + miner_id, + sector_number, + Some(unsealed_cid), &pieces, )], ..Default::default() diff --git a/integration_tests/src/tests/verified_claim_test.rs b/integration_tests/src/tests/verified_claim_test.rs index aeffa821c..7c82568a1 100644 --- a/integration_tests/src/tests/verified_claim_test.rs +++ b/integration_tests/src/tests/verified_claim_test.rs @@ -253,7 +253,7 @@ pub fn verified_claim_scenario_test(v: &dyn VM) { claim_id, deal_size, new_max_term, - &verified_client.id().unwrap(), + verified_client.id().unwrap(), ); // The miner extends the sector into the second year. diff --git a/integration_tests/src/util/workflows.rs b/integration_tests/src/util/workflows.rs index a5697ccb0..3b516ef5e 100644 --- a/integration_tests/src/util/workflows.rs +++ b/integration_tests/src/util/workflows.rs @@ -406,17 +406,17 @@ pub fn prove_commit_sectors( let events: Vec = to_prove .iter() .map(|ps| { - let mut pieces: Vec<(Cid, PaddedPieceSize)> = vec![]; + let mut pieces: Vec<(Cid, u64)> = vec![]; for deal_id in &ps.info.deal_ids { let proposal = st.get_proposal(&store, *deal_id).unwrap(); - pieces.push((proposal.piece_cid, proposal.piece_size)); + pieces.push((proposal.piece_cid, proposal.piece_size.0)); } - let unsealed_cid = &ps.info.unsealed_cid.get_cid(ps.info.seal_proof).unwrap(); + let unsealed_cid = ps.info.unsealed_cid.0; Expect::build_sector_activation_event( "sector-activated", - &miner_id, - &ps.info.sector_number, + miner_id, + ps.info.sector_number, unsealed_cid, &pieces, ) @@ -887,9 +887,9 @@ pub fn verifreg_remove_expired_allocations( let alloc = allocs.get(client.id().unwrap(), *id).unwrap().unwrap(); Expect::build_verifreg_event( "allocation-removed", - id, - &client.id().unwrap(), - &alloc.provider, + *id, + client.id().unwrap(), + alloc.provider, ) }) .collect(); @@ -982,7 +982,7 @@ pub fn datacap_create_allocations( .iter() .enumerate() .map(|(i, alloc_id)| { - Expect::build_verifreg_event("allocation", alloc_id, &client_id, &reqs[i].provider) + Expect::build_verifreg_event("allocation", *alloc_id, client_id, reqs[i].provider) }) .collect::>(); @@ -1005,7 +1005,7 @@ pub fn datacap_extend_claim( claim: ClaimID, size: u64, new_term: ChainEpoch, - claim_client: &ActorID, + claim_client: ActorID, ) { let payload = AllocationRequests { allocations: vec![], @@ -1040,9 +1040,9 @@ pub fn datacap_extend_claim( true, // Burn vec![Expect::build_verifreg_event( "claim-updated", - &claim, + claim, claim_client, - &provider.id().unwrap(), + provider.id().unwrap(), )], ) .matches(v.take_invocations().last().unwrap()); @@ -1196,9 +1196,9 @@ pub fn market_publish_deal( ), events: vec![Expect::build_verifreg_event( "allocation", - &alloc_id, - &deal_client.id().unwrap(), - &miner_id.id().unwrap(), + alloc_id, + deal_client.id().unwrap(), + miner_id.id().unwrap(), )], ..Default::default() }]), @@ -1218,9 +1218,9 @@ pub fn market_publish_deal( subinvocs: Some(expect_publish_invocs), events: vec![Expect::build_market_event( "deal-published", - &ret.ids[0], - &deal_client.id().unwrap(), - &miner_id.id().unwrap(), + ret.ids[0], + deal_client.id().unwrap(), + miner_id.id().unwrap(), )], ..Default::default() } diff --git a/test_vm/src/messaging.rs b/test_vm/src/messaging.rs index fea11a2c1..70521f9c3 100644 --- a/test_vm/src/messaging.rs +++ b/test_vm/src/messaging.rs @@ -641,7 +641,6 @@ impl<'invocation> Runtime for InvocationCtx<'invocation> { Ok(Cid::new_v1(IPLD_RAW, Multihash::wrap(0, b"faketipset").unwrap())) } - // TODO No support for events yet. fn emit_event(&self, event: &ActorEvent) -> Result<(), ActorError> { self.events .borrow_mut()