diff --git a/Cargo.lock b/Cargo.lock index ec6f669fc503..d6c2f72f1b53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,9 +27,7 @@ dependencies = [ "forest_hash_utils", "forest_json_utils", "forest_vm", - "ipld_amt 0.2.1", "ipld_blockstore", - "ipld_hamt 2.0.0", "libp2p", "serde", ] @@ -2334,9 +2332,9 @@ dependencies = [ "hex", "indexmap", "integer-encoding 3.0.1", - "ipld_amt 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ipld_amt 0.2.1", "ipld_blockstore", - "ipld_hamt 1.0.0", + "ipld_hamt 2.0.0", "lazy_static", "libp2p", "log", diff --git a/utils/bigint/src/bigint_ser.rs b/utils/bigint/src/bigint_ser.rs index c19366b9b64d..5ca2d2e12b02 100644 --- a/utils/bigint/src/bigint_ser.rs +++ b/utils/bigint/src/bigint_ser.rs @@ -11,7 +11,7 @@ use std::borrow::Cow; pub struct BigIntSer<'a>(#[serde(with = "self")] pub &'a BigInt); /// Wrapper for deserializing as BigInt from bytes. -#[derive(Deserialize, Serialize, Clone, Default)] +#[derive(Deserialize, Serialize, Clone, Default, PartialEq)] #[serde(transparent)] pub struct BigIntDe(#[serde(with = "self")] pub BigInt); diff --git a/vm/actor/Cargo.toml b/vm/actor/Cargo.toml index c8164be623e6..55f6c8e0a4d5 100644 --- a/vm/actor/Cargo.toml +++ b/vm/actor/Cargo.toml @@ -20,8 +20,8 @@ cid = { package = "forest_cid", version = "0.3", features = ["cbor"] } serde = { version = "1.0", features = ["derive"] } lazy_static = "1.4.0" ipld_blockstore = "0.1" -ipld_hamt = { version = "1.0", features = ["go-interop"] } -ipld_amt = { features = ["go-interop"], version = "0.2" } +ipld_hamt = { path = "../../ipld/hamt" } +ipld_amt = { path = "../../ipld/amt", features = ["go-interop"]} forest_ipld = "0.1.1" unsigned-varint = "0.6" integer-encoding = { version = "3.0", default-features = false } diff --git a/vm/actor/src/builtin/market/mod.rs b/vm/actor/src/builtin/market/mod.rs index 2298455d2471..1ae7c21ec15a 100644 --- a/vm/actor/src/builtin/market/mod.rs +++ b/vm/actor/src/builtin/market/mod.rs @@ -303,7 +303,7 @@ impl Actor { msm.deal_proposals .as_mut() .unwrap() - .set(id, deal.proposal.clone()) + .set(id as usize, deal.proposal.clone()) .map_err(|e| { e.downcast_default(ExitCode::ErrIllegalState, "failed to set deal") })?; @@ -450,7 +450,7 @@ impl Actor { .deal_states .as_ref() .unwrap() - .get(deal_id) + .get(deal_id as usize) .map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, @@ -466,7 +466,7 @@ impl Actor { .deal_proposals .as_ref() .unwrap() - .get(deal_id) + .get(deal_id as usize) .map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, @@ -500,7 +500,7 @@ impl Actor { .as_mut() .unwrap() .set( - deal_id, + deal_id as usize, DealState { sector_start_epoch: curr_epoch, last_updated_epoch: EPOCH_UNDEFINED, @@ -548,9 +548,14 @@ impl Actor { })?; for id in params.deal_ids { - let deal = msm.deal_proposals.as_ref().unwrap().get(id).map_err(|e| { - e.downcast_default(ExitCode::ErrIllegalState, "failed to get deal proposal") - })?; + let deal = msm + .deal_proposals + .as_ref() + .unwrap() + .get(id as usize) + .map_err(|e| { + e.downcast_default(ExitCode::ErrIllegalState, "failed to get deal proposal") + })?; // deal could have terminated and hence deleted before the sector is terminated. // we should simply continue instead of aborting execution here if a deal is not found. if deal.is_none() { @@ -572,7 +577,7 @@ impl Actor { .deal_states .as_ref() .unwrap() - .get(id) + .get(id as usize) .map_err(|e| { e.downcast_default(ExitCode::ErrIllegalState, "failed to get deal state") })? @@ -590,7 +595,7 @@ impl Actor { msm.deal_states .as_mut() .unwrap() - .set(id, state) + .set(id as usize, state) .map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, @@ -626,7 +631,7 @@ impl Actor { let mut pieces: Vec = Vec::with_capacity(params.deal_ids.len()); for deal_id in params.deal_ids { let deal = proposals - .get(deal_id) + .get(deal_id as usize) .map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, @@ -702,7 +707,7 @@ impl Actor { .deal_proposals .as_ref() .unwrap() - .get(deal_id) + .get(deal_id as usize) .map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, @@ -724,7 +729,7 @@ impl Actor { .deal_states .as_ref() .unwrap() - .get(deal_id) + .get(deal_id as usize) .map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, @@ -755,14 +760,14 @@ impl Actor { .deal_proposals .as_mut() .unwrap() - .delete(deal_id) + .delete(deal_id as usize) .map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, "failed to delete deal", ) })?; - if !deleted { + if deleted.is_none() { return Err(actor_error!(ErrIllegalState; "failed to delete deal proposal: does not exist")); } @@ -825,30 +830,30 @@ impl Actor { .deal_proposals .as_mut() .unwrap() - .delete(deal_id) + .delete(deal_id as usize) .map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, "failed to delete deal proposal", ) })?; - if !deleted { + if deleted.is_none() { return Err(actor_error!(ErrIllegalState; "failed to delete deal proposal: does not exist")); } - let deleted = - msm.deal_states - .as_mut() - .unwrap() - .delete(deal_id) - .map_err(|e| { - e.downcast_default( - ExitCode::ErrIllegalState, - "failed to delete deal state", - ) - })?; - if !deleted { + let deleted = msm + .deal_states + .as_mut() + .unwrap() + .delete(deal_id as usize) + .map_err(|e| { + e.downcast_default( + ExitCode::ErrIllegalState, + "failed to delete deal state", + ) + })?; + if deleted.is_none() { return Err(actor_error!(ErrIllegalState; "failed to delete deal state: does not exist")); } @@ -862,7 +867,7 @@ impl Actor { msm.deal_states .as_mut() .unwrap() - .set(deal_id, state) + .set(deal_id as usize, state) .map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, @@ -983,7 +988,7 @@ where .into()); } let proposal = proposals - .get(*deal_id)? + .get(*deal_id as usize)? .ok_or_else(|| actor_error!(ErrNotFound, "no such deal {}", deal_id))?; validate_deal_can_activate(&proposal, miner_addr, sector_expiry, curr_epoch) diff --git a/vm/actor/src/builtin/miner/bitfield_queue.rs b/vm/actor/src/builtin/miner/bitfield_queue.rs index ced9f17738b3..676ea9eb3f29 100644 --- a/vm/actor/src/builtin/miner/bitfield_queue.rs +++ b/vm/actor/src/builtin/miner/bitfield_queue.rs @@ -41,13 +41,13 @@ impl<'db, BS: BlockStore> BitFieldQueue<'db, BS> { let bitfield = self .amt - .get(epoch as u64) + .get(epoch as usize) .map_err(|e| e.downcast_wrap(format!("failed to lookup queue epoch {}", epoch)))? .cloned() .unwrap_or_default(); self.amt - .set(epoch as u64, &bitfield | values) + .set(epoch as usize, &bitfield | values) .map_err(|e| e.downcast_wrap(format!("failed to set queue epoch {}", epoch)))?; Ok(()) @@ -56,12 +56,12 @@ impl<'db, BS: BlockStore> BitFieldQueue<'db, BS> { pub fn add_to_queue_values( &mut self, epoch: ChainEpoch, - values: &[u64], + values: &[usize], ) -> Result<(), Box> { if values.is_empty() { Ok(()) } else { - self.add_to_queue(epoch, &values.iter().map(|&i| i as usize).collect()) + self.add_to_queue(epoch, &values.iter().copied().collect()) } } @@ -70,7 +70,7 @@ impl<'db, BS: BlockStore> BitFieldQueue<'db, BS> { /// /// See the docs on `BitField::cut` to better understand what it does. pub fn cut(&mut self, to_cut: &BitField) -> Result<(), Box> { - let mut epochs_to_remove = Vec::::new(); + let mut epochs_to_remove = Vec::::new(); self.amt .for_each_mut(|epoch, bitfield| { @@ -87,7 +87,7 @@ impl<'db, BS: BlockStore> BitFieldQueue<'db, BS> { .map_err(|e| e.downcast_wrap("failed to cut from bitfield queue"))?; self.amt - .batch_delete(epochs_to_remove) + .batch_delete(epochs_to_remove, true) .map_err(|e| e.downcast_wrap("failed to remove empty epochs from bitfield queue"))?; Ok(()) @@ -95,12 +95,12 @@ impl<'db, BS: BlockStore> BitFieldQueue<'db, BS> { pub fn add_many_to_queue_values( &mut self, - values: &HashMap>, + values: &HashMap>, ) -> Result<(), Box> { // Update each epoch in-order to be deterministic. // Pre-quantize to reduce the number of updates. - let mut quantized_values = HashMap::>::with_capacity(values.len()); + let mut quantized_values = HashMap::>::with_capacity(values.len()); let mut updated_epochs = Vec::::with_capacity(values.len()); for (&raw_epoch, entries) in values { @@ -122,7 +122,7 @@ impl<'db, BS: BlockStore> BitFieldQueue<'db, BS> { /// Modified return value indicates whether this structure has been changed by the call. pub fn pop_until(&mut self, until: ChainEpoch) -> Result<(BitField, bool), Box> { let mut popped_values = BitField::new(); - let mut popped_keys = Vec::::new(); + let mut popped_keys = Vec::::new(); self.amt.for_each_while(|epoch, bitfield| { if epoch as ChainEpoch > until { @@ -130,7 +130,7 @@ impl<'db, BS: BlockStore> BitFieldQueue<'db, BS> { return Ok(false); } - popped_keys.push(epoch as u64); + popped_keys.push(epoch as usize); popped_values |= bitfield; Ok(true) })?; @@ -140,7 +140,7 @@ impl<'db, BS: BlockStore> BitFieldQueue<'db, BS> { return Ok((BitField::new(), false)); } - self.amt.batch_delete(popped_keys)?; + self.amt.batch_delete(popped_keys, true)?; Ok((popped_values, true)) } } diff --git a/vm/actor/src/builtin/miner/deadline_state.rs b/vm/actor/src/builtin/miner/deadline_state.rs index 86ab24fdb982..8df7caf1aecb 100644 --- a/vm/actor/src/builtin/miner/deadline_state.rs +++ b/vm/actor/src/builtin/miner/deadline_state.rs @@ -37,9 +37,9 @@ impl Deadlines { pub fn load_deadline( &self, store: &BS, - deadline_idx: u64, + deadline_idx: usize, ) -> Result { - if deadline_idx >= WPOST_PERIOD_DEADLINES as u64 { + if deadline_idx >= WPOST_PERIOD_DEADLINES as usize { return Err(actor_error!( ErrIllegalArgument, "invalid deadline {}", @@ -48,7 +48,7 @@ impl Deadlines { } store - .get(&self.due[deadline_idx as usize]) + .get(&self.due[deadline_idx]) .ok() .flatten() .ok_or_else(|| { @@ -63,10 +63,10 @@ impl Deadlines { pub fn for_each( &self, store: &BS, - mut f: impl FnMut(u64, Deadline) -> Result<(), Box>, + mut f: impl FnMut(usize, Deadline) -> Result<(), Box>, ) -> Result<(), Box> { for i in 0..self.due.len() { - let index = i as u64; + let index = i; let deadline = self.load_deadline(store, index)?; f(index, deadline)?; } @@ -76,10 +76,10 @@ impl Deadlines { pub fn update_deadline( &mut self, store: &BS, - deadline_idx: u64, + deadline_idx: usize, deadline: &Deadline, ) -> Result<(), Box> { - if deadline_idx >= WPOST_PERIOD_DEADLINES as u64 { + if deadline_idx >= WPOST_PERIOD_DEADLINES as usize { return Err(format!("invalid deadline {}", deadline_idx).into()); } @@ -147,7 +147,7 @@ impl Deadline { pub fn load_partition( &self, store: &BS, - partition_idx: u64, + partition_idx: usize, ) -> Result> { let partitions = Amt::::load(&self.partitions, store)?; @@ -169,7 +169,7 @@ impl Deadline { &mut self, store: &BS, expiration_epoch: ChainEpoch, - partitions: &[u64], + partitions: &[usize], quant: QuantSpec, ) -> Result<(), Box> { // Avoid doing any work if there's nothing to reschedule. @@ -212,11 +212,11 @@ impl Deadline { let mut all_on_time_pledge = TokenAmount::zero(); let mut all_active_power = PowerPair::zero(); let mut all_faulty_power = PowerPair::zero(); - let mut partitions_with_early_terminations = Vec::::new(); + let mut partitions_with_early_terminations = Vec::::new(); // For each partition with an expiry, remove and collect expirations from the partition queue. for i in expired_partitions.iter() { - let partition_idx = i as u64; + let partition_idx = i; let mut partition = partitions .get(partition_idx)? .cloned() @@ -289,7 +289,7 @@ impl Deadline { } // First update partitions, consuming the sectors - let mut partition_deadline_updates = HashMap::>::new(); + let mut partition_deadline_updates = HashMap::>::new(); let mut activated_power = PowerPair::zero(); self.live_sectors += sectors.len() as u64; self.total_sectors += sectors.len() as u64; @@ -367,11 +367,11 @@ impl Deadline { ) -> Result<(TerminationResult, /* has more */ bool), Box> { let mut partitions = self.partitions_amt(store)?; - let mut partitions_finished = Vec::::new(); + let mut partitions_finished = Vec::::new(); let mut result = TerminationResult::new(); for i in self.early_terminations.iter() { - let partition_idx = i as u64; + let partition_idx = i; let mut partition = match partitions.get(partition_idx).map_err(|e| { e.downcast_wrap(format!("failed to load partition {}", partition_idx)) @@ -534,7 +534,7 @@ impl Deadline { return Ok((BitField::new(), BitField::new(), PowerPair::zero())); } - if let Some(partition_idx) = to_remove_set.iter().find(|&&i| i as u64 >= partition_count) { + if let Some(partition_idx) = to_remove_set.iter().find(|&&i| i >= partition_count) { return Err( actor_error!(ErrIllegalArgument; "partition index {} out of range [0, {})", partition_idx, partition_count).into() ); @@ -637,7 +637,7 @@ impl Deadline { // Record partitions with some fault, for subsequently indexing in the deadline. // Duplicate entries don't matter, they'll be stored in a bitfield (a set). - let mut partitions_with_fault = Vec::::with_capacity(partition_sectors.len()); + let mut partitions_with_fault = Vec::::with_capacity(partition_sectors.len()); let mut power_delta = PowerPair::zero(); for (partition_idx, sector_numbers) in partition_sectors.iter() { @@ -758,11 +758,11 @@ impl Deadline { .map_err(|e| e.wrap("failed to load partitions"))?; let mut detected_any = false; - let mut rescheduled_partitions = Vec::::new(); + let mut rescheduled_partitions = Vec::::new(); let mut power_delta = PowerPair::zero(); let mut penalized_power = PowerPair::zero(); for partition_idx in 0..partitions.count() { - let proven = self.post_submissions.get(partition_idx as usize); + let proven = self.post_submissions.get(partition_idx); if proven { continue; @@ -850,7 +850,7 @@ impl Deadline { pub fn for_each( &self, store: &BS, - f: impl FnMut(u64, &Partition) -> Result<(), Box>, + f: impl FnMut(usize, &Partition) -> Result<(), Box>, ) -> Result<(), Box> { let parts = self.partitions_amt(store)?; parts.for_each(f) @@ -915,12 +915,12 @@ impl Deadline { let mut new_faulty_power_total = PowerPair::zero(); let mut retracted_recovery_power_total = PowerPair::zero(); let mut recovered_power_total = PowerPair::zero(); - let mut rescheduled_partitions = Vec::::new(); + let mut rescheduled_partitions = Vec::::new(); let mut power_delta = PowerPair::zero(); // Accumulate sectors info for proof verification. for post in post_partitions { - let already_proven = self.post_submissions.get(post.index as usize); + let already_proven = self.post_submissions.get(post.index); if already_proven { // Skip partitions already proven for this deadline. @@ -1044,7 +1044,7 @@ impl Deadline { let mut partitions = self.partitions_amt(store)?; // track partitions with moved expirations. - let mut rescheduled_partitions = Vec::::new(); + let mut rescheduled_partitions = Vec::::new(); let mut all_replaced = Vec::new(); for (partition_idx, sector_numbers) in partition_sectors.iter() { diff --git a/vm/actor/src/builtin/miner/deadlines.rs b/vm/actor/src/builtin/miner/deadlines.rs index 755e58c14134..cfb6728cdec0 100644 --- a/vm/actor/src/builtin/miner/deadlines.rs +++ b/vm/actor/src/builtin/miner/deadlines.rs @@ -14,14 +14,14 @@ use std::error::Error as StdError; pub fn new_deadline_info( proving_period_start: ChainEpoch, - deadline_idx: u64, + deadline_idx: usize, current_epoch: ChainEpoch, ) -> DeadlineInfo { DeadlineInfo::new( proving_period_start, - deadline_idx, + deadline_idx as u64, current_epoch, - WPOST_PERIOD_DEADLINES, + WPOST_PERIOD_DEADLINES as u64, WPOST_PROVING_PERIOD, WPOST_CHALLENGE_WINDOW, WPOST_CHALLENGE_LOOKBACK, @@ -36,9 +36,9 @@ impl Deadlines { &self, store: &BS, sector_number: SectorNumber, - ) -> Result<(u64, u64), Box> { + ) -> Result<(usize, usize), Box> { for i in 0..self.due.len() { - let deadline_idx = i as u64; + let deadline_idx = i; let deadline = self.load_deadline(store, deadline_idx)?; let partitions = Amt::::load(&deadline.partitions, store)?; @@ -65,7 +65,7 @@ impl Deadlines { /// Returns true if the deadline at the given index is currently mutable. pub fn deadline_is_mutable( proving_period_start: ChainEpoch, - deadline_idx: u64, + deadline_idx: usize, current_epoch: ChainEpoch, ) -> bool { // Get the next non-elapsed deadline (i.e., the next time we care about diff --git a/vm/actor/src/builtin/miner/expiration_queue.rs b/vm/actor/src/builtin/miner/expiration_queue.rs index c4e5aed2b403..8f532c59f0f0 100644 --- a/vm/actor/src/builtin/miner/expiration_queue.rs +++ b/vm/actor/src/builtin/miner/expiration_queue.rs @@ -294,7 +294,7 @@ impl<'db, BS: BlockStore> ExpirationQueue<'db, BS> { &mut self, fault_expiration: ChainEpoch, ) -> Result<(), Box> { - let mut rescheduled_epochs = Vec::::new(); + let mut rescheduled_epochs = Vec::::new(); let mut rescheduled_sectors = BitField::new(); let mut rescheduled_power = PowerPair::zero(); @@ -312,7 +312,7 @@ impl<'db, BS: BlockStore> ExpirationQueue<'db, BS> { expiration_set.active_power = PowerPair::zero(); mutated_expiration_sets.push((epoch, expiration_set)); } else { - rescheduled_epochs.push(epoch as u64); + rescheduled_epochs.push(epoch as usize); // sanity check to make sure we're not trying to re-schedule already faulty sectors. if !expiration_set.early_sectors.is_empty() { return Err( @@ -350,7 +350,7 @@ impl<'db, BS: BlockStore> ExpirationQueue<'db, BS> { )?; // Trim the rescheduled epochs from the queue. - self.amt.batch_delete(rescheduled_epochs)?; + self.amt.batch_delete(rescheduled_epochs, true)?; Ok(()) } @@ -589,7 +589,7 @@ impl<'db, BS: BlockStore> ExpirationQueue<'db, BS> { let mut active_power = PowerPair::zero(); let mut faulty_power = PowerPair::zero(); let mut on_time_pledge = TokenAmount::zero(); - let mut popped_keys = Vec::::new(); + let mut popped_keys = Vec::::new(); self.amt.for_each_while(|i, this_value| { if i as ChainEpoch > until { @@ -606,7 +606,7 @@ impl<'db, BS: BlockStore> ExpirationQueue<'db, BS> { Ok(true) })?; - self.amt.batch_delete(popped_keys)?; + self.amt.batch_delete(popped_keys, true)?; Ok(ExpirationSet { on_time_sectors, @@ -653,7 +653,7 @@ impl<'db, BS: BlockStore> ExpirationQueue<'db, BS> { let epoch = self.quant.quantize_up(raw_epoch); let mut expiration_set = self .amt - .get(epoch as u64) + .get(epoch as usize) .map_err(|e| e.downcast_wrap(format!("failed to lookup queue epoch {}", epoch)))? .ok_or_else(|| format!("missing expected expiration set at epoch {}", epoch))? .clone(); @@ -740,7 +740,7 @@ impl<'db, BS: BlockStore> ExpirationQueue<'db, BS> { })?; self.amt - .batch_delete(epochs_emptied.iter().map(|&i| i as u64))?; + .batch_delete(epochs_emptied.iter().map(|&i| i as usize), true)?; Ok(()) } @@ -748,7 +748,7 @@ impl<'db, BS: BlockStore> ExpirationQueue<'db, BS> { fn may_get(&self, key: ChainEpoch) -> Result> { Ok(self .amt - .get(key as u64) + .get(key as usize) .map_err(|e| e.downcast_wrap(format!("failed to lookup queue epoch {}", key)))? .cloned() .unwrap_or_default()) @@ -760,7 +760,7 @@ impl<'db, BS: BlockStore> ExpirationQueue<'db, BS> { expiration_set: ExpirationSet, ) -> Result<(), Box> { self.amt - .set(epoch as u64, expiration_set) + .set(epoch as usize, expiration_set) .map_err(|e| e.downcast_wrap(format!("failed to set queue epoch {}", epoch))) } @@ -772,11 +772,11 @@ impl<'db, BS: BlockStore> ExpirationQueue<'db, BS> { ) -> Result<(), Box> { if expiration_set.is_empty() { self.amt - .delete(epoch as u64) + .delete(epoch as usize) .map_err(|e| e.downcast_wrap(format!("failed to delete queue epoch {}", epoch)))?; } else { self.amt - .set(epoch as u64, expiration_set) + .set(epoch as usize, expiration_set) .map_err(|e| e.downcast_wrap(format!("failed to set queue epoch {}", epoch)))?; } diff --git a/vm/actor/src/builtin/miner/mod.rs b/vm/actor/src/builtin/miner/mod.rs index b1651588233d..3e713be22768 100644 --- a/vm/actor/src/builtin/miner/mod.rs +++ b/vm/actor/src/builtin/miner/mod.rs @@ -217,7 +217,7 @@ impl Actor { let period_start = current_proving_period_start(current_epoch, offset); let deadline_idx = current_deadline_index(current_epoch, period_start); - assert!(deadline_idx < WPOST_PERIOD_DEADLINES); + assert!(deadline_idx < WPOST_PERIOD_DEADLINES as usize); let info = MinerInfo::new( owner, @@ -468,7 +468,7 @@ impl Actor { let current_epoch = rt.curr_epoch(); let network_version = rt.network_version(); - if params.deadline >= WPOST_PERIOD_DEADLINES { + if params.deadline >= WPOST_PERIOD_DEADLINES as usize { return Err(actor_error!( ErrIllegalArgument, "invalid deadline {} of {}", @@ -564,7 +564,7 @@ impl Actor { } // The miner may only submit a proof for the current deadline. - if params.deadline != current_deadline.index { + if params.deadline != current_deadline.index as usize { return Err(actor_error!( ErrIllegalArgument, "invalid deadline {} at epoch {}, expected {}", @@ -792,7 +792,7 @@ impl Actor { )); } - if params.replace_sector_deadline >= WPOST_PERIOD_DEADLINES { + if params.replace_sector_deadline >= WPOST_PERIOD_DEADLINES as usize { return Err(actor_error!( ErrIllegalArgument, "invalid deadline {}", @@ -1171,7 +1171,7 @@ impl Actor { // This should be enforced by the power actor. We log here just in case // something goes wrong. - if params.sectors.len() as u64 > MAX_MINER_PROVE_COMMITS_PER_EPOCH { + if params.sectors.len() > MAX_MINER_PROVE_COMMITS_PER_EPOCH { log::warn!( "confirmed more prove commits in an epoch than permitted: {} > {}", params.sectors.len(), @@ -1521,7 +1521,7 @@ impl Actor { let mut sector_count: u64 = 0; for decl in &mut params.extensions { - if decl.deadline >= WPOST_PERIOD_DEADLINES { + if decl.deadline >= WPOST_PERIOD_DEADLINES as usize { return Err(actor_error!( ErrIllegalArgument, "deadline {} not in range 0..{}", @@ -1579,8 +1579,8 @@ impl Actor { .map_err(|e| e.wrap("failed to load deadlines"))?; // Group declarations by deadline, and remember iteration order. - let mut decls_by_deadline = HashMap::>::new(); - let mut deadlines_to_load = Vec::::new(); + let mut decls_by_deadline = HashMap::>::new(); + let mut deadlines_to_load = Vec::::new(); for decl in params.extensions { decls_by_deadline @@ -1614,7 +1614,7 @@ impl Actor { let quant = state.quant_spec_for_deadline(deadline_idx); // Group modified partitions by epoch to which they are extended. Duplicates are ok. - let mut partitions_by_new_epoch = HashMap::>::new(); + let mut partitions_by_new_epoch = HashMap::>::new(); let mut epochs_to_reschedule = Vec::::new(); for decl in decls_by_deadline.get_mut(&deadline_idx).unwrap() { @@ -2233,7 +2233,7 @@ impl Actor { BS: BlockStore, RT: Runtime, { - if params.deadline >= WPOST_PERIOD_DEADLINES { + if params.deadline >= WPOST_PERIOD_DEADLINES as usize { return Err(actor_error!( ErrIllegalArgument, "invalid deadline {}", @@ -3596,10 +3596,10 @@ fn current_proving_period_start(current_epoch: ChainEpoch, offset: ChainEpoch) - period_start } -fn current_deadline_index(current_epoch: ChainEpoch, period_start: ChainEpoch) -> u64 { +fn current_deadline_index(current_epoch: ChainEpoch, period_start: ChainEpoch) -> usize { assert!(current_epoch >= period_start); - ((current_epoch - period_start) / WPOST_CHALLENGE_WINDOW) as u64 + ((current_epoch - period_start) / WPOST_CHALLENGE_WINDOW) as usize } /// Computes deadline information for a fault or recovery declaration. @@ -3607,10 +3607,10 @@ fn current_deadline_index(current_epoch: ChainEpoch, period_start: ChainEpoch) - /// If the deadline has elapsed, it's instead taken as being for the next proving period after the current epoch. fn declaration_deadline_info( period_start: ChainEpoch, - deadline_idx: u64, + deadline_idx: usize, current_epoch: ChainEpoch, ) -> Result { - if deadline_idx >= WPOST_PERIOD_DEADLINES { + if deadline_idx >= WPOST_PERIOD_DEADLINES as usize { return Err(format!( "invalid deadline {}, must be < {}", deadline_idx, WPOST_PERIOD_DEADLINES diff --git a/vm/actor/src/builtin/miner/partition_state.rs b/vm/actor/src/builtin/miner/partition_state.rs index 0adf278d3237..1d7729b236cb 100644 --- a/vm/actor/src/builtin/miner/partition_state.rs +++ b/vm/actor/src/builtin/miner/partition_state.rs @@ -640,7 +640,7 @@ impl Partition { let mut early_terminated_queue = BitFieldQueue::new(store, &self.early_terminated, NO_QUANTIZATION)?; - let mut processed = Vec::::new(); + let mut processed = Vec::::new(); let mut remaining: Option<(BitField, ChainEpoch)> = None; let mut result = TerminationResult::new(); result.partitions_processed = 1; @@ -676,7 +676,7 @@ impl Partition { // Update early terminations early_terminated_queue .amt - .batch_delete(processed) + .batch_delete(processed, true) .map_err(|e| { e.downcast_wrap("failed to remove entries from early terminations queue") })?; @@ -684,7 +684,7 @@ impl Partition { if let Some((remaining_sectors, remaining_epoch)) = remaining.take() { early_terminated_queue .amt - .set(remaining_epoch as u64, remaining_sectors) + .set(remaining_epoch as usize, remaining_sectors) .map_err(|e| { e.downcast_wrap("failed to update remaining entry early terminations queue") })?; diff --git a/vm/actor/src/builtin/miner/sector_map.rs b/vm/actor/src/builtin/miner/sector_map.rs index 1b05c2c1a246..86d0e09d0f6c 100644 --- a/vm/actor/src/builtin/miner/sector_map.rs +++ b/vm/actor/src/builtin/miner/sector_map.rs @@ -7,7 +7,7 @@ use std::collections::HashMap; /// Maps deadlines to partition maps. #[derive(Default)] -pub struct DeadlineSectorMap(HashMap); +pub struct DeadlineSectorMap(HashMap); impl DeadlineSectorMap { pub fn new() -> Self { @@ -62,11 +62,11 @@ impl DeadlineSectorMap { /// Records the given sector bitfield at the given deadline/partition index. pub fn add( &mut self, - deadline_idx: u64, - partition_idx: u64, + deadline_idx: usize, + partition_idx: usize, sector_numbers: UnvalidatedBitField, ) -> Result<(), String> { - if deadline_idx >= WPOST_PERIOD_DEADLINES { + if deadline_idx >= WPOST_PERIOD_DEADLINES as usize { return Err(format!("invalid deadline {}", deadline_idx)); } @@ -79,8 +79,8 @@ impl DeadlineSectorMap { /// Records the given sectors at the given deadline/partition index. pub fn add_values( &mut self, - deadline_idx: u64, - partition_idx: u64, + deadline_idx: usize, + partition_idx: usize, sector_numbers: &[u64], ) -> Result<(), String> { self.add( @@ -95,14 +95,14 @@ impl DeadlineSectorMap { } /// Returns a sorted vec of deadlines in the map. - pub fn deadlines(&self) -> Vec { + pub fn deadlines(&self) -> Vec { let mut deadlines: Vec<_> = self.0.keys().copied().collect(); deadlines.sort_unstable(); deadlines } /// Walks the deadlines in deadline order. - pub fn iter(&mut self) -> impl Iterator + '_ { + pub fn iter(&mut self) -> impl Iterator + '_ { let mut vec: Vec<_> = self.0.iter_mut().map(|(&i, x)| (i, x)).collect(); vec.sort_unstable_by_key(|&(i, _)| i); vec.into_iter() @@ -111,13 +111,13 @@ impl DeadlineSectorMap { /// Maps partitions to sector bitfields. #[derive(Default)] -pub struct PartitionSectorMap(HashMap); +pub struct PartitionSectorMap(HashMap); impl PartitionSectorMap { /// Records the given sectors at the given partition. pub fn add_values( &mut self, - partition_idx: u64, + partition_idx: usize, sector_numbers: Vec, ) -> Result<(), String> { self.add( @@ -133,7 +133,7 @@ impl PartitionSectorMap { /// it with any existing bitfields if necessary. pub fn add( &mut self, - partition_idx: u64, + partition_idx: usize, mut sector_numbers: UnvalidatedBitField, ) -> Result<(), String> { match self.0.get_mut(&partition_idx) { @@ -173,14 +173,14 @@ impl PartitionSectorMap { } /// Returns a sorted vec of partitions in the map. - pub fn partitions(&self) -> Vec { + pub fn partitions(&self) -> Vec { let mut partitions: Vec<_> = self.0.keys().copied().collect(); partitions.sort_unstable(); partitions } /// Walks the partitions in the map, in order of increasing index. - pub fn iter(&mut self) -> impl Iterator + '_ { + pub fn iter(&mut self) -> impl Iterator + '_ { let mut vec: Vec<_> = self.0.iter_mut().map(|(&i, x)| (i, x)).collect(); vec.sort_unstable_by_key(|&(i, _)| i); vec.into_iter() diff --git a/vm/actor/src/builtin/miner/sectors.rs b/vm/actor/src/builtin/miner/sectors.rs index 3cbfdef72317..c5efb660b729 100644 --- a/vm/actor/src/builtin/miner/sectors.rs +++ b/vm/actor/src/builtin/miner/sectors.rs @@ -42,7 +42,7 @@ impl<'db, BS: BlockStore> Sectors<'db, BS> { for sector_number in sector_numbers.iter() { let sector_on_chain = self .amt - .get(sector_number as SectorNumber) + .get(sector_number) .map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, @@ -62,7 +62,7 @@ impl<'db, BS: BlockStore> Sectors<'db, BS> { ) -> Result, Box> { Ok(self .amt - .get(sector_number) + .get(sector_number as usize) .map_err(|e| e.downcast_wrap(format!("failed to get sector {}", sector_number)))? .cloned()) } @@ -75,7 +75,7 @@ impl<'db, BS: BlockStore> Sectors<'db, BS> { return Err(format!("sector number {} out of range", info.sector_number).into()); } - self.amt.set(sector_number, info).map_err(|e| { + self.amt.set(sector_number as usize, info).map_err(|e| { e.downcast_wrap(format!("failed to store sector {}", sector_number)) })?; } diff --git a/vm/actor/src/builtin/miner/state.rs b/vm/actor/src/builtin/miner/state.rs index e892cd08d910..f0549139332e 100644 --- a/vm/actor/src/builtin/miner/state.rs +++ b/vm/actor/src/builtin/miner/state.rs @@ -84,7 +84,7 @@ pub struct State { /// Index of the deadline within the proving period beginning at ProvingPeriodStart that has not yet been /// finalized. /// Updated at the end of each deadline window by a cron callback. - pub current_deadline: u64, + pub current_deadline: usize, /// The sector numbers due for PoSt at each deadline in the current proving period, frozen at period start. /// New sectors are added and expired ones removed at proving period boundary. @@ -102,7 +102,7 @@ impl State { pub fn new( info_cid: Cid, period_start: ChainEpoch, - current_deadline: u64, + current_deadline: usize, empty_bitfield_cid: Cid, empty_array_cid: Cid, empty_map_cid: Cid, @@ -159,7 +159,7 @@ impl State { } /// Returns deadline calculations for the current (according to state) proving period. - pub fn quant_spec_for_deadline(&self, deadline_idx: u64) -> QuantSpec { + pub fn quant_spec_for_deadline(&self, deadline_idx: usize) -> QuantSpec { new_deadline_info(self.proving_period_start, deadline_idx, 0).quant_spec() } @@ -364,7 +364,7 @@ impl State { for sector_num in sector_nos.iter() { sectors .amt - .delete(sector_num as u64) + .delete(sector_num) .map_err(|e| e.downcast_wrap("could not delete sector number"))?; } @@ -389,7 +389,7 @@ impl State { &self, store: &BS, sector_number: SectorNumber, - ) -> Result<(u64, u64), Box> { + ) -> Result<(usize, usize), Box> { let deadlines = self.load_deadlines(store)?; deadlines.find_sector(store, sector_number) } @@ -478,7 +478,7 @@ impl State { continue; } - let quant = self.quant_spec_for_deadline(deadline_idx as u64); + let quant = self.quant_spec_for_deadline(deadline_idx); let deadline = deadline_vec[deadline_idx].as_mut().unwrap(); let deadline_activated_power = deadline.add_sectors( @@ -492,7 +492,7 @@ impl State { activated_power += &deadline_activated_power; - deadlines.update_deadline(store, deadline_idx as u64, deadline)?; + deadlines.update_deadline(store, deadline_idx, deadline)?; } self.save_deadlines(store, deadlines)?; @@ -522,7 +522,7 @@ impl State { // Process early terminations. for i in self.early_terminations.iter() { - let deadline_idx = i as u64; + let deadline_idx = i; // Load deadline + partitions. let mut deadline = deadlines.load_deadline(store, deadline_idx)?; @@ -571,8 +571,8 @@ impl State { pub fn check_sector_health( &self, store: &BS, - deadline_idx: u64, - partition_idx: u64, + deadline_idx: usize, + partition_idx: usize, sector_number: SectorNumber, ) -> Result<(), Box> { let deadlines = self.load_deadlines(store)?; @@ -915,7 +915,7 @@ impl State { .map_err(|e| e.downcast_wrap("failed to load pre-commit sector queue"))?; // add entry for this sector to the queue - queue.add_to_queue_values(expire_epoch, &[sector_number])?; + queue.add_to_queue_values(expire_epoch, &[sector_number as usize])?; self.pre_committed_sectors_expiry = queue.amt.flush()?; Ok(()) @@ -995,14 +995,14 @@ impl State { }); } - self.current_deadline = (self.current_deadline + 1) % WPOST_PERIOD_DEADLINES; + self.current_deadline = (self.current_deadline + 1) % WPOST_PERIOD_DEADLINES as usize; if self.current_deadline == 0 { self.proving_period_start += WPOST_PROVING_PERIOD; } let mut deadlines = self.load_deadlines(store)?; - let mut deadline = deadlines.load_deadline(store, dl_info.index)?; + let mut deadline = deadlines.load_deadline(store, dl_info.index as usize)?; let previously_faulty_power = deadline.faulty_power.clone(); @@ -1046,7 +1046,7 @@ impl State { self.early_terminations.set(dl_info.index as usize); } - deadlines.update_deadline(store, dl_info.index, &deadline)?; + deadlines.update_deadline(store, dl_info.index as usize, &deadline)?; self.save_deadlines(store, deadlines)?; diff --git a/vm/actor/src/builtin/miner/types.rs b/vm/actor/src/builtin/miner/types.rs index 83a3d14076eb..54fd1939370d 100644 --- a/vm/actor/src/builtin/miner/types.rs +++ b/vm/actor/src/builtin/miner/types.rs @@ -36,8 +36,8 @@ pub struct CronEventPayload { #[derive(Debug)] pub struct PartitionKey { - pub deadline: u64, - pub partition: u64, + pub deadline: usize, + pub partition: usize, } #[derive(Serialize_tuple, Deserialize_tuple)] @@ -72,7 +72,7 @@ pub struct ConfirmSectorProofsParams { #[derive(Serialize_tuple, Deserialize_tuple)] pub struct PoStPartition { /// Partitions are numbered per-deadline, from zero. - pub index: u64, + pub index: usize, /// Sectors skipped while proving that weren't already declared faulty. pub skipped: UnvalidatedBitField, } @@ -81,7 +81,7 @@ pub struct PoStPartition { #[derive(Serialize_tuple, Deserialize_tuple)] pub struct SubmitWindowedPoStParams { /// The deadline index which the submission targets. - pub deadline: u64, + pub deadline: usize, /// The partitions being proven. pub partitions: Vec, /// Array of proofs, one per distinct registered proof type present in the sectors being proven. @@ -112,8 +112,8 @@ pub struct ExtendSectorExpirationParams { #[derive(Serialize_tuple, Deserialize_tuple)] pub struct ExpirationExtension { - pub deadline: u64, - pub partition: u64, + pub deadline: usize, + pub partition: usize, pub sectors: UnvalidatedBitField, pub new_expiration: ChainEpoch, } @@ -125,8 +125,8 @@ pub struct TerminateSectorsParams { #[derive(Serialize_tuple, Deserialize_tuple)] pub struct TerminationDeclaration { - pub deadline: u64, - pub partition: u64, + pub deadline: usize, + pub partition: usize, pub sectors: UnvalidatedBitField, } @@ -148,9 +148,9 @@ pub struct DeclareFaultsParams { #[derive(Serialize_tuple, Deserialize_tuple)] pub struct FaultDeclaration { /// The deadline to which the faulty sectors are assigned, in range [0..WPoStPeriodDeadlines) - pub deadline: u64, + pub deadline: usize, /// Partition index within the deadline containing the faulty sectors. - pub partition: u64, + pub partition: usize, /// Sectors in the partition being declared faulty. pub sectors: UnvalidatedBitField, } @@ -163,16 +163,16 @@ pub struct DeclareFaultsRecoveredParams { #[derive(Serialize_tuple, Deserialize_tuple)] pub struct RecoveryDeclaration { /// The deadline to which the recovered sectors are assigned, in range [0..WPoStPeriodDeadlines) - pub deadline: u64, + pub deadline: usize, /// Partition index within the deadline containing the recovered sectors. - pub partition: u64, + pub partition: usize, /// Sectors in the partition being declared recovered. pub sectors: UnvalidatedBitField, } #[derive(Serialize_tuple, Deserialize_tuple)] pub struct CompactPartitionsParams { - pub deadline: u64, + pub deadline: usize, pub partitions: UnvalidatedBitField, } @@ -218,8 +218,8 @@ pub struct SectorPreCommitInfo { /// Whether to replace a "committed capacity" no-deal sector (requires non-empty DealIDs) pub replace_capacity: bool, /// The committed capacity sector to replace, and its deadline/partition location - pub replace_sector_deadline: u64, - pub replace_sector_partition: u64, + pub replace_sector_deadline: usize, + pub replace_sector_partition: usize, pub replace_sector_number: SectorNumber, } diff --git a/vm/actor/src/builtin/paych/mod.rs b/vm/actor/src/builtin/paych/mod.rs index 437ef3bfbfe7..1438cff7f71d 100644 --- a/vm/actor/src/builtin/paych/mod.rs +++ b/vm/actor/src/builtin/paych/mod.rs @@ -333,16 +333,16 @@ impl Actor { #[inline] fn find_lane<'a, BS>( ls: &'a Amt, - id: u64, + id: usize, ) -> Result, ActorError> where BS: BlockStore, { - if id > MAX_LANE as u64 { + if id > MAX_LANE as usize { return Err(actor_error!(ErrIllegalArgument; "maximum lane ID is 2^63-1")); } - ls.get(id).map_err(|e| { + ls.get(id as usize).map_err(|e| { e.downcast_default( ExitCode::ErrIllegalState, format!("failed to load lane {}", id), diff --git a/vm/actor/src/builtin/paych/state.rs b/vm/actor/src/builtin/paych/state.rs index 9a9e73eea2c5..0e4bbe14238d 100644 --- a/vm/actor/src/builtin/paych/state.rs +++ b/vm/actor/src/builtin/paych/state.rs @@ -54,7 +54,7 @@ pub struct LaneState { /// Specifies which `lane`s to be merged with what `nonce` on `channel_update` #[derive(Default, Clone, Copy, Debug, PartialEq, Serialize_tuple, Deserialize_tuple)] pub struct Merge { - pub lane: u64, + pub lane: usize, pub nonce: u64, } diff --git a/vm/actor/src/builtin/paych/types.rs b/vm/actor/src/builtin/paych/types.rs index 184e7d4cd8ca..d8f6decbc6ce 100644 --- a/vm/actor/src/builtin/paych/types.rs +++ b/vm/actor/src/builtin/paych/types.rs @@ -42,7 +42,7 @@ pub struct SignedVoucher { /// (optional) Specified by `from` to add a verification method to the voucher pub extra: Option, /// Specifies which lane the Voucher merges into (will be created if does not exist) - pub lane: u64, + pub lane: usize, /// Set by `from` to prevent redemption of stale vouchers on a lane pub nonce: u64, /// Amount voucher can be redeemed for @@ -69,7 +69,7 @@ impl SignedVoucher { #[serde(with = "serde_bytes")] pub secret_pre_image: &'a [u8], pub extra: &'a Option, - pub lane: u64, + pub lane: usize, pub nonce: u64, #[serde(with = "bigint_ser")] pub amount: &'a BigInt, diff --git a/vm/actor/src/builtin/power/policy.rs b/vm/actor/src/builtin/power/policy.rs index 4886c89d3d8b..1c6d2b0aeac6 100644 --- a/vm/actor/src/builtin/power/policy.rs +++ b/vm/actor/src/builtin/power/policy.rs @@ -10,4 +10,4 @@ pub const CONSENSUS_MINER_MIN_MINERS: i64 = 3; /// given epoch to 200. /// /// To support onboarding 1EiB/year, we need to allow at least 32 prove commits per epoch. -pub const MAX_MINER_PROVE_COMMITS_PER_EPOCH: u64 = 200; +pub const MAX_MINER_PROVE_COMMITS_PER_EPOCH: usize = 200; diff --git a/vm/actor/src/builtin/power/state.rs b/vm/actor/src/builtin/power/state.rs index e7f11e77c0ee..d0c892bba76d 100644 --- a/vm/actor/src/builtin/power/state.rs +++ b/vm/actor/src/builtin/power/state.rs @@ -343,7 +343,8 @@ pub fn set_claim( claims .set(a.to_bytes().into(), claim) - .map_err(|e| e.downcast_wrap(format!("failed to set claim for address {}", a))) + .map_err(|e| e.downcast_wrap(format!("failed to set claim for address {}", a)))?; + Ok(()) } pub(super) fn epoch_key(e: ChainEpoch) -> BytesKey { @@ -353,7 +354,7 @@ pub(super) fn epoch_key(e: ChainEpoch) -> BytesKey { impl Cbor for State {} -#[derive(Debug, Serialize_tuple, Deserialize_tuple, Clone)] +#[derive(Debug, Serialize_tuple, Deserialize_tuple, Clone, PartialEq)] pub struct Claim { /// Miner's proof type used to determine minimum miner size pub seal_proof_type: RegisteredSealProof, diff --git a/vm/actor/src/util/balance_table.rs b/vm/actor/src/util/balance_table.rs index 6ca86db23908..c631ad1c6941 100644 --- a/vm/actor/src/util/balance_table.rs +++ b/vm/actor/src/util/balance_table.rs @@ -51,7 +51,8 @@ where self.0.delete(&key.to_bytes())?; Ok(()) } else { - Ok(self.0.set(key.to_bytes().into(), BigIntDe(sum))?) + self.0.set(key.to_bytes().into(), BigIntDe(sum))?; + Ok(()) } } diff --git a/vm/actor/src/util/multimap.rs b/vm/actor/src/util/multimap.rs index eb109384dd2b..6d7d4f85995b 100644 --- a/vm/actor/src/util/multimap.rs +++ b/vm/actor/src/util/multimap.rs @@ -49,7 +49,8 @@ where let new_root = arr.flush()?; // Set hamt node to array root - Ok(self.0.set(key, new_root)?) + self.0.set(key, new_root)?; + Ok(()) } /// Gets the Array of value type `V` using the multimap store. @@ -79,7 +80,7 @@ where pub fn for_each(&self, key: &[u8], f: F) -> Result<(), Box> where V: Serialize + DeserializeOwned, - F: FnMut(u64, &V) -> Result<(), Box>, + F: FnMut(usize, &V) -> Result<(), Box>, { if let Some(amt) = self.get::(key)? { amt.for_each(f)?; diff --git a/vm/actor/src/util/set.rs b/vm/actor/src/util/set.rs index fae395ca01ef..e4f806e808e1 100644 --- a/vm/actor/src/util/set.rs +++ b/vm/actor/src/util/set.rs @@ -41,7 +41,8 @@ where #[inline] pub fn put(&mut self, key: BytesKey) -> Result<(), Error> { // Set hamt node to array root - self.0.set(key, ()) + self.0.set(key, ())?; + Ok(()) } /// Checks if key exists in the set. diff --git a/vm/actor/src/util/set_multimap.rs b/vm/actor/src/util/set_multimap.rs index 4a9595d7fc26..2875988f4e31 100644 --- a/vm/actor/src/util/set_multimap.rs +++ b/vm/actor/src/util/set_multimap.rs @@ -44,7 +44,8 @@ where let new_root = set.root()?; // Set hamt node to set new root - Ok(self.0.set(u64_key(key as u64), new_root)?) + self.0.set(u64_key(key as u64), new_root)?; + Ok(()) } /// Puts slice of DealIDs in the hash set of the key. @@ -64,7 +65,8 @@ where let new_root = set.root()?; // Set hamt node to set new root - Ok(self.0.set(u64_key(key as u64), new_root)?) + self.0.set(u64_key(key as u64), new_root)?; + Ok(()) } /// Gets the set at the given index of the `SetMultimap` @@ -89,8 +91,8 @@ where // Save and calculate new root let new_root = set.root()?; - - Ok(self.0.set(u64_key(key as u64), new_root)?) + self.0.set(u64_key(key as u64), new_root)?; + Ok(()) } /// Removes set at index. diff --git a/vm/actor/tests/multimap_test.rs b/vm/actor/tests/multimap_test.rs index a7e9b0c0e3d8..f80ccb75fb60 100644 --- a/vm/actor/tests/multimap_test.rs +++ b/vm/actor/tests/multimap_test.rs @@ -34,7 +34,7 @@ fn for_each() { mm.add(addr.to_bytes().into(), 3).unwrap(); mm.add("Some other string".into(), 7).unwrap(); - let mut vals: Vec<(u64, u64)> = Vec::new(); + let mut vals: Vec<(usize, u64)> = Vec::new(); mm.for_each(&addr.to_bytes(), |i, v| { vals.push((i, *v)); Ok(()) diff --git a/vm/actor/tests/paych_actor_test.rs b/vm/actor/tests/paych_actor_test.rs index 12f5054bd0c3..f00947c23604 100644 --- a/vm/actor/tests/paych_actor_test.rs +++ b/vm/actor/tests/paych_actor_test.rs @@ -52,7 +52,7 @@ fn construct_lane_state_amt(rt: &MockRuntime, lss: Vec) -> Cid { arr.flush().unwrap() } -fn get_lane_state(rt: &MockRuntime, cid: &Cid, lane: u64) -> LaneState { +fn get_lane_state(rt: &MockRuntime, cid: &Cid, lane: usize) -> LaneState { let arr: Amt = Amt::load(cid, &rt.store).unwrap(); arr.get(lane).unwrap().unwrap().clone() @@ -287,7 +287,7 @@ mod create_lane_tests { time_lock_min: test_case.tl_min, time_lock_max: test_case.tl_max, secret_pre_image: test_case.secret_preimage.clone(), - lane: test_case.lane, + lane: test_case.lane as usize, nonce: test_case.nonce, amount: BigInt::from(test_case.amt), signature: test_case.sig.clone(), @@ -561,7 +561,7 @@ mod merge_tests { sv.lane = 0; sv.nonce = tc.voucher; sv.merges = vec![Merge { - lane: tc.lane, + lane: tc.lane as usize, nonce: tc.merge, }]; rt.set_caller(ACCOUNT_ACTOR_CODE_ID.clone(), state.from); @@ -596,7 +596,7 @@ mod merge_tests { fn lane_limit_exceeded() { let (mut rt, mut sv, _) = construct_runtime(1); - sv.lane = MAX_LANE as u64 + 1; + sv.lane = MAX_LANE as usize + 1; sv.nonce += 1; sv.amount = BigInt::from(100); failure_end(&mut rt, sv, ExitCode::ErrIllegalArgument); @@ -1009,7 +1009,7 @@ fn require_add_new_lane(rt: &mut MockRuntime, param: LaneParams) -> SignedVouche let mut sv = SignedVoucher { time_lock_min: param.epoch_num, time_lock_max: i64::MAX, - lane: param.lane, + lane: param.lane as usize, nonce: param.nonce, amount: param.amt.clone(), signature: Some(sig.clone()), @@ -1076,5 +1076,5 @@ fn verify_state(rt: &mut MockRuntime, exp_lanes: Option, expected_state: PS fn assert_lane_states_length(rt: &MockRuntime, cid: &Cid, l: u64) { let arr = Amt::::load(cid, &rt.store).unwrap(); - assert_eq!(arr.count(), l); + assert_eq!(arr.count(), l as usize); } diff --git a/vm/actor_interface/Cargo.toml b/vm/actor_interface/Cargo.toml index 0621aa8753d8..9d669a7aa1bd 100644 --- a/vm/actor_interface/Cargo.toml +++ b/vm/actor_interface/Cargo.toml @@ -21,8 +21,6 @@ forest_bitfield = "0.1" num-bigint = { version = "0.1.1", package = "forest_bigint", features = ["json"] } forest_hash_utils = "0.1" forest_json_utils = "0.1.1" -ipld_hamt = { path = "../../ipld/hamt" } -ipld_amt = { path = "../../ipld/amt", features = ["go-interop"]} [features] devnet = ["actorv0/devnet", "actorv2/devnet"] interopnet = ["actorv0/interopnet", "actorv2/interopnet"] diff --git a/vm/actor_interface/src/adt/array.rs b/vm/actor_interface/src/adt/array.rs index 16921346bed6..5ee7673838a0 100644 --- a/vm/actor_interface/src/adt/array.rs +++ b/vm/actor_interface/src/adt/array.rs @@ -10,8 +10,7 @@ use std::error::Error; pub enum Array<'a, BS, V> { V0(actorv0::ipld_amt::Amt<'a, V, BS>), V2(actorv2::ipld_amt::Amt<'a, V, BS>), - // TODO: Point this to the hamt from the actors v3 crate. - V3(ipld_amt::Amt<'a, V, BS>), + V3(actorv3::ipld_amt::Amt<'a, V, BS>), } impl<'a, BS, V> Array<'a, BS, V> @@ -23,7 +22,7 @@ where match version { ActorVersion::V0 => Array::V0(actorv0::ipld_amt::Amt::new(store)), ActorVersion::V2 => Array::V2(actorv2::ipld_amt::Amt::new(store)), - ActorVersion::V3 => Array::V3(ipld_amt::Amt::new(store)), + ActorVersion::V3 => Array::V3(actorv3::ipld_amt::Amt::new(store)), } } @@ -32,7 +31,7 @@ where match version { ActorVersion::V0 => Ok(Array::V0(actorv0::ipld_amt::Amt::load(cid, store)?)), ActorVersion::V2 => Ok(Array::V2(actorv2::ipld_amt::Amt::load(cid, store)?)), - ActorVersion::V3 => Ok(Array::V3(ipld_amt::Amt::load(cid, store)?)), + ActorVersion::V3 => Ok(Array::V3(actorv3::ipld_amt::Amt::load(cid, store)?)), } } diff --git a/vm/actor_interface/src/adt/map.rs b/vm/actor_interface/src/adt/map.rs index fe7d2ba1d836..f5e3b26d3e8f 100644 --- a/vm/actor_interface/src/adt/map.rs +++ b/vm/actor_interface/src/adt/map.rs @@ -11,8 +11,7 @@ use std::error::Error; pub enum Map<'a, BS, V> { V0(actorv0::Map<'a, BS, V>), V2(actorv2::Map<'a, BS, V>), - // TODO: Point this to the hamt from the actors v3 crate. - V3(ipld_hamt::Hamt<'a, BS, V>), + V3(actorv3::Map<'a, BS, V>), } impl<'a, BS, V> Map<'a, BS, V> @@ -24,8 +23,7 @@ where match version { ActorVersion::V0 => Map::V0(actorv0::make_map(store)), ActorVersion::V2 => Map::V2(actorv2::make_map(store)), - // TODO: Use interface from actorv3 - ActorVersion::V3 => Map::V3(ipld_hamt::Hamt::new_with_bit_width(store, 5)), + ActorVersion::V3 => Map::V3(actorv3::make_map(store)), } } @@ -34,9 +32,7 @@ where match version { ActorVersion::V0 => Ok(Map::V0(actorv0::make_map_with_root(cid, store)?)), ActorVersion::V2 => Ok(Map::V2(actorv2::make_map_with_root(cid, store)?)), - ActorVersion::V3 => Ok(Map::V3(ipld_hamt::Hamt::load_with_bit_width( - cid, store, 5, - )?)), + ActorVersion::V3 => Ok(Map::V3(actorv3::make_map_with_root(cid, store)?)), } }