mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(clippy): enable if_then_some_else_none lint (#11679)
Signed-off-by: jsvisa <delweng@gmail.com> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -186,6 +186,7 @@ explicit_iter_loop = "warn"
|
||||
flat_map_option = "warn"
|
||||
from_iter_instead_of_collect = "warn"
|
||||
if_not_else = "warn"
|
||||
if_then_some_else_none = "warn"
|
||||
implicit_clone = "warn"
|
||||
imprecise_flops = "warn"
|
||||
iter_on_empty_collections = "warn"
|
||||
|
||||
@ -297,11 +297,8 @@ impl ChainSpec {
|
||||
};
|
||||
|
||||
// If Prague is activated at genesis we set requests root to an empty trie root.
|
||||
let requests_root = if self.is_prague_active_at_timestamp(self.genesis.timestamp) {
|
||||
Some(EMPTY_ROOT_HASH)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let requests_root =
|
||||
self.is_prague_active_at_timestamp(self.genesis.timestamp).then_some(EMPTY_ROOT_HASH);
|
||||
|
||||
Header {
|
||||
gas_limit: self.genesis.gas_limit,
|
||||
|
||||
@ -282,17 +282,13 @@ impl StorageInner {
|
||||
parent.next_block_base_fee(chain_spec.base_fee_params_at_timestamp(timestamp))
|
||||
});
|
||||
|
||||
let blob_gas_used = if chain_spec.is_cancun_active_at_timestamp(timestamp) {
|
||||
let mut sum_blob_gas_used = 0;
|
||||
for tx in transactions {
|
||||
if let Some(blob_tx) = tx.transaction.as_eip4844() {
|
||||
sum_blob_gas_used += blob_tx.blob_gas();
|
||||
}
|
||||
}
|
||||
Some(sum_blob_gas_used)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let blob_gas_used = chain_spec.is_cancun_active_at_timestamp(timestamp).then(|| {
|
||||
transactions
|
||||
.iter()
|
||||
.filter_map(|tx| tx.transaction.as_eip4844())
|
||||
.map(|blob_tx| blob_tx.blob_gas())
|
||||
.sum::<u64>()
|
||||
});
|
||||
|
||||
let mut header = Header {
|
||||
parent_hash: self.best_hash,
|
||||
@ -304,7 +300,7 @@ impl StorageInner {
|
||||
gas_limit: chain_spec.max_gas_limit(),
|
||||
timestamp,
|
||||
base_fee_per_gas,
|
||||
blob_gas_used: blob_gas_used.map(Into::into),
|
||||
blob_gas_used,
|
||||
requests_root: requests.map(|r| proofs::calculate_requests_root(&r.0)),
|
||||
..Default::default()
|
||||
};
|
||||
@ -316,14 +312,10 @@ impl StorageInner {
|
||||
header.blob_gas_used = Some(0);
|
||||
|
||||
let (parent_excess_blob_gas, parent_blob_gas_used) = match parent {
|
||||
Some(parent_block)
|
||||
if chain_spec.is_cancun_active_at_timestamp(parent_block.timestamp) =>
|
||||
{
|
||||
(
|
||||
parent_block.excess_blob_gas.unwrap_or_default(),
|
||||
parent_block.blob_gas_used.unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
Some(parent) if chain_spec.is_cancun_active_at_timestamp(parent.timestamp) => (
|
||||
parent.excess_blob_gas.unwrap_or_default(),
|
||||
parent.blob_gas_used.unwrap_or_default(),
|
||||
),
|
||||
_ => (0, 0),
|
||||
};
|
||||
header.excess_blob_gas =
|
||||
|
||||
@ -212,14 +212,12 @@ where
|
||||
let block = payload.block();
|
||||
|
||||
let cancun_fields =
|
||||
if self.provider.chain_spec().is_cancun_active_at_timestamp(block.timestamp) {
|
||||
Some(CancunPayloadFields {
|
||||
self.provider.chain_spec().is_cancun_active_at_timestamp(block.timestamp).then(|| {
|
||||
CancunPayloadFields {
|
||||
parent_beacon_block_root: block.parent_beacon_block_root.unwrap(),
|
||||
versioned_hashes: block.blob_versioned_hashes().into_iter().copied().collect(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
self.to_engine.send(BeaconEngineMessage::NewPayload {
|
||||
|
||||
@ -31,16 +31,14 @@ where
|
||||
timestamp,
|
||||
prev_randao: B256::random(),
|
||||
suggested_fee_recipient: Address::random(),
|
||||
withdrawals: if self.chain_spec.is_shanghai_active_at_timestamp(timestamp) {
|
||||
Some(Default::default())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
parent_beacon_block_root: if self.chain_spec.is_cancun_active_at_timestamp(timestamp) {
|
||||
Some(B256::random())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
withdrawals: self
|
||||
.chain_spec
|
||||
.is_shanghai_active_at_timestamp(timestamp)
|
||||
.then(Default::default),
|
||||
parent_beacon_block_root: self
|
||||
.chain_spec
|
||||
.is_cancun_active_at_timestamp(timestamp)
|
||||
.then(B256::random),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,17 +134,10 @@ impl ConfigureEvmEnv for EthEvmConfig {
|
||||
let spec_id = revm_spec_by_timestamp_after_merge(&self.chain_spec, attributes.timestamp);
|
||||
|
||||
// if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is
|
||||
// cancun now, we need to set the excess blob gas to the default value
|
||||
// cancun now, we need to set the excess blob gas to the default value(0)
|
||||
let blob_excess_gas_and_price = parent
|
||||
.next_block_excess_blob_gas()
|
||||
.or_else(|| {
|
||||
if spec_id == SpecId::CANCUN {
|
||||
// default excess blob gas is zero
|
||||
Some(0)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.or_else(|| (spec_id == SpecId::CANCUN).then_some(0))
|
||||
.map(BlobExcessGasAndPrice::new);
|
||||
|
||||
let mut basefee = parent.next_block_base_fee(
|
||||
|
||||
@ -42,7 +42,7 @@ impl<T: Hash + Eq + fmt::Debug> LruCache<T> {
|
||||
pub fn insert_and_get_evicted(&mut self, entry: T) -> (bool, Option<T>) {
|
||||
let new = self.inner.peek(&entry).is_none();
|
||||
let evicted =
|
||||
if new && (self.limit as usize) <= self.inner.len() { self.remove_lru() } else { None };
|
||||
(new && (self.limit as usize) <= self.inner.len()).then(|| self.remove_lru()).flatten();
|
||||
_ = self.inner.get_or_insert(entry, || ());
|
||||
|
||||
(new, evicted)
|
||||
|
||||
@ -185,15 +185,15 @@ impl HeadersClient for TestFullBlockClient {
|
||||
.filter_map(|_| {
|
||||
headers.iter().find_map(|(hash, header)| {
|
||||
// Checks if the header matches the specified block or number.
|
||||
if BlockNumHash::new(header.number, *hash).matches_block_or_num(&block) {
|
||||
BlockNumHash::new(header.number, *hash).matches_block_or_num(&block).then(
|
||||
|| {
|
||||
match request.direction {
|
||||
HeadersDirection::Falling => block = header.parent_hash.into(),
|
||||
HeadersDirection::Rising => block = (header.number + 1).into(),
|
||||
}
|
||||
Some(header.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
header.clone()
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@ -78,7 +78,7 @@ impl LogArgs {
|
||||
format,
|
||||
self.verbosity.directive().to_string(),
|
||||
filter,
|
||||
if use_color { Some(self.color.to_string()) } else { None },
|
||||
use_color.then(|| self.color.to_string()),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -139,17 +139,10 @@ impl ConfigureEvmEnv for OptimismEvmConfig {
|
||||
let spec_id = revm_spec_by_timestamp_after_bedrock(&self.chain_spec, attributes.timestamp);
|
||||
|
||||
// if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is
|
||||
// cancun now, we need to set the excess blob gas to the default value
|
||||
// cancun now, we need to set the excess blob gas to the default value(0)
|
||||
let blob_excess_gas_and_price = parent
|
||||
.next_block_excess_blob_gas()
|
||||
.or_else(|| {
|
||||
if spec_id.is_enabled_in(SpecId::CANCUN) {
|
||||
// default excess blob gas is zero
|
||||
Some(0)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.or_else(|| (spec_id.is_enabled_in(SpecId::CANCUN)).then_some(0))
|
||||
.map(BlobExcessGasAndPrice::new);
|
||||
|
||||
let block_env = BlockEnv {
|
||||
|
||||
@ -267,11 +267,7 @@ mod tests {
|
||||
let mut receipt = random_receipt(&mut rng, transaction, Some(1));
|
||||
receipt.logs.push(random_log(
|
||||
&mut rng,
|
||||
if txi == (block.body.transactions.len() - 1) {
|
||||
Some(deposit_contract_addr)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
(txi == (block.body.transactions.len() - 1)).then_some(deposit_contract_addr),
|
||||
Some(1),
|
||||
));
|
||||
receipts.push((receipts.len() as u64, receipt));
|
||||
|
||||
@ -415,7 +415,7 @@ pub trait LoadPendingBlock: EthApiTypes {
|
||||
|
||||
// check if cancun is activated to set eip4844 header fields correctly
|
||||
let blob_gas_used =
|
||||
if cfg.handler_cfg.spec_id >= SpecId::CANCUN { Some(sum_blob_gas_used) } else { None };
|
||||
(cfg.handler_cfg.spec_id >= SpecId::CANCUN).then_some(sum_blob_gas_used);
|
||||
|
||||
// note(onbjerg): the rpc spec has not been changed to include requests, so for now we just
|
||||
// set these to empty
|
||||
|
||||
@ -39,13 +39,11 @@ impl Compact for AccountBeforeTx {
|
||||
let address = Address::from_slice(&buf[..20]);
|
||||
buf.advance(20);
|
||||
|
||||
let info = if len - 20 > 0 {
|
||||
let info = (len - 20 > 0).then(|| {
|
||||
let (acc, advanced_buf) = Account::from_compact(buf, len - 20);
|
||||
buf = advanced_buf;
|
||||
Some(acc)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
acc
|
||||
});
|
||||
|
||||
(Self { address, info }, buf)
|
||||
}
|
||||
|
||||
@ -256,10 +256,9 @@ impl DatabaseEnv {
|
||||
args: DatabaseArguments,
|
||||
) -> Result<Self, DatabaseError> {
|
||||
let _lock_file = if kind.is_rw() {
|
||||
Some(
|
||||
StorageLock::try_acquire(path)
|
||||
.map_err(|err| DatabaseError::Other(err.to_string()))?,
|
||||
)
|
||||
.map_err(|err| DatabaseError::Other(err.to_string()))?
|
||||
.into()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
@ -542,18 +542,18 @@ impl<TX: DbTx, Spec: Send + Sync> DatabaseProvider<TX, Spec> {
|
||||
// even if empty
|
||||
let withdrawals =
|
||||
if self.chain_spec.is_shanghai_active_at_timestamp(header_ref.timestamp) {
|
||||
Some(
|
||||
withdrawals_cursor
|
||||
.seek_exact(header_ref.number)?
|
||||
.map(|(_, w)| w.withdrawals)
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.unwrap_or_default()
|
||||
.into()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let requests =
|
||||
if self.chain_spec.is_prague_active_at_timestamp(header_ref.timestamp) {
|
||||
Some(requests_cursor.seek_exact(header_ref.number)?.unwrap_or_default().1)
|
||||
(requests_cursor.seek_exact(header_ref.number)?.unwrap_or_default().1)
|
||||
.into()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
@ -222,7 +222,7 @@ impl StaticFileProviderInner {
|
||||
/// Creates a new [`StaticFileProviderInner`].
|
||||
fn new(path: impl AsRef<Path>, access: StaticFileAccess) -> ProviderResult<Self> {
|
||||
let _lock_file = if access.is_read_write() {
|
||||
Some(StorageLock::try_acquire(path.as_ref())?)
|
||||
StorageLock::try_acquire(path.as_ref())?.into()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
@ -289,16 +289,16 @@ impl StaticFileProviderRW {
|
||||
//
|
||||
// If that expected block start is 0, then it means that there's no actual block data, and
|
||||
// there's no block data in static files.
|
||||
let segment_max_block = match self.writer.user_header().block_range() {
|
||||
Some(block_range) => Some(block_range.end()),
|
||||
None => {
|
||||
if self.writer.user_header().expected_block_start() > 0 {
|
||||
Some(self.writer.user_header().expected_block_start() - 1)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
let segment_max_block = self
|
||||
.writer
|
||||
.user_header()
|
||||
.block_range()
|
||||
.as_ref()
|
||||
.map(|block_range| block_range.end())
|
||||
.or_else(|| {
|
||||
(self.writer.user_header().expected_block_start() > 0)
|
||||
.then(|| self.writer.user_header().expected_block_start() - 1)
|
||||
});
|
||||
|
||||
self.reader().update_index(self.writer.user_header().segment(), segment_max_block)
|
||||
}
|
||||
|
||||
@ -344,13 +344,8 @@ impl TransactionsProvider for MockEthProvider {
|
||||
.values()
|
||||
.flat_map(|block| &block.body.transactions)
|
||||
.enumerate()
|
||||
.filter_map(|(tx_number, tx)| {
|
||||
if range.contains(&(tx_number as TxNumber)) {
|
||||
Some(tx.clone().into())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.filter(|&(tx_number, _)| range.contains(&(tx_number as TxNumber)))
|
||||
.map(|(_, tx)| tx.clone().into())
|
||||
.collect();
|
||||
|
||||
Ok(transactions)
|
||||
@ -366,11 +361,7 @@ impl TransactionsProvider for MockEthProvider {
|
||||
.flat_map(|block| &block.body.transactions)
|
||||
.enumerate()
|
||||
.filter_map(|(tx_number, tx)| {
|
||||
if range.contains(&(tx_number as TxNumber)) {
|
||||
Some(tx.recover_signer()?)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
range.contains(&(tx_number as TxNumber)).then(|| tx.recover_signer()).flatten()
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
@ -455,11 +455,10 @@ impl FinalizedBlockTracker {
|
||||
/// Updates the tracked finalized block and returns the new finalized block if it changed
|
||||
fn update(&mut self, finalized_block: Option<BlockNumber>) -> Option<BlockNumber> {
|
||||
let finalized = finalized_block?;
|
||||
if self.last_finalized_block.replace(finalized).map_or(true, |last| last < finalized) {
|
||||
Some(finalized)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.last_finalized_block
|
||||
.replace(finalized)
|
||||
.map_or(true, |last| last < finalized)
|
||||
.then_some(finalized)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -51,16 +51,14 @@ impl Compact for StoredSubNode {
|
||||
buf.advance(key_len);
|
||||
|
||||
let nibbles_exists = buf.get_u8() != 0;
|
||||
let nibble = if nibbles_exists { Some(buf.get_u8()) } else { None };
|
||||
let nibble = nibbles_exists.then(|| buf.get_u8());
|
||||
|
||||
let node_exists = buf.get_u8() != 0;
|
||||
let node = if node_exists {
|
||||
let node = node_exists.then(|| {
|
||||
let (node, rest) = BranchNodeCompact::from_compact(buf, 0);
|
||||
buf = rest;
|
||||
Some(node)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
node
|
||||
});
|
||||
|
||||
(Self { key, nibble, node }, buf)
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ impl From<StoredSubNode> for CursorSubNode {
|
||||
|
||||
impl From<CursorSubNode> for StoredSubNode {
|
||||
fn from(value: CursorSubNode) -> Self {
|
||||
let nibble = if value.nibble >= 0 { Some(value.nibble as u8) } else { None };
|
||||
let nibble = (value.nibble >= 0).then_some(value.nibble as u8);
|
||||
Self { key: value.key.to_vec(), nibble, node: value.node }
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,14 +111,13 @@ where
|
||||
.accounts
|
||||
.get(&hashed_address)
|
||||
.ok_or(TrieWitnessError::MissingAccount(hashed_address))?;
|
||||
let value = if account.is_some() || storage_multiproof.root != EMPTY_ROOT_HASH {
|
||||
let value =
|
||||
(account.is_some() || storage_multiproof.root != EMPTY_ROOT_HASH).then(|| {
|
||||
account_rlp.clear();
|
||||
TrieAccount::from((account.unwrap_or_default(), storage_multiproof.root))
|
||||
.encode(&mut account_rlp as &mut dyn BufMut);
|
||||
Some(account_rlp.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
account_rlp.clone()
|
||||
});
|
||||
let key = Nibbles::unpack(hashed_address);
|
||||
account_trie_nodes.extend(
|
||||
self.target_nodes(
|
||||
|
||||
Reference in New Issue
Block a user