From 390fcd1f019f8895638c0bd439378fdcb82dde5f Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Mon, 29 Jan 2024 15:57:37 +1100 Subject: [PATCH] Convert SectorDealIDs to an alias for Vec, removing struct Ref: https://github.com/filecoin-project/FIPs/pull/930 --- actors/market/src/lib.rs | 5 ++--- actors/market/src/state.rs | 19 +++++++------------ actors/market/tests/harness.rs | 2 +- integration_tests/src/util/mod.rs | 2 +- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/actors/market/src/lib.rs b/actors/market/src/lib.rs index 5517bd0a8..fc1972682 100644 --- a/actors/market/src/lib.rs +++ b/actors/market/src/lib.rs @@ -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, @@ -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 }); } diff --git a/actors/market/src/state.rs b/actors/market/src/state.rs index d5db93a5a..4bfece3aa 100644 --- a/actors/market/src/state.rs +++ b/actors/market/src/state.rs @@ -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, -} +pub type SectorDealIDs = Vec; pub type PendingDealAllocationsMap = Map2; pub const PENDING_ALLOCATIONS_CONFIG: Config = @@ -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, || { @@ -643,7 +639,7 @@ impl State { .delete(§or_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; } } @@ -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) })?; diff --git a/actors/market/tests/harness.rs b/actors/market/tests/harness.rs index ffd21cb4d..150e2836f 100644 --- a/actors/market/tests/harness.rs +++ b/actors/market/tests/harness.rs @@ -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![], } }) diff --git a/integration_tests/src/util/mod.rs b/integration_tests/src/util/mod.rs index 9f414017d..1646741ac 100644 --- a/integration_tests/src/util/mod.rs +++ b/integration_tests/src/util/mod.rs @@ -199,7 +199,7 @@ pub fn market_list_sectors_deals( let mut found: HashMap> = HashMap::new(); sector_deals .for_each(|sno, deal_ids| { - found.insert(sno, deal_ids.deals.clone()); + found.insert(sno, deal_ids.clone()); Ok(()) }) .unwrap();