Skip to content

Commit

Permalink
fix(events): deal-activated event on sector_content_changed (#1526)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg authored Mar 4, 2024
1 parent 8324a49 commit a663727
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
7 changes: 7 additions & 0 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,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)?;

Expand Down
64 changes: 64 additions & 0 deletions actors/market/tests/sector_content_changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -142,13 +160,31 @@ 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 {
sector: 1,
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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions integration_tests/src/tests/prove_commit3_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>(),
..Default::default()
},
]),
Expand Down
8 changes: 8 additions & 0 deletions integration_tests/src/tests/replica_update3_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>(),

..Default::default()
},
]),
Expand Down

0 comments on commit a663727

Please sign in to comment.