Skip to content

Commit 52fb779

Browse files
cleanup and clippy
1 parent 88a7fe5 commit 52fb779

File tree

13 files changed

+40
-143
lines changed

13 files changed

+40
-143
lines changed

actors/market/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -981,8 +981,7 @@ where
981981
illegal_argument,
982982
"deal id {} present multiple times",
983983
deal_id
984-
)
985-
.into());
984+
));
986985
}
987986
let proposal = proposals
988987
.get(*deal_id)?

actors/market/src/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ where
565565
lock_reason: Reason,
566566
) -> Result<(), ActorError> {
567567
if amount.is_negative() {
568-
return Err(actor_error!(illegal_state, "unlock negative amount: {}", amount).into());
568+
return Err(actor_error!(illegal_state, "unlock negative amount: {}", amount));
569569
}
570570
self.locked_table.as_mut().unwrap().must_subtract(addr, amount)?;
571571

@@ -618,7 +618,7 @@ where
618618
lock_reason: Reason,
619619
) -> Result<(), ActorError> {
620620
if amount.is_negative() {
621-
return Err(actor_error!(illegal_state, "negative amount to slash: {}", amount).into());
621+
return Err(actor_error!(illegal_state, "negative amount to slash: {}", amount));
622622
}
623623

624624
// Subtract from locked and escrow tables

actors/miner/src/bitfield_queue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::convert::TryInto;
55

66
use cid::Cid;
7-
use fil_actors_runtime::{ActorContext, ActorDowncast, ActorError, Array};
7+
use fil_actors_runtime::{ActorContext, ActorError, Array};
88
use fvm_ipld_amt::Error as AmtError;
99
use fvm_ipld_bitfield::BitField;
1010
use fvm_ipld_blockstore::Blockstore;
@@ -39,13 +39,13 @@ impl<'db, BS: Blockstore> BitFieldQueue<'db, BS> {
3939
let bitfield = self
4040
.amt
4141
.get(epoch)
42-
.map_err(|e| e.downcast_wrap(format!("failed to lookup queue epoch {}", epoch)))?
42+
.with_context(|| format!("failed to lookup queue epoch {}", epoch))?
4343
.cloned()
4444
.unwrap_or_default();
4545

4646
self.amt
4747
.set(epoch, &bitfield | values)
48-
.map_err(|e| e.downcast_wrap(format!("failed to set queue epoch {}", epoch)))?;
48+
.with_context(|| format!("failed to set queue epoch {}", epoch))?;
4949

5050
Ok(())
5151
}

actors/miner/src/deadline_state.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl Deadline {
614614
if let Some(&max_partition) = to_remove_set.iter().max() {
615615
if max_partition > partition_count {
616616
return Err(
617-
actor_error!(illegal_argument; "partition index {} out of range [0, {})", max_partition, partition_count).into()
617+
actor_error!(illegal_argument; "partition index {} out of range [0, {})", max_partition, partition_count),
618618
);
619619
}
620620
} else {
@@ -625,7 +625,7 @@ impl Deadline {
625625
// Should already be checked earlier, but we might as well check again.
626626
if !self.early_terminations.is_empty() {
627627
return Err(
628-
actor_error!(illegal_argument; "cannot remove partitions from deadline with early terminations").into(),
628+
actor_error!(illegal_argument; "cannot remove partitions from deadline with early terminations"),
629629
);
630630
}
631631

@@ -663,8 +663,7 @@ impl Deadline {
663663
illegal_argument,
664664
"cannot remove partition {}: has unproven sectors",
665665
partition_idx
666-
)
667-
.into());
666+
));
668667
}
669668

670669
// Get the live sectors.

actors/miner/src/partition_state.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl Partition {
484484
})?;
485485

486486
if !live_sectors.contains_all(sector_numbers) {
487-
return Err(actor_error!(illegal_argument, "can only terminate live sectors").into());
487+
return Err(actor_error!(illegal_argument, "can only terminate live sectors"));
488488
}
489489

490490
let sector_infos = sectors.load_sector(sector_numbers)?;
@@ -733,8 +733,7 @@ impl Partition {
733733
return Err(actor_error!(
734734
illegal_argument,
735735
"skipped faults contains sectors outside partition"
736-
)
737-
.into());
736+
));
738737
}
739738

740739
// Find all skipped faults that have been labeled recovered

actors/miner/src/sectors.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
use std::collections::BTreeSet;
55

66
use cid::Cid;
7-
use fil_actors_runtime::{actor_error, ActorDowncast, ActorError, Array};
7+
use fil_actors_runtime::{actor_error, ActorContext, ActorError, Array};
88
use fvm_ipld_amt::Error as AmtError;
99
use fvm_ipld_bitfield::BitField;
1010
use fvm_ipld_blockstore::Blockstore;
11-
use fvm_shared::error::ExitCode;
1211
use fvm_shared::sector::{SectorNumber, MAX_SECTOR_NUMBER};
1312

1413
use super::SectorOnChainInfo;
@@ -36,12 +35,7 @@ impl<'db, BS: Blockstore> Sectors<'db, BS> {
3635
let sector_on_chain = self
3736
.amt
3837
.get(sector_number)
39-
.map_err(|e| {
40-
e.downcast_default(
41-
ExitCode::USR_ILLEGAL_STATE,
42-
format!("failed to load sector {}", sector_number),
43-
)
44-
})?
38+
.with_context(|| format!("failed to load sector {}", sector_number))?
4539
.cloned()
4640
.ok_or_else(|| actor_error!(not_found; "sector not found: {}", sector_number))?;
4741
sector_infos.push(sector_on_chain);
@@ -56,7 +50,7 @@ impl<'db, BS: Blockstore> Sectors<'db, BS> {
5650
Ok(self
5751
.amt
5852
.get(sector_number)
59-
.map_err(|e| e.downcast_wrap(format!("failed to get sector {}", sector_number)))?
53+
.with_context(|| format!("failed to get sector {}", sector_number))?
6054
.cloned())
6155
}
6256

@@ -72,9 +66,9 @@ impl<'db, BS: Blockstore> Sectors<'db, BS> {
7266
));
7367
}
7468

75-
self.amt.set(sector_number, info).map_err(|e| {
76-
e.downcast_wrap(format!("failed to store sector {}", sector_number))
77-
})?;
69+
self.amt
70+
.set(sector_number, info)
71+
.with_context(|| format!("failed to store sector {}", sector_number))?;
7872
}
7973

8074
Ok(())

actors/miner/src/state.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,7 @@ impl State {
620620
not_found;
621621
"sector {} not a member of partition {}, deadline {}",
622622
sector_number, partition_idx, deadline_idx
623-
)
624-
.into());
623+
));
625624
}
626625

627626
let faulty = partition.faults.get(sector_number);
@@ -660,26 +659,23 @@ impl State {
660659
not_found;
661660
"sector {} not a member of partition {}, deadline {}",
662661
sector_number, partition_idx, deadline_idx
663-
)
664-
.into());
662+
));
665663
}
666664

667665
if partition.faults.get(sector_number) {
668666
return Err(actor_error!(
669667
forbidden;
670668
"sector {} not a member of partition {}, deadline {}",
671669
sector_number, partition_idx, deadline_idx
672-
)
673-
.into());
670+
));
674671
}
675672

676673
if partition.terminated.get(sector_number) {
677674
return Err(actor_error!(
678675
not_found;
679676
"sector {} not of partition {}, deadline {} is terminated",
680677
sector_number, partition_idx, deadline_idx
681-
)
682-
.into());
678+
));
683679
}
684680

685681
Ok(())
@@ -691,7 +687,7 @@ impl State {
691687
store: &BS,
692688
sectors: &BitField,
693689
) -> Result<Vec<SectorOnChainInfo>, ActorError> {
694-
Ok(Sectors::load(store, &self.sectors)?.load_sector(sectors)?)
690+
Sectors::load(store, &self.sectors)?.load_sector(sectors)
695691
}
696692

697693
pub fn load_deadlines<BS: Blockstore>(&self, store: &BS) -> Result<Deadlines, ActorError> {
@@ -717,12 +713,12 @@ impl State {
717713
&self,
718714
store: &BS,
719715
) -> Result<VestingFunds, ActorError> {
720-
Ok(store
716+
store
721717
.get_cbor(&self.vesting_funds)
722718
.with_context(|| format!("failed to load vesting funds {}", self.vesting_funds))?
723719
.ok_or_else(
724720
|| actor_error!(not_found; "failed to load vesting funds {:?}", self.vesting_funds),
725-
)?)
721+
)
726722
}
727723

728724
/// Saves the vesting table to the store.
@@ -868,8 +864,7 @@ impl State {
868864
"unlocked balance can not repay fee debt ({} < {})",
869865
unlocked_balance,
870866
self.fee_debt
871-
)
872-
.into());
867+
));
873868
}
874869

875870
Ok(std::mem::take(&mut self.fee_debt))
@@ -1175,9 +1170,7 @@ impl State {
11751170
make_map_with_root_and_bitwidth(&self.pre_committed_sectors, store, HAMT_BIT_WIDTH)?;
11761171
for sector_no in sector_nos.iter() {
11771172
if sector_no as u64 > MAX_SECTOR_NUMBER {
1178-
return Err(
1179-
actor_error!(illegal_argument; "sector number greater than maximum").into()
1180-
);
1173+
return Err(actor_error!(illegal_argument; "sector number greater than maximum"));
11811174
}
11821175
let info: &SectorPreCommitOnChainInfo =
11831176
precommitted

actors/runtime/src/actor_error.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use std::{fmt::Display, num::TryFromIntError};
33
use fvm_shared::error::ExitCode;
44
use thiserror::Error;
55

6-
use crate::ActorDowncast;
7-
86
/// The error type returned by actor method calls.
97
#[derive(Error, Debug, Clone, PartialEq)]
108
#[error("ActorError(exit_code: {exit_code:?}, msg: {msg})")]
@@ -232,7 +230,12 @@ impl<T, E: Into<ActorError>> ActorContext<T> for Result<T, E> {
232230
// TODO: remove once the runtime doesn't use anyhow::Result anymore
233231
impl From<anyhow::Error> for ActorError {
234232
fn from(e: anyhow::Error) -> Self {
235-
// THIS DEFAULT IS WRONG, it is just a placeholder
236-
e.downcast_default(ExitCode::USR_ILLEGAL_ARGUMENT, "runtime error")
233+
match e.downcast::<ActorError>() {
234+
Ok(actor_err) => actor_err,
235+
Err(other) => ActorError::unchecked(
236+
ExitCode::USR_ILLEGAL_ARGUMENT,
237+
format!("runtime error: {}", other),
238+
),
239+
}
237240
}
238241
}

actors/runtime/src/runtime/actor_blockstore.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ impl fvm_ipld_blockstore::Blockstore for ActorBlockstore {
1919

2020
fn get(&self, cid: &Cid) -> Result<Option<Vec<u8>>, Self::Error> {
2121
// If this fails, the _CID_ is invalid. I.e., we have a bug.
22-
fvm::ipld::get(cid).map(Some).map_err(|c| {
23-
actor_error!(illegal_state; "get failed with {:?} on CID '{}'", c, cid).into()
24-
})
22+
fvm::ipld::get(cid)
23+
.map(Some)
24+
.map_err(|c| actor_error!(illegal_state; "get failed with {:?} on CID '{}'", c, cid))
2525
}
2626

2727
fn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<(), Self::Error> {
2828
let code = Code::try_from(k.hash().code())
2929
.map_err(|e| actor_error!(serialization, e.to_string()))?;
3030
let k2 = self.put(code, &Block::new(k.codec(), block))?;
3131
if k != &k2 {
32-
Err(actor_error!(serialization; "put block with cid {} but has cid {}", k, k2).into())
32+
Err(actor_error!(serialization; "put block with cid {} but has cid {}", k, k2))
3333
} else {
3434
Ok(())
3535
}

actors/runtime/src/util/downcast.rs

-88
This file was deleted.

actors/runtime/src/util/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// Copyright 2019-2022 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4-
pub use self::downcast::*;
54
pub use self::multimap::{EitherError as MultiMapEitherError, Error as MultiMapError, Multimap};
65
pub use self::set::Set;
76
pub use self::set_multimap::SetMultimap;
87

98
pub mod cbor;
109
pub mod chaos;
11-
mod downcast;
1210
mod multimap;
1311
mod set;
1412
mod set_multimap;

actors/runtime/src/util/set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ where
7474
// Calls the for each function on the hamt with ignoring the value
7575
self.0.try_for_each(|s, _: &()| f(s)).map_err(|err| match err {
7676
fvm_ipld_hamt::EitherError::User(e) => e,
77-
fvm_ipld_hamt::EitherError::Hamt(e) => e.into(),
77+
fvm_ipld_hamt::EitherError::Hamt(e) => e,
7878
})
7979
}
8080

0 commit comments

Comments
 (0)