Skip to content

Commit

Permalink
chore: fix clippy errors (#9845)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
nkysg and mattsse authored Jul 27, 2024
1 parent 1ffa3d1 commit 7df4245
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 38 deletions.
8 changes: 4 additions & 4 deletions bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ impl Command {
debug!(target: "reth::cli", bytes = ?tx_bytes, "Decoding transaction");
let transaction = TransactionSigned::decode(&mut &Bytes::from_str(tx_bytes)?[..])?
.into_ecrecovered()
.ok_or(eyre::eyre!("failed to recover tx"))?;
.ok_or_else(|| eyre::eyre!("failed to recover tx"))?;

let encoded_length = match &transaction.transaction {
Transaction::Eip4844(TxEip4844 { blob_versioned_hashes, .. }) => {
let blobs_bundle = blobs_bundle.as_mut().ok_or(eyre::eyre!(
"encountered a blob tx. `--blobs-bundle-path` must be provided"
))?;
let blobs_bundle = blobs_bundle.as_mut().ok_or_else(|| {
eyre::eyre!("encountered a blob tx. `--blobs-bundle-path` must be provided")
})?;

let sidecar: BlobTransactionSidecar =
blobs_bundle.pop_sidecar(blob_versioned_hashes.len());
Expand Down
4 changes: 3 additions & 1 deletion bin/reth/src/commands/debug_cmd/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ impl Command {
storage_writer.write_to_storage(execution_outcome, OriginalValuesKnown::Yes)?;

let checkpoint = Some(StageCheckpoint::new(
block_number.checked_sub(1).ok_or(eyre::eyre!("GenesisBlockHasNoParent"))?,
block_number
.checked_sub(1)
.ok_or_else(|| eyre::eyre!("GenesisBlockHasNoParent"))?,
));

let mut account_hashing_done = false;
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ impl TreeState {

/// Returns the maximum block number stored.
pub(crate) fn max_block_number(&self) -> BlockNumber {
*self.blocks_by_number.last_key_value().unwrap_or((&BlockNumber::default(), &vec![])).0
self.blocks_by_number.last_key_value().map(|e| *e.0).unwrap_or_default()
}

/// Returns the minimum block number stored.
pub(crate) fn min_block_number(&self) -> BlockNumber {
*self.blocks_by_number.first_key_value().unwrap_or((&BlockNumber::default(), &vec![])).0
self.blocks_by_number.first_key_value().map(|e| *e.0).unwrap_or_default()
}

/// Returns the block number of the pending block: `head + 1`
Expand Down
4 changes: 2 additions & 2 deletions crates/exex/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ pub async fn test_exex_context_with_chain_spec(

let genesis = provider_factory
.block_by_hash(genesis_hash)?
.ok_or(eyre::eyre!("genesis block not found"))?
.ok_or_else(|| eyre::eyre!("genesis block not found"))?
.seal_slow()
.seal_with_senders()
.ok_or(eyre::eyre!("failed to recover senders"))?;
.ok_or_else(|| eyre::eyre!("failed to recover senders"))?;

let head = Head {
number: genesis.number,
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl NetworkConfigBuilder {
hello_message.unwrap_or_else(|| HelloMessage::builder(peer_id).build());
hello_message.port = listener_addr.port();

let head = head.unwrap_or(Head {
let head = head.unwrap_or_else(|| Head {
hash: chain_spec.genesis_hash(),
number: 0,
timestamp: chain_spec.genesis.timestamp,
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/cli/src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl ImportOpCommand {
"Importing chain file chunk"
);

let tip = file_client.tip().ok_or(eyre::eyre!("file client has no tip"))?;
let tip = file_client.tip().ok_or_else(|| eyre::eyre!("file client has no tip"))?;
info!(target: "reth::cli", "Chain file chunk read");

total_decoded_blocks += file_client.headers_len();
Expand Down
44 changes: 22 additions & 22 deletions crates/optimism/evm/src/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn extract_l1_info(block: &Block) -> Result<L1BlockInfo, OptimismBlockExecut
let l1_info_tx_data = block
.body
.first()
.ok_or(OptimismBlockExecutionError::L1BlockInfoError {
.ok_or_else(|| OptimismBlockExecutionError::L1BlockInfoError {
message: "could not find l1 block info tx in the L2 block".to_string(),
})
.map(|tx| tx.input())?;
Expand Down Expand Up @@ -71,21 +71,21 @@ pub fn parse_l1_info_tx_bedrock(data: &[u8]) -> Result<L1BlockInfo, OptimismBloc
})
}

let l1_base_fee = U256::try_from_be_slice(&data[64..96]).ok_or(
let l1_base_fee = U256::try_from_be_slice(&data[64..96]).ok_or_else(|| {
OptimismBlockExecutionError::L1BlockInfoError {
message: "could not convert l1 base fee".to_string(),
},
)?;
let l1_fee_overhead = U256::try_from_be_slice(&data[192..224]).ok_or(
}
})?;
let l1_fee_overhead = U256::try_from_be_slice(&data[192..224]).ok_or_else(|| {
OptimismBlockExecutionError::L1BlockInfoError {
message: "could not convert l1 fee overhead".to_string(),
},
)?;
let l1_fee_scalar = U256::try_from_be_slice(&data[224..256]).ok_or(
}
})?;
let l1_fee_scalar = U256::try_from_be_slice(&data[224..256]).ok_or_else(|| {
OptimismBlockExecutionError::L1BlockInfoError {
message: "could not convert l1 fee scalar".to_string(),
},
)?;
}
})?;

let mut l1block = L1BlockInfo::default();
l1block.l1_base_fee = l1_base_fee;
Expand Down Expand Up @@ -117,26 +117,26 @@ pub fn parse_l1_info_tx_ecotone(data: &[u8]) -> Result<L1BlockInfo, OptimismBloc
})
}

let l1_blob_base_fee_scalar = U256::try_from_be_slice(&data[8..12]).ok_or(
let l1_blob_base_fee_scalar = U256::try_from_be_slice(&data[8..12]).ok_or_else(|| {
OptimismBlockExecutionError::L1BlockInfoError {
message: "could not convert l1 blob base fee scalar".to_string(),
},
)?;
let l1_base_fee_scalar = U256::try_from_be_slice(&data[12..16]).ok_or(
}
})?;
let l1_base_fee_scalar = U256::try_from_be_slice(&data[12..16]).ok_or_else(|| {
OptimismBlockExecutionError::L1BlockInfoError {
message: "could not convert l1 base fee scalar".to_string(),
},
)?;
let l1_base_fee = U256::try_from_be_slice(&data[32..64]).ok_or(
}
})?;
let l1_base_fee = U256::try_from_be_slice(&data[32..64]).ok_or_else(|| {
OptimismBlockExecutionError::L1BlockInfoError {
message: "could not convert l1 blob base fee".to_string(),
},
)?;
let l1_blob_base_fee = U256::try_from_be_slice(&data[64..96]).ok_or(
}
})?;
let l1_blob_base_fee = U256::try_from_be_slice(&data[64..96]).ok_or_else(|| {
OptimismBlockExecutionError::L1BlockInfoError {
message: "could not convert l1 blob base fee".to_string(),
},
)?;
}
})?;

let mut l1block = L1BlockInfo::default();
l1block.l1_base_fee = l1_base_fee;
Expand Down
6 changes: 4 additions & 2 deletions crates/stages/stages/src/stages/sender_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ impl<DB: Database> Stage<DB> for SenderRecoveryStage {
info!(target: "sync::stages::sender_recovery", ?tx_range, "Recovering senders");

// Iterate over transactions in batches, recover the senders and append them
let batch = (tx_range.start..tx_range.end)
let batch = tx_range
.clone()
.step_by(BATCH_SIZE)
.map(|start| start..std::cmp::min(start + BATCH_SIZE as u64, tx_range.end))
.collect::<Vec<Range<u64>>>();
Expand Down Expand Up @@ -140,7 +141,8 @@ where
debug!(target: "sync::stages::sender_recovery", ?tx_range, "Recovering senders batch");

// Preallocate channels
let (chunks, receivers): (Vec<_>, Vec<_>) = (tx_range.start..tx_range.end)
let (chunks, receivers): (Vec<_>, Vec<_>) = tx_range
.clone()
.step_by(WORKER_CHUNK_SIZE)
.map(|start| {
let range = start..std::cmp::min(start + WORKER_CHUNK_SIZE as u64, tx_range.end);
Expand Down
4 changes: 2 additions & 2 deletions crates/storage/provider/src/providers/static_file/jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a> HeaderProvider for StaticFileJarProvider<'a> {
let mut cursor = self.cursor()?;
let mut headers = Vec::with_capacity((range.end - range.start) as usize);

for num in range.start..range.end {
for num in range {
if let Some(header) = cursor.get_one::<HeaderMask<Header>>(num.into())? {
headers.push(header);
}
Expand All @@ -131,7 +131,7 @@ impl<'a> HeaderProvider for StaticFileJarProvider<'a> {
let mut cursor = self.cursor()?;
let mut headers = Vec::with_capacity((range.end - range.start) as usize);

for number in range.start..range.end {
for number in range {
if let Some((header, hash)) =
cursor.get_two::<HeaderMask<Header, BlockHash>>(number.into())?
{
Expand Down
3 changes: 2 additions & 1 deletion crates/storage/provider/src/providers/static_file/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,8 @@ impl TransactionsProviderExt for StaticFileProvider {
let mut channels = Vec::new();

// iterator over the chunks
let chunks = (tx_range.start..tx_range.end)
let chunks = tx_range
.clone()
.step_by(chunk_size)
.map(|start| start..std::cmp::min(start + chunk_size as u64, tx_range.end));

Expand Down

0 comments on commit 7df4245

Please sign in to comment.