Skip to content

Commit

Permalink
tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Jan 11, 2024
1 parent 733a98f commit 4d20e04
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 178 deletions.
1 change: 1 addition & 0 deletions actors/market/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BS>(
&mut self,
store: &BS,
Expand Down
12 changes: 6 additions & 6 deletions actors/market/tests/cron_tick_deal_slashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion actors/market/tests/deal_api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 3 additions & 13 deletions actors/market/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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::<MarketActor>(
Method::BatchActivateDeals as u64,
IpldBlock::serialize_cbor(&params).unwrap(),
Expand Down Expand Up @@ -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],
Expand All @@ -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::<Vec<_>>();

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,
Expand Down
6 changes: 3 additions & 3 deletions actors/market/tests/market_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions actors/market/tests/on_miner_sectors_terminate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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::<DealID>::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::<DealID>::new(), get_sector_deal_ids(&rt, &provider2, sector_number));
check_state(&rt);
Expand All @@ -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);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
11 changes: 2 additions & 9 deletions actors/market/tests/random_cron_epoch_during_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
25 changes: 10 additions & 15 deletions actors/miner/src/emit.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Cid>,
pieces: &[(Cid, u64)],
) -> Result<(), ActorError> {
rt.emit_event(
&EventBuilder::new()
Expand All @@ -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<Cid>,
pieces: &[(Cid, u64)],
) -> Result<(), ActorError> {
rt.emit_event(
&EventBuilder::new()
Expand All @@ -54,25 +51,23 @@ trait WithSectorInfo {
fn with_sector_info(
self,
sector: SectorNumber,
unsealed_cid: &Cid,
pieces: &[(Cid, PaddedPieceSize)],
unsealed_cid: Option<Cid>,
pieces: &[(Cid, u64)],
) -> EventBuilder;
}

impl WithSectorInfo for EventBuilder {
fn with_sector_info(
self,
sector: SectorNumber,
unsealed_cid: &Cid,
pieces: &[(Cid, PaddedPieceSize)],
unsealed_cid: Option<Cid>,
pieces: &[(Cid, u64)],
) -> EventBuilder {
let mut event =
self.field_indexed("sector", &sector).field_indexed("unsealed-cid", unsealed_cid);
self.field_indexed("sector", &sector).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
}
Expand Down
1 change: 0 additions & 1 deletion actors/miner/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 4d20e04

Please sign in to comment.