From 8b7c77c8962f092c47b1c0027b250cf5814c5079 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Tue, 5 Mar 2024 08:41:44 +1100 Subject: [PATCH] fix(events): deal-activated event on sector_content_changed (#1526) --- actors/market/src/lib.rs | 7 ++ actors/market/tests/sector_content_changed.rs | 64 +++++++++++++++++++ .../src/tests/prove_commit2_test.rs | 7 ++ .../src/tests/replica_update2_test.rs | 8 +++ 4 files changed, 86 insertions(+) diff --git a/actors/market/src/lib.rs b/actors/market/src/lib.rs index 725107866..4aa626e2e 100644 --- a/actors/market/src/lib.rs +++ b/actors/market/src/lib.rs @@ -746,6 +746,13 @@ impl Actor { // No continue below here, to ensure state changes are consistent. activated_deals.insert(deal_id); + emit::deal_activated( + rt, + deal_id, + proposal.client.id().unwrap(), + proposal.provider.id().unwrap(), + )?; + // Remove any verified allocation ID for the pending deal. pending_deal_allocation_ids.delete(&deal_id)?; diff --git a/actors/market/tests/sector_content_changed.rs b/actors/market/tests/sector_content_changed.rs index 2366ba485..59439d38b 100644 --- a/actors/market/tests/sector_content_changed.rs +++ b/actors/market/tests/sector_content_changed.rs @@ -73,6 +73,15 @@ fn simple_one_sector() { minimum_commitment_epoch: END_EPOCH + 10, added: pieces, }]; + for deal_id in deal_ids.iter().rev() { + harness::expect_emitted( + &rt, + "deal-activated", + *deal_id, + CLIENT_ADDR.id().unwrap(), + MINER_ADDRESSES.provider.id().unwrap(), + ); + } let ret = sector_content_changed(&rt, PROVIDER_ADDR, changes).unwrap(); assert_eq!(1, ret.sectors.len()); assert_eq!(3, ret.sectors[0].added.len()); @@ -117,6 +126,15 @@ fn simple_multiple_sectors() { added: pieces[2..3].to_vec(), }, ]; + for deal_id in deal_ids.iter() { + harness::expect_emitted( + &rt, + "deal-activated", + *deal_id, + CLIENT_ADDR.id().unwrap(), + MINER_ADDRESSES.provider.id().unwrap(), + ); + } let ret = sector_content_changed(&rt, PROVIDER_ADDR, changes).unwrap(); assert_eq!(3, ret.sectors.len()); assert_eq!(vec![PieceReturn { accepted: true }], ret.sectors[0].added); @@ -142,6 +160,15 @@ fn new_deal_existing_sector() { minimum_commitment_epoch: END_EPOCH + 10, added: pieces[1..3].to_vec(), }]; + for deal_id in deal_ids[1..3].iter() { + harness::expect_emitted( + &rt, + "deal-activated", + *deal_id, + CLIENT_ADDR.id().unwrap(), + MINER_ADDRESSES.provider.id().unwrap(), + ); + } sector_content_changed(&rt, PROVIDER_ADDR, changes).unwrap(); let changes = vec![SectorChanges { @@ -149,6 +176,15 @@ fn new_deal_existing_sector() { minimum_commitment_epoch: END_EPOCH + 10, added: pieces[0..1].to_vec(), }]; + for deal_id in deal_ids[0..1].iter() { + harness::expect_emitted( + &rt, + "deal-activated", + *deal_id, + CLIENT_ADDR.id().unwrap(), + MINER_ADDRESSES.provider.id().unwrap(), + ); + } sector_content_changed(&rt, PROVIDER_ADDR, changes).unwrap(); // All deal IDs are stored under the right sector, in correct order. @@ -244,6 +280,16 @@ fn failures_isolated() { }, ]; + // only first and last pieces emit an event + for deal_id in [deal_ids.first().unwrap(), deal_ids.last().unwrap()] { + harness::expect_emitted( + &rt, + "deal-activated", + *deal_id, + CLIENT_ADDR.id().unwrap(), + MINER_ADDRESSES.provider.id().unwrap(), + ); + } let ret = sector_content_changed(&rt, PROVIDER_ADDR, changes).unwrap(); assert_eq!(3, ret.sectors.len()); // Broken second piece still allows first piece in same sector to activate. @@ -278,6 +324,15 @@ fn rejects_duplicates_in_same_sector() { added: vec![pieces[0].clone(), pieces[0].clone(), pieces[1].clone()], }, ]; + for deal_id in deal_ids.iter() { + harness::expect_emitted( + &rt, + "deal-activated", + *deal_id, + CLIENT_ADDR.id().unwrap(), + MINER_ADDRESSES.provider.id().unwrap(), + ); + } let ret = sector_content_changed(&rt, PROVIDER_ADDR, changes).unwrap(); assert_eq!(1, ret.sectors.len()); // The first piece succeeds just once, the second piece succeeds too. @@ -323,6 +378,15 @@ fn rejects_duplicates_across_sectors() { added: vec![pieces[0].clone(), pieces[1].clone(), pieces[2].clone()], }, ]; + for deal_id in deal_ids.iter() { + harness::expect_emitted( + &rt, + "deal-activated", + *deal_id, + CLIENT_ADDR.id().unwrap(), + MINER_ADDRESSES.provider.id().unwrap(), + ); + } let ret = sector_content_changed(&rt, PROVIDER_ADDR, changes).unwrap(); assert_eq!(3, ret.sectors.len()); // Succeeds in the first time. diff --git a/integration_tests/src/tests/prove_commit2_test.rs b/integration_tests/src/tests/prove_commit2_test.rs index 4a7eeeb3c..f8df6bb8a 100644 --- a/integration_tests/src/tests/prove_commit2_test.rs +++ b/integration_tests/src/tests/prove_commit2_test.rs @@ -323,6 +323,13 @@ pub fn prove_commit_sectors2_test(v: &dyn VM) { ), value: Some(TokenAmount::zero()), subinvocs: Some(vec![]), + events: deal_ids_s3 + .iter() + .chain(deal_ids_s4.iter()) + .map(|deal_id| { + Expect::build_market_event("deal-activated", *deal_id, client_id, miner_id) + }) + .collect::>(), ..Default::default() }, ]), diff --git a/integration_tests/src/tests/replica_update2_test.rs b/integration_tests/src/tests/replica_update2_test.rs index 8a08b1d0a..f89e43f13 100644 --- a/integration_tests/src/tests/replica_update2_test.rs +++ b/integration_tests/src/tests/replica_update2_test.rs @@ -387,6 +387,14 @@ pub fn prove_replica_update2_test(v: &dyn VM) { ), value: Some(TokenAmount::zero()), subinvocs: Some(vec![]), + events: deal_ids_s3 + .iter() + .chain(deal_ids_s4.iter()) + .map(|deal_id| { + Expect::build_market_event("deal-activated", *deal_id, client_id, miner_id) + }) + .collect::>(), + ..Default::default() }, ]),