Skip to content

Commit

Permalink
chore: update rust and fix clippy lints (#1992)
Browse files Browse the repository at this point in the history
Needed to upgrade wasmtime, and now's a reasonable time to do this.
  • Loading branch information
Stebalien authored Feb 12, 2024
1 parent fce783a commit 9abb85b
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 48 deletions.
4 changes: 3 additions & 1 deletion fvm/src/blockstore/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ fn take_reachable(cache: &mut HashMap<Cid, Vec<u8>>, root: &Cid) -> Result<Vec<(
//
// The alternative would be to check if it's in the datastore, but that's likely even more
// expensive. And there wouldn't be much we could do at that point but abort the block.
let Some(block) = cache.remove(&k) else { continue };
let Some(block) = cache.remove(&k) else {
continue;
};

// At the moment, only DAG_CBOR can link to other blocks.
if k.codec() == DAG_CBOR {
Expand Down
2 changes: 1 addition & 1 deletion ipld/amt/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ where
match self {
Node::Link { links } => {
// Check if first index is a link and all other values are empty.
links.get(0).and_then(|l| l.as_ref()).is_some()
links.first().and_then(|l| l.as_ref()).is_some()
&& links
.get(1..)
.map(|l| l.iter().all(|l| l.is_none()))
Expand Down
1 change: 1 addition & 0 deletions ipld/bitfield/src/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub(crate) fn ranges_from_bits(bits: impl IntoIterator<Item = u64>) -> impl Rang
}

#[cfg(test)]
#[allow(clippy::single_range_in_vec_init)]
mod tests {
use super::*;

Expand Down
1 change: 0 additions & 1 deletion ipld/hamt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use serde::{Deserialize, Serialize};

pub use self::error::Error;
pub use self::hamt::{Hamt, Hamtv0};
pub use self::hash::*;
pub use self::hash_algorithm::*;
pub use self::iter::{Iter, Iterv0};

Expand Down
4 changes: 3 additions & 1 deletion ipld/hamt/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ where
)));
}
if !kvs.windows(2).all(|window| {
let [a, b] = window else { panic!("invalid window length") };
let [a, b] = window else {
panic!("invalid window length")
};
a.key() < b.key()
}) {
return Err(Error::Dynamic(anyhow::anyhow!(
Expand Down
4 changes: 3 additions & 1 deletion ipld/kamt/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ where
)));
}
if !kvs.windows(2).all(|window| {
let [a, b] = window else { panic!("invalid window length") };
let [a, b] = window else {
panic!("invalid window length")
};
a.key() < b.key()
}) {
return Err(Error::Dynamic(anyhow::anyhow!(
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.70.0"
channel = "1.76.0"
components = ["clippy", "llvm-tools-preview", "rustfmt"]
targets = ["wasm32-unknown-unknown"]
12 changes: 2 additions & 10 deletions sdk/src/message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright 2021-2023 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT
use std::convert::TryInto;

use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_shared::econ::TokenAmount;
use fvm_shared::sys::out::vm::MessageContext;
Expand Down Expand Up @@ -51,18 +49,12 @@ pub fn method_number() -> MethodNum {
/// Returns the value received from the caller in AttoFIL.
#[inline(always)]
pub fn value_received() -> TokenAmount {
MESSAGE_CONTEXT
.value_received
.try_into()
.expect("invalid bigint")
MESSAGE_CONTEXT.value_received.into()
}

/// Returns the execution gas premium
pub fn gas_premium() -> TokenAmount {
MESSAGE_CONTEXT
.gas_premium
.try_into()
.expect("invalid bigint")
MESSAGE_CONTEXT.gas_premium.into()
}

/// Returns the message parameters as an Option<IpldBlock>.
Expand Down
28 changes: 14 additions & 14 deletions shared/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl quickcheck::Arbitrary for Address {
}
}

pub(self) fn parse_address(addr: &str) -> Result<(Address, Network), Error> {
fn parse_address(addr: &str) -> Result<(Address, Network), Error> {
if addr.len() > MAX_ADDRRESS_TEXT_LEN || addr.len() < 3 {
return Err(Error::InvalidLength);
}
Expand Down Expand Up @@ -385,6 +385,19 @@ pub(crate) fn from_leb_bytes(bz: &[u8]) -> Result<u64, Error> {
Ok(id)
}

/// Returns an address hash for given data
fn address_hash(ingest: &[u8]) -> [u8; 20] {
let digest = blake2b_simd::Params::new()
.hash_length(PAYLOAD_HASH_LEN)
.to_state()
.update(ingest)
.finalize();

let mut hash = [0u8; 20];
hash.copy_from_slice(digest.as_bytes());
hash
}

#[cfg(test)]
mod tests {
// Test cases for FOR-02: https://github.com/ChainSafe/forest/issues/1134
Expand Down Expand Up @@ -443,16 +456,3 @@ mod tests {
}
}
}

/// Returns an address hash for given data
fn address_hash(ingest: &[u8]) -> [u8; 20] {
let digest = blake2b_simd::Params::new()
.hash_length(PAYLOAD_HASH_LEN)
.to_state()
.update(ingest)
.finalize();

let mut hash = [0u8; 20];
hash.copy_from_slice(digest.as_bytes());
hash
}
12 changes: 6 additions & 6 deletions shared/src/econ/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ impl Zero for TokenAmount {
}
}

impl PartialOrd for TokenAmount {
impl Ord for TokenAmount {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.atto.partial_cmp(&other.atto)
fn cmp(&self, other: &Self) -> Ordering {
self.atto.cmp(&other.atto)
}
}

impl Ord for TokenAmount {
impl PartialOrd for TokenAmount {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
self.atto.cmp(&other.atto)
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

Expand Down
3 changes: 1 addition & 2 deletions testing/conformance/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ lazy_static! {
/// Override prices with a different network version.
static ref PRICE_NETWORK_VERSION: Option<NetworkVersion> = std::env::var("PRICE_NETWORK_VERSION").ok()
.map(|nv| {
let nv = nv.parse::<u32>().expect("PRICE_NETWORK_VERSION should be a number");
NetworkVersion::try_from(nv).expect("unknown price network version")
nv.parse::<u32>().expect("PRICE_NETWORK_VERSION should be a number").into()
});
}

Expand Down
6 changes: 1 addition & 5 deletions testing/conformance/src/vm.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright 2021-2023 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT
use std::convert::TryFrom;
use std::sync::{Arc, Mutex};

use anyhow::anyhow;
use fvm::kernel::filecoin::{DefaultFilecoinKernel, FilecoinKernel};

use fvm::call_manager::{CallManager, DefaultCallManager};
Expand Down Expand Up @@ -68,9 +66,7 @@ impl TestMachine<Box<DefaultMachine<MemoryBlockstore, TestExterns>>> {
tracing: bool,
price_network_version: Option<NetworkVersion>,
) -> anyhow::Result<TestMachine<Box<DefaultMachine<MemoryBlockstore, TestExterns>>>> {
let network_version = NetworkVersion::try_from(variant.nv)
.map_err(|_| anyhow!("unrecognized network version"))?;

let network_version = variant.nv.into();
let base_fee = v
.preconditions
.basefee
Expand Down
8 changes: 6 additions & 2 deletions testing/integration/tests/gas_calibration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,9 @@ fn on_scan_cbor_links() {
let mut iter_obs: HashMap<String, Vec<Obs>> = Default::default();

for event in ret.exec_trace {
let ExecutionEvent::GasCharge(charge) = event else { continue };
let ExecutionEvent::GasCharge(charge) = event else {
continue;
};
for (key, name) in [
("OnScanIpldLinks", "OnScanIpldLinks"),
("OnTrackLinks", "OnBlockOpen"),
Expand All @@ -559,7 +561,9 @@ fn on_scan_cbor_links() {
if charge.name != name {
continue;
}
let Some(t) = charge.elapsed.get() else { continue };
let Some(t) = charge.elapsed.get() else {
continue;
};

let ob = Obs {
charge: charge.name.into(),
Expand Down
2 changes: 1 addition & 1 deletion testing/test_actors/actors/fil-events-actor/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn invoke(params: u32) -> u32 {
"expected failed syscall"
);

let buf = vec![0; 100];
let buf = [0; 100];

// Value buffer not consumed.
let entry = fvm_shared::sys::EventEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn invoke(blk: u32) -> u32 {
fn invoke_method(_: u32) -> ! {
let method = sdk::message::method_number();
let exit_code = match method {
0 | 1 | 2 => 0,
0..=2 => 0,
_ => 0x42,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn random_bytes(size: usize, seed: u64) -> Vec<u8> {
lcg8(seed).take(size).collect()
}

fn random_mutations(data: &mut Vec<u8>, seed: u64, n: usize) {
fn random_mutations(data: &mut [u8], seed: u64, n: usize) {
let size = data.len();
if size > 0 {
for (i, b) in lcg64(seed).zip(lcg8(seed + 1)).take(n) {
Expand Down
1 change: 1 addition & 0 deletions testing/test_actors/actors/fil-oom-actor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2021-2023 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT
#![allow(clippy::slow_vector_initialization)]

/// Placeholder invoke for testing
#[no_mangle]
Expand Down

0 comments on commit 9abb85b

Please sign in to comment.