Skip to content

Commit

Permalink
chore: update rust version to 1.78 and fix lints
Browse files Browse the repository at this point in the history
This updates us to 1.78, the version the FVM is currently tested against.
  • Loading branch information
Stebalien committed Oct 21, 2024
1 parent 815fb3a commit 6365100
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 40 deletions.
2 changes: 1 addition & 1 deletion rust/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.73.0"
channel = "1.78.0"
components = ["clippy", "rustfmt"]
1 change: 1 addition & 0 deletions rust/src/bls/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub type BLSDigest = [u8; DIGEST_BYTES];
/// Unwraps or returns the passed in value.
macro_rules! try_ffi {
($res:expr, $val:expr) => {{
#[allow(clippy::blocks_in_conditions)]
match $res {
Ok(res) => res,
Err(_) => return $val,
Expand Down
15 changes: 3 additions & 12 deletions rust/src/fvm/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ impl MultiEngineContainer {

// fvm v4 implementation
mod v4 {
use anyhow::anyhow;
use cid::Cid;
use std::sync::Mutex;

Expand Down Expand Up @@ -158,11 +157,7 @@ mod v4 {
blockstore: CgoBlockstore,
externs: CgoExterns,
) -> anyhow::Result<InnerFvmMachine> {
let mut network_config = NetworkConfig::new(
cfg.network_version
.try_into()
.map_err(|nv| anyhow!("network version {nv} not supported"))?,
);
let mut network_config = NetworkConfig::new(cfg.network_version.into());
network_config.chain_id(ChainID::from(cfg.chain_id));

if cfg.actor_debugging {
Expand Down Expand Up @@ -194,7 +189,7 @@ mod v4 {

// fvm v3 implementation
mod v3 {
use anyhow::{anyhow, Context};
use anyhow::Context;
use cid::Cid;
use fvm4_shared::event::{self, ActorEvent, Entry, StampedEvent};
use num_traits::FromPrimitive;
Expand Down Expand Up @@ -434,11 +429,7 @@ mod v3 {
blockstore: CgoBlockstore,
externs: CgoExterns,
) -> anyhow::Result<InnerFvmMachine> {
let mut network_config = NetworkConfig3::new(
cfg.network_version
.try_into()
.map_err(|nv| anyhow!("network version {nv} not supported"))?,
);
let mut network_config = NetworkConfig3::new(cfg.network_version.into());
network_config.chain_id(ChainID3::from(cfg.chain_id));

if cfg.actor_debugging {
Expand Down
2 changes: 1 addition & 1 deletion rust/src/fvm/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ mod test {

assert_eq!(lotus_trace.gas_charges.len(), 1);
assert_eq!(
*lotus_trace.gas_charges.get(0).unwrap(),
*lotus_trace.gas_charges.first().unwrap(),
LotusGasCharge {
name: initial_gas_charge.clone().name,
total_gas: initial_gas_charge.total().round_up(),
Expand Down
1 change: 0 additions & 1 deletion rust/src/fvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod externs;

pub mod engine;
pub mod machine;
#[allow(clippy::incorrect_clone_impl_on_copy_type)]
pub mod types;

pub use cgo::FvmError;
2 changes: 2 additions & 0 deletions rust/src/fvm/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::non_canonical_clone_impl)]

use std::sync::Mutex;

use safer_ffi::prelude::*;
Expand Down
36 changes: 16 additions & 20 deletions rust/src/proofs/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,6 @@ pub mod tests {
let f_new_sealed_sector = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(&new_sealed_path)?;
f_new_sealed_sector.set_len(new_sealed_target_len)?;

Expand Down Expand Up @@ -2185,7 +2184,6 @@ pub mod tests {
let f_decoded_sector = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(&decoded_path)?;
f_decoded_sector.set_len(new_sealed_target_len)?;

Expand All @@ -2212,7 +2210,6 @@ pub mod tests {
let f_removed_data_sector = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(&removed_data_path)?;
f_removed_data_sector.set_len(new_sealed_target_len)?;

Expand Down Expand Up @@ -2352,7 +2349,7 @@ pub mod tests {
panic!("generate_candidates produced no results");
}

let private_replicas = vec![PrivateReplicaInfo {
let private_replicas = [PrivateReplicaInfo {
registered_proof: registered_proof_winning_post,
cache_dir_path: cache_dir_path_ref.to_vec().into_boxed_slice().into(),
comm_r: resp_b2.comm_r,
Expand All @@ -2369,12 +2366,11 @@ pub mod tests {
let msg = str::from_utf8(&resp_h.error_msg).unwrap();
panic!("generate_winning_post failed: {:?}", msg);
}
let public_replicas = vec![PublicReplicaInfo {
let public_replicas = [PublicReplicaInfo {
registered_proof: registered_proof_winning_post,
sector_id,
comm_r: resp_b2.comm_r,
}]
.into_boxed_slice();
}];

let resp_i = verify_winning_post(
&randomness,
Expand Down Expand Up @@ -2475,7 +2471,7 @@ pub mod tests {

// window post

let private_replicas = vec![PrivateReplicaInfo {
let private_replicas = [PrivateReplicaInfo {
registered_proof: registered_proof_window_post,
cache_dir_path: cache_dir_path_ref.to_vec().into_boxed_slice().into(),
comm_r: resp_b2.comm_r,
Expand All @@ -2490,7 +2486,7 @@ pub mod tests {
panic!("generate_window_post failed: {:?}", msg);
}

let public_replicas = vec![PublicReplicaInfo {
let public_replicas = [PublicReplicaInfo {
registered_proof: registered_proof_window_post,
sector_id,
comm_r: resp_b2.comm_r,
Expand All @@ -2514,7 +2510,7 @@ pub mod tests {

// Generate a legacy WindowPoSt for later use.
let legacy_registered_proof_window_post = RegisteredPoStProof::StackedDrgWindow2KiBV1;
let legacy_private_replicas = vec![PrivateReplicaInfo {
let legacy_private_replicas = [PrivateReplicaInfo {
registered_proof: legacy_registered_proof_window_post,
cache_dir_path: cache_dir_path_ref.to_vec().into_boxed_slice().into(),
comm_r: resp_b2.comm_r,
Expand All @@ -2530,7 +2526,7 @@ pub mod tests {
panic!("generate_window_post failed: {:?}", msg);
}

let public_replicas = vec![PublicReplicaInfo {
let public_replicas = [PublicReplicaInfo {
registered_proof: legacy_registered_proof_window_post, // legacy registered proofs type
sector_id,
comm_r: resp_b2.comm_r,
Expand All @@ -2554,7 +2550,7 @@ pub mod tests {

// Lastly ensure that the legacy WindowPoSt generated proof
// does not verify with the new proof version
let public_replicas = vec![PublicReplicaInfo {
let public_replicas = [PublicReplicaInfo {
registered_proof: registered_proof_window_post, // new registered proof type/version
sector_id,
comm_r: resp_b2.comm_r,
Expand Down Expand Up @@ -2585,7 +2581,7 @@ pub mod tests {
//////////////////////////////////////////////

let sectors = [sector_id, sector_id2];
let private_replicas = vec![
let private_replicas = [
PrivateReplicaInfo {
registered_proof: registered_proof_window_post,
cache_dir_path: cache_dir_path_ref.to_vec().into_boxed_slice().into(),
Expand All @@ -2601,7 +2597,7 @@ pub mod tests {
sector_id: sector_id2,
},
];
let public_replicas = vec![
let public_replicas = [
PublicReplicaInfo {
registered_proof: registered_proof_window_post,
sector_id,
Expand Down Expand Up @@ -2764,7 +2760,7 @@ pub mod tests {
let resp_k3 = verify_window_post(
&randomness,
public_replicas[..].into(),
vec![merged_proof_resp.value.clone()][..].into(),
[merged_proof_resp.value.clone()][..].into(),
&prover_id,
);

Expand Down Expand Up @@ -2909,7 +2905,7 @@ pub mod tests {
panic!("write_with_alignment failed: {:?}", msg);
}

let pieces = vec![
let pieces = [
PublicPieceInfo {
num_bytes: 127,
comm_p: resp_a1.comm_p,
Expand Down Expand Up @@ -2959,7 +2955,7 @@ pub mod tests {
let faulty_sealed_file = tempfile::NamedTempFile::new()?;
let faulty_sealed_path_ref = as_bytes(faulty_sealed_file.path());

let private_replicas = vec![PrivateReplicaInfo {
let private_replicas = [PrivateReplicaInfo {
registered_proof: registered_proof_window_post,
cache_dir_path: cache_dir_path_ref.to_vec().into_boxed_slice().into(),
comm_r: resp_b2.comm_r,
Expand Down Expand Up @@ -3002,7 +2998,7 @@ pub mod tests {
#[test]
#[ignore]
fn test_sealing_aggregation_versions() -> Result<()> {
let versions = vec![
let versions = [
(
RegisteredSealProof::StackedDrg2KiBV1,
RegisteredAggregationProof::SnarkPackV1,
Expand Down Expand Up @@ -3098,7 +3094,7 @@ pub mod tests {
panic!("write_with_alignment failed: {:?}", msg);
}

let pieces = vec![
let pieces = [
PublicPieceInfo {
num_bytes: 127,
comm_p: resp_a1.comm_p,
Expand Down Expand Up @@ -3239,7 +3235,7 @@ pub mod tests {
);
}

let inputs: Vec<AggregationInputs> = vec![
let inputs = [
AggregationInputs {
comm_r: resp_b2.comm_r,
comm_d: resp_b2.comm_d,
Expand Down
10 changes: 5 additions & 5 deletions rust/src/util/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,15 @@ where
T: Sized,
F: FnOnce() -> anyhow::Result<T> + std::panic::UnwindSafe,
{
let result = match panic::catch_unwind(|| {
let result = panic::catch_unwind(|| {
init_log();
log::debug!("{}: start", name);
let res = callback();
log::debug!("{}: end", name);
res
}) {
});

repr_c::Box::new(match result {
Ok(t) => match t {
Ok(t) => Result::ok(t),
Err(err) => Result::err_no_default(format!("{err:?}").into_bytes().into_boxed_slice()),
Expand All @@ -233,9 +235,7 @@ where
.into_boxed_slice(),
)
}
};

repr_c::Box::new(result)
})
}

/// Generate a destructor for the given type wrapped in a `repr_c::Box`.
Expand Down

0 comments on commit 6365100

Please sign in to comment.