Skip to content

Commit 4f329d6

Browse files
refactor: switch to anyhow from failure (#956)
refactor: switch to anyhow from failure
2 parents 144f1be + c0e71bd commit 4f329d6

40 files changed

+319
-419
lines changed

fil-proofs-tooling/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ clap = "2"
1414
serde = { version = "1.0", features = ["derive"] }
1515
serde_json = "1.0"
1616
toml = "0.5"
17-
failure = "0.1"
1817
permutate = "0.3"
1918
lazy_static = "1.2"
2019
glob = "0.3"
@@ -24,7 +23,7 @@ regex = "1.1.6"
2423
commandspec = "0.12.2"
2524
chrono = { version = "0.4.7", features = ["serde"] }
2625
memmap = "0.7.0"
27-
bellperson = "0.4.0"
26+
bellperson = "0.4.1"
2827
paired = "0.16.0"
2928
fil-sapling-crypto = "0.2.0"
3029
rand = "0.7"
@@ -40,8 +39,9 @@ blake2s_simd = "0.5.6"
4039
pretty_env_logger = "0.3.1"
4140
log = "0.4.8"
4241
uom = "0.25.0"
43-
merkletree = "0.12.2"
42+
merkletree = "0.13.0"
4443
bincode = "1.1.2"
44+
anyhow = "1.0.23"
4545

4646
[features]
4747
default = ["gpu"]

fil-proofs-tooling/src/bin/benchy/election_post.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Report {
5252
}
5353
}
5454

55-
pub fn run(sector_size: usize, window_size_nodes: usize) -> Result<(), failure::Error> {
55+
pub fn run(sector_size: usize, window_size_nodes: usize) -> anyhow::Result<()> {
5656
info!(
5757
"Benchy Election PoSt: sector-size={} - window_size={}",
5858
sector_size,

fil-proofs-tooling/src/bin/benchy/hash_fns.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use storage_proofs::crypto;
99
use storage_proofs::crypto::pedersen::JJ_PARAMS;
1010
use storage_proofs::util::{bits_to_bytes, bytes_into_boolean_vec, bytes_into_boolean_vec_be};
1111

12-
fn blake2s_count(bytes: usize) -> Result<Report, failure::Error> {
12+
fn blake2s_count(bytes: usize) -> anyhow::Result<Report> {
1313
let rng = &mut rand::thread_rng();
1414

1515
let mut cs = TestConstraintSystem::<Bls12>::new();
@@ -44,7 +44,7 @@ fn blake2s_count(bytes: usize) -> Result<Report, failure::Error> {
4444
})
4545
}
4646

47-
fn sha256_count(bytes: usize) -> Result<Report, failure::Error> {
47+
fn sha256_count(bytes: usize) -> anyhow::Result<Report> {
4848
let mut rng = rand::thread_rng();
4949

5050
let mut cs = TestConstraintSystem::<Bls12>::new();
@@ -70,7 +70,7 @@ fn sha256_count(bytes: usize) -> Result<Report, failure::Error> {
7070
})
7171
}
7272

73-
fn pedersen_count(bytes: usize) -> Result<Report, failure::Error> {
73+
fn pedersen_count(bytes: usize) -> anyhow::Result<Report> {
7474
let mut rng = rand::thread_rng();
7575

7676
let mut cs = TestConstraintSystem::<Bls12>::new();
@@ -119,7 +119,7 @@ struct Report {
119119
bytes: usize,
120120
}
121121

122-
pub fn run() -> Result<(), failure::Error> {
122+
pub fn run() -> anyhow::Result<()> {
123123
let reports = vec![
124124
blake2s_count(32)?,
125125
blake2s_count(64)?,

fil-proofs-tooling/src/bin/benchy/stacked.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::fs::{File, OpenOptions};
22
use std::time::Duration;
33
use std::{io, u32};
44

5+
use anyhow::bail;
56
use bellperson::Circuit;
67
use chrono::Utc;
7-
use failure::bail;
88
use log::info;
99
use memmap::MmapMut;
1010
use memmap::MmapOptions;
@@ -25,7 +25,7 @@ use storage_proofs::stacked::{
2525
};
2626
use tempfile::TempDir;
2727

28-
fn file_backed_mmap_from_zeroes(n: usize, use_tmp: bool) -> Result<MmapMut, failure::Error> {
28+
fn file_backed_mmap_from_zeroes(n: usize, use_tmp: bool) -> anyhow::Result<MmapMut> {
2929
let file: File = if use_tmp {
3030
tempfile::tempfile().unwrap()
3131
} else {
@@ -46,7 +46,7 @@ fn file_backed_mmap_from_zeroes(n: usize, use_tmp: bool) -> Result<MmapMut, fail
4646

4747
fn dump_proof_bytes<H: Hasher>(
4848
all_partition_proofs: &[stacked::Proof<H, Sha256Hasher>],
49-
) -> Result<(), failure::Error> {
49+
) -> anyhow::Result<()> {
5050
let file = OpenOptions::new()
5151
.write(true)
5252
.create(true)
@@ -90,10 +90,7 @@ impl From<Params> for Inputs {
9090
}
9191
}
9292

93-
fn generate_report<H: 'static>(
94-
params: Params,
95-
cache_dir: &TempDir,
96-
) -> Result<Report, failure::Error>
93+
fn generate_report<H: 'static>(params: Params, cache_dir: &TempDir) -> anyhow::Result<Report>
9794
where
9895
H: Hasher,
9996
{
@@ -220,7 +217,6 @@ where
220217
&priv_inputs,
221218
*partitions,
222219
)
223-
.map_err(|err| err.into())
224220
})?;
225221

226222
report.outputs.vanilla_proving_wall_time_us =
@@ -296,7 +292,6 @@ where
296292
&data,
297293
Some(store_config.clone()),
298294
)
299-
.map_err(|err| err.into())
300295
})?;
301296

302297
assert_ne!(&(*data), m.return_value.as_slice());
@@ -331,7 +326,7 @@ fn do_circuit_work<H: 'static + Hasher>(
331326
priv_in: Option<<StackedDrg<H, Sha256Hasher> as ProofScheme>::PrivateInputs>,
332327
params: &Params,
333328
report: &mut Report,
334-
) -> Result<CircuitWorkMeasurement, failure::Error> {
329+
) -> anyhow::Result<CircuitWorkMeasurement> {
335330
let mut proving_wall_time = Duration::new(0, 0);
336331
let mut proving_cpu_time = Duration::new(0, 0);
337332

@@ -382,7 +377,6 @@ fn do_circuit_work<H: 'static + Hasher>(
382377
return_value,
383378
} = measure(|| {
384379
StackedCompound::prove(&compound_public_params, &pub_inputs, &priv_inputs, &gparams)
385-
.map_err(|err| err.into())
386380
})?;
387381
proving_wall_time += wall_time;
388382
proving_cpu_time += cpu_time;
@@ -405,7 +399,6 @@ fn do_circuit_work<H: 'static + Hasher>(
405399
minimum_challenges: 1,
406400
},
407401
)
408-
.map_err(|err| err.into())
409402
})?;
410403

411404
// If one verification fails, result becomes permanently false.
@@ -503,7 +496,7 @@ pub struct RunOpts {
503496
pub size: usize,
504497
}
505498

506-
pub fn run(opts: RunOpts) -> Result<(), failure::Error> {
499+
pub fn run(opts: RunOpts) -> anyhow::Result<()> {
507500
let config = StackedConfig::new(opts.layers, opts.window_challenges, opts.wrapper_challenges);
508501

509502
let params = Params {

fil-proofs-tooling/src/bin/micro.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#[macro_use]
22
extern crate commandspec;
33
#[macro_use]
4-
extern crate failure;
4+
extern crate anyhow;
55
#[macro_use]
66
extern crate serde;
77

8-
use regex::Regex;
98
use std::io::{self, BufRead};
109

10+
use anyhow::Result;
1111
use fil_proofs_tooling::metadata::Metadata;
12+
use regex::Regex;
1213

1314
#[derive(Debug, Default, Clone, PartialEq, Serialize)]
1415
#[serde(rename_all = "kebab-case")]
@@ -47,7 +48,7 @@ fn make_detail_re(name: &str) -> Regex {
4748
}
4849

4950
/// Parses the output of `cargo bench -p storage-proofs --bench <benchmark> -- --verbose --colors never`.
50-
fn parse_criterion_out(s: impl AsRef<str>) -> Result<Vec<CriterionResult>, failure::Error> {
51+
fn parse_criterion_out(s: impl AsRef<str>) -> Result<Vec<CriterionResult>> {
5152
let mut res = Vec::new();
5253

5354
let start_re = Regex::new(r"^Benchmarking ([^:]+)$").expect("invalid regex");
@@ -258,7 +259,7 @@ fn time_to_us(s: &str) -> f64 {
258259
(normalized * 10000.0).round() / 10000.0
259260
}
260261

261-
fn run_benches(mut args: Vec<String>) -> Result<(), failure::Error> {
262+
fn run_benches(mut args: Vec<String>) -> Result<()> {
262263
let is_verbose = if let Some(index) = args.iter().position(|a| a.as_str() == "--verbose") {
263264
args.remove(index);
264265
true
@@ -271,7 +272,8 @@ fn run_benches(mut args: Vec<String>) -> Result<(), failure::Error> {
271272
cargo bench -p storage-proofs {args} -- --verbose --color never
272273
",
273274
args = args
274-
)?;
275+
)
276+
.map_err(|err| anyhow!("{:?}", err))?;
275277

276278
let process = cmd.stdout(std::process::Stdio::piped()).spawn()?;
277279

fil-proofs-tooling/src/measure.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::time::{Duration, Instant};
22

3+
use anyhow::Result;
34
use cpu_time::ProcessTime;
45

56
pub struct FuncMeasurement<T> {
@@ -8,9 +9,9 @@ pub struct FuncMeasurement<T> {
89
pub return_value: T,
910
}
1011

11-
pub fn measure<T, F>(f: F) -> Result<FuncMeasurement<T>, failure::Error>
12+
pub fn measure<T, F>(f: F) -> Result<FuncMeasurement<T>>
1213
where
13-
F: FnOnce() -> Result<T, failure::Error>,
14+
F: FnOnce() -> Result<T>,
1415
{
1516
let cpu_time_start = ProcessTime::now();
1617
let wall_start_time = Instant::now();

fil-proofs-tooling/src/metadata.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use anyhow::{anyhow, Result};
12
use chrono::{DateTime, TimeZone, Utc};
2-
use failure::Error;
33
use git2::Repository;
44
use serde::Serialize;
55

@@ -13,7 +13,7 @@ pub struct Metadata<T> {
1313
}
1414

1515
impl<T> Metadata<T> {
16-
pub fn wrap(benchmarks: T) -> Result<Self, failure::Error> {
16+
pub fn wrap(benchmarks: T) -> Result<Self> {
1717
Ok(Metadata {
1818
git: GitMetadata::new()?,
1919
system: SystemMetadata::new()?,
@@ -31,7 +31,7 @@ pub struct GitMetadata {
3131
}
3232

3333
impl GitMetadata {
34-
pub fn new() -> Result<Self, Error> {
34+
pub fn new() -> Result<Self> {
3535
let repo_path = if let Ok(mdir) = std::env::var("CARGO_MANIFEST_DIR") {
3636
std::path::Path::new(&mdir).into()
3737
} else {
@@ -66,19 +66,17 @@ pub struct SystemMetadata {
6666
}
6767

6868
impl SystemMetadata {
69-
pub fn new() -> Result<Self, Error> {
69+
pub fn new() -> Result<Self> {
7070
let host = futures::executor::block_on(heim::host::platform())
71-
.map_err(|_| failure::format_err!("Failed to retrieve host information"))?;
71+
.map_err(|_| anyhow!("Failed to retrieve host information"))?;
7272

7373
let memory = futures::executor::block_on(heim::memory::memory())
74-
.map_err(|_| failure::format_err!("Failed to retrieve memory information"))?;
75-
let cpu_logical =
76-
futures::executor::block_on(heim::cpu::logical_count()).map_err(|_| {
77-
failure::format_err!("Failed to retrieve cpu logical count information")
78-
})?;
74+
.map_err(|_| anyhow!("Failed to retrieve memory information"))?;
75+
let cpu_logical = futures::executor::block_on(heim::cpu::logical_count())
76+
.map_err(|_| anyhow!("Failed to retrieve cpu logical count information"))?;
77+
7978
let cpu_physical = futures::executor::block_on(heim::cpu::physical_count())
80-
.map_err(|_| failure::format_err!("Failed to retrieve cpu physical count information"))?
81-
.unwrap_or_default();
79+
.map_err(|_| anyhow!("Failed to retrieve cpu physical count information"))?;
8280

8381
let cpuid = raw_cpuid::CpuId::new();
8482
let processor = cpuid
@@ -108,7 +106,7 @@ impl SystemMetadata {
108106
.map(|info| format!("{:?}", info))
109107
.unwrap_or_default(),
110108
processor_cores_logical: cpu_logical,
111-
processor_cores_physical: cpu_physical,
109+
processor_cores_physical: cpu_physical.unwrap_or_default(),
112110
memory_total_bytes: memory.total().get::<uom::si::information::byte>(),
113111
})
114112
}

filecoin-proofs/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ storage-proofs = { version = "^0.6", path = "../storage-proofs" }
1313
bitvec = "0.5"
1414
chrono = "0.4"
1515
rand = "0.7"
16-
failure = "0.1"
1716
lazy_static = "1.2"
1817
memmap = "0.7"
1918
colored = "1.6"
@@ -27,7 +26,7 @@ serde_json = "1.0"
2726
regex = "1"
2827
ff = "0.5.0"
2928
blake2b_simd = "0.5"
30-
bellperson = "0.4.0"
29+
bellperson = "0.4.1"
3130
paired = "0.16.0"
3231
fil-sapling-crypto = "0.2.0"
3332
clap = "2"
@@ -42,8 +41,9 @@ blake2s_simd = "0.5.8"
4241
hex = "0.4.0"
4342
tee = "0.1.0"
4443
os_pipe = "0.9.1"
45-
merkletree = "0.12.2"
44+
merkletree = "0.13.0"
4645
bincode = "1.1.2"
46+
anyhow = "1.0.23"
4747

4848
[dependencies.reqwest]
4949
version = "0.9"
@@ -57,6 +57,7 @@ rexpect = "0.3.0"
5757
pretty_env_logger = "0.3.1"
5858
pretty_assertions = "0.6.1"
5959
rand_xorshift = "0.2.0"
60+
failure = "0.1"
6061

6162
[features]
6263
default = ["gpu"]

filecoin-proofs/src/api/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::fs::File;
22
use std::io::{BufWriter, Read, Seek, SeekFrom, Write};
33
use std::path::{Path, PathBuf};
44

5+
use anyhow::Result;
56
use merkletree::store::{StoreConfig, DEFAULT_CACHED_ABOVE_BASE_LAYER};
67
use storage_proofs::drgraph::DefaultTreeHasher;
78
use storage_proofs::hasher::Hasher;
@@ -14,7 +15,6 @@ use crate::constants::{
1415
DefaultPieceHasher,
1516
MINIMUM_RESERVED_BYTES_FOR_PIECE_IN_FULLY_ALIGNED_SECTOR as MINIMUM_PIECE_SIZE,
1617
};
17-
use crate::error;
1818
use crate::fr32::{write_padded, write_unpadded};
1919
use crate::parameters::public_params;
2020
use crate::pieces::get_aligned_source;
@@ -48,7 +48,7 @@ pub fn get_unsealed_range<T: Into<PathBuf> + AsRef<Path>>(
4848
ticket: Ticket,
4949
offset: UnpaddedByteIndex,
5050
num_bytes: UnpaddedBytesAmount,
51-
) -> error::Result<UnpaddedBytesAmount> {
51+
) -> Result<UnpaddedBytesAmount> {
5252
let comm_d =
5353
as_safe_commitment::<<DefaultPieceHasher as Hasher>::Domain, _>(&comm_d, "comm_d")?;
5454

@@ -95,7 +95,7 @@ pub fn get_unsealed_range<T: Into<PathBuf> + AsRef<Path>>(
9595
pub fn generate_piece_commitment<T: std::io::Read>(
9696
source: T,
9797
piece_size: UnpaddedBytesAmount,
98-
) -> error::Result<PieceInfo> {
98+
) -> Result<PieceInfo> {
9999
ensure_piece_size(piece_size)?;
100100

101101
let mut temp_piece_file = tempfile()?;
@@ -148,7 +148,7 @@ pub fn add_piece<R, W>(
148148
target: W,
149149
piece_size: UnpaddedBytesAmount,
150150
piece_lengths: &[UnpaddedBytesAmount],
151-
) -> error::Result<(UnpaddedBytesAmount, Commitment)>
151+
) -> Result<(UnpaddedBytesAmount, Commitment)>
152152
where
153153
R: Read,
154154
W: Read + Write + Seek,
@@ -233,7 +233,7 @@ where
233233
}
234234
}
235235

236-
fn ensure_piece_size(piece_size: UnpaddedBytesAmount) -> error::Result<()> {
236+
fn ensure_piece_size(piece_size: UnpaddedBytesAmount) -> Result<()> {
237237
ensure!(
238238
piece_size >= UnpaddedBytesAmount(MINIMUM_PIECE_SIZE),
239239
"Piece must be at least {} bytes",
@@ -262,7 +262,7 @@ pub fn write_and_preprocess<R, W>(
262262
source: R,
263263
target: W,
264264
piece_size: UnpaddedBytesAmount,
265-
) -> error::Result<(UnpaddedBytesAmount, Commitment)>
265+
) -> Result<(UnpaddedBytesAmount, Commitment)>
266266
where
267267
R: Read,
268268
W: Read + Write + Seek,
@@ -407,7 +407,7 @@ mod tests {
407407

408408
#[test]
409409
#[ignore]
410-
fn test_seal_lifecycle() -> Result<(), failure::Error> {
410+
fn test_seal_lifecycle() -> Result<()> {
411411
pretty_env_logger::try_init().ok();
412412

413413
let rng = &mut XorShiftRng::from_seed(crate::TEST_SEED);

0 commit comments

Comments
 (0)