Skip to content

Commit

Permalink
Simply deal activation return and intermediate data flow
Browse files Browse the repository at this point in the history
  • Loading branch information
anorth committed Jan 12, 2024
1 parent 6e3b5ca commit 01142b8
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 229 deletions.
32 changes: 8 additions & 24 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,7 @@ impl Actor {
validated_proposals.push(proposal);
}

let mut verified_infos = vec![];
let mut unverified_infos: Vec<UnVerifiedDealInfo> = vec![];
let mut nonverified_deal_space: BigInt = 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 @@ -611,21 +609,12 @@ impl Actor {
// Extract and remove any verified allocation ID for the pending deal.
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 {
unverified_infos.push(UnVerifiedDealInfo {
data: proposal.piece_cid,
size: proposal.piece_size,
});
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 @@ -648,12 +637,7 @@ impl Actor {

sectors_deals
.push((sector.sector_number, SectorDealIDs { deals: sector.deal_ids.clone() }));
activations.push(SectorDealActivation {
nonverified_deal_space,
verified_infos,
unverified_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(
Expand Down
21 changes: 7 additions & 14 deletions actors/market/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,11 @@ pub struct BatchActivateDealsParams {
pub compute_cid: bool,
}

// Information about a un-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 UnVerifiedDealInfo {
pub data: Cid,
pub size: PaddedPieceSize,
}

// Information about a verified 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,
}
Expand All @@ -122,12 +115,12 @@ pub struct VerifiedDealInfo {
#[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,
// #[serde(with = "bigint_ser")]
// pub nonverified_deal_space: BigInt,
/// Information about each verified deal activated.
pub verified_infos: Vec<VerifiedDealInfo>,
pub activated: Vec<ActivatedDeal>,
/// Information about each un-verified deal activated.
pub unverified_infos: Vec<UnVerifiedDealInfo>,
// pub unverified_infos: Vec<UnVerifiedDealInfo>,
/// 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
83 changes: 43 additions & 40 deletions actors/market/tests/verify_deals_for_activation_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_shared::address::Address;
use fvm_shared::bigint::BigInt;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use fvm_shared::piece::PieceInfo;
use fvm_shared::sector::RegisteredSealProof;
use num_traits::Zero;

use fil_actor_market::{
Actor as MarketActor, Method, SectorDeals, UnVerifiedDealInfo, VerifyDealsForActivationParams,
ActivatedDeal, Actor as MarketActor, Method, SectorDeals, VerifyDealsForActivationParams,
NO_ALLOCATION_ID,
};
use fil_actors_runtime::runtime::builtins::Type;
use fil_actors_runtime::test_utils::{
Expand Down Expand Up @@ -58,14 +57,15 @@ fn verify_deal_and_activate_to_get_deal_space_for_unverified_deal_proposal() {
let s_response = a_response.activations.get(0).unwrap();
assert_eq!(1, v_response.unsealed_cids.len());
assert_eq!(Some(make_piece_cid("1".as_bytes())), v_response.unsealed_cids[0]);
assert!(s_response.verified_infos.is_empty());
assert!(!s_response.unverified_infos.is_empty());
assert_eq!(BigInt::from(deal_proposal.piece_size.0), s_response.nonverified_deal_space);

let info = s_response.unverified_infos.get(0).unwrap();
assert_eq!(1, s_response.activated.len());
assert_eq!(
UnVerifiedDealInfo { data: deal_proposal.piece_cid, size: deal_proposal.piece_size },
*info
ActivatedDeal {
client: CLIENT_ADDR.id().unwrap(),
allocation_id: NO_ALLOCATION_ID,
data: deal_proposal.piece_cid,
size: deal_proposal.piece_size
},
*s_response.activated.get(0).unwrap()
);

check_state(&rt);
Expand Down Expand Up @@ -103,15 +103,11 @@ fn verify_deal_and_activate_to_get_deal_space_for_verified_deal_proposal() {

assert_eq!(1, response.unsealed_cids.len());
assert_eq!(Some(make_piece_cid("1".as_bytes())), response.unsealed_cids[0]);
assert_eq!(1, s_response.verified_infos.len());
assert!(s_response.unverified_infos.is_empty());
assert_eq!(deal_proposal.piece_size, s_response.verified_infos[0].size);
assert_eq!(deal_proposal.client.id().unwrap(), s_response.verified_infos[0].client);
assert_eq!(deal_proposal.piece_cid, s_response.verified_infos[0].data);
assert_eq!(next_allocation_id, s_response.verified_infos[0].allocation_id);

assert_eq!(BigInt::zero(), s_response.nonverified_deal_space);

assert_eq!(1, s_response.activated.len());
assert_eq!(deal_proposal.piece_size, s_response.activated[0].size);
assert_eq!(deal_proposal.client.id().unwrap(), s_response.activated[0].client);
assert_eq!(deal_proposal.piece_cid, s_response.activated[0].data);
assert_eq!(next_allocation_id, s_response.activated[0].allocation_id);
check_state(&rt);
}

Expand Down Expand Up @@ -139,7 +135,7 @@ fn verification_and_weights_for_verified_and_unverified_deals() {
assert_eq!(4, deal_ids.len());

let sector_number = 7;
let response = verify_deals_for_activation(
verify_deals_for_activation(
&rt,
PROVIDER_ADDR,
vec![SectorDeals {
Expand All @@ -158,38 +154,45 @@ fn verification_and_weights_for_verified_and_unverified_deals() {
},
);

let verified_space = BigInt::from(verified_deal_1.piece_size.0 + verified_deal_2.piece_size.0);
let unverified_space =
BigInt::from(unverified_deal_1.piece_size.0 + unverified_deal_2.piece_size.0);

let a_response =
activate_deals(&rt, SECTOR_EXPIRY, PROVIDER_ADDR, CURR_EPOCH, sector_number, &deal_ids);
let s_response = a_response.activations.get(0).unwrap();

assert_eq!(1, response.unsealed_cids.len());
let returned_verified_space: BigInt =
s_response.verified_infos.iter().map(|info| BigInt::from(info.size.0)).sum();
assert_eq!(verified_space, returned_verified_space);
assert_eq!(unverified_space, s_response.nonverified_deal_space);
assert_eq!(2, s_response.unverified_infos.len());

let resp_unverified_deal_1 = s_response.unverified_infos.get(0).unwrap();
let resp_unverified_deal_2 = s_response.unverified_infos.get(1).unwrap();

assert_eq!(4, s_response.activated.len());
assert_eq!(
&ActivatedDeal {
client: CLIENT_ADDR.id().unwrap(),
allocation_id: 1,
data: verified_deal_1.piece_cid,
size: verified_deal_1.piece_size,
},
s_response.activated.get(0).unwrap()
);
assert_eq!(
UnVerifiedDealInfo {
&ActivatedDeal {
client: CLIENT_ADDR.id().unwrap(),
allocation_id: 2,
data: verified_deal_2.piece_cid,
size: verified_deal_2.piece_size,
},
s_response.activated.get(1).unwrap()
);
assert_eq!(
&ActivatedDeal {
client: CLIENT_ADDR.id().unwrap(),
allocation_id: NO_ALLOCATION_ID,
data: unverified_deal_1.piece_cid,
size: unverified_deal_1.piece_size,
},
*resp_unverified_deal_1
s_response.activated.get(2).unwrap()
);

assert_eq!(
UnVerifiedDealInfo {
&ActivatedDeal {
client: CLIENT_ADDR.id().unwrap(),
allocation_id: NO_ALLOCATION_ID,
data: unverified_deal_2.piece_cid,
size: unverified_deal_2.piece_size,
},
*resp_unverified_deal_2
s_response.activated.get(3).unwrap()
);

check_state(&rt);
Expand Down
28 changes: 15 additions & 13 deletions actors/miner/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub mod market {
pub const BATCH_ACTIVATE_DEALS_METHOD: u64 = 6;
pub const ON_MINER_SECTORS_TERMINATE_METHOD: u64 = 7;

pub const NO_ALLOCATION_ID: u64 = 0;

#[derive(Serialize_tuple, Deserialize_tuple)]
pub struct SectorDeals {
pub sector_number: SectorNumber,
Expand All @@ -39,16 +41,16 @@ pub mod market {
}

#[derive(Serialize_tuple, Deserialize_tuple, Clone)]
pub struct VerifiedDealInfo {
pub struct ActivateDealInfo {
pub client: ActorID,
pub allocation_id: u64,
pub data: Cid,
pub size: PaddedPieceSize,
}

impl Default for VerifiedDealInfo {
fn default() -> VerifiedDealInfo {
VerifiedDealInfo {
impl Default for ActivateDealInfo {
fn default() -> ActivateDealInfo {
ActivateDealInfo {
size: PaddedPieceSize(0),
client: 0,
allocation_id: 0,
Expand All @@ -57,18 +59,18 @@ pub mod market {
}
}

#[derive(Serialize_tuple, Deserialize_tuple, Clone)]
pub struct UnVerifiedDealInfo {
pub data: Cid,
pub size: PaddedPieceSize,
}
// #[derive(Serialize_tuple, Deserialize_tuple, Clone)]
// pub struct UnVerifiedDealInfo {
// pub data: Cid,
// pub size: PaddedPieceSize,
// }

#[derive(Serialize_tuple, Deserialize_tuple, Clone)]
pub struct SectorDealActivation {
#[serde(with = "bigint_ser")]
pub nonverified_deal_space: BigInt,
pub verified_infos: Vec<VerifiedDealInfo>,
pub unverified_infos: Vec<UnVerifiedDealInfo>,
// #[serde(with = "bigint_ser")]
// pub nonverified_deal_space: BigInt,
pub activated: Vec<ActivateDealInfo>,
// pub unverified_infos: Vec<UnVerifiedDealInfo>,
pub unsealed_cid: Option<Cid>,
}

Expand Down
Loading

0 comments on commit 01142b8

Please sign in to comment.