diff --git a/fvm/src/blockstore/buffered.rs b/fvm/src/blockstore/buffered.rs index 0e0cd9031..0c0f90330 100644 --- a/fvm/src/blockstore/buffered.rs +++ b/fvm/src/blockstore/buffered.rs @@ -181,7 +181,9 @@ fn take_reachable(cache: &mut HashMap>, root: &Cid) -> Result> $(, $t: $t)*| { charge_for_exec(&mut caller)?; - let (mut memory, mut data) = memory_and_data(&mut caller); + let (mut memory, data) = memory_and_data(&mut caller); charge_syscall_gas!(data.kernel); let ctx = Context{kernel: &mut data.kernel, memory: &mut memory}; @@ -155,7 +155,7 @@ macro_rules! impl_bind_syscalls { self.func_wrap(module, name, move |mut caller: Caller<'_, InvocationData>, ret: u32 $(, $t: $t)*| { charge_for_exec(&mut caller)?; - let (mut memory, mut data) = memory_and_data(&mut caller); + let (mut memory, data) = memory_and_data(&mut caller); charge_syscall_gas!(data.kernel); // We need to check to make sure we can store the return value _before_ we do anything. diff --git a/fvm/src/syscalls/mod.rs b/fvm/src/syscalls/mod.rs index 26cbf242a..60ae4450b 100644 --- a/fvm/src/syscalls/mod.rs +++ b/fvm/src/syscalls/mod.rs @@ -26,7 +26,7 @@ mod send; mod sself; mod vm; -pub(self) use context::Context; +use context::Context; /// Invocation data attached to a wasm "store" and available to the syscall binding. pub struct InvocationData { @@ -170,7 +170,7 @@ pub fn charge_for_init( ) -> crate::kernel::Result { let min_memory_bytes = min_memory_bytes(module)?; let mut ctx = ctx.as_context_mut(); - let mut data = ctx.data_mut(); + let data = ctx.data_mut(); let memory_gas = data.kernel.price_list().init_memory_gas(min_memory_bytes); // Adjust `last_memory_bytes` so that we don't charge for it again in `charge_for_exec`. diff --git a/rust-toolchain.toml b/rust-toolchain.toml index ee6c1e260..9c924956f 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.70.0" +channel = "1.78.0" components = ["clippy", "llvm-tools-preview", "rustfmt"] targets = ["wasm32-unknown-unknown"] diff --git a/sdk/src/message.rs b/sdk/src/message.rs index 8426e73f3..ed29aa02e 100644 --- a/sdk/src/message.rs +++ b/sdk/src/message.rs @@ -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; @@ -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. diff --git a/shared/src/address/mod.rs b/shared/src/address/mod.rs index c4367ae8b..898f7b4f0 100644 --- a/shared/src/address/mod.rs +++ b/shared/src/address/mod.rs @@ -238,7 +238,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); } @@ -380,6 +380,19 @@ pub(crate) fn from_leb_bytes(bz: &[u8]) -> Result { 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 @@ -428,16 +441,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 -} diff --git a/shared/src/econ/mod.rs b/shared/src/econ/mod.rs index 458d6cfb5..b2b9b0884 100644 --- a/shared/src/econ/mod.rs +++ b/shared/src/econ/mod.rs @@ -81,17 +81,17 @@ impl Zero for TokenAmount { } } -impl PartialOrd for TokenAmount { +impl Ord for TokenAmount { #[inline] - fn partial_cmp(&self, other: &Self) -> Option { - 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 { + Some(self.cmp(other)) } } diff --git a/shared/tests/address_test.rs b/shared/tests/address_test.rs index 0ce8bc492..6af767c13 100644 --- a/shared/tests/address_test.rs +++ b/shared/tests/address_test.rs @@ -581,7 +581,7 @@ fn address_hashmap() { // insert other value let h2 = Address::new_id(2); - assert!(hm.get(&h2).is_none()); + assert!(!hm.contains_key(&h2)); hm.insert(h2, 2); assert_eq!(hm.get(&h2).unwrap(), &2); diff --git a/testing/conformance/src/driver.rs b/testing/conformance/src/driver.rs index 2240d064f..369300dd0 100644 --- a/testing/conformance/src/driver.rs +++ b/testing/conformance/src/driver.rs @@ -41,8 +41,7 @@ lazy_static! { /// Override prices with a different network version. static ref PRICE_NETWORK_VERSION: Option = std::env::var("PRICE_NETWORK_VERSION").ok() .map(|nv| { - let nv = nv.parse::().expect("PRICE_NETWORK_VERSION should be a number"); - NetworkVersion::try_from(nv).expect("unknown price network version") + nv.parse::().expect("PRICE_NETWORK_VERSION should be a number").into() }); } diff --git a/testing/conformance/src/vm.rs b/testing/conformance/src/vm.rs index 59952a8f5..3bcaa9a30 100644 --- a/testing/conformance/src/vm.rs +++ b/testing/conformance/src/vm.rs @@ -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 cid::Cid; use multihash::MultihashGeneric; @@ -84,9 +82,7 @@ impl TestMachine>> { tracing: bool, price_network_version: Option, ) -> anyhow::Result>>> { - 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 diff --git a/testing/integration/tests/gas_calibration_test.rs b/testing/integration/tests/gas_calibration_test.rs index 472745130..5f34fd6c4 100644 --- a/testing/integration/tests/gas_calibration_test.rs +++ b/testing/integration/tests/gas_calibration_test.rs @@ -210,7 +210,7 @@ fn on_event_target_size() { }; } - for (obs, name) in vec![(validate_obs, CHARGE_VALIDATE), (accept_obs, CHARGE_ACCEPT)].iter() { + for (obs, name) in &[(validate_obs, CHARGE_VALIDATE), (accept_obs, CHARGE_ACCEPT)] { let regression = run_linear_regression(obs); export(name, obs, ®ression).unwrap(); diff --git a/testing/test_actors/actors/fil-exit-data-actor/src/actor.rs b/testing/test_actors/actors/fil-exit-data-actor/src/actor.rs index 5e75b7932..33c55121d 100644 --- a/testing/test_actors/actors/fil-exit-data-actor/src/actor.rs +++ b/testing/test_actors/actors/fil-exit-data-actor/src/actor.rs @@ -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, }; diff --git a/testing/test_actors/actors/fil-gas-calibration-actor/src/actor.rs b/testing/test_actors/actors/fil-gas-calibration-actor/src/actor.rs index 76636de03..edbbef4cc 100644 --- a/testing/test_actors/actors/fil-gas-calibration-actor/src/actor.rs +++ b/testing/test_actors/actors/fil-gas-calibration-actor/src/actor.rs @@ -165,7 +165,9 @@ fn on_event(p: OnEventParams) -> Result<()> { fn on_event_shape(p: OnEventParams) -> Result<()> { const MAX_DATA: usize = 8 << 10; - let EventCalibrationMode::Shape((key_size, value_size, last_value_size)) = p.mode else { panic!() }; + let EventCalibrationMode::Shape((key_size, value_size, last_value_size)) = p.mode else { + panic!() + }; let mut value = vec![0; value_size]; // the last entry may not exceed total event values over MAX_DATA @@ -203,7 +205,9 @@ fn on_event_shape(p: OnEventParams) -> Result<()> { } fn on_event_target_size(p: OnEventParams) -> Result<()> { - let EventCalibrationMode::TargetSize(target_size) = p.mode else { panic!() }; + let EventCalibrationMode::TargetSize(target_size) = p.mode else { + panic!() + }; // Deduct the approximate overhead of each entry (3 bytes) + flag (1 byte). This // is fuzzy because the size of the encoded CBOR depends on the length of fields, but it's good enough. @@ -240,7 +244,7 @@ fn random_bytes(size: usize, seed: u64) -> Vec { lcg8(seed).take(size).collect() } -fn random_mutations(data: &mut Vec, 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) { diff --git a/testing/test_actors/actors/fil-oom-actor/src/lib.rs b/testing/test_actors/actors/fil-oom-actor/src/lib.rs index 3c8da29c0..34cb659c2 100644 --- a/testing/test_actors/actors/fil-oom-actor/src/lib.rs +++ b/testing/test_actors/actors/fil-oom-actor/src/lib.rs @@ -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]