Skip to content

Commit

Permalink
chore(storage): apply clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdeafbeef committed Feb 21, 2024
1 parent fcb72d4 commit 908b965
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 71 deletions.
67 changes: 67 additions & 0 deletions .scratch/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '3.8'
services:
node-0:
entrypoint: /entrypoints/entrypoint.sh
image: tycho-network
networks:
default:
ipv4_address: 172.0.30.2
stop_grace_period: 1s
stop_signal: KILL
volumes:
- ./entrypoints/node-0_entrypoint.sh:/entrypoints/entrypoint.sh
- /home/odm3n/dev/work/tycho/.scratch/global-config.json:/app/global-config.json
- /home/odm3n/dev/work/tycho/.scratch/logs/node-0:/app/logs:rw
node-1:
entrypoint: /entrypoints/entrypoint.sh
image: tycho-network
networks:
default:
ipv4_address: 172.0.30.3
stop_grace_period: 1s
stop_signal: KILL
volumes:
- ./entrypoints/node-0_entrypoint.sh:/entrypoints/entrypoint.sh
- /home/odm3n/dev/work/tycho/.scratch/global-config.json:/app/global-config.json
- /home/odm3n/dev/work/tycho/.scratch/logs/node-0:/app/logs:rw
node-2:
entrypoint: /entrypoints/entrypoint.sh
image: tycho-network
networks:
default:
ipv4_address: 172.0.30.4
stop_grace_period: 1s
stop_signal: KILL
volumes:
- ./entrypoints/node-0_entrypoint.sh:/entrypoints/entrypoint.sh
- /home/odm3n/dev/work/tycho/.scratch/global-config.json:/app/global-config.json
- /home/odm3n/dev/work/tycho/.scratch/logs/node-0:/app/logs:rw
node-3:
entrypoint: /entrypoints/entrypoint.sh
image: tycho-network
networks:
default:
ipv4_address: 172.0.30.5
stop_grace_period: 1s
stop_signal: KILL
volumes:
- ./entrypoints/node-0_entrypoint.sh:/entrypoints/entrypoint.sh
- /home/odm3n/dev/work/tycho/.scratch/global-config.json:/app/global-config.json
- /home/odm3n/dev/work/tycho/.scratch/logs/node-0:/app/logs:rw
node-4:
entrypoint: /entrypoints/entrypoint.sh
image: tycho-network
networks:
default:
ipv4_address: 172.0.30.6
stop_grace_period: 1s
stop_signal: KILL
volumes:
- ./entrypoints/node-0_entrypoint.sh:/entrypoints/entrypoint.sh
- /home/odm3n/dev/work/tycho/.scratch/global-config.json:/app/global-config.json
- /home/odm3n/dev/work/tycho/.scratch/logs/node-0:/app/logs:rw
networks:
default:
ipam:
config:
- subnet: 172.30.0.0/24
4 changes: 2 additions & 2 deletions block-util/src/archive_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl ArchivePackageVerifier {
part.as_ptr().add(offset),
buffer.as_mut_ptr().add(*filled),
remaining,
)
);
};

offset += remaining;
Expand Down Expand Up @@ -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
const ARCHIVE_ENTRY_HEADER_LEN: usize = ARCHIVE_ENTRY_PREFIX.len() + 2 + 4; // magic + filename len + data len
8 changes: 4 additions & 4 deletions block-util/src/block.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
8 changes: 4 additions & 4 deletions block-util/src/block_proof.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion block-util/src/mapped_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u8>().add(offset),
buffer.len(),
)
}
Expand Down
30 changes: 15 additions & 15 deletions block-util/src/stored_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self>
where
Self: Sized;
where
Self: Sized;

/// Deserializes the data from the buffer.
///
/// [`StoredValue::deserialize`]
#[inline(always)]
fn from_slice(mut data: &[u8]) -> Result<Self>
where
Self: Sized,
where
Self: Sized,
{
Self::deserialize(&mut data)
}
Expand Down Expand Up @@ -64,8 +64,8 @@ impl StoredValueBuffer for Vec<u8> {
}

impl<T> StoredValueBuffer for SmallVec<T>
where
T: smallvec::Array<Item = u8>,
where
T: smallvec::Array<Item = u8>,
{
#[inline(always)]
fn write_byte(&mut self, byte: u8) {
Expand Down Expand Up @@ -96,8 +96,8 @@ impl StoredValue for BlockId {
}

fn deserialize(reader: &mut &[u8]) -> Result<Self>
where
Self: Sized,
where
Self: Sized,
{
let shard = ShardIdent::deserialize(reader)?;
let seqno = reader.get_u32();
Expand Down Expand Up @@ -131,8 +131,8 @@ impl StoredValue for ShardIdent {
}

fn deserialize(reader: &mut &[u8]) -> Result<Self>
where
Self: Sized,
where
Self: Sized,
{
let workchain = reader.get_u32() as i32;
let prefix = reader.get_u64();
Expand All @@ -154,16 +154,16 @@ impl StoredValue for BlockIdShort {
}

fn deserialize(reader: &mut &[u8]) -> Result<Self>
where
Self: Sized,
where
Self: Sized,
{
let shard = ShardIdent::deserialize(reader)?;
let seqno = reader.get_u32();
Ok(Self { shard, seqno })
}
}

/// 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 @@ -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<BlockId> {
if data.len() < 80 {
return None;
Expand Down Expand Up @@ -238,4 +238,4 @@ mod tests {

assert_eq!(read_block_id_le(&serialized).unwrap(), block_id);
}
}
}
10 changes: 5 additions & 5 deletions storage/src/block_handle_storage/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion storage/src/block_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion storage/src/db/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ impl VersionProvider for NodeStateVersionProvider {
state.insert(Self::DB_VERSION_KEY, version)?;
Ok(())
}
}
}
4 changes: 2 additions & 2 deletions storage/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Db {
let cf = db.instantiate_table::<T>();
let res: (usize, usize) = cf
.iterator(rocksdb::IteratorMode::Start)
.flat_map(|x| {
.filter_map(|x| {
let x = match x {
Ok(x) => x,
Err(e) => {
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion storage/src/db/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions storage/src/models/block_handle.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
14 changes: 7 additions & 7 deletions storage/src/models/block_meta.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion storage/src/runtime_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ impl RuntimeStorage {
pub fn persistent_state_keeper(&self) -> &PersistentStateKeeper {
&self.persistent_state_keeper
}
}
}
2 changes: 1 addition & 1 deletion storage/src/runtime_storage/persistent_state_keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
4 changes: 2 additions & 2 deletions storage/src/shard_state_storage/cell_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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::<u8>();
unsafe { std::ptr::copy_nonoverlapping(buffer.as_ptr().add(offset), slot, 32) };
offset += 32;
}
Expand Down
2 changes: 1 addition & 1 deletion storage/src/shard_state_storage/cell_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn write_rev_cells<P: AsRef<Path>>(

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)));
}
}
Expand Down
Loading

0 comments on commit 908b965

Please sign in to comment.