Skip to content

Commit

Permalink
chore: fix clippy for version 0.1.81 (#2371)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Dec 1, 2024
1 parent 1b8e0ef commit 2224fdb
Show file tree
Hide file tree
Showing 29 changed files with 46 additions and 51 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/src/concurrency/worker_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl<'a, S: StateReader> WorkerExecutor<'a, S> {
}
}

impl<'a, U: UpdatableState> WorkerExecutor<'a, U> {
impl<U: UpdatableState> WorkerExecutor<'_, U> {
pub fn commit_chunk_and_recover_block_state(
self,
n_committed_txs: usize,
Expand Down
6 changes: 1 addition & 5 deletions crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,7 @@ impl EntryPointExecutionContext {
// would cause underflow error.
// Logically, we update remaining steps to `max(0, remaining_steps - steps_to_subtract)`.
let remaining_steps = self.n_remaining_steps();
let new_remaining_steps = if remaining_steps < steps_to_subtract {
0
} else {
remaining_steps - steps_to_subtract
};
let new_remaining_steps = remaining_steps.saturating_sub(steps_to_subtract);
self.vm_run_resources = RunResources::new(new_remaining_steps);
self.n_remaining_steps()
}
Expand Down
1 change: 0 additions & 1 deletion crates/blockifier/src/execution/syscalls/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ impl SyscallExecutionError {
}

/// Error codes returned by Cairo 1.0 code.
// "Out of gas";
pub const OUT_OF_GAS_ERROR: &str =
"0x000000000000000000000000000000000000000000004f7574206f6620676173";
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/execution/syscalls/syscall_base.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// This file is for sharing common logic between Native and VM syscall implementations.
use std::collections::{hash_map, HashMap, HashSet};
use std::convert::From;

Expand Down Expand Up @@ -30,8 +31,6 @@ use crate::transaction::account_transaction::is_cairo1;
pub type SyscallResult<T> = Result<T, SyscallExecutionError>;
pub const KECCAK_FULL_RATE_IN_WORDS: usize = 17;

/// This file is for sharing common logic between Native and VM syscall implementations.
pub struct SyscallHandlerBase<'state> {
// Input for execution.
pub state: &'state mut dyn State,
Expand Down
8 changes: 2 additions & 6 deletions crates/blockifier/src/fee/gas_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ pub fn get_da_gas_cost(state_changes_count: &StateChangesCount, use_kzg_da: bool
let fee_balance_value_cost = eth_gas_constants::get_calldata_word_cost(12);
discount += eth_gas_constants::GAS_PER_MEMORY_WORD - fee_balance_value_cost;

let gas = if naive_cost < discount {
// Cost must be non-negative after discount.
0
} else {
naive_cost - discount
};
// Cost must be non-negative after discount.
let gas = naive_cost.saturating_sub(discount);

(u64_from_usize(gas).into(), 0_u8.into())
};
Expand Down
6 changes: 3 additions & 3 deletions crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ impl<'a, S: StateReader + ?Sized> MutRefState<'a, S> {
}

/// Proxies inner object to expose `State` functionality.
impl<'a, S: StateReader + ?Sized> StateReader for MutRefState<'a, S> {
impl<S: StateReader + ?Sized> StateReader for MutRefState<'_, S> {
fn get_storage_at(
&self,
contract_address: ContractAddress,
Expand Down Expand Up @@ -535,7 +535,7 @@ impl<'a, S: StateReader + ?Sized> StateReader for MutRefState<'a, S> {

pub type TransactionalState<'a, U> = CachedState<MutRefState<'a, U>>;

impl<'a, S: StateReader> TransactionalState<'a, S> {
impl<S: StateReader> TransactionalState<'_, S> {
/// Creates a transactional instance from the given updatable state.
/// It allows performing buffered modifying actions on the given state, which
/// will either all happen (will be updated in the state and committed)
Expand All @@ -549,7 +549,7 @@ impl<'a, S: StateReader> TransactionalState<'a, S> {
}

/// Adds the ability to perform a transactional execution.
impl<'a, U: UpdatableState> TransactionalState<'a, U> {
impl<U: UpdatableState> TransactionalState<'_, U> {
/// Commits changes in the child (wrapping) state to its parent.
pub fn commit(self) {
let state = self.state.0;
Expand Down
2 changes: 1 addition & 1 deletion crates/committer_cli/src/tests/python_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl TryFrom<String> for PythonTest {
impl PythonTest {
/// Returns the input string if it's `Some`, or an error if it's `None`.
pub fn non_optional_input(input: Option<&str>) -> Result<&str, PythonTestError> {
input.ok_or_else(|| PythonTestError::NoneInputError)
input.ok_or(PythonTestError::NoneInputError)
}

/// Runs the test with the given arguments.
Expand Down
2 changes: 2 additions & 0 deletions crates/native_blockifier/src/py_block_executor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(non_local_definitions)]

use std::collections::HashMap;

use blockifier::abi::constants as abi_constants;
Expand Down
2 changes: 2 additions & 0 deletions crates/native_blockifier/src/py_objects.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(non_local_definitions)]

use std::collections::HashMap;

use blockifier::abi::constants;
Expand Down
2 changes: 2 additions & 0 deletions crates/native_blockifier/src/py_validator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(non_local_definitions)]

use blockifier::blockifier::stateful_validator::{StatefulValidator, StatefulValidatorResult};
use blockifier::bouncer::BouncerConfig;
use blockifier::context::BlockContext;
Expand Down
2 changes: 2 additions & 0 deletions crates/native_blockifier/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(non_local_definitions)]

use std::collections::HashMap;
use std::convert::TryFrom;
use std::path::PathBuf;
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_storage/src/base_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ where
) -> StorageResult<Self>;
}

impl<'env, Mode: TransactionKind> BaseLayerStorageReader for StorageTxn<'env, Mode> {
impl<Mode: TransactionKind> BaseLayerStorageReader for StorageTxn<'_, Mode> {
fn get_base_layer_block_marker(&self) -> StorageResult<BlockNumber> {
let markers_table = self.open_table(&self.tables.markers)?;
Ok(markers_table.get(&self.txn, &MarkerKind::BaseLayerBlock)?.unwrap_or_default())
}
}

impl<'env> BaseLayerStorageWriter for StorageTxn<'env, RW> {
impl BaseLayerStorageWriter for StorageTxn<'_, RW> {
fn update_base_layer_block_marker(self, block_number: &BlockNumber) -> StorageResult<Self> {
let markers_table = self.open_table(&self.tables.markers)?;
markers_table.upsert(&self.txn, &MarkerKind::BaseLayerBlock, block_number)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_storage/src/body/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub struct EventIterByContractAddress<'env, 'txn> {
transaction_metadata_table: TransactionMetadataTable<'env>,
}

impl<'env, 'txn> EventIterByContractAddress<'env, 'txn> {
impl EventIterByContractAddress<'_, '_> {
/// Returns the next event. If there are no more events, returns None.
///
/// # Errors
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_storage/src/body/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ where
) -> StorageResult<(Self, Option<RevertedBlockBody>)>;
}

impl<'env, Mode: TransactionKind> BodyStorageReader for StorageTxn<'env, Mode> {
impl<Mode: TransactionKind> BodyStorageReader for StorageTxn<'_, Mode> {
fn get_body_marker(&self) -> StorageResult<BlockNumber> {
let markers_table = self.open_table(&self.tables.markers)?;
Ok(markers_table.get(&self.txn, &MarkerKind::Body)?.unwrap_or_default())
Expand Down Expand Up @@ -341,7 +341,7 @@ impl<'env, Mode: TransactionKind> StorageTxn<'env, Mode> {
}
}

impl<'env> BodyStorageWriter for StorageTxn<'env, RW> {
impl BodyStorageWriter for StorageTxn<'_, RW> {
#[latency_histogram("storage_append_body_latency_seconds", false)]
fn append_body(self, block_number: BlockNumber, block_body: BlockBody) -> StorageResult<Self> {
let markers_table = self.open_table(&self.tables.markers)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_storage/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ where
) -> StorageResult<Self>;
}

impl<'env, Mode: TransactionKind> ClassStorageReader for StorageTxn<'env, Mode> {
impl<Mode: TransactionKind> ClassStorageReader for StorageTxn<'_, Mode> {
fn get_class(&self, class_hash: &ClassHash) -> StorageResult<Option<SierraContractClass>> {
let declared_classes_table = self.open_table(&self.tables.declared_classes)?;
let contract_class_location = declared_classes_table.get(&self.txn, class_hash)?;
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<'env, Mode: TransactionKind> ClassStorageReader for StorageTxn<'env, Mode>
}
}

impl<'env> ClassStorageWriter for StorageTxn<'env, RW> {
impl ClassStorageWriter for StorageTxn<'_, RW> {
#[latency_histogram("storage_append_classes_latency_seconds", false)]
fn append_classes(
self,
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_storage/src/compiled_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ where
fn append_casm(self, class_hash: &ClassHash, casm: &CasmContractClass) -> StorageResult<Self>;
}

impl<'env, Mode: TransactionKind> CasmStorageReader for StorageTxn<'env, Mode> {
impl<Mode: TransactionKind> CasmStorageReader for StorageTxn<'_, Mode> {
fn get_casm(&self, class_hash: &ClassHash) -> StorageResult<Option<CasmContractClass>> {
let casm_table = self.open_table(&self.tables.casms)?;
let casm_location = casm_table.get(&self.txn, class_hash)?;
Expand All @@ -91,7 +91,7 @@ impl<'env, Mode: TransactionKind> CasmStorageReader for StorageTxn<'env, Mode> {
}
}

impl<'env> CasmStorageWriter for StorageTxn<'env, RW> {
impl CasmStorageWriter for StorageTxn<'_, RW> {
#[latency_histogram("storage_append_casm_latency_seconds", false)]
fn append_casm(self, class_hash: &ClassHash, casm: &CasmContractClass) -> StorageResult<Self> {
let casm_table = self.open_table(&self.tables.casms)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_storage/src/compression_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn serialize_and_compress(object: &impl StorageSerde) -> Result<Vec<u8>, Sto
///
/// # Arguments
/// * data - bytes to decompress.
///
/// # Errors
/// Returns [`std::io::Error`] if any read error is encountered.
pub fn decompress(data: &[u8]) -> Result<Vec<u8>, std::io::Error> {
Expand Down
8 changes: 4 additions & 4 deletions crates/papyrus_storage/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl DbWriter {

type DbWriteTransaction<'env> = DbTransaction<'env, RW>;

impl<'a> DbWriteTransaction<'a> {
impl DbWriteTransaction<'_> {
#[latency_histogram("storage_commit_inner_db_latency_seconds", false)]
pub(crate) fn commit(self) -> DbResult<()> {
self.txn.commit()?;
Expand All @@ -279,7 +279,7 @@ pub(crate) struct DbTransaction<'env, Mode: TransactionKind> {
txn: libmdbx::Transaction<'env, Mode::Internal, EnvironmentKind>,
}

impl<'a, Mode: TransactionKind> DbTransaction<'a, Mode> {
impl<Mode: TransactionKind> DbTransaction<'_, Mode> {
pub fn open_table<'env, K: Key + Debug, V: ValueSerde + Debug, T: TableType>(
&'env self,
table_id: &TableIdentifier<K, V, T>,
Expand Down Expand Up @@ -326,8 +326,8 @@ impl<'cursor, 'txn, Mode: TransactionKind, K: Key, V: ValueSerde, T: TableType>
}
}

impl<'cursor, 'txn, Mode: TransactionKind, K: Key, V: ValueSerde, T: TableType> Iterator
for DbIter<'cursor, 'txn, Mode, K, V, T>
impl<'txn, Mode: TransactionKind, K: Key, V: ValueSerde, T: TableType> Iterator
for DbIter<'_, 'txn, Mode, K, V, T>
where
DbCursor<'txn, Mode, K, V, T>: DbCursorTrait<Key = K, Value = V>,
{
Expand Down
3 changes: 1 addition & 2 deletions crates/papyrus_storage/src/db/table_types/dup_sort_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,11 @@ impl<'env, K: KeyTrait + Debug, V: ValueSerde + Debug, T: DupSortTableType + Dup
}

impl<
'txn,
Mode: TransactionKind,
K: KeyTrait + Debug,
V: ValueSerde + Debug,
T: DupSortTableType + DupSortUtils<K, V>,
> DbCursorTrait for DbCursor<'txn, Mode, K, V, T>
> DbCursorTrait for DbCursor<'_, Mode, K, V, T>
{
type Key = K;
type Value = V;
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_storage/src/db/table_types/simple_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ impl<'env, K: KeyTrait + Debug, V: ValueSerde + Debug> Table<'env>
}
}

impl<'txn, Mode: TransactionKind, K: KeyTrait + Debug, V: ValueSerde + Debug> DbCursorTrait
for DbCursor<'txn, Mode, K, V, SimpleTable>
impl<Mode: TransactionKind, K: KeyTrait + Debug, V: ValueSerde + Debug> DbCursorTrait
for DbCursor<'_, Mode, K, V, SimpleTable>
{
type Key = K;
type Value = V;
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_storage/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ where
) -> StorageResult<Self>;
}

impl<'env, Mode: TransactionKind> HeaderStorageReader for StorageTxn<'env, Mode> {
impl<Mode: TransactionKind> HeaderStorageReader for StorageTxn<'_, Mode> {
fn get_header_marker(&self) -> StorageResult<BlockNumber> {
let markers_table = self.open_table(&self.tables.markers)?;
Ok(markers_table.get(&self.txn, &MarkerKind::Header)?.unwrap_or_default())
Expand Down Expand Up @@ -234,7 +234,7 @@ impl<'env, Mode: TransactionKind> HeaderStorageReader for StorageTxn<'env, Mode>
}
}

impl<'env> HeaderStorageWriter for StorageTxn<'env, RW> {
impl HeaderStorageWriter for StorageTxn<'_, RW> {
fn append_header(
self,
block_number: BlockNumber,
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ pub struct StorageTxn<'env, Mode: TransactionKind> {
scope: StorageScope,
}

impl<'env> StorageTxn<'env, RW> {
impl StorageTxn<'_, RW> {
/// Commits the changes made in the transaction to the storage.
#[latency_histogram("storage_commit_latency_seconds", false)]
pub fn commit(self) -> StorageResult<()> {
Expand All @@ -481,7 +481,7 @@ impl<'env> StorageTxn<'env, RW> {
}
}

impl<'env, Mode: TransactionKind> StorageTxn<'env, Mode> {
impl<Mode: TransactionKind> StorageTxn<'_, Mode> {
pub(crate) fn open_table<K: Key + Debug, V: ValueSerde + Debug, T: TableType>(
&self,
table_id: &TableIdentifier<K, V, T>,
Expand Down
5 changes: 2 additions & 3 deletions crates/papyrus_storage/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ pub(crate) type NoncesTable<'env> =
// block_num.
// * nonces_table: (contract_address, block_num) -> (nonce). Specifies that at `block_num`, the
// nonce of `contract_address` was changed to `nonce`.

pub trait StateStorageReader<Mode: TransactionKind> {
/// The state marker is the first block number that doesn't exist yet.
fn get_state_marker(&self) -> StorageResult<BlockNumber>;
Expand Down Expand Up @@ -159,7 +158,7 @@ where
) -> StorageResult<(Self, Option<RevertedStateDiff>)>;
}

impl<'env, Mode: TransactionKind> StateStorageReader<Mode> for StorageTxn<'env, Mode> {
impl<Mode: TransactionKind> StateStorageReader<Mode> for StorageTxn<'_, Mode> {
// The block number marker is the first block number that doesn't exist yet.
fn get_state_marker(&self) -> StorageResult<BlockNumber> {
let markers_table = self.open_table(&self.tables.markers)?;
Expand Down Expand Up @@ -425,7 +424,7 @@ impl<'env, Mode: TransactionKind> StateReader<'env, Mode> {
}
}

impl<'env> StateStorageWriter for StorageTxn<'env, RW> {
impl StateStorageWriter for StorageTxn<'_, RW> {
#[latency_histogram("storage_append_thin_state_diff_latency_seconds", false)]
fn append_state_diff(
self,
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_storage/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
fn delete_blocks_version(self) -> StorageResult<Self>;
}

impl<'env, Mode: TransactionKind> VersionStorageReader for StorageTxn<'env, Mode> {
impl<Mode: TransactionKind> VersionStorageReader for StorageTxn<'_, Mode> {
fn get_state_version(&self) -> StorageResult<Option<Version>> {
let version_table = self.open_table(&self.tables.storage_version)?;
Ok(version_table.get(&self.txn, &VERSION_STATE_KEY.to_string())?)
Expand All @@ -68,7 +68,7 @@ impl<'env, Mode: TransactionKind> VersionStorageReader for StorageTxn<'env, Mode
}
}

impl<'env> VersionStorageWriter for StorageTxn<'env, RW> {
impl VersionStorageWriter for StorageTxn<'_, RW> {
fn set_state_version(self, version: &Version) -> StorageResult<Self> {
let version_table = self.open_table(&self.tables.storage_version)?;
if let Some(current_storage_version) = self.get_state_version()? {
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn set_events(tx: &mut TransactionOutput, events: Vec<Event>) {
}

//////////////////////////////////////////////////////////////////////////
/// EXTERNAL FUNCTIONS - REMOVE DUPLICATIONS
// EXTERNAL FUNCTIONS - REMOVE DUPLICATIONS
//////////////////////////////////////////////////////////////////////////

// Returns a test block with a variable number of transactions and events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl ConsensusContext for SequencerConsensusContext {
}

async fn set_height_and_round(&mut self, height: BlockNumber, round: Round) {
if self.current_height.is_none_or(|h| height > h) {
if self.current_height.map(|h| height > h).unwrap_or(true) {
self.current_height = Some(height);
assert_eq!(round, 0);
self.current_round = round;
Expand Down
1 change: 0 additions & 1 deletion crates/starknet_api/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ impl ChainId {
/// The address of a contract, used for example in [StateDiff](`crate::state::StateDiff`),
/// [DeclareTransaction](`crate::transaction::DeclareTransaction`), and
/// [BlockHeader](`crate::block::BlockHeader`).
// The block hash table is stored in address 0x1,
// this is a special address that is not used for contracts.
pub const BLOCK_HASH_TABLE_ADDRESS: ContractAddress = ContractAddress(PatriciaKey(StarkHash::ONE));
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_client/src/test_utils/read_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ use starknet_api::test_utils::path_in_resources;

pub fn read_resource_file(path_in_resource_dir: &str) -> String {
let path = path_in_resources(path_in_resource_dir);
return read_to_string(path.to_str().unwrap()).unwrap();
read_to_string(path.to_str().unwrap()).unwrap()
}
2 changes: 1 addition & 1 deletion crates/starknet_task_executor/src/tokio_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl TaskExecutor for TokioExecutor {

/// Spawns a task that may block, on a dedicated thread, preventing disruption of the async
/// runtime.
///
/// # Example
///
/// ```
Expand Down

0 comments on commit 2224fdb

Please sign in to comment.