Skip to content

Commit de646c5

Browse files
anorthshamb0
authored andcommitted
Implement extension of claims by spending new datacap (filecoin-project#685)
1 parent 988f197 commit de646c5

File tree

11 files changed

+598
-272
lines changed

11 files changed

+598
-272
lines changed

actors/market/src/ext.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub mod miner {
3737
pub mod verifreg {
3838
use super::*;
3939
use cid::Cid;
40+
use fil_actors_runtime::BatchReturn;
4041
use fvm_shared::clock::ChainEpoch;
4142
use fvm_shared::piece::PaddedPieceSize;
4243

@@ -54,13 +55,26 @@ pub mod verifreg {
5455
}
5556

5657
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
57-
pub struct AllocationsRequest {
58-
pub requests: Vec<AllocationRequest>,
58+
pub struct ClaimExtensionRequest {
59+
pub provider: Address,
60+
pub claim: ClaimID,
61+
pub term_max: ChainEpoch,
62+
}
63+
64+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
65+
pub struct AllocationRequests {
66+
pub allocations: Vec<AllocationRequest>,
67+
pub extensions: Vec<ClaimExtensionRequest>,
5968
}
6069

6170
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
6271
pub struct AllocationsResponse {
63-
pub allocations: Vec<AllocationID>,
72+
// Result for each allocation request.
73+
pub allocation_results: BatchReturn,
74+
// Result for each extension request.
75+
pub extension_results: BatchReturn,
76+
// IDs of new allocations created.
77+
pub new_allocations: Vec<AllocationID>,
6478
}
6579
}
6680

actors/market/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ impl Actor {
379379
.and_then(|ret| datacap_transfer_response(&ret));
380380
match alloc_ids {
381381
Ok(ids) => {
382+
// Note: when changing this to do anything other than expect complete success,
383+
// inspect the BatchReturn values to determine which deals succeeded and which failed.
382384
if ids.len() != 1 {
383385
return Err(actor_error!(
384386
unspecified,
@@ -1156,7 +1158,7 @@ fn datacap_transfer_request(
11561158
to: *VERIFIED_REGISTRY_ACTOR_ADDR,
11571159
amount: TokenAmount::from_whole(datacap_required),
11581160
operator_data: serialize(
1159-
&ext::verifreg::AllocationsRequest { requests: alloc_reqs },
1161+
&ext::verifreg::AllocationRequests { allocations: alloc_reqs, extensions: vec![] },
11601162
"allocation requests",
11611163
)?,
11621164
})
@@ -1167,7 +1169,7 @@ fn datacap_transfer_response(ret: &RawBytes) -> Result<Vec<AllocationID>, ActorE
11671169
let ret: TransferFromReturn = deserialize(ret, "transfer from response")?;
11681170
let allocs: ext::verifreg::AllocationsResponse =
11691171
deserialize(&ret.recipient_data, "allocations response")?;
1170-
Ok(allocs.allocations)
1172+
Ok(allocs.new_allocations)
11711173
}
11721174

11731175
pub fn gen_rand_next_epoch(

actors/market/tests/harness.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ use fil_actors_runtime::{
2727
network::EPOCHS_IN_DAY,
2828
runtime::{Policy, Runtime},
2929
test_utils::*,
30-
ActorError, SetMultimap, BURNT_FUNDS_ACTOR_ADDR, CRON_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ADDR,
31-
REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
32-
VERIFIED_REGISTRY_ACTOR_ADDR,
30+
ActorError, BatchReturn, SetMultimap, BURNT_FUNDS_ACTOR_ADDR, CRON_ACTOR_ADDR,
31+
DATACAP_TOKEN_ACTOR_ADDR, REWARD_ACTOR_ADDR, STORAGE_MARKET_ACTOR_ADDR,
32+
STORAGE_POWER_ACTOR_ADDR, SYSTEM_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR,
3333
};
3434
use fvm_ipld_encoding::{to_vec, RawBytes};
3535
use fvm_shared::bigint::BigInt;
@@ -491,15 +491,16 @@ pub fn publish_deals(
491491
if deal.verified_deal {
492492
// Expect transfer of data cap to the verified registry, with spec for the allocation.
493493
let curr_epoch = rt.epoch;
494-
let alloc_req = ext::verifreg::AllocationsRequest {
495-
requests: vec![AllocationRequest {
494+
let alloc_req = ext::verifreg::AllocationRequests {
495+
allocations: vec![AllocationRequest {
496496
provider: deal.provider,
497497
data: deal.piece_cid,
498498
size: deal.piece_size,
499499
term_min: deal.end_epoch - deal.start_epoch,
500500
term_max: (deal.end_epoch - deal.start_epoch) + 90 * EPOCHS_IN_DAY,
501501
expiration: min(deal.start_epoch, curr_epoch + 60 * EPOCHS_IN_DAY),
502502
}],
503+
extensions: vec![],
503504
};
504505
let datacap_amount = TokenAmount::from_whole(deal.piece_size.0 as i64);
505506
let params = TransferFromParams {
@@ -508,7 +509,11 @@ pub fn publish_deals(
508509
amount: datacap_amount.clone(),
509510
operator_data: serialize(&alloc_req, "allocation requests").unwrap(),
510511
};
511-
let alloc_ids = AllocationsResponse { allocations: vec![alloc_id] };
512+
let alloc_ids = AllocationsResponse {
513+
allocation_results: BatchReturn::ok(1),
514+
extension_results: BatchReturn::empty(),
515+
new_allocations: vec![alloc_id],
516+
};
512517
rt.expect_send(
513518
*DATACAP_TOKEN_ACTOR_ADDR,
514519
ext::datacap::TRANSFER_FROM_METHOD as u64,

actors/market/tests/market_actor_test.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use fil_actors_runtime::network::EPOCHS_IN_DAY;
1313
use fil_actors_runtime::runtime::{Policy, Runtime};
1414
use fil_actors_runtime::test_utils::*;
1515
use fil_actors_runtime::{
16-
make_empty_map, make_map_with_root_and_bitwidth, ActorError, Map, SetMultimap,
16+
make_empty_map, make_map_with_root_and_bitwidth, ActorError, BatchReturn, Map, SetMultimap,
1717
BURNT_FUNDS_ACTOR_ADDR, DATACAP_TOKEN_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
1818
VERIFIED_REGISTRY_ACTOR_ADDR,
1919
};
@@ -863,15 +863,16 @@ fn provider_and_client_addresses_are_resolved_before_persisting_state_and_sent_t
863863
);
864864

865865
// Data cap transfer is requested using the resolved address (not that it matters).
866-
let alloc_req = ext::verifreg::AllocationsRequest {
867-
requests: vec![AllocationRequest {
866+
let alloc_req = ext::verifreg::AllocationRequests {
867+
allocations: vec![AllocationRequest {
868868
provider: provider_resolved,
869869
data: deal.piece_cid,
870870
size: deal.piece_size,
871871
term_min: deal.end_epoch - deal.start_epoch,
872872
term_max: (deal.end_epoch - deal.start_epoch) + 90 * EPOCHS_IN_DAY,
873873
expiration: deal.start_epoch,
874874
}],
875+
extensions: vec![],
875876
};
876877
let datacap_amount = TokenAmount::from_whole(deal.piece_size.0 as i64);
877878
let transfer_params = TransferFromParams {
@@ -885,7 +886,11 @@ fn provider_and_client_addresses_are_resolved_before_persisting_state_and_sent_t
885886
to_balance: datacap_amount,
886887
allowance: TokenAmount::zero(),
887888
recipient_data: serialize(
888-
&AllocationsResponse { allocations: vec![1] },
889+
&AllocationsResponse {
890+
allocation_results: BatchReturn::ok(1),
891+
extension_results: BatchReturn::empty(),
892+
new_allocations: vec![1],
893+
},
889894
"allocations response",
890895
)
891896
.unwrap(),

0 commit comments

Comments
 (0)