Skip to content

Commit

Permalink
[v3] chore: update the rust compiler and fix new lint errors (#2038)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien authored Sep 12, 2024
1 parent 3c5da7e commit 27e0440
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 50 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 fvm/src/state_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ mod tests {
tree.set_actor(INIT_ACTOR_ID, act_s);

// Test mutate function
tree.mutate_actor(INIT_ACTOR_ID, |mut actor| {
tree.mutate_actor(INIT_ACTOR_ID, |actor| {
actor.sequence = 2;
Ok(())
})
Expand Down
4 changes: 2 additions & 2 deletions fvm/src/syscalls/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ macro_rules! impl_bind_syscalls {
self.func_wrap(module, name, move |mut caller: Caller<'_, InvocationData<K>> $(, $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};
Expand Down Expand Up @@ -155,7 +155,7 @@ macro_rules! impl_bind_syscalls {
self.func_wrap(module, name, move |mut caller: Caller<'_, InvocationData<K>>, 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.
Expand Down
4 changes: 2 additions & 2 deletions fvm/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K> {
Expand Down Expand Up @@ -170,7 +170,7 @@ pub fn charge_for_init<K: Kernel>(
) -> crate::kernel::Result<GasTimer> {
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`.
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.78.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 @@ -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);
}
Expand Down Expand Up @@ -380,6 +380,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 @@ -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
}
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
2 changes: 1 addition & 1 deletion shared/tests/address_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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 @@ -41,8 +41,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 cid::Cid;
use multihash::MultihashGeneric;

Expand Down Expand Up @@ -84,9 +82,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
2 changes: 1 addition & 1 deletion testing/integration/tests/gas_calibration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &regression).unwrap();
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 @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -240,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 27e0440

Please sign in to comment.