Skip to content

Commit

Permalink
chore: update to rust 1.78 and fix lints (#2040)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien authored Sep 12, 2024
1 parent cefb3d1 commit 306ab00
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 45 deletions.
6 changes: 3 additions & 3 deletions fvm/src/state_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ mod tests {
tree.set_actor(&INIT_ACTOR_ADDR, act_s).unwrap();

// Test mutate function
tree.mutate_actor(&INIT_ACTOR_ADDR, |mut actor| {
tree.mutate_actor(&INIT_ACTOR_ADDR, |actor| {
actor.sequence = 2;
Ok(())
})
Expand Down Expand Up @@ -750,8 +750,8 @@ mod tests {
let mut tree = StateTree::new(&store, StateTreeVersion::V3).unwrap();
let mut addresses: Vec<Address> = Vec::new();

let test_addresses = vec!["t0100", "t0101", "t0102"];
for a in test_addresses.iter() {
let test_addresses = ["t0100", "t0101", "t0102"];
for a in &test_addresses {
addresses.push(a.parse().unwrap());
}

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 @@ -123,7 +123,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 @@ -153,7 +153,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
2 changes: 1 addition & 1 deletion fvm/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.70.0"
channel = "1.78.0"
components = ["clippy", "llvm-tools-preview", "rustfmt"]
7 changes: 1 addition & 6 deletions sdk/src/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::convert::TryInto;

use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_shared::econ::TokenAmount;
use fvm_shared::sys::BlockId;
Expand Down Expand Up @@ -29,10 +27,7 @@ pub fn method_number() -> MethodNum {
/// Returns the value received from the caller in AttoFIL.
#[inline(always)]
pub fn value_received() -> TokenAmount {
INVOCATION_CONTEXT
.value_received
.try_into()
.expect("invalid bigint")
INVOCATION_CONTEXT.value_received.into()
}

/// Returns the message parameters as an Option<IpldBlock>.
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ macro_rules! fvm_syscalls {
// Returns no values.
(module = $module:literal; $(#[$attrs:meta])* $v:vis fn $name:ident($($args:ident : $args_ty:ty),*$(,)?) -> Result<()>; $($rest:tt)*) => {
$(#[$attrs])*
#[allow(clippy::missing_safety_doc)]
$v unsafe fn $name($($args:$args_ty),*) -> Result<(), $crate::sys::ErrorNumber> {
#[link(wasm_import_module = $module)]
extern "C" {
Expand All @@ -122,6 +123,7 @@ macro_rules! fvm_syscalls {
// Returns a value.
(module = $module:literal; $(#[$attrs:meta])* $v:vis fn $name:ident($($args:ident : $args_ty:ty),*$(,)?) -> Result<$ret:ty>; $($rest:tt)*) => {
$(#[$attrs])*
#[allow(clippy::missing_safety_doc)]
$v unsafe fn $name($($args:$args_ty),*) -> Result<$ret, $crate::sys::ErrorNumber> {
#[link(wasm_import_module = $module)]
extern "C" {
Expand All @@ -147,6 +149,7 @@ macro_rules! fvm_syscalls {
// Does not return.
(module = $module:literal; $(#[$attrs:meta])* $v:vis fn $name:ident($($args:ident : $args_ty:ty),*$(,)?) -> !; $($rest:tt)*) => {
$(#[$attrs])*
#[allow(clippy::missing_safety_doc)]
$v unsafe fn $name($($args:$args_ty),*) -> ! {
#[link(wasm_import_module = $module)]
extern "C" {
Expand Down
60 changes: 30 additions & 30 deletions shared/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,36 @@ pub(crate) fn from_leb_bytes(bz: &[u8]) -> Result<u64, Error> {
Ok(id)
}

/// Checksum calculates the 4 byte checksum hash
pub fn checksum(ingest: &[u8]) -> Vec<u8> {
blake2b_simd::Params::new()
.hash_length(CHECKSUM_HASH_LEN)
.to_state()
.update(ingest)
.finalize()
.as_bytes()
.to_vec()
}

/// Validates the checksum against the ingest data
pub fn validate_checksum(ingest: &[u8], expect: Vec<u8>) -> bool {
let digest = checksum(ingest);
digest == expect
}

/// 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 @@ -372,33 +402,3 @@ mod tests {
}
}
}

/// Checksum calculates the 4 byte checksum hash
pub fn checksum(ingest: &[u8]) -> Vec<u8> {
blake2b_simd::Params::new()
.hash_length(CHECKSUM_HASH_LEN)
.to_state()
.update(ingest)
.finalize()
.as_bytes()
.to_vec()
}

/// Validates the checksum against the ingest data
pub fn validate_checksum(ingest: &[u8], expect: Vec<u8>) -> bool {
let digest = checksum(ingest);
digest == expect
}

/// 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
}
2 changes: 1 addition & 1 deletion shared/src/econ/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Zero for TokenAmount {
impl PartialOrd for TokenAmount {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.atto.partial_cmp(&other.atto)
Some(self.atto.cmp(&other.atto))
}
}

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 @@ -541,7 +541,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

0 comments on commit 306ab00

Please sign in to comment.