Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit f0a0631
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Wed Jan 31 11:57:31 2024 +0400

    emit event during settling payments

commit a35b1cc
Merge: 1722310 859c731
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Tue Jan 30 09:47:20 2024 +0400

    Merge remote-tracking branch 'origin/master' into feat/ddo-actor-events

commit 1722310
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Mon Jan 29 14:04:27 2024 +0400

    Apply suggestions from code review

    Co-authored-by: Rod Vagg <rod@vagg.org>

commit b149550
Merge: 803f420 d0b8d9c
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Mon Jan 29 14:00:12 2024 +0400

    Merge remote-tracking branch 'origin/integration/manual-settlement' into feat/ddo-actor-events

commit d0b8d9c
Author: Alex Su <alexanderytsu@gmail.com>
Date:   Mon Oct 16 09:09:28 2023 +1100

    Use ExitCode::USR_NOT_FOUND for missing state in GetDealActivation (#1441)

    * hide deals that are asynchronously termianted in get_deal_activation

    * add test for EX_DEAL_EXPIRED behaviour

commit c6227a2
Author: Alex Su <alexanderytsu@gmail.com>
Date:   Mon Oct 9 13:00:46 2023 +1100

    Additional tests for synchronous termination and SettleDealPayments (#1423)

    * rename some tests and comments to no longer reference slashed_epoch which will never be observable

    * port cron tick tests for deal termination

    * move deal termination tests

    * modify generate and publish deal to return proposal inline

    * fix bug when settling payments between between publish and activation

    * deal termination edge cases

    * pr review

commit 21baa60
Author: Alex Su <alexanderytsu@gmail.com>
Date:   Fri Sep 8 12:29:14 2023 +1000

    Explicit deal settlement in built-in market (#1377)

commit 803f420
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Tue Jan 23 18:21:17 2024 +0400

    changes

commit 78ec9f6
Merge: c90fafe e671d69
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Tue Jan 23 18:21:02 2024 +0400

    Merge remote-tracking branch 'origin/integration/direct-onboarding' into feat/ddo-actor-events

commit e671d69
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Jan 23 14:07:21 2024 +1300

    More review response for #1486. (#1508)

commit db65674
Author: Steven Allen <steven@stebalien.com>
Date:   Wed Jan 17 10:56:30 2024 -0800

    Cleanup batch return merge logic (#1503)

    This just avoids some awkward unwraps.

commit 84b0c00
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Wed Jan 17 09:05:16 2024 +1300

    Response to review on #1486 (#1499)

    Response to review on #1486

commit 049b9c7
Author: Steven Allen <steven@stebalien.com>
Date:   Mon Jan 15 12:48:17 2024 -0800

    chore: remove unnecessary clone of piece payload (#1494)

commit 9334a87
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Jan 9 07:04:12 2024 +1300

    Add aggregate proof type parameter to ProveCommitSectors3 (#1489)

commit 4126ccb
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Fri Dec 22 07:17:28 2023 +1100

    Add missing vm_test annotations. (#1488)

commit 3ad21ac
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Dec 19 11:49:23 2023 +1100

    Rename PCS2/PRU2 to PCS3/PRU3 (#1485)

commit 53cb47e
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Dec 19 11:08:21 2023 +1100

    Transparent serialization for ProveReplicaUpdates2Return (#1484)

commit 5cdfc2f
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Oct 31 13:49:37 2023 +1100

    Integration test for prove_replica_updates2 (#1453)

commit 0f8c593
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Oct 31 12:52:33 2023 +1100

    Integration test for prove_commit_sectors2 (#1450)

commit 5cecdf6
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Oct 31 11:52:06 2023 +1100

    Add GetDealSector exported API method to market actor (#1443)

commit 21c01a9
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Oct 17 05:20:35 2023 +1100

    More tests for direct data onboarding (#1440)

    Tests that CommD computed from pieces must match that declared at precommit. Tests that updating an empty replica to be empty is permitted (later, when we allow updates to non-empty replicas, it won't be a no-op).

commit 47e1cf1
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Mon Oct 16 07:18:28 2023 +1100

    Tests for prove_commit_sectors2 (#1437)

commit a108360
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Thu Sep 28 03:11:22 2023 +1000

    Tests for ProveCommitSectors2 for cases that abort entirely (#1414)

commit ff66f79
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Sat Sep 23 05:05:35 2023 +1000

    Check state invariants in direct onboarding tests (#1416)

commit 3354d8a
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Sat Sep 16 04:23:58 2023 +1000

    Tests and fixes for ProveReplicaUpdates2 (#1411)

    * Tests and fixes for ProveReplicaUpdates2

    * Helper function

commit 869af32
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Mon Sep 11 10:17:48 2023 +1000

    Move prove_commit2 tests to separate file from pru tests (#1410)

commit 24b5cd6
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Fri Sep 8 10:19:52 2023 +1000

    PRU2 tests that abort the whole method (#1407)

commit ff472f2
Author: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
Date:   Thu Sep 7 19:04:58 2023 -0400

    Prove commit 2 simple tests (#1408)

commit a861f02
Author: Shrenuj Bansal <108157875+shrenujbansal@users.noreply.github.com>
Date:   Wed Sep 6 21:47:36 2023 -0400

    Return error if success count for proof validation or data activations is 0 (#1406)

commit 0457d86
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Wed Sep 6 08:26:36 2023 +1000

    Remove allocation id from market deal state. Clean up and improve state checks. (#1403)

commit e0083f4
Author: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
Date:   Mon Sep 4 20:48:54 2023 -0400

    Deprecate Deal IDs (#1402)

    Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>

commit d78586f
Author: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
Date:   Mon Sep 4 14:44:41 2023 -0400

    Deprecate unused Prove Replica update 2 (#1401)

    * Simplify input to activate_sectors_deals
    * Remove old PRU2 and parameter types
    * Reuse PRU2 name for DDO PRU fka PRU 3

    ---------

    Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>

commit c1aa98f
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Mon Sep 4 11:09:24 2023 +1000

    Basic unit tests for ProveReplicaUpdate3 (#1394)

commit 5de9cae
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Fri Sep 1 08:24:52 2023 +1000

    Compute batch returns for direct onboarding methods (#1393)

commit 06f282a
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Thu Aug 31 05:10:48 2023 +1000

    Send SectorContentChanged from new onboarding methods (#1386)

    Send SectorContentChanged from new onboarding methods. Simplify return values to make notifications fire and forget.

commit 6a2a089
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Thu Aug 31 03:43:37 2023 +1000

    Miner notifies market of termination only of sectors with non-zero data (#1387)

    Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>

commit ba9b579
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Wed Aug 30 20:07:45 2023 +1000

    Implement new ProveReplicaUpdates3 for direct data onboarding. (#1385)

commit 9c681c7
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Aug 29 08:38:39 2023 +1000

    Implements new ProveCommit batch+aggregate for direct onboarding (#1380)

    Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>

commit c5fd304
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Aug 15 13:35:08 2023 +1000

    Implements SectorContentChanged method in built-in market actor (#1353)

commit e55498d
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Wed Aug 9 08:40:52 2023 +1000

    Remove deprecated precommit methods (#1357)

    - PreCommitSector and PreCommitBatch deprecated
    - PreCommitBatchV2 now requires specifying (compact) CommD
    - Move all testing to use PreCommitBatchV2

    Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
    Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>

commit 181305e
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Fri Aug 4 04:33:49 2023 +1000

    Implement sector->deal mapping in built-in market actor (#1347)

commit c90fafe
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Thu Jan 18 20:06:10 2024 +0400

    changes as per steb's review

commit 7e0abca
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Fri Jan 12 11:24:13 2024 +1300

    Simply deal activation return and intermediate data flow

commit 6e3b5ca
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Thu Jan 11 21:41:05 2024 +0400

    finish review

commit 4d20e04
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Thu Jan 11 18:28:23 2024 +0400

    tests pass

commit 733a98f
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Wed Jan 10 17:51:41 2024 +0400

    fix itests

commit aef0fdd
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Wed Jan 10 17:21:41 2024 +0400

    batch activate deals should return piece info

commit 4a1ecdf
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Tue Jan 9 19:59:35 2024 +0400

    rustfmt

commit f92222d
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Tue Jan 9 19:53:59 2024 +0400

    itests green

commit 6f8be0d
Merge: 693338f aa0a168
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Tue Jan 9 17:28:53 2024 +0400

    Merge remote-tracking branch 'origin/integration/direct-onboarding' into feat/ddo-actor-events

commit 693338f
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Tue Jan 9 17:25:36 2024 +0400

    itests almost there

commit aa0a168
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Jan 9 07:04:12 2024 +1300

    Add aggregate proof type parameter to ProveCommitSectors3 (#1489)

commit 9e19d32
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Mon Jan 8 19:32:09 2024 +0400

    itests partially complete

commit 0485317
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Mon Jan 8 17:09:44 2024 +0400

    itests work 1

commit 2ce92e6
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Mon Jan 8 14:29:03 2024 +0400

    miner actor events

commit 9a22c67
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Wed Jan 3 12:48:36 2024 +0400

    miner actor events

commit 6e5d70c
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Tue Jan 2 13:15:42 2024 +0400

    market actor events

commit f522274
Author: Aarsh Shah <aarshkshah1992@gmail.com>
Date:   Tue Jan 2 10:02:11 2024 +0400

    verifreg events and itest harness

commit 1d85ec5
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Fri Dec 22 07:17:28 2023 +1100

    Add missing vm_test annotations. (#1488)

commit 0d103fe
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Dec 19 11:49:23 2023 +1100

    Rename PCS2/PRU2 to PCS3/PRU3 (#1485)

commit e01a799
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Dec 19 11:08:21 2023 +1100

    Transparent serialization for ProveReplicaUpdates2Return (#1484)

commit 13931e0
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Oct 31 13:49:37 2023 +1100

    Integration test for prove_replica_updates2 (#1453)

commit 39b488b
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Oct 31 12:52:33 2023 +1100

    Integration test for prove_commit_sectors2 (#1450)

commit 04f3843
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Oct 31 11:52:06 2023 +1100

    Add GetDealSector exported API method to market actor (#1443)

commit e48433c
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Oct 17 05:20:35 2023 +1100

    More tests for direct data onboarding (#1440)

    Tests that CommD computed from pieces must match that declared at precommit. Tests that updating an empty replica to be empty is permitted (later, when we allow updates to non-empty replicas, it won't be a no-op).

commit 7dfdfc2
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Mon Oct 16 07:18:28 2023 +1100

    Tests for prove_commit_sectors2 (#1437)

commit df2711e
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Thu Sep 28 03:11:22 2023 +1000

    Tests for ProveCommitSectors2 for cases that abort entirely (#1414)

commit 3f3a6c4
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Sat Sep 23 05:05:35 2023 +1000

    Check state invariants in direct onboarding tests (#1416)

commit c9fdbaa
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Sat Sep 16 04:23:58 2023 +1000

    Tests and fixes for ProveReplicaUpdates2 (#1411)

    * Tests and fixes for ProveReplicaUpdates2

    * Helper function

commit 6ef0eb2
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Mon Sep 11 10:17:48 2023 +1000

    Move prove_commit2 tests to separate file from pru tests (#1410)

commit 5f28bc2
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Fri Sep 8 10:19:52 2023 +1000

    PRU2 tests that abort the whole method (#1407)

commit 415bc7a
Author: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
Date:   Thu Sep 7 19:04:58 2023 -0400

    Prove commit 2 simple tests (#1408)

commit d3e7256
Author: Shrenuj Bansal <108157875+shrenujbansal@users.noreply.github.com>
Date:   Wed Sep 6 21:47:36 2023 -0400

    Return error if success count for proof validation or data activations is 0 (#1406)

commit aaca941
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Wed Sep 6 08:26:36 2023 +1000

    Remove allocation id from market deal state. Clean up and improve state checks. (#1403)

commit 2724624
Author: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
Date:   Mon Sep 4 20:48:54 2023 -0400

    Deprecate Deal IDs (#1402)

    Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>

commit fbbdaf8
Author: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
Date:   Mon Sep 4 14:44:41 2023 -0400

    Deprecate unused Prove Replica update 2 (#1401)

    * Simplify input to activate_sectors_deals
    * Remove old PRU2 and parameter types
    * Reuse PRU2 name for DDO PRU fka PRU 3

    ---------

    Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>

commit 4b9042b
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Mon Sep 4 11:09:24 2023 +1000

    Basic unit tests for ProveReplicaUpdate3 (#1394)

commit 3a293df
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Fri Sep 1 08:24:52 2023 +1000

    Compute batch returns for direct onboarding methods (#1393)

commit 351a15a
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Thu Aug 31 05:10:48 2023 +1000

    Send SectorContentChanged from new onboarding methods (#1386)

    Send SectorContentChanged from new onboarding methods. Simplify return values to make notifications fire and forget.

commit 35efa32
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Thu Aug 31 03:43:37 2023 +1000

    Miner notifies market of termination only of sectors with non-zero data (#1387)

    Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>

commit 8dd2c12
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Wed Aug 30 20:07:45 2023 +1000

    Implement new ProveReplicaUpdates3 for direct data onboarding. (#1385)

commit 079ebbc
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Aug 29 08:38:39 2023 +1000

    Implements new ProveCommit batch+aggregate for direct onboarding (#1380)

    Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>

commit 047c3ec
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Tue Aug 15 13:35:08 2023 +1000

    Implements SectorContentChanged method in built-in market actor (#1353)

commit 3e14b94
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Wed Aug 9 08:40:52 2023 +1000

    Remove deprecated precommit methods (#1357)

    - PreCommitSector and PreCommitBatch deprecated
    - PreCommitBatchV2 now requires specifying (compact) CommD
    - Move all testing to use PreCommitBatchV2

    Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
    Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com>

commit dd3b68e
Author: Alex North <445306+anorth@users.noreply.github.com>
Date:   Fri Aug 4 04:33:49 2023 +1000

    Implement sector->deal mapping in built-in market actor (#1347)
  • Loading branch information
aarshkshah1992 committed Jan 31, 2024
1 parent 859c731 commit 05f44ee
Show file tree
Hide file tree
Showing 49 changed files with 1,966 additions and 447 deletions.
76 changes: 76 additions & 0 deletions actors/market/src/emit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use fil_actors_runtime::runtime::Runtime;
use fil_actors_runtime::{ActorError, EventBuilder};
use fvm_shared::deal::DealID;
use fvm_shared::ActorID;

/// Indicates a deal has been published.
pub fn deal_published(
rt: &impl Runtime,
client: ActorID,
provider: ActorID,
deal_id: DealID,
) -> Result<(), ActorError> {
rt.emit_event(
&EventBuilder::new()
.typ("deal-published")
.with_parties(deal_id, client, provider)
.build()?,
)
}

/// Indicates a deal has been activated.
pub fn deal_activated(
rt: &impl Runtime,
deal_id: DealID,
client: ActorID,
provider: ActorID,
) -> Result<(), ActorError> {
rt.emit_event(
&EventBuilder::new()
.typ("deal-activated")
.with_parties(deal_id, client, provider)
.build()?,
)
}

/// Indicates a deal has been terminated.
pub fn deal_terminated(
rt: &impl Runtime,
deal_id: DealID,
client: ActorID,
provider: ActorID,
) -> Result<(), ActorError> {
rt.emit_event(
&EventBuilder::new()
.typ("deal-terminated")
.with_parties(deal_id, client, provider)
.build()?,
)
}

/// Indicates a deal has been completed successfully.
pub fn deal_completed(
rt: &impl Runtime,
deal_id: DealID,
client: ActorID,
provider: ActorID,
) -> Result<(), ActorError> {
rt.emit_event(
&EventBuilder::new()
.typ("deal-completed")
.with_parties(deal_id, client, provider)
.build()?,
)
}

trait WithParties {
fn with_parties(self, id: DealID, client: ActorID, provider: ActorID) -> EventBuilder;
}

impl WithParties for EventBuilder {
fn with_parties(self, id: DealID, client: ActorID, provider: ActorID) -> EventBuilder {
self.field_indexed("id", &id)
.field_indexed("client", &client)
.field_indexed("provider", &provider)
}
}
109 changes: 81 additions & 28 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub mod policy;
pub mod testing;

mod deal;
mod emit;
mod state;
mod types;

Expand Down Expand Up @@ -470,19 +471,26 @@ impl Actor {
// notify clients, any failures cause the entire publish_storage_deals method to fail
// it's unsafe to ignore errors here, since that could be used to attack storage contract clients
// that might be unaware they're making storage deals
for (i, valid_deal) in valid_deals.iter().enumerate() {
for (valid_deal, &deal_id) in valid_deals.iter().zip(&new_deal_ids) {
_ = extract_send_result(rt.send_simple(
&valid_deal.proposal.client,
MARKET_NOTIFY_DEAL_METHOD,
IpldBlock::serialize_cbor(&MarketNotifyDealParams {
proposal: valid_deal.serialized_proposal.to_vec(),
deal_id: new_deal_ids[i],
deal_id,
})?,
TokenAmount::zero(),
))
.with_context_code(ExitCode::USR_ILLEGAL_ARGUMENT, || {
format!("failed to notify deal with proposal cid {}", valid_deal.cid)
})?;

emit::deal_published(
rt,
valid_deal.proposal.client.id().unwrap(),
valid_deal.proposal.provider.id().unwrap(),
deal_id,
)?;
}

Ok(PublishStorageDealsReturn { ids: new_deal_ids, valid_deals: valid_input_bf })
Expand Down Expand Up @@ -555,7 +563,7 @@ impl Actor {
let mut deal_states: Vec<(DealID, DealState)> = vec![];
let mut batch_gen = BatchReturnGen::new(params.sectors.len());
let mut activations: Vec<SectorDealActivation> = vec![];
let mut activated_deals = BTreeSet::<DealID>::new();
let mut activated_deals: HashSet<DealID> = HashSet::new();
let mut sectors_deals: Vec<(SectorNumber, SectorDealIDs)> = vec![];

'sector: for sector in params.sectors {
Expand Down Expand Up @@ -598,8 +606,7 @@ impl Actor {
validated_proposals.push(proposal);
}

let mut verified_infos = vec![];
let mut nonverified_deal_space = BigInt::zero();
let mut activated = vec![];
// Given that all deals validated, prepare the state updates for them all.
// There's no continue below here to ensure updates are consistent.
// Any error must abort.
Expand All @@ -609,16 +616,12 @@ impl Actor {
let alloc_id =
pending_deal_allocation_ids.delete(deal_id)?.unwrap_or(NO_ALLOCATION_ID);

if alloc_id != NO_ALLOCATION_ID {
verified_infos.push(VerifiedDealInfo {
client: proposal.client.id().unwrap(),
allocation_id: alloc_id,
data: proposal.piece_cid,
size: proposal.piece_size,
})
} else {
nonverified_deal_space += proposal.piece_size.0;
}
activated.push(ActivatedDeal {
client: proposal.client.id().unwrap(),
allocation_id: alloc_id,
data: proposal.piece_cid,
size: proposal.piece_size,
});

// Prepare initial deal state.
deal_states.push((
Expand All @@ -640,11 +643,17 @@ impl Actor {

sectors_deals
.push((sector.sector_number, SectorDealIDs { deals: sector.deal_ids.clone() }));
activations.push(SectorDealActivation {
nonverified_deal_space,
verified_infos,
unsealed_cid: data_commitment,
});
activations.push(SectorDealActivation { activated, unsealed_cid: data_commitment });

for (deal_id, proposal) in sector.deal_ids.iter().zip(&validated_proposals) {
emit::deal_activated(
rt,
*deal_id,
proposal.client.id().unwrap(),
proposal.provider.id().unwrap(),
)?;
}

batch_gen.add_success();
}

Expand Down Expand Up @@ -843,6 +852,13 @@ impl Actor {
.entry(state.sector_number)
.or_default()
.push(id);

emit::deal_terminated(
rt,
id,
deal.client.id().unwrap(),
deal.provider.id().unwrap(),
)?;
}

st.remove_sector_deal_ids(rt.store(), &provider_deals_to_remove)?;
Expand Down Expand Up @@ -926,13 +942,14 @@ impl Actor {
// https://github.com/filecoin-project/builtin-actors/issues/1389
// handling of legacy deals is still done in cron. we handle such deals here and continue to
// reschedule them. eventually, all legacy deals will expire and the below code can be removed.
let (slash_amount, _payment_amount, remove_deal) = st.process_deal_update(
rt.store(),
&state,
&deal_proposal,
&dcid,
curr_epoch,
)?;
let (slash_amount, _payment_amount, completed, remove_deal) = st
.process_deal_update(
rt.store(),
&state,
&deal_proposal,
&dcid,
curr_epoch,
)?;

if remove_deal {
// TODO: remove handling for terminated-deal slashing when marked-for-termination deals are all processed
Expand All @@ -949,6 +966,15 @@ impl Actor {
.entry(state.sector_number)
.or_default()
.push(deal_id);

if !completed {
emit::deal_terminated(
rt,
deal_id,
deal_proposal.client.id().unwrap(),
deal_proposal.provider.id().unwrap(),
)?;
}
} else {
if !slash_amount.is_zero() {
return Err(actor_error!(
Expand All @@ -972,6 +998,15 @@ impl Actor {
);
new_updates_scheduled.entry(next_epoch).or_default().push(deal_id);
}

if completed {
emit::deal_completed(
rt,
deal_id,
deal_proposal.client.id().unwrap(),
deal_proposal.provider.id().unwrap(),
)?;
}
}
epochs_completed.push(i);
}
Expand Down Expand Up @@ -1247,7 +1282,7 @@ impl Actor {
));
}

let (_, payment_amount, remove_deal) = match st.process_deal_update(
let (_, payment_amount, completed, remove_deal) = match st.process_deal_update(
rt.store(),
&deal_state,
&deal_proposal,
Expand All @@ -1269,6 +1304,15 @@ impl Actor {
.entry(deal_state.sector_number)
.or_default()
.push(deal_id);

if !completed {
emit::deal_terminated(
rt,
deal_id,
deal_proposal.client.id().unwrap(),
deal_proposal.provider.id().unwrap(),
)?;
}
} else {
deal_state.last_updated_epoch = curr_epoch;
new_deal_states.push((deal_id, deal_state));
Expand All @@ -1279,6 +1323,15 @@ impl Actor {
payment: payment_amount,
});
batch_gen.add_success();

if completed {
emit::deal_completed(
rt,
deal_id,
deal_proposal.client.id().unwrap(),
deal_proposal.provider.id().unwrap(),
)?;
}
}

st.put_deal_states(rt.store(), &new_deal_states)?;
Expand Down
9 changes: 5 additions & 4 deletions actors/market/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ impl State {
(
/* slash_amount */ TokenAmount,
/* payment_amount */ TokenAmount,
/* is_deal_completed */ bool,
/* remove */ bool,
),
ActorError,
Expand Down Expand Up @@ -859,7 +860,7 @@ impl State {

// this is a safe no-op but can happen if a storage provider calls settle_deal_payments too early
if deal.start_epoch > epoch {
return Ok((TokenAmount::zero(), TokenAmount::zero(), false));
return Ok((TokenAmount::zero(), TokenAmount::zero(), false, false));
}

let payment_end_epoch = if ever_slashed {
Expand Down Expand Up @@ -921,15 +922,15 @@ impl State {
self.slash_balance(store, &deal.provider, &slashed, Reason::ProviderCollateral)
.context("slashing balance")?;

return Ok((slashed, payment_remaining + elapsed_payment, true));
return Ok((slashed, payment_remaining + elapsed_payment, false, true));
}

if epoch >= deal.end_epoch {
self.process_deal_expired(store, deal, state)?;
return Ok((TokenAmount::zero(), elapsed_payment, true));
return Ok((TokenAmount::zero(), elapsed_payment, true, true));
}

Ok((TokenAmount::zero(), elapsed_payment, false))
Ok((TokenAmount::zero(), elapsed_payment, false, false))
}

pub fn process_slashed_deal<BS>(
Expand Down
13 changes: 5 additions & 8 deletions actors/market/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,20 @@ pub struct BatchActivateDealsParams {
pub compute_cid: bool,
}

// Information about a verified deal that has been activated.
// Information about a deal that has been activated.
#[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq)]
pub struct VerifiedDealInfo {
pub struct ActivatedDeal {
pub client: ActorID,
pub allocation_id: AllocationID,
pub allocation_id: AllocationID, // NO_ALLOCATION_ID for unverified deals.
pub data: Cid,
pub size: PaddedPieceSize,
}

// Information about a sector-grouping of deals that have been activated.
#[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq)]
pub struct SectorDealActivation {
/// The total size of the non-verified deals activated.
#[serde(with = "bigint_ser")]
pub nonverified_deal_space: BigInt,
/// Information about each verified deal activated.
pub verified_infos: Vec<VerifiedDealInfo>,
/// Information about each deal activated.
pub activated: Vec<ActivatedDeal>,
/// Unsealed CID computed from the deals specified for the sector.
/// A None indicates no deals were specified, or the computation was not requested.
pub unsealed_cid: Option<Cid>,
Expand Down
1 change: 1 addition & 0 deletions actors/market/tests/activate_deal_failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ fn assert_activation_failure(
deal_ids: vec![deal_id],
}],
false,
&[],
)
.unwrap();
let res: BatchActivateDealsResult =
Expand Down
9 changes: 5 additions & 4 deletions actors/market/tests/batch_activate_deals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn sectors_fail_and_succeed_independently_during_batch_activation() {
},
];

let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false).unwrap();
let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false, &[id_4]).unwrap();
let res: BatchActivateDealsResult =
res.unwrap().deserialize().expect("VerifyDealsForActivation failed!");

Expand Down Expand Up @@ -227,7 +227,7 @@ fn handles_sectors_empty_of_deals_gracefully() {
SectorDeals { sector_number: 3, deal_ids: vec![], sector_type, sector_expiry: END_EPOCH },
];

let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false).unwrap();
let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false, &[id_1]).unwrap();
let res: BatchActivateDealsResult =
res.unwrap().deserialize().expect("VerifyDealsForActivation failed!");

Expand Down Expand Up @@ -273,7 +273,7 @@ fn fails_to_activate_single_sector_duplicate_deals() {
sector_expiry: END_EPOCH,
},
];
let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false).unwrap();
let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false, &[]).unwrap();
let res: BatchActivateDealsResult =
res.unwrap().deserialize().expect("VerifyDealsForActivation failed!");

Expand Down Expand Up @@ -328,7 +328,8 @@ fn fails_to_activate_cross_sector_duplicate_deals() {
},
];

let res = batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false).unwrap();
let res =
batch_activate_deals_raw(&rt, PROVIDER_ADDR, sectors_deals, false, &[id_1, id_3]).unwrap();
let res: BatchActivateDealsResult =
res.unwrap().deserialize().expect("VerifyDealsForActivation failed!");

Expand Down
Loading

0 comments on commit 05f44ee

Please sign in to comment.