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 committed Jan 29, 2024
1 parent d0b8d9c commit 390fcd1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
5 changes: 2 additions & 3 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,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 {
nonverified_deal_space,
verified_infos,
Expand Down Expand Up @@ -753,7 +752,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
19 changes: 7 additions & 12 deletions actors/market/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,12 @@ 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 SectorDealIDs = Vec<DealID>;

pub type PendingDealAllocationsMap<BS> = Map2<BS, DealID, AllocationID>;
pub const PENDING_ALLOCATIONS_CONFIG: Config =
Expand Down Expand Up @@ -610,10 +606,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 Down Expand Up @@ -643,7 +639,7 @@ impl State {
.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 +683,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
2 changes: 1 addition & 1 deletion actors/market/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ pub fn get_sector_deal_ids(
.flat_map(|sector_number| {
let deals: Option<&SectorDealIDs> = 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 @@ -199,7 +199,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 390fcd1

Please sign in to comment.