Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions crates/executor/src/blockchain_tree/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,10 @@ impl Chain {
let chain_tip = *self.blocks.last_entry().expect("chain is never empty").key();
let block_number = match split_at {
SplitAt::Hash(block_hash) => {
let block_number = self.blocks.iter().find_map(|(num, block)| {
if block.hash() == block_hash {
Some(*num)
} else {
None
}
});
let block_number = self
.blocks
.iter()
.find_map(|(num, block)| (block.hash() == block_hash).then_some(*num));
let Some(block_number) = block_number else { return ChainSplit::NoSplitPending(self)};
// If block number is same as tip whole chain is becoming canonical.
if block_number == chain_tip {
Expand Down
6 changes: 1 addition & 5 deletions crates/executor/src/blockchain_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,7 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
}
break
}
if self.block_indices.canonical_hash(&fork.number) == Some(fork.hash) {
Some(fork)
} else {
None
}
(self.block_indices.canonical_hash(&fork.number) == Some(fork.hash)).then_some(fork)
}

/// Insert a chain into the tree.
Expand Down
6 changes: 1 addition & 5 deletions crates/net/discv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,7 @@ impl Discv4Service {

/// Returns the current enr sequence
fn enr_seq(&self) -> Option<u64> {
if self.config.enable_eip868 {
Some(self.local_eip_868_enr.seq())
} else {
None
}
(self.config.enable_eip868).then(|| self.local_eip_868_enr.seq())
}

/// Sets the [Interval] used for periodically looking up targets over the network
Expand Down
17 changes: 7 additions & 10 deletions crates/net/discv4/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,14 @@ impl Stream for MockDiscovery {
let this = self.get_mut();
// process all incoming commands
while let Poll::Ready(maybe_cmd) = this.command_rx.poll_recv(cx) {
if let Some(cmd) = maybe_cmd {
match cmd {
MockCommand::MockPong { node_id } => {
this.queue_pong(node_id);
}
MockCommand::MockNeighbours { target, nodes } => {
this.queue_neighbours(target, nodes);
}
let Some(cmd) = maybe_cmd else { return Poll::Ready(None) };
match cmd {
MockCommand::MockPong { node_id } => {
this.queue_pong(node_id);
}
MockCommand::MockNeighbours { target, nodes } => {
this.queue_neighbours(target, nodes);
}
} else {
return Poll::Ready(None)
}
}

Expand Down
7 changes: 3 additions & 4 deletions crates/net/dns/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,9 @@ async fn lookup_with_timeout<R: Resolver>(
query: &str,
timeout: Duration,
) -> LookupResult<Option<String>> {
match tokio::time::timeout(timeout, r.lookup_txt(query)).await {
Ok(res) => Ok(res),
Err(_) => Err(LookupError::RequestTimedOut),
}
tokio::time::timeout(timeout, r.lookup_txt(query))
.await
.map_err(|_| LookupError::RequestTimedOut)
}

#[cfg(test)]
Expand Down
6 changes: 1 addition & 5 deletions crates/net/downloaders/src/bodies/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ where
/// Retrieve header hashes for the next request.
fn next_request(&self) -> Option<Vec<H256>> {
let mut hashes = self.headers.iter().filter(|h| !h.is_empty()).map(|h| h.hash()).peekable();
if hashes.peek().is_some() {
Some(hashes.collect())
} else {
None
}
hashes.peek().is_some().then(|| hashes.collect())
}

/// Submit the request.
Expand Down
9 changes: 3 additions & 6 deletions crates/net/eth-wire/src/p2pstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,9 @@ where
match ready!(this.inner.as_mut().poll_flush(cx)) {
Err(err) => return Poll::Ready(Err(err.into())),
Ok(()) => {
if let Some(message) = this.outgoing_messages.pop_front() {
if let Err(err) = this.inner.as_mut().start_send(message) {
return Poll::Ready(Err(err.into()))
}
} else {
return Poll::Ready(Ok(()))
let Some(message) = this.outgoing_messages.pop_front() else { return Poll::Ready(Ok(())) };
if let Err(err) = this.inner.as_mut().start_send(message) {
return Poll::Ready(Err(err.into()))
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions crates/net/nat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,10 @@ impl FromStr for NatResolver {
"none" => NatResolver::None,
"publicip" | "public-ip" => NatResolver::PublicIp,
s => {
if let Some(ip) = s.strip_prefix("extip:") {
NatResolver::ExternalIp(ip.parse::<IpAddr>()?)
} else {
return Err(ParseNatResolverError::UnknonwVariant(format!(
let Some(ip) = s.strip_prefix("extip:") else { return Err(ParseNatResolverError::UnknonwVariant(format!(
"Unknown Nat Resolver: {s}"
)))
}
))) };
NatResolver::ExternalIp(ip.parse::<IpAddr>()?)
}
};
Ok(r)
Expand Down
7 changes: 2 additions & 5 deletions crates/net/network/src/eth_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,8 @@ where
let mut block: BlockHashOrNumber = match start_block {
BlockHashOrNumber::Hash(start) => start.into(),
BlockHashOrNumber::Number(num) => {
if let Some(hash) = self.client.block_hash(num).unwrap_or_default() {
hash.into()
} else {
return headers
}
let Some(hash) = self.client.block_hash(num).unwrap_or_default() else { return headers };
hash.into()
}
};

Expand Down
6 changes: 1 addition & 5 deletions crates/net/network/src/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ impl StateFetcher {
return PollAction::NoRequests
}

let peer_id = if let Some(peer_id) = self.next_peer() {
peer_id
} else {
return PollAction::NoPeersAvailable
};
let Some(peer_id) = self.next_peer() else { return PollAction::NoPeersAvailable };

let request = self.queued_requests.pop_front().expect("not empty; qed");
let request = self.prepare_block_request(peer_id, request);
Expand Down
6 changes: 1 addition & 5 deletions crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ pub struct SealedBlockWithSenders {
impl SealedBlockWithSenders {
/// New sealed block with sender. Return none if len of tx and senders does not match
pub fn new(block: SealedBlock, senders: Vec<Address>) -> Option<Self> {
if block.body.len() != senders.len() {
None
} else {
Some(Self { block, senders })
}
(!block.body.len() != senders.len()).then_some(Self { block, senders })
}

/// Split Structure to its components
Expand Down
14 changes: 4 additions & 10 deletions crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,14 @@ impl ChainSpec {
/// Get the header for the genesis block.
pub fn genesis_header(&self) -> Header {
// If London is activated at genesis, we set the initial base fee as per EIP-1559.
let base_fee_per_gas = if self.fork(Hardfork::London).active_at_block(0) {
Some(EIP1559_INITIAL_BASE_FEE)
} else {
None
};
let base_fee_per_gas =
(self.fork(Hardfork::London).active_at_block(0)).then_some(EIP1559_INITIAL_BASE_FEE);

// If shanghai is activated, initialize the header with an empty withdrawals hash, and
// empty withdrawals list.
let withdrawals_root =
if self.fork(Hardfork::Shanghai).active_at_timestamp(self.genesis.timestamp) {
Some(EMPTY_WITHDRAWALS)
} else {
None
};
(self.fork(Hardfork::Shanghai).active_at_timestamp(self.genesis.timestamp))
.then_some(EMPTY_WITHDRAWALS);

Header {
gas_limit: self.genesis.gas_limit,
Expand Down
12 changes: 4 additions & 8 deletions crates/primitives/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,10 @@ impl FromStr for NodeRecord {
.port()
.ok_or_else(|| NodeRecordParseError::InvalidUrl("no port specified".to_string()))?;

let udp_port = if let Some(discovery_port) =
url.query_pairs().find_map(|(maybe_disc, port)| {
if maybe_disc.as_ref() == "discport" {
Some(port)
} else {
None
}
}) {
let udp_port = if let Some(discovery_port) = url
.query_pairs()
.find_map(|(maybe_disc, port)| (maybe_disc.as_ref() == "discport").then_some(port))
{
discovery_port.parse::<u16>().map_err(NodeRecordParseError::Discport)?
} else {
port
Expand Down
12 changes: 2 additions & 10 deletions crates/revm/revm-inspectors/src/tracing/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,7 @@ impl CallTraceStep {

/// Returns the error message if it is an erroneous result.
pub fn as_error(&self) -> Option<String> {
if self.is_error() {
Some(format!("{:?}", self.status))
} else {
None
}
self.is_error().then(|| format!("{:?}", self.status))
}
}

Expand All @@ -280,11 +276,7 @@ impl From<&CallTraceStep> for StructLog {
memory: Some(convert_memory(step.memory.data())),
op: step.op.to_string(),
pc: step.pc as u64,
refund_counter: if step.gas_refund_counter > 0 {
Some(step.gas_refund_counter)
} else {
None
},
refund_counter: (step.gas_refund_counter > 0).then_some(step.gas_refund_counter),
stack: Some(step.stack.data().clone()),
// Filled in `CallTraceArena::geth_trace` as a result of compounding all slot changes
storage: None,
Expand Down
28 changes: 9 additions & 19 deletions crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,9 @@ impl<Client: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvi
return Ok(PayloadStatus::from_status(PayloadStatusEnum::Syncing))
};

let parent_td = if let Some(parent_td) = self.client.header_td(&block.parent_hash)? {
parent_td
} else {
return Ok(PayloadStatus::from_status(PayloadStatusEnum::Invalid {
let Some(parent_td) = self.client.header_td(&block.parent_hash)? else { return Ok(PayloadStatus::from_status(PayloadStatusEnum::Invalid {
validation_error: EngineApiError::PayloadPreMerge.to_string(),
}))
};
})) };

// Short circuit the check by passing parent total difficulty.
if !self.chain_spec.fork(Hardfork::Paris).active_at_ttd(parent_td, U256::ZERO) {
Expand Down Expand Up @@ -352,32 +348,26 @@ impl<Client: HeaderProvider + BlockProvider + StateProviderFactory + EvmEnvProvi
}))
}

let head = if let Some(head) = self.client.header(&head_block_hash)? {
head
} else {
// Block is not known, nothing to do.
return Ok(ForkchoiceUpdated::from_status(PayloadStatusEnum::Syncing))
};
let Some(head) = self.client.header(&head_block_hash)? else {
// Block is not known, nothing to do
return Ok(ForkchoiceUpdated::from_status(PayloadStatusEnum::Syncing)) };
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you indent this? Seems weird that no linter caught it


// The finalized block hash is not known, we are still syncing
if !finalized_block_hash.is_zero() && !self.client.is_known(&finalized_block_hash)? {
return Ok(ForkchoiceUpdated::from_status(PayloadStatusEnum::Syncing))
}

let head_td = if let Some(head_td) = self.client.header_td(&head_block_hash)? {
head_td
} else {
// internal error - we have the head block but not the total difficulty
return Ok(ForkchoiceUpdated::from_status(PayloadStatusEnum::Invalid {
let Some(head_td) = self.client.header_td(&head_block_hash)? else {
// internal error - we have the head block but not the total difficulty
return Ok(ForkchoiceUpdated::from_status(PayloadStatusEnum::Invalid {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

validation_error: EngineApiError::Internal(
reth_interfaces::provider::ProviderError::TotalDifficulty {
number: head.number,
}
.into(),
)
.to_string(),
}))
};
})) };

// From the Engine API spec:
//
Expand Down
10 changes: 2 additions & 8 deletions crates/rpc/rpc/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ macro_rules! impl_to_rpc_result {
F: FnOnce($err) -> M,
M: Into<String>,
{
match self {
Ok(t) => Ok(t),
Err(err) => Err($crate::result::internal_rpc_err(op(err))),
}
self.map_err(|err| $crate::result::internal_rpc_err(op(err)))
}

#[inline]
Expand Down Expand Up @@ -122,10 +119,7 @@ impl ToRpcResultExt for RethResult<Option<Block>> {

fn map_ok_or_rpc_err(self) -> RpcResult<<Self as ToRpcResultExt>::Ok> {
match self {
Ok(block) => match block {
Some(value) => Ok(value),
None => Err(EthApiError::UnknownBlockNumber.into()),
},
Ok(block) => block.ok_or_else(|| EthApiError::UnknownBlockNumber.into()),
Err(err) => Err(internal_rpc_err(err.to_string())),
}
}
Expand Down
10 changes: 4 additions & 6 deletions crates/storage/libmdbx-rs/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,15 +760,13 @@ where
let err_code =
unsafe { ffi::mdbx_cursor_get(cursor.cursor(), &mut key, &mut data, op) };

if err_code == ffi::MDBX_SUCCESS {
Some(IntoIter::new(
(err_code == ffi::MDBX_SUCCESS).then(|| {
IntoIter::new(
Cursor::new_at_position(&**cursor).unwrap(),
ffi::MDBX_GET_CURRENT,
ffi::MDBX_NEXT_DUP,
))
} else {
None
}
)
})
})
}
IterDup::Err(err) => err.take().map(|e| IntoIter::Err(Some(e))),
Expand Down
12 changes: 2 additions & 10 deletions crates/transaction-pool/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,12 @@ impl TransactionId {
return None
}
let prev_nonce = transaction_nonce.saturating_sub(1);
if on_chain_nonce <= prev_nonce {
Some(Self::new(sender, prev_nonce))
} else {
None
}
(on_chain_nonce <= prev_nonce).then(|| Self::new(sender, prev_nonce))
}

/// Returns the `TransactionId` that would come before this transaction.
pub(crate) fn unchecked_ancestor(&self) -> Option<TransactionId> {
if self.nonce == 0 {
None
} else {
Some(TransactionId::new(self.sender, self.nonce - 1))
}
(self.nonce != 0).then(|| TransactionId::new(self.sender, self.nonce - 1))
}

/// Returns the `TransactionId` that directly follows this transaction: `self.nonce + 1`
Expand Down