From 28b24388eb8b00d5b319be5fa7937b8a25d6e0ca Mon Sep 17 00:00:00 2001 From: Vladimir Petrzhikovskii Date: Thu, 15 Feb 2024 12:48:29 +0100 Subject: [PATCH] chore(storage): apply clippy suggestions --- block-util/src/archive_package.rs | 4 +-- block-util/src/block.rs | 8 ++--- block-util/src/block_proof.rs | 8 ++--- block-util/src/mapped_file.rs | 2 +- block-util/src/package_entry_id.rs | 12 ++++---- block-util/src/shard_state.rs | 2 +- block-util/src/stored_value.rs | 30 +++++++++---------- block-util/src/top_blocks.rs | 4 +-- block-util/src/with_archive_data.rs | 6 ++-- storage/src/block_handle_storage/mod.rs | 10 +++---- storage/src/block_storage/mod.rs | 2 +- storage/src/db/migrations/mod.rs | 2 +- storage/src/db/mod.rs | 4 +-- storage/src/db/tables.rs | 2 +- storage/src/models/block_handle.rs | 10 +++---- storage/src/models/block_meta.rs | 14 ++++----- storage/src/runtime_storage/mod.rs | 2 +- .../persistent_state_keeper.rs | 2 +- .../src/shard_state_storage/cell_storage.rs | 4 +-- .../src/shard_state_storage/cell_writer.rs | 2 +- .../src/shard_state_storage/entries_buffer.rs | 24 +++++++-------- .../replace_transaction.rs | 4 +-- .../shard_state_storage/shard_state_reader.rs | 8 ++--- 23 files changed, 83 insertions(+), 83 deletions(-) diff --git a/block-util/src/archive_package.rs b/block-util/src/archive_package.rs index 9909d95eb..ff98c8ebb 100644 --- a/block-util/src/archive_package.rs +++ b/block-util/src/archive_package.rs @@ -150,7 +150,7 @@ impl ArchivePackageVerifier { part.as_ptr().add(offset), buffer.as_mut_ptr().add(*filled), remaining, - ) + ); }; offset += remaining; @@ -226,4 +226,4 @@ pub enum ArchivePackageError { pub const ARCHIVE_PREFIX: [u8; 4] = u32::to_le_bytes(0xae8fdd01); const ARCHIVE_ENTRY_PREFIX: [u8; 2] = u16::to_le_bytes(0x1e8b); -const ARCHIVE_ENTRY_HEADER_LEN: usize = ARCHIVE_ENTRY_PREFIX.len() + 2 + 4; // magic + filename len + data len \ No newline at end of file +const ARCHIVE_ENTRY_HEADER_LEN: usize = ARCHIVE_ENTRY_PREFIX.len() + 2 + 4; // magic + filename len + data len diff --git a/block-util/src/block.rs b/block-util/src/block.rs index 304d20c31..1043adc5b 100644 --- a/block-util/src/block.rs +++ b/block-util/src/block.rs @@ -1,7 +1,7 @@ -/// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node -/// -/// Changes: -/// - replaced old `failure` crate with `anyhow` +// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node +// +// Changes: +// - replaced old `failure` crate with `anyhow` use anyhow::{anyhow, Context, Result}; use everscale_types::models::*; use everscale_types::prelude::*; diff --git a/block-util/src/block_proof.rs b/block-util/src/block_proof.rs index 87e91eb8f..aa22cbc41 100644 --- a/block-util/src/block_proof.rs +++ b/block-util/src/block_proof.rs @@ -1,7 +1,7 @@ -/// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node -/// -/// Changes: -/// - replaced old `failure` crate with `anyhow` +// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node +// +// Changes: +// - replaced old `failure` crate with `anyhow` use anyhow::{anyhow, Context, Result}; use everscale_types::merkle::*; use everscale_types::models::*; diff --git a/block-util/src/mapped_file.rs b/block-util/src/mapped_file.rs index 16d90d20c..a8155adfb 100644 --- a/block-util/src/mapped_file.rs +++ b/block-util/src/mapped_file.rs @@ -78,7 +78,7 @@ impl MappedFile { pub unsafe fn write_all_at(&self, offset: usize, buffer: &[u8]) { std::ptr::copy_nonoverlapping( buffer.as_ptr(), - (self.ptr as *mut u8).add(offset), + self.ptr.cast::().add(offset), buffer.len(), ) } diff --git a/block-util/src/package_entry_id.rs b/block-util/src/package_entry_id.rs index 55a1a04f3..f21e68af8 100644 --- a/block-util/src/package_entry_id.rs +++ b/block-util/src/package_entry_id.rs @@ -40,8 +40,8 @@ impl PackageEntryId { } impl PackageEntryId - where - I: Borrow, +where + I: Borrow, { /// Returns package entry prefix fn filename_prefix(&self) -> &'static str { @@ -91,8 +91,8 @@ impl GetFileName for BlockId { } impl GetFileName for PackageEntryId - where - I: Borrow + Hash, +where + I: Borrow + Hash, { fn filename(&self) -> String { match self { @@ -188,7 +188,7 @@ enum PackageEntryIdError { #[cfg(test)] mod tests { - use rand::{random}; + use rand::random; use super::*; @@ -212,4 +212,4 @@ mod tests { check_package_id(PackageEntryId::Proof(block_id.clone())); check_package_id(PackageEntryId::ProofLink(block_id)); } -} \ No newline at end of file +} diff --git a/block-util/src/shard_state.rs b/block-util/src/shard_state.rs index c0f6430f1..0c5841535 100644 --- a/block-util/src/shard_state.rs +++ b/block-util/src/shard_state.rs @@ -58,7 +58,7 @@ impl ShardStateStuff { left: Lazy::from_raw(left), right: Lazy::from_raw(right), }) - .map_err(From::from) + .map_err(From::from) } pub fn deserialize_zerostate(id: BlockId, bytes: &[u8]) -> Result { diff --git a/block-util/src/stored_value.rs b/block-util/src/stored_value.rs index 9f9cca243..cb4a7a152 100644 --- a/block-util/src/stored_value.rs +++ b/block-util/src/stored_value.rs @@ -23,16 +23,16 @@ pub trait StoredValue { /// /// NOTE: `reader` should not be used after this call in case of an error fn deserialize(reader: &mut &[u8]) -> Result - where - Self: Sized; + where + Self: Sized; /// Deserializes the data from the buffer. /// /// [`StoredValue::deserialize`] #[inline(always)] fn from_slice(mut data: &[u8]) -> Result - where - Self: Sized, + where + Self: Sized, { Self::deserialize(&mut data) } @@ -64,8 +64,8 @@ impl StoredValueBuffer for Vec { } impl StoredValueBuffer for SmallVec - where - T: smallvec::Array, +where + T: smallvec::Array, { #[inline(always)] fn write_byte(&mut self, byte: u8) { @@ -96,8 +96,8 @@ impl StoredValue for BlockId { } fn deserialize(reader: &mut &[u8]) -> Result - where - Self: Sized, + where + Self: Sized, { let shard = ShardIdent::deserialize(reader)?; let seqno = reader.get_u32(); @@ -131,8 +131,8 @@ impl StoredValue for ShardIdent { } fn deserialize(reader: &mut &[u8]) -> Result - where - Self: Sized, + where + Self: Sized, { let workchain = reader.get_u32() as i32; let prefix = reader.get_u64(); @@ -154,8 +154,8 @@ impl StoredValue for BlockIdShort { } fn deserialize(reader: &mut &[u8]) -> Result - where - Self: Sized, + where + Self: Sized, { let shard = ShardIdent::deserialize(reader)?; let seqno = reader.get_u32(); @@ -163,7 +163,7 @@ impl StoredValue for BlockIdShort { } } -/// Writes BlockIdExt in little-endian format +/// Writes `BlockIdExt` in little-endian format pub fn write_block_id_le(block_id: &BlockId) -> [u8; 80] { let mut bytes = [0u8; 80]; bytes[..4].copy_from_slice(&block_id.shard.workchain().to_le_bytes()); @@ -174,7 +174,7 @@ pub fn write_block_id_le(block_id: &BlockId) -> [u8; 80] { bytes } -/// Reads BlockIdExt in little-endian format +/// Reads `BlockIdExt` in little-endian format pub fn read_block_id_le(data: &[u8]) -> Option { if data.len() < 80 { return None; @@ -238,4 +238,4 @@ mod tests { assert_eq!(read_block_id_le(&serialized).unwrap(), block_id); } -} \ No newline at end of file +} diff --git a/block-util/src/top_blocks.rs b/block-util/src/top_blocks.rs index 51b187cee..61534e2c5 100644 --- a/block-util/src/top_blocks.rs +++ b/block-util/src/top_blocks.rs @@ -115,8 +115,8 @@ impl StoredValue for TopBlocks { } fn deserialize(reader: &mut &[u8]) -> Result - where - Self: Sized, + where + Self: Sized, { let mc_block = BlockIdShort::deserialize(reader)?; diff --git a/block-util/src/with_archive_data.rs b/block-util/src/with_archive_data.rs index 090ce1d63..591832ee9 100644 --- a/block-util/src/with_archive_data.rs +++ b/block-util/src/with_archive_data.rs @@ -16,8 +16,8 @@ pub struct WithArchiveData { impl WithArchiveData { /// Constructs a new object from the context with known raw data pub fn new(data: T, archive_data: A) -> Self - where - Bytes: From, + where + Bytes: From, { Self { data, @@ -79,4 +79,4 @@ mod tests { ); assert!(WithArchiveData::loaded(()).new_archive_data().is_err()); } -} \ No newline at end of file +} diff --git a/storage/src/block_handle_storage/mod.rs b/storage/src/block_handle_storage/mod.rs index d776e067f..cd6dd1eb8 100644 --- a/storage/src/block_handle_storage/mod.rs +++ b/storage/src/block_handle_storage/mod.rs @@ -1,8 +1,8 @@ -/// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node -/// -/// Changes: -/// - replaced old `failure` crate with `anyhow` -/// - simplified storing +// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node +// +// Changes: +// - replaced old `failure` crate with `anyhow` +// - simplified storing use std::sync::{Arc, Weak}; use anyhow::Result; diff --git a/storage/src/block_storage/mod.rs b/storage/src/block_storage/mod.rs index 0db7c3ff0..6ec18ff0e 100644 --- a/storage/src/block_storage/mod.rs +++ b/storage/src/block_storage/mod.rs @@ -53,7 +53,7 @@ impl BlockStorage { ); if let Some(Err(e)) = value.map(check_archive) { - tracing::error!(archive_id, "failed to read archive: {e:?}") + tracing::error!(archive_id, "failed to read archive: {e:?}"); } archive_ids.insert(archive_id); diff --git a/storage/src/db/migrations/mod.rs b/storage/src/db/migrations/mod.rs index a3213c917..710c980eb 100644 --- a/storage/src/db/migrations/mod.rs +++ b/storage/src/db/migrations/mod.rs @@ -47,4 +47,4 @@ impl VersionProvider for NodeStateVersionProvider { state.insert(Self::DB_VERSION_KEY, version)?; Ok(()) } -} \ No newline at end of file +} diff --git a/storage/src/db/mod.rs b/storage/src/db/mod.rs index 806e1d4ba..61c14a84d 100644 --- a/storage/src/db/mod.rs +++ b/storage/src/db/mod.rs @@ -173,7 +173,7 @@ impl Db { let cf = db.instantiate_table::(); let res: (usize, usize) = cf .iterator(rocksdb::IteratorMode::Start) - .flat_map(|x| { + .filter_map(|x| { let x = match x { Ok(x) => x, Err(e) => { @@ -243,7 +243,7 @@ pub struct DiskUsageInfo { impl Drop for Db { fn drop(&mut self) { - self.raw().cancel_all_background_work(true) + self.raw().cancel_all_background_work(true); } } diff --git a/storage/src/db/tables.rs b/storage/src/db/tables.rs index 10cdd1bfa..722924a4d 100644 --- a/storage/src/db/tables.rs +++ b/storage/src/db/tables.rs @@ -89,7 +89,7 @@ impl ColumnFamily for PackageEntries { } } -/// Maps BlockId to root cell hash +/// Maps `BlockId` to root cell hash /// - Key: `BlockId` /// - Value: `[u8; 32]` pub struct ShardStates; diff --git a/storage/src/models/block_handle.rs b/storage/src/models/block_handle.rs index 6c239544c..a4114b722 100644 --- a/storage/src/models/block_handle.rs +++ b/storage/src/models/block_handle.rs @@ -1,8 +1,8 @@ -/// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node -/// -/// Changes: -/// - replaced old `failure` crate with `anyhow` -/// - moved all flags to meta +// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node +// +// Changes: +// - replaced old `failure` crate with `anyhow` +// - moved all flags to meta use std::sync::{Arc, Weak}; use anyhow::Result; diff --git a/storage/src/models/block_meta.rs b/storage/src/models/block_meta.rs index 751abd2a0..1e5e2804f 100644 --- a/storage/src/models/block_meta.rs +++ b/storage/src/models/block_meta.rs @@ -1,9 +1,9 @@ -/// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node -/// -/// Changes: -/// - replaced old `failure` crate with `anyhow` -/// - moved all flags here from block handle -/// - removed temporary unused flags +// This file is a modified copy of the file from https://github.com/tonlabs/ton-labs-node +// +// Changes: +// - replaced old `failure` crate with `anyhow` +// - moved all flags here from block handle +// - removed temporary unused flags use std::sync::atomic::{AtomicU64, Ordering}; use anyhow::Result; @@ -209,7 +209,7 @@ impl BlockMeta { impl StoredValue for BlockMeta { /// 8 bytes flags - /// 4 bytes gen_utime + /// 4 bytes `gen_utime` const SIZE_HINT: usize = 8 + 4; type OnStackSlice = [u8; Self::SIZE_HINT]; diff --git a/storage/src/runtime_storage/mod.rs b/storage/src/runtime_storage/mod.rs index 69bdafae1..6cf671e3c 100644 --- a/storage/src/runtime_storage/mod.rs +++ b/storage/src/runtime_storage/mod.rs @@ -20,4 +20,4 @@ impl RuntimeStorage { pub fn persistent_state_keeper(&self) -> &PersistentStateKeeper { &self.persistent_state_keeper } -} \ No newline at end of file +} diff --git a/storage/src/runtime_storage/persistent_state_keeper.rs b/storage/src/runtime_storage/persistent_state_keeper.rs index 24bfc8c77..18217419d 100644 --- a/storage/src/runtime_storage/persistent_state_keeper.rs +++ b/storage/src/runtime_storage/persistent_state_keeper.rs @@ -82,7 +82,7 @@ impl PersistentStateKeeper { .map(|handle| (handle.id().seqno, handle.meta().brief())) } - pub fn new_state_found(&self) -> tokio::sync::futures::Notified { + pub fn new_state_found(&self) -> tokio::sync::futures::Notified<'_> { self.persistent_state_changed.notified() } } diff --git a/storage/src/shard_state_storage/cell_storage.rs b/storage/src/shard_state_storage/cell_storage.rs index 8750b46b6..45faa0782 100644 --- a/storage/src/shard_state_storage/cell_storage.rs +++ b/storage/src/shard_state_storage/cell_storage.rs @@ -243,7 +243,7 @@ impl CellStorage { let cells = &self.db.cells; let cells_cf = &cells.cf(); - let mut transaction: FastHashMap<&HashBytes, CellState> = + let mut transaction: FastHashMap<&HashBytes, CellState<'_>> = FastHashMap::with_capacity_and_hasher(128, Default::default()); let mut buffer = Vec::with_capacity(4); @@ -394,7 +394,7 @@ impl StorageCell { }; for slot in reference_data.iter().take(ref_count) { - let slot = slot.get() as *mut u8; + let slot = slot.get().cast::(); unsafe { std::ptr::copy_nonoverlapping(buffer.as_ptr().add(offset), slot, 32) }; offset += 32; } diff --git a/storage/src/shard_state_storage/cell_writer.rs b/storage/src/shard_state_storage/cell_writer.rs index 36fb131ea..261e09131 100644 --- a/storage/src/shard_state_storage/cell_writer.rs +++ b/storage/src/shard_state_storage/cell_writer.rs @@ -240,7 +240,7 @@ fn write_rev_cells>( for i in 0..preload_count { let index = indices_buffer[i]; - let hash = unsafe { *(keys[i] as *const [u8; 32]) }; + let hash = unsafe { *keys[i].cast::<[u8; 32]>() }; stack.push((index, StackItem::New(hash))); } } diff --git a/storage/src/shard_state_storage/entries_buffer.rs b/storage/src/shard_state_storage/entries_buffer.rs index 5347ad5fe..a2f9896eb 100644 --- a/storage/src/shard_state_storage/entries_buffer.rs +++ b/storage/src/shard_state_storage/entries_buffer.rs @@ -21,8 +21,8 @@ impl EntriesBuffer { &'a mut self, references: &'b [u32], ) -> (HashesEntryWriter<'a>, EntriesBufferChildren<'b>) - where - 'a: 'b, + where + 'a: 'b, { let [first, tail @ ..] = &mut *self.0; ( @@ -40,7 +40,7 @@ impl EntriesBuffer { pub struct EntriesBufferChildren<'a>(&'a [u32], &'a [[u8; HashesEntry::LEN]]); impl EntriesBufferChildren<'_> { - pub fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator)> { self.0 .iter() .zip(self.1) @@ -51,7 +51,7 @@ impl EntriesBufferChildren<'_> { pub struct HashesEntryWriter<'a>(&'a mut [u8; HashesEntry::LEN]); impl HashesEntryWriter<'_> { - pub fn as_reader(&self) -> HashesEntry { + pub fn as_reader(&self) -> HashesEntry<'_> { HashesEntry(self.0) } @@ -87,7 +87,7 @@ impl HashesEntryWriter<'_> { pub fn get_hash_slice(&mut self, i: u8) -> &mut [u8; 32] { let offset = HashesEntry::HASHES_OFFSET + 32 * i as usize; - unsafe { &mut *(self.0.as_mut_ptr().add(offset) as *mut _) } + unsafe { &mut *self.0.as_mut_ptr().add(offset).cast() } } pub fn set_depth(&mut self, i: u8, depth: u16) { @@ -97,7 +97,7 @@ impl HashesEntryWriter<'_> { pub fn get_depth_slice(&mut self, i: u8) -> &mut [u8; 2] { let offset = HashesEntry::DEPTHS_OFFSET + 2 * i as usize; - unsafe { &mut *(self.0.as_mut_ptr().add(offset) as *mut _) } + unsafe { &mut *self.0.as_mut_ptr().add(offset).cast() } } } @@ -138,7 +138,7 @@ impl<'a> HashesEntry<'a> { pub fn hash(&self, n: u8) -> &'a [u8; 32] { let offset = Self::HASHES_OFFSET + 32 * self.level_mask().hash_index(n) as usize; - unsafe { &*(self.0.as_ptr().add(offset) as *const _) } + unsafe { &*self.0.as_ptr().add(offset).cast() } } pub fn depth(&self, n: u8) -> u16 { @@ -147,8 +147,8 @@ impl<'a> HashesEntry<'a> { } pub fn pruned_branch_hash<'b>(&self, n: u8, data: &'b [u8]) -> Option<&'b [u8; 32]> - where - 'a: 'b, + where + 'a: 'b, { let level_mask = self.level_mask(); let index = level_mask.hash_index(n) as usize; @@ -156,13 +156,13 @@ impl<'a> HashesEntry<'a> { Some(if index == level { let offset = Self::HASHES_OFFSET; - unsafe { &*(self.0.as_ptr().add(offset) as *const _) } + unsafe { &*self.0.as_ptr().add(offset).cast() } } else { let offset = 1 + 1 + index * 32; if data.len() < offset + 32 { return None; } - unsafe { &*(data.as_ptr().add(offset) as *const _) } + unsafe { &*data.as_ptr().add(offset).cast() } }) } @@ -179,4 +179,4 @@ impl<'a> HashesEntry<'a> { u16::from_be_bytes([data[offset], data[offset + 1]]) } } -} \ No newline at end of file +} diff --git a/storage/src/shard_state_storage/replace_transaction.rs b/storage/src/shard_state_storage/replace_transaction.rs index ebdf5f398..54260369e 100644 --- a/storage/src/shard_state_storage/replace_transaction.rs +++ b/storage/src/shard_state_storage/replace_transaction.rs @@ -183,7 +183,7 @@ impl<'a> ShardStateReplaceTransaction<'a> { hashes_file.write_all_at( cell_index as usize * HashesEntry::LEN, ctx.entries_buffer.current_entry_buffer(), - ) + ); }; chunk_buffer.truncate(chunk_size); @@ -368,7 +368,7 @@ impl<'a> ShardStateReplaceTransaction<'a> { cell.descriptor.d1, cell.descriptor.d2, ]); - output_buffer.extend_from_slice(&(cell.bit_len as u16).to_le_bytes()); + output_buffer.extend_from_slice(&cell.bit_len.to_le_bytes()); output_buffer.extend_from_slice(cell.data); let hash_count = cell.descriptor.hash_count(); diff --git a/storage/src/shard_state_storage/shard_state_reader.rs b/storage/src/shard_state_storage/shard_state_reader.rs index 001a2eecf..42ba73393 100644 --- a/storage/src/shard_state_storage/shard_state_reader.rs +++ b/storage/src/shard_state_storage/shard_state_reader.rs @@ -2,7 +2,7 @@ use std::io::Read; use anyhow::{Context, Result}; use crc::{Crc, CRC_32_ISCSI}; -use everscale_types::cell::{CellDescriptor, CellType, LevelMask}; +use everscale_types::cell::{CellDescriptor, LevelMask}; use smallvec::SmallVec; macro_rules! try_read { @@ -301,8 +301,8 @@ impl<'a> RawCell<'a> { cell_index: usize, data_buffer: &'a mut [u8], ) -> Result - where - R: Read, + where + R: Read, { let mut descriptor = [0u8; 2]; src.read_exact(&mut descriptor)?; @@ -524,4 +524,4 @@ impl ByteOrderRead for T { self.read_exact(&mut buf)?; Ok(u32::from_le_bytes(buf)) } -} \ No newline at end of file +}