Skip to content

Commit

Permalink
rm more generics when useless (#12595)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Nov 16, 2024
1 parent d9ed07a commit dda1906
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 96 deletions.
14 changes: 7 additions & 7 deletions crates/exex/exex/src/wal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ mod tests {
use crate::wal::{cache::CachedBlock, Wal};

fn read_notifications(wal: &Wal) -> eyre::Result<Vec<ExExNotification>> {
let Some(files_range) = wal.inner.storage.files_range()? else { return Ok(Vec::new()) };

wal.inner
.storage
.iter_notifications(files_range)
.map(|entry| Ok(entry?.2))
.collect::<eyre::Result<_>>()
wal.inner.storage.files_range()?.map_or(Ok(Vec::new()), |range| {
wal.inner
.storage
.iter_notifications(range)
.map(|entry| entry.map(|(_, _, n)| n))
.collect()
})
}

fn sort_committed_blocks(
Expand Down
16 changes: 8 additions & 8 deletions crates/net/eth-wire-types/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ mod tests {
fn encode_get_block_header_number() {
let expected = hex!("ca820457c682270f050580");
let mut data = vec![];
RequestPair::<GetBlockHeaders> {
RequestPair {
request_id: 1111,
message: GetBlockHeaders {
start_block: BlockHashOrNumber::Number(9999),
Expand All @@ -215,7 +215,7 @@ mod tests {
#[test]
fn decode_get_block_header_number() {
let data = hex!("ca820457c682270f050580");
let expected = RequestPair::<GetBlockHeaders> {
let expected = RequestPair {
request_id: 1111,
message: GetBlockHeaders {
start_block: BlockHashOrNumber::Number(9999),
Expand All @@ -234,7 +234,7 @@ mod tests {
// [ (f90202) 0x0457 = 1111, [ (f901fc) [ (f901f9) header ] ] ]
let expected = hex!("f90202820457f901fcf901f9a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008208ae820d0582115c8215b3821a0a827788a00000000000000000000000000000000000000000000000000000000000000000880000000000000000");
let mut data = vec![];
RequestPair::<BlockHeaders<_>> {
RequestPair {
request_id: 1111,
message: BlockHeaders(vec![
Header {
Expand Down Expand Up @@ -269,7 +269,7 @@ mod tests {
#[test]
fn decode_block_header() {
let data = hex!("f90202820457f901fcf901f9a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008208ae820d0582115c8215b3821a0a827788a00000000000000000000000000000000000000000000000000000000000000000880000000000000000");
let expected = RequestPair::<BlockHeaders<_>> {
let expected = RequestPair {
request_id: 1111,
message: BlockHeaders(vec![
Header {
Expand Down Expand Up @@ -306,7 +306,7 @@ mod tests {
fn encode_get_block_bodies() {
let expected = hex!("f847820457f842a000000000000000000000000000000000000000000000000000000000deadc0dea000000000000000000000000000000000000000000000000000000000feedbeef");
let mut data = vec![];
RequestPair::<GetBlockBodies> {
RequestPair {
request_id: 1111,
message: GetBlockBodies(vec![
hex!("00000000000000000000000000000000000000000000000000000000deadc0de").into(),
Expand All @@ -321,7 +321,7 @@ mod tests {
#[test]
fn decode_get_block_bodies() {
let data = hex!("f847820457f842a000000000000000000000000000000000000000000000000000000000deadc0dea000000000000000000000000000000000000000000000000000000000feedbeef");
let expected = RequestPair::<GetBlockBodies> {
let expected = RequestPair {
request_id: 1111,
message: GetBlockBodies(vec![
hex!("00000000000000000000000000000000000000000000000000000000deadc0de").into(),
Expand All @@ -337,7 +337,7 @@ mod tests {
fn encode_block_bodies() {
let expected = hex!("f902dc820457f902d6f902d3f8d2f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afbf901fcf901f9a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008208ae820d0582115c8215b3821a0a827788a00000000000000000000000000000000000000000000000000000000000000000880000000000000000");
let mut data = vec![];
let request = RequestPair::<BlockBodies<_>> {
let request = RequestPair {
request_id: 1111,
message: BlockBodies(vec![
BlockBody {
Expand Down Expand Up @@ -408,7 +408,7 @@ mod tests {
#[test]
fn decode_block_bodies() {
let data = hex!("f902dc820457f902d6f902d3f8d2f867088504a817c8088302e2489435353535353535353535353535353535353535358202008025a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c12a064b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10f867098504a817c809830334509435353535353535353535353535353535353535358202d98025a052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afba052f8f61201b2b11a78d6e866abc9c3db2ae8631fa656bfe5cb53668255367afbf901fcf901f9a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008208ae820d0582115c8215b3821a0a827788a00000000000000000000000000000000000000000000000000000000000000000880000000000000000");
let expected = RequestPair::<BlockBodies<_>> {
let expected = RequestPair {
request_id: 1111,
message: BlockBodies(vec![
BlockBody {
Expand Down
2 changes: 1 addition & 1 deletion crates/net/eth-wire-types/src/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ impl RequestTxHashes {

impl FromIterator<(TxHash, Eth68TxMetadata)> for RequestTxHashes {
fn from_iter<I: IntoIterator<Item = (TxHash, Eth68TxMetadata)>>(iter: I) -> Self {
Self::new(iter.into_iter().map(|(hash, _)| hash).collect::<HashSet<_>>())
Self::new(iter.into_iter().map(|(hash, _)| hash).collect())
}
}

Expand Down
42 changes: 10 additions & 32 deletions crates/net/eth-wire-types/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,52 +77,30 @@ impl<N: NetworkPrimitives> ProtocolMessage<N> {
)?)
}
}
EthMessageID::GetBlockHeaders => {
let request_pair = RequestPair::<GetBlockHeaders>::decode(buf)?;
EthMessage::GetBlockHeaders(request_pair)
}
EthMessageID::BlockHeaders => {
let request_pair = RequestPair::<BlockHeaders<_>>::decode(buf)?;
EthMessage::BlockHeaders(request_pair)
}
EthMessageID::GetBlockBodies => {
let request_pair = RequestPair::<GetBlockBodies>::decode(buf)?;
EthMessage::GetBlockBodies(request_pair)
}
EthMessageID::BlockBodies => {
let request_pair = RequestPair::<BlockBodies<_>>::decode(buf)?;
EthMessage::BlockBodies(request_pair)
}
EthMessageID::GetBlockHeaders => EthMessage::GetBlockHeaders(RequestPair::decode(buf)?),
EthMessageID::BlockHeaders => EthMessage::BlockHeaders(RequestPair::decode(buf)?),
EthMessageID::GetBlockBodies => EthMessage::GetBlockBodies(RequestPair::decode(buf)?),
EthMessageID::BlockBodies => EthMessage::BlockBodies(RequestPair::decode(buf)?),
EthMessageID::GetPooledTransactions => {
let request_pair = RequestPair::<GetPooledTransactions>::decode(buf)?;
EthMessage::GetPooledTransactions(request_pair)
EthMessage::GetPooledTransactions(RequestPair::decode(buf)?)
}
EthMessageID::PooledTransactions => {
let request_pair = RequestPair::<PooledTransactions>::decode(buf)?;
EthMessage::PooledTransactions(request_pair)
EthMessage::PooledTransactions(RequestPair::decode(buf)?)
}
EthMessageID::GetNodeData => {
if version >= EthVersion::Eth67 {
return Err(MessageError::Invalid(version, EthMessageID::GetNodeData))
}
let request_pair = RequestPair::<GetNodeData>::decode(buf)?;
EthMessage::GetNodeData(request_pair)
EthMessage::GetNodeData(RequestPair::decode(buf)?)
}
EthMessageID::NodeData => {
if version >= EthVersion::Eth67 {
return Err(MessageError::Invalid(version, EthMessageID::GetNodeData))
}
let request_pair = RequestPair::<NodeData>::decode(buf)?;
EthMessage::NodeData(request_pair)
}
EthMessageID::GetReceipts => {
let request_pair = RequestPair::<GetReceipts>::decode(buf)?;
EthMessage::GetReceipts(request_pair)
}
EthMessageID::Receipts => {
let request_pair = RequestPair::<Receipts>::decode(buf)?;
EthMessage::Receipts(request_pair)
EthMessage::NodeData(RequestPair::decode(buf)?)
}
EthMessageID::GetReceipts => EthMessage::GetReceipts(RequestPair::decode(buf)?),
EthMessageID::Receipts => EthMessage::Receipts(RequestPair::decode(buf)?),
};
Ok(Self { message_type, message })
}
Expand Down
8 changes: 4 additions & 4 deletions crates/net/eth-wire-types/src/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod tests {
fn encode_get_receipts() {
let expected = hex!("f847820457f842a000000000000000000000000000000000000000000000000000000000deadc0dea000000000000000000000000000000000000000000000000000000000feedbeef");
let mut data = vec![];
let request = RequestPair::<GetReceipts> {
let request = RequestPair {
request_id: 1111,
message: GetReceipts(vec![
hex!("00000000000000000000000000000000000000000000000000000000deadc0de").into(),
Expand All @@ -72,7 +72,7 @@ mod tests {
let request = RequestPair::<GetReceipts>::decode(&mut &data[..]).unwrap();
assert_eq!(
request,
RequestPair::<GetReceipts> {
RequestPair {
request_id: 1111,
message: GetReceipts(vec![
hex!("00000000000000000000000000000000000000000000000000000000deadc0de").into(),
Expand All @@ -88,7 +88,7 @@ mod tests {
fn encode_receipts() {
let expected = hex!("f90172820457f9016cf90169f901668001b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f85ff85d940000000000000000000000000000000000000011f842a0000000000000000000000000000000000000000000000000000000000000deada0000000000000000000000000000000000000000000000000000000000000beef830100ff");
let mut data = vec![];
let request = RequestPair::<Receipts> {
let request = RequestPair {
request_id: 1111,
message: Receipts(vec![vec![
ReceiptWithBloom {
Expand Down Expand Up @@ -124,7 +124,7 @@ mod tests {
let request = RequestPair::<Receipts>::decode(&mut &data[..]).unwrap();
assert_eq!(
request,
RequestPair::<Receipts> {
RequestPair {
request_id: 1111,
message: Receipts(vec![
vec![
Expand Down
8 changes: 4 additions & 4 deletions crates/net/eth-wire-types/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod tests {
fn encode_get_node_data() {
let expected = hex!("f847820457f842a000000000000000000000000000000000000000000000000000000000deadc0dea000000000000000000000000000000000000000000000000000000000feedbeef");
let mut data = vec![];
let request = RequestPair::<GetNodeData> {
let request = RequestPair {
request_id: 1111,
message: GetNodeData(vec![
hex!("00000000000000000000000000000000000000000000000000000000deadc0de").into(),
Expand All @@ -54,7 +54,7 @@ mod tests {
let request = RequestPair::<GetNodeData>::decode(&mut &data[..]).unwrap();
assert_eq!(
request,
RequestPair::<GetNodeData> {
RequestPair {
request_id: 1111,
message: GetNodeData(vec![
hex!("00000000000000000000000000000000000000000000000000000000deadc0de").into(),
Expand All @@ -69,7 +69,7 @@ mod tests {
fn encode_node_data() {
let expected = hex!("ce820457ca84deadc0de84feedbeef");
let mut data = vec![];
let request = RequestPair::<NodeData> {
let request = RequestPair {
request_id: 1111,
message: NodeData(vec![
hex!("deadc0de").as_slice().into(),
Expand All @@ -87,7 +87,7 @@ mod tests {
let request = RequestPair::<NodeData>::decode(&mut &data[..]).unwrap();
assert_eq!(
request,
RequestPair::<NodeData> {
RequestPair {
request_id: 1111,
message: NodeData(vec![
hex!("deadc0de").as_slice().into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/net/eth-wire-types/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ mod tests {
let total_difficulty = U256::from(rng.gen::<u64>());

// create a genesis that has a random part, so we can check that the hash is preserved
let genesis = Genesis { nonce: rng.gen::<u64>(), ..Default::default() };
let genesis = Genesis { nonce: rng.gen(), ..Default::default() };

// build head
let head = Head {
Expand Down
22 changes: 7 additions & 15 deletions crates/net/eth-wire-types/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mod tests {
fn encode_get_pooled_transactions() {
let expected = hex!("f847820457f842a000000000000000000000000000000000000000000000000000000000deadc0dea000000000000000000000000000000000000000000000000000000000feedbeef");
let mut data = vec![];
let request = RequestPair::<GetPooledTransactions> {
let request = RequestPair {
request_id: 1111,
message: GetPooledTransactions(vec![
hex!("00000000000000000000000000000000000000000000000000000000deadc0de").into(),
Expand All @@ -114,7 +114,7 @@ mod tests {
let request = RequestPair::<GetPooledTransactions>::decode(&mut &data[..]).unwrap();
assert_eq!(
request,
RequestPair::<GetPooledTransactions> {
RequestPair {
request_id: 1111,
message: GetPooledTransactions(vec![
hex!("00000000000000000000000000000000000000000000000000000000deadc0de").into(),
Expand Down Expand Up @@ -182,7 +182,7 @@ mod tests {
.expect("Failed to convert TransactionSigned to PooledTransactionsElement")
})
.collect();
let request = RequestPair::<PooledTransactions> {
let request = RequestPair {
request_id: 1111,
message: PooledTransactions(message), /* Assuming PooledTransactions wraps a
* Vec<PooledTransactionsElement> */
Expand Down Expand Up @@ -248,10 +248,7 @@ mod tests {
.expect("Failed to convert TransactionSigned to PooledTransactionsElement")
})
.collect();
let expected = RequestPair::<PooledTransactions> {
request_id: 1111,
message: PooledTransactions(message),
};
let expected = RequestPair { request_id: 1111, message: PooledTransactions(message) };

let request = RequestPair::<PooledTransactions>::decode(&mut &data[..]).unwrap();
assert_eq!(request, expected);
Expand Down Expand Up @@ -383,10 +380,8 @@ mod tests {
.expect("Failed to convert TransactionSigned to PooledTransactionsElement")
})
.collect();
let expected_transactions = RequestPair::<PooledTransactions> {
request_id: 0,
message: PooledTransactions(message),
};
let expected_transactions =
RequestPair { request_id: 0, message: PooledTransactions(message) };

// checking tx by tx for easier debugging if there are any regressions
for (decoded, expected) in
Expand Down Expand Up @@ -522,10 +517,7 @@ mod tests {
.expect("Failed to convert TransactionSigned to PooledTransactionsElement")
})
.collect();
let transactions = RequestPair::<PooledTransactions> {
request_id: 0,
message: PooledTransactions(message),
};
let transactions = RequestPair { request_id: 0, message: PooledTransactions(message) };

let mut encoded = vec![];
transactions.encode(&mut encoded);
Expand Down
2 changes: 1 addition & 1 deletion crates/net/nat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl FromStr for NatResolver {
"Unknown Nat Resolver: {s}"
)))
};
Self::ExternalIp(ip.parse::<IpAddr>()?)
Self::ExternalIp(ip.parse()?)
}
};
Ok(r)
Expand Down
Loading

0 comments on commit dda1906

Please sign in to comment.