From 470b1e266e406e880084914f1e0672dc403afd0d Mon Sep 17 00:00:00 2001 From: Thomas Coratger Date: Wed, 3 Jul 2024 20:44:53 +0200 Subject: [PATCH 1/2] clippy: rm some type_complexity --- crates/consensus/beacon/src/engine/mod.rs | 19 +++++++++++++------ crates/etl/src/lib.rs | 11 +++++++++-- crates/storage/db/benches/hash_keys.rs | 1 - crates/storage/db/src/static_file/cursor.rs | 10 ++++++---- examples/stateful-precompile/src/main.rs | 9 +++++++-- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index b0a0284b6de6..9673f6205db2 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -88,6 +88,18 @@ const MAX_INVALID_HEADERS: u32 = 512u32; /// If the distance exceeds this threshold, the pipeline will be used for sync. pub const MIN_BLOCKS_FOR_PIPELINE_RUN: u64 = EPOCH_SLOTS; +/// Represents a pending forkchoice update. +/// +/// This type encapsulates the necessary components for a pending forkchoice update +/// in the context of a beacon consensus engine. +/// +/// It consists of: +/// - The current fork choice state. +/// - Optional payload attributes specific to the engine type. +/// - Sender for the result of an oneshot channel, conveying the outcome of the fork choice update. +type PendingForkchoiceUpdate = + (ForkchoiceState, Option, oneshot::Sender>); + /// The beacon consensus engine is the driver that switches between historical and live sync. /// /// The beacon consensus engine is itself driven by messages from the Consensus Layer, which are @@ -189,12 +201,7 @@ where /// It is recorded if we cannot process the forkchoice update because /// a hook with database read-write access is active. /// This is a temporary solution to always process missed FCUs. - #[allow(clippy::type_complexity)] - pending_forkchoice_update: Option<( - ForkchoiceState, - Option, - oneshot::Sender>, - )>, + pending_forkchoice_update: Option>, /// Tracks the header of invalid payloads that were rejected by the engine because they're /// invalid. invalid_headers: InvalidHeaderCache, diff --git a/crates/etl/src/lib.rs b/crates/etl/src/lib.rs index 137a96fff1c4..0b1bd129ca0a 100644 --- a/crates/etl/src/lib.rs +++ b/crates/etl/src/lib.rs @@ -164,6 +164,14 @@ where } } +/// Type alias for the items stored in the heap of [`EtlIter`]. +/// +/// Each item in the heap is a tuple containing: +/// - A `Reverse` tuple of a key-value pair (`Vec, Vec`), used to maintain the heap in +/// ascending order of keys. +/// - An index (`usize`) representing the source file from which the key-value pair was read. +type HeapItem = (Reverse<(Vec, Vec)>, usize); + /// `EtlIter` is an iterator for traversing through sorted key-value pairs in a collection of ETL /// files. These files are created using the [`Collector`] and contain data where keys are encoded /// and values are compressed. @@ -174,8 +182,7 @@ where #[derive(Debug)] pub struct EtlIter<'a> { /// Heap managing the next items to be iterated. - #[allow(clippy::type_complexity)] - heap: BinaryHeap<(Reverse<(Vec, Vec)>, usize)>, + heap: BinaryHeap, /// Reference to the vector of ETL files being iterated over. files: &'a mut Vec, } diff --git a/crates/storage/db/benches/hash_keys.rs b/crates/storage/db/benches/hash_keys.rs index d37146fd1e28..1807e6f4a6ec 100644 --- a/crates/storage/db/benches/hash_keys.rs +++ b/crates/storage/db/benches/hash_keys.rs @@ -130,7 +130,6 @@ where /// Generates two batches. The first is to be inserted into the database before running the /// benchmark. The second is to be benchmarked with. -#[allow(clippy::type_complexity)] fn generate_batches(size: usize) -> (Vec>, Vec>) where T: Table, diff --git a/crates/storage/db/src/static_file/cursor.rs b/crates/storage/db/src/static_file/cursor.rs index 9a93ca224429..c00318f8c184 100644 --- a/crates/storage/db/src/static_file/cursor.rs +++ b/crates/storage/db/src/static_file/cursor.rs @@ -10,6 +10,9 @@ use std::sync::Arc; #[derive(Debug, Deref, DerefMut)] pub struct StaticFileCursor<'a>(NippyJarCursor<'a, SegmentHeader>); +/// Type alias for column results. +type ColumnResult = ProviderResult>; + impl<'a> StaticFileCursor<'a> { /// Returns a new [`StaticFileCursor`]. pub fn new(jar: &'a NippyJar, reader: Arc) -> ProviderResult { @@ -56,7 +59,7 @@ impl<'a> StaticFileCursor<'a> { pub fn get_one( &mut self, key_or_num: KeyOrNumber<'_>, - ) -> ProviderResult> { + ) -> ColumnResult { let row = self.get(key_or_num, M::MASK)?; match row { @@ -69,7 +72,7 @@ impl<'a> StaticFileCursor<'a> { pub fn get_two( &mut self, key_or_num: KeyOrNumber<'_>, - ) -> ProviderResult> { + ) -> ColumnResult<(M::FIRST, M::SECOND)> { let row = self.get(key_or_num, M::MASK)?; match row { @@ -79,11 +82,10 @@ impl<'a> StaticFileCursor<'a> { } /// Gets three column values from a row. - #[allow(clippy::type_complexity)] pub fn get_three( &mut self, key_or_num: KeyOrNumber<'_>, - ) -> ProviderResult> { + ) -> ColumnResult<(M::FIRST, M::SECOND, M::THIRD)> { let row = self.get(key_or_num, M::MASK)?; match row { diff --git a/examples/stateful-precompile/src/main.rs b/examples/stateful-precompile/src/main.rs index 538adfaafe75..038a18c4b5a6 100644 --- a/examples/stateful-precompile/src/main.rs +++ b/examples/stateful-precompile/src/main.rs @@ -30,6 +30,12 @@ use reth_tracing::{RethTracer, Tracer}; use schnellru::{ByLength, LruMap}; use std::{collections::HashMap, sync::Arc}; +/// Type alias for the LRU cache used within the [`PrecompileCache`]. +type PrecompileLRUCache = LruMap<(Bytes, u64), PrecompileResult>; + +/// Type alias for the thread-safe `Arc>` wrapper around [`PrecompileCache`]. +type CachedPrecompileResult = Arc>; + /// A cache for precompile inputs / outputs. /// /// This assumes that the precompile is a standard precompile, as in `StandardPrecompileFn`, meaning @@ -40,8 +46,7 @@ use std::{collections::HashMap, sync::Arc}; #[derive(Debug, Default)] pub struct PrecompileCache { /// Caches for each precompile input / output. - #[allow(clippy::type_complexity)] - cache: HashMap<(Address, SpecId), Arc>>>, + cache: HashMap<(Address, SpecId), CachedPrecompileResult>, } /// Custom EVM configuration From 889d289c3640421329d39ca0f71abb9c103bb999 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Wed, 3 Jul 2024 21:05:26 +0200 Subject: [PATCH 2/2] Update crates/storage/db/src/static_file/cursor.rs Co-authored-by: Matthias Seitz --- crates/storage/db/src/static_file/cursor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/storage/db/src/static_file/cursor.rs b/crates/storage/db/src/static_file/cursor.rs index c00318f8c184..4a052c6abf3b 100644 --- a/crates/storage/db/src/static_file/cursor.rs +++ b/crates/storage/db/src/static_file/cursor.rs @@ -10,7 +10,7 @@ use std::sync::Arc; #[derive(Debug, Deref, DerefMut)] pub struct StaticFileCursor<'a>(NippyJarCursor<'a, SegmentHeader>); -/// Type alias for column results. +/// Type alias for column results with optional values. type ColumnResult = ProviderResult>; impl<'a> StaticFileCursor<'a> {