Skip to content

Commit

Permalink
refactor(storage): fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pashinov committed Mar 27, 2024
1 parent 1b25703 commit e97ebd7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
6 changes: 3 additions & 3 deletions storage/src/db/file_db/mapped_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl MappedFile {
(self.ptr as *const u8).add(offset),
buffer.as_mut_ptr(),
buffer.len(),
)
);
}

/// Copies buffer to the mapped memory
Expand All @@ -88,9 +88,9 @@ 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::<u8>()).add(offset),
buffer.len(),
)
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions storage/src/db/file_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl Seek for FileDb {
}
}

impl Into<File> for FileDb {
fn into(self) -> File {
self.file
impl From<FileDb> for File {
fn from(val: FileDb) -> Self {
val.file
}
}
2 changes: 1 addition & 1 deletion storage/src/store/persistent_state/cell_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<'a> CellWriter<'a> {
}

pub fn remove(&self) -> Result<()> {
fs::remove_file(&self.base_path).context(format!(
fs::remove_file(self.base_path).context(format!(
"Failed to remove persistent state file {:?}",
self.base_path
))
Expand Down
6 changes: 3 additions & 3 deletions storage/src/store/persistent_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ impl PersistentStateStorage {
block_id: &BlockId,
root_hash: &HashBytes,
) -> Result<()> {
let block_id = block_id.clone();
let block_id = *block_id;
let root_hash = *root_hash;
let db = self.db.clone();
let is_cancelled = Some(self.is_cancelled.clone());
let base_path = self.get_state_file_path(&mc_block_id, &block_id);
let base_path = self.get_state_file_path(mc_block_id, &block_id);

tokio::task::spawn_blocking(move || {
let cell_writer = cell_writer::CellWriter::new(&db, &base_path);
Expand All @@ -71,7 +71,7 @@ impl PersistentStateStorage {
);

if let Err(e) = cell_writer.remove() {
tracing::error!(%block_id, "{e}")
tracing::error!(%block_id, "{e}");
}
}
}
Expand Down
18 changes: 6 additions & 12 deletions storage/src/store/shard_state/replace_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ impl<'a> ShardStateReplaceTransaction<'a> {

if chunk_size > 0 {
tracing::debug!(chunk_size, "creating chunk");
cells_file.write(&chunk_size.to_le_bytes())?;
let bytes = cells_file.write(&chunk_size.to_le_bytes())?;
tracing::trace!(bytes, "writing cells to file");
}

if self.cells_read < header.cell_count {
Expand Down Expand Up @@ -190,7 +191,7 @@ impl<'a> ShardStateReplaceTransaction<'a> {
unsafe { hashes_file.read_exact_at(index as usize * HashesEntry::LEN, buffer) }
}

self.finalize_cell(&mut ctx, cell_index as u32, cell)?;
ShardStateReplaceTransaction::finalize_cell(&mut ctx, cell_index as u32, cell)?;

// SAFETY: `entries_buffer` is guaranteed to be in separate memory area
unsafe {
Expand Down Expand Up @@ -227,7 +228,7 @@ impl<'a> ShardStateReplaceTransaction<'a> {
progress_bar.complete();

// Load stored shard state
let result = match self.db.shard_states.get(shard_state_key)? {
match self.db.shard_states.get(shard_state_key)? {
Some(root) => {
let cell_id = HashBytes::from_slice(&root[..32]);

Expand All @@ -239,13 +240,10 @@ impl<'a> ShardStateReplaceTransaction<'a> {
)?))
}
None => Err(ReplaceTransactionError::NotFound.into()),
};

result
}
}

fn finalize_cell(
&self,
ctx: &mut FinalizationContext<'_>,
cell_index: u32,
cell: RawCell<'_>,
Expand Down Expand Up @@ -277,11 +275,7 @@ impl<'a> ShardStateReplaceTransaction<'a> {
cell.descriptor.level_mask()
}
CellType::LibraryReference => LevelMask::new(0),
CellType::MerkleProof => {
is_merkle_cell = true;
children_mask.virtualize(1)
}
CellType::MerkleUpdate => {
CellType::MerkleProof | CellType::MerkleUpdate => {
is_merkle_cell = true;
children_mask.virtualize(1)
}
Expand Down
4 changes: 2 additions & 2 deletions storage/src/utils/stored_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,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());
Expand All @@ -176,7 +176,7 @@ pub fn write_block_id_le(block_id: &BlockId) -> [u8; 80] {
bytes
}

/// Reads BlockId in little-endian format
/// Reads `BlockId` in little-endian format
pub fn read_block_id_le(data: &[u8]) -> Option<BlockId> {
if data.len() < 80 {
return None;
Expand Down

0 comments on commit e97ebd7

Please sign in to comment.