Skip to content

Commit

Permalink
Convert SectorDealIDs to an alias for Vec<DealID>, removing struct (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg authored Feb 2, 2024
1 parent a96db01 commit 0f381a6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
9 changes: 4 additions & 5 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ impl Actor {
let mut batch_gen = BatchReturnGen::new(params.sectors.len());
let mut activations: Vec<SectorDealActivation> = vec![];
let mut activated_deals: HashSet<DealID> = HashSet::new();
let mut sectors_deals: Vec<(SectorNumber, SectorDealIDs)> = vec![];
let mut sectors_deals: Vec<(SectorNumber, Vec<DealID>)> = vec![];

'sector: for sector in params.sectors {
let mut sector_deal_ids = sector.deal_ids.clone();
Expand Down Expand Up @@ -641,8 +641,7 @@ impl Actor {
None
};

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

for (deal_id, proposal) in sector.deal_ids.iter().zip(&validated_proposals) {
Expand Down Expand Up @@ -686,7 +685,7 @@ impl Actor {

let mut deal_states: Vec<(DealID, DealState)> = vec![];
let mut activated_deals: HashSet<DealID> = HashSet::new();
let mut sectors_deals: Vec<(SectorNumber, SectorDealIDs)> = vec![];
let mut sectors_deals: Vec<(SectorNumber, Vec<DealID>)> = vec![];
let mut sectors_ret: Vec<ext::miner::SectorReturn> = vec![];

for sector in &params.sectors {
Expand Down Expand Up @@ -762,7 +761,7 @@ impl Actor {
ret.accepted = true;
}

sectors_deals.push((sector.sector, SectorDealIDs { deals: sector_deal_ids }));
sectors_deals.push((sector.sector, sector_deal_ids));
assert_eq!(pieces_ret.len(), sector.added.len(), "mismatched piece returns");
sectors_ret.push(ext::miner::SectorReturn { added: pieces_ret });
}
Expand Down
26 changes: 9 additions & 17 deletions actors/market/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,10 @@ pub struct State {
/// or has data replaced.
/// Grouping by provider limits the cost of operations in the expected use case
/// of multiple sectors all belonging to the same provider.
/// HAMT[ActorID]HAMT[SectorNumber]SectorDealIDs
/// HAMT[ActorID]HAMT[SectorNumber][]DealID
pub provider_sectors: Cid,
}

/// IDs of deals associated with a single sector.
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct SectorDealIDs {
pub deals: Vec<DealID>,
}

pub type PendingDealAllocationsMap<BS> = Map2<BS, DealID, AllocationID>;
pub const PENDING_ALLOCATIONS_CONFIG: Config =
Config { bit_width: HAMT_BIT_WIDTH, ..DEFAULT_HAMT_CONFIG };
Expand All @@ -102,7 +95,7 @@ pub type ProviderSectorsMap<BS> = Map2<BS, ActorID, Cid>;
pub const PROVIDER_SECTORS_CONFIG: Config =
Config { bit_width: HAMT_BIT_WIDTH, ..DEFAULT_HAMT_CONFIG };

pub type SectorDealsMap<BS> = Map2<BS, SectorNumber, SectorDealIDs>;
pub type SectorDealsMap<BS> = Map2<BS, SectorNumber, Vec<DealID>>;
pub const SECTOR_DEALS_CONFIG: Config = Config { bit_width: HAMT_BIT_WIDTH, ..DEFAULT_HAMT_CONFIG };

impl State {
Expand Down Expand Up @@ -599,7 +592,7 @@ impl State {
&mut self,
store: &impl Blockstore,
provider: ActorID,
sector_deal_ids: &[(SectorNumber, SectorDealIDs)],
sector_deal_ids: &[(SectorNumber, Vec<DealID>)],
) -> Result<(), ActorError> {
let mut provider_sectors = self.load_provider_sectors(store)?;
let mut sector_deals = load_provider_sector_deals(store, &provider_sectors, provider)?;
Expand All @@ -610,10 +603,10 @@ impl State {
.get(sector_number)
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to read sector deals")?;
if let Some(existing_deal_ids) = existing_deal_ids {
new_deals.deals.extend(existing_deal_ids.deals.iter());
new_deals.extend(existing_deal_ids.iter());
}
new_deals.deals.sort();
new_deals.deals.dedup();
new_deals.sort();
new_deals.dedup();
sector_deals
.set(sector_number, new_deals)
.with_context_code(ExitCode::USR_ILLEGAL_STATE, || {
Expand All @@ -639,11 +632,11 @@ impl State {
let mut popped_sector_deals = Vec::new();
let mut flush = false;
for sector_number in sector_numbers {
let deals: Option<SectorDealIDs> = sector_deals
let deals: Option<Vec<DealID>> = sector_deals
.delete(&sector_number)
.with_context(|| format!("provider {}", provider))?;
if let Some(deals) = deals {
popped_sector_deals.extend(deals.deals.iter());
popped_sector_deals.extend(deals.iter());
flush = true;
}
}
Expand Down Expand Up @@ -687,14 +680,13 @@ impl State {
// Loading into a HashSet could be an improvement for large collections of deals
// in a single sector being removed at one time.
let new_deals = existing_deal_ids
.deals
.iter()
.filter(|deal_id| !deals_to_remove.contains(*deal_id))
.cloned()
.collect();

sector_deals
.set(sector_number, SectorDealIDs { deals: new_deals })
.set(sector_number, new_deals)
.with_context_code(ExitCode::USR_ILLEGAL_STATE, || {
format!("failed to set sector deals for {} {}", provider, sector_number)
})?;
Expand Down
10 changes: 5 additions & 5 deletions actors/market/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ use fil_actor_market::ext::miner::{
use fil_actor_market::ext::verifreg::{AllocationID, AllocationRequest, AllocationsResponse};
use fil_actor_market::{
deal_cid, deal_get_payment_remaining, BatchActivateDealsParams, BatchActivateDealsResult,
PendingDealAllocationsMap, ProviderSectorsMap, SectorDealIDs, SectorDealsMap,
SettleDealPaymentsParams, SettleDealPaymentsReturn, PENDING_ALLOCATIONS_CONFIG,
PROVIDER_SECTORS_CONFIG, SECTOR_DEALS_CONFIG,
PendingDealAllocationsMap, ProviderSectorsMap, SectorDealsMap, SettleDealPaymentsParams,
SettleDealPaymentsReturn, PENDING_ALLOCATIONS_CONFIG, PROVIDER_SECTORS_CONFIG,
SECTOR_DEALS_CONFIG,
};
use fil_actor_market::{
ext, ext::miner::GetControlAddressesReturnParams, next_update_epoch,
Expand Down Expand Up @@ -567,9 +567,9 @@ pub fn get_sector_deal_ids(
sector_numbers
.iter()
.flat_map(|sector_number| {
let deals: Option<&SectorDealIDs> = sector_deals.get(sector_number).unwrap();
let deals: Option<&Vec<DealID>> = sector_deals.get(sector_number).unwrap();
match deals {
Some(deals) => deals.deals.clone(),
Some(deals) => deals.clone(),
None => vec![],
}
})
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub fn market_list_sectors_deals(
let mut found: HashMap<SectorNumber, Vec<DealID>> = HashMap::new();
sector_deals
.for_each(|sno, deal_ids| {
found.insert(sno, deal_ids.deals.clone());
found.insert(sno, deal_ids.clone());
Ok(())
})
.unwrap();
Expand Down

0 comments on commit 0f381a6

Please sign in to comment.